summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2017-08-17 15:54:52 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2017-08-17 15:54:52 +0000
commit54ff7e7582b374b7e940b560f3fdda512dfd7ebb (patch)
treef4c776a59bc67a1d970bc543d0f1874d9570bf67
parentd33fe05c66b8423d956c55f0cc6a74269cd94adc (diff)
parent399d9bfa21160e9954e51798060780fcd09e54ae (diff)
Merge changes I36636687,I4c45f787 into oc-mr1-dev
* changes: Doc updates Translate default channel on locale change
-rw-r--r--core/java/android/app/Notification.java10
-rw-r--r--core/java/android/app/NotificationChannelGroup.java10
-rw-r--r--services/core/java/com/android/server/notification/NotificationManagerService.java1
-rw-r--r--services/core/java/com/android/server/notification/RankingHelper.java16
-rw-r--r--services/tests/notification/src/com/android/server/notification/RankingHelperTest.java22
5 files changed, 47 insertions, 12 deletions
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index dea1dbeeffae..586f13f1f942 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -1164,7 +1164,8 @@ public class Notification implements Parcelable
* Constant for {@link Builder#setGroupAlertBehavior(int)}, meaning that all children
* notification in a group should be silenced (no sound or vibration) even if they are posted
* to a {@link NotificationChannel} that has sound and/or vibration. Use this constant to
- * mute this notification if this notification is a group child.
+ * mute this notification if this notification is a group child. This must be applied to all
+ * children notifications you want to mute.
*
* <p> For example, you might want to use this constant if you post a number of children
* notifications at once (say, after a periodic sync), and only need to notify the user
@@ -1179,7 +1180,8 @@ public class Notification implements Parcelable
* to mute this notification if this notification is a group summary.
*
* <p>For example, you might want to use this constant if only the children notifications
- * in your group have content and the summary is only used to visually group notifications.
+ * in your group have content and the summary is only used to visually group notifications
+ * rather than to alert the user that new information is available.
*/
public static final int GROUP_ALERT_CHILDREN = 2;
@@ -2914,7 +2916,9 @@ public class Notification implements Parcelable
* Sets the group alert behavior for this notification. Use this method to mute this
* notification if alerts for this notification's group should be handled by a different
* notification. This is only applicable for notifications that belong to a
- * {@link #setGroup(String) group}.
+ * {@link #setGroup(String) group}. This must be called on all notifications you want to
+ * mute. For example, if you want only the summary of your group to make noise, all
+ * children in the group should have the group alert behavior {@link #GROUP_ALERT_SUMMARY}.
*
* <p> The default value is {@link #GROUP_ALERT_ALL}.</p>
*/
diff --git a/core/java/android/app/NotificationChannelGroup.java b/core/java/android/app/NotificationChannelGroup.java
index 7e8f191acdb9..18ad9cf3d8e3 100644
--- a/core/java/android/app/NotificationChannelGroup.java
+++ b/core/java/android/app/NotificationChannelGroup.java
@@ -15,24 +15,18 @@
*/
package android.app;
-import android.annotation.StringRes;
import android.annotation.SystemApi;
import android.content.Intent;
-import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
-import android.service.notification.NotificationListenerService;
import android.text.TextUtils;
-import android.util.Slog;
import org.json.JSONException;
import org.json.JSONObject;
-import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlSerializer;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
/**
@@ -115,10 +109,8 @@ public final class NotificationChannelGroup implements Parcelable {
return mName;
}
- /*
+ /**
* Returns the list of channels that belong to this group
- *
- * @hide
*/
public List<NotificationChannel> getChannels() {
return mChannels;
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index 28acd9af6f5f..845efa6186c8 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -804,6 +804,7 @@ public class NotificationManagerService extends SystemService {
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_LOCALE_CHANGED.equals(intent.getAction())) {
mZenModeHelper.updateDefaultZenRules();
+ mRankingHelper.onLocaleChanged(context, ActivityManager.getCurrentUser());
}
}
};
diff --git a/services/core/java/com/android/server/notification/RankingHelper.java b/services/core/java/com/android/server/notification/RankingHelper.java
index 9622a24a2d4d..3386fe832e0f 100644
--- a/services/core/java/com/android/server/notification/RankingHelper.java
+++ b/services/core/java/com/android/server/notification/RankingHelper.java
@@ -1073,6 +1073,22 @@ public class RankingHelper implements RankingConfig {
}
}
+ protected void onLocaleChanged(Context context, int userId) {
+ synchronized (mRecords) {
+ int N = mRecords.size();
+ for (int i = 0; i < N; i++) {
+ Record record = mRecords.valueAt(i);
+ if (UserHandle.getUserId(record.uid) == userId) {
+ if (record.channels.containsKey(NotificationChannel.DEFAULT_CHANNEL_ID)) {
+ record.channels.get(NotificationChannel.DEFAULT_CHANNEL_ID).setName(
+ context.getResources().getString(
+ R.string.default_notification_channel_label));
+ }
+ }
+ }
+ }
+ }
+
public void onPackagesChanged(boolean removingPackage, int changeUserId, String[] pkgList,
int[] uidList) {
if (pkgList == null || pkgList.length == 0) {
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 801479b33ce5..65bf33084bb4 100644
--- a/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java
+++ b/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java
@@ -46,6 +46,7 @@ import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
+import android.content.res.Resources;
import android.graphics.Color;
import android.media.AudioAttributes;
import android.net.Uri;
@@ -78,6 +79,7 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -127,6 +129,8 @@ public class RankingHelperTest extends NotificationTestCase {
when(mPm.getPackageUidAsUser(eq(UPDATED_PKG), anyInt())).thenReturn(UID2);
when(mContext.getResources()).thenReturn(
InstrumentationRegistry.getContext().getResources());
+ when(mContext.getContentResolver()).thenReturn(
+ InstrumentationRegistry.getContext().getContentResolver());
when(mContext.getPackageManager()).thenReturn(mPm);
when(mContext.getApplicationInfo()).thenReturn(legacy);
// most tests assume badging is enabled
@@ -1366,4 +1370,22 @@ public class RankingHelperTest extends NotificationTestCase {
assertFalse(mHelper.badgingEnabled(USER));
assertTrue(mHelper.badgingEnabled(USER2));
}
+
+ @Test
+ public void testOnLocaleChanged_updatesDefaultChannels() throws Exception {
+ String newLabel = "bananas!";
+ final NotificationChannel defaultChannel = mHelper.getNotificationChannel(PKG, UID,
+ NotificationChannel.DEFAULT_CHANNEL_ID, false);
+ assertFalse(newLabel.equals(defaultChannel.getName()));
+
+ Resources res = mock(Resources.class);
+ when(mContext.getResources()).thenReturn(res);
+ when(res.getString(com.android.internal.R.string.default_notification_channel_label))
+ .thenReturn(newLabel);
+
+ mHelper.onLocaleChanged(mContext, USER.getIdentifier());
+
+ assertEquals(newLabel, mHelper.getNotificationChannel(PKG, UID,
+ NotificationChannel.DEFAULT_CHANNEL_ID, false).getName());
+ }
}