1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
public static PackageManagerService main(Context context, Installer installer, @NonNull DomainVerificationService domainVerificationService, boolean factoryTest) { PackageManagerServiceCompilerMapping.checkProperties(); final TimingsTraceAndSlog t = new TimingsTraceAndSlog(TAG + "Timing", Trace.TRACE_TAG_PACKAGE_MANAGER); t.traceBegin("create package manager"); final PackageManagerTracedLock lock = new PackageManagerTracedLock(); final Object installLock = new Object();
HandlerThread backgroundThread = new ServiceThread("PackageManagerBg", Process.THREAD_PRIORITY_BACKGROUND, true ); backgroundThread.start(); Handler backgroundHandler = new Handler(backgroundThread.getLooper(), BACKGROUND_HANDLER_CALLBACK);
PackageManagerServiceInjector injector = new PackageManagerServiceInjector( context, lock, installer, installLock, new PackageAbiHelperImpl(), backgroundHandler, SYSTEM_PARTITIONS, (i, pm) -> new ComponentResolver(i.getUserManagerService(), pm.mUserNeedsBadging), (i, pm) -> PermissionManagerService.create(context, i.getSystemConfig().getAvailableFeatures()), (i, pm) -> new UserManagerService(context, pm, new UserDataPreparer(installer, installLock, context), lock), (i, pm) -> new Settings(Environment.getDataDirectory(), RuntimePermissionsPersistence.createInstance(), i.getPermissionManagerServiceInternal(), domainVerificationService, backgroundHandler, lock), (i, pm) -> AppsFilterImpl.create(i, i.getLocalService(PackageManagerInternal.class)), (i, pm) -> (PlatformCompat) ServiceManager.getService("platform_compat"), (i, pm) -> SystemConfig.getInstance(), (i, pm) -> new PackageDexOptimizer(i.getInstaller(), i.getInstallLock(), i.getContext(), "*dexopt*"), (i, pm) -> new DexManager(i.getContext(), i.getPackageDexOptimizer(), i.getInstaller(), i.getInstallLock(), i.getDynamicCodeLogger()), (i, pm) -> new DynamicCodeLogger(i.getInstaller()), (i, pm) -> new ArtManagerService(i.getContext(), i.getInstaller(), i.getInstallLock()), (i, pm) -> ApexManager.getInstance(), (i, pm) -> new ViewCompiler(i.getInstallLock(), i.getInstaller()), (i, pm) -> (IncrementalManager) i.getContext().getSystemService(Context.INCREMENTAL_SERVICE), (i, pm) -> new DefaultAppProvider(() -> context.getSystemService(RoleManager.class), () -> LocalServices.getService(UserManagerInternal.class)), (i, pm) -> new DisplayMetrics(), (i, pm) -> new PackageParser2(pm.mSeparateProcesses, i.getDisplayMetrics(), pm.mCacheDir, pm.mPackageParserCallback) , (i, pm) -> new PackageParser2(pm.mSeparateProcesses, i.getDisplayMetrics(), null, pm.mPackageParserCallback) , (i, pm) -> new PackageParser2(pm.mSeparateProcesses, i.getDisplayMetrics(), null, pm.mPackageParserCallback) , (i, pm) -> new PackageInstallerService( i.getContext(), pm, i::getScanningPackageParser), (i, pm, cn) -> new InstantAppResolverConnection( i.getContext(), cn, Intent.ACTION_RESOLVE_INSTANT_APP_PACKAGE), (i, pm) -> new ModuleInfoProvider(i.getContext()), (i, pm) -> LegacyPermissionManagerService.create(i.getContext()), (i, pm) -> domainVerificationService, (i, pm) -> { HandlerThread thread = new ServiceThread(TAG, Process.THREAD_PRIORITY_DEFAULT, true ); thread.start(); return new PackageHandler(thread.getLooper(), pm); }, new DefaultSystemWrapper(), LocalServices::getService, context::getSystemService, (i, pm) -> { if (useArtService()) { return null; } try { return new BackgroundDexOptService(i.getContext(), i.getDexManager(), pm); } catch (LegacyDexoptDisabledException e) { throw new RuntimeException(e); } }, (i, pm) -> IBackupManager.Stub.asInterface(ServiceManager.getService( Context.BACKUP_SERVICE)), (i, pm) -> new SharedLibrariesImpl(pm, i), (i, pm) -> new CrossProfileIntentFilterHelper(i.getSettings(), i.getUserManagerService(), i.getLock(), i.getUserManagerInternal(), context), (i, pm) -> new UpdateOwnershipHelper());
if (Build.VERSION.SDK_INT <= 0) { Slog.w(TAG, "**** ro.build.version.sdk not set!"); } PackageManagerService m = new PackageManagerService(injector, factoryTest, PackagePartitions.FINGERPRINT, Build.IS_ENG, Build.IS_USERDEBUG, Build.VERSION.SDK_INT, Build.VERSION.INCREMENTAL); t.traceEnd();
final CompatChange.ChangeListener selinuxChangeListener = packageName -> { synchronized (m.mInstallLock) { final Computer snapshot = m.snapshotComputer(); final PackageStateInternal packageState = snapshot.getPackageStateInternal(packageName); if (packageState == null) { Slog.e(TAG, "Failed to find package setting " + packageName); return; } AndroidPackage pkg = packageState.getPkg(); SharedUserApi sharedUser = snapshot.getSharedUser( packageState.getSharedUserAppId()); String oldSeInfo = packageState.getSeInfo();
if (pkg == null) { Slog.e(TAG, "Failed to find package " + packageName); return; } final String newSeInfo = SELinuxMMAC.getSeInfo(packageState, pkg, sharedUser, m.mInjector.getCompatibility());
if (!newSeInfo.equals(oldSeInfo)) { Slog.i(TAG, "Updating seInfo for package " + packageName + " from: " + oldSeInfo + " to: " + newSeInfo); m.commitPackageStateMutation(null, packageName, state -> state.setOverrideSeInfo(newSeInfo)); m.mAppDataHelper.prepareAppDataAfterInstallLIF(pkg); } } };
injector.getCompatibility().registerListener(SELinuxMMAC.SELINUX_LATEST_CHANGES, selinuxChangeListener); injector.getCompatibility().registerListener(SELinuxMMAC.SELINUX_R_CHANGES, selinuxChangeListener);
m.installAllowlistedSystemPackages(); IPackageManagerImpl iPackageManager = m.new IPackageManagerImpl(); ServiceManager.addService("package", iPackageManager); final PackageManagerNative pmn = new PackageManagerNative(m); ServiceManager.addService("package_native", pmn); return m; }
|