美文网首页
CMFileManager之Root模式

CMFileManager之Root模式

作者: 赵海洋 | 来源:发表于2018-07-19 16:28 被阅读0次

aosp定制时,需要集成并调整CMFileManager的默认参数,
直接更改/aosp/packages/apps/CMFileManager/src/com/cyanogenmod/filemanager/preferences/FileManagerSettings.java中的SETTINGS_ACCESS_MODE("cm_filemanager_access_mode", AccessMode.SAFE)SETTINGS_ACCESS_MODE("cm_filemanager_access_mode", AccessMode.ROOT),作用是想使rom安装后文件管理器默认就用root模式初使化。

但是打包安装后发现在某个ROM里打开后,CM文件管理器没有进入root模式,并且选项中也没有调整root模式这一个选项。

查看代码在src/com/cyanogenmod/filemanager/activities/preferences/GeneralPreferenceFragment.java中有这么一段代码是对访问模式是否显示进行调控制的:

 private void updateAccessModeStatus() {
        // If device is not rooted, or is a restricted user, this setting cannot be changed
        final Context context = getActivity();
        boolean restrictedAccess = AndroidHelper.isSecondaryUser(context) &&
                FileManagerApplication.isRestrictSecondaryUsersAccess(context);
        this.mAccessMode.setEnabled(FileManagerApplication.isDeviceRooted() && !restrictedAccess);
        if (!FileManagerApplication.isDeviceRooted()) {
            PreferenceCategory category = (PreferenceCategory) findPreference(
                    "general_advanced_settings");
            category.removePreference(mAccessMode);
        }
    }

其中FileManagerApplication.isDeviceRooted()返回的全局变量是由如下代码初使化的:

// Check if the device is rooted
sIsDeviceRooted = areShellCommandsPresent();

  /**
     * Method that check if all shell commands are present in the device
     *
     * @return boolean Check if the device has all of the shell commands
     */
    private boolean areShellCommandsPresent() {
        try {
            String shellCommands = getString(R.string.shell_required_commands);
            String[] commands = shellCommands.split(","); //$NON-NLS-1$
            int cc = commands.length;
            if (cc == 0) {
                //???
                Log.w(TAG, "No shell commands."); //$NON-NLS-1$
                return false;
            }
            for (int i = 0; i < cc; i++) {
                String c = commands[i].trim();
                if (c.length() == 0) continue;
                File cmd = new File(c);
                if (!cmd.exists() || !cmd.isFile()) {
                    Log.w(TAG,
                            String.format(
                                    "Command %s not found. Exists: %s; IsFile: %s.", //$NON-NLS-1$
                                    c,
                                    String.valueOf(cmd.exists()),
                                    String.valueOf(cmd.isFile())));
                    return false;
                }
            }
            // All commands are present
            return true;
        } catch (Exception e) {
            Log.e(TAG,
                    "Failed to read shell commands.", e); //$NON-NLS-1$
        }
        return false;
    }

由代码可见,它需要有R.string.shell_required_commands中包含的所有文件都存在才判断为root模式。res/values/overlay.xml中找到所有的shell指令:

/system/bin/cat,
        /system/bin/chmod,
        /system/bin/chown,
        /system/bin/dd,
        /system/bin/df,
        /system/bin/gzip,
        /system/bin/id,
        /system/bin/kill,
        /system/bin/ln,
        /system/bin/ls,
        /system/bin/mkdir,
        /system/bin/mount,
        /system/bin/mv,
        /system/bin/ps,
        /system/bin/rm,
        /system/bin/sh,
        /system/xbin/awk,
        /system/xbin/bunzip2,
        /system/xbin/busybox,
        /system/xbin/bzip2,
        /system/xbin/cp,
        /system/xbin/cut,
        /system/xbin/dirname,
        /system/xbin/echo,
        /system/xbin/find,
        /system/xbin/grep,
        /system/xbin/groups,
        /system/xbin/gunzip,
        /system/xbin/pwd,
        /system/xbin/readlink,
        /system/xbin/stat,
        /system/xbin/su,
        /system/xbin/tar,
        /system/xbin/xargs,
        /system/xbin/md5sum,
        /system/xbin/sha1sum

但我的rom里并没有/system/xbin/awk和其它一些文件。
经过在多个rom里对比,发现这个不正常的rom里的busybox相关工具编译不完整,最后完整编译后解决。

相关文章

网友评论

      本文标题:CMFileManager之Root模式

      本文链接:https://www.haomeiwen.com/subject/knutmftx.html