Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 01a84282 authored by Miranda Kephart's avatar Miranda Kephart
Browse files

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 2976ca86)
parent ca6185ae
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -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)) {
+18 −1
Original line number Diff line number Diff line
@@ -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);