zoukankan      html  css  js  c++  java
  • [FAQ04776]如何默认打开user版本 debug 选项, 默认打开adb 连接【转】

    本文转载自:http://blog.csdn.net/thinkinwm/article/details/24865933

    Description]

    如何默认打开user 版本的USB debug 选项, 默认打开adb 连接

    [Keyword]

    量产版本 user usb debug root adb 连接

    [Solution]
    1. 在android 4.0 之前,这个设置是在frameworks/base/service/..../SystemServer.java 里面
    设置会根据system property 的persist.service.adb.enable 来设置。您可以看到类似如代码:

    [java] view plain copy
     
    1. // make sure the ADB_ENABLED setting value matches the secure property value  
    2. Settings.Secure.putInt(mContentResolver, Settings.Secure.ADB_ENABLED,  
    3.         "1".equals(SystemProperties.get("persist.service.adb.enable")) ? 1 : 0);  
    4. // register observer to listen for settings changes  
    5. mContentResolver.registerContentObserver(Settings.Secure.getUriFor(Settings.Secu  
    6. ENABLED),false, new AdbSettingsObserver());  


       
    而这个persist.service.adb.enable 默认是放在在default.prop 中,在编译的时候在
    build/core/main.mk 中确认,

    [java] view plain copy
     
    1. ifeq (true,$(strip $(enable_target_debugging)))  
    2.   # Target is more debuggable and adbd is on by default  
    3.   ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=1 persist.service.adb.enable=1  
    4.   # Include the debugging/testing OTA keys in this build.  
    5.   INCLUDE_TEST_OTA_KEYS := true  
    6. else # !enable_target_debugging  
    7.   # Target is less debuggable and adbd is off by default  
    8.   ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=0 persist.service.adb.enable=0  
    9. 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 中,您也可以
    看到类似的代码如:

    [java] view plain copy
     
    1. public  UsbHandler(Looper looper) {  
    2.        // persist.sys.usb.config should never be unset.  But if it is, set it to "adb"  
    3.        // so we have a chance of debugging what happened.  
    4.         mDefaultFunctions = SystemProperties.get("persist.sys.usb.config", "adb");  
    5.        // sanity check the sys.usb.config system property  
    6.        // this may be necessary if we crashed while switching USB configurations  
    7.        String config = SystemProperties.get("sys.usb.config", "none");  
    8.        if (!config.equals(mDefaultFunctions)) {  
    9.            Slog.w(TAG, "resetting config to persistent property: " + mDefaultFunctions);  
    10.            SystemProperties.set("sys.usb.config", mDefaultFunctions);  
    11.        }  
    12.        mCurrentFunctions = mDefaultFunctions;  
    13.        String state = FileUtils.readTextFile(new File(STATE_PATH), 0, null).trim();  
    14.        updateState(state);  
    15.        mAdbEnabled = containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_ADB);  
    16. public void  systemReady() {  
    17. // make sure the ADB_ENABLED setting value matches the current state  
    18.    Settings.Secure.putInt(mContentResolver, Settings.Secure.ADB_ENABLED, mAdbEnabled ?  
    19. 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; 即可。

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

    1. 根据编译命令确定ro.debuggable

    build/core/main.mk

    [java] view plain copy
     
    1. ## user/userdebug ##  
    2.   
    3. user_variant := $(filter user userdebug,$(TARGET_BUILD_VARIANT))  
    4. enable_target_debugging := true  
    5. tags_to_install :=  
    6. ifneq (,$(user_variant))  
    7.   # Target is secure in user builds.  
    8.   ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1  
    9.   
    10.   ifeq ($(user_variant),userdebug)  
    11.     # Pick up some extra useful tools  
    12.     tags_to_install += debug  
    13.   
    14.     # Enable Dalvik lock contention logging for userdebug builds.  
    15.     ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.lockprof.threshold=500  
    16.   else  
    17.     # Disable debugging in plain user builds.  
    18.     enable_target_debugging :=  
    19.   endif  
    20.   
    21.   # enable dex pre-optimization for all TARGET projects in default to   
    22.   # speed up device first boot-up  
    23.   #add by yanqi.liu for costomization @{  
    24.   ifneq ($(JRD_IS_GOAL_PERSO),true)  
    25.      WITH_DEXPREOPT := true  
    26.   endif  
    27. #}  
    28.   # Turn on Dalvik preoptimization for user builds, but only if not  
    29.   # explicitly disabled and the build is running on Linux (since host  
    30.   # Dalvik isn't built for non-Linux hosts).  
    31.   ifneq (true,$(DISABLE_DEXPREOPT))  
    32.     ifeq ($(user_variant),user)  
    33.       ifeq ($(HOST_OS),linux)  
    34.         ifneq ($(JRD_IS_GOAL_PERSO),true)  
    35.            WITH_DEXPREOPT := true  
    36.         endif  
    37.       endif  
    38.     endif  
    39.   endif  
    40.   
    41.   # Disallow mock locations by default for user builds  
    42.   ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=0  
    43.   
    44. else # !user_variant  
    45.   # Turn on checkjni for non-user builds.  
    46.   # Kirby: turn off it temporarily to gain performance {  
    47.   # ADDITIONAL_BUILD_PROPERTIES += ro.kernel.android.checkjni=1  
    48. #  ADDITIONAL_BUILD_PROPERTIES += ro.kernel.android.checkjni=0  
    49.   # } Kirby  
    50.   # Set device insecure for non-user builds.  
    51.   ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=0  
    52.   # Allow mock locations by default for non user builds  
    53.   ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=1  
    54. endif # !user_variant  
    55.   
    56.   
    57. # always enable aed  
    58. ADDITIONAL_DEFAULT_PROPERTIES += persist.mtk.aee.aed=on  
    59.   
    60. # Turn on Jazz AOT by default if not explicitly disabled and the build  
    61. # is running on Linux (since host Dalvik isn't built for non-Linux hosts).  
    62. ifneq (true,$(DISABLE_JAZZ))  
    63.   ifeq ($(strip $(MTK_JAZZ)),yes)  
    64.     ifeq ($(HOST_OS),linux)  
    65.       # Build host dalvikvm which Jazz AOT relies on.  
    66.       WITH_HOST_DALVIK := true  
    67.       WITH_JAZZ := true  
    68.     endif  
    69.   endif  
    70. endif  
    71.   
    72. ifeq (true,$(strip $(enable_target_debugging)))  
    73.   # Target is more debuggable and adbd is on by default  
    74.   ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=1  
    75.   ADDITIONAL_DEFAULT_PROPERTIES += ro.adb.secure=0  
    76.   # Include the debugging/testing OTA keys in this build.  
    77.   INCLUDE_TEST_OTA_KEYS := true  
    78. else # !enable_target_debugging  
    79.   # Target is less debuggable and adbd is off by default  
    80.   ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=0  
    81.   ADDITIONAL_DEFAULT_PROPERTIES += ro.adb.secure=1  
    82. endif # !enable_target_debugging  


    2. 确定默认的usb功能

    build/tools/post_process_props.py

    [java] view plain copy
     
    1. # Put the modifications that you need to make into the /system/build.prop into this  
    2. # function. The prop object has get(name) and put(name,value) methods.  
    3. def mangle_build_prop(prop):  
    4.   #pass  
    5.   #If ro.mmitest is true, then disable MTP, add mass_storage for default  
    6.   if prop.get("ro.mmitest") == "true":  
    7.     prop.put("persist.sys.usb.config", "mass_storage")  
    8.   
    9.   # If ro.debuggable is 1, then enable adb on USB by default  
    10.   # (this is for userdebug builds)  
    11.   if prop.get("ro.build.type") == "eng":  
    12.     val = prop.get("persist.sys.usb.config").strip(' ')  
    13.     if val == "":  
    14.       val = "adb"  
    15.     else:  
    16.       val = val + ",adb"  
    17.     prop.put("persist.sys.usb.config", val)  
    18.   # UsbDeviceManager expects a value here.  If it doesn't get it, it will  
    19.   # default to "adb". That might not the right policy there, but it's better  
    20.   # to be explicit.  
    21.   if not prop.get("persist.sys.usb.config"):  
    22.     prop.put("persist.sys.usb.config", "none");  
    23.   
    24.   
    25. # Put the modifications that you need to make into the /system/build.prop into this  
    26. # function. The prop object has get(name) and put(name,value) methods.  
    27. def mangle_default_prop(prop):  
    28.   # If ro.debuggable is 1, then enable adb on USB by default  
    29.   # (this is for userdebug builds)  
    30.   if prop.get("ro.debuggable") == "1":  
    31.     val = prop.get("persist.sys.usb.config")  
    32.     if val == "":  
    33.       val = "adb"  
    34.     else:  
    35.       val = val + ",adb"  
    36.     prop.put("persist.sys.usb.config", val)  
    37.   # UsbDeviceManager expects a value here.  If it doesn't get it, it will  
    38.   # default to "adb". That might not the right policy there, but it's better  
    39.   # to be explicit.  
    40.   if not prop.get("persist.sys.usb.config"):  
    41.     prop.put("persist.sys.usb.config", "none");  
  • 相关阅读:
    跨域问题注解解决
    跳出循环到指定位置
    idea model管理
    maven 取本地jar
    注解 元注解
    手动打jar包到maven
    sonar搭建
    jmockit、junit
    注解
    虚拟机指令
  • 原文地址:https://www.cnblogs.com/zzb-Dream-90Time/p/8167340.html
Copyright © 2011-2022 走看看