zoukankan      html  css  js  c++  java
  • android 设置app root权限简单方法

    vim frameworks/base/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;
               }

        }
  • 相关阅读:
    QML控件设置style样式
    QML:ListElement: cannot use script for property value
    内存更换乌龙事件
    服务器的寿命到底有多长
    这些年渠道管理系统上发生的那些事
    IT囧事之误删测试环境的生产库
    旁观一个软件产品的终结
    一根网线引发的血案
    论代码规范命名的重要性
    服务器故障之内存损坏
  • 原文地址:https://www.cnblogs.com/muhuacat/p/7146039.html
Copyright © 2011-2022 走看看