[RK3288][Android5.1] 调试笔记 -- Android系统ROOT(免授权)

Platform: RK3288
OS: Android 5.1

Kernel: 3.10.79


1.删除system/extras/su/Android.mk 屏蔽系统su编译

2.使用 PRODUCT_COPY_FILES 拷贝附件的su到out/../system/xbin/目录下
例 PRODUCT_COPY_FILES +=$(CUR_PATH)/su:system/xbin/su

在 \device\rockchip\rk3288\device.mk  文件中

PRODUCT_COPY_FILES += \
    device/rockchip/rk3288/rk3288_box/init.rc:root/init.rc \
    device/rockchip/rk3288/fstab.rk30board.bootmode.unknown:root/fstab.rk30board.bootmode.unknown \
+    $(LOCAL_PATH)/su:system/xbin/su \
    device/rockchip/rk3288/rk3288_box/fstab.rk30board.bootmode.emmc:root/fstab.rk30board.bootmode.emmc

并把 su 文件中放在此文件同一目录下

此方法不是最稳妥的方案,还请大神指点下


3.如下添加对应的代码到init.rk30board.rc
diff --git a/device/rockchip/common/init.rk30board.rc b/device/rockchip/common/init.rk30board.rc
index 8a44718..db978a0 100644
--- a/device/rockchip/common/init.rk30board.rc
+++ b/device/rockchip/common/init.rk30board.rc
@@ -164,3 +164,8 @@ on property:app.logsave.start=1

on property:app.logsave.start=0
     stop catlog
+
+
+service daemonsu /system/xbin/su --daemon
+    class main
+    oneshot


备注:若要在开发者选项中做个开关,则方案如下:

        1. +++ \device\rockchip\common\init.rk30board.rc    文件下添加

         # yr add new code for root test 2017.11.08
        service su /system/xbin/su --daemon
            class main
            seclabel u:r:su:s0
        #    oneshot
    
        on property:persist.sys.root_access=0
            stop su

        on property:persist.sys.root_access=1
            start su

        #end

        2、+++ \device\rockchip\rk3288\system.prop  文件下添加

        persist.sys.root_access=0

        3、\packages\apps\Settings\src\com\android\settings\DevelopmentSettings.java   文件下添加

    private static final String ROOT_ACCESS_KEY = "root_access";
    private static final String ROOT_ACCESS_PROPERTY = "persist.sys.root_access";

    private SwitchPreference mRootAccess;
    private Object mSelectedRootValue;

    private Dialog mRootDialog;


        mRootAccess = (SwitchPreference) findPreference(ROOT_ACCESS_KEY);
        mAllPrefs.add(mRootAccess);
        mRootAccess.setOnPreferenceChangeListener(this);

         updateRootAccessOptions();


   private void updateRootAccessOptions() {
       //Log.e("jxwtest", "updateRootAccessOptions");
        String value = SystemProperties.get(ROOT_ACCESS_PROPERTY, "0");
        mRootAccess.setChecked(!"0".equals(value));
    }

    private void writeRootAccessOptions(Object newValue) {
        //Log.e("jxwtest", "writeRootAccessOptions");
       SystemProperties.set(ROOT_ACCESS_PROPERTY, newValue.toString());
       updateRootAccessOptions();
    }

    private void resetRootAccessOptions() {
        //Log.e("jxwtest", "resetRootAccessOptions");
        String oldValue = SystemProperties.get(ROOT_ACCESS_PROPERTY, "0");
        SystemProperties.set(ROOT_ACCESS_PROPERTY, "0");

        updateRootAccessOptions();
    }


        else if (ROOT_ACCESS_KEY.equals(preference.getKey())) {
            //String newValue1 = mRootAccess.isChecked()?"1":"0";
            boolean switchStatus = (boolean)newValue;
            String newValue1 = switchStatus?"1":"0";
            //Log.e("jxwtest", "onPreferenceChange:newValue="+newValue+",newValue1="+newValue1);
             if ("0".equals(SystemProperties.get(ROOT_ACCESS_PROPERTY, "0"))
                    && switchStatus) {
                mSelectedRootValue = newValue1;
                mDialogClicked = false;
                if (mRootDialog != null) {
                    dismissDialogs();
                }
                mRootDialog = new AlertDialog.Builder(getActivity())
                        .setMessage(getResources().getString(R.string.root_access_warning_message))
                        .setTitle(R.string.root_access_warning_title)
                        .setPositiveButton(android.R.string.yes, this)
                        .setNegativeButton(android.R.string.no, this).show();
                mRootDialog.setOnDismissListener(this);
            } else {
                writeRootAccessOptions(newValue1);
            }
            return true;
        }

        if (mRootDialog != null) {
            //Log.e("jxwtest", "dismissDialogs");
            mRootDialog.dismiss();
            mRootDialog = null;
        }


        else if (dialog == mRootDialog) {
            //Log.e("jxwtest", "onClick");
            if (which == DialogInterface.BUTTON_POSITIVE) {
                writeRootAccessOptions(mSelectedRootValue);
            } else {
                // Reset the option
                writeRootAccessOptions("0");
            }
        }

        else if (dialog == mRootDialog) {
            //Log.e("jxwtest", "onDismiss");
            updateRootAccessOptions();
            mRootDialog = null;
        }

         4.  \packages\apps\Settings\res\xml\development_prefs.xml   文件下添加


            android:key="root_access"
        android:title="@string/root_access"
        android:persistent="false"/>



4.修改
+++ b/system/core/include/private/android_filesystem_config.h
@@ -245,7 +245,7 @@ static const struct fs_path_config android_files[] = {

     /* the following five files are INTENTIONALLY set-uid, but they
      * are NOT included on user builds. */
-    { 04750, AID_ROOT,      AID_SHELL,     0, "system/xbin/su" },
+    { 06755, AID_ROOT,      AID_ROOT,     0, "system/xbin/su" },


5.编译后烧写固件,如无法获取root,请查看ls -l system/xbin/su 的权限是否为6755


参考文献:http://developer.t-firefly.com/thread-9810-1-1.html

文件下载地址:http://download.csdn.net/download/jkjiang123/10110894



你可能感兴趣的:(android)