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

Commit 2a8162ee authored by Yuanjia Hsu's avatar Yuanjia Hsu Committed by Android (Google) Code Review
Browse files

Merge "Allow override the suppress Overlay condition" into main

parents 41fb975b 0325fefe
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -1430,6 +1430,13 @@ flag {
   bug: "319809270"
}

flag {
   name: "override_suppress_overlay_condition"
   namespace: "systemui"
   description: "Allow override the conditions to suppress the clipboard overlay"
   bug: "358473717"
}

flag {
   name: "media_projection_dialog_behind_lockscreen"
   namespace: "systemui"
+16 −4
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.clipboardoverlay;
import static android.content.ClipDescription.CLASSIFICATION_COMPLETE;

import static com.android.systemui.Flags.clipboardNoninteractiveOnLockscreen;
import static com.android.systemui.Flags.overrideSuppressOverlayCondition;
import static com.android.systemui.clipboardoverlay.ClipboardOverlayEvent.CLIPBOARD_OVERLAY_ENTERED;
import static com.android.systemui.clipboardoverlay.ClipboardOverlayEvent.CLIPBOARD_OVERLAY_UPDATED;
import static com.android.systemui.clipboardoverlay.ClipboardOverlayEvent.CLIPBOARD_TOAST_SHOWN;
@@ -63,6 +64,7 @@ public class ClipboardListener implements
    private final ClipboardManager mClipboardManager;
    private final KeyguardManager mKeyguardManager;
    private final UiEventLogger mUiEventLogger;
    private final ClipboardOverlaySuppressionController mClipboardOverlaySuppressionController;
    private ClipboardOverlay mClipboardOverlay;

    @Inject
@@ -71,13 +73,15 @@ public class ClipboardListener implements
            ClipboardToast clipboardToast,
            UserScopedService<ClipboardManager> clipboardManager,
            KeyguardManager keyguardManager,
            UiEventLogger uiEventLogger) {
            UiEventLogger uiEventLogger,
            ClipboardOverlaySuppressionController clipboardOverlaySuppressionController) {
        mContext = context;
        mOverlayProvider = clipboardOverlayControllerProvider;
        mClipboardToast = clipboardToast;
        mClipboardManager = clipboardManager.forUser(UserHandle.CURRENT);
        mKeyguardManager = keyguardManager;
        mUiEventLogger = uiEventLogger;
        mClipboardOverlaySuppressionController = clipboardOverlaySuppressionController;
    }

    @Override
@@ -94,10 +98,18 @@ public class ClipboardListener implements
        String clipSource = mClipboardManager.getPrimaryClipSource();
        ClipData clipData = mClipboardManager.getPrimaryClip();

        if (overrideSuppressOverlayCondition()) {
            if (mClipboardOverlaySuppressionController.shouldSuppressOverlay(clipData, clipSource,
                    Build.IS_EMULATOR)) {
                Log.i(TAG, "Clipboard overlay suppressed.");
                return;
            }
        } else {
            if (shouldSuppressOverlay(clipData, clipSource, Build.IS_EMULATOR)) {
                Log.i(TAG, "Clipboard overlay suppressed.");
                return;
            }
        }

        // user should not access intents before setup or while device is locked
        if ((clipboardNoninteractiveOnLockscreen() && mKeyguardManager.isDeviceLocked())
+29 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.systemui.clipboardoverlay

import android.content.ClipData

/** Interface to control the clipboard overlay suppression behavior. */
interface ClipboardOverlaySuppressionController {

    /** Decides if the clipboard overlay should be suppressed. */
    fun shouldSuppressOverlay(
        clipData: ClipData?,
        clipSource: String?,
        isEmulator: Boolean,
    ): Boolean
}
+50 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.systemui.clipboardoverlay

import android.content.ClipData
import com.android.internal.annotations.VisibleForTesting
import com.android.systemui.dagger.SysUISingleton
import javax.inject.Inject

@SysUISingleton
open class ClipboardOverlaySuppressionControllerImpl @Inject constructor() :
    ClipboardOverlaySuppressionController {

    // The overlay is suppressed if EXTRA_SUPPRESS_OVERLAY is true and the device is an emulator or
    // the source package is SHELL_PACKAGE. This is meant to suppress the overlay when the emulator
    // or a mirrored device is syncing the clipboard.
    override fun shouldSuppressOverlay(
        clipData: ClipData?,
        clipSource: String?,
        isEmulator: Boolean,
    ): Boolean {
        if (!(isEmulator || SHELL_PACKAGE == clipSource)) {
            return false
        }
        if (clipData == null || clipData.description.extras == null) {
            return false
        }
        return clipData.description.extras.getBoolean(EXTRA_SUPPRESS_OVERLAY, false)
    }

    companion object {
        @VisibleForTesting const val SHELL_PACKAGE = "com.android.shell"

        @VisibleForTesting
        const val EXTRA_SUPPRESS_OVERLAY = "com.android.systemui.SUPPRESS_CLIPBOARD_OVERLAY"
    }
}
+32 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.systemui.clipboardoverlay.dagger

import com.android.systemui.clipboardoverlay.ClipboardOverlaySuppressionController
import com.android.systemui.clipboardoverlay.ClipboardOverlaySuppressionControllerImpl
import dagger.Binds
import dagger.Module

/** Dagger Module for code in the clipboard overlay package. */
@Module
interface ClipboardOverlaySuppressionModule {

    /** Provides implementation for [ClipboardOverlaySuppressionController]. */
    @Binds
    fun provideClipboardOverlaySuppressionController(
        clipboardOverlaySuppressionControllerImpl: ClipboardOverlaySuppressionControllerImpl
    ): ClipboardOverlaySuppressionController
}
Loading