前言
為了讓應用程序可以直接調(diào)用su執(zhí)行系統(tǒng)命令和獲取root權限,本文基于Purple Pi OH主板的Android SDK,介紹如果修改和編譯一個root版本的Android11系統(tǒng),以下為sdk源碼修改方法。
Purple Pi OH作為一款兼容樹莓派的開源主板,采用瑞芯微RK3566 (Cortex-A55) 四核64位超強CPU,主頻最高達1.8 GHz,算力高達1Tops,支持INT8/INT16,支持TensorFlow/MXNet/PyTorch/Caffe框架,多路視頻輸出和輸入,支持4K、H.265/H.264視頻解碼,接口豐富。
玩法豐富,支持OpenHarmony、Ubuntu、Debian、Android等多種系統(tǒng),提供豐富開源資料。
產(chǎn)品規(guī)格書:Purple Pi OH 產(chǎn)品手冊
關閉selinux
device/rockchip/common/BoardConfig.mk
diff --git a/device/rockchip/common/BoardConfig.mkb/device/rockchip/common/BoardConfig.mk indexe03c54f6a0..4fc6dc9868 100755 --- a/device/rockchip/common/BoardConfig.mk +++ b/device/rockchip/common/BoardConfig.mk @@ -59,7+59,7@@ BOARD_BOOT_HEADER_VERSION ?= 2 BOARD_MKBOOTIMG_ARGS := BOARD_PREBUILT_DTBOIMAGE ?= $(TARGET_DEVICE_DIR)/dtbo.img BOARD_ROCKCHIP_VIRTUAL_AB_ENABLE ?= false -BOARD_SELINUX_ENFORCING ?= true +BOARD_SELINUX_ENFORCING ?= false # Use the non-open-sourceparts, ifthey're present
注釋用戶組權限檢測
system/extras/su/su.cpp
diff --git a/system/extras/su/su.cpp b/system/extras/su/su.cpp index 1a1ab6bf40..af3d2a68c7 100644 --- a/system/extras/su/su.cpp +++ b/system/extras/su/su.cpp @@ -80,8+80,8@@ voidextract_uidgids(constchar* uidgids, uid_t* uid, gid_t* gid, gid_t* gids, i } intmain(intargc, char** argv){ - uid_tcurrent_uid = getuid(); - if(current_uid != AID_ROOT && current_uid != AID_SHELL) error(1, 0, "not allowed"); + //uid_t current_uid = getuid(); + //if (current_uid != AID_ROOT && current_uid != AID_SHELL) error(1, 0, "not allowed"); // Handle -h and --help. ++argv;給su文件默認授予root權限
system/core/libcutils/fs_config.cpp
diff --git a/system/core/libcutils/fs_config.cpp b/system/core/libcutils/fs_config.cpp index 5805a4d19b..92e93e76ff 100644 --- a/system/core/libcutils/fs_config.cpp +++ b/system/core/libcutils/fs_config.cpp @@ -188,7+188,7@@ staticconststructfs_path_configandroid_files[] = { // the following two files are INTENTIONALLY set-uid, but they // are NOT included on user builds. { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/procmem"}, - { 04750, AID_ROOT, AID_SHELL, 0, "system/xbin/su"}, + { 06755, AID_ROOT, AID_SHELL, 0, "system/xbin/su"}, // the following files have enhanced capabilities and ARE included // in user builds.
frameworks/base/core/jni/com_android_internal_os_Zygote.cpp
diff --git a/frameworks/base/core/jni/com_android_internal_os_Zygote.cpp b/frameworks/base/core/jni/com_android_internal_os_Zygote.cpp index 9eede83e21..d161e6fad3 100644 --- a/frameworks/base/core/jni/com_android_internal_os_Zygote.cpp +++ b/frameworks/base/core/jni/com_android_internal_os_Zygote.cpp @@ -656,7+656,7@@ staticvoidEnableKeepCapabilities(fail_fn_t fail_fn) { } staticvoidDropCapabilitiesBoundingSet(fail_fn_t fail_fn) { - for(inti = 0; prctl(PR_CAPBSET_READ, i, 0, 0, 0) >= 0; i++) {; +/* for (int i = 0; prctl(PR_CAPBSET_READ, i, 0, 0, 0) >= 0; i++) {; if (prctl(PR_CAPBSET_DROP, i, 0, 0, 0) == -1) { if (errno == EINVAL) { ALOGE("prctl(PR_CAPBSET_DROP) failed with EINVAL. Please verify " @@ -665,7 +665,7 @@ static void DropCapabilitiesBoundingSet(fail_fn_t fail_fn) { fail_fn(CREATE_ERROR("prctl(PR_CAPBSET_DROP, %d) failed: %s", i, strerror(errno))); } } - } + }*/ }
kernel/security/commoncap.c
diff --git a/kernel/security/commoncap.c b/kernel/security/commoncap.c index 876cfe01d9..ce87b1b780 100644 --- a/kernel/security/commoncap.c +++ b/kernel/security/commoncap.c @@ -1166,12+1166,12@@ intcap_task_setnice(struct task_struct *p, intnice) staticintcap_prctl_drop(unsignedlongcap) { structcred*new; - +/* if (!ns_capable(current_user_ns(), CAP_SETPCAP)) return -EPERM; if (!cap_valid(cap)) return -EINVAL; - +*/ new= prepare_creds(); if(!new) return-ENOMEM;編譯鏡像
修改后需要重新編譯內(nèi)核和AOSP,Android編譯需要選擇rk3566_r-userdebug版本
sourcebuild/envsetup.sh lunch rk3566_r-userdebug檢測驗證root是否成功
可在應用程序中調(diào)用 /system/xbin/su來測試系統(tǒng)是否root成功
publicstaticvoidRootCommand() { Process process = null; try{ process = Runtime.getRuntime().exec("/system/xbin/su"); process.waitFor(); } catch(IOException | InterruptedException e) { e.printStackTrace(); } finally{ if(process != null) { process.destroy(); } } }
root的系統(tǒng)可正常執(zhí)行,而非root的系統(tǒng)會提示沒有權限
java.io.IOException: Cannot run program "/system/xbin/su": error=13, Permission denied
審核編輯:湯梓紅
-
Android
+關注
關注
12文章
3961瀏覽量
129470 -
cpu
+關注
關注
68文章
11028瀏覽量
215808 -
主板
+關注
關注
53文章
2070瀏覽量
72532 -
root
+關注
關注
1文章
86瀏覽量
21611 -
樹莓派
+關注
關注
121文章
1926瀏覽量
106906
原文標題:【技術分享】Purple Pi OH Android11 ROOT 方法
文章出處:【微信號:industio,微信公眾號:深圳觸覺智能】歡迎添加關注!文章轉載請注明出處。
發(fā)布評論請先 登錄
【觸覺智能 Purple Pi OH 開發(fā)板體驗】+1、開箱體驗

【觸覺智能 Purple Pi OH 開發(fā)板體驗】+ 熟悉PurplePiOH編譯固件

請問是否有關于Android11平臺默認開放root權限的文檔?
[觸覺智能 Purple Pi OH開發(fā)板體驗] 二.RK3566運行Android11
【觸覺智能 Purple Pi OH 開發(fā)板體驗】檢測Android系統(tǒng)的完備性
Purple Pi OH Android11 ROOT方法

Purple Pi OH 開發(fā)板體驗:固件開發(fā)+應用開發(fā)

Purple Pi OH 開發(fā)板體驗:應用開發(fā)的問題

Purple Pi OH Android11 ROOT 方法

【觸覺智能 Purple Pi OH 開發(fā)板體驗】+ 兩款Purple Pi的對比

瑞芯微RK3566鴻蒙開發(fā)板Android11修改第三方輸入法為默認輸入法

瑞芯微RK3566/RK3568 Android11使用OTA升級固件方法,深圳觸覺智能鴻蒙開發(fā)板演示,備戰(zhàn)第九屆華為ICT大賽

瑞芯微RK3566/RK3568 Android11下該如何默認屏蔽導航欄/狀態(tài)欄?看這篇文章就懂了

評論