Merge "Zen: Add events as a new config attribute." into lmp-dev

This commit is contained in:
John Spurlock
2014-09-22 21:09:38 +00:00
committed by Android (Google) Code Review
2 changed files with 23 additions and 4 deletions

View File

@@ -61,6 +61,8 @@ public class ZenModeConfig implements Parcelable {
private static final int MINUTES_MS = 60 * SECONDS_MS;
private static final int ZERO_VALUE_MS = 20 * SECONDS_MS;
private static final boolean DEFAULT_ALLOW_EVENTS = true;
private static final int XML_VERSION = 1;
private static final String ZEN_TAG = "zen";
private static final String ZEN_ATT_VERSION = "version";
@@ -68,6 +70,7 @@ public class ZenModeConfig implements Parcelable {
private static final String ALLOW_ATT_CALLS = "calls";
private static final String ALLOW_ATT_MESSAGES = "messages";
private static final String ALLOW_ATT_FROM = "from";
private static final String ALLOW_ATT_EVENTS = "events";
private static final String SLEEP_TAG = "sleep";
private static final String SLEEP_ATT_MODE = "mode";
@@ -91,6 +94,7 @@ public class ZenModeConfig implements Parcelable {
public boolean allowCalls;
public boolean allowMessages;
public boolean allowEvents = DEFAULT_ALLOW_EVENTS;
public int allowFrom = SOURCE_ANYONE;
public String sleepMode;
@@ -108,6 +112,7 @@ public class ZenModeConfig implements Parcelable {
public ZenModeConfig(Parcel source) {
allowCalls = source.readInt() == 1;
allowMessages = source.readInt() == 1;
allowEvents = source.readInt() == 1;
if (source.readInt() == 1) {
sleepMode = source.readString();
}
@@ -134,6 +139,7 @@ public class ZenModeConfig implements Parcelable {
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(allowCalls ? 1 : 0);
dest.writeInt(allowMessages ? 1 : 0);
dest.writeInt(allowEvents ? 1 : 0);
if (sleepMode != null) {
dest.writeInt(1);
dest.writeString(sleepMode);
@@ -167,6 +173,7 @@ public class ZenModeConfig implements Parcelable {
.append("allowCalls=").append(allowCalls)
.append(",allowMessages=").append(allowMessages)
.append(",allowFrom=").append(sourceToString(allowFrom))
.append(",allowEvents=").append(allowEvents)
.append(",sleepMode=").append(sleepMode)
.append(",sleepStart=").append(sleepStartHour).append('.').append(sleepStartMinute)
.append(",sleepEnd=").append(sleepEndHour).append('.').append(sleepEndMinute)
@@ -200,6 +207,7 @@ public class ZenModeConfig implements Parcelable {
return other.allowCalls == allowCalls
&& other.allowMessages == allowMessages
&& other.allowFrom == allowFrom
&& other.allowEvents == allowEvents
&& Objects.equals(other.sleepMode, sleepMode)
&& other.sleepStartHour == sleepStartHour
&& other.sleepStartMinute == sleepStartMinute
@@ -213,7 +221,7 @@ public class ZenModeConfig implements Parcelable {
@Override
public int hashCode() {
return Objects.hash(allowCalls, allowMessages, allowFrom, sleepMode,
return Objects.hash(allowCalls, allowMessages, allowFrom, allowEvents, sleepMode,
sleepStartHour, sleepStartMinute, sleepEndHour, sleepEndMinute,
Arrays.hashCode(conditionComponents), Arrays.hashCode(conditionIds),
exitCondition, exitConditionComponent);
@@ -281,6 +289,7 @@ public class ZenModeConfig implements Parcelable {
if (ALLOW_TAG.equals(tag)) {
rt.allowCalls = safeBoolean(parser, ALLOW_ATT_CALLS, false);
rt.allowMessages = safeBoolean(parser, ALLOW_ATT_MESSAGES, false);
rt.allowEvents = safeBoolean(parser, ALLOW_ATT_EVENTS, DEFAULT_ALLOW_EVENTS);
rt.allowFrom = safeInt(parser, ALLOW_ATT_FROM, SOURCE_ANYONE);
if (rt.allowFrom < SOURCE_ANYONE || rt.allowFrom > MAX_SOURCE) {
throw new IndexOutOfBoundsException("bad source in config:" + rt.allowFrom);
@@ -323,6 +332,7 @@ public class ZenModeConfig implements Parcelable {
out.startTag(null, ALLOW_TAG);
out.attribute(null, ALLOW_ATT_CALLS, Boolean.toString(allowCalls));
out.attribute(null, ALLOW_ATT_MESSAGES, Boolean.toString(allowMessages));
out.attribute(null, ALLOW_ATT_EVENTS, Boolean.toString(allowEvents));
out.attribute(null, ALLOW_ATT_FROM, Integer.toString(allowFrom));
out.endTag(null, ALLOW_TAG);

View File

@@ -182,6 +182,12 @@ public class ZenModeHelper {
}
return shouldInterceptAudience(record);
}
if (isEvent(record)) {
if (!mConfig.allowEvents) {
ZenLog.traceIntercepted(record, "!allowEvents");
return true;
}
}
ZenLog.traceIntercepted(record, "!allowed");
return true;
}
@@ -328,17 +334,20 @@ public class ZenModeHelper {
}
}
private boolean isSystem(NotificationRecord record) {
private static boolean isSystem(NotificationRecord record) {
return record.isCategory(Notification.CATEGORY_SYSTEM);
}
private boolean isAlarm(NotificationRecord record) {
private static boolean isAlarm(NotificationRecord record) {
return record.isCategory(Notification.CATEGORY_ALARM)
|| record.isCategory(Notification.CATEGORY_EVENT)
|| record.isAudioStream(AudioManager.STREAM_ALARM)
|| record.isAudioAttributesUsage(AudioAttributes.USAGE_ALARM);
}
private static boolean isEvent(NotificationRecord record) {
return record.isCategory(Notification.CATEGORY_EVENT);
}
private boolean isCall(NotificationRecord record) {
return isDefaultPhoneApp(record.sbn.getPackageName())
|| record.isCategory(Notification.CATEGORY_CALL);