如何默认打开user版本 debug 选项,默认打开adb 连接 user版本如何打开root权限

\u5982\u4f55\u9ed8\u8ba4\u6253\u5f00user debug \u9009\u9879

[Description]
\u5982\u4f55\u9ed8\u8ba4\u6253\u5f00user debug \u9009\u9879

[Keyword]
user debug root

[Solution]
1. \u5728android 4.0 \u4e4b\u524d\uff0c\u8fd9\u4e2a\u8bbe\u7f6e\u662f\u5728frameworks/base/service/..../SystemServer.java \u91cc\u9762\u8bbe\u7f6e\u4f1a\u6839\u636esystem property \u7684persist.service.adb.enable \u6765\u8bbe\u7f6e\u3002\u60a8\u53ef\u4ee5\u770b\u5230\u7c7b\u4f3c\u5982\u4ee3\u7801\uff1a
// 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());

\u800c\u8fd9\u4e2apersist.service.adb.enable \u9ed8\u8ba4\u662f\u653e\u5728\u5728default.prop \u4e2d\uff0c\u5728\u7f16\u8bd1\u7684\u65f6\u5019\u5728build/core/main.mk \u4e2d\u786e\u8ba4,
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
\u60a8\u9700\u8981\u5c06: ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=0 persist.service.adb.enable=0 \u6539\u6210
ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=1 persist.service.adb.enable=1

2. \u5728android 4.0 \u4e4b\u540e\uff0c\u56e0\u4e3aadb \u7684\u63a7\u5236\uff0c\u7edf\u4e00\u4f7f\u7528\u4e86persist.sys.usb.config \u6765\u63a7\u5236\uff0c\u4e8e\u662f\u5bf9\u5e94\u7684\u8bbe\u7f6e\u70b9\u4e5f\u6539\u5230\u4e86frameworks/base/service/...../usb/UsbDeviceManager.java \u4e2d\uff0c\u60a8\u4e5f\u53ef\u4ee5\u770b\u5230\u7c7b\u4f3c\u7684\u4ee3\u7801\u5982\uff1a
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);

\u800c\u8fd9\u4e2apersist.sys.usb.config \u4e2dadb \u7684\u914d\u7f6e\u662f\u5728alps/build/tools/post_process_props.py \u4e2d\u6839\u636ero.debuggable = 1 or 0 \u6765\u8bbe\u7f6e\uff0c1 \u5c31\u662f\u5f00\u542fadb, 0 \u5373\u5173\u95edadb debug. \u800c\u8fd9\u4e2aro.debuggable \u4e5f\u662f\u5728alps/build/core/main.mk \u4e2d\u8bbe\u7f6e\uff0c\u548c2.3 \u4fee\u6539\u7c7b\u4f3c
\u4e0d\u8fc7\u60a8\u8fd9\u6837\u6253\u5f00\u4e4b\u540e\uff0c\u5bf9\u4e8euser \u7248\u672cadb shell \u5f00\u542f\u7684\u8fd8\u662fshell \u6743\u9650\uff0c\u800c\u4e0d\u662froot \u6743\u9650\uff0c\u5982\u679c\u60a8\u9700\u8981root \u6743\u9650\uff0c\u9700\u8981\u518d\u6539\u4e00\u4e0bsystem/core/adb/adb.c \u91cc\u9762\u7684should_drop_privileges() \u8fd9\u4e2a\u51fd\u6570\uff0c\u5728#ifndef ALLOW_ADBD_ROOT \u65f6return 0; \u800c\u4e0d\u662freturn 1; \u5373\u53ef\u3002

\u4f60\u53ef\u4ee5\u7528\u5e94\u7528\u5b9d\u7684Kingroot\u6765\u83b7\u53d6\u6743\u9650\u3002\u4f46\u662f\u83b7\u53d6\u6743\u9650\u53ef\u80fd\u5bf9\u4ee5\u540e\u7cfb\u7edf\u5347\u7ea7\u6709\u5f71\u54cd\u3002\u8981\u8c28\u614e\u64cd\u4f5c\u7684\u54e6\u3002
1. \u4f60\u53ef\u4ee5\u5728\u7535\u8111\u91cc\u9762\u4e0b\u8f7d\u4e2a\u5e94\u7528\u5b9d\u30022.\u628a\u624b\u673a\u8c03\u8282\u6210USB\u8fde\u63a5\u6a21\u5f0f\u30023.\u7528\u6570\u636e\u7ebf\u628a\u624b\u673a\u548c\u7535\u8111\u8fde\u63a5\u30024.\u627e\u5230\u5e94\u7528\u5b9d\u91cc\u9762\u5de5\u5177\u7bb1kingroot \u3002\u7136\u540e\u5b89\u88c5\u6b65\u9aa4\u64cd\u4f5c\u5c31\u597d\u4e86\u3002

  1. 在android 4.0 之前,这个设置是在frameworks/base/service/..../SystemServer.java 里面
  设置会根据system property 的persist.service.adb.enable 来设置。您可以看到类似如代码:
  [java] view plaincopy在CODE上查看代码片派生到我的代码片
  // 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.Secu
  ENABLED),false, new AdbSettingsObserver());

  
  而这个persist.service.adb.enable 默认是放在在default.prop 中,在编译的时候在
  build/core/main.mk 中确认,
  [java] view plaincopy在CODE上查看代码片派生到我的代码片
  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 中,您也可以
  看到类似的代码如:
  [java] view plaincopy在CODE上查看代码片派生到我的代码片
  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; 即可。

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

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

  build/core/main.mk

  [java] view plaincopy在CODE上查看代码片派生到我的代码片
  ## user/userdebug ##
  
  user_variant := $(filter user userdebug,$(TARGET_BUILD_VARIANT))
  enable_target_debugging := true
  tags_to_install :=
  ifneq (,$(user_variant))
  # Target is secure in user builds.
  ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1
  
  ifeq ($(user_variant),userdebug)
  # Pick up some extra useful tools
  tags_to_install += debug
  
  # Enable Dalvik lock contention logging for userdebug builds.
  ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.lockprof.threshold=500
  else
  # Disable debugging in plain user builds.
  enable_target_debugging :=
  endif
  
  # enable dex pre-optimization for all TARGET projects in default to
  # speed up device first boot-up
  #add by yanqi.liu for costomization @{
  ifneq ($(JRD_IS_GOAL_PERSO),true)
  WITH_DEXPREOPT := true
  endif
  #}
  # Turn on Dalvik preoptimization for user builds, but only if not
  # explicitly disabled and the build is running on Linux (since host
  # Dalvik isn't built for non-Linux hosts).
  ifneq (true,$(DISABLE_DEXPREOPT))
  ifeq ($(user_variant),user)
  ifeq ($(HOST_OS),linux)
  ifneq ($(JRD_IS_GOAL_PERSO),true)
  WITH_DEXPREOPT := true
  endif
  endif
  endif
  endif
  
  # Disallow mock locations by default for user builds
  ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=0
  
  else # !user_variant
  # Turn on checkjni for non-user builds.
  # Kirby: turn off it temporarily to gain performance {
  # ADDITIONAL_BUILD_PROPERTIES += ro.kernel.android.checkjni=1
  # ADDITIONAL_BUILD_PROPERTIES += ro.kernel.android.checkjni=0
  # } Kirby
  # Set device insecure for non-user builds.
  ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=0
  # Allow mock locations by default for non user builds
  ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=1
  endif # !user_variant
  
  
  # always enable aed
  ADDITIONAL_DEFAULT_PROPERTIES += persist.mtk.aee.aed=on
  
  # Turn on Jazz AOT by default if not explicitly disabled and the build
  # is running on Linux (since host Dalvik isn't built for non-Linux hosts).
  ifneq (true,$(DISABLE_JAZZ))
  ifeq ($(strip $(MTK_JAZZ)),yes)
  ifeq ($(HOST_OS),linux)
  # Build host dalvikvm which Jazz AOT relies on.
  WITH_HOST_DALVIK := true
  WITH_JAZZ := true
  endif
  endif
  endif
  
  ifeq (true,$(strip $(enable_target_debugging)))
  # Target is more debuggable and adbd is on by default
  ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=1
  ADDITIONAL_DEFAULT_PROPERTIES += ro.adb.secure=0
  # 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
  ADDITIONAL_DEFAULT_PROPERTIES += ro.adb.secure=1
  endif # !enable_target_debugging

  2. 确定默认的usb功能
  build/tools/post_process_props.py

  [java] view plaincopy在CODE上查看代码片派生到我的代码片
  # Put the modifications that you need to make into the /system/build.prop into this
  # function. The prop object has get(name) and put(name,value) methods.
  def mangle_build_prop(prop):
  #pass
  #If ro.mmitest is true, then disable MTP, add mass_storage for default
  if prop.get("ro.mmitest") == "true":
  prop.put("persist.sys.usb.config", "mass_storage")
  
  # If ro.debuggable is 1, then enable adb on USB by default
  # (this is for userdebug builds)
  if prop.get("ro.build.type") == "eng":
  val = prop.get("persist.sys.usb.config").strip('\r\n')
  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");
  
  
  # Put the modifications that you need to make into the /system/build.prop into this
  # function. The prop object has get(name) and put(name,value) methods.
  def mangle_default_prop(prop):
  # 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");

扩展阅读:设置安装 ... 19816811路由器设置 ... 打开文件 ... lenovo hotkey ... 一键修复丢失dll的方法 ... 如何使用net user命令 ... 浏览器怎么打开链接 ... map集合修改value ... 动态链接库user32 dll ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网