summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Julia Reynolds <juliacr@google.com> 2017-02-08 13:34:19 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2017-02-08 13:34:28 +0000
commit0ebe2d1b0dca82cadbce2fad5eff32c7d498d1f6 (patch)
tree7e5303e429898b914a573d6c9e3c5446752fdae2
parent8bc078d73413bbfe1a0c790ca62aec12a815080f (diff)
parentc9842c16274cbfaf60ad116b0f8bee913b82de7c (diff)
Merge changes from topics 'proto', 'lights'
* changes: Dump notification records to proto Highlight selected channel on launching settings. Let developers choose a light color for channels
-rw-r--r--api/current.txt4
-rw-r--r--api/system-current.txt4
-rw-r--r--api/test-current.txt4
-rw-r--r--core/java/android/app/Notification.java5
-rw-r--r--core/java/android/app/NotificationChannel.java39
-rw-r--r--core/proto/android/os/incident.proto2
-rw-r--r--core/proto/android/service/notification.proto45
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java9
-rw-r--r--services/core/java/com/android/server/notification/NotificationManagerService.java37
-rw-r--r--services/core/java/com/android/server/notification/NotificationRecord.java24
-rw-r--r--services/core/java/com/android/server/notification/RankingHelper.java3
-rw-r--r--services/tests/notification/src/com/android/server/notification/BuzzBeepBlinkTest.java3
-rw-r--r--services/tests/notification/src/com/android/server/notification/NotificationRecordTest.java26
-rw-r--r--services/tests/notification/src/com/android/server/notification/RankingHelperTest.java23
14 files changed, 197 insertions, 31 deletions
diff --git a/api/current.txt b/api/current.txt
index 3b4fd77316ae..5c1bff80b655 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -5472,11 +5472,13 @@ package android.app {
method public boolean canBypassDnd();
method public boolean canShowBadge();
method public int describeContents();
+ method public void enableLights(boolean);
method public void enableVibration(boolean);
method public android.media.AudioAttributes getAudioAttributes();
method public java.lang.String getGroup();
method public java.lang.String getId();
method public int getImportance();
+ method public int getLightColor();
method public int getLockscreenVisibility();
method public java.lang.CharSequence getName();
method public android.net.Uri getSound();
@@ -5484,7 +5486,7 @@ package android.app {
method public void setBypassDnd(boolean);
method public void setGroup(java.lang.String);
method public void setImportance(int);
- method public void setLights(boolean);
+ method public void setLightColor(int);
method public void setLockscreenVisibility(int);
method public void setShowBadge(boolean);
method public void setSound(android.net.Uri, android.media.AudioAttributes);
diff --git a/api/system-current.txt b/api/system-current.txt
index 8a0c781a7971..a29c7f8a71e4 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -5648,11 +5648,13 @@ package android.app {
method public boolean canBypassDnd();
method public boolean canShowBadge();
method public int describeContents();
+ method public void enableLights(boolean);
method public void enableVibration(boolean);
method public android.media.AudioAttributes getAudioAttributes();
method public java.lang.String getGroup();
method public java.lang.String getId();
method public int getImportance();
+ method public int getLightColor();
method public int getLockscreenVisibility();
method public java.lang.CharSequence getName();
method public android.net.Uri getSound();
@@ -5665,7 +5667,7 @@ package android.app {
method public void setDeleted(boolean);
method public void setGroup(java.lang.String);
method public void setImportance(int);
- method public void setLights(boolean);
+ method public void setLightColor(int);
method public void setLockscreenVisibility(int);
method public void setShowBadge(boolean);
method public void setSound(android.net.Uri, android.media.AudioAttributes);
diff --git a/api/test-current.txt b/api/test-current.txt
index b1966afd0aae..5d6f5d08646d 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -5482,11 +5482,13 @@ package android.app {
method public boolean canBypassDnd();
method public boolean canShowBadge();
method public int describeContents();
+ method public void enableLights(boolean);
method public void enableVibration(boolean);
method public android.media.AudioAttributes getAudioAttributes();
method public java.lang.String getGroup();
method public java.lang.String getId();
method public int getImportance();
+ method public int getLightColor();
method public int getLockscreenVisibility();
method public java.lang.CharSequence getName();
method public android.net.Uri getSound();
@@ -5494,7 +5496,7 @@ package android.app {
method public void setBypassDnd(boolean);
method public void setGroup(java.lang.String);
method public void setImportance(int);
- method public void setLights(boolean);
+ method public void setLightColor(int);
method public void setLockscreenVisibility(int);
method public void setShowBadge(boolean);
method public void setSound(android.net.Uri, android.media.AudioAttributes);
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index 44e328e0d7cc..9ef40b4c0097 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -49,7 +49,6 @@ import android.os.Parcelable;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.UserHandle;
-import android.service.notification.StatusBarNotification;
import android.text.BidiFormatter;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
@@ -3128,7 +3127,7 @@ public class Notification implements Parcelable
* Not all devices will honor all (or even any) of these values.
*
- * @deprecated use {@link NotificationChannel#setLights(boolean)} instead.
+ * @deprecated use {@link NotificationChannel#enableLights(boolean)} instead.
* @see Notification#ledARGB
* @see Notification#ledOnMS
* @see Notification#ledOffMS
@@ -3227,7 +3226,7 @@ public class Notification implements Parcelable
* For all default values, use {@link #DEFAULT_ALL}.
*
* @deprecated use {@link NotificationChannel#enableVibration(boolean)} and
- * {@link NotificationChannel#setLights(boolean)} and
+ * {@link NotificationChannel#enableLights(boolean)} and
* {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead.
*/
@Deprecated
diff --git a/core/java/android/app/NotificationChannel.java b/core/java/android/app/NotificationChannel.java
index afcbcdf43344..1a516087a6e5 100644
--- a/core/java/android/app/NotificationChannel.java
+++ b/core/java/android/app/NotificationChannel.java
@@ -21,7 +21,7 @@ import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlSerializer;
import android.annotation.SystemApi;
-import android.app.NotificationManager;
+import android.graphics.Color;
import android.media.AudioAttributes;
import android.net.Uri;
import android.os.Parcel;
@@ -51,7 +51,6 @@ public final class NotificationChannel implements Parcelable {
private static final String ATT_VISIBILITY = "visibility";
private static final String ATT_IMPORTANCE = "importance";
private static final String ATT_LIGHTS = "lights";
- //TODO: add support for light colors
private static final String ATT_LIGHT_COLOR = "light_color";
private static final String ATT_VIBRATION = "vibration";
private static final String ATT_VIBRATION_ENABLED = "vibration_enabled";
@@ -129,7 +128,7 @@ public final class NotificationChannel implements Parcelable {
USER_LOCKED_AUDIO_ATTRIBUTES
};
-
+ private static final int DEFAULT_LIGHT_COLOR = 0;
private static final int DEFAULT_VISIBILITY =
NotificationManager.VISIBILITY_NO_OVERRIDE;
private static final int DEFAULT_IMPORTANCE =
@@ -144,6 +143,7 @@ public final class NotificationChannel implements Parcelable {
private int mLockscreenVisibility = DEFAULT_VISIBILITY;
private Uri mSound;
private boolean mLights;
+ private int mLightColor = DEFAULT_LIGHT_COLOR;
private long[] mVibration;
private int mUserLockedFields;
private boolean mVibrationEnabled;
@@ -194,6 +194,7 @@ public final class NotificationChannel implements Parcelable {
mGroup = null;
}
mAudioAttributes = in.readInt() > 0 ? AudioAttributes.CREATOR.createFromParcel(in) : null;
+ mLightColor = in.readInt();
}
@Override
@@ -232,6 +233,7 @@ public final class NotificationChannel implements Parcelable {
} else {
dest.writeInt(0);
}
+ dest.writeInt(mLightColor);
}
/**
@@ -331,11 +333,22 @@ public final class NotificationChannel implements Parcelable {
* Only modifiable before the channel is submitted to
* {@link NotificationManager#notify(String, int, Notification)}.
*/
- public void setLights(boolean lights) {
+ public void enableLights(boolean lights) {
this.mLights = lights;
}
/**
+ * Sets the notification light color for notifications posted to this channel, if lights are
+ * {@link #enableLights(boolean) enabled} on this channel and the device supports that feature.
+ *
+ * Only modifiable before the channel is submitted to
+ * {@link NotificationManager#notify(String, int, Notification)}.
+ */
+ public void setLightColor(int argb) {
+ this.mLightColor = argb;
+ }
+
+ /**
* Sets whether notification posted to this channel should vibrate. The vibration pattern can
* be set with {@link #setVibrationPattern(long[])}.
*
@@ -411,6 +424,14 @@ public final class NotificationChannel implements Parcelable {
}
/**
+ * Returns the notification light color for notifications posted to this channel. Irrelevant
+ * unless {@link #shouldShowLights()}.
+ */
+ public int getLightColor() {
+ return mLightColor;
+ }
+
+ /**
* Returns whether notifications posted to this channel always vibrate.
*/
public boolean shouldVibrate() {
@@ -478,7 +499,8 @@ public final class NotificationChannel implements Parcelable {
!= safeInt(parser, ATT_PRIORITY, Notification.PRIORITY_DEFAULT));
setLockscreenVisibility(safeInt(parser, ATT_VISIBILITY, DEFAULT_VISIBILITY));
setSound(safeUri(parser, ATT_SOUND), safeAudioAttributes(parser));
- setLights(safeBool(parser, ATT_LIGHTS, false));
+ enableLights(safeBool(parser, ATT_LIGHTS, false));
+ setLightColor(safeInt(parser, ATT_LIGHT_COLOR, DEFAULT_LIGHT_COLOR));
enableVibration(safeBool(parser, ATT_VIBRATION_ENABLED, false));
setVibrationPattern(safeLongArray(parser, ATT_VIBRATION, null));
setShowBadge(safeBool(parser, ATT_SHOW_BADGE, false));
@@ -519,6 +541,9 @@ public final class NotificationChannel implements Parcelable {
if (shouldShowLights()) {
out.attribute(null, ATT_LIGHTS, Boolean.toString(shouldShowLights()));
}
+ if (getLightColor() != DEFAULT_LIGHT_COLOR) {
+ out.attribute(null, ATT_LIGHT_COLOR, Integer.toString(getLightColor()));
+ }
if (shouldVibrate()) {
out.attribute(null, ATT_VIBRATION_ENABLED, Boolean.toString(shouldVibrate()));
}
@@ -569,6 +594,7 @@ public final class NotificationChannel implements Parcelable {
record.put(ATT_FLAGS, Integer.toString(getAudioAttributes().getFlags()));
}
record.put(ATT_LIGHTS, Boolean.toString(shouldShowLights()));
+ record.put(ATT_LIGHT_COLOR, Integer.toString(getLightColor()));
record.put(ATT_VIBRATION_ENABLED, Boolean.toString(shouldVibrate()));
record.put(ATT_USER_LOCKED, Integer.toString(getUserLockedFields()));
record.put(ATT_VIBRATION, longArrayToString(getVibrationPattern()));
@@ -669,6 +695,7 @@ public final class NotificationChannel implements Parcelable {
if (mBypassDnd != that.mBypassDnd) return false;
if (getLockscreenVisibility() != that.getLockscreenVisibility()) return false;
if (mLights != that.mLights) return false;
+ if (getLightColor() != that.getLightColor()) return false;
if (getUserLockedFields() != that.getUserLockedFields()) return false;
if (mVibrationEnabled != that.mVibrationEnabled) return false;
if (mShowBadge != that.mShowBadge) return false;
@@ -698,6 +725,7 @@ public final class NotificationChannel implements Parcelable {
result = 31 * result + getLockscreenVisibility();
result = 31 * result + (getSound() != null ? getSound().hashCode() : 0);
result = 31 * result + (mLights ? 1 : 0);
+ result = 31 * result + getLightColor();
result = 31 * result + Arrays.hashCode(mVibration);
result = 31 * result + getUserLockedFields();
result = 31 * result + (mVibrationEnabled ? 1 : 0);
@@ -718,6 +746,7 @@ public final class NotificationChannel implements Parcelable {
", mLockscreenVisibility=" + mLockscreenVisibility +
", mSound=" + mSound +
", mLights=" + mLights +
+ ", mLightColor=" + mLightColor +
", mVibration=" + Arrays.toString(mVibration) +
", mUserLockedFields=" + mUserLockedFields +
", mVibrationEnabled=" + mVibrationEnabled +
diff --git a/core/proto/android/os/incident.proto b/core/proto/android/os/incident.proto
index 9beae08cb331..ba1d6646adae 100644
--- a/core/proto/android/os/incident.proto
+++ b/core/proto/android/os/incident.proto
@@ -23,6 +23,7 @@ import "frameworks/base/libs/incident/proto/android/privacy.proto";
import "frameworks/base/core/proto/android/service/appwidget.proto";
import "frameworks/base/core/proto/android/service/fingerprint.proto";
import "frameworks/base/core/proto/android/service/netstats.proto";
+import "frameworks/base/core/proto/android/service/notification.proto";
import "frameworks/base/core/proto/android/providers/settings.proto";
package android.os;
@@ -55,4 +56,5 @@ message IncidentProto {
android.service.NetworkStatsServiceDumpProto netstats = 3001;
android.providers.settings.SettingsServiceDumpProto settings = 3002;
android.service.appwidget.AppWidgetServiceDumpProto appwidget = 3003;
+ android.service.notification.NotificationServiceDumpProto notification = 3004;
}
diff --git a/core/proto/android/service/notification.proto b/core/proto/android/service/notification.proto
new file mode 100644
index 000000000000..bc257e04440d
--- /dev/null
+++ b/core/proto/android/service/notification.proto
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+syntax = "proto3";
+
+package android.service.notification;
+
+option java_multiple_files = true;
+option java_outer_classname = "NotificationServiceProto";
+
+message NotificationServiceDumpProto {
+ repeated NotificationRecordProto records = 1;
+}
+
+message NotificationRecordProto {
+ string key = 1;
+ State state = 2;
+ int32 flags = 3;
+ string channelId = 4;
+ string sound = 5;
+ int32 sound_usage = 6;
+ bool can_vibrate = 7;
+ bool can_show_light = 8;
+ string group_key = 9;
+ int32 importance = 10;
+}
+
+enum State {
+ ENQUEUED = 0;
+
+ POSTED = 1;
+} \ No newline at end of file
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
index 54c67d22e861..bffa14fb2296 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
@@ -279,6 +279,9 @@ public class StatusBar extends SystemUI implements DemoMode,
protected static final boolean ENABLE_HEADS_UP = true;
protected static final String SETTING_HEADS_UP_TICKER = "ticker_gets_heads_up";
+ // Must match constant in Settings. Used to highlight preferences when linking to Settings.
+ private static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
+
private static final String PERMISSION_SELF = "com.android.systemui.permission.SELF";
// Should match the values in PhoneWindowManager
@@ -5789,10 +5792,12 @@ public class StatusBar extends SystemUI implements DemoMode,
}
// The (i) button in the guts that links to the system notification settings for that app
- private void startAppNotificationSettingsActivity(String packageName, final int appUid) {
+ private void startAppNotificationSettingsActivity(String packageName, final int appUid,
+ final String channelId) {
final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_APP_PACKAGE, packageName);
intent.putExtra(Settings.EXTRA_APP_UID, appUid);
+ intent.putExtra(EXTRA_FRAGMENT_ARG_KEY, channelId);
startNotificationGutsIntent(intent, appUid);
}
@@ -5857,7 +5862,7 @@ public class StatusBar extends SystemUI implements DemoMode,
int appUid) -> {
MetricsLogger.action(mContext, MetricsEvent.ACTION_NOTE_INFO);
guts.resetFalsingCheck();
- startAppNotificationSettingsActivity(pkg, appUid);
+ startAppNotificationSettingsActivity(pkg, appUid, channel.getId());
};
final View.OnClickListener onDoneClick = (View v) -> {
// If the user has security enabled, show challenge if the setting is changed.
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index b543b7308eb2..32c98a1c2545 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -115,6 +115,9 @@ import android.service.notification.IStatusBarNotificationHolder;
import android.service.notification.NotificationAssistantService;
import android.service.notification.NotificationListenerService;
import android.service.notification.NotificationRankingUpdate;
+import android.service.notification.NotificationRecordProto;
+import android.service.notification.NotificationServiceDumpProto;
+import android.service.notification.NotificationServiceProto;
import android.service.notification.SnoozeCriterion;
import android.service.notification.StatusBarNotification;
import android.service.notification.ZenModeConfig;
@@ -128,6 +131,7 @@ import android.util.Log;
import android.util.Slog;
import android.util.SparseArray;
import android.util.Xml;
+import android.util.proto.ProtoOutputStream;
import android.view.WindowManagerInternal;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
@@ -2400,6 +2404,8 @@ public class NotificationManagerService extends SystemService {
final DumpFilter filter = DumpFilter.parseFromArguments(args);
if (filter != null && filter.stats) {
dumpJson(pw, filter);
+ } else if (filter != null && filter.proto) {
+ dumpProto(fd, filter);
} else {
dumpImpl(pw, filter);
}
@@ -2764,6 +2770,33 @@ public class NotificationManagerService extends SystemService {
pw.println(dump);
}
+ private void dumpProto(FileDescriptor fd, DumpFilter filter) {
+ final ProtoOutputStream proto = new ProtoOutputStream(fd);
+ synchronized (mNotificationLock) {
+ long records = proto.start(NotificationServiceDumpProto.RECORDS);
+ int N = mNotificationList.size();
+ if (N > 0) {
+ for (int i = 0; i < N; i++) {
+ final NotificationRecord nr = mNotificationList.get(i);
+ if (filter.filtered && !filter.matches(nr.sbn)) continue;
+ nr.dump(proto, filter.redact);
+ proto.write(NotificationRecordProto.STATE, NotificationServiceProto.POSTED);
+ }
+ }
+ N = mEnqueuedNotifications.size();
+ if (N > 0) {
+ for (int i = 0; i < N; i++) {
+ final NotificationRecord nr = mEnqueuedNotifications.get(i);
+ if (filter.filtered && !filter.matches(nr.sbn)) continue;
+ nr.dump(proto, filter.redact);
+ proto.write(NotificationRecordProto.STATE, NotificationServiceProto.ENQUEUED);
+ }
+ }
+ proto.end(records);
+ }
+ proto.flush();
+ }
+
void dumpImpl(PrintWriter pw, DumpFilter filter) {
pw.print("Current Notification Manager state");
if (filter.filtered) {
@@ -4822,11 +4855,15 @@ public class NotificationManagerService extends SystemService {
public long since;
public boolean stats;
public boolean redact = true;
+ public boolean proto = false;
public static DumpFilter parseFromArguments(String[] args) {
final DumpFilter filter = new DumpFilter();
for (int ai = 0; ai < args.length; ai++) {
final String a = args[ai];
+ if ("--proto".equals(args[0])) {
+ filter.proto = true;
+ }
if ("--noredact".equals(a) || "--reveal".equals(a)) {
filter.redact = false;
} else if ("p".equals(a) || "pkg".equals(a) || "--package".equals(a)) {
diff --git a/services/core/java/com/android/server/notification/NotificationRecord.java b/services/core/java/com/android/server/notification/NotificationRecord.java
index d26aa9e00d12..3016b17db7b9 100644
--- a/services/core/java/com/android/server/notification/NotificationRecord.java
+++ b/services/core/java/com/android/server/notification/NotificationRecord.java
@@ -37,12 +37,14 @@ import android.os.Build;
import android.os.UserHandle;
import android.provider.Settings;
import android.service.notification.NotificationListenerService;
+import android.service.notification.NotificationRecordProto;
import android.service.notification.SnoozeCriterion;
import android.service.notification.StatusBarNotification;
import android.text.TextUtils;
import android.util.Log;
import android.util.Slog;
import android.util.TimeUtils;
+import android.util.proto.ProtoOutputStream;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.MetricsLogger;
@@ -185,7 +187,9 @@ public final class NotificationRecord {
int defaultLightOff = mContext.getResources().getInteger(
com.android.internal.R.integer.config_defaultNotificationLedOff);
- Light light = getChannel().shouldShowLights() ? new Light(defaultLightColor,
+ int channelLightColor = getChannel().getLightColor() != 0 ? getChannel().getLightColor()
+ : defaultLightColor;
+ Light light = getChannel().shouldShowLights() ? new Light(channelLightColor,
defaultLightOn, defaultLightOff) : null;
if (mPreChannelsNotification
&& (getChannel().getUserLockedFields()
@@ -335,6 +339,24 @@ public final class NotificationRecord {
/** @deprecated Use {@link #getUser()} instead. */
public int getUserId() { return sbn.getUserId(); }
+ void dump(ProtoOutputStream proto, boolean redact) {
+ proto.write(NotificationRecordProto.KEY, sbn.getKey());
+ if (getChannel() != null) {
+ proto.write(NotificationRecordProto.CHANNEL_ID, getChannel().getId());
+ }
+ proto.write(NotificationRecordProto.CAN_SHOW_LIGHT, getLight() != null);
+ proto.write(NotificationRecordProto.CAN_VIBRATE, getVibration() != null);
+ proto.write(NotificationRecordProto.FLAGS, sbn.getNotification().flags);
+ proto.write(NotificationRecordProto.GROUP_KEY, getGroupKey());
+ proto.write(NotificationRecordProto.IMPORTANCE, getImportance());
+ if (getSound() != null) {
+ proto.write(NotificationRecordProto.SOUND, getSound().toString());
+ }
+ if (getAudioAttributes() != null) {
+ proto.write(NotificationRecordProto.SOUND_USAGE, getAudioAttributes().getUsage());
+ }
+ }
+
void dump(PrintWriter pw, String prefix, Context baseContext, boolean redact) {
final Notification notification = sbn.getNotification();
final Icon icon = notification.getSmallIcon();
diff --git a/services/core/java/com/android/server/notification/RankingHelper.java b/services/core/java/com/android/server/notification/RankingHelper.java
index 8176e5dc4788..4cbeec815c31 100644
--- a/services/core/java/com/android/server/notification/RankingHelper.java
+++ b/services/core/java/com/android/server/notification/RankingHelper.java
@@ -563,7 +563,8 @@ public class RankingHelper implements RankingConfig {
channel.setImportance(updatedChannel.getImportance());
}
if ((channel.getUserLockedFields() & NotificationChannel.USER_LOCKED_LIGHTS) == 0) {
- channel.setLights(updatedChannel.shouldShowLights());
+ channel.enableLights(updatedChannel.shouldShowLights());
+ channel.setLightColor(updatedChannel.getLightColor());
}
if ((channel.getUserLockedFields() & NotificationChannel.USER_LOCKED_PRIORITY) == 0) {
channel.setBypassDnd(updatedChannel.canBypassDnd());
diff --git a/services/tests/notification/src/com/android/server/notification/BuzzBeepBlinkTest.java b/services/tests/notification/src/com/android/server/notification/BuzzBeepBlinkTest.java
index 9202cce3b062..15f7557c92ef 100644
--- a/services/tests/notification/src/com/android/server/notification/BuzzBeepBlinkTest.java
+++ b/services/tests/notification/src/com/android/server/notification/BuzzBeepBlinkTest.java
@@ -20,7 +20,6 @@ import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
import com.android.server.lights.Light;
-import com.android.server.statusbar.StatusBarManagerInternal;
import org.junit.Before;
import org.junit.Test;
@@ -224,7 +223,7 @@ public class BuzzBeepBlinkTest {
} else {
builder.setLights(CUSTOM_LIGHT_COLOR, CUSTOM_LIGHT_ON, CUSTOM_LIGHT_OFF);
}
- channel.setLights(true);
+ channel.enableLights(true);
}
builder.setDefaults(defaults);
diff --git a/services/tests/notification/src/com/android/server/notification/NotificationRecordTest.java b/services/tests/notification/src/com/android/server/notification/NotificationRecordTest.java
index 0ec368f44f81..13d6c5d774d6 100644
--- a/services/tests/notification/src/com/android/server/notification/NotificationRecordTest.java
+++ b/services/tests/notification/src/com/android/server/notification/NotificationRecordTest.java
@@ -33,6 +33,7 @@ import android.app.NotificationManager;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
+import android.graphics.Color;
import android.media.AudioAttributes;
import android.net.Uri;
import android.os.Build;
@@ -137,10 +138,11 @@ public class NotificationRecordTest {
defaults |= Notification.DEFAULT_LIGHTS;
} else {
builder.setLights(CUSTOM_LIGHT.color, CUSTOM_LIGHT.onMs, CUSTOM_LIGHT.offMs);
+ channel.setLightColor(Color.BLUE);
}
- channel.setLights(true);
+ channel.enableLights(true);
} else {
- channel.setLights(false);
+ channel.enableLights(false);
}
builder.setDefaults(defaults);
@@ -316,7 +318,7 @@ public class NotificationRecordTest {
@Test
public void testLights_locked_preUpgrade() throws Exception {
- defaultChannel.setLights(true);
+ defaultChannel.enableLights(true);
defaultChannel.lockFields(NotificationChannel.USER_LOCKED_LIGHTS);
StatusBarNotification sbn = getNotification(true /*preO */, true /* noisy */,
true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */,
@@ -327,7 +329,7 @@ public class NotificationRecordTest {
}
@Test
- public void testLights_upgrade() throws Exception {
+ public void testLights_upgrade_defaultLights() throws Exception {
int defaultLightColor = mMockContext.getResources().getColor(
com.android.internal.R.color.config_defaultNotificationColor);
int defaultLightOn = mMockContext.getResources().getInteger(
@@ -339,6 +341,22 @@ public class NotificationRecordTest {
defaultLightColor, defaultLightOn, defaultLightOff);
StatusBarNotification sbn = getNotification(false /*preO */, true /* noisy */,
true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */,
+ true /* lights */, true /*defaultLights */);
+ NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel);
+ assertEquals(expected, record.getLight());
+ }
+
+ @Test
+ public void testLights_upgrade() throws Exception {
+ int defaultLightOn = mMockContext.getResources().getInteger(
+ com.android.internal.R.integer.config_defaultNotificationLedOn);
+ int defaultLightOff = mMockContext.getResources().getInteger(
+ com.android.internal.R.integer.config_defaultNotificationLedOff);
+
+ NotificationRecord.Light expected = new NotificationRecord.Light(
+ Color.BLUE, defaultLightOn, defaultLightOff);
+ StatusBarNotification sbn = getNotification(false /*preO */, true /* noisy */,
+ true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */,
true /* lights */, false /*defaultLights */);
NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel);
assertEquals(expected, record.getLight());
diff --git a/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java b/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java
index 9fa46d1c6bb0..e20b5715043d 100644
--- a/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java
+++ b/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java
@@ -36,6 +36,7 @@ import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
+import android.graphics.Color;
import android.media.AudioAttributes;
import android.net.Uri;
import android.os.Build;
@@ -200,6 +201,7 @@ public class RankingHelperTest {
assertTrue(Arrays.equals(expected.getVibrationPattern(), actual.getVibrationPattern()));
assertEquals(expected.getGroup(), actual.getGroup());
assertEquals(expected.getAudioAttributes(), actual.getAudioAttributes());
+ assertEquals(expected.getLightColor(), actual.getLightColor());
}
@Test
@@ -260,12 +262,13 @@ public class RankingHelperTest {
NotificationChannel channel2 =
new NotificationChannel("id2", "name2", NotificationManager.IMPORTANCE_LOW);
channel2.setSound(new Uri.Builder().scheme("test").build(), mAudioAttributes);
- channel2.setLights(true);
+ channel2.enableLights(true);
channel2.setBypassDnd(true);
channel2.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
channel2.enableVibration(true);
channel2.setGroup(ncg.getId());
channel2.setVibrationPattern(new long[]{100, 67, 145, 156});
+ channel2.setLightColor(Color.BLUE);
mHelper.createNotificationChannelGroup(pkg, uid, ncg, true);
mHelper.createNotificationChannel(pkg, uid, channel1, true);
@@ -437,7 +440,7 @@ public class RankingHelperTest {
// all fields locked by user
final NotificationChannel channel =
new NotificationChannel("id2", "name2", NotificationManager.IMPORTANCE_LOW);
- channel.setLights(false);
+ channel.enableLights(false);
channel.lockFields(NotificationChannel.USER_LOCKED_VIBRATION);
mHelper.createNotificationChannel(pkg, uid, channel, false);
@@ -459,7 +462,7 @@ public class RankingHelperTest {
// all fields locked by user
final NotificationChannel channel =
new NotificationChannel("id2", "name2", NotificationManager.IMPORTANCE_LOW);
- channel.setLights(false);
+ channel.enableLights(false);
channel.lockFields(NotificationChannel.USER_LOCKED_LIGHTS);
mHelper.createNotificationChannel(pkg, uid, channel, false);
@@ -467,7 +470,7 @@ public class RankingHelperTest {
// same id, try to update
final NotificationChannel channel2 =
new NotificationChannel("id2", "name2", NotificationManager.IMPORTANCE_HIGH);
- channel2.setLights(true);
+ channel2.enableLights(true);
mHelper.updateNotificationChannelFromAssistant(pkg, uid, channel2);
@@ -542,7 +545,7 @@ public class RankingHelperTest {
final NotificationChannel channel =
new NotificationChannel("id2", "name2", NotificationManager.IMPORTANCE_LOW);
channel.setSound(new Uri.Builder().scheme("test").build(), mAudioAttributes);
- channel.setLights(true);
+ channel.enableLights(true);
channel.setBypassDnd(true);
channel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
@@ -552,7 +555,7 @@ public class RankingHelperTest {
final NotificationChannel channel2 =
new NotificationChannel("id2", "name2", NotificationManager.IMPORTANCE_HIGH);
channel2.setSound(new Uri.Builder().scheme("test2").build(), mAudioAttributes);
- channel2.setLights(false);
+ channel2.enableLights(false);
channel2.setBypassDnd(false);
channel2.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
@@ -574,7 +577,7 @@ public class RankingHelperTest {
final NotificationChannel channel =
new NotificationChannel("id2", "name2", NotificationManager.IMPORTANCE_LOW);
channel.setSound(new Uri.Builder().scheme("test").build(), mAudioAttributes);
- channel.setLights(true);
+ channel.enableLights(true);
channel.setBypassDnd(true);
channel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
channel.setShowBadge(true);
@@ -601,7 +604,7 @@ public class RankingHelperTest {
final NotificationChannel channel =
new NotificationChannel("id2", "name2", NotificationManager.IMPORTANCE_LOW);
channel.setSound(new Uri.Builder().scheme("test").build(), mAudioAttributes);
- channel.setLights(true);
+ channel.enableLights(true);
channel.setBypassDnd(true);
channel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
channel.setShowBadge(true);
@@ -628,7 +631,7 @@ public class RankingHelperTest {
NotificationChannel channel =
new NotificationChannel("id2", "name2", NotificationManager.IMPORTANCE_LOW);
channel.setSound(new Uri.Builder().scheme("test").build(), mAudioAttributes);
- channel.setLights(true);
+ channel.enableLights(true);
channel.setBypassDnd(true);
channel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
channel.enableVibration(true);
@@ -654,7 +657,7 @@ public class RankingHelperTest {
NotificationChannel channel =
new NotificationChannel("id2", "name2", NotificationManager.IMPORTANCE_LOW);
channel.setSound(new Uri.Builder().scheme("test").build(), mAudioAttributes);
- channel.setLights(true);
+ channel.enableLights(true);
channel.setBypassDnd(true);
channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
channel.enableVibration(true);