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

你可能感兴趣的:(技术总结)