From e0aff5f686b0f0e54aada70959da259cae413d1e Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Tue, 21 Feb 2023 11:05:29 -0800 Subject: [PATCH] Remove lockpattern utils construction... where possible. By invoking the constructor, we are not reusing the cache that will mitigate binder calls for reading state. There is an instance of LockPatternUtils that is injectable via dagger. Some classes, however, cannot inject this. (i.e. view, service, or static method). I've removed the instances where I could to hopefully mitigate binder calls and jank. Fixes: 268192609 Test: Check to see if bouncer works properly mostly. Change-Id: I56a19fa6e419f1a7af28171edf4ebaccf55e9929 --- .../com/android/keyguard/EmergencyButton.java | 9 +++----- .../keyguard/EmergencyButtonController.java | 21 +++++++++++++------ .../src/com/android/keyguard/NumPadKey.java | 3 --- ...NotificationLockscreenUserManagerImpl.java | 5 +++-- ...NotificationLockscreenUserManagerTest.java | 4 +++- 5 files changed, 24 insertions(+), 18 deletions(-) diff --git a/packages/SystemUI/src/com/android/keyguard/EmergencyButton.java b/packages/SystemUI/src/com/android/keyguard/EmergencyButton.java index a25b281f807c6..c5a06b48e0157 100644 --- a/packages/SystemUI/src/com/android/keyguard/EmergencyButton.java +++ b/packages/SystemUI/src/com/android/keyguard/EmergencyButton.java @@ -24,7 +24,6 @@ import android.view.ViewConfiguration; import android.widget.Button; import com.android.internal.util.EmergencyAffordanceManager; -import com.android.internal.widget.LockPatternUtils; /** * This class implements a smart emergency button that updates itself based @@ -40,8 +39,6 @@ public class EmergencyButton extends Button { private int mDownY; private boolean mLongPressWasDragged; - private LockPatternUtils mLockPatternUtils; - private final boolean mEnableEmergencyCallWhileSimLocked; public EmergencyButton(Context context) { @@ -58,7 +55,6 @@ public class EmergencyButton extends Button { @Override protected void onFinishInflate() { super.onFinishInflate(); - mLockPatternUtils = new LockPatternUtils(mContext); if (mEmergencyAffordanceManager.needsEmergencyAffordance()) { setOnLongClickListener(v -> { if (!mLongPressWasDragged @@ -95,7 +91,8 @@ public class EmergencyButton extends Button { return super.performLongClick(); } - void updateEmergencyCallButton(boolean isInCall, boolean hasTelephonyRadio, boolean simLocked) { + void updateEmergencyCallButton(boolean isInCall, boolean hasTelephonyRadio, boolean simLocked, + boolean isSecure) { boolean visible = false; if (hasTelephonyRadio) { // Emergency calling requires a telephony radio. @@ -107,7 +104,7 @@ public class EmergencyButton extends Button { visible = mEnableEmergencyCallWhileSimLocked; } else { // Only show if there is a secure screen (pin/pattern/SIM pin/SIM puk); - visible = mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser()); + visible = isSecure; } } } diff --git a/packages/SystemUI/src/com/android/keyguard/EmergencyButtonController.java b/packages/SystemUI/src/com/android/keyguard/EmergencyButtonController.java index ea808eb19b90e..62298f10d6b71 100644 --- a/packages/SystemUI/src/com/android/keyguard/EmergencyButtonController.java +++ b/packages/SystemUI/src/com/android/keyguard/EmergencyButtonController.java @@ -34,6 +34,7 @@ import androidx.annotation.Nullable; import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; +import com.android.internal.widget.LockPatternUtils; import com.android.keyguard.dagger.KeyguardBouncerScope; import com.android.systemui.shade.ShadeController; import com.android.systemui.statusbar.policy.ConfigurationController; @@ -57,6 +58,7 @@ public class EmergencyButtonController extends ViewController { private final MetricsLogger mMetricsLogger; private EmergencyButtonCallback mEmergencyButtonCallback; + private LockPatternUtils mLockPatternUtils; private final KeyguardUpdateMonitorCallback mInfoCallback = new KeyguardUpdateMonitorCallback() { @@ -83,7 +85,8 @@ public class EmergencyButtonController extends ViewController { KeyguardUpdateMonitor keyguardUpdateMonitor, TelephonyManager telephonyManager, PowerManager powerManager, ActivityTaskManager activityTaskManager, ShadeController shadeController, - @Nullable TelecomManager telecomManager, MetricsLogger metricsLogger) { + @Nullable TelecomManager telecomManager, MetricsLogger metricsLogger, + LockPatternUtils lockPatternUtils) { super(view); mConfigurationController = configurationController; mKeyguardUpdateMonitor = keyguardUpdateMonitor; @@ -93,6 +96,7 @@ public class EmergencyButtonController extends ViewController { mShadeController = shadeController; mTelecomManager = telecomManager; mMetricsLogger = metricsLogger; + mLockPatternUtils = lockPatternUtils; } @Override @@ -116,10 +120,12 @@ public class EmergencyButtonController extends ViewController { private void updateEmergencyCallButton() { if (mView != null) { mView.updateEmergencyCallButton( - mTelecomManager != null && mTelecomManager.isInCall(), - getContext().getPackageManager().hasSystemFeature( + /* isInCall= */ mTelecomManager != null && mTelecomManager.isInCall(), + /* hasTelephonyRadio= */ getContext().getPackageManager().hasSystemFeature( PackageManager.FEATURE_TELEPHONY), - mKeyguardUpdateMonitor.isSimPinVoiceSecure()); + /* simLocked= */ mKeyguardUpdateMonitor.isSimPinVoiceSecure(), + /* isSecure= */ + mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser())); } } @@ -178,13 +184,15 @@ public class EmergencyButtonController extends ViewController { @Nullable private final TelecomManager mTelecomManager; private final MetricsLogger mMetricsLogger; + private final LockPatternUtils mLockPatternUtils; @Inject public Factory(ConfigurationController configurationController, KeyguardUpdateMonitor keyguardUpdateMonitor, TelephonyManager telephonyManager, PowerManager powerManager, ActivityTaskManager activityTaskManager, ShadeController shadeController, - @Nullable TelecomManager telecomManager, MetricsLogger metricsLogger) { + @Nullable TelecomManager telecomManager, MetricsLogger metricsLogger, + LockPatternUtils lockPatternUtils) { mConfigurationController = configurationController; mKeyguardUpdateMonitor = keyguardUpdateMonitor; @@ -194,6 +202,7 @@ public class EmergencyButtonController extends ViewController { mShadeController = shadeController; mTelecomManager = telecomManager; mMetricsLogger = metricsLogger; + mLockPatternUtils = lockPatternUtils; } /** Construct an {@link com.android.keyguard.EmergencyButtonController}. */ @@ -201,7 +210,7 @@ public class EmergencyButtonController extends ViewController { return new EmergencyButtonController(view, mConfigurationController, mKeyguardUpdateMonitor, mTelephonyManager, mPowerManager, mActivityTaskManager, mShadeController, - mTelecomManager, mMetricsLogger); + mTelecomManager, mMetricsLogger, mLockPatternUtils); } } } diff --git a/packages/SystemUI/src/com/android/keyguard/NumPadKey.java b/packages/SystemUI/src/com/android/keyguard/NumPadKey.java index 0a4880e1ce66b..3b0644eaab827 100644 --- a/packages/SystemUI/src/com/android/keyguard/NumPadKey.java +++ b/packages/SystemUI/src/com/android/keyguard/NumPadKey.java @@ -33,7 +33,6 @@ import android.widget.TextView; import androidx.annotation.Nullable; -import com.android.internal.widget.LockPatternUtils; import com.android.settingslib.Utils; import com.android.systemui.R; @@ -46,7 +45,6 @@ public class NumPadKey extends ViewGroup implements NumPadAnimationListener { private final TextView mDigitText; private final TextView mKlondikeText; - private final LockPatternUtils mLockPatternUtils; private final PowerManager mPM; private int mDigit = -1; @@ -107,7 +105,6 @@ public class NumPadKey extends ViewGroup implements NumPadAnimationListener { setOnHoverListener(new LiftToActivateListener( (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE))); - mLockPatternUtils = new LockPatternUtils(context); mPM = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); LayoutInflater inflater = (LayoutInflater) getContext().getSystemService( Context.LAYOUT_INFLATER_SERVICE); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java index f4cd985adbdb8..51c5183ffee9e 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java @@ -213,7 +213,8 @@ public class NotificationLockscreenUserManagerImpl implements DeviceProvisionedController deviceProvisionedController, KeyguardStateController keyguardStateController, SecureSettings secureSettings, - DumpManager dumpManager) { + DumpManager dumpManager, + LockPatternUtils lockPatternUtils) { mContext = context; mMainHandler = mainHandler; mDevicePolicyManager = devicePolicyManager; @@ -225,7 +226,7 @@ public class NotificationLockscreenUserManagerImpl implements mClickNotifier = clickNotifier; mOverviewProxyServiceLazy = overviewProxyServiceLazy; statusBarStateController.addCallback(this); - mLockPatternUtils = new LockPatternUtils(context); + mLockPatternUtils = lockPatternUtils; mKeyguardManager = keyguardManager; mBroadcastDispatcher = broadcastDispatcher; mDeviceProvisionedController = deviceProvisionedController; diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java index 452606dfcca4d..8ee1ea8a99167 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java @@ -44,6 +44,7 @@ import android.testing.TestableLooper; import androidx.test.filters.SmallTest; +import com.android.internal.widget.LockPatternUtils; import com.android.systemui.Dependency; import com.android.systemui.SysuiTestCase; import com.android.systemui.broadcast.BroadcastDispatcher; @@ -354,7 +355,8 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase { mDeviceProvisionedController, mKeyguardStateController, mSettings, - mock(DumpManager.class)); + mock(DumpManager.class), + mock(LockPatternUtils.class)); } public BroadcastReceiver getBaseBroadcastReceiverForTest() {