This article was reproduced from: http://www.wxtlife.com/2015/11/24/Android-set-adb-status/
for the first time to get my latest articles, please follow the public number: technical Agents
In the overall system development, the general system default ADB development is open, then in the external release of the system, certainly do not want to open the ADB by default, but in the process of development, it is certainly hoped to be able to open the ADB through some kind of operation, easy to debug, which need to make a switch in a part of the system. So this article is about how to add an adb switch to the system.
-
- There is a USB DEUBG switch in the system, this switch is open for USB debugging to ADB but by default the developer mode can be opened.
-
- The ADB startup will definitely start a
adbd service, so you can shut down the ADB service by killing it manually. Of course this is the ADBD after the boot can do so, but still directly default does not start the service bar, when needed to open it.
The Open adbd service is actually started in the file in the system boot, there are a init.rc lot of calls start adbd or restart adbd this part is the Android boot process zygote (fertilized eggs) started, which involves the entire Android startup process, and init.rc The definition and use of the document can be viewed online.
The first thing to do is to comment out all the parts of the system start adbd and restart adbd not use the system default boot mode. Usually in the init.rc file, in the use find . -iname "init*.rc" | xargs grep "adbd" of the system all about the ADBD service to search out, to avoid missing.
Then look at init.rc how the ADBD service in the file is defined:
| 123456 |
# ADBD is controlled via property triggers in init.<platform>.usb.rcservice ADBD/SBIN/ADBD class core so Cket ADBD Stream 660 system system disabled Seclabel U:R:ADBD:S0 |
In fact it is defined sbin/adbd as a file for the ADBD service, which defines the service in the init.rc file, then we use init.rc the trigger in the file to control the opening and closing of the ADBD service. Define a property persist.sys.adbd.on to mark the switch state of ADB and define the trigger content as follows:
| 12345 |
On Property:persist.sys.adbd.on=1 start adbd on property:persist.sys.adbd.on=0 stop ADBD |
It is also possible to see the literal meaning of a change in Init.rc when property system Properties persist.sys.adbd.on change. And when the value of the property is 1, it is called, when it is 0, it is start adbd called stop adbd , because ADBD is a service that can be controlled by start and stop, so the state of ADB can be switched by setting the property attribute in the program.
The general realization process is this, eloquence literary talent, not good expression, forgive me.
There is a need to understand some of the Android boot process, as well as the init file definition.
Tip: System permissions are required to set system properties, so this is only useful if your own development system is applied.
About permission-related articles reference http://blog.csdn.net/a345017062/article/details/6254402
Android system settings Android adb switch method "turn"