Skip to content

Commit 8e54079

Browse files
Miranda Kephartaoleary
authored andcommitted
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. (cherry picked from commit 2976ca8) (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:b9ffec803b31f1b57756105c9fbfd0cb672fcfde) Merged-In: I1a48cbe64852dce3fba69915ca11dad8878f66eb Change-Id: I1a48cbe64852dce3fba69915ca11dad8878f66eb
1 parent 236c9d7 commit 8e54079

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

packages/SystemUI/src/com/android/systemui/clipboardoverlay/ClipboardListener.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import static com.google.android.setupcompat.util.WizardManagerHelper.SETTINGS_SECURE_USER_SETUP_COMPLETE;
2727

28+
import android.app.KeyguardManager;
2829
import android.content.ClipData;
2930
import android.content.ClipboardManager;
3031
import android.content.Context;
@@ -61,6 +62,7 @@ public class ClipboardListener implements
6162
private final ClipboardToast mClipboardToast;
6263
private final ClipboardManager mClipboardManager;
6364
private final FeatureFlags mFeatureFlags;
65+
private final KeyguardManager mKeyguardManager;
6466
private final UiEventLogger mUiEventLogger;
6567
private ClipboardOverlay mClipboardOverlay;
6668

@@ -69,12 +71,14 @@ public ClipboardListener(Context context,
6971
Provider<ClipboardOverlayController> clipboardOverlayControllerProvider,
7072
ClipboardToast clipboardToast,
7173
ClipboardManager clipboardManager,
74+
KeyguardManager keyguardManager,
7275
FeatureFlags featureFlags,
7376
UiEventLogger uiEventLogger) {
7477
mContext = context;
7578
mOverlayProvider = clipboardOverlayControllerProvider;
7679
mClipboardToast = clipboardToast;
7780
mClipboardManager = clipboardManager;
81+
mKeyguardManager = keyguardManager;
7882
mFeatureFlags = featureFlags;
7983
mUiEventLogger = uiEventLogger;
8084
}
@@ -102,7 +106,9 @@ public void onPrimaryClipChanged() {
102106
return;
103107
}
104108

105-
if (!isUserSetupComplete() // user should not access intents from this state
109+
// user should not access intents before setup or while device is locked
110+
if (mKeyguardManager.isDeviceLocked()
111+
|| !isUserSetupComplete()
106112
|| clipData == null // shouldn't happen, but just in case
107113
|| clipData.getItemCount() == 0) {
108114
if (shouldShowToast(clipData)) {

packages/SystemUI/tests/src/com/android/systemui/clipboardoverlay/ClipboardListenerTest.java

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import static org.mockito.Mockito.verifyZeroInteractions;
3030
import static org.mockito.Mockito.when;
3131

32+
import android.app.KeyguardManager;
3233
import android.content.ClipData;
3334
import android.content.ClipDescription;
3435
import android.content.ClipboardManager;
@@ -62,6 +63,8 @@ public class ClipboardListenerTest extends SysuiTestCase {
6263
@Mock
6364
private ClipboardManager mClipboardManager;
6465
@Mock
66+
private KeyguardManager mKeyguardManager;
67+
@Mock
6568
private ClipboardOverlayController mOverlayController;
6669
@Mock
6770
private ClipboardToast mClipboardToast;
@@ -102,7 +105,7 @@ public void setup() {
102105
mFeatureFlags.set(CLIPBOARD_MINIMIZED_LAYOUT, true);
103106

104107
mClipboardListener = new ClipboardListener(getContext(), mOverlayControllerProvider,
105-
mClipboardToast, mClipboardManager, mFeatureFlags, mUiEventLogger);
108+
mClipboardToast, mClipboardManager, mKeyguardManager, mFeatureFlags, mUiEventLogger);
106109
}
107110

108111

@@ -252,4 +255,44 @@ public void test_minimizedLayoutFlagOn_usesNew() {
252255
assertEquals(mSampleClipData, mClipDataCaptor.getValue());
253256
assertEquals(mSampleSource, mStringCaptor.getValue());
254257
}
258+
259+
@Test
260+
public void test_deviceLocked_showsToast() {
261+
when(mKeyguardManager.isDeviceLocked()).thenReturn(true);
262+
263+
mClipboardListener.start();
264+
mClipboardListener.onPrimaryClipChanged();
265+
266+
verify(mUiEventLogger, times(1)).log(
267+
ClipboardOverlayEvent.CLIPBOARD_TOAST_SHOWN, 0, mSampleSource);
268+
verify(mClipboardToast, times(1)).showCopiedToast();
269+
verifyZeroInteractions(mClipboardOverlayControllerFactory);
270+
}
271+
272+
@Test
273+
public void test_nullClipData_showsNothing() {
274+
when(mClipboardManager.getPrimaryClip()).thenReturn(null);
275+
276+
mClipboardListener.start();
277+
mClipboardListener.onPrimaryClipChanged();
278+
279+
verifyZeroInteractions(mUiEventLogger);
280+
verifyZeroInteractions(mClipboardToast);
281+
verifyZeroInteractions(mClipboardOverlayControllerFactory);
282+
}
283+
284+
@Test
285+
public void test_emptyClipData_showsToast() {
286+
ClipDescription description = new ClipDescription("Test", new String[0]);
287+
ClipData noItems = new ClipData(description, new ArrayList<>());
288+
when(mClipboardManager.getPrimaryClip()).thenReturn(noItems);
289+
290+
mClipboardListener.start();
291+
mClipboardListener.onPrimaryClipChanged();
292+
293+
verify(mUiEventLogger, times(1)).log(
294+
ClipboardOverlayEvent.CLIPBOARD_TOAST_SHOWN, 0, mSampleSource);
295+
verify(mClipboardToast, times(1)).showCopiedToast();
296+
verifyZeroInteractions(mClipboardOverlayControllerFactory);
297+
}
255298
}

0 commit comments

Comments
 (0)