diff options
| author | 2025-02-04 10:23:07 -0800 | |
|---|---|---|
| committer | 2025-02-04 10:23:07 -0800 | |
| commit | b088b1268362a33e6a92b7858d12286aa8cb9bf5 (patch) | |
| tree | 0f48d91db0507dc48dc5b71876b19df75e84e997 | |
| parent | da0c2d29279cd0afc6ccf2edf6084a71f0cd6d80 (diff) | |
| parent | 70621f3ab4170fe2d406658bc70eca108d3856ac (diff) | |
Merge "Move wifi check into systemUI" into main
5 files changed, 119 insertions, 150 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java index baaf6c9a76ae..3eec1cd2d54c 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java @@ -92,6 +92,8 @@ import com.android.systemui.statusbar.notification.collection.NotificationEntryB import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection; import com.android.systemui.statusbar.notification.collection.render.NotificationVisibilityProvider; import com.android.systemui.statusbar.notification.row.shared.LockscreenOtpRedaction; +import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepository; +import com.android.systemui.statusbar.pipeline.wifi.shared.model.WifiNetworkModel; import com.android.systemui.statusbar.policy.DeviceProvisionedController; import com.android.systemui.statusbar.policy.KeyguardStateController; import com.android.systemui.util.concurrency.FakeExecutor; @@ -113,15 +115,15 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import platform.test.runner.parameterized.ParameterizedAndroidJunit4; +import platform.test.runner.parameterized.Parameters; + import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; -import platform.test.runner.parameterized.ParameterizedAndroidJunit4; -import platform.test.runner.parameterized.Parameters; - @SmallTest @RunWith(ParameterizedAndroidJunit4.class) public class NotificationLockscreenUserManagerTest extends SysuiTestCase { @@ -169,8 +171,18 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase { private KeyguardStateController mKeyguardStateController; @Mock private Lazy<DeviceUnlockedInteractor> mDeviceUnlockedInteractorLazy; + + @Mock + private Lazy<WifiRepository> mWifiRepositoryLazy; @Mock private DeviceUnlockedInteractor mDeviceUnlockedInteractor; + + @Mock + private WifiRepository mWifiRepository; + + @Mock + private StateFlow<WifiNetworkModel> mWifiStateFlow; + @Mock private Lazy<KeyguardInteractor> mKeyguardInteractorLazy; @Mock @@ -266,6 +278,8 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase { when(mKeyguardInteractorLazy.get()).thenReturn(mKeyguardInteractor); when(mKeyguardInteractor.isKeyguardDismissible()) .thenReturn(mock(StateFlow.class)); + when(mWifiRepositoryLazy.get()).thenReturn(mWifiRepository); + when(mWifiRepository.getWifiNetwork()).thenReturn(mock(StateFlow.class)); mLockscreenUserManager = new TestNotificationLockscreenUserManager(mContext); mLockscreenUserManager.setUpWithPresenter(mPresenter); @@ -528,6 +542,9 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase { .set(mSensitiveNotifPostTime - TimeUnit.DAYS.toMillis(1)); // Device is not currently locked mLockscreenUserManager.mLocked.set(false); + mLockscreenUserManager.mConnectedToWifi.set(false); + mLockscreenUserManager.mLastWifiConnectionTime.set( + mSensitiveNotifPostTime - TimeUnit.DAYS.toMillis(1)); // Sensitive Content notifications are always redacted assertEquals(REDACTION_TYPE_NONE, @@ -542,6 +559,9 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase { mCurrentUser.id); changeSetting(LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS); mLockscreenUserManager.mLocked.set(true); + mLockscreenUserManager.mConnectedToWifi.set(false); + mLockscreenUserManager.mLastWifiConnectionTime.set( + mSensitiveNotifPostTime - TimeUnit.DAYS.toMillis(1)); // Device was locked after this notification arrived mLockscreenUserManager.mLastLockTime .set(mSensitiveNotifPostTime + TimeUnit.DAYS.toMillis(1)); @@ -562,6 +582,51 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase { mLockscreenUserManager.mLastLockTime .set(mSensitiveNotifPostTime - TimeUnit.SECONDS.toMillis(1)); mLockscreenUserManager.mLocked.set(true); + mLockscreenUserManager.mConnectedToWifi.set(false); + mLockscreenUserManager.mLastWifiConnectionTime.set( + mSensitiveNotifPostTime - TimeUnit.DAYS.toMillis(1)); + + // Sensitive Content notifications are always redacted + assertEquals(REDACTION_TYPE_NONE, + mLockscreenUserManager.getRedactionType(mSensitiveContentNotif)); + } + + @Test + @EnableFlags(LockscreenOtpRedaction.FLAG_NAME) + public void testHasSensitiveContent_notRedactedIfOnWifi() { + // Allow private notifications for this user + mSettings.putIntForUser(LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1, + mCurrentUser.id); + changeSetting(LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS); + // Claim the device was last locked 1 day ago + mLockscreenUserManager.mLastLockTime + .set(mSensitiveNotifPostTime - TimeUnit.DAYS.toMillis(1)); + mLockscreenUserManager.mLocked.set(true); + // We are currently connected to wifi + mLockscreenUserManager.mConnectedToWifi.set(true); + mLockscreenUserManager.mLastWifiConnectionTime.set( + mSensitiveNotifPostTime - TimeUnit.DAYS.toMillis(1)); + + // Sensitive Content notifications are always redacted + assertEquals(REDACTION_TYPE_NONE, + mLockscreenUserManager.getRedactionType(mSensitiveContentNotif)); + } + + @Test + @EnableFlags(LockscreenOtpRedaction.FLAG_NAME) + public void testHasSensitiveContent_notRedactedIfConnectedToWifiSinceReceiving() { + // Allow private notifications for this user + mSettings.putIntForUser(LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1, + mCurrentUser.id); + changeSetting(LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS); + // Claim the device was last locked 1 day ago + mLockscreenUserManager.mLastLockTime + .set(mSensitiveNotifPostTime - TimeUnit.DAYS.toMillis(1)); + mLockscreenUserManager.mLocked.set(true); + mLockscreenUserManager.mConnectedToWifi.set(false); + // We are not currently connected to wifi, but did connect after the notification came in + mLockscreenUserManager.mLastWifiConnectionTime.set( + mSensitiveNotifPostTime + TimeUnit.SECONDS.toMillis(1)); // Sensitive Content notifications are always redacted assertEquals(REDACTION_TYPE_NONE, @@ -570,7 +635,7 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase { @Test @DisableFlags(LockscreenOtpRedaction.FLAG_NAME) - public void testHasSensitiveContent_notRedactedFlagDisabled() { + public void testHasSensitiveContent_notRedactedIfFlagDisabled() { // Allow private notifications for this user mSettings.putIntForUser(LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1, mCurrentUser.id); @@ -579,6 +644,7 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase { mLockscreenUserManager.mLastLockTime .set(mSensitiveNotifPostTime - TimeUnit.DAYS.toMillis(1)); mLockscreenUserManager.mLocked.set(true); + mLockscreenUserManager.mConnectedToWifi.set(false); // Sensitive Content notifications are always redacted assertEquals(REDACTION_TYPE_NONE, @@ -592,10 +658,11 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase { mSettings.putIntForUser(LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1, mCurrentUser.id); changeSetting(LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS); - when(mKeyguardManager.isDeviceLocked()).thenReturn(true); + mLockscreenUserManager.mLocked.set(true); // Claim the device was last unlocked 1 day ago mLockscreenUserManager.mLastLockTime .set(mSensitiveNotifPostTime - TimeUnit.DAYS.toMillis(1)); + mLockscreenUserManager.mConnectedToWifi.set(false); // Sensitive Content notifications are always redacted assertEquals(REDACTION_TYPE_SENSITIVE_CONTENT, @@ -1155,6 +1222,7 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase { mFakeFeatureFlags, mDeviceUnlockedInteractorLazy, mKeyguardInteractorLazy, + mWifiRepositoryLazy, null //CoroutineScope ); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java index 382fc7058bf0..25ebc8c1ffa1 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java @@ -61,7 +61,6 @@ import com.android.systemui.Dumpable; import com.android.systemui.Flags; import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.dagger.SysUISingleton; -import com.android.systemui.dagger.qualifiers.Application; import com.android.systemui.dagger.qualifiers.Background; import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.deviceentry.domain.interactor.DeviceUnlockedInteractor; @@ -77,6 +76,7 @@ import com.android.systemui.statusbar.notification.collection.NotificationEntry; import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection; import com.android.systemui.statusbar.notification.collection.render.NotificationVisibilityProvider; import com.android.systemui.statusbar.notification.row.shared.LockscreenOtpRedaction; +import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepository; import com.android.systemui.statusbar.policy.DeviceProvisionedController; import com.android.systemui.statusbar.policy.KeyguardStateController; import com.android.systemui.util.ListenerSet; @@ -85,6 +85,8 @@ import com.android.systemui.util.settings.SecureSettings; import dagger.Lazy; +import kotlinx.coroutines.CoroutineScope; + import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collection; @@ -97,8 +99,6 @@ import java.util.concurrent.atomic.AtomicLong; import javax.inject.Inject; -import kotlinx.coroutines.CoroutineScope; - /** * Handles keeping track of the current user, profiles, and various things related to hiding * contents, redacting notifications, and the lockscreen. @@ -300,6 +300,12 @@ public class NotificationLockscreenUserManagerImpl implements // Whether or not the device is locked @VisibleForTesting protected final AtomicBoolean mLocked = new AtomicBoolean(true); + // The last time the device connected to a wifi network + @VisibleForTesting + protected final AtomicLong mLastWifiConnectionTime = new AtomicLong(-1); + // Whether the device is connected to wifi + @VisibleForTesting + protected final AtomicBoolean mConnectedToWifi = new AtomicBoolean(false); protected int mCurrentUserId = 0; @@ -331,7 +337,8 @@ public class NotificationLockscreenUserManagerImpl implements FeatureFlagsClassic featureFlags, Lazy<DeviceUnlockedInteractor> deviceUnlockedInteractorLazy, Lazy<KeyguardInteractor> keyguardInteractor, - @Application CoroutineScope coroutineScope + Lazy<WifiRepository> wifiRepository, + @Background CoroutineScope coroutineScope ) { mContext = context; mMainExecutor = mainExecutor; @@ -366,14 +373,29 @@ public class NotificationLockscreenUserManagerImpl implements // To avoid dependency injection cycle, finish constructing this object before using the // KeyguardInteractor. The CoroutineScope will only be null in tests. if (LockscreenOtpRedaction.isEnabled() && coroutineScope != null) { - mMainExecutor.execute(() -> JavaAdapterKt.collectFlow(coroutineScope, + mMainExecutor.execute(() -> { + JavaAdapterKt.collectFlow(coroutineScope, keyguardInteractor.get().isKeyguardDismissible(), unlocked -> { if (!unlocked) { mLastLockTime.set(System.currentTimeMillis()); } mLocked.set(!unlocked); - })); + notifyNotificationStateChanged(); + }); + JavaAdapterKt.collectFlow(coroutineScope, wifiRepository.get().getWifiNetwork(), + n -> { + boolean wasConnectedToWifi = mConnectedToWifi.get(); + boolean isConnectedToWifi = + wifiRepository.get().isWifiConnectedWithValidSsid(); + if (wasConnectedToWifi != isConnectedToWifi) { + // We are either connecting, or disconnecting from wifi + mLastWifiConnectionTime.set(System.currentTimeMillis()); + mConnectedToWifi.set(isConnectedToWifi); + notifyNotificationStateChanged(); + } + }); + }); } } @@ -732,9 +754,11 @@ public class NotificationLockscreenUserManagerImpl implements * We show the sensitive content redaction view if * 1. The feature is enabled * 2. The device is locked - * 3. The notification has the `hasSensitiveContent` ranking variable set to true - * 4. The device has been locked for at least LOCK_TIME_FOR_SENSITIVE_REDACTION_MS - * 5. The notification arrived since the last lock time + * 3. The device is NOT connected to Wifi + * 4. The notification has the `hasSensitiveContent` ranking variable set to true + * 5. The device has not connected to Wifi since receiving the notification + * 6. The notification arrived at least LOCK_TIME_FOR_SENSITIVE_REDACTION_MS before the last + * lock time. */ private boolean shouldShowSensitiveContentRedactedView(NotificationEntry ent) { if (!LockscreenOtpRedaction.isEnabled()) { @@ -745,18 +769,27 @@ public class NotificationLockscreenUserManagerImpl implements return false; } + if (mConnectedToWifi.get()) { + return false; + } + if (ent.getRanking() == null || !ent.getRanking().hasSensitiveContent()) { return false; } - long lastLockedTime = mLastLockTime.get(); - if (ent.getSbn().getNotification().getWhen() < lastLockedTime) { + long lastWifiConnectTime = mLastWifiConnectionTime.get(); + // If the device has connected to wifi since receiving the notification, do not redact + if (ent.getSbn().getPostTime() < lastWifiConnectTime) { return false; } - if ((System.currentTimeMillis() - lastLockedTime) < LOCK_TIME_FOR_SENSITIVE_REDACTION_MS) { + // If the lock screen was not already locked for LOCK_TIME_FOR_SENSITIVE_REDACTION_MS when + // this notification arrived, do not redact + long latestTimeForRedaction = mLastLockTime.get() + LOCK_TIME_FOR_SENSITIVE_REDACTION_MS; + if (ent.getSbn().getPostTime() < latestTimeForRedaction) { return false; } + return true; } diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 638b2dd4a7fe..b16b766b6ef6 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -29,7 +29,6 @@ import static android.app.Flags.lifetimeExtensionRefactor; import static android.app.Flags.nmSummarization; import static android.app.Flags.nmSummarizationUi; import static android.app.Flags.notificationClassificationUi; -import static android.app.Flags.redactSensitiveContentNotificationsOnLockscreen; import static android.app.Flags.sortSectionByTime; import static android.app.Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION; import static android.app.Notification.EXTRA_BUILDER_APPLICATION_INFO; @@ -260,9 +259,6 @@ import android.content.pm.VersionedPackage; import android.content.res.Resources; import android.database.ContentObserver; import android.metrics.LogMaker; -import android.net.ConnectivityManager; -import android.net.Network; -import android.net.NetworkCapabilities; import android.net.Uri; import android.os.Binder; import android.os.Build; @@ -675,7 +671,6 @@ public class NotificationManagerService extends SystemService { private UsageStatsManagerInternal mUsageStatsManagerInternal; private TelecomManager mTelecomManager; private PowerManager mPowerManager; - private ConnectivityManager mConnectivityManager; private PostNotificationTrackerFactory mPostNotificationTrackerFactory; private LockPatternUtils mLockUtils; @@ -800,8 +795,6 @@ public class NotificationManagerService extends SystemService { private ModuleInfo mAdservicesModuleInfo; - private boolean mConnectedToWifi; - static class Archive { final SparseArray<Boolean> mEnabled; final int mBufferSize; @@ -2697,7 +2690,6 @@ public class NotificationManagerService extends SystemService { TelecomManager telecomManager, NotificationChannelLogger channelLogger, SystemUiSystemPropertiesFlags.FlagResolver flagResolver, PermissionManager permissionManager, PowerManager powerManager, - ConnectivityManager connectivityManager, PostNotificationTrackerFactory postNotificationTrackerFactory) { mHandler = handler; if (Flags.nmBinderPerfThrottleEffectsSuppressorBroadcast()) { @@ -2733,8 +2725,6 @@ public class NotificationManagerService extends SystemService { mUm = userManager; mTelecomManager = telecomManager; mPowerManager = powerManager; - mConnectivityManager = connectivityManager; - registerNetworkCallback(); mPostNotificationTrackerFactory = postNotificationTrackerFactory; mPlatformCompat = IPlatformCompat.Stub.asInterface( ServiceManager.getService(Context.PLATFORM_COMPAT_SERVICE)); @@ -2950,28 +2940,6 @@ public class NotificationManagerService extends SystemService { mAppOps.startWatchingMode(AppOpsManager.OP_POST_NOTIFICATION, null, mAppOpsListener); } - private void registerNetworkCallback() { - mConnectivityManager.registerDefaultNetworkCallback( - new ConnectivityManager.NetworkCallback() { - @Override - public void onCapabilitiesChanged(@NonNull Network network, - @NonNull NetworkCapabilities capabilities) { - updateWifiConnectionState(capabilities); - } - @Override - public void onLost(@NonNull Network network) { - mConnectedToWifi = false; - } - }, mHandler); - } - - @VisibleForTesting() - void updateWifiConnectionState(NetworkCapabilities capabilities) { - mConnectedToWifi = capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) - && capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED) - && capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_TRUSTED); - } - /** * Cleanup broadcast receivers change listeners. */ @@ -3094,7 +3062,6 @@ public class NotificationManagerService extends SystemService { new NotificationChannelLoggerImpl(), SystemUiSystemPropertiesFlags.getResolver(), getContext().getSystemService(PermissionManager.class), getContext().getSystemService(PowerManager.class), - getContext().getSystemService(ConnectivityManager.class), new PostNotificationTrackerFactory() {}); publishBinderService(Context.NOTIFICATION_SERVICE, mService, /* allowIsolated= */ false, @@ -11886,14 +11853,6 @@ public class NotificationManagerService extends SystemService { smartActions = null; smartReplies = null; } - if (redactSensitiveContentNotificationsOnLockscreen()) { - if (mListeners.hasSensitiveContent(record) && mConnectedToWifi - && info.isSystemUi) { - // We don't inform systemUI of sensitive content if - // connected to wifi, though we do still redact from untrusted listeners. - hasSensitiveContent = false; - } - } } ranking.populate( key, diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java index 3aa95449cc98..03a6ab187204 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java @@ -25,7 +25,6 @@ import static android.app.ActivityManagerInternal.ServiceNotificationPolicy.SHOW import static android.app.ActivityTaskManager.INVALID_TASK_ID; import static android.app.Flags.FLAG_KEYGUARD_PRIVATE_NOTIFICATIONS; import static android.app.Flags.FLAG_NM_BINDER_PERF_CACHE_CHANNELS; -import static android.app.Flags.FLAG_REDACT_SENSITIVE_CONTENT_NOTIFICATIONS_ON_LOCKSCREEN; import static android.app.Flags.FLAG_SORT_SECTION_BY_TIME; import static android.app.Notification.EXTRA_ALLOW_DURING_SETUP; import static android.app.Notification.EXTRA_PICTURE; @@ -257,8 +256,6 @@ import android.graphics.drawable.Icon; import android.media.AudioAttributes; import android.media.AudioManager; import android.media.session.MediaSession; -import android.net.ConnectivityManager; -import android.net.NetworkCapabilities; import android.net.Uri; import android.os.Binder; import android.os.Build; @@ -483,8 +480,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Mock private PowerManager mPowerManager; @Mock - private ConnectivityManager mConnectivityManager; - @Mock private LightsManager mLightsManager; private final ArrayList<WakeLock> mAcquiredWakeLocks = new ArrayList<>(); private final TestPostNotificationTrackerFactory mPostNotificationTrackerFactory = @@ -575,9 +570,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Mock NotificationAttentionHelper mAttentionHelper; - @Mock - NetworkCapabilities mWifiNetworkCapabilities; - private NotificationManagerService.WorkerHandler mWorkerHandler; private Handler mBroadcastsHandler; @@ -779,15 +771,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mActivityIntentImmutable = spy(PendingIntent.getActivity(mContext, 0, new Intent().setPackage(mPkg), FLAG_IMMUTABLE)); - when(mWifiNetworkCapabilities.hasTransport(eq(NetworkCapabilities.TRANSPORT_WIFI))) - .thenReturn(true); - when(mWifiNetworkCapabilities - .hasCapability(eq(NetworkCapabilities.NET_CAPABILITY_VALIDATED))) - .thenReturn(true); - when(mWifiNetworkCapabilities - .hasCapability(eq(NetworkCapabilities.NET_CAPABILITY_TRUSTED))) - .thenReturn(true); - initNMS(); } @@ -824,7 +807,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mGroupHelper, mAm, mAtm, mAppUsageStats, mDevicePolicyManager, mUgm, mUgmInternal, mAppOpsManager, mUm, mHistoryManager, mStatsManager, mAmi, mToastRateLimiter, mPermissionHelper, mock(UsageStatsManagerInternal.class), mTelecomManager, mLogger, - mTestFlagResolver, mPermissionManager, mPowerManager, mConnectivityManager, + mTestFlagResolver, mPermissionManager, mPowerManager, mPostNotificationTrackerFactory); mService.setAttentionHelper(mAttentionHelper); @@ -14421,78 +14404,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { } @Test - public void testMakeRankingUpdate_clearsHasSensitiveContentIfConnectedToWifi() { - mSetFlagsRule.enableFlags(FLAG_REDACT_SENSITIVE_NOTIFICATIONS_FROM_UNTRUSTED_LISTENERS, - FLAG_REDACT_SENSITIVE_CONTENT_NOTIFICATIONS_ON_LOCKSCREEN); - mService.updateWifiConnectionState(mWifiNetworkCapabilities); - when(mListeners.hasSensitiveContent(any())).thenReturn(true); - NotificationRecord pkgA = new NotificationRecord(mContext, - generateSbn("a", 1000, 9, 0), mTestNotificationChannel); - mService.addNotification(pkgA); - ManagedServices.ManagedServiceInfo info = mock(ManagedServices.ManagedServiceInfo.class); - info.isSystemUi = true; - when(info.enabledAndUserMatches(anyInt())).thenReturn(true); - when(info.isSameUser(anyInt())).thenReturn(true); - NotificationRankingUpdate nru = mService.makeRankingUpdateLocked(info); - NotificationListenerService.Ranking ranking = - nru.getRankingMap().getRawRankingObject(pkgA.getSbn().getKey()); - assertFalse(ranking.hasSensitiveContent()); - } - - @Test - public void testMakeRankingUpdate_doesntClearHasSensitiveContentIfNotConnectedToWifi() { - mSetFlagsRule.enableFlags(FLAG_REDACT_SENSITIVE_NOTIFICATIONS_FROM_UNTRUSTED_LISTENERS, - FLAG_REDACT_SENSITIVE_CONTENT_NOTIFICATIONS_ON_LOCKSCREEN); - mService.updateWifiConnectionState(mock(NetworkCapabilities.class)); - when(mListeners.hasSensitiveContent(any())).thenReturn(true); - NotificationRecord record = getSensitiveNotificationRecord(); - mService.addNotification(record); - ManagedServices.ManagedServiceInfo info = mock(ManagedServices.ManagedServiceInfo.class); - info.isSystemUi = true; - when(info.enabledAndUserMatches(anyInt())).thenReturn(true); - when(info.isSameUser(anyInt())).thenReturn(true); - NotificationRankingUpdate nru = mService.makeRankingUpdateLocked(info); - NotificationListenerService.Ranking ranking = - nru.getRankingMap().getRawRankingObject(record.getSbn().getKey()); - assertTrue(ranking.hasSensitiveContent()); - } - - @Test - public void testMakeRankingUpdate_doesntClearHasSensitiveContentIfNotSysUi() { - mSetFlagsRule.enableFlags(FLAG_REDACT_SENSITIVE_NOTIFICATIONS_FROM_UNTRUSTED_LISTENERS); - mSetFlagsRule.disableFlags(FLAG_REDACT_SENSITIVE_CONTENT_NOTIFICATIONS_ON_LOCKSCREEN); - mService.updateWifiConnectionState(mWifiNetworkCapabilities); - when(mListeners.hasSensitiveContent(any())).thenReturn(true); - NotificationRecord record = getSensitiveNotificationRecord(); - mService.addNotification(record); - ManagedServices.ManagedServiceInfo info = mock(ManagedServices.ManagedServiceInfo.class); - when(info.enabledAndUserMatches(anyInt())).thenReturn(true); - when(info.isSameUser(anyInt())).thenReturn(true); - NotificationRankingUpdate nru = mService.makeRankingUpdateLocked(info); - NotificationListenerService.Ranking ranking = - nru.getRankingMap().getRawRankingObject(record.getSbn().getKey()); - assertTrue(ranking.hasSensitiveContent()); - } - - @Test - public void testMakeRankingUpdate_doesntClearHasSensitiveContentIfFlagDisabled() { - mSetFlagsRule.enableFlags(FLAG_REDACT_SENSITIVE_NOTIFICATIONS_FROM_UNTRUSTED_LISTENERS); - mSetFlagsRule.disableFlags(FLAG_REDACT_SENSITIVE_CONTENT_NOTIFICATIONS_ON_LOCKSCREEN); - mService.updateWifiConnectionState(mWifiNetworkCapabilities); - when(mListeners.hasSensitiveContent(any())).thenReturn(true); - NotificationRecord record = getSensitiveNotificationRecord(); - mService.addNotification(record); - ManagedServices.ManagedServiceInfo info = mock(ManagedServices.ManagedServiceInfo.class); - info.isSystemUi = true; - when(info.enabledAndUserMatches(anyInt())).thenReturn(true); - when(info.isSameUser(anyInt())).thenReturn(true); - NotificationRankingUpdate nru = mService.makeRankingUpdateLocked(info); - NotificationListenerService.Ranking ranking = - nru.getRankingMap().getRawRankingObject(record.getSbn().getKey()); - assertTrue(ranking.hasSensitiveContent()); - } - - @Test public void testMakeRankingUpdate_doestntRedactIfFlagDisabled() { mSetFlagsRule.disableFlags(FLAG_REDACT_SENSITIVE_NOTIFICATIONS_FROM_UNTRUSTED_LISTENERS); when(mListeners.isUidTrusted(anyInt())).thenReturn(false); diff --git a/services/tests/uiservicestests/src/com/android/server/notification/RoleObserverTest.java b/services/tests/uiservicestests/src/com/android/server/notification/RoleObserverTest.java index ad900fe6e376..31436c602e56 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/RoleObserverTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/RoleObserverTest.java @@ -47,7 +47,6 @@ import android.companion.ICompanionDeviceManager; import android.content.Context; import android.content.pm.IPackageManager; import android.content.pm.PackageManager; -import android.net.ConnectivityManager; import android.os.Handler; import android.os.Looper; import android.os.PowerManager; @@ -172,7 +171,6 @@ public class RoleObserverTest extends UiServiceTestCase { mock(NotificationChannelLogger.class), new TestableFlagResolver(), mock(PermissionManager.class), mock(PowerManager.class), - mock(ConnectivityManager.class), new NotificationManagerService.PostNotificationTrackerFactory() {}); } catch (SecurityException e) { if (!e.getMessage().contains("Permission Denial: not allowed to send broadcast")) { |