写点什么

FrameWork 内核解析之 PackageMS 启动(一)下篇,android 开发电子书

用户头像
Android架构
关注
发布于: 33 分钟前

2.3 PackageMS::main

public static PackageManagerService main(Context context, Installer installer,boolean factoryTest, boolean onlyCore) {...PackageManagerService m = new PackageManagerService(context, installer,...ServiceManager.addService("package", m);return m;}

2.4 PackageMS 初始化

public PackageManagerService(Context context, Installer installer,boolean factoryTest, boolean onlyCore) {...// PMS_START// A.1 创建 SettingsmSettings = new Settings(mPackages);// A.2 system phone log nfc bluetooth shell 添加到 SettingmSettings.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.s


《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》
浏览器打开:qq.cn.hn/FTe 免费领取
复制代码


hell", SHELL_UID,ApplicationInfo.FLAG_SYSTEM, ApplicationInfo.PRIVATE_FLAG_PRIVILEGED);...mPackageDexOptimizer = new PackageDexOptimizer(installer, mInstallLock, context,"dexopt");...// A.3 初始化 SystemConfigSystemConfig systemConfig = SystemConfig.getInstance();mGlobalGids = systemConfig.getGlobalGids();mSystemPermissions = systemConfig.getSystemPermissions();mAvailableFeatures = systemConfig.getAvailableFeatures();


synchronized (mInstallLock) {synchronized (mPackages) {mHandlerThread = new ServiceThread(TAG,Process.THREAD_PRIORITY_BACKGROUND, true /allowIo/);mHandlerThread.start();// A.4 创建 PackageHandlermHandler = new PackageHandler(mHandlerThread.getLooper());Watchdog.getInstance().addThread(mHandler, WATCHDOG_TIMEOUT);...ArrayMap<String, String> libConfig = systemConfig.getSharedLibraries();for (int i=0; i<libConfig.size(); i++) {mSharedLibraries.put(libConfig.keyAt(i),new SharedLibraryEntry(libConfig.valueAt(i), null));}


// PMS_SYSTEM_SCAN_START...final String bootClassPath = System.getenv("BOOTCLASSPATH");final String systemServerClassPath = System.getenv("SYSTEMSERVERCLASSPATH");...// B.1 对满足调价的 Jar Apk 执行 dex 优化 mInstaller.dexopt(lib, Process.SYSTEM_UID, dexCodeInstructionSet, dexoptNeeded, DEXOPT_PUBLIC /dexFlags/,getCompilerFilterForReason(REASON_SHARED_APK), StorageManager.UUID_PRIVATE_INTERNAL, SKIP_SHARED_LIBRARY_CHECK);...// B.2 扫描 system/app system/priv-app// Collect ordinary system packages.final File systemAppDir = new File(Environment.getRootDirectory(), "app");scanDirTracedLI(systemAppDir, mDefParseFlags| PackageParser.PARSE_IS_SYSTEM| PackageParser.PARSE_IS_SYSTEM_DIR, scanFlags, 0);...// Collect all OEM packages.final File oemAppDir = new File(Environment.getOemDirectory(), "app");scanDirTracedLI(oemAppDir, mDefParseFlags| PackageParser.PARSE_IS_SYSTEM| PackageParser.PARSE_IS_SYSTEM_DIR, scanFlags, 0);...


//look for any incomplete package installationsArrayList<PackageSetting> deletePkgsList = mSettings.getListOfIncompleteInstallPackagesLPr();for (int i = 0; i < deletePkgsList.size(); i++) {// Actual deletion of code and data will be handled by later// reconciliation stepfinal String packageName = deletePkgsList.get(i).name;logCriticalInfo(Log.WARN, "Cleaning up incompletely installed app: " + packageName);synchronized (mPackages) {mSettings.removePackageLPw(packageName);}}


//delete tmp filesdeleteTempPackageFiles();


// Remove any shared userIDs that have no associated packagesmSettings.pruneSharedUsersLPw();


// PMS_DATA_SCAN_START


//C.1 处理非系统 App //data/app 、 自定义 app 路径 if (!mOnlyCore) {scanDirTracedLI(mAppInstallDir, 0, scanFlags | SCAN_REQUIRE_KNOWN, 0);...


/**


  • Remove disable package settings for any updated system

  • apps that were removed via an OTA. If they're not a

  • previously-updated app, remove them completely.

  • Otherwise, just revoke their system-level permissions.*/for (String deletedAppName : possiblyDeletedUpdatedSystemApps) {PackageParser.Package deletedPkg = mPackages.get(deletedAppName);mSettings.removeDisabledSystemPackageLPw(deletedAppName);


String msg = "Updated system app + " + deletedAppName


  • " no longer present; removing system privileges for "

  • deletedAppName;


deletedPkg.applicationInfo.flags &= ~ApplicationInfo.FLAG_SYSTEM;

用户头像

Android架构

关注

还未添加个人签名 2021.10.31 加入

还未添加个人简介

评论

发布
暂无评论
FrameWork内核解析之PackageMS启动(一)下篇,android开发电子书