From 6336ca4738bfb4e580ccde8f4bb6353cb2d3e666 Mon Sep 17 00:00:00 2001 From: Evan Severson Date: Fri, 8 Apr 2022 15:42:36 -0700 Subject: [PATCH] Update task manager ui information on dialog opening A proper fix would be to have a listner for changes to getBackgroundRestrictionExemptionReason(), but creating this listener mechanism would be very difficult since the value is computed on demand and there's a lot of signals that go into it. This change works around by refreshing the ui information when the dialog is opened. In theory we should also update the values when the footer is shown but this will cause a lot of IPCs and with the current policies the ui in the footer won't actually change as a result of the exemption reason code changing. Test: Change the battery restriction and validate UI has changed. Fixes: 228306315 Change-Id: I61857df989ea6015c91dbd60db1d700a1dde266e --- .../systemui/qs/FgsManagerController.kt | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/qs/FgsManagerController.kt b/packages/SystemUI/src/com/android/systemui/qs/FgsManagerController.kt index 2ffbf5418583d..3b906c81c01cf 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/FgsManagerController.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/FgsManagerController.kt @@ -229,6 +229,10 @@ class FgsManagerController @Inject constructor( synchronized(lock) { if (dialog == null) { + runningServiceTokens.keys.forEach { + it.updateUiControl() + } + val dialog = SystemUIDialog(context) dialog.setTitle(R.string.fgs_manager_dialog_title) @@ -397,10 +401,20 @@ class FgsManagerController @Inject constructor( val userId: Int, val packageName: String ) { - val uiControl: UIControl by lazy { - val uid = packageManager.getPackageUidAsUser(packageName, userId) + val uid by lazy { packageManager.getPackageUidAsUser(packageName, userId) } - when (activityManager.getBackgroundRestrictionExemptionReason(uid)) { + private var uiControlInitialized = false + var uiControl: UIControl = UIControl.NORMAL + get() { + if (!uiControlInitialized) { + updateUiControl() + } + return field + } + private set + + fun updateUiControl() { + uiControl = when (activityManager.getBackgroundRestrictionExemptionReason(uid)) { PowerExemptionManager.REASON_SYSTEM_UID, PowerExemptionManager.REASON_DEVICE_DEMO_MODE -> UIControl.HIDE_ENTRY @@ -413,6 +427,7 @@ class FgsManagerController @Inject constructor( PowerExemptionManager.REASON_SYSTEM_MODULE -> UIControl.HIDE_BUTTON else -> UIControl.NORMAL } + uiControlInitialized = true } override fun equals(other: Any?): Boolean {