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

Commit 7b55838f authored by Ahaan Ugale's avatar Ahaan Ugale
Browse files

Avoid re-showing Toast for sensitive content screen capture blocking

While an app stays in the block list, avoid showing the Toast every time
its blocked window becomes visible.

Bug: 323580163
Test: manual
Test: atest CtsSensitiveContentProtectionTestCases:android.sensitivecontentprotection.cts.ViewSensitiveContentTest --iterations
Change-Id: If89ff070ae1fe4b47bd588410a36ed4b8e372931
parent f2001b43
Loading
Loading
Loading
Loading
+28 −3
Original line number Diff line number Diff line
@@ -240,6 +240,7 @@ import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.DisplayMetrics;
import android.util.EventLog;
import android.util.IntArray;
import android.util.MergedConfiguration;
import android.util.Pair;
import android.util.Slog;
@@ -1105,6 +1106,14 @@ public class WindowManagerService extends IWindowManager.Stub

    @GuardedBy("mGlobalLock")
    final SensitiveContentPackages mSensitiveContentPackages = new SensitiveContentPackages();
    /**
     * UIDs for which a Toast has been shown to indicate
     * {@link LocalService#addBlockScreenCaptureForApps(ArraySet) screen capture blocking}. This is
     * used to ensure we don't keep re-showing the Toast every time the window becomes visible.
     * UIDs are removed when the app is removed from the block list.
     */
    @GuardedBy("mGlobalLock")
    private final IntArray mCaptureBlockedToastShownUids = new IntArray();

    /** Listener to notify activity manager about app transitions. */
    final WindowManagerInternal.AppTransitionListener mActivityManagerAppTransitionNotifier
@@ -8749,6 +8758,15 @@ public class WindowManagerService extends IWindowManager.Stub
                if (modified) {
                    WindowManagerService.this.refreshScreenCaptureDisabled();
                }
                if (sensitiveContentImprovements()) {
                    for (int i = 0; i < packageInfos.size(); i++) {
                        int uid = packageInfos.valueAt(i).getUid();
                        if (mCaptureBlockedToastShownUids.contains(uid)) {
                            mCaptureBlockedToastShownUids.remove(
                                    mCaptureBlockedToastShownUids.indexOf(uid));
                        }
                    }
                }
            }
        }

@@ -8759,6 +8777,9 @@ public class WindowManagerService extends IWindowManager.Stub
                if (modified) {
                    WindowManagerService.this.refreshScreenCaptureDisabled();
                }
                if (sensitiveContentImprovements()) {
                    mCaptureBlockedToastShownUids.clear();
                }
            }
        }

@@ -10160,9 +10181,13 @@ public class WindowManagerService extends IWindowManager.Stub
     * on sensitive content protections.
     */
    private void showToastIfBlockingScreenCapture(@NonNull WindowState w) {
        // TODO(b/323580163): Check if already shown and update shown state.
        if (mSensitiveContentPackages.shouldBlockScreenCaptureForApp(w.getOwningPackage(),
                w.getOwningUid(), w.getWindowToken())) {
        int uid = w.getOwningUid();
        if (mCaptureBlockedToastShownUids.contains(uid)) {
            return;
        }
        if (mSensitiveContentPackages.shouldBlockScreenCaptureForApp(w.getOwningPackage(), uid,
                w.getWindowToken())) {
            mCaptureBlockedToastShownUids.add(uid);
            mH.post(() -> {
                Toast.makeText(mContext, Looper.getMainLooper(),
                                mContext.getString(R.string.screen_not_shared_sensitive_content),