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

Commit f77e8020 authored by Matías Hernández's avatar Matías Hernández
Browse files

Add NM.getAutomaticZenRuleState() API

Since rules can be triggered externally on V, apps need a way to query their current state.

Test: atest ZenModeHelperTest
Bug: 326047233
Change-Id: I245408f631b3cc5b558df3c7ae2f73762459c616
parent fed62d90
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -7011,6 +7011,7 @@ package android.app {
    method public void deleteNotificationChannelGroup(String);
    method public android.service.notification.StatusBarNotification[] getActiveNotifications();
    method public android.app.AutomaticZenRule getAutomaticZenRule(String);
    method @FlaggedApi("android.app.modes_api") public int getAutomaticZenRuleState(@NonNull String);
    method public java.util.Map<java.lang.String,android.app.AutomaticZenRule> getAutomaticZenRules();
    method public int getBubblePreference();
    method @NonNull public android.app.NotificationManager.Policy getConsolidatedNotificationPolicy();
+1 −0
Original line number Diff line number Diff line
@@ -225,6 +225,7 @@ interface INotificationManager
    boolean removeAutomaticZenRule(String id, boolean fromUser);
    boolean removeAutomaticZenRules(String packageName, boolean fromUser);
    int getRuleInstanceCount(in ComponentName owner);
    int getAutomaticZenRuleState(String id);
    void setAutomaticZenRuleState(String id, in Condition condition);

    byte[] getBackupPayload(int user);
+20 −0
Original line number Diff line number Diff line
@@ -1405,6 +1405,26 @@ public class NotificationManager {
        }
    }

    /**
     * Returns the current activation state of an {@link AutomaticZenRule}.
     *
     * <p>Returns {@link Condition#STATE_UNKNOWN} if the rule does not exist or the calling
     * package doesn't have access to it.
     *
     * @param id The id of the rule
     * @return the state of the rule.
     */
    @FlaggedApi(Flags.FLAG_MODES_API)
    @Condition.State
    public int getAutomaticZenRuleState(@NonNull String id) {
        INotificationManager service = getService();
        try {
            return service.getAutomaticZenRuleState(id);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Informs the notification manager that the state of an {@link AutomaticZenRule} has changed.
     * Use this method to put the system into Do Not Disturb mode or request that it exits Do Not
+8 −0
Original line number Diff line number Diff line
@@ -5720,6 +5720,14 @@ public class NotificationManagerService extends SystemService {
            return mZenModeHelper.getCurrentInstanceCount(owner);
        }
        @Override
        @Condition.State
        public int getAutomaticZenRuleState(@NonNull String id) {
            Objects.requireNonNull(id, "id is null");
            enforcePolicyAccess(Binder.getCallingUid(), "getAutomaticZenRuleState");
            return mZenModeHelper.getAutomaticZenRuleState(id);
        }
        @Override
        public void setAutomaticZenRuleState(String id, Condition condition) {
            Objects.requireNonNull(id, "id is null");
+14 −0
Original line number Diff line number Diff line
@@ -856,6 +856,20 @@ public class ZenModeHelper {
        }
    }

    @Condition.State
    int getAutomaticZenRuleState(String id) {
        synchronized (mConfigLock) {
            if (mConfig == null) {
                return Condition.STATE_UNKNOWN;
            }
            ZenRule rule = mConfig.automaticRules.get(id);
            if (rule == null || !canManageAutomaticZenRule(rule)) {
                return Condition.STATE_UNKNOWN;
            }
            return rule.condition != null ? rule.condition.state : Condition.STATE_FALSE;
        }
    }

    void setAutomaticZenRuleState(String id, Condition condition, @ConfigChangeOrigin int origin,
            int callingUid) {
        requirePublicOrigin("setAutomaticZenRuleState", origin);
Loading