From f0a9a49d81cace039680bde9552ccaa43411be49 Mon Sep 17 00:00:00 2001 From: Rahul Banerjee Date: Tue, 17 Jan 2023 13:29:17 -0800 Subject: [PATCH] Fix ANR in SystemUI due to race condition. Bug: 265374290 Test: atest CentralSurfacesImplTest Change-Id: Ia70a3b777dc63535bc173875b2f54056ec6cca39 --- .../systemui/statusbar/phone/CentralSurfacesImpl.java | 10 +++++----- .../statusbar/phone/CentralSurfacesImplTest.java | 4 ++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java index f1e1f426b4675..5014cfe39cce9 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java @@ -884,6 +884,11 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces { wiredChargingRippleController.registerCallbacks(); mLightRevealScrimViewModelLazy = lightRevealScrimViewModelLazy; + + // Based on teamfood flag, turn predictive back dispatch on at runtime. + if (mFeatureFlags.isEnabled(Flags.WM_ENABLE_PREDICTIVE_BACK_SYSUI)) { + mContext.getApplicationInfo().setEnableOnBackInvokedCallback(true); + } } @Override @@ -998,11 +1003,6 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces { // Lastly, call to the icon policy to install/update all the icons. mIconPolicy.init(); - // Based on teamfood flag, turn predictive back dispatch on at runtime. - if (mFeatureFlags.isEnabled(Flags.WM_ENABLE_PREDICTIVE_BACK_SYSUI)) { - mContext.getApplicationInfo().setEnableOnBackInvokedCallback(true); - } - mKeyguardStateController.addCallback(new KeyguardStateController.Callback() { @Override public void onUnlockedChanged() { diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CentralSurfacesImplTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CentralSurfacesImplTest.java index c8157ccc8a9a0..6705208bf672c 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CentralSurfacesImplTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CentralSurfacesImplTest.java @@ -321,6 +321,10 @@ public class CentralSurfacesImplTest extends SysuiTestCase { public void setup() throws Exception { MockitoAnnotations.initMocks(this); + // CentralSurfacesImpl's runtime flag check fails if the flag is absent. + // This value is unused, because test manifest is opted in. + mFeatureFlags.set(Flags.WM_ENABLE_PREDICTIVE_BACK_SYSUI, false); + IThermalService thermalService = mock(IThermalService.class); mPowerManager = new PowerManager(mContext, mPowerManagerService, thermalService, Handler.createAsync(Looper.myLooper()));