Android Data Recovery
[Tech] Use Android Code to Enable USB Debugging
-- Thursday, June 23, 2016
Firstly, let’s have a look at the analysis of the code of USB debugging. In the resource code "packages/apps/Settings/src/com/android /settings/DevelopmentSettings.java", you can find the code related to USB Debugging:
In this file, it will save the values in the Settings database according to the user settings. In other places of the settings will perform a corresponding action according to the dynamic change of the values.
After searching, the value in "frameworks/base/services/java/com/android/server/NotificationManagerService.java" is used to judge whether notification should be shown in the status bar. The code is as below:
With the code analysis, we can get the USB debugging automatically turned on relying on the program.
When finished the above steps, you still cannot get USB debugging enabled yet. With Logcat, you can find that the code written in it still have no right to enable USB debugging, because "android.permission.WRITE_SECURE_SETTINGS" disallows common program to perform, and there must be a system signature or being put in /system/app directory.
You can add two permissions in "AndroidManifest.xml" like follows:
After pushing the Java program code in /system/app directory and add the 0644 permission in the .apk, you can restart your phone. Now, the USB debugging is automatically enabled.