diff options
| author | 2016-07-13 15:26:01 +0000 | |
|---|---|---|
| committer | 2016-07-13 15:26:03 +0000 | |
| commit | f6d766020f9b4d082ee38c38e6496655e1e56c61 (patch) | |
| tree | f120c378e06e7d79967b1756cc17d1357f460329 | |
| parent | 17ca90430ba88c347062ea222fe0bc2be8d52a57 (diff) | |
| parent | 44ad6ff4c2162842335372060ad6a34fabc8b29d (diff) | |
Merge "Attribute manual zen mode in volume panel footer." into nyc-mr1-dev
4 files changed, 75 insertions, 30 deletions
diff --git a/core/java/android/service/notification/ZenModeConfig.java b/core/java/android/service/notification/ZenModeConfig.java index 6911b0161704..69960b04518a 100644 --- a/core/java/android/service/notification/ZenModeConfig.java +++ b/core/java/android/service/notification/ZenModeConfig.java @@ -20,6 +20,8 @@ import android.app.ActivityManager; import android.app.NotificationManager.Policy; import android.content.ComponentName; import android.content.Context; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; import android.content.res.Resources; import android.net.Uri; 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_CONDITION_ID = "conditionId"; 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 allowRepeatCallers = DEFAULT_ALLOW_REPEAT_CALLERS; @@ -502,6 +505,7 @@ public class ZenModeConfig implements Parcelable { rt.conditionId = safeUri(parser, RULE_ATT_CONDITION_ID); rt.component = safeComponentName(parser, RULE_ATT_COMPONENT); rt.creationTime = safeLong(parser, RULE_ATT_CREATION_TIME, 0); + rt.enabler = parser.getAttributeValue(null, RULE_ATT_ENABLER); rt.condition = readConditionXml(parser); 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_CREATION_TIME, Long.toString(rule.creationTime)); + if (rule.enabler != null) { + out.attribute(null, RULE_ATT_ENABLER, rule.enabler); + } if (rule.condition != null) { writeConditionXml(rule.condition, out); } @@ -989,6 +996,25 @@ public class ZenModeConfig implements Parcelable { 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, int userHandle, boolean shortVersion) { return getConditionLine(context, config, userHandle, false /*useLine1*/, shortVersion); @@ -997,23 +1023,28 @@ public class ZenModeConfig implements Parcelable { private static String getConditionLine(Context context, ZenModeConfig config, int userHandle, boolean useLine1, boolean shortVersion) { if (config == null) return ""; + String summary = ""; if (config.manualRule != null) { final Uri id = config.manualRule.conditionId; - if (id == null) { - return context.getString(com.android.internal.R.string.zen_mode_forever); - } - final long time = tryParseCountdownConditionId(id); - Condition c = config.manualRule.condition; - if (time > 0) { - final long now = System.currentTimeMillis(); - final long span = time - now; - c = toTimeCondition(context, time, Math.round(span / (float) MINUTES_MS), - userHandle, shortVersion); + if (config.manualRule.enabler != null) { + summary = getOwnerCaption(context, config.manualRule.enabler); + } else { + if (id == null) { + summary = context.getString(com.android.internal.R.string.zen_mode_forever); + } else { + final long time = tryParseCountdownConditionId(id); + Condition c = config.manualRule.condition; + if (time > 0) { + final long now = System.currentTimeMillis(); + final long span = time - now; + c = toTimeCondition(context, time, Math.round(span / (float) MINUTES_MS), + userHandle, shortVersion); + } + final String rt = c == null ? "" : useLine1 ? c.line1 : c.summary; + summary = TextUtils.isEmpty(rt) ? "" : rt; + } } - final String rt = c == null ? "" : useLine1 ? c.line1 : c.summary; - return TextUtils.isEmpty(rt) ? "" : rt; } - String summary = ""; for (ZenRule automaticRule : config.automaticRules.values()) { if (automaticRule.isAutomaticActive()) { if (summary.isEmpty()) { @@ -1023,6 +1054,7 @@ public class ZenModeConfig implements Parcelable { .getString(R.string.zen_mode_rule_name_combination, summary, automaticRule.name); } + } } return summary; @@ -1038,6 +1070,7 @@ public class ZenModeConfig implements Parcelable { public ComponentName component; // optional public String id; // required for automatic (unique) public long creationTime; // required for automatic + public String enabler; // package name, only used for manual rules. public ZenRule() { } @@ -1055,6 +1088,9 @@ public class ZenModeConfig implements Parcelable { id = source.readString(); } creationTime = source.readLong(); + if (source.readInt() == 1) { + enabler = source.readString(); + } } @Override @@ -1083,6 +1119,12 @@ public class ZenModeConfig implements Parcelable { dest.writeInt(0); } dest.writeLong(creationTime); + if (enabler != null) { + dest.writeInt(1); + dest.writeString(enabler); + } else { + dest.writeInt(0); + } } @Override @@ -1097,6 +1139,7 @@ public class ZenModeConfig implements Parcelable { .append(",component=").append(component) .append(",id=").append(id) .append(",creationTime=").append(creationTime) + .append(",enabler=").append(enabler) .append(']').toString(); } @@ -1143,6 +1186,9 @@ public class ZenModeConfig implements Parcelable { if (creationTime != to.creationTime) { d.addLine(item, "creationTime", creationTime, to.creationTime); } + if (enabler != to.enabler) { + d.addLine(item, "enabler", enabler, to.enabler); + } } @Override @@ -1158,13 +1204,14 @@ public class ZenModeConfig implements Parcelable { && Objects.equals(other.condition, condition) && Objects.equals(other.component, component) && Objects.equals(other.id, id) - && other.creationTime == creationTime; + && other.creationTime == creationTime + && Objects.equals(other.enabler, enabler); } @Override public int hashCode() { return Objects.hash(enabled, snoozing, name, zenMode, conditionId, condition, - component, id, creationTime); + component, id, creationTime, enabler); } public boolean isAutomaticActive() { diff --git a/packages/SystemUI/src/com/android/systemui/volume/ZenFooter.java b/packages/SystemUI/src/com/android/systemui/volume/ZenFooter.java index f01e95fa3873..995ecaed6ecf 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/ZenFooter.java +++ b/packages/SystemUI/src/com/android/systemui/volume/ZenFooter.java @@ -124,12 +124,8 @@ public class ZenFooter extends LinearLayout { : null; Util.setText(mSummaryLine1, line1); - final boolean isForever = mConfig != null && mConfig.manualRule != null - && mConfig.manualRule.conditionId == null; - final CharSequence line2 = - isForever ? mContext.getString(com.android.internal.R.string.zen_mode_forever_dnd) - : ZenModeConfig.getConditionSummary(mContext, mConfig, mController.getCurrentUser(), - true /*shortVersion*/); + final CharSequence line2 = ZenModeConfig.getConditionSummary(mContext, mConfig, + mController.getCurrentUser(), true /*shortVersion*/); Util.setText(mSummaryLine2, line2); } diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index ec77dafb2914..8d19a24753a2 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -1851,7 +1851,7 @@ public class NotificationManagerService extends SystemService { enforceSystemOrSystemUIOrVolume("INotificationManager.setZenMode"); final long identity = Binder.clearCallingIdentity(); try { - mZenModeHelper.setManualZenMode(mode, conditionId, reason); + mZenModeHelper.setManualZenMode(mode, conditionId, null, reason); } finally { Binder.restoreCallingIdentity(identity); } @@ -1928,7 +1928,7 @@ public class NotificationManagerService extends SystemService { if (zen == -1) throw new IllegalArgumentException("Invalid filter: " + filter); final long identity = Binder.clearCallingIdentity(); try { - mZenModeHelper.setManualZenMode(zen, null, "setInterruptionFilter"); + mZenModeHelper.setManualZenMode(zen, null, pkg, "setInterruptionFilter"); } finally { Binder.restoreCallingIdentity(identity); } diff --git a/services/core/java/com/android/server/notification/ZenModeHelper.java b/services/core/java/com/android/server/notification/ZenModeHelper.java index 6864ed898ada..8c9dc3ba60f2 100644 --- a/services/core/java/com/android/server/notification/ZenModeHelper.java +++ b/services/core/java/com/android/server/notification/ZenModeHelper.java @@ -54,7 +54,6 @@ import android.service.notification.ZenModeConfig; import android.service.notification.ZenModeConfig.EventInfo; import android.service.notification.ZenModeConfig.ScheduleInfo; import android.service.notification.ZenModeConfig.ZenRule; -import android.text.TextUtils; import android.util.AndroidRuntimeException; import android.util.Log; import android.util.SparseArray; @@ -229,7 +228,7 @@ public class ZenModeHelper { public void requestFromListener(ComponentName name, int filter) { final int newZen = NotificationManager.zenModeFromInterruptionFilter(filter, -1); if (newZen != -1) { - setManualZenMode(newZen, null, + setManualZenMode(newZen, null, name != null ? name.getPackageName() : null, "listener:" + (name != null ? name.flattenToShortString() : null)); } } @@ -452,11 +451,11 @@ public class ZenModeHelper { rule.creationTime); } - public void setManualZenMode(int zenMode, Uri conditionId, String reason) { - setManualZenMode(zenMode, conditionId, reason, true /*setRingerMode*/); + public void setManualZenMode(int zenMode, Uri conditionId, String caller, String reason) { + 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) { ZenModeConfig newConfig; synchronized (mConfig) { @@ -478,6 +477,7 @@ public class ZenModeHelper { newRule.enabled = true; newRule.zenMode = zenMode; newRule.conditionId = conditionId; + newRule.enabler = caller; newConfig.manualRule = newRule; } setConfigLocked(newConfig, reason, setRingerMode); @@ -950,7 +950,8 @@ public class ZenModeHelper { break; } if (newZen != -1) { - setManualZenMode(newZen, null, "ringerModeInternal", false /*setRingerMode*/); + setManualZenMode(newZen, null, "ringerModeInternal", null, + false /*setRingerMode*/); } if (isChange || newZen != -1 || ringerModeExternal != ringerModeExternalOut) { @@ -988,7 +989,8 @@ public class ZenModeHelper { break; } if (newZen != -1) { - setManualZenMode(newZen, null, "ringerModeExternal", false /*setRingerMode*/); + setManualZenMode(newZen, null, "ringerModeExternal", caller, + false /*setRingerMode*/); } ZenLog.traceSetRingerModeExternal(ringerModeOld, ringerModeNew, caller, |