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

Commit 1d34dc7c authored by Yuri Lin's avatar Yuri Lin
Browse files

[conflict] Merge "Use rule package name in addAutomaticZenRule; specify...

[conflict] Merge "Use rule package name in addAutomaticZenRule; specify "android" for all system apps" into tm-dev am: 0232c797

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20506676



Change-Id: I20a759905063d95e44cc5e65c09f43407175cddb
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 27393bb4 0232c797
Loading
Loading
Loading
Loading
+9 −3
Original line number Original line Diff line number Diff line
@@ -4932,10 +4932,10 @@ public class NotificationManagerService extends SystemService {
            }
            }
            enforcePolicyAccess(Binder.getCallingUid(), "addAutomaticZenRule");
            enforcePolicyAccess(Binder.getCallingUid(), "addAutomaticZenRule");
            // If the caller is system, take the package name from the rule's owner rather than
            // If the calling app is the system (from any user), take the package name from the
            // from the caller's package.
            // rule's owner rather than from the caller's package.
            String rulePkg = pkg;
            String rulePkg = pkg;
            if (isCallingUidSystem()) {
            if (isCallingAppIdSystem()) {
                if (automaticZenRule.getOwner() != null) {
                if (automaticZenRule.getOwner() != null) {
                    rulePkg = automaticZenRule.getOwner().getPackageName();
                    rulePkg = automaticZenRule.getOwner().getPackageName();
                }
                }
@@ -9667,6 +9667,12 @@ public class NotificationManagerService extends SystemService {
        return uid == Process.SYSTEM_UID;
        return uid == Process.SYSTEM_UID;
    }
    }
    protected boolean isCallingAppIdSystem() {
        final int uid = Binder.getCallingUid();
        final int appid = UserHandle.getAppId(uid);
        return appid == Process.SYSTEM_UID;
    }
    protected boolean isUidSystemOrPhone(int uid) {
    protected boolean isUidSystemOrPhone(int uid) {
        final int appid = UserHandle.getAppId(uid);
        final int appid = UserHandle.getAppId(uid);
        return (appid == Process.SYSTEM_UID || appid == Process.PHONE_UID
        return (appid == Process.SYSTEM_UID || appid == Process.PHONE_UID
+22 −0
Original line number Original line Diff line number Diff line
@@ -7406,9 +7406,31 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        verify(mockZenModeHelper).addAutomaticZenRule(eq("android"), eq(rule), anyString());
        verify(mockZenModeHelper).addAutomaticZenRule(eq("android"), eq(rule), anyString());
    }
    }


    @Test
    public void testAddAutomaticZenRule_systemAppIdCallTakesPackageFromOwner() throws Exception {
        // The multi-user case: where the calling uid doesn't match the system uid, but the calling
        // *appid* is the system.
        mService.isSystemUid = false;
        mService.isSystemAppId = true;
        ZenModeHelper mockZenModeHelper = mock(ZenModeHelper.class);
        when(mConditionProviders.isPackageOrComponentAllowed(anyString(), anyInt()))
                .thenReturn(true);
        mService.setZenHelper(mockZenModeHelper);
        ComponentName owner = new ComponentName("android", "ProviderName");
        ZenPolicy zenPolicy = new ZenPolicy.Builder().allowAlarms(true).build();
        boolean isEnabled = true;
        AutomaticZenRule rule = new AutomaticZenRule("test", owner, owner, mock(Uri.class),
                zenPolicy, NotificationManager.INTERRUPTION_FILTER_PRIORITY, isEnabled);
        mBinderService.addAutomaticZenRule(rule, "com.android.settings");

        // verify that zen mode helper gets passed in a package name of "android"
        verify(mockZenModeHelper).addAutomaticZenRule(eq("android"), eq(rule), anyString());
    }

    @Test
    @Test
    public void testAddAutomaticZenRule_nonSystemCallTakesPackageFromArg() throws Exception {
    public void testAddAutomaticZenRule_nonSystemCallTakesPackageFromArg() throws Exception {
        mService.isSystemUid = false;
        mService.isSystemUid = false;
        mService.isSystemAppId = false;
        ZenModeHelper mockZenModeHelper = mock(ZenModeHelper.class);
        ZenModeHelper mockZenModeHelper = mock(ZenModeHelper.class);
        when(mConditionProviders.isPackageOrComponentAllowed(anyString(), anyInt()))
        when(mConditionProviders.isPackageOrComponentAllowed(anyString(), anyInt()))
                .thenReturn(true);
                .thenReturn(true);
+7 −0
Original line number Original line Diff line number Diff line
@@ -32,6 +32,7 @@ import java.util.Set;
public class TestableNotificationManagerService extends NotificationManagerService {
public class TestableNotificationManagerService extends NotificationManagerService {
    int countSystemChecks = 0;
    int countSystemChecks = 0;
    boolean isSystemUid = true;
    boolean isSystemUid = true;
    boolean isSystemAppId = true;
    int countLogSmartSuggestionsVisible = 0;
    int countLogSmartSuggestionsVisible = 0;
    Set<Integer> mChannelToastsSent = new HashSet<>();
    Set<Integer> mChannelToastsSent = new HashSet<>();


@@ -57,6 +58,12 @@ public class TestableNotificationManagerService extends NotificationManagerServi
        return isSystemUid;
        return isSystemUid;
    }
    }


    @Override
    protected boolean isCallingAppIdSystem() {
        countSystemChecks++;
        return isSystemUid || isSystemAppId;
    }

    @Override
    @Override
    protected boolean isCallerSystemOrPhone() {
    protected boolean isCallerSystemOrPhone() {
        countSystemChecks++;
        countSystemChecks++;