Add group name into channel summary, if applicable.

Bug: 36642898
Test: ran integration & robo tests (no new failures); verified manually with apps with channels & without.

Change-Id: I16a255b0e5d929f4485d3725bd18179e6f411c03
This commit is contained in:
Alison Cichowlas
2017-05-30 08:48:59 -04:00
parent 52c031edae
commit 8ad2fa6865
3 changed files with 62 additions and 3 deletions

View File

@@ -8830,4 +8830,8 @@
<!-- Summary label for new device suggestion, which is displayed in Settings homepage [CHAR LIMIT=100] --> <!-- Summary label for new device suggestion, which is displayed in Settings homepage [CHAR LIMIT=100] -->
<string name="new_device_suggestion_summary">Check out the top 5 features</string> <string name="new_device_suggestion_summary">Check out the top 5 features</string>
<!-- The divider symbol between different parts of the notification header including spaces. not translatable [CHAR LIMIT=3] -->
<string name="notification_header_divider_symbol_with_spaces" translatable="false">" • "</string>
</resources> </resources>

View File

@@ -18,13 +18,17 @@ package com.android.settings.notification;
import android.app.Activity; import android.app.Activity;
import android.app.NotificationChannel; import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.AsyncTask;
import android.provider.Settings; import android.provider.Settings;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.BidiFormatter;
import android.text.SpannableStringBuilder;
import android.util.ArrayMap; import android.util.ArrayMap;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@@ -60,6 +64,8 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
private RestrictedSwitchPreference mVibrate; private RestrictedSwitchPreference mVibrate;
private NotificationSoundPreference mRingtone; private NotificationSoundPreference mRingtone;
private FooterPreference mFooter; private FooterPreference mFooter;
private NotificationChannelGroup mChannelGroup;
private EntityHeaderController mHeaderPref;
@Override @Override
public int getMetricsCategory() { public int getMetricsCategory() {
@@ -89,6 +95,27 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
mShowLegacyChannelConfig = true; mShowLegacyChannelConfig = true;
} else { } else {
populateUpgradedChannelPrefs(); populateUpgradedChannelPrefs();
if (mChannel.getGroup() != null) {
// Go look up group name
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... unused) {
if (mChannel.getGroup() != null) {
mChannelGroup = mBackend.getGroup(mChannel.getGroup(), mPkg, mUid);
}
return null;
}
@Override
protected void onPostExecute(Void unused) {
if (getHost() == null || mChannelGroup == null) {
return;
}
setChannelGroupLabel(mChannelGroup.getName());
}
}.execute();
}
} }
updateDependents(mChannel.getImportance() == IMPORTANCE_NONE); updateDependents(mChannel.getImportance() == IMPORTANCE_NONE);
@@ -110,9 +137,10 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
rows.put(mAppRow.pkg, mAppRow); rows.put(mAppRow.pkg, mAppRow);
collectConfigActivities(rows); collectConfigActivities(rows);
final Activity activity = getActivity(); final Activity activity = getActivity();
final Preference pref = EntityHeaderController mHeaderPref = EntityHeaderController
.newInstance(activity, this /* fragment */, null /* header */) .newInstance(activity, this /* fragment */, null /* header */)
.setRecyclerView(getListView(), getLifecycle()) .setRecyclerView(getListView(), getLifecycle());
final Preference pref = mHeaderPref
.setIcon(mAppRow.icon) .setIcon(mAppRow.icon)
.setLabel(mChannel.getName()) .setLabel(mChannel.getName())
.setSummary(mAppRow.label) .setSummary(mAppRow.label)
@@ -124,6 +152,20 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
getPreferenceScreen().addPreference(pref); getPreferenceScreen().addPreference(pref);
} }
private void setChannelGroupLabel(CharSequence groupName) {
final SpannableStringBuilder summary = new SpannableStringBuilder();
BidiFormatter bidi = BidiFormatter.getInstance();
summary.append(bidi.unicodeWrap(mAppRow.label.toString()));
if (groupName != null) {
summary.append(bidi.unicodeWrap(mContext.getText(
R.string.notification_header_divider_symbol_with_spaces)));
summary.append(bidi.unicodeWrap(groupName.toString()));
}
final Activity activity = getActivity();
mHeaderPref.setSummary(summary.toString());
mHeaderPref.done(activity, getPrefContext());
}
private void addFooterPref() { private void addFooterPref() {
if (!TextUtils.isEmpty(mChannel.getDescription())) { if (!TextUtils.isEmpty(mChannel.getDescription())) {
FooterPreference descPref = new FooterPreference(getPrefContext()); FooterPreference descPref = new FooterPreference(getPrefContext());
@@ -341,7 +383,7 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
if (mAppLink != null) { if (mAppLink != null) {
setVisible(mAppLink, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN)); setVisible(mAppLink, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN));
} }
if (mFooter !=null) { if (mFooter != null) {
setVisible(mFooter, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN)); setVisible(mFooter, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN));
} }
} }

View File

@@ -122,6 +122,19 @@ public class NotificationBackend {
} }
} }
public NotificationChannelGroup getGroup(String groupId, String pkg, int uid) {
if (groupId == null) {
return null;
}
try {
return sINM.getNotificationChannelGroupForPackage(groupId, pkg, uid);
} catch (Exception e) {
Log.w(TAG, "Error calling NoMan", e);
return null;
}
}
public ParceledListSlice<NotificationChannelGroup> getChannelGroups(String pkg, int uid) { public ParceledListSlice<NotificationChannelGroup> getChannelGroups(String pkg, int uid) {
try { try {
return sINM.getNotificationChannelGroupsForPackage(pkg, uid, false); return sINM.getNotificationChannelGroupsForPackage(pkg, uid, false);