Show localized channel names

Test: manual
Change-Id: I85d60e564aeff8074cdb8138fe7ac1c078be986a
diff --git a/src/com/android/settings/notification/AppNotificationSettings.java b/src/com/android/settings/notification/AppNotificationSettings.java
index 4c310e6..eecc77c 100644
--- a/src/com/android/settings/notification/AppNotificationSettings.java
+++ b/src/com/android/settings/notification/AppNotificationSettings.java
@@ -182,13 +182,13 @@
                             getPrefContext());
                     channelPref.setDisabledByAdmin(mSuspendedAppsAdmin);
                     channelPref.setKey(channel.getId());
-                    channelPref.setTitle(channel.getName());
+                    channelPref.setTitle(getNotificationChannelLabel(channel));
                     channelPref.setChecked(channel.getImportance() != IMPORTANCE_NONE);
                     channelPref.setMultiLine(true);
 
                     if (channel.isDeleted()) {
-                        channelPref.setTitle(
-                                getString(R.string.deleted_channel_name, channel.getName()));
+                        channelPref.setTitle(getString(R.string.deleted_channel_name,
+                                getNotificationChannelLabel(channel)));
                         channelPref.setEnabled(false);
                     } else {
                         channelPref.setSummary(getImportanceSummary(channel.getImportance()));
@@ -275,8 +275,10 @@
             if (left.isDeleted() != right.isDeleted()) {
                 return Boolean.compare(left.isDeleted(), right.isDeleted());
             }
-            if (!Objects.equals(left.getName(), right.getName())) {
-                return sCollator.compare(left.getName().toString(), right.getName().toString());
+            if (!Objects.equals(getNotificationChannelLabel(left),
+                    getNotificationChannelLabel(right))) {
+                return sCollator.compare(getNotificationChannelLabel(left).toString(),
+                        getNotificationChannelLabel(right).toString());
             }
             return left.getId().compareTo(right.getId());
         }
diff --git a/src/com/android/settings/notification/ChannelNotificationSettings.java b/src/com/android/settings/notification/ChannelNotificationSettings.java
index ea450f4..7be98c1 100644
--- a/src/com/android/settings/notification/ChannelNotificationSettings.java
+++ b/src/com/android/settings/notification/ChannelNotificationSettings.java
@@ -130,7 +130,7 @@
                     .getApplicationFeatureProvider(activity)
                     .newAppHeaderController(this /* fragment */, null /* appHeader */)
                     .setIcon(mAppRow.icon)
-                    .setLabel(mChannel.getName())
+                    .setLabel(getNotificationChannelLabel(mChannel))
                     .setSummary(mAppRow.label)
                     .setPackageName(mAppRow.pkg)
                     .setUid(mAppRow.uid)
diff --git a/src/com/android/settings/notification/NotificationBackend.java b/src/com/android/settings/notification/NotificationBackend.java
index 2a2185d..d201d60 100644
--- a/src/com/android/settings/notification/NotificationBackend.java
+++ b/src/com/android/settings/notification/NotificationBackend.java
@@ -155,8 +155,4 @@
         public boolean showBadge;
         public int userId;
     }
-
-    public static class ChannelRow extends AppRow {
-        public NotificationChannel channel;
-    }
 }
diff --git a/src/com/android/settings/notification/NotificationSettingsBase.java b/src/com/android/settings/notification/NotificationSettingsBase.java
index 80d249f..099b4f4 100644
--- a/src/com/android/settings/notification/NotificationSettingsBase.java
+++ b/src/com/android/settings/notification/NotificationSettingsBase.java
@@ -248,4 +248,17 @@
                 return getContext().getString(R.string.notification_importance_high);
         }
     }
+
+    protected CharSequence getNotificationChannelLabel(NotificationChannel channel) {
+        if (channel.getName() != null) {
+            return channel.getName();
+        }
+        try {
+            ApplicationInfo info = mPm.getApplicationInfoAsUser(mAppRow.pkg, 0, mAppRow.userId);
+            return mPm.getText(mAppRow.pkg, channel.getNameResId(), info);
+        } catch (NameNotFoundException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
 }