From 7771e6ebf536f69290be8eb88aaeae8c91231fd5 Mon Sep 17 00:00:00 2001 From: Nikolas Havrikov Date: Fri, 19 Jun 2020 11:45:34 +0200 Subject: [PATCH] Ensure mShowDialogs gets updated as part of global config update The "App keeps crashing" dialog appears on Android TV even though it should not. This would usually be accounted for by setting mShowDialogs to false in the ActivityTaskManagerService on boot. However, this does not happen because the service uses a method of the ActivityTaskManager which pulls its configuration from the context, which at this point is not yet updated to reflect relevant values like the uiMode. This change solves this problem by introducing an internal method in the ActivityTaskManager, which acts on a given configuration instead of the one from the context. This is helpful because the caller ActivityTaskManagerService is holding on to the correct configuration in the first place. Furthermore, this change does not impact any outward-facing behavior, nor does it introduce code duplication as the old method of ActivityTaskManager new merely delegates its task to the new one with the same configuration it would have originally pulled from the context. Test: Manually on ADT-3 device Bug: 159019027 Change-Id: I0fac574a69a19243c2e62b967978ef5d8318ee51 --- core/java/android/app/ActivityTaskManager.java | 14 +++++++++++--- .../server/wm/ActivityTaskManagerService.java | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/core/java/android/app/ActivityTaskManager.java b/core/java/android/app/ActivityTaskManager.java index 1cc63da3db0a6..0f31529451fb3 100644 --- a/core/java/android/app/ActivityTaskManager.java +++ b/core/java/android/app/ActivityTaskManager.java @@ -433,13 +433,21 @@ public class ActivityTaskManager { } } - /** Returns whether the current UI mode supports error dialogs (ANR, crash, etc). */ - public static boolean currentUiModeSupportsErrorDialogs(@NonNull Context context) { - final Configuration config = context.getResources().getConfiguration(); + /** + * @return whether the UI mode of the given config supports error dialogs (ANR, crash, etc). + * @hide + */ + public static boolean currentUiModeSupportsErrorDialogs(@NonNull Configuration config) { int modeType = config.uiMode & Configuration.UI_MODE_TYPE_MASK; return (modeType != Configuration.UI_MODE_TYPE_CAR && !(modeType == Configuration.UI_MODE_TYPE_WATCH && Build.IS_USER) && modeType != Configuration.UI_MODE_TYPE_TELEVISION && modeType != Configuration.UI_MODE_TYPE_VR_HEADSET); } + + /** @return whether the current UI mode supports error dialogs (ANR, crash, etc). */ + public static boolean currentUiModeSupportsErrorDialogs(@NonNull Context context) { + final Configuration config = context.getResources().getConfiguration(); + return currentUiModeSupportsErrorDialogs(config); + } } diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java index 6dd1ea934497a..5fbb7a500161c 100644 --- a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java +++ b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java @@ -5413,7 +5413,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { final boolean hideDialogsSet = Settings.Global.getInt(mContext.getContentResolver(), HIDE_ERROR_DIALOGS, 0) != 0; mShowDialogs = inputMethodExists - && ActivityTaskManager.currentUiModeSupportsErrorDialogs(mContext) + && ActivityTaskManager.currentUiModeSupportsErrorDialogs(config) && !hideDialogsSet; }