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

Commit 6faa5b8c authored by Matías Hernández's avatar Matías Hernández Committed by Android (Google) Code Review
Browse files

Merge "Fix getAutomaticZenRules to use proper conversion" into main

parents f283fec0 0c7fa7c6
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -214,6 +214,8 @@ interface INotificationManager
    void setNotificationPolicyAccessGranted(String pkg, boolean granted);
    void setNotificationPolicyAccessGranted(String pkg, boolean granted);
    void setNotificationPolicyAccessGrantedForUser(String pkg, int userId, boolean granted);
    void setNotificationPolicyAccessGrantedForUser(String pkg, int userId, boolean granted);
    AutomaticZenRule getAutomaticZenRule(String id);
    AutomaticZenRule getAutomaticZenRule(String id);
    Map<String, AutomaticZenRule> getAutomaticZenRules();
    // TODO: b/310620812 - Remove getZenRules() when MODES_API is inlined.
    List<ZenModeConfig.ZenRule> getZenRules();
    List<ZenModeConfig.ZenRule> getZenRules();
    String addAutomaticZenRule(in AutomaticZenRule automaticZenRule, String pkg);
    String addAutomaticZenRule(in AutomaticZenRule automaticZenRule, String pkg);
    boolean updateAutomaticZenRule(String id, in AutomaticZenRule automaticZenRule);
    boolean updateAutomaticZenRule(String id, in AutomaticZenRule automaticZenRule);
+14 −10
Original line number Original line Diff line number Diff line
@@ -1256,6 +1256,9 @@ public class NotificationManager {
    public Map<String, AutomaticZenRule> getAutomaticZenRules() {
    public Map<String, AutomaticZenRule> getAutomaticZenRules() {
        INotificationManager service = getService();
        INotificationManager service = getService();
        try {
        try {
            if (Flags.modesApi()) {
                return service.getAutomaticZenRules();
            } else {
                List<ZenModeConfig.ZenRule> rules = service.getZenRules();
                List<ZenModeConfig.ZenRule> rules = service.getZenRules();
                Map<String, AutomaticZenRule> ruleMap = new HashMap<>();
                Map<String, AutomaticZenRule> ruleMap = new HashMap<>();
                for (ZenModeConfig.ZenRule rule : rules) {
                for (ZenModeConfig.ZenRule rule : rules) {
@@ -1267,6 +1270,7 @@ public class NotificationManager {
                    ruleMap.put(rule.id, azr);
                    ruleMap.put(rule.id, azr);
                }
                }
                return ruleMap;
                return ruleMap;
            }
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
+12 −1
Original line number Original line Diff line number Diff line
@@ -360,6 +360,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.LinkedList;
import java.util.List;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Objects;
import java.util.Set;
import java.util.Set;
@@ -5245,12 +5246,22 @@ public class NotificationManagerService extends SystemService {
            }
            }
        }
        }
        // TODO: b/310620812 - Remove getZenRules() when MODES_API is inlined.
        @Override
        @Override
        public List<ZenModeConfig.ZenRule> getZenRules() throws RemoteException {
        public List<ZenModeConfig.ZenRule> getZenRules() throws RemoteException {
            enforcePolicyAccess(Binder.getCallingUid(), "getAutomaticZenRules");
            enforcePolicyAccess(Binder.getCallingUid(), "getZenRules");
            return mZenModeHelper.getZenRules();
            return mZenModeHelper.getZenRules();
        }
        }
        @Override
        public Map<String, AutomaticZenRule> getAutomaticZenRules() {
            if (!android.app.Flags.modesApi()) {
                throw new IllegalStateException("getAutomaticZenRules called with flag off!");
            }
            enforcePolicyAccess(Binder.getCallingUid(), "getAutomaticZenRules");
            return mZenModeHelper.getAutomaticZenRules();
        }
        @Override
        @Override
        public AutomaticZenRule getAutomaticZenRule(String id) throws RemoteException {
        public AutomaticZenRule getAutomaticZenRule(String id) throws RemoteException {
            Objects.requireNonNull(id, "Id is null");
            Objects.requireNonNull(id, "Id is null");
+17 −0
Original line number Original line Diff line number Diff line
@@ -106,7 +106,9 @@ import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Objects;


/**
/**
@@ -334,6 +336,7 @@ public class ZenModeHelper {
        return mZenMode;
        return mZenMode;
    }
    }


    // TODO: b/310620812 - Make private (or inline) when MODES_API is inlined.
    public List<ZenRule> getZenRules() {
    public List<ZenRule> getZenRules() {
        List<ZenRule> rules = new ArrayList<>();
        List<ZenRule> rules = new ArrayList<>();
        synchronized (mConfigLock) {
        synchronized (mConfigLock) {
@@ -347,6 +350,20 @@ public class ZenModeHelper {
        return rules;
        return rules;
    }
    }


    /**
     * Get the list of {@link AutomaticZenRule} instances that the calling package can manage
     * (which means the owned rules for a regular app, and every rule for system callers) together
     * with their ids.
     */
    Map<String, AutomaticZenRule> getAutomaticZenRules() {
        List<ZenRule> ruleList = getZenRules();
        HashMap<String, AutomaticZenRule> rules = new HashMap<>(ruleList.size());
        for (ZenRule rule : ruleList) {
            rules.put(rule.id, zenRuleToAutomaticZenRule(rule));
        }
        return rules;
    }

    public AutomaticZenRule getAutomaticZenRule(String id) {
    public AutomaticZenRule getAutomaticZenRule(String id) {
        ZenRule rule;
        ZenRule rule;
        synchronized (mConfigLock) {
        synchronized (mConfigLock) {