UltiDev IP address binding - android

I am trying to create a web service for my android application. The web service is supposed to run on UltiDev, the issue i get is when i try to access the web service through a local android emulator. I was advised to change the url of the web service to http://10.0.2.2:portnumber/serviceName but when i attempt to make this change i get an error in UltiDev. It turns out that i have to bind the port first before i can do this, however UltiDev does not allow me to do this. This is the error i get. Sorry i can't post the actual image because i need reputation points first.
Failed to register application because System.ApplicationException: Unable to register application because not all required applications settings are specified: Listen endpoints are either not specified or are already taken by other applications.
at UWS.Configuration.WebAppConfigEntry.ApplyFinalDefaultsAndValidateBeforeSaving()
.....

Could you please clarify whether you are trying to do this programmatically, or using UWS Explorer UI? Please attach a screenshot - it always helps.
In case you use UWS Explorer, the screenshot below shows how to add a port binding. If you click "Specify host name or IP address" radiobutton, you will be able to specify an IP address.
If you do all that, but then you still get the same error, it means your system acts as if all IP+ports are already taken, which often is caused by security software, like firewall+antiviruses.

Related

Read Preferred Network Type Setting

I am trying to read the Preferred network type setting from the device. But nowhere android API's are available.
Use case:
Trying to read the Preferred network type and connected network type so that if the device has LTE enabled and the user is forcefully switched back to the lower network(3G,2G); then there should be a notification sent to the user.
I have checked the system setting code, But it's deprecated.
Settings.Secure.getString(getApplicationContext().getContentResolver(),
Settings.System.NETWORK_PREFERENCE);
Is there any alternate way to read the system secured settings(By reflection?).
And Also is it possible to write back the setting with the user permission?
Help is much appreciated.
I think the right code is:
Settings.Global.getString(context.getContentResolver(),Settings.Global.NETWORK_PREFERENCE)

Android Studio: Local network - pass PC/Laptop IP to App

Is there a way to pass my PCs/Laptops current local IP to my App via command line argument or something else?
I don't want to switch to a static IP or enter it all the time I begin to work on my App that relies on a local server that runs on my laptop. I think the easiest way would be to pass it as a macro from the run configurations. Is there a way to do this or something similar?
There are two main ways to do this.
Write your IP Address to a system property and then read that in your app.
Start your activity with an intent that contains the IP Address as an extra.
Of the two, I'd suggest using an intent. Refer to this other answer for how to use adb to start your app. In your activity code, in onCreate you should call getIntent and then get your extra and parse it.

Android: Error Resolving hostname to IP

I have been doing some low-level hacking on Android.
I'm trying to enable wifi i.e. establish Internet Connectivity through terminal (adb shell). I have written a C program to achieve this by hacking into android's bionic library and libnetutils library to get things working.
Everything works fine. I'm able to acquire an IP address via dhcp request. The problem is that whenever I try to open any site for ex. google.com via browser, it does not opens. But when I enter the IP address of the site "74.125.228.66" (google.com), the page gets loaded.
I have tried several options, like modifying the dns entries in file "resolv.conf" (present in /system/etc) and in file "20-dns.conf" (in /system/etc/dhcpcd/dhcpcd-hooks).
I also tried using "setprop" call to set dns values manually for "dhcp.eth0.dns*" and "dhcp.wlan0.dns*".
But nothing seems to work. There's also an interesting behavior I noticed. If I turn on wifi manually from "settings" menu and then turn it off and then run my program, I don't face this issue anymore. Looks like it uses some settings that I could not figure out.
My guess is that this is DNS issue, but it may be something else. Let me know if anyone has faced this issue before.
Here's is what I do to enable wifi:
Enable wpa_supplicant daemon using set_prop().
Send a dhcp request to acquire IP (code from dhcpclient.c in libnetutils).
Enable dhcpcd daemon using set_prop(). (Even without this, everything works. I ran this so that IP lease gets renewed automatically. ( Although I'm not sure about this, if dhcpcd daemon would take care of lease renewal or not) ).
In order to enable WIFI on Android via command line through a C program, you'll need to do the following:
1) Enable wpa_supplicant daemon. (Make sure you have the wpa_supplicant.conf file at /data/misc/wifi with AP (access point) information in it.). wpa_supplicant internally takes care of loading the driver and then establishes connectivity to the specified networks in its configuration file based on availability and strength.
2) Issue a dhcp request. ( To fetch IP, lease, dns1, dns2 etc.)
3) Start dhcpcd daemon. (For Lease renewal)
4) Set net.dns* properties. (Without this, DNS service would not work for any application)
In order to enable daemons (wpa_supplicant and dhcpcd) and set net.dns* properties , you'll need to use Android property system (property_set() and property_get() functions). To learn more about Android Property System, follow this link:
http://rxwen.blogspot.com/2010/01/android-property-system.html
In order to use above 2 functions, you'll need to hack into bionic and core libcutils library.
Location:
/bionic/libc/bionic/system_properties.c
/system/core/libcutils/properties.c
For issuing dhcp request, you need to hack some of the implementation of libnetutils
Location:
/system/core/libnetutils/*
Disabling Wifi:
1) Unload the driver manually.
2) Stop wpa_supplicant daemon.
3) Stop dhcpcd daemon.
4) Unset net.dns* properties.
In this case, driver needs to be unloaded manually unlike loading. If this step is not done, then any of the existing connections will not be torn apart even after 2, 3, and 4. To manually unload the driver, you need to issue "DRIVER STOP" request to wpa_supplicant which will take care of interacting with kernel to unload the driver.
In order to communicate with wpa_supplicant, you'll need to hack into wpa_cli implementation to see how it works. It basically uses UNIX Domain Sockets to interact with the supplicant. You basically need to have a look at wpa_ctrl.c and wpa_cli.c
To learn more about wpa_supplicant, wpa_cli, follow below link:
http://hostap.epitest.fi/wpa_supplicant/devel/
All above that I explained to you is done in Android at HAL layer.
Location:
/hardware/libhardware_legacy/wifi/wifi.c
So, basically whenever you toggle wifi switch from settings menu, control passes from wifi_app code to wifi_frameworks layer (WifiManager and WifiServices) which passes control to wifi.c (HAL layer) through JNI implementation (WifiNative).
A good starting point would be to look at wifi.c if you want to know things that are done at low level to enable wifi.
PS - All above is what I learned after several attempts trying to figure out stuff on my own. There are no documents or blogs (atleast I didn't find any!) that would specify what needs to be done and order of events that should be followed to enable/disable WIFI. So, it may be possible you might find a better way of doing things. This worked for me, something else might work for you!

Android : Network info measurement

I am trying to develop android applicaton for getting low-level info about network info measurement.
I want to know How to get these data?
3G:
-RSCP
-ECNO (not Eclo)
-BER
2G:
-RxLevelQuality
-RxLevelSub
Call State:
-Handover
-Dropped Call
-Call Failed
If anyone have idea,Please help me!.
[CALL STATE]
I found 'DisconnectCause' from here
, but I think it always return NORMAL.
You can build your own firmware that collects this information, then deploy this firmware on your personal phone.
Outside of what you get from TelephonyManager, the rest of your requested data is inaccessible by Android SDK applications.
I found 'DisconnectCause' from here , but I think it always return NORMAL.
That is not from the Android OS. That is from SipDroid, a third-party SIP client.

Web Server on Android phone

I'm trying to set up a web server using the Restlet framework on my Android phone. My idea is to build a game where one phone creates some markers on a map which then can be transferred directly to other phones using rest. At first (and for simplicity) I want to transfer a List of Objects.
Running a server on my computer seems to work fine, but when I transfer the code to my Android application, it won't start the server. Here is the code:
Component serverComponent = new Component();
serverComponent.getServers().add(Protocol.HTTP, 80);
final Router router = new Router(serverComponent.getContext().createChildContext());
router.attach("/gamedata", GameDataResourceServer.class);
serverComponent.getDefaultHost().attach(router);
serverComponent.start();
When the line serverComponent.start(); is executed, this Exception is thrown:
java.net.BindException: Permission denied (maybe missing INTERNET permission), although the internet permission is in the manifest file. Searching for some tutorials didn't help either. The result are either client applications or very complicated scenarios.
Could someone give an example for a simple application?
In Unix-type environments you typically need root access to bind to a TCP port below 1024. You're trying to bind to port 80, and unless you run this code as root the OS will prevent the request.

Categories

Resources