在settings中,有一个控制是否允许远程调试的选项usb debugging,当这个开关为off的时候,无法使用adb,也不能把**当作ms-storage来使用。 java中能访问的设定保存在/data/data/com.android.providers.settings/databases/settings.db里面。
字段名字叫做 adb_enabled。用户操作settings来修改设定时,实际上就是改变这个字段。
android进程system server中起了一个线程在一直监视db的这个字段。
根据这个字段的值来修改system propertity,其实也就是修改linux的环境变量
persist.service.adb.enable
代码如下
- class ServerThread extends Thread {
- private static final String TAG = "SystemServer";
- private final static boolean INCLUDE_DEMO = false;
- private static final int LOG_BOOT_PROGRESS_SYSTEM_RUN = 3010;
- private ContentResolver mContentResolver;
- private class AdbSettingsObserver extends ContentObserver {
- public AdbSettingsObserver() {
- super(null);
- }
- @Override
- public void onChange(boolean selfChange) {
- boolean enableAdb = (Settings.Secure.getInt(mContentResolver,
- Settings.Secure.ADB_ENABLED, 0) > 0);
- // setting this secure property will start or stop adbd
- SystemProperties.set("persist.service.adb.enable", enableAdb ? "1" : "0");
- }
- }
在linux的启动配置文件init.rc中有这样的配置 - # adbd is controlled by the persist.service.adb.enable system property
- service adbd /sbin/adbd
- disabled
- # adbd on at boot in emulator
- on property:ro.kernel.qemu=1
- start adbd
- on property:persist.service.adb.enable=1
- start adbd
- on property:persist.service.adb.enable=0
- stop adbd
从这里我们可以看出来其实设定adb_enabled与否其实就是在控制是否启动adbd这个daemon。