Android default open adb debugging method analysis

android default open adb debugging method analysis

default open usb adb debugging

when using adb debugging android, each time access usb line, will prompt a confirmation to open usb Debugging the function window, sometimes we need to turn on the usb debugging function by default. Or no need to pop up a dialog box, it is directly enabled by default. This we need to analyze the process of adb.

adb certification process is as follows:


1. If we use the adb command on the PC side, we will generate a pair of keys in the current user directory, and the key is stored in it. Android directory, where adbkey is the private key and is the public key.

2. adb will send the public key ( to the android device to get the authentication and establish an adb connection.

3. android will judge according to the attribute, whether to authenticate, if it is 0, no authentication is required, and an adb connection is allowed. If it is 1, then key authentication is required.

4. If adb key authentication is required, compare the received with the local /data/misc/adb/adb_keys. If they are the same, it means that the device is allowed to connect to the adb. If it is not the same, a dialog box will pop up, prompting the user whether to allow the usb debugging function.


From the above process we can open the usb debugging function by default in the following three ways:

1. In /frameworks/base/packages/SystemUI/src/com/android /systemui/usb Modify this directory.

privatefinalActivity mActivity;
publicUsbDisconnectedReceiver(Activity activity){
mActivity = activity;
Publicvoid onReceive(Context content,Intent intent){
String action = intent.getAction();
Boolean connected = intent.getBooleanExtra(UsbManager.USB_CONNECTED,false);
//boolean connected = false;// directly close the dialog
//Direct confirmation is allowed to pass
Try {
IBinder b = ServiceManager.getService(USB_SERVICE);
IUsbManager service = IUsbManager.Stub.asInterface(b);
service.allowUsbDebugging(true, mKey);
} catch (Exception e) {
Log.e(TAG, "Unable to notify Usb service", e);

Directly allows the modification of the attribute by

2. Different android versions are modified differently. The main purpose is to make the final default.prop

3. We import the public key on the PC directly into the android key file /data/misc/adb/adb_keys, so that each time the authentication is passed, the authentication can be guaranteed, but change one. After the PC, you need to copy the previously authenticated key to the new PC, otherwise it will not be authenticated.