[MTK]如何默认打开user debug 选项

http://blog.csdn.net/duanlove/article/details/9670765

[Description]
如何默认打开user debug 选项
 
[Keyword]
user debug root
 
[Solution]
1. 在android 4.0 之前,这个设置是在frameworks/base/service/..../SystemServer.java 里面设置会根据system property 的persist.service.adb.enable 来设置。您可以看到类似如代码:
        // make sure the ADB_ENABLED setting value matches the secure property value
        Settings.Secure.putInt(mContentResolver, Settings.Secure.ADB_ENABLED,
                "1".equals(SystemProperties.get("persist.service.adb.enable")) ? 1 : 0);
        // register observer to listen for settings changes
        mContentResolver.registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.ADB_ENABLED),
                false, new AdbSettingsObserver());
    
 而这个persist.service.adb.enable 默认是放在在default.prop 中,在编译的时候在build/core/main.mk 中确认,
 ifeq (true,$(strip $(enable_target_debugging)))
   # Target is more debuggable and adbd is on by default
   ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=1 persist.service.adb.enable=1
   # Include the debugging/testing OTA keys in this build.
   INCLUDE_TEST_OTA_KEYS := true
 else # !enable_target_debugging
   # Target is less debuggable and adbd is off by default
   ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=0 persist.service.adb.enable=0
 endif # !enable_target_debugging
 您需要将: ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=0 persist.service.adb.enable=0  改成
 ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=1 persist.service.adb.enable=1
    
2. 在android 4.0 之后,因为adb 的控制,统一使用了persist.sys.usb.config 来控制,于是对应的设置点也改到了frameworks/base/service/...../usb/UsbDeviceManager.java 中,您也可以看到类似的代码如:
public  UsbHandler(Looper looper) {
        // persist.sys.usb.config should never be unset.  But if it is, set it to "adb"
        // so we have a chance of debugging what happened.
         mDefaultFunctions = SystemProperties.get("persist.sys.usb.config", "adb");
        // sanity check the sys.usb.config system property
        // this may be necessary if we crashed while switching USB configurations
        String config = SystemProperties.get("sys.usb.config", "none");
        if (!config.equals(mDefaultFunctions)) {
            Slog.w(TAG, "resetting config to persistent property: " + mDefaultFunctions);
            SystemProperties.set("sys.usb.config", mDefaultFunctions);
        }
        mCurrentFunctions = mDefaultFunctions;
        String state = FileUtils.readTextFile(new File(STATE_PATH), 0, null).trim();
        updateState(state);
        mAdbEnabled = containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_ADB);
public void  systemReady() {
 // make sure the ADB_ENABLED setting value matches the current state
    Settings.Secure.putInt(mContentResolver, Settings.Secure.ADB_ENABLED, mAdbEnabled ? 1 : 0);
 
而这个persist.sys.usb.config 中adb 的配置是在alps/build/tools/post_process_props.py 中根据ro.debuggable = 1 or 0 来设置,1 就是开启adb, 0 即关闭adb debug. 而这个ro.debuggable 也是在alps/build/core/main.mk 中设置,和2.3 修改类似
不过您这样打开之后,对于user 版本adb shell 开启的还是shell 权限,而不是root 权限,如果您需要root 权限,需要再改一下system/core/adb/adb.c 里面的should_drop_privileges() 这个函数,在#ifndef ALLOW_ADBD_ROOT 时return 0; 而不是return 1; 即可。


----------------------------------------------------------------------------------------------------------------------------------------


今天需要编译一个android4.2.2 的user版本来测试;

android编译相关的东西在源码的build目录下,全编前需要执行

. build/envsetup.sh

执行上面的shell脚本会include一些其他目录下的shell脚本,以及声明一些命令函数,比如说接下来执行的choosecombo命令;

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
function choosecombo()
{
    choosetype $1
    echo
    echo
    chooseproduct $2
    echo
    echo
    choosevariant $3
    echo
    set_stuff_for_environment
    printconfig
}

choosecombo release msm8960 eng;

release表示的是Build type;(choose type) type有release和debug两个选项

msm8960表示的是product;(choose product) product有genric和msm8960,当然product根据项目不同是有不同选项的;

eng表示的是版本类型;(choose variant) variant有user,userdebug,eng三个选项

通过adb shell中执行getprop persist.sys.usb.config,可以看到系统usb的相关选项,persist.sys.usb.config显示的就是当前系统关于usb选项的系统配置;

diag,serial_smd,serial_tty,rmnet_bam,mass_storage,adb

全编脚本中make命令会调用build/core/**main.mk**,在里面可以看到一段关于debuggable的编译选项,赋值ADDITIONAL_DEFAULT_PROPERTIES;

1
2
3
4
5
6
7
8
9
ifeq (true,$(strip $(enable_target_debugging)))
  # Target is more debuggable and adbd is on by default
  ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=1
  # Include the debugging/testing OTA keys in this build.
  INCLUDE_TEST_OTA_KEYS := true
else # !enable_target_debugging
  # Target is less debuggable and adbd is off by default
  ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=0
endif # !enable_target_debugging

并且

1
include $(BUILD_SYSTEM)/Makefile

在build/core/Makefile中的

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# default.prop
INSTALLED_DEFAULT_PROP_TARGET := $(TARGET_ROOT_OUT)/default.prop
ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_DEFAULT_PROP_TARGET)
ADDITIONAL_DEFAULT_PROPERTIES := 
    $(call collapse-pairs, $(ADDITIONAL_DEFAULT_PROPERTIES))
ADDITIONAL_DEFAULT_PROPERTIES += 
    $(call collapse-pairs, $(PRODUCT_DEFAULT_PROPERTY_OVERRIDES))
ADDITIONAL_DEFAULT_PROPERTIES := $(call uniq-pairs-by-first-component, 
    $(ADDITIONAL_DEFAULT_PROPERTIES),=)
$(INSTALLED_DEFAULT_PROP_TARGET):
    @echo Target buildinfo: $@
    @mkdir -p $(dir $@)
    $(hide) echo "#" > $@; 
            echo "# ADDITIONAL_DEFAULT_PROPERTIES" >> $@; 
            echo "#" >> $@;
    $(hide) $(foreach line,$(ADDITIONAL_DEFAULT_PROPERTIES), 
        echo "$(line)" >> $@;)
    build/tools/post_process_props.py $@

执行**post_process_props.py**脚本文件,**post_process_props.py会根据main.mk中的ro.debuggable指定的值来生成default.prop的persist.sys.usb.config;**
**

**


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# If ro.debuggable is 1, then enable adb on USB by default
  # (this is for userdebug builds)
  if prop.get("ro.debuggable") == "1":
    val = prop.get("persist.sys.usb.config")
    if val == "":
      val = "adb"
    else:
      val = val + ",adb"
    prop.put("persist.sys.usb.config", val)
  # UsbDeviceManager expects a value here.  If it doesn't get it, it will
  # default to "adb". That might not the right policy there, but it's better
  # to be explicit.
  if not prop.get("persist.sys.usb.config"):
    prop.put("persist.sys.usb.config", "none");

如果想要编译user版本的时候打开adb,修改

1
prop.put("persist.sys.usb.config", "none");

1
prop.put("persist.sys.usb.config", "adb");

即可;

eng版本的default.prop

1
2
3
4
5
6
7
#
# ADDITIONAL_DEFAULT_PROPERTIES
#
ro.secure=0
ro.allow.mock.location=1
ro.debuggable=1
persist.sys.usb.config=adb

默认user版本default.prop

**

**

1
2
3
4
5
6
7
#
# ADDITIONAL_DEFAULT_PROPERTIES
#
ro.secure=1
ro.allow.mock.location=1
ro.debuggable=0
persist.sys.usb.config=none

以上结论经过自己验证可行,如有错误之处,希望能够指出;

另外,针对user版本上无法进行usb debug,可以在settings-About phone-Build number上点击N次,然后就会提示“No need,you are already a developer”,这时,settings中

就会出现Develper options选项,进去就可以打开usb debug了;

声明:eoe文章著作权属于作者,受法律保护,转载时请务必以超链接形式附带如下信息

原文作者: cnhua5

原文地址: http://my.eoe.cn/cnhua5/archive/19725.html




你可能感兴趣的:(android,system)