美文网首页
辅助类Settings

辅助类Settings

作者: Wi1ls努力努力再努力 | 来源:发表于2019-02-26 15:54 被阅读0次

接下来先看 Setting 类,Setting 的作用是管理 Android 系统运行过程中的一些设置信息
在 PackageManagerService.java的构造方法中,首先使用到:

mSettings = new Settings(mPackages);
mSettings.addSharedUserLPw("android.uid.system", Process.SYSTEM_UID, ApplicationInfo.FLAG_SYSTEM, ApplicationInfo.PRIVATE_FLAG_PRIVILEGED);
mSettings.addSharedUserLPw("android.uid.phone",RADIO_UID, ApplicationInfo.FLAG_SYSTEM, ApplicationInfo.PRIVATE_FLAG_PRIVILEGED);
mSettings.addSharedUserLPw("android.uid.log", LOG_UID, ApplicationInfo.FLAG_SYSTEM, ApplicationInfo.PRIVATE_FLAG_PRIVILEGED);
mSettings.addSharedUserLPw("android.uid.nfc", NFC_UID, ApplicationInfo.FLAG_SYSTEM, ApplicationInfo.PRIVATE_FLAG_PRIVILEGED);
mSettings.addSharedUserLPw("android.uid.bluetooth", BLUETOOTH_UID, ApplicationInfo.FLAG_SYSTEM, ApplicationInfo.PRIVATE_FLAG_PRIVILEGED);
mSettings.addSharedUserLPw("android.uid.shell", SHELL_UID, ApplicationInfo.FLAG_SYSTEM, ApplicationInfo.PRIVATE_FLAG_PRIVILEGED);
//.../frameworks//base/services/core/java/com/android/server/pm/Settings.java



Setting(Object lock){
  this(Environment.getDataDirectory(), lock);
}
Setting(File dataDir, object lock){
  mLock = lock;

  //  /data/system
  mSystemDir = new File(dataDir,"system");
  // /data/system/packages.xml
  mSettingsFileName = new File(mSystemDir, "packages.xml");
  // /data/system/packages-backup.xml
  mBackupSettingFilename = new File(mSystemDir, "packages-backup.xml");
  // /data/system/packages.list
  mPackageListFilename = new File(mSystemDir, "packages.list");
  // /data/system/packages-stopped.xml
  mStoppedPackagesFilename = new File(mSystemDir, "packages-stopped.xml");
  // /data/system/packages-stopped-backup.xml
  mBackupStoppedPackagesFilename = new File(mSystemDir, "packages-stopped-backup.xml");
}

1.packages.xml:记录系统所有安装应用的基本信息,如签名、权限
2.packages-backup.xml:packages.xml的备份
3.packages-stopped.xml:记录系统中所有被强制停止运行的应用信息
4.packages-stopped-back.xml:packages-stopped.xml的备份
5.packages.list:保存了应用的数据目录和 UID 等信息
备份是一种容错机制


下面以"android.uid.system"来分析:

mSetting.addSharedUserLPw("android.uid.system", Process.SYSTEM_UID,ApplicationInfo.FLAG_SYSTEM,ApplicationInfo.PRIVATE_FLAG_PRIVILEGED);

对应参数:
name="android.uid.system"
uid=Process.SYSTEM_UID,值为1000
pkgFlags=ApplicationInfo.FLAG_SYSTEM,标志系统 Package
pkgPrivateFlags=ApplicationInfo.PRIVATE_FLAG_PRIVILEGED(享有特权)


关于 UID,插入Process.java中变量

/**
     * Defines the UID/GID under which system code runs.
     */
    public static final int SYSTEM_UID = 1000;

    /**
     * Defines the UID/GID under which the telephony code runs.
     */
    public static final int PHONE_UID = 1001;

    /**
     * Defines the UID/GID for the user shell.
     * @hide
     */
    public static final int SHELL_UID = 2000;

    /**
     * Defines the UID/GID for the log group.
     * @hide
     */
    public static final int LOG_UID = 1007;

    /**
     * Defines the UID/GID for the WIFI supplicant process.
     * @hide
     */
    public static final int WIFI_UID = 1010;

    /**
     * Defines the UID/GID for the mediaserver process.
     * @hide
     */
    public static final int MEDIA_UID = 1013;

    /**
     * Defines the UID/GID for the DRM process.
     * @hide
     */
    public static final int DRM_UID = 1019;

    /**
     * Defines the UID/GID for the group that controls VPN services.
     * @hide
     */
    public static final int VPN_UID = 1016;

    /**
     * Defines the UID/GID for the NFC service process.
     * @hide
     */
    public static final int NFC_UID = 1027;

    /**
     * Defines the UID/GID for the Bluetooth service process.
     * @hide
     */
    public static final int BLUETOOTH_UID = 1002;

不同的 UID/GID授予不同的权限


final ArrayMap<String, SharedUserSetting> mSharedUser = new ArrayMap<String, SharedUserSetting>();

   //这里分析的参数name="android.uid.system",uid=1000,pkgFlags=ApplicationInfo.FLAG_SYSTEM
SharedUserSetting addSharedUserLPw(String name, int uid, int pkgFlags, int pkgPriveateFlags){
  SharedUserSetting s = mSharedUsers.get(name);
  if(s != null){
    if(s.userId == uid){
      return s;
    }
    PackageManagerService.reportSetringsProblem(Log.ERROR,"Adding duplicate shared user, keeping first: "+name);
    return null;
  } 
  s = new SharedUserSetting(name, pkgFlags, pkgPrivateFlags);
  s.userId = uid;
  if(addUseridLPw(uid, s, name){
    //将name=s添加到 mSharedUsers
    mSharedUsers.put(name, s);
    return s;
  } 
  return null;
}

//从上,这uid=1000,s为 ShareUserSetting,name="android.uid.system"
private boolean addUserIdLPw(int uid,Object obj, Object name){
  //Android对 uid 进行了分类,系统 APK 的 uid 小于10000
  //如果 uid>10000,表示是应用 APK
  //对于应用的 uid 限制在19999以内
  if(uid > Proccess.LAST_APPLICATION_UID){
    return false;
  }
  //表示是应用 APK
  if(uid >= Process.FIRST_APPLICATION_UID){
    int N = mUserIds.size(); 
    //计算 uid 与FIRST_APPLICATION_UID的差作为索引
    final int index = uid - Process.FIRST_APPLICATION_UID;
    while(index>=N){
      mUserIds.add(null);
      N++;
    }
    ...
    mUserIds.set(index, obj);//mUserIds 保存应用package的 uid
  }else{
    ...
    mOtherUserIds.put(uid,obj);//mOtherUserIds 保存系统 package 的 uid
  }
  return true;
}

相关文章

  • 辅助类Settings

    接下来先看 Setting 类,Setting 的作用是管理 Android 系统运行过程中的一些设置信息在 Pa...

  • Gradle入门系列(五)——Gradle其它模块与Plugin

    Gradle其它模块 一、Settings类 settings.gradle(对应Settings.java)决定...

  • Gradle Settings 类的学习

    # 任务 了解 Settings 类作用于 Gradle 构建的哪个阶段? 了解 Settings 类与 sett...

  • 辅助类

    情境文本颜色 情境背景色 关闭按钮 通过使用一个象征关闭的图标,可以让模态框和警告框消失 三角符号 指示某个元素具...

  • 【Android】系统Setting页面的跳转

    1. ACTION_ACCESSIBILITY_SETTINGS : // 跳转系统的辅助功能界面 Inten...

  • IDEA(2018.3)通用设置

    1.IDEA配置(File -> Settings) 1.配置类的注解 URL: File -> Settings...

  • idea创建类时添加类注释

    idea创建类时添加类注释(细节) File -> Settings -> Editor -> File and ...

  • Canvas辅助类

    辅助类:范围裁切canvas.clipXXX,控制裁切范围,超出范围的会被裁切掉不绘制出来 几何变换...

  • Bootstrap 辅助类

    知识点 情境文本颜色通过颜色来展示意图,如果文本是个链接鼠标移动到文本上会变暗。 类 | 描述 | :-: | -...

  • 辅助APP类

    //APPHelper.h @interfaceAPPHelper + (APPHelper*)call; - (...

网友评论

      本文标题:辅助类Settings

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