For a long time, I've been trying to find a way to break a breakpointDebug the Android system's own service, or bind type of service, such as I want to see how the Wifimanager inside the Getwifiapconfiguration function is implemented. See from code:
Public Wificonfiguration getwifiapconfiguration () {
try {
return Mservice.getwifiapconfiguration ();
} catch (RemoteException e) {
return null;
}
}
It calls directly to a Mservice variable. And this thing is a class that implements the Iwifimanager interface. I can't hit it with a breakpoint in my own application, although I can find the real implementation of it is in/frameworks/opt/net/wifi/service/java/com/android/server/wifi/ The Wifiserviceimpl.java. Today, thank you for this article: http://shine80769769.blog.163.com/blog/static/179148245201286114839627/finally found the breakpoint.How to debug the system service:1. First get a copy of the service source code. Like/frameworks/base/services/accessibility.2. In Android studio, import the project->create project from existing sources, then select the directory you want to add to the project root directory, select libraries, select modules, select SDK, Next. Now, the code is added, although the required class library is missing, the display is all wrong, but it doesn't matter, it doesn't affect debugging. 3. From the Run menu, select Edit Configurations to add a remote type ofDebug. The port number defaults to 5005, and you can change it to any value you want. such as can be set into 9999For a long time, I've been trying to find a way to break a breakpointDebug the Android system's own service, or bind type of service, such as I want to see how the Wifimanager inside the Getwifiapconfiguration function is implemented. See from code:
Public Wificonfiguration getwifiapconfiguration () {
try {
return Mservice.getwifiapconfiguration ();
} catch (RemoteException e) {
return null;
}
}
It calls directly to a Mservice variable. And this thing is a class that implements the Iwifimanager interface. I can't hit it with a breakpoint in my own application, although I can find the real implementation of it is in/frameworks/opt/net/wifi/service/java/com/android/server/wifi/ The Wifiserviceimpl.java. Today, thank you for this article: http://shine80769769.blog.163.com/blog/static/179148245201286114839627/finally found the breakpoint.How to debug the system service:1. First get a copy of the service source code. Like/frameworks/base/services/accessibility.2. In Android studio, import the project->create project from existing sources, then select the directory you want to add to the project root directory, select libraries, select modules, select SDK, Next. Now, the code is added, although the required class library is missing, the display is all wrong, but it doesn't matter, it doesn't affect debugging. 3. From the Run menu, select Edit Configurations to add a remote type ofDebug. The port number defaults to 5005, and you can change it to any value you want. such as can be set into 9999
4. Using adb shell PS | grep System_server Find the process where the accessibility service is located, here is 548system 548 195 1716200 121628 ffffffff b6e855d8 S system_ser Ver5. Also, use ADB jdwp to ensure that 548 is ready for debugging. This step is just for a look, not a necessity. 6. ADB forward tcp:9999 jdwp:548 This is the most critical step to turn the 9999 port of the machine to the JDWP 548 port of the remote machine. Here, 9999 is the port in the Debug configuration you just set up. Android Studio listens on the local port at the start of debugging. It is equivalent to listening on the jdwp 548 port. 7. Run this debug in Android Studio. When the service-related function is called, a breakpoint is found to be hit. If the app you're debugging isn't running yet, for example, it's your own app. You can choose it to debug your app in the developer options, or set it up to wait for the debugger after it runs through ADB shell am set-debug-app-w < package name >. Then it waits for the debugger to mount and you are doing the above action. OK, now basically all the system-level Java can debug breakpoints, it should be easier to look at the code.
"Original" How to use Android Studio breakpoint on Android with service or bind type service