Loading packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java +73 −5 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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 { Loading Loading @@ -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 Loading Loading @@ -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); Loading Loading @@ -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, Loading @@ -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)); Loading @@ -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, Loading @@ -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); Loading @@ -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, Loading @@ -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, Loading Loading @@ -1155,6 +1222,7 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase { mFakeFeatureFlags, mDeviceUnlockedInteractorLazy, mKeyguardInteractorLazy, mWifiRepositoryLazy, null //CoroutineScope ); } Loading packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java +45 −12 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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; Loading @@ -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. Loading Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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(); } }); }); } } Loading Loading @@ -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()) { Loading @@ -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; } Loading services/core/java/com/android/server/notification/NotificationManagerService.java +0 −41 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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()) { Loading Loading @@ -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)); Loading Loading @@ -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. */ Loading Loading @@ -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, Loading Loading @@ -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, services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +1 −90 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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 = Loading Loading @@ -575,9 +570,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Mock NotificationAttentionHelper mAttentionHelper; @Mock NetworkCapabilities mWifiNetworkCapabilities; private NotificationManagerService.WorkerHandler mWorkerHandler; private Handler mBroadcastsHandler; Loading Loading @@ -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(); } Loading Loading @@ -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); Loading Loading @@ -14420,78 +14403,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { return record; } @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); services/tests/uiservicestests/src/com/android/server/notification/RoleObserverTest.java +0 −2 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java +73 −5 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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 { Loading Loading @@ -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 Loading Loading @@ -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); Loading Loading @@ -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, Loading @@ -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)); Loading @@ -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, Loading @@ -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); Loading @@ -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, Loading @@ -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, Loading Loading @@ -1155,6 +1222,7 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase { mFakeFeatureFlags, mDeviceUnlockedInteractorLazy, mKeyguardInteractorLazy, mWifiRepositoryLazy, null //CoroutineScope ); } Loading
packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java +45 −12 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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; Loading @@ -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. Loading Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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(); } }); }); } } Loading Loading @@ -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()) { Loading @@ -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; } Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +0 −41 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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()) { Loading Loading @@ -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)); Loading Loading @@ -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. */ Loading Loading @@ -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, Loading Loading @@ -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,
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +1 −90 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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 = Loading Loading @@ -575,9 +570,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Mock NotificationAttentionHelper mAttentionHelper; @Mock NetworkCapabilities mWifiNetworkCapabilities; private NotificationManagerService.WorkerHandler mWorkerHandler; private Handler mBroadcastsHandler; Loading Loading @@ -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(); } Loading Loading @@ -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); Loading Loading @@ -14420,78 +14403,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { return record; } @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);
services/tests/uiservicestests/src/com/android/server/notification/RoleObserverTest.java +0 −2 File changed.Preview size limit exceeded, changes collapsed. Show changes