Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8f7bebca authored by Wale Ogunwale's avatar Wale Ogunwale
Browse files

Changed alert window notifications to use single channel

Per UX request.

Change-Id: Iefe1be52743519af5ee1481b59613c87f16bdf7d
Fixes: 37422870
Test: Verify alert window notification channel.
parent 721a3488
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -47,6 +47,7 @@ public class SystemNotificationChannels {
    public static String RETAIL_MODE = "RETAIL_MODE";
    public static String RETAIL_MODE = "RETAIL_MODE";
    public static String USB = "USB";
    public static String USB = "USB";
    public static String FOREGROUND_SERVICE = "FOREGROUND_SERVICE";
    public static String FOREGROUND_SERVICE = "FOREGROUND_SERVICE";
    public static String ALERT_WINDOW = "ALERT_WINDOW";


    public static void createAll(Context context) {
    public static void createAll(Context context) {
        final NotificationManager nm = context.getSystemService(NotificationManager.class);
        final NotificationManager nm = context.getSystemService(NotificationManager.class);
@@ -137,6 +138,11 @@ public class SystemNotificationChannels {
                context.getString(R.string.notification_channel_foreground_service),
                context.getString(R.string.notification_channel_foreground_service),
                NotificationManager.IMPORTANCE_MIN));
                NotificationManager.IMPORTANCE_MIN));


        channelsList.add(new NotificationChannel(
                ALERT_WINDOW,
                context.getString(R.string.alert_windows_notification_channel_name),
                NotificationManager.IMPORTANCE_MIN));

        nm.createNotificationChannels(channelsList);
        nm.createNotificationChannels(channelsList);
    }
    }


+1 −1
Original line number Original line Diff line number Diff line
@@ -3225,7 +3225,7 @@
    <skip />
    <skip />
    <!-- Name of notification channel the system post notification to inform the use about apps
    <!-- 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] -->
         that are drawing ui on-top of other apps (alert-windows) [CHAR LIMIT=NONE] -->
    <string name="alert_windows_notification_channel_name"><xliff:g id="name" example="Google Maps">%s</xliff:g> displaying over other apps</string>
    <string name="alert_windows_notification_channel_name">App activity</string>
    <!-- Notification title when an application is displaying ui on-top of other apps
    <!-- Notification title when an application is displaying ui on-top of other apps
         [CHAR LIMIT=30] -->
         [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>
    <string name="alert_windows_notification_title"><xliff:g id="name" example="Google Maps">%s</xliff:g> is displaying over other apps</string>
+4 −21
Original line number Original line Diff line number Diff line
@@ -16,15 +16,14 @@


package com.android.server.wm;
package com.android.server.wm;


import static android.app.NotificationManager.IMPORTANCE_MIN;
import static android.app.PendingIntent.FLAG_CANCEL_CURRENT;
import static android.app.PendingIntent.FLAG_CANCEL_CURRENT;
import static android.content.Context.NOTIFICATION_SERVICE;
import static android.content.Context.NOTIFICATION_SERVICE;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.provider.Settings.ACTION_MANAGE_OVERLAY_PERMISSION;
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.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Context;
@@ -41,7 +40,7 @@ import com.android.server.policy.IconUtilities;


/** Displays an ongoing notification for a process displaying an alert window */
/** Displays an ongoing notification for a process displaying an alert window */
class AlertWindowNotification {
class AlertWindowNotification {
    private static final String CHANNEL_PREFIX = "com.android.server.wm.AlertWindowNotification - ";
    private static final String TAG_PREFIX = "com.android.server.wm.AlertWindowNotification: ";
    private static final int NOTIFICATION_ID = 0;
    private static final int NOTIFICATION_ID = 0;


    private static int sNextRequestCode = 0;
    private static int sNextRequestCode = 0;
@@ -58,7 +57,7 @@ class AlertWindowNotification {
        mPackageName = packageName;
        mPackageName = packageName;
        mNotificationManager =
        mNotificationManager =
                (NotificationManager) mService.mContext.getSystemService(NOTIFICATION_SERVICE);
                (NotificationManager) mService.mContext.getSystemService(NOTIFICATION_SERVICE);
        mNotificationTag = CHANNEL_PREFIX + mPackageName;
        mNotificationTag = TAG_PREFIX + mPackageName;
        mRequestCode = sNextRequestCode++;
        mRequestCode = sNextRequestCode++;
        mIconUtilities = new IconUtilities(mService.mContext);
        mIconUtilities = new IconUtilities(mService.mContext);
    }
    }
@@ -100,11 +99,9 @@ class AlertWindowNotification {
        final String appName = (aInfo != null)
        final String appName = (aInfo != null)
                ? pm.getApplicationLabel(aInfo).toString() : mPackageName;
                ? pm.getApplicationLabel(aInfo).toString() : mPackageName;


        createNotificationChannelIfNeeded(context, appName);

        final String message = context.getString(R.string.alert_windows_notification_message,
        final String message = context.getString(R.string.alert_windows_notification_message,
                appName);
                appName);
        final Notification.Builder builder = new Notification.Builder(context, mNotificationTag)
        final Notification.Builder builder = new Notification.Builder(context, ALERT_WINDOW)
                .setOngoing(true)
                .setOngoing(true)
                .setContentTitle(
                .setContentTitle(
                        context.getString(R.string.alert_windows_notification_title, appName))
                        context.getString(R.string.alert_windows_notification_title, appName))
@@ -134,20 +131,6 @@ class AlertWindowNotification {
        return PendingIntent.getActivity(context, mRequestCode, intent, FLAG_CANCEL_CURRENT);
        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) {
    private ApplicationInfo getApplicationInfo(PackageManager pm, String packageName) {
        try {
        try {
            return pm.getApplicationInfo(packageName, 0);
            return pm.getApplicationInfo(packageName, 0);