Exclude headless packages from being scanned as stopped.

With the enabling of putting all system apps in stopped state, we want
to automatically exclude all packages that don't have a launcher entry,
since those packages don't have a clean way for a user to "unstop" them.
This is a rather conservative approach, that may be revisited in the
future.

Bug: 269129704
Test: Manual inspection no headless packages are stopped

Change-Id: Ic2ea4b37d34ebcfea912e65e1bd0f2e1150a3daa
This commit is contained in:
Martijn Coenen
2023-04-03 14:06:23 +00:00
parent 86a93d4648
commit 876ab66e3f
2 changed files with 33 additions and 1 deletions

View File

@@ -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<ResolveInfo> 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

View File

@@ -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<ResolveInfo> 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,