diff --git a/services/core/java/com/android/server/pm/InstallPackageHelper.java b/services/core/java/com/android/server/pm/InstallPackageHelper.java index 5f424edb15c4b..f0f091f16d473 100644 --- a/services/core/java/com/android/server/pm/InstallPackageHelper.java +++ b/services/core/java/com/android/server/pm/InstallPackageHelper.java @@ -117,6 +117,7 @@ import android.content.pm.PackageInstaller; import android.content.pm.PackageManager; import android.content.pm.PermissionGroupInfo; import android.content.pm.PermissionInfo; +import android.content.pm.ResolveInfo; import android.content.pm.SharedLibraryInfo; import android.content.pm.Signature; import android.content.pm.SigningDetails; @@ -3946,6 +3947,24 @@ final class InstallPackageHelper { mPm.mSettings.disableSystemPackageLPw(parsedPackage.getPackageName(), true); } } + + // If this is a system app we hadn't seen before, and this is a first boot or OTA, + // we need to unstop it if it doesn't have a launcher entry. + if (mPm.mShouldStopSystemPackagesByDefault && scanResult.mRequest.mPkgSetting == null + && ((scanFlags & SCAN_FIRST_BOOT_OR_UPGRADE) != 0) + && ((scanFlags & SCAN_AS_SYSTEM) != 0)) { + final Intent launcherIntent = new Intent(Intent.ACTION_MAIN); + launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER); + launcherIntent.setPackage(parsedPackage.getPackageName()); + final List launcherActivities = + mPm.snapshotComputer().queryIntentActivitiesInternal(launcherIntent, null, + PackageManager.MATCH_DIRECT_BOOT_AWARE + | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, 0); + if (launcherActivities.isEmpty()) { + scanResult.mPkgSetting.setStopped(false, 0); + } + } + if (mIncrementalManager != null && isIncrementalPath(parsedPackage.getPath())) { if (scanResult.mPkgSetting != null && scanResult.mPkgSetting.isLoading()) { // Continue monitoring loading progress of active incremental packages diff --git a/services/core/java/com/android/server/pm/Settings.java b/services/core/java/com/android/server/pm/Settings.java index 94a00d6e2e480..def8cb30f091a 100644 --- a/services/core/java/com/android/server/pm/Settings.java +++ b/services/core/java/com/android/server/pm/Settings.java @@ -4280,10 +4280,23 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile // Non-Apex system apps, that are not included in the allowlist in // initialNonStoppedSystemPackages, should be marked as stopped by default. - final boolean shouldBeStopped = service.mShouldStopSystemPackagesByDefault + boolean shouldBeStopped = service.mShouldStopSystemPackagesByDefault && ps.isSystem() && !ps.isApex() && !service.mInitialNonStoppedSystemPackages.contains(ps.getPackageName()); + if (shouldBeStopped) { + final Intent launcherIntent = new Intent(Intent.ACTION_MAIN); + launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER); + launcherIntent.setPackage(ps.getPackageName()); + final List launcherActivities = + service.snapshotComputer().queryIntentActivitiesInternal(launcherIntent, + null, + PackageManager.MATCH_DIRECT_BOOT_AWARE + | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, 0); + if (launcherActivities.isEmpty()) { + shouldBeStopped = false; + } + } ps.setStopped(shouldBeStopped, userHandle); // If userTypeInstallablePackages is the *only* reason why we're not installing,