Revert "Changed alert window notifications to use single channel"
This reverts commit 8f7bebca3656f4993edef290e62c960f245ff373.
We now want multiple channels so the user can disable which ever ones they like.
Change-Id: I6015cd5f1e3f37a8a01e1db42b57a94087780304
Fixes: 38428796
Bug: 37422870
diff --git a/services/core/java/com/android/server/wm/AlertWindowNotification.java b/services/core/java/com/android/server/wm/AlertWindowNotification.java
index 50b1520..7ed3eac 100644
--- a/services/core/java/com/android/server/wm/AlertWindowNotification.java
+++ b/services/core/java/com/android/server/wm/AlertWindowNotification.java
@@ -16,14 +16,15 @@
package com.android.server.wm;
+import static android.app.NotificationManager.IMPORTANCE_MIN;
import static android.app.PendingIntent.FLAG_CANCEL_CURRENT;
import static android.content.Context.NOTIFICATION_SERVICE;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.provider.Settings.ACTION_MANAGE_OVERLAY_PERMISSION;
-import static com.android.internal.notification.SystemNotificationChannels.ALERT_WINDOW;
import android.app.Notification;
+import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
@@ -40,7 +41,7 @@
/** Displays an ongoing notification for a process displaying an alert window */
class AlertWindowNotification {
- private static final String TAG_PREFIX = "com.android.server.wm.AlertWindowNotification: ";
+ private static final String CHANNEL_PREFIX = "com.android.server.wm.AlertWindowNotification - ";
private static final int NOTIFICATION_ID = 0;
private static int sNextRequestCode = 0;
@@ -57,7 +58,7 @@
mPackageName = packageName;
mNotificationManager =
(NotificationManager) mService.mContext.getSystemService(NOTIFICATION_SERVICE);
- mNotificationTag = TAG_PREFIX + mPackageName;
+ mNotificationTag = CHANNEL_PREFIX + mPackageName;
mRequestCode = sNextRequestCode++;
mIconUtilities = new IconUtilities(mService.mContext);
}
@@ -99,9 +100,11 @@
final String appName = (aInfo != null)
? pm.getApplicationLabel(aInfo).toString() : mPackageName;
+ createNotificationChannelIfNeeded(context, appName);
+
final String message = context.getString(R.string.alert_windows_notification_message,
appName);
- final Notification.Builder builder = new Notification.Builder(context, ALERT_WINDOW)
+ final Notification.Builder builder = new Notification.Builder(context, mNotificationTag)
.setOngoing(true)
.setContentTitle(
context.getString(R.string.alert_windows_notification_title, appName))
@@ -131,6 +134,20 @@
return PendingIntent.getActivity(context, mRequestCode, intent, FLAG_CANCEL_CURRENT);
}
+ private void createNotificationChannelIfNeeded(Context context, String appName) {
+ if (mNotificationManager.getNotificationChannel(mNotificationTag) != null) {
+ return;
+ }
+ final String nameChannel =
+ context.getString(R.string.alert_windows_notification_channel_name, appName);
+ final NotificationChannel channel =
+ new NotificationChannel(mNotificationTag, nameChannel, IMPORTANCE_MIN);
+ channel.enableLights(false);
+ channel.enableVibration(false);
+ mNotificationManager.createNotificationChannel(channel);
+ }
+
+
private ApplicationInfo getApplicationInfo(PackageManager pm, String packageName) {
try {
return pm.getApplicationInfo(packageName, 0);