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

Commit 5686addb authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

Merge "Add id and creation date to Zen rules."

parents d18097bc 56106ff3
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -4021,6 +4021,8 @@ package android.app {
    ctor public AutomaticZenRule(android.os.Parcel);
    method public int describeContents();
    method public android.net.Uri getConditionId();
    method public long getCreationTime();
    method public java.lang.String getId();
    method public int getInterruptionFilter();
    method public java.lang.String getName();
    method public android.content.ComponentName getOwner();
+2 −0
Original line number Diff line number Diff line
@@ -4132,6 +4132,8 @@ package android.app {
    ctor public AutomaticZenRule(android.os.Parcel);
    method public int describeContents();
    method public android.net.Uri getConditionId();
    method public long getCreationTime();
    method public java.lang.String getId();
    method public int getInterruptionFilter();
    method public java.lang.String getName();
    method public android.content.ComponentName getOwner();
+45 −3
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ public class AutomaticZenRule implements Parcelable {
    private int interruptionFilter;
    private Uri conditionId;
    private ComponentName owner;
    private String id;
    private long creationTime;

    /**
     * Creates an automatic zen rule.
@@ -55,6 +57,17 @@ public class AutomaticZenRule implements Parcelable {
        this.enabled = enabled;
    }

    /**
     * @SystemApi
     * @hide
     */
    public AutomaticZenRule(String name, ComponentName owner, Uri conditionId,
            int interruptionFilter, boolean enabled, String id, long creationTime) {
        this(name, owner, conditionId, interruptionFilter, enabled);
        this.id = id;
        this.creationTime = creationTime;
    }

    public AutomaticZenRule(Parcel source) {
        enabled = source.readInt() == 1;
        if (source.readInt() == 1) {
@@ -63,6 +76,10 @@ public class AutomaticZenRule implements Parcelable {
        interruptionFilter = source.readInt();
        conditionId = source.readParcelable(null);
        owner = source.readParcelable(null);
        if (source.readInt() == 1) {
            id = source.readString();
        }
        creationTime = source.readLong();
    }

    /**
@@ -100,6 +117,20 @@ public class AutomaticZenRule implements Parcelable {
        return enabled;
    }

    /**
     * Returns the wall time in milliseconds when this rule was created, if known.
     */
    public long getCreationTime() {
      return creationTime;
    }

    /**
     * Returns the unique identifier for this rule.
     */
    public String getId() {
      return id;
    }

    /**
     * Sets the representation of the state that causes this rule to become active.
     */
@@ -146,6 +177,13 @@ public class AutomaticZenRule implements Parcelable {
        dest.writeInt(interruptionFilter);
        dest.writeParcelable(conditionId, 0);
        dest.writeParcelable(owner, 0);
        if (id != null) {
            dest.writeInt(1);
            dest.writeString(id);
        } else {
            dest.writeInt(0);
        }
        dest.writeLong(creationTime);
    }

    @Override
@@ -156,6 +194,8 @@ public class AutomaticZenRule implements Parcelable {
                .append(",interruptionFilter=").append(interruptionFilter)
                .append(",conditionId=").append(conditionId)
                .append(",owner=").append(owner)
                .append(",id=").append(id)
                .append(",creationTime=").append(creationTime)
                .append(']').toString();
    }

@@ -168,12 +208,14 @@ public class AutomaticZenRule implements Parcelable {
                && Objects.equals(other.name, name)
                && other.interruptionFilter == interruptionFilter
                && Objects.equals(other.conditionId, conditionId)
                && Objects.equals(other.owner, owner);
                && Objects.equals(other.owner, owner)
                && Objects.equals(other.id, id)
                && other.creationTime == creationTime;
    }

    @Override
    public int hashCode() {
        return Objects.hash(enabled, name, interruptionFilter, conditionId, owner);
        return Objects.hash(enabled, name, interruptionFilter, conditionId, owner, id, creationTime);
    }

    public static final Parcelable.Creator<AutomaticZenRule> CREATOR
+34 −2
Original line number Diff line number Diff line
@@ -110,6 +110,7 @@ public class ZenModeConfig implements Parcelable {
    private static final String RULE_ATT_COMPONENT = "component";
    private static final String RULE_ATT_ZEN = "zen";
    private static final String RULE_ATT_CONDITION_ID = "conditionId";
    private static final String RULE_ATT_CREATION_TIME = "creationTime";

    public boolean allowCalls = DEFAULT_ALLOW_CALLS;
    public boolean allowRepeatCallers = DEFAULT_ALLOW_REPEAT_CALLERS;
@@ -415,6 +416,7 @@ public class ZenModeConfig implements Parcelable {
                    final String id = parser.getAttributeValue(null, RULE_ATT_ID);
                    final ZenRule automaticRule = readRuleXml(parser);
                    if (id != null && automaticRule != null) {
                        automaticRule.id = id;
                        rt.automaticRules.put(id, automaticRule);
                    }
                }
@@ -468,6 +470,7 @@ public class ZenModeConfig implements Parcelable {
        }
        rt.conditionId = safeUri(parser, RULE_ATT_CONDITION_ID);
        rt.component = safeComponentName(parser, RULE_ATT_COMPONENT);
        rt.creationTime = safeLong(parser, RULE_ATT_CREATION_TIME, 0);
        rt.condition = readConditionXml(parser);
        return rt;
    }
@@ -485,6 +488,7 @@ public class ZenModeConfig implements Parcelable {
        if (rule.conditionId != null) {
            out.attribute(null, RULE_ATT_CONDITION_ID, rule.conditionId.toString());
        }
        out.attribute(null, RULE_ATT_CREATION_TIME, Long.toString(rule.creationTime));
        if (rule.condition != null) {
            writeConditionXml(rule.condition, out);
        }
@@ -552,6 +556,11 @@ public class ZenModeConfig implements Parcelable {
        return Uri.parse(val);
    }

    private static long safeLong(XmlPullParser parser, String att, long defValue) {
        final String val = parser.getAttributeValue(null, att);
        return tryParseLong(val, defValue);
    }

    public ArraySet<String> getAutomaticRuleNames() {
        final ArraySet<String> rt = new ArraySet<String>();
        for (int i = 0; i < automaticRules.size(); i++) {
@@ -943,6 +952,8 @@ public class ZenModeConfig implements Parcelable {
        public Uri conditionId;          // required for automatic
        public Condition condition;      // optional
        public ComponentName component;  // optional
        public String id;                // required for automatic (unique)
        public long creationTime;        // required for automatic

        public ZenRule() { }

@@ -956,6 +967,10 @@ public class ZenModeConfig implements Parcelable {
            conditionId = source.readParcelable(null);
            condition = source.readParcelable(null);
            component = source.readParcelable(null);
            if (source.readInt() == 1) {
                id = source.readString();
            }
            creationTime = source.readLong();
        }

        @Override
@@ -977,6 +992,13 @@ public class ZenModeConfig implements Parcelable {
            dest.writeParcelable(conditionId, 0);
            dest.writeParcelable(condition, 0);
            dest.writeParcelable(component, 0);
            if (id != null) {
                dest.writeInt(1);
                dest.writeString(id);
            } else {
                dest.writeInt(0);
            }
            dest.writeLong(creationTime);
        }

        @Override
@@ -989,6 +1011,8 @@ public class ZenModeConfig implements Parcelable {
                    .append(",conditionId=").append(conditionId)
                    .append(",condition=").append(condition)
                    .append(",component=").append(component)
                    .append(",id=").append(id)
                    .append(",creationTime=").append(creationTime)
                    .append(']').toString();
        }

@@ -1029,6 +1053,12 @@ public class ZenModeConfig implements Parcelable {
            if (!Objects.equals(component, to.component)) {
                d.addLine(item, "component", component, to.component);
            }
            if (!Objects.equals(id, to.id)) {
                d.addLine(item, "id", id, to.id);
            }
            if (creationTime == to.creationTime) {
                d.addLine(item, "creationTime", creationTime, to.creationTime);
            }
        }

        @Override
@@ -1042,13 +1072,15 @@ public class ZenModeConfig implements Parcelable {
                    && other.zenMode == zenMode
                    && Objects.equals(other.conditionId, conditionId)
                    && Objects.equals(other.condition, condition)
                    && Objects.equals(other.component, component);
                    && Objects.equals(other.component, component)
                    && Objects.equals(other.id, id)
                    && other.creationTime == creationTime;
        }

        @Override
        public int hashCode() {
            return Objects.hash(enabled, snoozing, name, zenMode, conditionId, condition,
                    component);
                    component, id, creationTime);
        }

        public boolean isAutomaticActive() {
+13 −4
Original line number Diff line number Diff line
@@ -232,6 +232,8 @@ public class ZenModeHelper {
        ZenModeConfig.ZenRule rule = new ZenModeConfig.ZenRule();
        if (ruleId == null) {
            ruleId = newConfig.newRuleId();
            rule.id = ruleId;
            rule.creationTime = System.currentTimeMillis();
            rule.name = automaticZenRule.getName();
            rule.component = automaticZenRule.getOwner();
        } else {
@@ -312,7 +314,8 @@ public class ZenModeHelper {

    private AutomaticZenRule createAutomaticZenRule(ZenRule rule) {
        return new AutomaticZenRule(rule.name, rule.component, rule.conditionId,
                NotificationManager.zenModeToInterruptionFilter(rule.zenMode), rule.enabled);
                NotificationManager.zenModeToInterruptionFilter(rule.zenMode), rule.enabled,
                rule.id, rule.creationTime);
    }

    public void setManualZenMode(int zenMode, Uri conditionId, String reason) {
@@ -640,7 +643,9 @@ public class ZenModeHelper {
        rule1.conditionId = ZenModeConfig.toScheduleConditionId(weeknights);
        rule1.zenMode = Global.ZEN_MODE_ALARMS;
        rule1.component = ScheduleConditionProvider.COMPONENT;
        config.automaticRules.put(config.newRuleId(), rule1);
        rule1.id = config.newRuleId();
        rule1.creationTime = System.currentTimeMillis();
        config.automaticRules.put(rule1.id, rule1);

        final ScheduleInfo weekends = new ScheduleInfo();
        weekends.days = ZenModeConfig.WEEKEND_DAYS;
@@ -654,7 +659,9 @@ public class ZenModeHelper {
        rule2.conditionId = ZenModeConfig.toScheduleConditionId(weekends);
        rule2.zenMode = Global.ZEN_MODE_ALARMS;
        rule2.component = ScheduleConditionProvider.COMPONENT;
        config.automaticRules.put(config.newRuleId(), rule2);
        rule2.id = config.newRuleId();
        rule2.creationTime = System.currentTimeMillis();
        config.automaticRules.put(rule2.id, rule2);
    }

    private void appendDefaultEventRules(ZenModeConfig config) {
@@ -669,7 +676,9 @@ public class ZenModeHelper {
        rule.conditionId = ZenModeConfig.toEventConditionId(events);
        rule.zenMode = Global.ZEN_MODE_ALARMS;
        rule.component = EventConditionProvider.COMPONENT;
        config.automaticRules.put(config.newRuleId(), rule);
        rule.id = config.newRuleId();
        rule.creationTime = System.currentTimeMillis();
        config.automaticRules.put(rule.id, rule);
    }

    private static int zenSeverity(int zen) {