Track both framework and app overlays per package
Always bundle framework and app overlays. The old implementation, where
framework and app overlays were tracked independently, lead to an error
in the following scenario:
1. Enable app overlay -> change reflected in app
2. Enable framework overlay -> error: no change reflected in app
3. Disable app overlay -> change reflected in app, including framework
overlay
This change also leads to better architecture since the package manager
no longer needs to know that an app's overlays consist of both framework
and app specific overlays. Instead, that knowledge is handled by the
overlay manager.
Also, correct indentation in "cmd package dump packages" output and
remove obsolete constant DUMP_ENABLED_OVERLAYS.
Test: Manual
Change-Id: I707fc00052a15b22fb8c17e6155732520e6b2e52
Bug: 62680061
diff --git a/services/core/java/com/android/server/om/OverlayManagerService.java b/services/core/java/com/android/server/om/OverlayManagerService.java
index ef3e7bc..2940a6e 100644
--- a/services/core/java/com/android/server/om/OverlayManagerService.java
+++ b/services/core/java/com/android/server/om/OverlayManagerService.java
@@ -714,11 +714,17 @@
final Map<String, List<String>> pendingChanges = new ArrayMap<>(targetPackageNames.size());
synchronized (mLock) {
+ final List<String> frameworkOverlays =
+ mImpl.getEnabledOverlayPackageNames("android", userId);
final int N = targetPackageNames.size();
for (int i = 0; i < N; i++) {
final String targetPackageName = targetPackageNames.get(i);
- pendingChanges.put(targetPackageName,
- mImpl.getEnabledOverlayPackageNames(targetPackageName, userId));
+ List<String> list = new ArrayList<>();
+ if (!"android".equals(targetPackageName)) {
+ list.addAll(frameworkOverlays);
+ }
+ list.addAll(mImpl.getEnabledOverlayPackageNames(targetPackageName, userId));
+ pendingChanges.put(targetPackageName, list);
}
}
diff --git a/services/core/java/com/android/server/om/OverlayManagerServiceImpl.java b/services/core/java/com/android/server/om/OverlayManagerServiceImpl.java
index 261bcc5..db6e974 100644
--- a/services/core/java/com/android/server/om/OverlayManagerServiceImpl.java
+++ b/services/core/java/com/android/server/om/OverlayManagerServiceImpl.java
@@ -170,6 +170,7 @@
final PackageInfo targetPackage = mPackageManager.getPackageInfo(packageName, userId);
updateAllOverlaysForTarget(packageName, userId, targetPackage);
+ mListener.onOverlaysChanged(packageName, userId);
}
void onTargetPackageChanged(@NonNull final String packageName, final int userId) {
@@ -178,7 +179,9 @@
}
final PackageInfo targetPackage = mPackageManager.getPackageInfo(packageName, userId);
- updateAllOverlaysForTarget(packageName, userId, targetPackage);
+ if (updateAllOverlaysForTarget(packageName, userId, targetPackage)) {
+ mListener.onOverlaysChanged(packageName, userId);
+ }
}
void onTargetPackageUpgrading(@NonNull final String packageName, final int userId) {
@@ -186,7 +189,9 @@
Slog.d(TAG, "onTargetPackageUpgrading packageName=" + packageName + " userId=" + userId);
}
- updateAllOverlaysForTarget(packageName, userId, null);
+ if (updateAllOverlaysForTarget(packageName, userId, null)) {
+ mListener.onOverlaysChanged(packageName, userId);
+ }
}
void onTargetPackageUpgraded(@NonNull final String packageName, final int userId) {
@@ -195,7 +200,9 @@
}
final PackageInfo targetPackage = mPackageManager.getPackageInfo(packageName, userId);
- updateAllOverlaysForTarget(packageName, userId, targetPackage);
+ if (updateAllOverlaysForTarget(packageName, userId, targetPackage)) {
+ mListener.onOverlaysChanged(packageName, userId);
+ }
}
void onTargetPackageRemoved(@NonNull final String packageName, final int userId) {
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index 3bbbde0..eaa1789 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -21583,8 +21583,7 @@
public static final int DUMP_FROZEN = 1 << 19;
public static final int DUMP_DEXOPT = 1 << 20;
public static final int DUMP_COMPILER_STATS = 1 << 21;
- public static final int DUMP_ENABLED_OVERLAYS = 1 << 22;
- public static final int DUMP_CHANGES = 1 << 23;
+ public static final int DUMP_CHANGES = 1 << 22;
public static final int OPTION_SHOW_FILTERS = 1 << 0;
@@ -21828,8 +21827,6 @@
dumpState.setDump(DumpState.DUMP_DEXOPT);
} else if ("compiler-stats".equals(cmd)) {
dumpState.setDump(DumpState.DUMP_COMPILER_STATS);
- } else if ("enabled-overlays".equals(cmd)) {
- dumpState.setDump(DumpState.DUMP_ENABLED_OVERLAYS);
} else if ("changes".equals(cmd)) {
dumpState.setDump(DumpState.DUMP_CHANGES);
} else if ("write".equals(cmd)) {
@@ -24606,12 +24603,7 @@
}
final PackageSetting ps = mSettings.mPackages.get(targetPackageName);
- String[] frameworkOverlayPaths = null;
- if (!"android".equals(targetPackageName)) {
- frameworkOverlayPaths =
- mSettings.mPackages.get("android").getOverlayPaths(userId);
- }
- ps.setOverlayPaths(overlayPaths, frameworkOverlayPaths, userId);
+ ps.setOverlayPaths(overlayPaths, userId);
return true;
}
}
diff --git a/services/core/java/com/android/server/pm/PackageSettingBase.java b/services/core/java/com/android/server/pm/PackageSettingBase.java
index d17267f..f685127 100644
--- a/services/core/java/com/android/server/pm/PackageSettingBase.java
+++ b/services/core/java/com/android/server/pm/PackageSettingBase.java
@@ -330,21 +330,9 @@
modifyUserState(userId).installReason = installReason;
}
- void setOverlayPaths(List<String> overlayPaths, String[] frameworkOverlayPaths, int userId) {
- if (overlayPaths == null && frameworkOverlayPaths == null) {
- modifyUserState(userId).overlayPaths = null;
- return;
- }
- final List<String> paths;
- if (frameworkOverlayPaths == null) {
- paths = overlayPaths;
- } else {
- paths = Lists.newArrayList(frameworkOverlayPaths);
- if (overlayPaths != null) {
- paths.addAll(overlayPaths);
- }
- }
- modifyUserState(userId).overlayPaths = paths.toArray(new String[paths.size()]);
+ void setOverlayPaths(List<String> overlayPaths, int userId) {
+ modifyUserState(userId).overlayPaths = overlayPaths == null ? null :
+ overlayPaths.toArray(new String[overlayPaths.size()]);
}
String[] getOverlayPaths(int userId) {
diff --git a/services/core/java/com/android/server/pm/Settings.java b/services/core/java/com/android/server/pm/Settings.java
index b006c2d..45d0c58 100644
--- a/services/core/java/com/android/server/pm/Settings.java
+++ b/services/core/java/com/android/server/pm/Settings.java
@@ -4861,9 +4861,9 @@
String[] overlayPaths = ps.getOverlayPaths(user.id);
if (overlayPaths != null && overlayPaths.length > 0) {
- pw.println("Overlay paths:");
+ pw.print(prefix); pw.println(" overlay paths:");
for (String path : overlayPaths) {
- pw.println(path);
+ pw.print(prefix); pw.print(" "); pw.println(path);
}
}