Do not relaunch bg activities when application info changes

Update the configurations via ActivityTaskManager to prevent the
activities being relaunched while in background. Instead, the
activities will be relaunched after brought to front and being visible.

This also prevents all activities in the system being relaunched
at the same time.

Bug: 185301309
Test: update app info via shell command while activity in background
Change-Id: Ibf93b9e3f203578c25e0b6b50494065938790f24
This commit is contained in:
Louis Chang
2021-04-12 09:35:51 +08:00
parent 062b61f2de
commit 8b5afd93b6
3 changed files with 7 additions and 23 deletions

View File

@@ -5961,20 +5961,6 @@ public final class ActivityThread extends ClientTransactionHandler
// Update all affected Resources objects to use new ResourcesImpl
mResourcesManager.applyNewResourceDirsLocked(ai, oldResDirs);
}
ApplicationPackageManager.configurationChanged();
// Trigger a regular Configuration change event, only with a different assetsSeq number
// so that we actually call through to all components.
// TODO(adamlesinski): Change this to make use of ActivityManager's upcoming ability to
// store configurations per-process.
final Configuration config = mConfigurationController.getConfiguration();
Configuration newConfig = new Configuration();
newConfig.assetsSeq = (config != null ? config.assetsSeq : 0) + 1;
mConfigurationController.handleConfigurationChanged(newConfig, null /* compat */);
// Preserve windows to avoid black flickers when overlays change.
relaunchAllActivities(true /* preserveWindows */, "handleApplicationInfoChanged");
}
/**

View File

@@ -184,15 +184,6 @@ public class ActivityThreadTest {
});
}
@Test
public void testHandleActivity_assetsChanged() {
relaunchActivityAndAssertPreserveWindow(activity -> {
// Relaunches all activities.
activity.getActivityThread().handleApplicationInfoChanged(
activity.getApplicationInfo());
});
}
@Test
public void testRecreateActivity() {
relaunchActivityAndAssertPreserveWindow(Activity::recreate);

View File

@@ -77,6 +77,7 @@ import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManagerInternal;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Point;
import android.net.LocalSocket;
@@ -4643,6 +4644,12 @@ public final class ProcessList {
}
});
}
// Update the global configuration and increase the assets sequence number.
Configuration currentConfig = mService.mActivityTaskManager.getConfiguration();
Configuration newConfig = new Configuration();
newConfig.assetsSeq = (currentConfig != null ? currentConfig.assetsSeq : 0) + 1;
mService.mActivityTaskManager.updateConfiguration(newConfig);
}
@GuardedBy("mService")