From a6ae2c14cb3c87897d8e6abc569b40ee10b3fc1b Mon Sep 17 00:00:00 2001 From: Courtney Goeltzenleuchter Date: Thu, 6 Feb 2020 17:44:21 -0700 Subject: [PATCH] Work around AM ContentObserver timing issue For the CtsAngleDeveloperOptionHostTest tests we are seeing a flaky failure in CTS and MTS testing. We tracked it down to a timing issue with how/when the Activity Manager's cached settings values are updated. Basically, we will set the settings to activate a particular code path in GraphicsEnvironment and then run a test to check that behavior. Sometimes, the test would fail. Logging showed that the test set the values but the GraphicsEnvironment code path did not see the changes because the Activity Manager's ContentObserver hadn't had time to process the settings change. We can't read from the settings provider directly because that has a huge performance impact and this is code run during application startup. Solution here is to add a command to ActivityManager to update it's settings cache. The test application then does: Set setting. Send AM refresh-settings-cache command. At this time we know the cache is up-to-date and the test can run. Test: atest android.angle.cts.CtsAngleDeveloperOptionHostTest Bug: 148545737 Bug: 148546966 Change-Id: I7a12ce098315bb98eaafad122c770bfbfe67b988 --- .../java/com/android/server/am/ActivityManagerService.java | 7 +++++++ .../com/android/server/am/ActivityManagerShellCommand.java | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 3ad96ea193bff..d3f1f02b4704e 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -19369,6 +19369,13 @@ public class ActivityManagerService extends IActivityManager.Stub } } + /** + * Force the settings cache to be loaded + */ + void refreshSettingsCache() { + mCoreSettingsObserver.onChange(true); + } + /** * Kill processes for the user with id userId and that depend on the package named packageName */ diff --git a/services/core/java/com/android/server/am/ActivityManagerShellCommand.java b/services/core/java/com/android/server/am/ActivityManagerShellCommand.java index 53a967b0ce50f..73ca31e8d5ff4 100644 --- a/services/core/java/com/android/server/am/ActivityManagerShellCommand.java +++ b/services/core/java/com/android/server/am/ActivityManagerShellCommand.java @@ -306,6 +306,8 @@ final class ActivityManagerShellCommand extends ShellCommand { return runWaitForBroadcastIdle(pw); case "compat": return runCompat(pw); + case "refresh-settings-cache": + return runRefreshSettingsCache(); default: return handleDefaultCommands(cmd); } @@ -2940,6 +2942,11 @@ final class ActivityManagerShellCommand extends ShellCommand { return 0; } + int runRefreshSettingsCache() throws RemoteException { + mInternal.refreshSettingsCache(); + return 0; + } + private int runCompat(PrintWriter pw) throws RemoteException { final PlatformCompat platformCompat = (PlatformCompat) ServiceManager.getService(Context.PLATFORM_COMPAT_SERVICE);