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

Commit 7847a7f8 authored by John Spurlock's avatar John Spurlock Committed by Android Git Automerger
Browse files

am 6ccb72e9: Merge "Zen: Add the ability to enter "None" mode during...

am 6ccb72e9: Merge "Zen: Add the ability to enter "None" mode during downtime." into lmp-mr1-dev automerge: 2f9e7f6d

* commit '6ccb72e9':
  Zen: Add the ability to enter "None" mode during downtime.
parents 8491c4ea 6ccb72e9
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -78,6 +78,7 @@ public class ZenModeConfig implements Parcelable {
    private static final String ALLOW_ATT_EVENTS = "events";
    private static final String SLEEP_TAG = "sleep";
    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_MIN = "startMin";
@@ -107,6 +108,7 @@ public class ZenModeConfig implements Parcelable {
    public int sleepStartMinute; // 0-59
    public int sleepEndHour;
    public int sleepEndMinute;
    public boolean sleepNone;    // false = priority, true = none
    public ComponentName[] conditionComponents;
    public Uri[] conditionIds;
    public Condition exitCondition;
@@ -125,6 +127,7 @@ public class ZenModeConfig implements Parcelable {
        sleepStartMinute = source.readInt();
        sleepEndHour = source.readInt();
        sleepEndMinute = source.readInt();
        sleepNone = source.readInt() == 1;
        int len = source.readInt();
        if (len > 0) {
            conditionComponents = new ComponentName[len];
@@ -155,6 +158,7 @@ public class ZenModeConfig implements Parcelable {
        dest.writeInt(sleepStartMinute);
        dest.writeInt(sleepEndHour);
        dest.writeInt(sleepEndMinute);
        dest.writeInt(sleepNone ? 1 : 0);
        if (conditionComponents != null && conditionComponents.length > 0) {
            dest.writeInt(conditionComponents.length);
            dest.writeTypedArray(conditionComponents, 0);
@@ -182,6 +186,7 @@ public class ZenModeConfig implements Parcelable {
            .append(",sleepMode=").append(sleepMode)
            .append(",sleepStart=").append(sleepStartHour).append('.').append(sleepStartMinute)
            .append(",sleepEnd=").append(sleepEndHour).append('.').append(sleepEndMinute)
            .append(",sleepNone=").append(sleepNone)
            .append(",conditionComponents=")
            .append(conditionComponents == null ? null : TextUtils.join(",", conditionComponents))
            .append(",conditionIds=")
@@ -214,6 +219,7 @@ public class ZenModeConfig implements Parcelable {
                && other.allowFrom == allowFrom
                && other.allowEvents == allowEvents
                && Objects.equals(other.sleepMode, sleepMode)
                && other.sleepNone == sleepNone
                && other.sleepStartHour == sleepStartHour
                && other.sleepStartMinute == sleepStartMinute
                && other.sleepEndHour == sleepEndHour
@@ -226,7 +232,7 @@ public class ZenModeConfig implements Parcelable {

    @Override
    public int hashCode() {
        return Objects.hash(allowCalls, allowMessages, allowFrom, allowEvents, sleepMode,
        return Objects.hash(allowCalls, allowMessages, allowFrom, allowEvents, sleepMode, sleepNone,
                sleepStartHour, sleepStartMinute, sleepEndHour, sleepEndMinute,
                Arrays.hashCode(conditionComponents), Arrays.hashCode(conditionIds),
                exitCondition, exitConditionComponent);
@@ -302,6 +308,7 @@ public class ZenModeConfig implements Parcelable {
                } else if (SLEEP_TAG.equals(tag)) {
                    final String mode = parser.getAttributeValue(null, SLEEP_ATT_MODE);
                    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 startMinute = safeInt(parser, SLEEP_ATT_START_MIN, 0);
                    final int endHour = safeInt(parser, SLEEP_ATT_END_HR, 0);
@@ -345,6 +352,7 @@ public class ZenModeConfig implements Parcelable {
        if (sleepMode != null) {
            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_MIN, Integer.toString(sleepStartMinute));
        out.attribute(null, SLEEP_ATT_END_HR, Integer.toString(sleepEndHour));
+9 −7
Original line number Diff line number Diff line
@@ -553,19 +553,21 @@ public class ConditionProviders extends ManagedServices {

    private class DowntimeCallback implements DowntimeConditionProvider.Callback {
        @Override
        public void onDowntimeChanged(boolean inDowntime) {
        public void onDowntimeChanged(int downtimeMode) {
            final int mode = mZenModeHelper.getZenMode();
            final ZenModeConfig config = mZenModeHelper.getConfig();
            // enter downtime
            if (inDowntime && mode == Global.ZEN_MODE_OFF && config != null) {
            final boolean inDowntime = downtimeMode == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS
                    || 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(),
                        Condition.STATE_TRUE);
                mZenModeHelper.setZenMode(Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS, "downtimeEnter");
                mZenModeHelper.setZenMode(downtimeMode, "downtimeEnter");
                setZenModeCondition(condition, "downtime");
            }
            // exit downtime
            if (!inDowntime && mDowntime.isDowntimeCondition(mExitCondition)
                    && (mode == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS
            if (!inDowntime && downtimeCurrent && (mode == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS
                    || mode == Global.ZEN_MODE_NO_INTERRUPTIONS)) {
                mZenModeHelper.setZenMode(Global.ZEN_MODE_OFF, "downtimeExit");
            }
+25 −18
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.provider.Settings.Global;
import android.service.notification.Condition;
import android.service.notification.ConditionProviderService;
import android.service.notification.IConditionProvider;
@@ -64,7 +65,7 @@ public class DowntimeConditionProvider extends ConditionProviderService {
    private final ArraySet<Integer> mDays = new ArraySet<Integer>();

    private boolean mConnected;
    private boolean mInDowntime;
    private int mDowntimeMode;
    private ZenModeConfig mConfig;
    private Callback mCallback;

@@ -75,7 +76,7 @@ public class DowntimeConditionProvider extends ConditionProviderService {
    public void dump(PrintWriter pw, DumpFilter filter) {
        pw.println("    DowntimeConditionProvider:");
        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) {
@@ -113,7 +114,7 @@ public class DowntimeConditionProvider extends ConditionProviderService {
    public void onRequestConditions(int relevance) {
        if (DEBUG) Slog.d(TAG, "onRequestConditions relevance=" + relevance);
        if ((relevance & Condition.FLAG_RELEVANT_NOW) != 0) {
            if (mInDowntime && mConfig != null) {
            if (isInDowntime() && mConfig != null) {
                notifyCondition(createCondition(mConfig.toDowntimeInfo(), Condition.STATE_TRUE));
            }
        }
@@ -124,7 +125,7 @@ public class DowntimeConditionProvider extends ConditionProviderService {
        if (DEBUG) Slog.d(TAG, "onSubscribe conditionId=" + conditionId);
        final DowntimeInfo downtime = ZenModeConfig.tryParseDowntimeConditionId(conditionId);
        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;
            if (DEBUG) Slog.d(TAG, "notify condition state: " + Condition.stateToString(state));
            notifyCondition(createCondition(downtime, state));
@@ -146,7 +147,7 @@ public class DowntimeConditionProvider extends ConditionProviderService {
    }

    public boolean isInDowntime() {
        return mInDowntime;
        return mDowntimeMode != Global.ZEN_MODE_OFF;
    }

    public Condition createCondition(DowntimeInfo downtime, int state) {
@@ -182,15 +183,18 @@ public class DowntimeConditionProvider extends ConditionProviderService {
        }
    }

    private boolean isInDowntime(long time) {
        if (mConfig == null || mDays.size() == 0) return false;
    private int computeDowntimeMode(long time) {
        if (mConfig == null || mDays.size() == 0) return Global.ZEN_MODE_OFF;
        final long start = getTime(time, mConfig.sleepStartHour, mConfig.sleepStartMinute);
        long end = getTime(time, mConfig.sleepEndHour, mConfig.sleepEndMinute);
        if (start == end) return false;
        if (start == end) return Global.ZEN_MODE_OFF;
        if (end < start) {
            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) {
@@ -202,18 +206,18 @@ public class DowntimeConditionProvider extends ConditionProviderService {
    }

    private void reevaluateDowntime() {
        final boolean inDowntime = isInDowntime(System.currentTimeMillis());
        if (DEBUG) Slog.d(TAG, "inDowntime=" + inDowntime);
        if (inDowntime == mInDowntime) return;
        Slog.i(TAG, (inDowntime ? "Entering" : "Exiting" ) + " downtime");
        mInDowntime = inDowntime;
        ZenLog.traceDowntime(mInDowntime, getDayOfWeek(System.currentTimeMillis()), mDays);
        final int downtimeMode = computeDowntimeMode(System.currentTimeMillis());
        if (DEBUG) Slog.d(TAG, "downtimeMode=" + downtimeMode);
        if (downtimeMode == mDowntimeMode) return;
        mDowntimeMode = downtimeMode;
        Slog.i(TAG, (isInDowntime() ? "Entering" : "Exiting" ) + " downtime");
        ZenLog.traceDowntime(mDowntimeMode, getDayOfWeek(System.currentTimeMillis()), mDays);
        fireDowntimeChanged();
    }

    private void fireDowntimeChanged() {
        if (mCallback != null) {
            mCallback.onDowntimeChanged(mInDowntime);
            mCallback.onDowntimeChanged(mDowntimeMode);
        }
    }

@@ -256,7 +260,10 @@ public class DowntimeConditionProvider extends ConditionProviderService {
            time = addDays(time, 1);
        }
        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);
        if (mConfig.sleepMode != null) {
            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 {
        void onDowntimeChanged(boolean inDowntime);
        void onDowntimeChanged(int downtimeMode);
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -75,8 +75,8 @@ public class ZenLog {
        append(TYPE_SET_RINGER_MODE, ringerModeToString(ringerMode));
    }

    public static void traceDowntime(boolean inDowntime, int day, ArraySet<Integer> days) {
        append(TYPE_DOWNTIME, inDowntime + ",day=" + day + ",days=" + days);
    public static void traceDowntime(int downtimeMode, int day, ArraySet<Integer> days) {
        append(TYPE_DOWNTIME, zenModeToString(downtimeMode) + ",day=" + day + ",days=" + days);
    }

    public static void traceSetZenMode(int mode, String reason) {