Current location - Quotes Website - Signature design - Turn on usb debugging with adb command.
Turn on usb debugging with adb command.
Enabling USB debugging for Android phones is very important for using pea clip and debugging programs. Let's talk about how to automatically open USB debugging with code. First, analyze the related source code of USB debugging.

Find the code about USB Debug Enable in packages/apps/settings/src/com/Android/settings/development settings.java:

【java】? View the plain? copy

Settings. secure . putint(getContentResolver(),? Settings. Secure.ADB_ENABLED,? 0? );

In this file, the values will be saved to the settings database according to the user settings. Other places will take corresponding actions according to the dynamic changes of their values.

After searching, it is found in FrameWorks/base/services/Java/com/Android/server/notificationmanagerservice.java that this value is used to judge whether to notify in the status bar. The code is as follows:

Other places will take corresponding actions according to the dynamic change of its value, such as status bar message prompt.

【java】? View the plain? copy

Invalid? Observation ()? {

Content parser? Parser? =? m context . getcontentresolver();

Resolver. registercontentserver (setting. Secure.getUriFor(

Settings. Secure.ADB_ENABLED),? Fake? ,? This? );

update();

}

@Overridepublicvoid? onChange(? Bull? Self-change)? {

update();

}

publicvoid? update()? {

Content parser? Parser? =? m context . getcontentresolver();

Madben Brad? =? Settings. Secure.getInt (parser,

Settings. Secure.ADB_ENABLED,? 0? )? ! =? 0? ;

updateAdbNotification();

}

By analyzing the code, we can use the program to automatically open usb debugging.

【java】? View the plain? copy

Bull? enableAdb? =? (settings. secure . getint(getContentResolver(),? Settings. Secure.ADB_ENABLED,? 0)? & gt? 0); ?

What if? (! enableAdb)? {?

Settings. secure . putint(getContentResolver(),? Settings. Secure.ADB_ENABLED,? 1); ?

}?

Run it immediately, and an exception will appear. You can see that there is no permission through Logcat. Android. Permission Write _ secure _ settings is not allowed to be executed by ordinary programs, and must be signed or put into the system.

/system /app.

(1), add two permissions to AndroidManifest.xml

[html]? View the plain? copy

& lt permission? Android:name = " Android . permission . write _ SETTINGS " & gt; & lt/uses-permission & gt;

& lt permission? Android:name = " Android . permission . write _ SECURE _ SETTINGS "? /& gt; ?

You can push the program to /system/app, add 0644 permission to this apk, and restart the phone, and you will find that usb debugging is automatically started.