Merge "Zen: Add the ability to enter "None" mode during downtime." into lmp-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
2f9e7f6d8b
@@ -78,6 +78,7 @@ public class ZenModeConfig implements Parcelable {
|
|||||||
private static final String ALLOW_ATT_EVENTS = "events";
|
private static final String ALLOW_ATT_EVENTS = "events";
|
||||||
private static final String SLEEP_TAG = "sleep";
|
private static final String SLEEP_TAG = "sleep";
|
||||||
private static final String SLEEP_ATT_MODE = "mode";
|
private static final String SLEEP_ATT_MODE = "mode";
|
||||||
|
private static final String SLEEP_ATT_NONE = "none";
|
||||||
|
|
||||||
private static final String SLEEP_ATT_START_HR = "startHour";
|
private static final String SLEEP_ATT_START_HR = "startHour";
|
||||||
private static final String SLEEP_ATT_START_MIN = "startMin";
|
private static final String SLEEP_ATT_START_MIN = "startMin";
|
||||||
@@ -107,6 +108,7 @@ public class ZenModeConfig implements Parcelable {
|
|||||||
public int sleepStartMinute; // 0-59
|
public int sleepStartMinute; // 0-59
|
||||||
public int sleepEndHour;
|
public int sleepEndHour;
|
||||||
public int sleepEndMinute;
|
public int sleepEndMinute;
|
||||||
|
public boolean sleepNone; // false = priority, true = none
|
||||||
public ComponentName[] conditionComponents;
|
public ComponentName[] conditionComponents;
|
||||||
public Uri[] conditionIds;
|
public Uri[] conditionIds;
|
||||||
public Condition exitCondition;
|
public Condition exitCondition;
|
||||||
@@ -125,6 +127,7 @@ public class ZenModeConfig implements Parcelable {
|
|||||||
sleepStartMinute = source.readInt();
|
sleepStartMinute = source.readInt();
|
||||||
sleepEndHour = source.readInt();
|
sleepEndHour = source.readInt();
|
||||||
sleepEndMinute = source.readInt();
|
sleepEndMinute = source.readInt();
|
||||||
|
sleepNone = source.readInt() == 1;
|
||||||
int len = source.readInt();
|
int len = source.readInt();
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
conditionComponents = new ComponentName[len];
|
conditionComponents = new ComponentName[len];
|
||||||
@@ -155,6 +158,7 @@ public class ZenModeConfig implements Parcelable {
|
|||||||
dest.writeInt(sleepStartMinute);
|
dest.writeInt(sleepStartMinute);
|
||||||
dest.writeInt(sleepEndHour);
|
dest.writeInt(sleepEndHour);
|
||||||
dest.writeInt(sleepEndMinute);
|
dest.writeInt(sleepEndMinute);
|
||||||
|
dest.writeInt(sleepNone ? 1 : 0);
|
||||||
if (conditionComponents != null && conditionComponents.length > 0) {
|
if (conditionComponents != null && conditionComponents.length > 0) {
|
||||||
dest.writeInt(conditionComponents.length);
|
dest.writeInt(conditionComponents.length);
|
||||||
dest.writeTypedArray(conditionComponents, 0);
|
dest.writeTypedArray(conditionComponents, 0);
|
||||||
@@ -182,6 +186,7 @@ public class ZenModeConfig implements Parcelable {
|
|||||||
.append(",sleepMode=").append(sleepMode)
|
.append(",sleepMode=").append(sleepMode)
|
||||||
.append(",sleepStart=").append(sleepStartHour).append('.').append(sleepStartMinute)
|
.append(",sleepStart=").append(sleepStartHour).append('.').append(sleepStartMinute)
|
||||||
.append(",sleepEnd=").append(sleepEndHour).append('.').append(sleepEndMinute)
|
.append(",sleepEnd=").append(sleepEndHour).append('.').append(sleepEndMinute)
|
||||||
|
.append(",sleepNone=").append(sleepNone)
|
||||||
.append(",conditionComponents=")
|
.append(",conditionComponents=")
|
||||||
.append(conditionComponents == null ? null : TextUtils.join(",", conditionComponents))
|
.append(conditionComponents == null ? null : TextUtils.join(",", conditionComponents))
|
||||||
.append(",conditionIds=")
|
.append(",conditionIds=")
|
||||||
@@ -214,6 +219,7 @@ public class ZenModeConfig implements Parcelable {
|
|||||||
&& other.allowFrom == allowFrom
|
&& other.allowFrom == allowFrom
|
||||||
&& other.allowEvents == allowEvents
|
&& other.allowEvents == allowEvents
|
||||||
&& Objects.equals(other.sleepMode, sleepMode)
|
&& Objects.equals(other.sleepMode, sleepMode)
|
||||||
|
&& other.sleepNone == sleepNone
|
||||||
&& other.sleepStartHour == sleepStartHour
|
&& other.sleepStartHour == sleepStartHour
|
||||||
&& other.sleepStartMinute == sleepStartMinute
|
&& other.sleepStartMinute == sleepStartMinute
|
||||||
&& other.sleepEndHour == sleepEndHour
|
&& other.sleepEndHour == sleepEndHour
|
||||||
@@ -226,7 +232,7 @@ public class ZenModeConfig implements Parcelable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(allowCalls, allowMessages, allowFrom, allowEvents, sleepMode,
|
return Objects.hash(allowCalls, allowMessages, allowFrom, allowEvents, sleepMode, sleepNone,
|
||||||
sleepStartHour, sleepStartMinute, sleepEndHour, sleepEndMinute,
|
sleepStartHour, sleepStartMinute, sleepEndHour, sleepEndMinute,
|
||||||
Arrays.hashCode(conditionComponents), Arrays.hashCode(conditionIds),
|
Arrays.hashCode(conditionComponents), Arrays.hashCode(conditionIds),
|
||||||
exitCondition, exitConditionComponent);
|
exitCondition, exitConditionComponent);
|
||||||
@@ -302,6 +308,7 @@ public class ZenModeConfig implements Parcelable {
|
|||||||
} else if (SLEEP_TAG.equals(tag)) {
|
} else if (SLEEP_TAG.equals(tag)) {
|
||||||
final String mode = parser.getAttributeValue(null, SLEEP_ATT_MODE);
|
final String mode = parser.getAttributeValue(null, SLEEP_ATT_MODE);
|
||||||
rt.sleepMode = isValidSleepMode(mode)? mode : null;
|
rt.sleepMode = isValidSleepMode(mode)? mode : null;
|
||||||
|
rt.sleepNone = safeBoolean(parser, SLEEP_ATT_NONE, false);
|
||||||
final int startHour = safeInt(parser, SLEEP_ATT_START_HR, 0);
|
final int startHour = safeInt(parser, SLEEP_ATT_START_HR, 0);
|
||||||
final int startMinute = safeInt(parser, SLEEP_ATT_START_MIN, 0);
|
final int startMinute = safeInt(parser, SLEEP_ATT_START_MIN, 0);
|
||||||
final int endHour = safeInt(parser, SLEEP_ATT_END_HR, 0);
|
final int endHour = safeInt(parser, SLEEP_ATT_END_HR, 0);
|
||||||
@@ -345,6 +352,7 @@ public class ZenModeConfig implements Parcelable {
|
|||||||
if (sleepMode != null) {
|
if (sleepMode != null) {
|
||||||
out.attribute(null, SLEEP_ATT_MODE, sleepMode);
|
out.attribute(null, SLEEP_ATT_MODE, sleepMode);
|
||||||
}
|
}
|
||||||
|
out.attribute(null, SLEEP_ATT_NONE, Boolean.toString(sleepNone));
|
||||||
out.attribute(null, SLEEP_ATT_START_HR, Integer.toString(sleepStartHour));
|
out.attribute(null, SLEEP_ATT_START_HR, Integer.toString(sleepStartHour));
|
||||||
out.attribute(null, SLEEP_ATT_START_MIN, Integer.toString(sleepStartMinute));
|
out.attribute(null, SLEEP_ATT_START_MIN, Integer.toString(sleepStartMinute));
|
||||||
out.attribute(null, SLEEP_ATT_END_HR, Integer.toString(sleepEndHour));
|
out.attribute(null, SLEEP_ATT_END_HR, Integer.toString(sleepEndHour));
|
||||||
|
|||||||
@@ -553,19 +553,21 @@ public class ConditionProviders extends ManagedServices {
|
|||||||
|
|
||||||
private class DowntimeCallback implements DowntimeConditionProvider.Callback {
|
private class DowntimeCallback implements DowntimeConditionProvider.Callback {
|
||||||
@Override
|
@Override
|
||||||
public void onDowntimeChanged(boolean inDowntime) {
|
public void onDowntimeChanged(int downtimeMode) {
|
||||||
final int mode = mZenModeHelper.getZenMode();
|
final int mode = mZenModeHelper.getZenMode();
|
||||||
final ZenModeConfig config = mZenModeHelper.getConfig();
|
final ZenModeConfig config = mZenModeHelper.getConfig();
|
||||||
// enter downtime
|
final boolean inDowntime = downtimeMode == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS
|
||||||
if (inDowntime && mode == Global.ZEN_MODE_OFF && config != null) {
|
|| downtimeMode == Global.ZEN_MODE_NO_INTERRUPTIONS;
|
||||||
|
final boolean downtimeCurrent = mDowntime.isDowntimeCondition(mExitCondition);
|
||||||
|
// enter downtime, or update mode if reconfigured during an active downtime
|
||||||
|
if (inDowntime && (mode == Global.ZEN_MODE_OFF || downtimeCurrent) && config != null) {
|
||||||
final Condition condition = mDowntime.createCondition(config.toDowntimeInfo(),
|
final Condition condition = mDowntime.createCondition(config.toDowntimeInfo(),
|
||||||
Condition.STATE_TRUE);
|
Condition.STATE_TRUE);
|
||||||
mZenModeHelper.setZenMode(Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS, "downtimeEnter");
|
mZenModeHelper.setZenMode(downtimeMode, "downtimeEnter");
|
||||||
setZenModeCondition(condition, "downtime");
|
setZenModeCondition(condition, "downtime");
|
||||||
}
|
}
|
||||||
// exit downtime
|
// exit downtime
|
||||||
if (!inDowntime && mDowntime.isDowntimeCondition(mExitCondition)
|
if (!inDowntime && downtimeCurrent && (mode == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS
|
||||||
&& (mode == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS
|
|
||||||
|| mode == Global.ZEN_MODE_NO_INTERRUPTIONS)) {
|
|| mode == Global.ZEN_MODE_NO_INTERRUPTIONS)) {
|
||||||
mZenModeHelper.setZenMode(Global.ZEN_MODE_OFF, "downtimeExit");
|
mZenModeHelper.setZenMode(Global.ZEN_MODE_OFF, "downtimeExit");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.provider.Settings.Global;
|
||||||
import android.service.notification.Condition;
|
import android.service.notification.Condition;
|
||||||
import android.service.notification.ConditionProviderService;
|
import android.service.notification.ConditionProviderService;
|
||||||
import android.service.notification.IConditionProvider;
|
import android.service.notification.IConditionProvider;
|
||||||
@@ -64,7 +65,7 @@ public class DowntimeConditionProvider extends ConditionProviderService {
|
|||||||
private final ArraySet<Integer> mDays = new ArraySet<Integer>();
|
private final ArraySet<Integer> mDays = new ArraySet<Integer>();
|
||||||
|
|
||||||
private boolean mConnected;
|
private boolean mConnected;
|
||||||
private boolean mInDowntime;
|
private int mDowntimeMode;
|
||||||
private ZenModeConfig mConfig;
|
private ZenModeConfig mConfig;
|
||||||
private Callback mCallback;
|
private Callback mCallback;
|
||||||
|
|
||||||
@@ -75,7 +76,7 @@ public class DowntimeConditionProvider extends ConditionProviderService {
|
|||||||
public void dump(PrintWriter pw, DumpFilter filter) {
|
public void dump(PrintWriter pw, DumpFilter filter) {
|
||||||
pw.println(" DowntimeConditionProvider:");
|
pw.println(" DowntimeConditionProvider:");
|
||||||
pw.print(" mConnected="); pw.println(mConnected);
|
pw.print(" mConnected="); pw.println(mConnected);
|
||||||
pw.print(" mInDowntime="); pw.println(mInDowntime);
|
pw.print(" mDowntimeMode="); pw.println(Global.zenModeToString(mDowntimeMode));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void attachBase(Context base) {
|
public void attachBase(Context base) {
|
||||||
@@ -113,7 +114,7 @@ public class DowntimeConditionProvider extends ConditionProviderService {
|
|||||||
public void onRequestConditions(int relevance) {
|
public void onRequestConditions(int relevance) {
|
||||||
if (DEBUG) Slog.d(TAG, "onRequestConditions relevance=" + relevance);
|
if (DEBUG) Slog.d(TAG, "onRequestConditions relevance=" + relevance);
|
||||||
if ((relevance & Condition.FLAG_RELEVANT_NOW) != 0) {
|
if ((relevance & Condition.FLAG_RELEVANT_NOW) != 0) {
|
||||||
if (mInDowntime && mConfig != null) {
|
if (isInDowntime() && mConfig != null) {
|
||||||
notifyCondition(createCondition(mConfig.toDowntimeInfo(), Condition.STATE_TRUE));
|
notifyCondition(createCondition(mConfig.toDowntimeInfo(), Condition.STATE_TRUE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -124,7 +125,7 @@ public class DowntimeConditionProvider extends ConditionProviderService {
|
|||||||
if (DEBUG) Slog.d(TAG, "onSubscribe conditionId=" + conditionId);
|
if (DEBUG) Slog.d(TAG, "onSubscribe conditionId=" + conditionId);
|
||||||
final DowntimeInfo downtime = ZenModeConfig.tryParseDowntimeConditionId(conditionId);
|
final DowntimeInfo downtime = ZenModeConfig.tryParseDowntimeConditionId(conditionId);
|
||||||
if (downtime != null && mConfig != null) {
|
if (downtime != null && mConfig != null) {
|
||||||
final int state = mConfig.toDowntimeInfo().equals(downtime) && mInDowntime
|
final int state = mConfig.toDowntimeInfo().equals(downtime) && isInDowntime()
|
||||||
? Condition.STATE_TRUE : Condition.STATE_FALSE;
|
? Condition.STATE_TRUE : Condition.STATE_FALSE;
|
||||||
if (DEBUG) Slog.d(TAG, "notify condition state: " + Condition.stateToString(state));
|
if (DEBUG) Slog.d(TAG, "notify condition state: " + Condition.stateToString(state));
|
||||||
notifyCondition(createCondition(downtime, state));
|
notifyCondition(createCondition(downtime, state));
|
||||||
@@ -146,7 +147,7 @@ public class DowntimeConditionProvider extends ConditionProviderService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInDowntime() {
|
public boolean isInDowntime() {
|
||||||
return mInDowntime;
|
return mDowntimeMode != Global.ZEN_MODE_OFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Condition createCondition(DowntimeInfo downtime, int state) {
|
public Condition createCondition(DowntimeInfo downtime, int state) {
|
||||||
@@ -182,15 +183,18 @@ public class DowntimeConditionProvider extends ConditionProviderService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isInDowntime(long time) {
|
private int computeDowntimeMode(long time) {
|
||||||
if (mConfig == null || mDays.size() == 0) return false;
|
if (mConfig == null || mDays.size() == 0) return Global.ZEN_MODE_OFF;
|
||||||
final long start = getTime(time, mConfig.sleepStartHour, mConfig.sleepStartMinute);
|
final long start = getTime(time, mConfig.sleepStartHour, mConfig.sleepStartMinute);
|
||||||
long end = getTime(time, mConfig.sleepEndHour, mConfig.sleepEndMinute);
|
long end = getTime(time, mConfig.sleepEndHour, mConfig.sleepEndMinute);
|
||||||
if (start == end) return false;
|
if (start == end) return Global.ZEN_MODE_OFF;
|
||||||
if (end < start) {
|
if (end < start) {
|
||||||
end = addDays(end, 1);
|
end = addDays(end, 1);
|
||||||
}
|
}
|
||||||
return isInDowntime(-1, time, start, end) || isInDowntime(0, time, start, end);
|
final boolean inDowntime = isInDowntime(-1, time, start, end)
|
||||||
|
|| isInDowntime(0, time, start, end);
|
||||||
|
return inDowntime ? (mConfig.sleepNone ? Global.ZEN_MODE_NO_INTERRUPTIONS
|
||||||
|
: Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS) : Global.ZEN_MODE_OFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isInDowntime(int daysOffset, long time, long start, long end) {
|
private boolean isInDowntime(int daysOffset, long time, long start, long end) {
|
||||||
@@ -202,18 +206,18 @@ public class DowntimeConditionProvider extends ConditionProviderService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void reevaluateDowntime() {
|
private void reevaluateDowntime() {
|
||||||
final boolean inDowntime = isInDowntime(System.currentTimeMillis());
|
final int downtimeMode = computeDowntimeMode(System.currentTimeMillis());
|
||||||
if (DEBUG) Slog.d(TAG, "inDowntime=" + inDowntime);
|
if (DEBUG) Slog.d(TAG, "downtimeMode=" + downtimeMode);
|
||||||
if (inDowntime == mInDowntime) return;
|
if (downtimeMode == mDowntimeMode) return;
|
||||||
Slog.i(TAG, (inDowntime ? "Entering" : "Exiting" ) + " downtime");
|
mDowntimeMode = downtimeMode;
|
||||||
mInDowntime = inDowntime;
|
Slog.i(TAG, (isInDowntime() ? "Entering" : "Exiting" ) + " downtime");
|
||||||
ZenLog.traceDowntime(mInDowntime, getDayOfWeek(System.currentTimeMillis()), mDays);
|
ZenLog.traceDowntime(mDowntimeMode, getDayOfWeek(System.currentTimeMillis()), mDays);
|
||||||
fireDowntimeChanged();
|
fireDowntimeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireDowntimeChanged() {
|
private void fireDowntimeChanged() {
|
||||||
if (mCallback != null) {
|
if (mCallback != null) {
|
||||||
mCallback.onDowntimeChanged(mInDowntime);
|
mCallback.onDowntimeChanged(mDowntimeMode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,7 +260,10 @@ public class DowntimeConditionProvider extends ConditionProviderService {
|
|||||||
time = addDays(time, 1);
|
time = addDays(time, 1);
|
||||||
}
|
}
|
||||||
final PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, requestCode,
|
final PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, requestCode,
|
||||||
new Intent(action).putExtra(EXTRA_TIME, time), PendingIntent.FLAG_UPDATE_CURRENT);
|
new Intent(action)
|
||||||
|
.addFlags(Intent.FLAG_RECEIVER_FOREGROUND)
|
||||||
|
.putExtra(EXTRA_TIME, time),
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
alarms.cancel(pendingIntent);
|
alarms.cancel(pendingIntent);
|
||||||
if (mConfig.sleepMode != null) {
|
if (mConfig.sleepMode != null) {
|
||||||
if (DEBUG) Slog.d(TAG, String.format("Scheduling %s for %s, %s in the future, now=%s",
|
if (DEBUG) Slog.d(TAG, String.format("Scheduling %s for %s, %s in the future, now=%s",
|
||||||
@@ -290,6 +297,6 @@ public class DowntimeConditionProvider extends ConditionProviderService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public interface Callback {
|
public interface Callback {
|
||||||
void onDowntimeChanged(boolean inDowntime);
|
void onDowntimeChanged(int downtimeMode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,8 +75,8 @@ public class ZenLog {
|
|||||||
append(TYPE_SET_RINGER_MODE, ringerModeToString(ringerMode));
|
append(TYPE_SET_RINGER_MODE, ringerModeToString(ringerMode));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void traceDowntime(boolean inDowntime, int day, ArraySet<Integer> days) {
|
public static void traceDowntime(int downtimeMode, int day, ArraySet<Integer> days) {
|
||||||
append(TYPE_DOWNTIME, inDowntime + ",day=" + day + ",days=" + days);
|
append(TYPE_DOWNTIME, zenModeToString(downtimeMode) + ",day=" + day + ",days=" + days);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void traceSetZenMode(int mode, String reason) {
|
public static void traceSetZenMode(int mode, String reason) {
|
||||||
|
|||||||
Reference in New Issue
Block a user