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

Commit e0bf51a8 authored by Yuri Lin's avatar Yuri Lin Committed by Android Build Coastguard Worker
Browse files

Revert "Fix system zen rules by using owner package name if caller is system"

This reverts commit e5e51116.

Reason for revert: broke DND schedules in multi-user mode b/257477671

Change-Id: Ic5126e4c95c8ef8c17b339a6fb0f08ca9cc97323
(cherry picked from commit 3535f5cb)
Merged-In: Ic5126e4c95c8ef8c17b339a6fb0f08ca9cc97323
parent b1ad676f
Loading
Loading
Loading
Loading
+1 −10
Original line number Diff line number Diff line
@@ -4958,16 +4958,7 @@ public class NotificationManagerService extends SystemService {
            }
            enforcePolicyAccess(Binder.getCallingUid(), "addAutomaticZenRule");
            // If the caller is system, take the package name from the rule's owner rather than
            // from the caller's package.
            String rulePkg = pkg;
            if (isCallingUidSystem()) {
                if (automaticZenRule.getOwner() != null) {
                    rulePkg = automaticZenRule.getOwner().getPackageName();
                }
            }
            return mZenModeHelper.addAutomaticZenRule(rulePkg, automaticZenRule,
            return mZenModeHelper.addAutomaticZenRule(pkg, automaticZenRule,
                    "addAutomaticZenRule");
        }
+0 −37
Original line number Diff line number Diff line
@@ -7548,43 +7548,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        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
    public void testAreNotificationsEnabledForPackage() throws Exception {
        mBinderService.areNotificationsEnabledForPackage(mContext.getPackageName(),