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

Commit acaed332 authored by Richard MacGregor's avatar Richard MacGregor
Browse files

Add SensitiveNotificationProtectionLog

LogBuffer for Sensitive notification protection logging

Bug: 326266756
Test: manual
Flag: ACONFIG com.android.server.notification.screenshare_notification_hiding TEAMFOOD

Change-Id: I5004f551df7b450b3f4b9af23321accc6d6def92
parent 848934ea
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -119,6 +119,16 @@ public class LogModule {
        return factory.create("LSShadeTransitionLog", 50);
    }

    /** */
    @Provides
    @SysUISingleton
    @SensitiveNotificationProtectionLog
    public static LogBuffer provideSensitiveNotificationProtectionLogBuffer(
            LogBufferFactory factory
    ) {
        return factory.create("SensitiveNotificationProtectionLog", 10);
    }

    /** Provides a logging buffer for shade window messages. */
    @Provides
    @SysUISingleton
+25 −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.log.dagger

import javax.inject.Qualifier

/** A [com.android.systemui.log.LogBuffer] for SensitiveNotificationProtection. */
@Qualifier
@MustBeDocumented
@Retention(AnnotationRetention.RUNTIME)
annotation class SensitiveNotificationProtectionLog
+8 −3
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import javax.inject.Inject;
public class SensitiveNotificationProtectionControllerImpl
        implements SensitiveNotificationProtectionController {
    private static final String LOG_TAG = "SNPC";
    private final SensitiveNotificationProtectionControllerLogger mLogger;
    private final ArraySet<String> mExemptPackages = new ArraySet<>();
    private final ListenerSet<Runnable> mListeners = new ListenerSet<>();
    private volatile MediaProjectionInfo mProjection;
@@ -66,6 +67,7 @@ public class SensitiveNotificationProtectionControllerImpl
                        if (mDisableScreenShareProtections) {
                            Log.w(LOG_TAG,
                                    "Screen share protections disabled, ignoring projectionstart");
                            mLogger.logProjectionStart(false, info.getPackageName());
                            return;
                        }

@@ -73,6 +75,7 @@ public class SensitiveNotificationProtectionControllerImpl
                        // Launch cookie only set (non-null) if sharing single app/task
                        updateProjectionStateAndNotifyListeners(
                                (info.getLaunchCookie() == null) ? info : null);
                        mLogger.logProjectionStart(isSensitiveStateActive(), info.getPackageName());
                    } finally {
                        Trace.endSection();
                    }
@@ -82,6 +85,7 @@ public class SensitiveNotificationProtectionControllerImpl
                public void onStop(MediaProjectionInfo info) {
                    Trace.beginSection("SNPC.onProjectionStop");
                    try {
                        mLogger.logProjectionStop();
                        updateProjectionStateAndNotifyListeners(null);
                    } finally {
                        Trace.endSection();
@@ -96,7 +100,10 @@ public class SensitiveNotificationProtectionControllerImpl
            MediaProjectionManager mediaProjectionManager,
            IActivityManager activityManager,
            @Main Handler mainHandler,
            @Background Executor bgExecutor) {
            @Background Executor bgExecutor,
            SensitiveNotificationProtectionControllerLogger logger) {
        mLogger = logger;

        if (!screenshareNotificationHiding()) {
            return;
        }
@@ -202,8 +209,6 @@ public class SensitiveNotificationProtectionControllerImpl
            return false;
        }

        // TODO(b/316955558): Add disabled by developer option

        return !mExemptPackages.contains(projection.getPackageName());
    }

+45 −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.statusbar.policy

import com.android.systemui.log.LogBuffer
import com.android.systemui.log.core.LogLevel
import com.android.systemui.log.dagger.SensitiveNotificationProtectionLog
import javax.inject.Inject

/** Logger for [SensitiveNotificationProtectionController]. */
class SensitiveNotificationProtectionControllerLogger
@Inject
constructor(@SensitiveNotificationProtectionLog private val buffer: LogBuffer) {
    fun logProjectionStart(protectionEnabled: Boolean, pkg: String) {
        buffer.log(
            TAG,
            LogLevel.DEBUG,
            {
                bool1 = protectionEnabled
                str1 = pkg
            },
            { "Projection started - protection enabled:$bool1, pkg=$str1" }
        )
    }

    fun logProjectionStop() {
        buffer.log(TAG, LogLevel.DEBUG, {}, { "Projection ended - protection disabled" })
    }
}

private const val TAG = "SNPC"
+5 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.testing.AndroidTestingRunner
import androidx.test.filters.SmallTest
import com.android.server.notification.Flags
import com.android.systemui.SysuiTestCase
import com.android.systemui.log.logcatLogBuffer
import com.android.systemui.util.concurrency.FakeExecutor
import com.android.systemui.util.settings.FakeGlobalSettings
import com.android.systemui.util.time.FakeSystemClock
@@ -38,6 +39,8 @@ import org.mockito.MockitoAnnotations
@RunWith(AndroidTestingRunner::class)
@DisableFlags(Flags.FLAG_SCREENSHARE_NOTIFICATION_HIDING)
class SensitiveNotificationProtectionControllerFlagDisabledTest : SysuiTestCase() {
    private val logger = SensitiveNotificationProtectionControllerLogger(logcatLogBuffer())

    @Mock private lateinit var handler: Handler
    @Mock private lateinit var activityManager: IActivityManager
    @Mock private lateinit var mediaProjectionManager: MediaProjectionManager
@@ -54,7 +57,8 @@ class SensitiveNotificationProtectionControllerFlagDisabledTest : SysuiTestCase(
                mediaProjectionManager,
                activityManager,
                handler,
                FakeExecutor(FakeSystemClock())
                FakeExecutor(FakeSystemClock()),
                logger
            )
    }

Loading