diff options
| author | 2017-05-23 03:32:38 +0000 | |
|---|---|---|
| committer | 2017-05-23 03:32:43 +0000 | |
| commit | 540cb28c5abee91bcdfe065b31501393d993ea24 (patch) | |
| tree | 3ca5330c598f652d025ac770f9e2a75d49a84cfa | |
| parent | 42c6529c1dbb411ca6b41890ff2f336726286afc (diff) | |
| parent | af38fd7b0f4de5d4f2b0f750e9d2775c06c66b38 (diff) | |
Merge "Revert "Changed alert window notifications to use single channel"" into oc-dev
3 files changed, 22 insertions, 11 deletions
diff --git a/core/java/com/android/internal/notification/SystemNotificationChannels.java b/core/java/com/android/internal/notification/SystemNotificationChannels.java index d279746294b3..797cf2b6de56 100644 --- a/core/java/com/android/internal/notification/SystemNotificationChannels.java +++ b/core/java/com/android/internal/notification/SystemNotificationChannels.java @@ -47,7 +47,6 @@ public class SystemNotificationChannels { public static String RETAIL_MODE = "RETAIL_MODE"; public static String USB = "USB"; public static String FOREGROUND_SERVICE = "FOREGROUND_SERVICE"; - public static String ALERT_WINDOW = "ALERT_WINDOW"; public static void createAll(Context context) { final NotificationManager nm = context.getSystemService(NotificationManager.class); @@ -138,11 +137,6 @@ public class SystemNotificationChannels { context.getString(R.string.notification_channel_foreground_service), NotificationManager.IMPORTANCE_MIN)); - channelsList.add(new NotificationChannel( - ALERT_WINDOW, - context.getString(R.string.alert_windows_notification_channel_name), - NotificationManager.IMPORTANCE_MIN)); - nm.createNotificationChannels(channelsList); } diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index fcabe3199f69..f747d3dfcba3 100644 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -3225,7 +3225,7 @@ <skip /> <!-- Name of notification channel the system post notification to inform the use about apps that are drawing ui on-top of other apps (alert-windows) [CHAR LIMIT=NONE] --> - <string name="alert_windows_notification_channel_name">App activity</string> + <string name="alert_windows_notification_channel_name"><xliff:g id="name" example="Google Maps">%s</xliff:g> displaying over other apps</string> <!-- Notification title when an application is displaying ui on-top of other apps [CHAR LIMIT=30] --> <string name="alert_windows_notification_title"><xliff:g id="name" example="Google Maps">%s</xliff:g> is displaying over other apps</string> diff --git a/services/core/java/com/android/server/wm/AlertWindowNotification.java b/services/core/java/com/android/server/wm/AlertWindowNotification.java index 50b1520f32a4..7ed3eac10d11 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 @@ import com.android.server.policy.IconUtilities; /** 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 @@ class AlertWindowNotification { 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 @@ class AlertWindowNotification { 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 @@ class AlertWindowNotification { 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); |