[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

### 回答1: MTK指的是联发科技(MediaTek)所生产的手机芯片,而强制打开USB调试是指在手机设置中强制开启USB调试功能。 开启USB调试可以使手机与电脑之间建立连接,从而实现数据传输、文件共享、调试等功能。在某些情况下,由于手机系统的限制或其他原因,无法直接通过设置界面打开USB调试。这时候,我们需要通过一些特殊的方法来强制打开该功能。 以下是一种可能的方法,用于在MTK芯片的手机上强制打开USB调试: 1. 首先,确保已经在电脑上安装了手机的驱动程序,可以从手机厂商的官方网站或其他可靠来源下载并安装。 2. 连接手机和电脑,确保手机处于解锁状态,并且两者之间建立了正常的USB连接。 3. 在电脑上打开命令提示符(CMD)或终端窗口,输入以下命令:adb devices,然后按回车键。 4. 如果手机驱动已正确安装并且USB调试已正常启用,命令行窗口将显示连接的设备列表。如果没有找到任何设备,请继续下一步。 5. 在命令行窗口中输入以下命令:adb shell setprop persist.sys.usb.config mtp,然后按回车键。 6. 等待片刻,再次输入adb devices命令,查看设备列表是否更新为连接的设备。 7. 如果设备列表显示连接的设备,则说明USB调试已成功打开。如果仍然无法找到设备,请尝试重新连接手机、重启手机或电脑,并再次执行上述步骤。 需要注意的是,这仅是一种可能的方法,并且可能因手机型号、系统版本等因素而有所不同。在进行任何操作前,请确保了解风险,并在可靠的来源获取相关信息和指导。 总结:强制打开MTK芯片手机的USB调试可以通过连接手机到电脑,使用adb命令行输入特定命令来实现。这样可以方便进行数据传输、文件共享和调试等操作。 ### 回答2: 在MTK(联发科技)处理器的设备上,强制打开USB调试的方法如下: 首先,确保你的MTK设备(如手机或平板电脑)连接到电脑上并处于开机、解锁状态。 然后,通过以下步骤强制打开USB调试: 1. 在电脑上打开终端或命令提示符窗口,并进入ADB(Android Debug Bridge)工具的安装目录。 2. 键入以下命令以检查是否连接成功: adb devices 如果成功连接,将显示已连接的设备的序列号。 3. 输入以下命令以获取设备的Build类型: adb shell getprop ro.build.type 可能会显示"eng"、"user"或"userdebug"。请注意,以下步骤可能在不同类型的Build上有所不同。 4. 如果设备的Build类型为"eng",则输入以下命令来强制打开USB调试: adb shell setprop persist.sys.usb.config adb 如果Build类型为"user"或"userdebug",则输入以下命令: adb shell setprop sys.usb.config adb 5. 重新启动设备后,USB调试将被强制打开。 请注意,这种方法可能因设备型号和操作系统版本的不同而有所变化。在操作前,请确保备份重要数据,并谨慎操作,以免造成设备数据的丢失或损坏。 ### 回答3: 要在MTK设备上强制打开USB调试,可以按照以下步骤进行操作: 1. 首先,在MTK手机上找到“设置”应用,通常在主屏幕或应用抽屉中。 2. 打开“设置”应用后,向下滚动并找到“关于手机”选项,然后点击它。 3. 在“关于手机”菜单中,向下滚动并找到“版本号”或“版本信息”选项,然后连续点击该选项7次,直到出现“您已成为开发者”或类似的弹出消息。这将激活设备的开发者选项。 4. 返回到“设置”菜单,然后找到并点击新出现的“开发者选项”。 5. 在“开发者选项”菜单中,向下滚动并找到“USB调试”选项,并将其开关切换为打开状态。 6. 现在,您已成功将MTK设备上的USB调试功能打开。 请注意,MTK设备的菜单和选项可能会因设备型号和操作系统版本的不同而稍有差异。在某些设备上,可能需要额外的确认步骤或权限授权才能强制打开USB调试。如果您遇到任何问题或困难,请参考设备的用户手册或联系设备制造商获取更精确的指导。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值