From 01a842822adc467beb972e9e3c37a0244dbd105a Mon Sep 17 00:00:00 2001 From: Miranda Kephart Date: Fri, 16 Feb 2024 10:14:15 -0500 Subject: Block clipboard UI when device is locked In some situations (see bug for details) it's possible to enter the clipboard even while the device is locked, and from there access the provided intents. Users should not be able to access intents from this state; this change adds an additional check before showing the interactive UI. The behavior is identical to what we do when user setup is not complete (b/251778420): we show a toast to note that content has been copied, but no interactive UI. Interactive UI is only blocked when device is locked (i.e. requiring pin entry/password/biometric/etc), not if the keyguard is up but trivially dismissable. Bug: 317048495 Test: atest ClipboardListenerTest; verification using steps in linked bug as well as forcing text content to appear client-side, to verify that even if text content is received in the ClipboardListener, no interactive UI appears. Change-Id: I1a48cbe64852dce3fba69915ca11dad8878f66eb Merged-In: I1a48cbe64852dce3fba69915ca11dad8878f66eb (cherry picked from commit 2976ca86d5c5be558191a1fe706d4cd0d7ccdecb) --- .../systemui/clipboardoverlay/ClipboardListener.java | 8 +++++++- .../clipboardoverlay/ClipboardListenerTest.java | 19 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/clipboardoverlay/ClipboardListener.java b/packages/SystemUI/src/com/android/systemui/clipboardoverlay/ClipboardListener.java index edda87527b1d..f512d58a13a0 100644 --- a/packages/SystemUI/src/com/android/systemui/clipboardoverlay/ClipboardListener.java +++ b/packages/SystemUI/src/com/android/systemui/clipboardoverlay/ClipboardListener.java @@ -25,6 +25,7 @@ import static com.android.systemui.flags.Flags.CLIPBOARD_MINIMIZED_LAYOUT; import static com.google.android.setupcompat.util.WizardManagerHelper.SETTINGS_SECURE_USER_SETUP_COMPLETE; +import android.app.KeyguardManager; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; @@ -60,6 +61,7 @@ public class ClipboardListener implements private final ClipboardToast mClipboardToast; private final ClipboardManager mClipboardManager; private final FeatureFlags mFeatureFlags; + private final KeyguardManager mKeyguardManager; private final UiEventLogger mUiEventLogger; private ClipboardOverlay mClipboardOverlay; @@ -69,12 +71,14 @@ public class ClipboardListener implements ClipboardToast clipboardToast, ClipboardManager clipboardManager, FeatureFlags featureFlags, + KeyguardManager keyguardManager, UiEventLogger uiEventLogger) { mContext = context; mOverlayProvider = clipboardOverlayControllerProvider; mClipboardToast = clipboardToast; mClipboardManager = clipboardManager; mFeatureFlags = featureFlags; + mKeyguardManager = keyguardManager; mUiEventLogger = uiEventLogger; } @@ -97,7 +101,9 @@ public class ClipboardListener implements return; } - if (!isUserSetupComplete() // user should not access intents from this state + // user should not access intents before setup or while device is locked + if (mKeyguardManager.isDeviceLocked() + || !isUserSetupComplete() || clipData == null // shouldn't happen, but just in case || clipData.getItemCount() == 0) { if (shouldShowToast(clipData)) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/clipboardoverlay/ClipboardListenerTest.java b/packages/SystemUI/tests/src/com/android/systemui/clipboardoverlay/ClipboardListenerTest.java index fd6e31ba3bee..cb73d4296c49 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/clipboardoverlay/ClipboardListenerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/clipboardoverlay/ClipboardListenerTest.java @@ -29,6 +29,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; +import android.app.KeyguardManager; import android.content.ClipData; import android.content.ClipDescription; import android.content.ClipboardManager; @@ -62,6 +63,8 @@ public class ClipboardListenerTest extends SysuiTestCase { @Mock private ClipboardManager mClipboardManager; @Mock + private KeyguardManager mKeyguardManager; + @Mock private ClipboardOverlayController mOverlayController; @Mock private ClipboardToast mClipboardToast; @@ -102,7 +105,8 @@ public class ClipboardListenerTest extends SysuiTestCase { mFeatureFlags.set(CLIPBOARD_MINIMIZED_LAYOUT, true); mClipboardListener = new ClipboardListener(getContext(), mOverlayControllerProvider, - mClipboardToast, mClipboardManager, mFeatureFlags, mUiEventLogger); + mClipboardToast, mClipboardManager, mFeatureFlags, mKeyguardManager, + mUiEventLogger); } @@ -196,6 +200,19 @@ public class ClipboardListenerTest extends SysuiTestCase { verifyZeroInteractions(mOverlayControllerProvider); } + @Test + public void test_deviceLocked_showsToast() { + when(mKeyguardManager.isDeviceLocked()).thenReturn(true); + + mClipboardListener.start(); + mClipboardListener.onPrimaryClipChanged(); + + verify(mUiEventLogger, times(1)).log( + ClipboardOverlayEvent.CLIPBOARD_TOAST_SHOWN, 0, mSampleSource); + verify(mClipboardToast, times(1)).showCopiedToast(); + verifyZeroInteractions(mOverlayControllerProvider); + } + @Test public void test_nullClipData_showsNothing() { when(mClipboardManager.getPrimaryClip()).thenReturn(null); -- cgit v1.2.3-59-g8ed1b