Update the application info of all activities
The application was applying the legacy theme when brought to the
foreground after theme switched. That's because the app process
was killed while the it was in the background and the application-info
that cached in the ActivityRecord was used next time starting app
process.
Bug: 280130977
Test: relaunch chrome after theme switched and manually kill process
Change-Id: Iea30ee6dd28a53b3fec226b24ffb567411d445a7
diff --git a/services/core/java/com/android/server/am/ProcessList.java b/services/core/java/com/android/server/am/ProcessList.java
index e484a6c..97fb0e7 100644
--- a/services/core/java/com/android/server/am/ProcessList.java
+++ b/services/core/java/com/android/server/am/ProcessList.java
@@ -4907,6 +4907,18 @@
@GuardedBy(anyOf = {"mService", "mProcLock"})
void updateApplicationInfoLOSP(List<String> packagesToUpdate, int userId,
boolean updateFrameworkRes) {
+ final ArrayMap<String, ApplicationInfo> applicationInfoByPackage = new ArrayMap<>();
+ for (int i = packagesToUpdate.size() - 1; i >= 0; i--) {
+ final String packageName = packagesToUpdate.get(i);
+ final ApplicationInfo ai = mService.getPackageManagerInternal().getApplicationInfo(
+ packageName, STOCK_PM_FLAGS, Process.SYSTEM_UID, userId);
+ if (ai != null) {
+ applicationInfoByPackage.put(packageName, ai);
+ }
+ }
+ mService.mActivityTaskManager.updateActivityApplicationInfo(userId,
+ applicationInfoByPackage);
+
final ArrayList<WindowProcessController> targetProcesses = new ArrayList<>();
for (int i = mLruProcesses.size() - 1; i >= 0; i--) {
final ProcessRecord app = mLruProcesses.get(i);
@@ -4921,8 +4933,7 @@
app.getPkgList().forEachPackage(packageName -> {
if (updateFrameworkRes || packagesToUpdate.contains(packageName)) {
try {
- final ApplicationInfo ai = AppGlobals.getPackageManager()
- .getApplicationInfo(packageName, STOCK_PM_FLAGS, app.userId);
+ final ApplicationInfo ai = applicationInfoByPackage.get(packageName);
if (ai != null) {
if (ai.packageName.equals(app.info.packageName)) {
app.info = ai;
diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
index fb62412..59159bb 100644
--- a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
+++ b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
@@ -4588,6 +4588,20 @@
}
/**
+ * Updates the {@link ApplicationInfo}s of the package activities th that are attached in the
+ * WM hierarchy.
+ */
+ public void updateActivityApplicationInfo(int userId,
+ ArrayMap<String, ApplicationInfo> applicationInfoByPackage) {
+ synchronized (mGlobalLock) {
+ if (mRootWindowContainer != null) {
+ mRootWindowContainer.updateActivityApplicationInfo(userId,
+ applicationInfoByPackage);
+ }
+ }
+ }
+
+ /**
* Update the asset configuration and increase the assets sequence number.
* @param processes the processes that needs to update the asset configuration
*/
diff --git a/services/core/java/com/android/server/wm/RootWindowContainer.java b/services/core/java/com/android/server/wm/RootWindowContainer.java
index 2f0c303..38ff8ad2 100644
--- a/services/core/java/com/android/server/wm/RootWindowContainer.java
+++ b/services/core/java/com/android/server/wm/RootWindowContainer.java
@@ -3173,6 +3173,20 @@
});
}
+ void updateActivityApplicationInfo(int userId,
+ ArrayMap<String, ApplicationInfo> applicationInfoByPackage) {
+ forAllActivities(r -> {
+ if (r.mUserId != userId) {
+ return;
+ }
+
+ final ApplicationInfo aInfo = applicationInfoByPackage.get(r.packageName);
+ if (aInfo != null) {
+ r.updateApplicationInfo(aInfo);
+ }
+ });
+ }
+
void finishVoiceTask(IVoiceInteractionSession session) {
final IBinder binder = session.asBinder();
forAllLeafTasks(t -> t.finishIfVoiceTask(binder), true /* traverseTopToBottom */);