How To Debug Framework In Android Studio

I choose API 17 because it doesn't have emulator rotate bug.

important steps:
0) make sure your android studio has downloaded sdk 17 with sources.
1) create any simple android project. make target sdk 17. min sdk 17 and compile with 17. build tools version doesn't matter. (File-> Project Structure-> app under Modules -> Flavor)
2) create emulator instance with api 17
3) open ddms, highlight system_process, that is it. (Tools -> Android - > Android Device Monitor)
4) for the simple project, config debug profiles: remote 8700, Run->Edit Configurations -> + -> Remote -> port 8700
5) from the simple project. launch debug with the profile. (now you will notice ddms's system_process has an special bug icon)
6) open file $(Android_Studio)/sdk/sources/android-17/com/android/server/am/ActivityStack.java in android studio, and then set a breakpoint at: realStartActivityLocked(…) func
7) IMPORTANT STEP: in android studio, from bottom pane, select Debugger -> Threads, WAIT threads are populated. because it means studio is connected with ddms now.
8) from emulator, launch any app/ or your simple app.
9) breakpoint will be intercepted, if not try restart the app in emulator again.

two refs:
http://apienthusiast.blogspot.com/2014/06/debugging-android-java-framework.html
http://source.android.com/source/using-eclipse.html
http://jmlinnik.blogspot.kr/2011/12/debug-built-in-applications-in-eclipse.html
https://software.intel.com/en-us/articles/android-system-level-javac-code-debugging

http://apienthusiast.blogspot.ca/2014/07/debugging-android-native-applications.html

adb

background

three components:

A client, which runs on your development machine. You can invoke a client from a shell by issuing an adb command. Other Android tools such as the ADT plugin and DDMS also create adb clients.

A server, which runs as a background process on your development machine. The server manages communication between the client and the adb daemon running on an emulator or device.

A daemon, which runs as a background process on each emulator or device instance.

When you start an adb client, the client first checks whether there is an adb server process already running. If there isn't, it starts the server process. When the server starts, it binds to local TCP port 5037 and listens for commands sent from adb clients-all adb clients use port 5037 to communicate with the adb server.

The server then sets up connections to all running emulator/device instances. It locates emulator/device instances by scanning odd-numbered ports in the range 5555 to 5585, the range used by emulators/devices. Where the server finds an adb daemon, it sets up a connection to that port. Note that each emulator/device instance acquires a pair of sequential ports - an even-numbered port for console connections and an odd-numbered port for adb connections. For example:

Emulator 1, console: 5554
Emulator 1, adb: 5555
Emulator 2, console: 5556
Emulator 2, adb: 5557 …

As shown, the emulator instance connected to adb on port 5555 is the same as the instance whose console listens on port 5554.

Once the server has set up connections to all emulator instances, you can use adb commands to control and access those instances. Because the server manages connections to emulator/device instances and handles commands from multiple adb clients, you can control any emulator/device instance from any client (or from a script).

++++
http://wiki.sdx-developers.com/android-debug-bridge-adb/

https://github.com/ACRA/acra/wiki/AdvancedUsage

http://codeseekah.com/2012/08/07/port-forwarding-an-android-local-port/

adb over wireless
1 Connect the Android-powered device via USB to your computer.
2 On Pc, enter adb tcpip 5555 at the command prompt.
3 on Pc Enter adb connect <device-ip-address>:5555 You should now be connected to the Android-powered device and can issue the usual adbcommands like adb logcat.
4 To set your device to listen on USB, enter adb usb.

https://sites.google.com/site/androidkernelwiki/howtos/use-adb-over-the-network
https://wiki.linaro.org/Platform/Android/SetupAdbOverTcp
http://stackoverflow.com/questions/2604727/how-can-i-connect-to-android-with-adb-over-tcp

adb connection over 3G
http://redkrieg.com/2010/10/11/adb-over-ssh-fun-with-port-forwards/

adb remote connection
http://rxwen.blogspot.com/2009/11/adb-for-remote-connections.html
http://www.41post.com/5003/programming/android-adb-remote-emulator-access

adb forward

http://home.nouwen.name/android/adb.html
http://bharathisubramanian.wordpress.com/2012/03/10/android-socket-communication-thru-adb/
http://www.codeproject.com/Articles/191930/Android-Usb-Port-Forwarding?fid=1625023&select=4779234&fr=26#xx0xx

1)android: nc -l 127.0.0.1 1112
2)pc: adb forward tcp:1111 tcp:1112
3)pc: nc 127.0.0.1 1111
now whatever string typed on target will appear on host and vice versa.

remote debug: https://software.intel.com/en-us/android/articles/remote-application-debug-on-android-os

1) android: gdbserver :1112 /system/bin/executable or gdbserver :1234 —attach pid
2) pc: adb forward tcp:1111 tcp:1112
3) pc: ./prebuilts/gcc/linux-x86/x86/i686-linux-android-4.6/bin/i686-linux-android-gdb
4) pc: (gdb) target remote :1234

https://github.com/rafalrusin/netcat/blob/master/src/netcat/NetCat.java
http://nettool.sourceforge.net/
http://examples.javacodegeeks.com/android/core/socket-core/android-socket-example/

http://www.jnchen.com/blog/2012/11/tunnelling-adb

netcat

1) terminal-1 on host 192.168.1.144: listening to listening mode to prepare tunnel remote side and waiting for clients.

cd /tmp
mknod backpipe
nc -l -p 8000 192.168.1.144 0<backpipe | nc -l -p 8500 192.168.1.144 | tee backpipe

2) terminal-2 on host 192.168.1.148: listening mode. to simulate a backend web server

cd /tmp
nc -l 192.168.1.148 8600

3) terminal-3 on host 192.168.1.148: client to client mode: , to bridge tunnel near backend side into the web server

cd /tmp
mknod backpipe2
nc 192.168.1.144 8500 0<backpipe2 | nc 192.168.1.148 8600 | tee backpipe2

4) terminal-4 on host 192.168.1.145: client to connect to the server at step 1. to simulate a client connects to the tunnel remote side.

cd /tmp
nc 192.168.1.144 8000
netcat-2.png

use my own DualListener

1) start my own DualListener on 192.168.1.144 that has Tunnel remote side and accepts client connections.

java -cp netcat.jar netcat.DualListener -app_port 8000 -tunnel_waiting_port 8500 192.168.1.144

it is waiting for application on port 8000 and also waiting tunnel establishing request on port 8500.

2) terminal-2 on host 192.168.1.148: listening mode. to simulate a backend web server

cd /tmp
nc -l 192.168.1.148 8600

or you can use my special Echo server program that echos everything it receives.

java -cp netcat.jar netcat.Echo -p 8600 192.168.148

3) terminal-3 on host 192.168.1.148: client to client mode, to bridge tunnel near backend side into the web server

cd /tmp
mknod backpipe2
nc 192.168.1.144 8500 0<backpipe2 | nc 192.168.1.148 8600 | tee backpipe2

or if you are using the special netcat:

java -cp netcat.jar netcat.NetCat -p 8500 -f 192.168.1.148:8600  192.168.1.144

4) terminal-4 on host 192.168.1.145 or anywhere: client to connect to the server at step 1. to simulate a client to connect to the tunnel remote side.

cd /tmp
nc 192.168.1.144 8000

Now whatever string typed on terminal 4 will appear on terminal 2; and vice versa(whatever string typed on terminal 2 will appear on terminal 4)

1)

pc-1:  adb logcat -v time -s LocalService:*  MainActivity.* MyActivity:* DualListener:* StreamTransferer:*

2)

pc-2:  python -m SimpleHTTPServer 8600 or  java -cp netcat.jar netcat.Echo -p 8600 192.168.148

3)

pc-1:  adb forward tcp:8499 tcp:8500

4) android: start AdbTunnel
5)

pc-1:  java -cp netcat.jar netcat.NetCat -p 8499 -f 192.168.1.148:8600  127.0.0.1

6) android: start netcat

http://developer.android.com/tools/devices/emulator.html#networkaddresses

Add a New Comment
or Sign in as Wikidot user
(will not be published)
- +
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License