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

Commit be3ac33d authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Merge cherrypicks of [20404656, 20406274] into security-aosp-sc-v2-release.

Change-Id: I3aee8c5b65d302e0e37aef56021b54b6fc85086c
parents b9f77bae 6a7aca4c
Loading
Loading
Loading
Loading
+1 −10
Original line number Original line Diff line number Diff line
@@ -4774,16 +4774,7 @@ 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
            return mZenModeHelper.addAutomaticZenRule(pkg, automaticZenRule,
            // from the caller's package.
            String rulePkg = pkg;
            if (isCallingUidSystem()) {
                if (automaticZenRule.getOwner() != null) {
                    rulePkg = automaticZenRule.getOwner().getPackageName();
                }
            }

            return mZenModeHelper.addAutomaticZenRule(rulePkg, automaticZenRule,
                    "addAutomaticZenRule");
                    "addAutomaticZenRule");
        }
        }


+0 −37
Original line number Original line Diff line number Diff line
@@ -6714,43 +6714,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        mBinderService.addAutomaticZenRule(rule, mContext.getPackageName());
        mBinderService.addAutomaticZenRule(rule, mContext.getPackageName());
    }
    }


    @Test
    public void testAddAutomaticZenRule_systemCallTakesPackageFromOwner() throws Exception {
        mService.isSystemUid = 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
    public void testAddAutomaticZenRule_nonSystemCallTakesPackageFromArg() throws Exception {
        mService.isSystemUid = false;
        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, "another.package");

        // verify that zen mode helper gets passed in the package name from the arg, not the owner
        verify(mockZenModeHelper).addAutomaticZenRule(
                eq("another.package"), eq(rule), anyString());
    }

    @Test
    @Test
    public void testAreNotificationsEnabledForPackage_crossUser() throws Exception {
    public void testAreNotificationsEnabledForPackage_crossUser() throws Exception {
        try {
        try {