diff options
| author | 2015-10-06 19:48:44 +0000 | |
|---|---|---|
| committer | 2015-10-06 19:48:44 +0000 | |
| commit | 5686addb76ae43f362297abd81e79d73624e68d0 (patch) | |
| tree | 54d3ae4f4c925807d148a54266ed3d91f418712a | |
| parent | d18097bc2255dca3421b614bfe6636dededf4534 (diff) | |
| parent | 56106ff337e056d2daa5862545f4a06796d9e9a1 (diff) | |
Merge "Add id and creation date to Zen rules."
| -rw-r--r-- | api/current.txt | 2 | ||||
| -rw-r--r-- | api/system-current.txt | 2 | ||||
| -rw-r--r-- | core/java/android/app/AutomaticZenRule.java | 48 | ||||
| -rw-r--r-- | core/java/android/service/notification/ZenModeConfig.java | 36 | ||||
| -rw-r--r-- | services/core/java/com/android/server/notification/ZenModeHelper.java | 17 |
5 files changed, 96 insertions, 9 deletions
diff --git a/api/current.txt b/api/current.txt index 09361f208634..2331170c6748 100644 --- a/api/current.txt +++ b/api/current.txt @@ -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(); diff --git a/api/system-current.txt b/api/system-current.txt index 23805a3bd151..dacc338b0ce3 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -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(); diff --git a/core/java/android/app/AutomaticZenRule.java b/core/java/android/app/AutomaticZenRule.java index fea5624411ad..e5fa02b248f4 100644 --- a/core/java/android/app/AutomaticZenRule.java +++ b/core/java/android/app/AutomaticZenRule.java @@ -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(); } /** @@ -101,6 +118,20 @@ public class AutomaticZenRule implements Parcelable { } /** + * 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. */ public void setConditionId(Uri conditionId) { @@ -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 @@ -187,4 +229,4 @@ public class AutomaticZenRule implements Parcelable { return new AutomaticZenRule[size]; } }; -}
\ No newline at end of file +} diff --git a/core/java/android/service/notification/ZenModeConfig.java b/core/java/android/service/notification/ZenModeConfig.java index 4de903efff18..9a0f7fc811f2 100644 --- a/core/java/android/service/notification/ZenModeConfig.java +++ b/core/java/android/service/notification/ZenModeConfig.java @@ -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() { diff --git a/services/core/java/com/android/server/notification/ZenModeHelper.java b/services/core/java/com/android/server/notification/ZenModeHelper.java index 4d41e3a9d734..0d09fc2c7083 100644 --- a/services/core/java/com/android/server/notification/ZenModeHelper.java +++ b/services/core/java/com/android/server/notification/ZenModeHelper.java @@ -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) { |