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

Commit b08568f9 authored by Richard MacGregor's avatar Richard MacGregor Committed by Android (Google) Code Review
Browse files

Merge "Add traces for otp redaction for apps" into main

parents 09426da1 f84da395
Loading
Loading
Loading
Loading
+57 −28
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.media.projection.MediaProjectionManager;
import android.os.Handler;
import android.os.Looper;
import android.os.RemoteException;
import android.os.Trace;
import android.os.UserHandle;
import android.service.notification.NotificationListenerService;
import android.service.notification.NotificationListenerService.RankingMap;
@@ -49,12 +50,12 @@ public final class SensitiveContentProtectionManagerService extends SystemServic
    private static final String TAG = "SensitiveContentProtect";
    private static final boolean DEBUG = false;

    @VisibleForTesting
    NotificationListener mNotificationListener;
    @VisibleForTesting NotificationListener mNotificationListener;
    private @Nullable MediaProjectionManager mProjectionManager;
    private @Nullable WindowManagerInternal mWindowManager;

    final Object mSensitiveContentProtectionLock = new Object();

    @GuardedBy("mSensitiveContentProtectionLock")
    private boolean mProjectionActive = false;

@@ -63,13 +64,24 @@ public final class SensitiveContentProtectionManagerService extends SystemServic
                @Override
                public void onStart(MediaProjectionInfo info) {
                    if (DEBUG) Log.d(TAG, "onStart projection: " + info);
                    Trace.beginSection(
                            "SensitiveContentProtectionManagerService.onProjectionStart");
                    try {
                        onProjectionStart();
                    } finally {
                        Trace.endSection();
                    }
                }

                @Override
                public void onStop(MediaProjectionInfo info) {
                    if (DEBUG) Log.d(TAG, "onStop projection: " + info);
                    Trace.beginSection("SensitiveContentProtectionManagerService.onProjectionStop");
                    try {
                        onProjectionEnd();
                    } finally {
                        Trace.endSection();
                    }
                }
            };

@@ -94,8 +106,7 @@ public final class SensitiveContentProtectionManagerService extends SystemServic
    }

    @VisibleForTesting
    void init(MediaProjectionManager projectionManager,
            WindowManagerInternal windowManager) {
    void init(MediaProjectionManager projectionManager, WindowManagerInternal windowManager) {
        if (DEBUG) Log.d(TAG, "init");

        checkNotNull(projectionManager, "Failed to get valid MediaProjectionManager");
@@ -109,7 +120,8 @@ public final class SensitiveContentProtectionManagerService extends SystemServic
        mProjectionManager.addCallback(mProjectionCallback, new Handler(Looper.getMainLooper()));

        try {
            mNotificationListener.registerAsSystemService(getContext(),
            mNotificationListener.registerAsSystemService(
                    getContext(),
                    new ComponentName(getContext(), NotificationListener.class),
                    UserHandle.USER_ALL);
        } catch (RemoteException e) {
@@ -174,8 +186,8 @@ public final class SensitiveContentProtectionManagerService extends SystemServic
        }

        // notify windowmanager of any currently posted sensitive content notifications
        ArraySet<PackageInfo> packageInfos = getSensitivePackagesFromNotifications(
                notifications, rankingMap);
        ArraySet<PackageInfo> packageInfos =
                getSensitivePackagesFromNotifications(notifications, rankingMap);

        mWindowManager.addBlockScreenCaptureForApps(packageInfos);
    }
@@ -197,8 +209,8 @@ public final class SensitiveContentProtectionManagerService extends SystemServic
        return sensitivePackages;
    }

    private PackageInfo getSensitivePackageFromNotification(StatusBarNotification sbn,
            RankingMap rankingMap) {
    private PackageInfo getSensitivePackageFromNotification(
            StatusBarNotification sbn, RankingMap rankingMap) {
        if (sbn == null) {
            Log.w(TAG, "Unable to protect null notification");
            return null;
@@ -220,17 +232,24 @@ public final class SensitiveContentProtectionManagerService extends SystemServic
        @Override
        public void onListenerConnected() {
            super.onListenerConnected();
            Trace.beginSection("SensitiveContentProtectionManagerService.onListenerConnected");
            try {
                // Projection started before notification listener was connected
                synchronized (mSensitiveContentProtectionLock) {
                    if (mProjectionActive) {
                        updateAppsThatShouldBlockScreenCapture();
                    }
                }
            } finally {
                Trace.endSection();
            }
        }

        @Override
        public void onNotificationPosted(StatusBarNotification sbn, RankingMap rankingMap) {
            super.onNotificationPosted(sbn, rankingMap);
            Trace.beginSection("SensitiveContentProtectionManagerService.onNotificationPosted");
            try {
                synchronized (mSensitiveContentProtectionLock) {
                    if (!mProjectionActive) {
                        return;
@@ -240,19 +259,29 @@ public final class SensitiveContentProtectionManagerService extends SystemServic
                    PackageInfo packageInfo = getSensitivePackageFromNotification(sbn, rankingMap);

                    if (packageInfo != null) {
                    mWindowManager.addBlockScreenCaptureForApps(new ArraySet(Set.of(packageInfo)));
                        mWindowManager.addBlockScreenCaptureForApps(
                                new ArraySet(Set.of(packageInfo)));
                    }
                }
            } finally {
                Trace.endSection();
            }
        }

        @Override
        public void onNotificationRankingUpdate(RankingMap rankingMap) {
            super.onNotificationRankingUpdate(rankingMap);
            Trace.beginSection(
                    "SensitiveContentProtectionManagerService.onNotificationRankingUpdate");
            try {
                synchronized (mSensitiveContentProtectionLock) {
                    if (mProjectionActive) {
                        updateAppsThatShouldBlockScreenCapture(rankingMap);
                    }
                }
            } finally {
                Trace.endSection();
            }
        }
    }
}