Merge changes I36636687,I4c45f787 into oc-mr1-dev

* changes:
  Doc updates
  Translate default channel on locale change
This commit is contained in:
TreeHugger Robot
2017-08-17 15:54:52 +00:00
committed by Android (Google) Code Review
5 changed files with 47 additions and 12 deletions

View File

@@ -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>
*/

View File

@@ -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;

View File

@@ -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());
}
}
};

View File

@@ -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) {

View File

@@ -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());
}
}