本文转载自: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 来设置。您可以看到类似如代码:

  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 中确认,

  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 中,您也可以
看到类似的代码如:

  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

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

2. 确定默认的usb功能

build/tools/post_process_props.py

  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. # If ro.debuggable is 1, then enable adb on USB by default
  9. # (this is for userdebug builds)
  10. if prop.get("ro.build.type") == "eng":
  11. val = prop.get("persist.sys.usb.config").strip('\r\n')
  12. if val == "":
  13. val = "adb"
  14. else:
  15. val = val + ",adb"
  16. prop.put("persist.sys.usb.config", val)
  17. # UsbDeviceManager expects a value here.  If it doesn't get it, it will
  18. # default to "adb". That might not the right policy there, but it's better
  19. # to be explicit.
  20. if not prop.get("persist.sys.usb.config"):
  21. prop.put("persist.sys.usb.config", "none");
  22. # Put the modifications that you need to make into the /system/build.prop into this
  23. # function. The prop object has get(name) and put(name,value) methods.
  24. def mangle_default_prop(prop):
  25. # If ro.debuggable is 1, then enable adb on USB by default
  26. # (this is for userdebug builds)
  27. if prop.get("ro.debuggable") == "1":
  28. val = prop.get("persist.sys.usb.config")
  29. if val == "":
  30. val = "adb"
  31. else:
  32. val = val + ",adb"
  33. prop.put("persist.sys.usb.config", val)
  34. # UsbDeviceManager expects a value here.  If it doesn't get it, it will
  35. # default to "adb". That might not the right policy there, but it's better
  36. # to be explicit.
  37. if not prop.get("persist.sys.usb.config"):
  38. prop.put("persist.sys.usb.config", "none");

[FAQ04776]如何默认打开user版本 debug 选项, 默认打开adb 连接【转】的更多相关文章

  1. ionic新入坑-环境搭建+新建项目+打开低版本项目处理

    是的.我又双叒叕入新坑了.想我大学的时候web-app刚火起来.还帮忙做了我们学校医务室系统的web-app页面部分呢.时间太紧最后也没出个完整的版本.那时候只是用H5简单做了web部分.是想着用ph ...

  2. maven 修改默认的JDK版本

    maven jdk 版本配置 maven 默认使用的 jdk 版本 新建一个 maven 项目,如下 : 项目左下方出现一个感叹号,JRE 显示的是 1.5 版本.解决方式有两种,一种是配置 pom. ...

  3. Android 5.0 版本 USB 调试模式打开方法

    Android 4.2 版本 USB 调试模式打开方法 1. 进入“设置”页面,点击“关于平板电脑”.见下图红色方框.   2. 疯狂点击“版本号”,见下图红色方框,直到出现“您现在处于开发者模式!” ...

  4. 修改linux下默认的python版本

    首先在终端输入:python --verison 查看本机默认采用的python 版本 接着进入/usr/local/lib 目录查看当前系统中安装了多少个python版本 如果只有一个,就安装你需要 ...

  5. 转:使用vs2013打开VS2015的工程文件的解决方案(适用于大多数vs低版本打开高版本)

    http://www.cnblogs.com/WayneLiu/p/5060277.html 前言:重装系统前我使用的是vs2015(有点装*),由于使用2015实在在班上太另类了, 导致我想在其他同 ...

  6. winform窗口打开后文本框的默认焦点设置

    原文:http://blog.csdn.net/kongwei521/article/details/6871411 winform窗口打开后文本框的默认焦点设置,进入窗口后默认聚焦到某个文本框,两种 ...

  7. (转)Windows Server 2008 默认"照片库查看器" 无法打开图片, 只能用画图程序打开

    1.解决[启用Win2008照片查看器] Win2008 中放了一些图片,本来以为可以象Win7那样直接用“照片查看器”打开,可是Win2008默认竟然是用“画图”打开的,非常不方便. 再仔细一看,“ ...

  8. 低版本的 opencv库的 vs2010 打开 高版本opencv

    打开track.vcxproj文件, 注释掉跟版本有关的行就可. 本例子中,当用双击.sln用vs2010打开高版本的opencv项目时,会出现错误, 并且会有错误信息提示,双击该错误信息,就会打开该 ...

  9. VS2010打开旧版本MFC工程无对话框

    解决方案: 左侧有个"资源视图",打开,里面就能找得到对话框,如果没有资源视图,就在菜单的视图选项里打开资源视图!

随机推荐

  1. poj 3304 判断是否存在一条直线与所有线段相交

    Segments Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8579   Accepted: 2608 Descript ...

  2. CSS参数介绍

    原文发布时间为:2008-08-03 -- 来源于本人的百度文章 [由搬家工具导入] 行高       line-height: 16px 宽度       (具体位置)-width: 16px 文字 ...

  3. 解析XML字符串为json对象

    var overtime='<?xml version="1.0" encoding="UTF-8"?><response><co ...

  4. ci框架——分页

    1:在models里面写一个模型:page_model.php class Page_model extends CI_Model{ function page($tablename,$per_num ...

  5. Day 13 Python 一之helloworld

    直接肝程序吧! """ # 作业六:用户登录测试(三次机会) count = 1 while count <= 3: user = input('请输入用户名: ' ...

  6. Codeforces Round #511 (Div. 2) C. Enlarge GCD

    题目链接 题目就是找每个数的最小素因子,然后递归除,本来没啥问题,结果今天又学习了个新坑点. 我交了题后,疯狂CE,我以为爆内存,结果是,我对全局数组赋值, 如果直接赋值,会直接在exe内产生内存,否 ...

  7. BZOJ——1614: [Usaco2007 Jan]Telephone Lines架设电话线

    Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1930  Solved: 823[Submit][Status][Discuss] Description ...

  8. linux fork()

    一. linux下C语言可以用fork()建立子进程.fork函数返回两个值,对于子进程,返回0; 父进程,返回子进程ID. 所以用if(fork()==0)      {子进程执行的代码段:}els ...

  9. J粒子发现40周年-丁肇中中科院讲座笔记

    J粒子发现40周年-丁肇中中科院讲座笔记 华清远见2014-10-18   北京海淀区  张俊浩 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveXVuZm ...

  10. 梯度下降和EM算法,kmeans的em推导

    I. 牛顿迭代法给定一个复杂的非线性函数f(x),希望求它的最小值,我们一般可以这样做,假定它足够光滑,那么它的最小值也就是它的极小值点,满足f′(x0)=0,然后可以转化为求方程f′(x)=0的根了 ...