Loading core/java/android/service/notification/NotificationAssistantService.java +0 −2 Original line number Diff line number Diff line Loading @@ -37,9 +37,7 @@ import android.os.Looper; import android.os.Message; import android.os.RemoteException; import android.util.Log; import com.android.internal.os.SomeArgs; import java.lang.annotation.Retention; import java.util.List; Loading services/core/java/com/android/server/notification/NotificationManagerService.java +10 −1 Original line number Diff line number Diff line Loading @@ -5832,7 +5832,16 @@ public class NotificationManagerService extends SystemService { @Override public ComponentName getEffectsSuppressor() { return !mEffectsSuppressors.isEmpty() ? mEffectsSuppressors.get(0) : null; ComponentName suppressor = !mEffectsSuppressors.isEmpty() ? mEffectsSuppressors.get(0) : null; if (isCallerSystemOrSystemUiOrShell() || suppressor == null || mPackageManagerInternal.isSameApp(suppressor.getPackageName(), Binder.getCallingUid(), UserHandle.getUserId(Binder.getCallingUid()))) { return suppressor; } return null; } @Override Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +44 −0 Original line number Diff line number Diff line Loading @@ -99,6 +99,7 @@ import static android.service.notification.Flags.FLAG_REDACT_SENSITIVE_NOTIFICAT import static android.service.notification.NotificationListenerService.FLAG_FILTER_TYPE_ALERTING; import static android.service.notification.NotificationListenerService.FLAG_FILTER_TYPE_CONVERSATIONS; import static android.service.notification.NotificationListenerService.FLAG_FILTER_TYPE_ONGOING; import static android.service.notification.NotificationListenerService.HINT_HOST_DISABLE_EFFECTS; import static android.service.notification.NotificationListenerService.REASON_CANCEL; import static android.service.notification.NotificationListenerService.REASON_LOCKDOWN; import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_NEGATIVE; Loading Loading @@ -15673,4 +15674,47 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { // yay } } @Test public void testGetEffectsSuppressor_noSuppressor() throws Exception { when(mUmInternal.getProfileIds(anyInt(), anyBoolean())).thenReturn(new int[]{mUserId}); when(mListeners.checkServiceTokenLocked(any())).thenReturn(mListener); when(mPackageManagerInternal.isSameApp(anyString(), anyInt(), anyInt())).thenReturn(true); assertThat(mBinderService.getEffectsSuppressor()).isNull(); } @Test public void testGetEffectsSuppressor_suppressorSameApp() throws Exception { when(mUmInternal.getProfileIds(anyInt(), anyBoolean())).thenReturn(new int[]{mUserId}); when(mListeners.checkServiceTokenLocked(any())).thenReturn(mListener); mService.isSystemUid = false; mService.isSystemAppId = false; mBinderService.requestHintsFromListener(mock(INotificationListener.class), HINT_HOST_DISABLE_EFFECTS); when(mPackageManagerInternal.isSameApp(anyString(), anyInt(), anyInt())).thenReturn(true); assertThat(mBinderService.getEffectsSuppressor()).isEqualTo(mListener.component); } @Test public void testGetEffectsSuppressor_suppressorDiffApp() throws Exception { when(mUmInternal.getProfileIds(anyInt(), anyBoolean())).thenReturn(new int[]{mUserId}); when(mListeners.checkServiceTokenLocked(any())).thenReturn(mListener); mService.isSystemUid = false; mService.isSystemAppId = false; mBinderService.requestHintsFromListener(mock(INotificationListener.class), HINT_HOST_DISABLE_EFFECTS); when(mPackageManagerInternal.isSameApp(anyString(), anyInt(), anyInt())).thenReturn(false); assertThat(mBinderService.getEffectsSuppressor()).isEqualTo(null); } @Test public void testGetEffectsSuppressor_suppressorDiffAppSystemCaller() throws Exception { when(mUmInternal.getProfileIds(anyInt(), anyBoolean())).thenReturn(new int[]{mUserId}); when(mListeners.checkServiceTokenLocked(any())).thenReturn(mListener); mService.isSystemUid = true; mBinderService.requestHintsFromListener(mock(INotificationListener.class), HINT_HOST_DISABLE_EFFECTS); when(mPackageManagerInternal.isSameApp(anyString(), anyInt(), anyInt())).thenReturn(false); assertThat(mBinderService.getEffectsSuppressor()).isEqualTo(mListener.component); } } Loading
core/java/android/service/notification/NotificationAssistantService.java +0 −2 Original line number Diff line number Diff line Loading @@ -37,9 +37,7 @@ import android.os.Looper; import android.os.Message; import android.os.RemoteException; import android.util.Log; import com.android.internal.os.SomeArgs; import java.lang.annotation.Retention; import java.util.List; Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +10 −1 Original line number Diff line number Diff line Loading @@ -5832,7 +5832,16 @@ public class NotificationManagerService extends SystemService { @Override public ComponentName getEffectsSuppressor() { return !mEffectsSuppressors.isEmpty() ? mEffectsSuppressors.get(0) : null; ComponentName suppressor = !mEffectsSuppressors.isEmpty() ? mEffectsSuppressors.get(0) : null; if (isCallerSystemOrSystemUiOrShell() || suppressor == null || mPackageManagerInternal.isSameApp(suppressor.getPackageName(), Binder.getCallingUid(), UserHandle.getUserId(Binder.getCallingUid()))) { return suppressor; } return null; } @Override Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +44 −0 Original line number Diff line number Diff line Loading @@ -99,6 +99,7 @@ import static android.service.notification.Flags.FLAG_REDACT_SENSITIVE_NOTIFICAT import static android.service.notification.NotificationListenerService.FLAG_FILTER_TYPE_ALERTING; import static android.service.notification.NotificationListenerService.FLAG_FILTER_TYPE_CONVERSATIONS; import static android.service.notification.NotificationListenerService.FLAG_FILTER_TYPE_ONGOING; import static android.service.notification.NotificationListenerService.HINT_HOST_DISABLE_EFFECTS; import static android.service.notification.NotificationListenerService.REASON_CANCEL; import static android.service.notification.NotificationListenerService.REASON_LOCKDOWN; import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_NEGATIVE; Loading Loading @@ -15673,4 +15674,47 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { // yay } } @Test public void testGetEffectsSuppressor_noSuppressor() throws Exception { when(mUmInternal.getProfileIds(anyInt(), anyBoolean())).thenReturn(new int[]{mUserId}); when(mListeners.checkServiceTokenLocked(any())).thenReturn(mListener); when(mPackageManagerInternal.isSameApp(anyString(), anyInt(), anyInt())).thenReturn(true); assertThat(mBinderService.getEffectsSuppressor()).isNull(); } @Test public void testGetEffectsSuppressor_suppressorSameApp() throws Exception { when(mUmInternal.getProfileIds(anyInt(), anyBoolean())).thenReturn(new int[]{mUserId}); when(mListeners.checkServiceTokenLocked(any())).thenReturn(mListener); mService.isSystemUid = false; mService.isSystemAppId = false; mBinderService.requestHintsFromListener(mock(INotificationListener.class), HINT_HOST_DISABLE_EFFECTS); when(mPackageManagerInternal.isSameApp(anyString(), anyInt(), anyInt())).thenReturn(true); assertThat(mBinderService.getEffectsSuppressor()).isEqualTo(mListener.component); } @Test public void testGetEffectsSuppressor_suppressorDiffApp() throws Exception { when(mUmInternal.getProfileIds(anyInt(), anyBoolean())).thenReturn(new int[]{mUserId}); when(mListeners.checkServiceTokenLocked(any())).thenReturn(mListener); mService.isSystemUid = false; mService.isSystemAppId = false; mBinderService.requestHintsFromListener(mock(INotificationListener.class), HINT_HOST_DISABLE_EFFECTS); when(mPackageManagerInternal.isSameApp(anyString(), anyInt(), anyInt())).thenReturn(false); assertThat(mBinderService.getEffectsSuppressor()).isEqualTo(null); } @Test public void testGetEffectsSuppressor_suppressorDiffAppSystemCaller() throws Exception { when(mUmInternal.getProfileIds(anyInt(), anyBoolean())).thenReturn(new int[]{mUserId}); when(mListeners.checkServiceTokenLocked(any())).thenReturn(mListener); mService.isSystemUid = true; mBinderService.requestHintsFromListener(mock(INotificationListener.class), HINT_HOST_DISABLE_EFFECTS); when(mPackageManagerInternal.isSameApp(anyString(), anyInt(), anyInt())).thenReturn(false); assertThat(mBinderService.getEffectsSuppressor()).isEqualTo(mListener.component); } }