Android调试:user版本如何打开root权限,打开调试之android9.0

概述
相比较android8.1,在android9.0上,修改略有不同,主要是selinux判断函数在android9.0上做了修改。
所以在第2步上,修改地方从init.cpp挪到selinux.cpp文件中,函数名字也做了更改。具体修改如下:
1.修改ro.adb.secure和ro.secure属性

/code/1-android9.0/build/core$ git diff
diff --git a/core/main.mk b/core/main.mk
index 44ad271..947d7a3 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -239,11 +239,11 @@ enable_target_debugging := true
 tags_to_install :=
 ifneq (,$(user_variant))
   # Target is secure in user builds.
-  ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1
+  ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=0
   ADDITIONAL_DEFAULT_PROPERTIES += security.perf_harden=1

   ifeq ($(user_variant),user)
-    ADDITIONAL_DEFAULT_PROPERTIES += ro.adb.secure=1
+    ADDITIONAL_DEFAULT_PROPERTIES += ro.adb.secure=0
   endif

   ifeq ($(user_variant),userdebug)
@@ -251,7 +251,7 @@ ifneq (,$(user_variant))
     tags_to_install += debug
   else
     # Disable debugging in plain user builds.
-    enable_target_debugging :=
+   # enable_target_debugging :=
   endif

   # Disallow mock locations by default for user builds

2.修改selinux

/code/1-android9.0/system/core/
diff --git a/init/selinux.cpp b/init/selinux.cpp
index 0ba5c4a..12f932a 100644
--- a/init/selinux.cpp
+++ b/init/selinux.cpp
@@ -89,7 +89,8 @@ EnforcingStatus StatusFromCmdline() {
 }

 bool IsEnforcing() {
-    if (ALLOW_PERMISSIVE_SELINUX) {
+   return false;
+   if (ALLOW_PERMISSIVE_SELINUX) {
         return StatusFromCmdline() == SELINUX_ENFORCING;
     }
     return true;

3.修改adb模块的android.mk文件

/code/1-android9.0/system/core$ git diff
diff --git a/adb/Android.mk b/adb/Android.mk
index ece0645..4057e37 100644
--- a/adb/Android.mk
+++ b/adb/Android.mk
@@ -350,9 +350,9 @@ LOCAL_CFLAGS := \
     -D_GNU_SOURCE \
     -Wno-deprecated-declarations \

-LOCAL_CFLAGS += -DALLOW_ADBD_NO_AUTH=$(if $(filter userdebug eng,$(TARGET_BUILD_VARIANT)),1,0)
+LOCAL_CFLAGS += -DALLOW_ADBD_NO_AUTH=$(if $(filter user userdebug eng,$(TARGET_BUILD_VARIANT)),1,0

-ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
+ifneq (,$(filter user userdebug eng,$(TARGET_BUILD_VARIANT)))
 LOCAL_CFLAGS += -DALLOW_ADBD_DISABLE_VERITY=1
 LOCAL_CFLAGS += -DALLOW_ADBD_ROOT=1
 endif

另外需要修改user版本串口只有输出不能输入的问题

现象:
编译成user版本之后串口只有输出没有输入.

原因:
编译user版本之后 ro.debuggable=0

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
  # Enable Dalvik lock contention logging.
  ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.lockprof.threshold=500
  # 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

system/core/rootdir/init.rc
service console /system/bin/sh
    class core
    console
    disabled
    user shell
    group shell log
    seclabel u:r:shell:s0

on property:ro.debuggable=1
    start console

可见console是否启动受属性ro.debuggable的控制.

解决方法:

  1. 修改 ro.debuggable = 1
  2. 直接将disabled移除,默认无条件启动console.

你可能感兴趣的:(调试,Android,驱动,Linux)