中易网

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

答案:2  悬赏:70  
解决时间 2021-01-15 05:57
  • 提问者网友:黑米和小志
  • 2021-01-14 10:28
如何默认打开user版本 debug 选项,默认打开adb 连接
最佳答案
  • 二级知识专家网友:三千妖杀
  • 2021-01-14 10:40
如何默认打开user 版本的USB debug 选项, 默认打开adb 连接
在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.Secu
re.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);
全部回答
  • 1楼网友:千杯敬自由
  • 2021-01-14 10:57
修改bulid
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息