From 4b2c1af9d21d331c506d3358ab3a1cfd897d6110 Mon Sep 17 00:00:00 2001 From: Beverly Date: Thu, 17 Feb 2022 17:35:11 +0000 Subject: [PATCH] Cache quickPickupEnabled state To avoid making an IPC every time DozeParameters#isQuickPickupEnabled is called. Test: atest SystemUITests Test: manually toggle on/off AOD and pickup gestures and then check the dumpsys for the quickpickup gesture enabled state Fixes: 220144555 Change-Id: Id12021076256258a869d7d6b1adb588a20391bbf --- .../statusbar/phone/DozeParameters.java | 68 ++++++++++++++++++- .../statusbar/phone/DozeParametersTest.java | 4 ++ 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeParameters.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeParameters.java index b141110a2ec29..8b25c2bc20b98 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeParameters.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeParameters.java @@ -16,9 +16,14 @@ package com.android.systemui.statusbar.phone; +import android.content.ContentResolver; +import android.content.Context; import android.content.res.Configuration; import android.content.res.Resources; +import android.database.ContentObserver; import android.hardware.display.AmbientDisplayConfiguration; +import android.net.Uri; +import android.os.Handler; import android.os.PowerManager; import android.os.SystemProperties; import android.os.UserHandle; @@ -34,6 +39,7 @@ import com.android.keyguard.KeyguardUpdateMonitorCallback; import com.android.systemui.Dumpable; import com.android.systemui.R; import com.android.systemui.dagger.SysUISingleton; +import com.android.systemui.dagger.qualifiers.Background; import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.doze.AlwaysOnDisplayPolicy; import com.android.systemui.doze.DozeScreenState; @@ -86,6 +92,7 @@ public class DozeParameters implements private boolean mDozeAlwaysOn; private boolean mControlScreenOffAnimation; + private boolean mIsQuickPickupEnabled; private boolean mKeyguardShowing; @VisibleForTesting @@ -101,10 +108,17 @@ public class DozeParameters implements public void onShadeExpandedChanged(boolean expanded) { updateControlScreenOff(); } + + @Override + public void onUserSwitchComplete(int newUserId) { + updateQuickPickupEnabled(); + } }; @Inject protected DozeParameters( + Context context, + @Background Handler handler, @Main Resources resources, AmbientDisplayConfiguration ambientDisplayConfiguration, AlwaysOnDisplayPolicy alwaysOnDisplayPolicy, @@ -146,6 +160,14 @@ public class DozeParameters implements if (mFoldAodAnimationController != null) { mFoldAodAnimationController.addCallback(this); } + + SettingsObserver quickPickupSettingsObserver = new SettingsObserver(context, handler); + quickPickupSettingsObserver.observe(); + } + + private void updateQuickPickupEnabled() { + mIsQuickPickupEnabled = + mAmbientDisplayConfiguration.quickPickupSensorEnabled(UserHandle.USER_CURRENT); } public boolean getDisplayStateSupported() { @@ -239,8 +261,11 @@ public class DozeParameters implements return mDozeAlwaysOn && !mBatteryController.isAodPowerSave(); } + /** + * Whether the quick pickup gesture is supported and enabled for the device. + */ public boolean isQuickPickupEnabled() { - return mAmbientDisplayConfiguration.quickPickupSensorEnabled(UserHandle.USER_CURRENT); + return mIsQuickPickupEnabled; } /** @@ -436,6 +461,7 @@ public class DozeParameters implements pw.print("getPickupVibrationThreshold(): "); pw.println(getPickupVibrationThreshold()); pw.print("getSelectivelyRegisterSensorsUsingProx(): "); pw.println(getSelectivelyRegisterSensorsUsingProx()); + pw.print("isQuickPickupEnabled(): "); pw.println(isQuickPickupEnabled()); } private boolean getPostureSpecificBool( @@ -458,4 +484,44 @@ public class DozeParameters implements */ void onAlwaysOnChange(); } + + private final class SettingsObserver extends ContentObserver { + private final Uri mQuickPickupGesture = + Settings.Secure.getUriFor(Settings.Secure.DOZE_QUICK_PICKUP_GESTURE); + private final Uri mPickupGesture = + Settings.Secure.getUriFor(Settings.Secure.DOZE_PICK_UP_GESTURE); + private final Uri mAlwaysOnEnabled = + Settings.Secure.getUriFor(Settings.Secure.DOZE_ALWAYS_ON); + private final Context mContext; + + SettingsObserver(Context context, Handler handler) { + super(handler); + mContext = context; + } + + void observe() { + ContentResolver resolver = mContext.getContentResolver(); + resolver.registerContentObserver(mQuickPickupGesture, false, this, + UserHandle.USER_ALL); + resolver.registerContentObserver(mPickupGesture, false, this, UserHandle.USER_ALL); + resolver.registerContentObserver(mAlwaysOnEnabled, false, this, UserHandle.USER_ALL); + update(null); + } + + @Override + public void onChange(boolean selfChange, Uri uri) { + update(uri); + } + + public void update(Uri uri) { + if (uri == null + || mQuickPickupGesture.equals(uri) + || mPickupGesture.equals(uri) + || mAlwaysOnEnabled.equals(uri)) { + // the quick pickup gesture is dependent on alwaysOn being disabled and + // the pickup gesture being enabled + updateQuickPickupEnabled(); + } + } + } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/DozeParametersTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/DozeParametersTest.java index a14ea54fc7e83..5f2bbd3419628 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/DozeParametersTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/DozeParametersTest.java @@ -27,6 +27,7 @@ import static org.mockito.Mockito.when; import android.content.res.Resources; import android.hardware.display.AmbientDisplayConfiguration; +import android.os.Handler; import android.os.PowerManager; import android.provider.Settings; import android.test.suitebuilder.annotation.SmallTest; @@ -61,6 +62,7 @@ import java.util.Optional; public class DozeParametersTest extends SysuiTestCase { private DozeParameters mDozeParameters; + @Mock Handler mHandler; @Mock Resources mResources; @Mock private AmbientDisplayConfiguration mAmbientDisplayConfiguration; @Mock private AlwaysOnDisplayPolicy mAlwaysOnDisplayPolicy; @@ -102,6 +104,8 @@ public class DozeParametersTest extends SysuiTestCase { .thenReturn(mFoldAodAnimationController); mDozeParameters = new DozeParameters( + mContext, + mHandler, mResources, mAmbientDisplayConfiguration, mAlwaysOnDisplayPolicy,