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

Commit c2381727 authored by Julia Reynolds's avatar Julia Reynolds Committed by android-build-merger
Browse files

Merge \"Attribute manual zen mode in volume panel footer.\" into nyc-mr1-dev

am: f6d76602

Change-Id: I89ee22c5304e7de651aa34bddf5635f2e87e6b01
parents b3fa8d87 f6d76602
Loading
Loading
Loading
Loading
+62 −15
Original line number Original line Diff line number Diff line
@@ -20,6 +20,8 @@ import android.app.ActivityManager;
import android.app.NotificationManager.Policy;
import android.app.NotificationManager.Policy;
import android.content.ComponentName;
import android.content.ComponentName;
import android.content.Context;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.content.res.Resources;
import android.net.Uri;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcel;
@@ -118,6 +120,7 @@ public class ZenModeConfig implements Parcelable {
    private static final String RULE_ATT_ZEN = "zen";
    private static final String RULE_ATT_ZEN = "zen";
    private static final String RULE_ATT_CONDITION_ID = "conditionId";
    private static final String RULE_ATT_CONDITION_ID = "conditionId";
    private static final String RULE_ATT_CREATION_TIME = "creationTime";
    private static final String RULE_ATT_CREATION_TIME = "creationTime";
    private static final String RULE_ATT_ENABLER = "enabler";


    public boolean allowCalls = DEFAULT_ALLOW_CALLS;
    public boolean allowCalls = DEFAULT_ALLOW_CALLS;
    public boolean allowRepeatCallers = DEFAULT_ALLOW_REPEAT_CALLERS;
    public boolean allowRepeatCallers = DEFAULT_ALLOW_REPEAT_CALLERS;
@@ -502,6 +505,7 @@ public class ZenModeConfig implements Parcelable {
        rt.conditionId = safeUri(parser, RULE_ATT_CONDITION_ID);
        rt.conditionId = safeUri(parser, RULE_ATT_CONDITION_ID);
        rt.component = safeComponentName(parser, RULE_ATT_COMPONENT);
        rt.component = safeComponentName(parser, RULE_ATT_COMPONENT);
        rt.creationTime = safeLong(parser, RULE_ATT_CREATION_TIME, 0);
        rt.creationTime = safeLong(parser, RULE_ATT_CREATION_TIME, 0);
        rt.enabler = parser.getAttributeValue(null, RULE_ATT_ENABLER);
        rt.condition = readConditionXml(parser);
        rt.condition = readConditionXml(parser);
        return rt;
        return rt;
    }
    }
@@ -520,6 +524,9 @@ public class ZenModeConfig implements Parcelable {
            out.attribute(null, RULE_ATT_CONDITION_ID, rule.conditionId.toString());
            out.attribute(null, RULE_ATT_CONDITION_ID, rule.conditionId.toString());
        }
        }
        out.attribute(null, RULE_ATT_CREATION_TIME, Long.toString(rule.creationTime));
        out.attribute(null, RULE_ATT_CREATION_TIME, Long.toString(rule.creationTime));
        if (rule.enabler != null) {
            out.attribute(null, RULE_ATT_ENABLER, rule.enabler);
        }
        if (rule.condition != null) {
        if (rule.condition != null) {
            writeConditionXml(rule.condition, out);
            writeConditionXml(rule.condition, out);
        }
        }
@@ -989,6 +996,25 @@ public class ZenModeConfig implements Parcelable {
        return UUID.randomUUID().toString().replace("-", "");
        return UUID.randomUUID().toString().replace("-", "");
    }
    }


    private static String getOwnerCaption(Context context, String owner) {
        final PackageManager pm = context.getPackageManager();
        try {
            final ApplicationInfo info = pm.getApplicationInfo(owner, 0);
            if (info != null) {
                final CharSequence seq = info.loadLabel(pm);
                if (seq != null) {
                    final String str = seq.toString().trim();
                    if (str.length() > 0) {
                        return str;
                    }
                }
            }
        } catch (Throwable e) {
            Slog.w(TAG, "Error loading owner caption", e);
        }
        return "";
    }

    public static String getConditionSummary(Context context, ZenModeConfig config,
    public static String getConditionSummary(Context context, ZenModeConfig config,
            int userHandle, boolean shortVersion) {
            int userHandle, boolean shortVersion) {
        return getConditionLine(context, config, userHandle, false /*useLine1*/, shortVersion);
        return getConditionLine(context, config, userHandle, false /*useLine1*/, shortVersion);
@@ -997,11 +1023,15 @@ public class ZenModeConfig implements Parcelable {
    private static String getConditionLine(Context context, ZenModeConfig config,
    private static String getConditionLine(Context context, ZenModeConfig config,
            int userHandle, boolean useLine1, boolean shortVersion) {
            int userHandle, boolean useLine1, boolean shortVersion) {
        if (config == null) return "";
        if (config == null) return "";
        String summary = "";
        if (config.manualRule != null) {
        if (config.manualRule != null) {
            final Uri id = config.manualRule.conditionId;
            final Uri id = config.manualRule.conditionId;
            if (config.manualRule.enabler != null) {
                summary = getOwnerCaption(context, config.manualRule.enabler);
            } else {
                if (id == null) {
                if (id == null) {
                return context.getString(com.android.internal.R.string.zen_mode_forever);
                    summary = context.getString(com.android.internal.R.string.zen_mode_forever);
            }
                } else {
                    final long time = tryParseCountdownConditionId(id);
                    final long time = tryParseCountdownConditionId(id);
                    Condition c = config.manualRule.condition;
                    Condition c = config.manualRule.condition;
                    if (time > 0) {
                    if (time > 0) {
@@ -1011,9 +1041,10 @@ public class ZenModeConfig implements Parcelable {
                                userHandle, shortVersion);
                                userHandle, shortVersion);
                    }
                    }
                    final String rt = c == null ? "" : useLine1 ? c.line1 : c.summary;
                    final String rt = c == null ? "" : useLine1 ? c.line1 : c.summary;
            return TextUtils.isEmpty(rt) ? "" : rt;
                    summary = TextUtils.isEmpty(rt) ? "" : rt;
                }
            }
        }
        }
        String summary = "";
        for (ZenRule automaticRule : config.automaticRules.values()) {
        for (ZenRule automaticRule : config.automaticRules.values()) {
            if (automaticRule.isAutomaticActive()) {
            if (automaticRule.isAutomaticActive()) {
                if (summary.isEmpty()) {
                if (summary.isEmpty()) {
@@ -1023,6 +1054,7 @@ public class ZenModeConfig implements Parcelable {
                            .getString(R.string.zen_mode_rule_name_combination, summary,
                            .getString(R.string.zen_mode_rule_name_combination, summary,
                                    automaticRule.name);
                                    automaticRule.name);
                }
                }

            }
            }
        }
        }
        return summary;
        return summary;
@@ -1038,6 +1070,7 @@ public class ZenModeConfig implements Parcelable {
        public ComponentName component;  // optional
        public ComponentName component;  // optional
        public String id;                // required for automatic (unique)
        public String id;                // required for automatic (unique)
        public long creationTime;        // required for automatic
        public long creationTime;        // required for automatic
        public String enabler;          // package name, only used for manual rules.


        public ZenRule() { }
        public ZenRule() { }


@@ -1055,6 +1088,9 @@ public class ZenModeConfig implements Parcelable {
                id = source.readString();
                id = source.readString();
            }
            }
            creationTime = source.readLong();
            creationTime = source.readLong();
            if (source.readInt() == 1) {
                enabler = source.readString();
            }
        }
        }


        @Override
        @Override
@@ -1083,6 +1119,12 @@ public class ZenModeConfig implements Parcelable {
                dest.writeInt(0);
                dest.writeInt(0);
            }
            }
            dest.writeLong(creationTime);
            dest.writeLong(creationTime);
            if (enabler != null) {
                dest.writeInt(1);
                dest.writeString(enabler);
            } else {
                dest.writeInt(0);
            }
        }
        }


        @Override
        @Override
@@ -1097,6 +1139,7 @@ public class ZenModeConfig implements Parcelable {
                    .append(",component=").append(component)
                    .append(",component=").append(component)
                    .append(",id=").append(id)
                    .append(",id=").append(id)
                    .append(",creationTime=").append(creationTime)
                    .append(",creationTime=").append(creationTime)
                    .append(",enabler=").append(enabler)
                    .append(']').toString();
                    .append(']').toString();
        }
        }


@@ -1143,6 +1186,9 @@ public class ZenModeConfig implements Parcelable {
            if (creationTime != to.creationTime) {
            if (creationTime != to.creationTime) {
                d.addLine(item, "creationTime", creationTime, to.creationTime);
                d.addLine(item, "creationTime", creationTime, to.creationTime);
            }
            }
            if (enabler != to.enabler) {
                d.addLine(item, "enabler", enabler, to.enabler);
            }
        }
        }


        @Override
        @Override
@@ -1158,13 +1204,14 @@ public class ZenModeConfig implements Parcelable {
                    && Objects.equals(other.condition, condition)
                    && Objects.equals(other.condition, condition)
                    && Objects.equals(other.component, component)
                    && Objects.equals(other.component, component)
                    && Objects.equals(other.id, id)
                    && Objects.equals(other.id, id)
                    && other.creationTime == creationTime;
                    && other.creationTime == creationTime
                    && Objects.equals(other.enabler, enabler);
        }
        }


        @Override
        @Override
        public int hashCode() {
        public int hashCode() {
            return Objects.hash(enabled, snoozing, name, zenMode, conditionId, condition,
            return Objects.hash(enabled, snoozing, name, zenMode, conditionId, condition,
                    component, id, creationTime);
                    component, id, creationTime, enabler);
        }
        }


        public boolean isAutomaticActive() {
        public boolean isAutomaticActive() {
+2 −6
Original line number Original line Diff line number Diff line
@@ -124,12 +124,8 @@ public class ZenFooter extends LinearLayout {
                : null;
                : null;
        Util.setText(mSummaryLine1, line1);
        Util.setText(mSummaryLine1, line1);


        final boolean isForever = mConfig != null && mConfig.manualRule != null
        final CharSequence line2 = ZenModeConfig.getConditionSummary(mContext, mConfig,
                && mConfig.manualRule.conditionId == null;
                                mController.getCurrentUser(), true /*shortVersion*/);
        final CharSequence line2 =
                isForever ? mContext.getString(com.android.internal.R.string.zen_mode_forever_dnd)
                : ZenModeConfig.getConditionSummary(mContext, mConfig, mController.getCurrentUser(),
                        true /*shortVersion*/);
        Util.setText(mSummaryLine2, line2);
        Util.setText(mSummaryLine2, line2);
    }
    }


+2 −2
Original line number Original line Diff line number Diff line
@@ -1851,7 +1851,7 @@ public class NotificationManagerService extends SystemService {
            enforceSystemOrSystemUIOrVolume("INotificationManager.setZenMode");
            enforceSystemOrSystemUIOrVolume("INotificationManager.setZenMode");
            final long identity = Binder.clearCallingIdentity();
            final long identity = Binder.clearCallingIdentity();
            try {
            try {
                mZenModeHelper.setManualZenMode(mode, conditionId, reason);
                mZenModeHelper.setManualZenMode(mode, conditionId, null, reason);
            } finally {
            } finally {
                Binder.restoreCallingIdentity(identity);
                Binder.restoreCallingIdentity(identity);
            }
            }
@@ -1928,7 +1928,7 @@ public class NotificationManagerService extends SystemService {
            if (zen == -1) throw new IllegalArgumentException("Invalid filter: " + filter);
            if (zen == -1) throw new IllegalArgumentException("Invalid filter: " + filter);
            final long identity = Binder.clearCallingIdentity();
            final long identity = Binder.clearCallingIdentity();
            try {
            try {
                mZenModeHelper.setManualZenMode(zen, null, "setInterruptionFilter");
                mZenModeHelper.setManualZenMode(zen, null, pkg, "setInterruptionFilter");
            } finally {
            } finally {
                Binder.restoreCallingIdentity(identity);
                Binder.restoreCallingIdentity(identity);
            }
            }
+9 −7
Original line number Original line Diff line number Diff line
@@ -54,7 +54,6 @@ import android.service.notification.ZenModeConfig;
import android.service.notification.ZenModeConfig.EventInfo;
import android.service.notification.ZenModeConfig.EventInfo;
import android.service.notification.ZenModeConfig.ScheduleInfo;
import android.service.notification.ZenModeConfig.ScheduleInfo;
import android.service.notification.ZenModeConfig.ZenRule;
import android.service.notification.ZenModeConfig.ZenRule;
import android.text.TextUtils;
import android.util.AndroidRuntimeException;
import android.util.AndroidRuntimeException;
import android.util.Log;
import android.util.Log;
import android.util.SparseArray;
import android.util.SparseArray;
@@ -229,7 +228,7 @@ public class ZenModeHelper {
    public void requestFromListener(ComponentName name, int filter) {
    public void requestFromListener(ComponentName name, int filter) {
        final int newZen = NotificationManager.zenModeFromInterruptionFilter(filter, -1);
        final int newZen = NotificationManager.zenModeFromInterruptionFilter(filter, -1);
        if (newZen != -1) {
        if (newZen != -1) {
            setManualZenMode(newZen, null,
            setManualZenMode(newZen, null, name != null ? name.getPackageName() : null,
                    "listener:" + (name != null ? name.flattenToShortString() : null));
                    "listener:" + (name != null ? name.flattenToShortString() : null));
        }
        }
    }
    }
@@ -452,11 +451,11 @@ public class ZenModeHelper {
                rule.creationTime);
                rule.creationTime);
    }
    }


    public void setManualZenMode(int zenMode, Uri conditionId, String reason) {
    public void setManualZenMode(int zenMode, Uri conditionId, String caller, String reason) {
        setManualZenMode(zenMode, conditionId, reason, true /*setRingerMode*/);
        setManualZenMode(zenMode, conditionId, reason, caller, true /*setRingerMode*/);
    }
    }


    private void setManualZenMode(int zenMode, Uri conditionId, String reason,
    private void setManualZenMode(int zenMode, Uri conditionId, String reason, String caller,
            boolean setRingerMode) {
            boolean setRingerMode) {
        ZenModeConfig newConfig;
        ZenModeConfig newConfig;
        synchronized (mConfig) {
        synchronized (mConfig) {
@@ -478,6 +477,7 @@ public class ZenModeHelper {
                newRule.enabled = true;
                newRule.enabled = true;
                newRule.zenMode = zenMode;
                newRule.zenMode = zenMode;
                newRule.conditionId = conditionId;
                newRule.conditionId = conditionId;
                newRule.enabler = caller;
                newConfig.manualRule = newRule;
                newConfig.manualRule = newRule;
            }
            }
            setConfigLocked(newConfig, reason, setRingerMode);
            setConfigLocked(newConfig, reason, setRingerMode);
@@ -950,7 +950,8 @@ public class ZenModeHelper {
                    break;
                    break;
            }
            }
            if (newZen != -1) {
            if (newZen != -1) {
                setManualZenMode(newZen, null, "ringerModeInternal", false /*setRingerMode*/);
                setManualZenMode(newZen, null, "ringerModeInternal", null,
                        false /*setRingerMode*/);
            }
            }


            if (isChange || newZen != -1 || ringerModeExternal != ringerModeExternalOut) {
            if (isChange || newZen != -1 || ringerModeExternal != ringerModeExternalOut) {
@@ -988,7 +989,8 @@ public class ZenModeHelper {
                    break;
                    break;
            }
            }
            if (newZen != -1) {
            if (newZen != -1) {
                setManualZenMode(newZen, null, "ringerModeExternal", false /*setRingerMode*/);
                setManualZenMode(newZen, null, "ringerModeExternal", caller,
                        false /*setRingerMode*/);
            }
            }


            ZenLog.traceSetRingerModeExternal(ringerModeOld, ringerModeNew, caller,
            ZenLog.traceSetRingerModeExternal(ringerModeOld, ringerModeNew, caller,