Debug Android application remotely over same vpn - android

I've developed an Android application which worked fine on my side but failed (not crash) on client side.
I do the research but still can't figure how to do.
From this post Debugging android device over the Internet
I know it can achieved by using abd, but it required both pc connect on the same network, which are not suitable for my case where my client are connect on difference network.
This post suggest another solution which is port forward, but warmed not recommended as this was pretty dangerous.
The following post suggest method of adb -a -P 5037 nodaemon server but I'm not really understand does it work for my situation as i getting error of could not install *smartsocket* listener: cannot bind to 0.0.0.0:5037: Only one usage of each socket address (protocol/network address/port) is normally permitted. (10048)
My question is how do remotely debug (get the logcat) of client application under difference network but was able to connect on the same VPN. Thanks.

Even i had faced the similar problem and this blog talks on same thing and there is some solution already out there which can be used for working on remote android devices, it looks paid one though.

Related

Connection refused: ADB connection from Iphone to windows

I am trying to build a watch face for Android wear. The Android wear is an emulator and the device that I have is an iPhone connected via USB to my windows laptop
I have followed the instructions from the below link
https://developer.android.com/studio/command-line/adb.html ,
verified device compatibility as per
https://www.android.com/wear/check/
and have also followed responses as per the answers # adb connection over tcp not working now, however I am receiving the following error
unable to connect to :5555: cannot connect :5555: No conn
ection could be made because the target machine actively refused it. (10061)
Actively refused it means that the host sent a reset instead of an ack when you tried to connect. It is therefore not a problem in your code. Either there is a firewall blocking the connection or the process that is hosting the service is not listening on that port. You may also want to check these SO posts: Trouble debugging android wear over bluetooth - Unable to connect to localhost and No connection could be made because the target machine actively refused it? which also stated that the machine exists but that it has no services listening on the specified port, or there is a firewall stopping you. You may check it out.
Thanks. I was able to figure out with some research that getting to have iPhone with a wearable emulator may not be possible and decided to have both my device and wearable as emulators. Though it was difficult, I was able to get both my emulators talk to each other with the below link Pairing Android and Wear emulators and https://kennethmascarenhas.wordpress.com/2014/08/19/developing-for-android-wear-with-emulators/?utm_source=Android%20Weekly&utm_campaign=a97f04efe2-Android_Weekly_116&utm_medium=email&utm_term=0_4eb677ad19-a97f04efe2-337259209 with a minor change to authentication, which I have included as comment in the stackoverflow post

How to set up a Wifi-Direct connection between Android and Linux

I want to connect two devices using Wifi-Direct.
One is a pc with Linux (during my test I'm using Linux Mint 17.2), the other is an Android smartphone (Samsung Galaxy S3 with Android 4.3. Not rooted and don't want to root).
Reading a number of guides on the internet, I decided to use wpa_supplicant in Linux and to create an app for Android.
This is one of the best guides I found for wpa_supplicant:
https://web.archive.org/web/20210114180304/https://processors.wiki.ti.com/index.php/OMAP_Wireless_Connectivity_NLCP_WiFi_Direct_Configuration_Scripts
When I run iw list I see that the "Supported interface modes:" allows P2P_client and P2P_GO.
My wpa_supplicant.conf contains:
ctrl_interface=/var/run/wpa_supplicant
update_config=1
ap_scan=1
device_name=My-pc
device_type=1-0050F204-1
driver_param=use_p2p_group_interface=1
p2p_go_intent=15
p2p_go_ht40=1
The app is very similar to this example (it's from a book) https://github.com/retomeier/Wrox-ProfessionalAndroid-4E/blob/9741a8b62005d49519b1decfea21e7213fdd94a3/Snippets_ch18/app/src/main/java/com/professionalandroid/apps/myapplication/WiFiDirectActivity.java
It works as expected. When I try it with two Android devices, they can see each other and connect (it appear the Wifi-Direct icon).
Now I am trying to connect Android and Linux, but I guess I don't really understand how wpa_supplicant works.
I also saw this question that is very similar to what I asked, but it doesn't really answer my doubts...
Direct Wifi Communication between android smartphone and other devices
My problem is that I can't understand how to do the handshake between the two devices and how to set up the network.
Wpa_supplicant is my problem. I run:
sudo wpa_supplicant -wlan0 -Dnl80211 -c/etc/wpa_supplicant.conf
sudo wpa_cli
But I had a lot of problems:
The device_name (and other parameters) weren't set as I specifiend in the .conf file
wpa_supplicant continues to try to connect to all the networks
p2p_find was really slow...
so I went into /usr/share/dbus-1/system-services and moved away the two files
fi.epitest.hostap.WPASupplicant.service
fi.w1.wpa_supplicant1.service
Now I can
sudo killall wpa_supplicant
and it really dies, disconnecting me from Wifi without reconnecting the following second.
Now I can launch wpa_supplicant and the three problems are resolved.
I go into wpa_cli, launch "p2p_find" and at the same time, I enable the search from within the app.
Android and Linux can now see each other.
P2P-DEVICE-FOUND 00:11:22:44:88:ff p2p_dev_addr=00:11:22:44:88:ff
pri_dev_type=10-0050F204-5 name='GT-I9300' config_methods=0x188
dev_capab=0x24 group_capab=0x0 vendor_elems=1 new=0
With "p2p_peers" I can see the cellphone MAC.
> aa:bb:cc:dd:ee:ff
Here I can't go ahead. I tried various possibilities, but none of them worked. My objective is to have Linux as Group Owner.
Question 1.1: Which is the correct way to handshake the two devices?
Question 1.2: When I try p2p_connect I often get "Michael MIC failure detected" between the results, what does it means in this contest?
Question 1.3: Android currently tries to connect with PBC. There is a way to connect with PIN?
Seeing that I couldn't connect Android/Linux, I tried to do some practice with Linux/Linux (Linux Mint as GO, Ubuntu as Client), following examples from internet like the ones in the first link.
I have a number of problems even here.
In Mint I try
p2p_connect MAC_UBUNTU pin auth
in Ubuntu I try
p2p_connect MAC_MINT PIN_GENERATED_BY_MINT
When I write the psp_connect in Mint, it creates a new interface p2p_wlan0 _0, and it returns
P2P-DEVICE-LOST p2p_dev_addr=MAC_UBUNTU
then the p2p_connect launched from Ubuntu fails.
Question 2.1 Why it switches interface when creating the group?
Question 2.2 What is the correct way to handle this change? After the change I can't p2p_find Ubuntu anymore (I have to wait some time or restart everything)
Question 2.3 Should Ubuntu change it's interface?
Question 2.3 In the new interface I should set the IP for both Ubuntu and Mint... how should I do this with static IPs?
Question 2.4 If I want to set up for example a DHCP server and client?
Question 1.4 And with Android(client) / Linux(GO)?
I worked a lot on this problem and here is the answers that I found:
Answer 1.1 There are a lot of possibilities and the correct one depends on what you are trying to achieve.
You can find the various possibilities here: http://processors.wiki.ti.com/index.php/OMAP_Wireless_Connectivity_NLCP_WiFi_Direct_Configuration_Scripts
I wanted Linux as a GO and Android as a client, so what worked for me in Linux is:
// Kill current supplicant and avoid its automatic recreation
system("mv /usr/share/dbus-1/system-services/fi.* .");
system("killall udhcpd");
system("wpa_cli -i wlan0 terminate -B");
usleep(300000);
// Start new supplicant
system("wpa_supplicant -Dnl80211 -iwlan0 -c /etc/p2p_supplicant.conf -B");
system("wpa_cli -iwlan0 p2p_group_add");
system("ifconfig p2p-wlan0-0 192.168.1.2");
// Connect with a peer
for (;;) {
system("wpa_cli -ip2p-wlan0-0 wps_pbc");
system("udhcpd /etc/udhcpd.conf");
// Here start your TCP server on a port
Server server([port]);
server.startServer();
}
N.B. To destroy P2P connection and restart the normal one I use this script:
#!/bin/bash
wpa_cli -i wlan0 terminate -B
wpa_cli -i p2p-wlan0-0 terminate -B
cp ./fi.* /usr/share/dbus-1/system-services/
service network-manager restart
Here the server listens for a connection and the android client connects to it. I used a very easy TCP server found on the first website and it worked like a charm.
It's important to start the udhcpd or you won't get the "connected" icon in Android.
For the Android side, I followed what I saw on http://developer.android.com/training/connect-devices-wirelessly/wifi-direct.html and it worked perfectly.
Answer 1.2 From wpa_cli you can get a lot of different warnings and errors. I saw that simply calling the function (like I did in the previous snippet) made everything work despite the warnings. I ignored them.
Answer 1.3 The connection using PIN works, when I tried it I wasn't starting the udhcpd and that crashed my connection every time. It was not due to PIN or PBC.
Answer 2.1 Both the server and the client are switching interface.
It is a very similar behaviour to what you usually do with sockets. You create a listening socket, somebody connects, you create a new socket to handle that client in a separate thread while the listening socket is still there, waiting for other users.
You do the same with interfaces. Starting a wpa_cli that monitors the wlan0 interface and one that monitors the p2p-wlan0-0 interface gives a good idea of what is happening during the change.
Answer 2.2 The client "went" to the other interface and is now ready to receive an IP. Start the DHCP and TCP servers!
Answer 2.3 Don't use static IP. Only only for the server is ok, the client should use a DHCP IP. Maybe there is a way to handle static IPs, but it was not useful for my objectives.
Answer 2.4 Done. That was the problem all along
Answer 1.4 This works perfectly even with Android/linux.
Sorry if I made some mistake in my answer, I still don't get the whole picture of WiFi-Direct connections, I simply hope that this can help someone else.
(May not be a complete answer, but right direction)
The issue is on the Linux side. I'm encountering similar issues between a Cyanogenmod (Android 5) and Fedora 22, attempting to use Wifi Direct (Wifi P2P) for Intel's Wireless Display Software for Linux OS (WDS).
Specifically, Intel's connman diverged (written from scratch) back in 2009 from what had been standard in Linux, NetworkManager. Connman appears to be the only implementation of Wifi Direct (Wifi P2P) for Linux, and had been written for the embedded (mobile) market.
Due to an RPM issue, connman remains untested on my system, but the software should provide the dbus communications Linux needs.
Website: https://01.org/connman
Did you simply tried to activated your hotspot option on Android? Then connect with the Ubuntu device, check the connected IP on the Android hotspot options and give it to your app.
It work for me for remote controling my Ubuntu system.

httpconnection refused on android device when connecting with localhost

I am making an app which requires connection with my localhost on PC. It is working fine with emulator but when trying it out in my real device it is throwing exception:
org.apache.http.conn.HttpHostConnectException: Connection to http://192.168.XX.XX:8090 refused, network host unreachable etc etc
where 8090 is the port in which my Apache Tomcat is running and 192.168.xx.xx is my pc's ip address. I have tried out many things but none worked. Also I'm using USB connection not wifi to access localhost from device.
Please help!!!! thanks
Have you looked at similar questions linked by Stackoverflow, such as Cannot access localhost from Android device or How can I access my localhost from my Android device??
This question does not have a single answer, there can be many different problems. You do not list what you tried to exclude.
Also, can you paste the actual error without removing technical details? You can omit the stack trace. Can you add the line doing the connection?
As a first step, since the message says "network host unreachable" you should check that your phone can access your computer at all. Try navigating to http://192.168.XX.XX:8090 with your phone's browser, if that succeeds probably there's a problem in your app (the code, permissions, etc.).
If that fails you have more subquestions, which are general network troubleshooting questions:
- can the phone indeed reach the IP of your PC? If yes:
- does the webserver listen for outside connections? If yes:
- what is blocking the connection between phone and webserver? Is there any firewall involved? For this one, understanding how networking works "inside", that is, which nodes are supposed to relay the packets to the other side, will tell you which nodes might not be doing their job. (With a USB connection, that's the two hosts themselves).
Maybe you did some of the experiments and excluded some of these hypotheses. If so, it would be helpful to describe those experiments. If you are not doing that, and you want to learn to troubleshoot better, you might look into the scientific method for troubleshooting (Google "troubleshooting scientific method", there are several essays which look helpful, like this).
It is probably your manifest file is corrupted. Even I was getting same error; while I checked my logcat closely, I found that some permissions were 'not recognized'.
So, check your manifest permissions, or re-write them, it will solve your problem.

How can I get my android emulator use my computer's VPN interface?

My company requires VPN to connect to our dev systems and for the first time I'm trying to work on an android app from home. Turns out the emulator doesn't want to use the VPN interface so even though I have connectivity to our dev systems on my VPN-connected laptop the emulator that's running on it does not.
I have thought of 3 solutions to this:
run a VPN client on the emulator, but I was hoping for a simpler solution than that
setting up a proxy server on my local machine
forwarding a port on my local machine
2 and 3 can probably work, but I'd still like to know if there is an easy way to get the emulator to use the VPN interface without a workaround.
I'm running OS X 10.7 and I've already tried adjusting the interface priority order with network>>set service order.
I suppose I can dust off the old dell and try it there, but I would expect the same results.
First start your vpn connection and then restart the emulator, now the emulator should use the host vpn connection.
it's mostly because of the DNS issue, according to the android doc:
At startup, the emulator reads the list of DNS servers that your system is currently using. It then stores the IP addresses of up to four servers on this list and sets up aliases to them on the emulated addresses 10.0.2.3, 10.0.2.4, 10.0.2.5 and 10.0.2.6 as needed.
I encountered this issue and tried something on dns settings but I could not solve it. As #machado said in the comment section below you should boot the emulator via "Cold Boot Now" option. I hope this helps.
What I do on my mac is just make sure 'send all traffic over vpn' is checked.
You'll find this setting after you click advanced while having your vpn connection selected in network preferences.
Works well for my situation, but may not depending on the type of VPN you're connecting to.
I had the same issue and solved it by connecting to cisco vpn after the android emulator has started and connected to the internet.
Works for me in windows 7
I setup a vpn connection on Windows. Then I started the emulator. The emulator and everything on my pc started to use that vpn connection.

Communication between Android Emulators

I wanted to know if it is possible the comunication between two Android Emulators started on two different machines networked.
For example
- Emulator A run on machine M1
- Emulator B run on machine M2
Can A and B exchange messages?
If yes, what ip address do I use?
Thank you very much
Deborah
You might know this already. As of android-sdk-tools_r7 it should at least be possible to connect two emulators to each other. Whether is works between physical machines is not something I know. It might be possible to set up masquerading between the two hosts for this specific broadcast.
From the android commit
Enable interconnection of emulators
This patch adds a -shared-net-id option to the emulator which
joins the emulator in a shared network.
If the option is given the emulator is started with an additional
network interface bound to a multicast socket. This multicast socket
emulates a network hub, interconnecting emulators.
If the -shared-net-id option is not given, nothing changes.
To connect two emulators, use the -shared-net-id <number> command line option when starting the emulator. They will then directly share everything sent to or read from ip 10.1.2.<number> on the emulator.
Another approach would be to enable port forwarding between the emulators using adb, and then set up masquerading for those ports on the networked machines.
I'm not really sure that either of these solutions match the use case that you're asking after. If not, adding more details to the original question might help. :)
Disclaimer: I have not tried the first approach, and the second I've only used to make sure that an emulator could bypass a nasty corporate firewall and HTTP proxy so that we could test the android browser. The principle should be sound though.
Update:
Nope, I played around with it a whole lot and found no nice solutions. I am not good enough at iptables to set up a valid tunnel that way that works for the server end.
Regards,
Mikael
An emulator normally has outbound access to the development machine's LAN or internet connection, so the problem is on the inbound side.
You can use an emulator or ADB port forward to send traffic into the emulator, but possibly only locally originating traffic on the development machine's loopback interface, and not external traffic. If that is indeed the case, the simplest thing would probably be to write or configure a port forwarder that listens on the development machine's external interface and forwards to the port that is forwarded into the emulator.

Categories

Resources