当前位置:   article > 正文

PackageManagerService启动_packagemangerser

packagemangerser

这个是本人总结的,mkw的framework面试的资料,需要具体的视频和其他的资料,TB店铺 纳新工作室  中找framework 资料就好哈。

ContextImpl 持有ApplicationPackageManager ,然后ApplicationPackageManager 持有 IPakcageManager.binder,可以和IPackageManager 之间进行通信。

1.同样从systemServer.java开始启动 

  1. private void startBootstrapServices(){
  2. ...
  3. mSystemServiceManager.startBootPhase(SystemService.PHASE_WAIT_FOR_DEFAULT_DISPLAY);
  4. ...
  5. mPackageManagerService = PackageManagerService.main(mSystemContext,installer,mFactoryTestMode!=FactoryTest.FACTORY_TEST_OFF,mOnlyCore);
  6. mFirstBoot = mPackageManagerService.isFirstBoot();
  7. mPackageManager = mSystemContext.getPackageManager();
  8. ...
  9. }

SystemServer::startOtherServices

  1. private void startOtherServices(){
  2. ...
  3. mSystemServiceManager.startBootPhase(SystemService.PHASE_LOCK_SETTINGS_READY);
  4. mSystemServiceManager.startBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY);
  5. ...
  6. mPackageManagerService.systemReady();
  7. ...
  8. mSystemServiceManager.startBootPhase(SystemService.PHASE_ACTIVITY_MANAGER_READY);
  9. }}

PackageMs::main

  1. public static PackageManagerService main(Context context,Installer installer,boolean factoryTest,boolean onlyCore){
  2. ...
  3. PackageManagerService m = new PackageManagerService(context,installer,...)
  4. ...
  5. ServiceManager.addService("package",m);
  6. return m;
  7. }

packageMs 初始化

  1. public PackageManagerService(Context context,Installer installser,boolean factoryTest,boolean nlyCore){
  2. ...
  3. //PMS_START
  4. //1.创建settings
  5. mSettings = new Settings(mPackages);
  6. //2.system phone log nfc bluetooth shell 添加到setting
  7. mSettings.addSharedUserLPw("android.uid.system",Process.SYSTEM_UID,ApplicationInfo.FLAG_SYSTEM,ApplicationInfo.PRIVATE_FLAG_PRIVILEDGE);
  8. mSettings.addSharedUserLPw("android.uid.phone",RADIO_UID,
  9. log nfc bluetooth shell...
  10. //初始化SystemConfig
  11. SystemConfig systemConfig = SystemConfig.getInstance();
  12. mGlobalGids = systemConfig.getGlobalGids();
  13. mSystemPermissions = systemConfig.getSystemPermissions();
  14. mAvailableFratures = systemConfig.getAvailableFeatures();
  15. synchronized(mInstallLock){
  16. synchronized(mPackages){
  17. mHandlerThread = new ServiceThread(TAG,Process.THREAD_PRIORITY_BACKGROUND,true);
  18. mHandlerThread.start();
  19. //创建packageHandler
  20. mHandler = new PackageHandler(mHandlerThread.getLooper());
  21. Watchdog.getInstance().addThread(mHandler,WATCHDOG_TIMEOUT);
  22. ...
  23. ArrayMap<String,String> libConfig = systemConfig.getSharedLibraries();
  24. for(int i=0;i<libConfig.size();i++){
  25. mSharedLibraries.put(libConfig.keyAt(i),new SharedLibraryEntry(libConfig.valueAt(i)));
  26. }
  27. }
  28. //PM_SYSTEM_SCAN_STSRT
  29. ...
  30. final String bootClassPath = System.getenv("BOOTCLASSPATH");
  31. final String systemServerClassPath = system.getenv("SYSTEMSERVERCLASSPATH");
  32. ...
  33. //对满足调价的jar和apk进行dex优化
  34. mInstaller.dexopt(lib,Process.SYSTEM_UID,dexCodeInstructionSet,
  35. dexoptNeeded,DEXOPT_PUBLIC/**/)
  36. ...
  37. //2扫描system/app system/priv-app
  38. //Collect ordinary system packages
  39. final File systemAppDir = new File(Environment.getRootDirectiry(),"app");
  40. scanDirTracedLI(systemAppDir,mDefParseFlags|PackageParser.PARSE_IS_SYSTEM|
  41. |PackageParse.PARSE_IS_SYSTEM_DIR,scanFlags,0);
  42. ...
  43. //Collect all oem packages
  44. final File oemAppDir = new File(Environment.getOemDirectory(),"app");
  45. scanDirTraceLI(oemAppDir,mDefParseFlags|PackageParse.PAESE_IS_SYSTEM|PackageParse.PAESE_IS_SYSTEM_DIR,scanFlags,0);
  46. ...
  47. //look for any incomplete package installations
  48. ArrayList<PackageSetting> deletePkgsList =
  49. mSettings.getListOfIncompleteInstallPackagesLPr();
  50. for (int i = 0; i < deletePkgsList.size(); i++) {
  51. // Actual deletion of code and data will be handled by later
  52. // reconciliation step
  53. final String packageName = deletePkgsList.get(i).name;
  54. logCriticalInfo(Log.WARN, "Cleaning up incompletely
  55. installed app: " + packageName);
  56. synchronized (mPackages) {
  57. mSettings.removePackageLPw(packageName);}}
  58. //处理三方app,太复杂了
  59. }}} }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/199119
推荐阅读
相关标签
  

闽ICP备14008679号