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

Commit c62eed79 authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

Merge "Restrict getEffectsSuppressor" into main

parents d337fa79 97cbe4a7
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -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;

+10 −1
Original line number Diff line number Diff line
@@ -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
+44 −0
Original line number Diff line number Diff line
@@ -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;
@@ -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);
    }
}