summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Spurlock <jspurlock@google.com>2015-05-28 22:13:03 -0400
committerJohn Spurlock <jspurlock@google.com>2015-05-28 22:13:03 -0400
commit995a749f278b45a2931b2846a60a8231dfd755b4 (patch)
treebfda222f3a3c9d38ed2a1490f5bfadaaa3762041
parent35ef0a626c89af03d40df1a4eda73aa6725c0941 (diff)
downloadframeworks_base-995a749f278b45a2931b2846a60a8231dfd755b4.zip
frameworks_base-995a749f278b45a2931b2846a60a8231dfd755b4.tar.gz
frameworks_base-995a749f278b45a2931b2846a60a8231dfd755b4.tar.bz2
Zen: Use account name instead of calendar id in event conditions.
- Migrate the existing calendar attribute in the event condition from a long calendar id to the calendar account name. More portable across a backup/restore. - Also skip restoring transient state (like the current condition state) from restored automatic rules. Bug: 17755700 Change-Id: I9bdb421d2209e3ce90873008665c254d67c788d2
-rw-r--r--core/java/android/service/notification/ZenModeConfig.java21
-rw-r--r--services/core/java/com/android/server/notification/CalendarTracker.java4
-rw-r--r--services/core/java/com/android/server/notification/EventConditionProvider.java2
-rw-r--r--services/core/java/com/android/server/notification/ZenModeHelper.java9
4 files changed, 20 insertions, 16 deletions
diff --git a/core/java/android/service/notification/ZenModeConfig.java b/core/java/android/service/notification/ZenModeConfig.java
index 1da46d0..db19f7a 100644
--- a/core/java/android/service/notification/ZenModeConfig.java
+++ b/core/java/android/service/notification/ZenModeConfig.java
@@ -410,10 +410,10 @@ public class ZenModeConfig implements Parcelable {
rt.allowMessagesFrom = DEFAULT_SOURCE;
}
} else if (MANUAL_TAG.equals(tag)) {
- rt.manualRule = readRuleXml(parser, false /*conditionRequired*/);
+ rt.manualRule = readRuleXml(parser);
} else if (AUTOMATIC_TAG.equals(tag)) {
final String id = parser.getAttributeValue(null, RULE_ATT_ID);
- final ZenRule automaticRule = readRuleXml(parser, true /*conditionRequired*/);
+ final ZenRule automaticRule = readRuleXml(parser);
if (id != null && automaticRule != null) {
rt.automaticRules.put(id, automaticRule);
}
@@ -455,7 +455,7 @@ public class ZenModeConfig implements Parcelable {
out.endTag(null, ZEN_TAG);
}
- public static ZenRule readRuleXml(XmlPullParser parser, boolean conditionRequired) {
+ public static ZenRule readRuleXml(XmlPullParser parser) {
final ZenRule rt = new ZenRule();
rt.enabled = safeBoolean(parser, RULE_ATT_ENABLED, true);
rt.snoozing = safeBoolean(parser, RULE_ATT_SNOOZING, false);
@@ -801,7 +801,7 @@ public class ZenModeConfig implements Parcelable {
.authority(SYSTEM_AUTHORITY)
.appendPath(EVENT_PATH)
.appendQueryParameter("userId", Long.toString(event.userId))
- .appendQueryParameter("calendar", Long.toString(event.calendar))
+ .appendQueryParameter("calendar", event.calendar != null ? event.calendar : "")
.appendQueryParameter("reply", Integer.toString(event.reply))
.build();
}
@@ -819,21 +819,21 @@ public class ZenModeConfig implements Parcelable {
if (!isEvent) return null;
final EventInfo rt = new EventInfo();
rt.userId = tryParseInt(conditionId.getQueryParameter("userId"), UserHandle.USER_NULL);
- rt.calendar = tryParseLong(conditionId.getQueryParameter("calendar"),
- EventInfo.ANY_CALENDAR);
+ rt.calendar = conditionId.getQueryParameter("calendar");
+ if (TextUtils.isEmpty(rt.calendar) || tryParseLong(rt.calendar, -1L) != -1L) {
+ rt.calendar = null;
+ }
rt.reply = tryParseInt(conditionId.getQueryParameter("reply"), 0);
return rt;
}
public static class EventInfo {
- public static final long ANY_CALENDAR = 0;
-
public static final int REPLY_ANY_EXCEPT_NO = 0;
public static final int REPLY_YES_OR_MAYBE = 1;
public static final int REPLY_YES = 2;
public int userId = UserHandle.USER_NULL; // USER_NULL = unspecified - use current user
- public long calendar = ANY_CALENDAR; // CalendarContract.Calendars._ID, or ANY_CALENDAR
+ public String calendar; // CalendarContract.Calendars.OWNER_ACCOUNT, or null for any
public int reply;
@Override
@@ -846,7 +846,7 @@ public class ZenModeConfig implements Parcelable {
if (!(o instanceof EventInfo)) return false;
final EventInfo other = (EventInfo) o;
return userId == other.userId
- && calendar == other.calendar
+ && Objects.equals(calendar, other.calendar)
&& reply == other.reply;
}
@@ -860,7 +860,6 @@ public class ZenModeConfig implements Parcelable {
public static int resolveUserId(int userId) {
return userId == UserHandle.USER_NULL ? ActivityManager.getCurrentUser() : userId;
-
}
}
diff --git a/services/core/java/com/android/server/notification/CalendarTracker.java b/services/core/java/com/android/server/notification/CalendarTracker.java
index de321fe..783b16f 100644
--- a/services/core/java/com/android/server/notification/CalendarTracker.java
+++ b/services/core/java/com/android/server/notification/CalendarTracker.java
@@ -16,8 +16,6 @@
package com.android.server.notification;
-import static android.service.notification.ZenModeConfig.EventInfo.ANY_CALENDAR;
-
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
@@ -183,7 +181,7 @@ public class CalendarTracker {
calendarPrimary));
final boolean meetsTime = time >= begin && time < end;
final boolean meetsCalendar = calendarVisible && calendarPrimary
- && (filter.calendar == ANY_CALENDAR || filter.calendar == calendarId);
+ && (filter.calendar == null || Objects.equals(filter.calendar, owner));
final boolean meetsAvailability = availability != Instances.AVAILABILITY_FREE;
if (meetsCalendar && meetsAvailability) {
if (DEBUG) Log.d(TAG, " MEETS CALENDAR & AVAILABILITY");
diff --git a/services/core/java/com/android/server/notification/EventConditionProvider.java b/services/core/java/com/android/server/notification/EventConditionProvider.java
index 46cc47b..88ef366 100644
--- a/services/core/java/com/android/server/notification/EventConditionProvider.java
+++ b/services/core/java/com/android/server/notification/EventConditionProvider.java
@@ -211,7 +211,7 @@ public class EventConditionProvider extends SystemConditionProviderService {
continue;
}
CheckEventResult result = null;
- if (event.calendar == EventInfo.ANY_CALENDAR) {
+ if (event.calendar == null) { // any calendar
// event could exist on any tracker
for (int i = 0; i < mTrackers.size(); i++) {
final CalendarTracker tracker = mTrackers.valueAt(i);
diff --git a/services/core/java/com/android/server/notification/ZenModeHelper.java b/services/core/java/com/android/server/notification/ZenModeHelper.java
index 755b2ea..efc447e 100644
--- a/services/core/java/com/android/server/notification/ZenModeHelper.java
+++ b/services/core/java/com/android/server/notification/ZenModeHelper.java
@@ -265,6 +265,13 @@ public class ZenModeHelper {
return;
}
config.manualRule = null; // don't restore the manual rule
+ if (config.automaticRules != null) {
+ for (ZenModeConfig.ZenRule automaticRule : config.automaticRules.values()) {
+ // don't restore transient state from restored automatic rules
+ automaticRule.snoozing = false;
+ automaticRule.condition = null;
+ }
+ }
}
if (DEBUG) Log.d(TAG, "readXml");
setConfig(config, "readXml");
@@ -498,7 +505,7 @@ public class ZenModeHelper {
if (config == null) return;
final EventInfo events = new EventInfo();
- events.calendar = EventInfo.ANY_CALENDAR;
+ events.calendar = null; // any calendar
events.reply = EventInfo.REPLY_YES_OR_MAYBE;
final ZenRule rule = new ZenRule();
rule.enabled = false;