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

Commit 3b20b67e authored by Manjeet Rulhania's avatar Manjeet Rulhania Committed by Android (Google) Code Review
Browse files

Merge "Flag guard notification protection in protection service" into main

parents 1e52b493 4901f016
Loading
Loading
Loading
Loading
+27 −15
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.server;
import static android.provider.Settings.Global.DISABLE_SCREEN_SHARE_PROTECTIONS_FOR_APPS_AND_NOTIFICATIONS;

import static com.android.internal.util.Preconditions.checkNotNull;
import static com.android.server.notification.Flags.sensitiveNotificationAppProtection;

import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -50,8 +51,12 @@ import java.util.Set;
public final class SensitiveContentProtectionManagerService extends SystemService {
    private static final String TAG = "SensitiveContentProtect";
    private static final boolean DEBUG = false;
    private static final boolean sNotificationProtectionEnabled =
            sensitiveNotificationAppProtection();

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

@@ -88,8 +93,10 @@ public final class SensitiveContentProtectionManagerService extends SystemServic

    public SensitiveContentProtectionManagerService(@NonNull Context context) {
        super(context);
        if (sNotificationProtectionEnabled) {
            mNotificationListener = new NotificationListener();
        }
    }

    @Override
    public void onStart() {}
@@ -120,6 +127,7 @@ public final class SensitiveContentProtectionManagerService extends SystemServic
        //  handler, delegate, and binder death recipient
        mProjectionManager.addCallback(mProjectionCallback, getContext().getMainThreadHandler());

        if (sNotificationProtectionEnabled) {
            try {
                mNotificationListener.registerAsSystemService(
                        getContext(),
@@ -129,6 +137,7 @@ public final class SensitiveContentProtectionManagerService extends SystemServic
                // Intra-process call, should never happen.
            }
        }
    }

    /** Cleanup any callbacks and listeners */
    @VisibleForTesting
@@ -136,12 +145,13 @@ public final class SensitiveContentProtectionManagerService extends SystemServic
        if (mProjectionManager != null) {
            mProjectionManager.removeCallback(mProjectionCallback);
        }

        if (sNotificationProtectionEnabled) {
            try {
                mNotificationListener.unregisterAsSystemService();
            } catch (RemoteException e) {
                // Intra-process call, should never happen.
            }
        }

        if (mWindowManager != null) {
            onProjectionEnd();
@@ -160,9 +170,11 @@ public final class SensitiveContentProtectionManagerService extends SystemServic

        synchronized (mSensitiveContentProtectionLock) {
            mProjectionActive = true;
            if (sNotificationProtectionEnabled) {
                updateAppsThatShouldBlockScreenCapture();
            }
        }
    }

    private void onProjectionEnd() {
        synchronized (mSensitiveContentProtectionLock) {
+2 −1
Original line number Diff line number Diff line
@@ -3014,7 +3014,8 @@ public final class SystemServer implements Dumpable {
            t.traceEnd();
        }

        if (com.android.server.notification.Flags.sensitiveNotificationAppProtection()) {
        if (com.android.server.notification.Flags.sensitiveNotificationAppProtection()
                || android.view.flags.Flags.sensitiveContentAppProtection()) {
            t.traceBegin("StartSensitiveContentProtectionManager");
            mSystemServiceManager.startService(SensitiveContentProtectionManagerService.class);
            t.traceEnd();
+9 −0
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.server;

import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;

import static com.android.server.notification.Flags.FLAG_SENSITIVE_NOTIFICATION_APP_PROTECTION;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doCallRealMethod;
@@ -31,6 +33,9 @@ import static org.mockito.Mockito.when;

import android.media.projection.MediaProjectionInfo;
import android.media.projection.MediaProjectionManager;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.provider.Settings;
import android.service.notification.NotificationListenerService.Ranking;
import android.service.notification.NotificationListenerService.RankingMap;
@@ -61,6 +66,7 @@ import java.util.Set;
@SmallTest
@RunWith(AndroidTestingRunner.class)
@RunWithLooper
@RequiresFlagsEnabled(FLAG_SENSITIVE_NOTIFICATION_APP_PROTECTION)
public class SensitiveContentProtectionManagerServiceTest {
    private static final String NOTIFICATION_KEY_1 = "com.android.server.notification.TEST_KEY_1";
    private static final String NOTIFICATION_KEY_2 = "com.android.server.notification.TEST_KEY_2";
@@ -73,6 +79,9 @@ public class SensitiveContentProtectionManagerServiceTest {

    private static final ArraySet<PackageInfo> EMPTY_SET = new ArraySet<>();

    @Rule
    public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();

    @Rule
    public final TestableContext mContext =
            new TestableContext(getInstrumentation().getTargetContext(), null);