您的位置:首页 > 移动开发

android 设置app root权限简单方法

2017-02-16 15:22 330 查看
vim framework/base/ vim core/java/com/android/internal/os/ZygoteConnection.java +709 

 private static void applyUidSecurityPolicy(Arguments args, Credentials peer,

            String peerSecurityContext)

            throws ZygoteSecurityException {

        int peerUid = peer.getUid();

        if (peerUid == 0) {

            // Root can do what it wants

        } else if (peerUid == Process.SYSTEM_UID ) {

            // System UID is restricted, except in factory test mode

            String factoryTest = SystemProperties.get("ro.factorytest");

            boolean uidRestricted;

            /* In normal operation, SYSTEM_UID can only specify a restricted

             * set of UIDs. In factory test mode, SYSTEM_UID may specify any uid.

             */

            uidRestricted

                 = !(factoryTest.equals("1") || factoryTest.equals("2"));

            if (uidRestricted

                    && args.uidSpecified && (args.uid < Process.SYSTEM_UID)) {

                throw new ZygoteSecurityException(

                        "System UID may not launch process with UID < "

                                + Process.SYSTEM_UID);

            }

        } else {

            // Everything else

            if (args.uidSpecified || args.gidSpecified

                || args.gids != null) {

                throw new ZygoteSecurityException(

                        "App UIDs may not specify uid's or gid's");

            }

        }

        if (args.uidSpecified || args.gidSpecified || args.gids != null) {

            boolean allowed = SELinux.checkSELinuxAccess(peerSecurityContext,

                                                         peerSecurityContext,

                                                         "zygote",

                                                         "specifyids");

            if (!allowed) {

                throw new ZygoteSecurityException(

                        "Peer may not specify uid's or gid's");

            }

        }

        // If not otherwise specified, uid and gid are inherited from peer

        if (!args.uidSpecified) {

            args.uid = peer.getUid();

            args.uidSpecified = true;

        }

        if (!args.gidSpecified) {

            args.gid = peer.getGid();

            args.gidSpecified = true;

        }
        if((args.niceName!=null) && (args.niceName.equals("com.example.hellojni")) ){

           args.uid=0;

           args.gid=0;

           }

    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: