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

Commit 1dc93bc4 authored by Geoffrey Pitsch's avatar Geoffrey Pitsch
Browse files

SystemUI uses Builder API with NotificationChannel

Some changes to channels based on UX feedback.

Test: runtest systemui
Change-Id: I1b2f661ba145d6926035f992231dc3c2f8cbf844
parent 825310b6
Loading
Loading
Loading
Loading
+8 −11
Original line number Original line Diff line number Diff line
@@ -51,9 +51,6 @@ public class PluginInstanceManager<T extends Plugin> {
    private static final String TAG = "PluginInstanceManager";
    private static final String TAG = "PluginInstanceManager";
    private static final String PLUGIN_PERMISSION = "com.android.systemui.permission.PLUGIN";
    private static final String PLUGIN_PERMISSION = "com.android.systemui.permission.PLUGIN";


    // must be one of the channels created in NotificationChannels.java
    private static final String NOTIFICATION_CHANNEL_ID = "ALR";

    private final Context mContext;
    private final Context mContext;
    private final PluginListener<T> mListener;
    private final PluginListener<T> mListener;
    private final String mAction;
    private final String mAction;
@@ -310,12 +307,12 @@ public class PluginInstanceManager<T extends Plugin> {
                            mContext.getPackageName());
                            mContext.getPackageName());
                    final int color = Resources.getSystem().getIdentifier(
                    final int color = Resources.getSystem().getIdentifier(
                            "system_notification_accent_color", "color", "android");
                            "system_notification_accent_color", "color", "android");
                    final Notification.Builder nb = new Notification.Builder(mContext)
                    final Notification.Builder nb = new Notification.Builder(mContext,
                            PluginManager.NOTIFICATION_CHANNEL_ID)
                                    .setStyle(new Notification.BigTextStyle())
                                    .setStyle(new Notification.BigTextStyle())
                                    .setSmallIcon(icon)
                                    .setSmallIcon(icon)
                                    .setWhen(0)
                                    .setWhen(0)
                                    .setShowWhen(false)
                                    .setShowWhen(false)
                            .setChannel(NOTIFICATION_CHANNEL_ID)
                                    .setVisibility(Notification.VISIBILITY_PUBLIC)
                                    .setVisibility(Notification.VISIBILITY_PUBLIC)
                                    .setColor(mContext.getColor(color));
                                    .setColor(mContext.getColor(color));
                    String label = cls;
                    String label = cls;
+13 −9
Original line number Original line Diff line number Diff line
@@ -55,6 +55,9 @@ public class PluginManager extends BroadcastReceiver {


    static final String DISABLE_PLUGIN = "com.android.systemui.action.DISABLE_PLUGIN";
    static final String DISABLE_PLUGIN = "com.android.systemui.action.DISABLE_PLUGIN";


    // must be one of the channels created in NotificationChannels.java
    static final String NOTIFICATION_CHANNEL_ID = "ALR";

    private static PluginManager sInstance;
    private static PluginManager sInstance;


    private final HandlerThread mBackgroundThread;
    private final HandlerThread mBackgroundThread;
@@ -191,7 +194,8 @@ public class PluginManager extends BroadcastReceiver {
                } catch (NameNotFoundException e) {
                } catch (NameNotFoundException e) {
                }
                }
                // Localization not required as this will never ever appear in a user build.
                // Localization not required as this will never ever appear in a user build.
                final Notification.Builder nb = new Notification.Builder(mContext)
                final Notification.Builder nb =
                        new Notification.Builder(mContext, NOTIFICATION_CHANNEL_ID)
                                .setSmallIcon(icon)
                                .setSmallIcon(icon)
                                .setWhen(0)
                                .setWhen(0)
                                .setShowWhen(false)
                                .setShowWhen(false)
+2 −4
Original line number Original line Diff line number Diff line
@@ -1802,10 +1802,8 @@
    <string name="notification_channel_alerts">Alerts</string>
    <string name="notification_channel_alerts">Alerts</string>
    <!-- Title for the notification channel dedicated to screenshot progress. [CHAR LIMIT=NONE] -->
    <!-- Title for the notification channel dedicated to screenshot progress. [CHAR LIMIT=NONE] -->
    <string name="notification_channel_screenshot">Screenshots</string>
    <string name="notification_channel_screenshot">Screenshots</string>
    <!-- Title for the notification channel for urgent security issues. [CHAR LIMIT=NONE] -->
    <!-- Title for the notification channel for miscellaneous notices. [CHAR LIMIT=NONE] -->
    <string name="notification_channel_security">Security</string>
    <string name="notification_channel_general">General Messages</string>
    <!-- Title for the notification channel containing multi-user status information. [CHAR LIMIT=NONE] -->
    <string name="notification_channel_user_status">User status</string>
    <!-- Title for the notification channel for problems with storage (i.e. low disk). [CHAR LIMIT=NONE] -->
    <!-- Title for the notification channel for problems with storage (i.e. low disk). [CHAR LIMIT=NONE] -->
    <string name="notification_channel_storage">Storage</string>
    <string name="notification_channel_storage">Storage</string>


+35 −35
Original line number Original line Diff line number Diff line
@@ -145,14 +145,14 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI {
    }
    }


    private void showInvalidChargerNotification() {
    private void showInvalidChargerNotification() {
        final Notification.Builder nb = new Notification.Builder(mContext)
        final Notification.Builder nb =
                new Notification.Builder(mContext, NotificationChannels.ALERTS)
                        .setSmallIcon(R.drawable.ic_power_low)
                        .setSmallIcon(R.drawable.ic_power_low)
                        .setWhen(0)
                        .setWhen(0)
                        .setShowWhen(false)
                        .setShowWhen(false)
                        .setOngoing(true)
                        .setOngoing(true)
                        .setContentTitle(mContext.getString(R.string.invalid_charger_title))
                        .setContentTitle(mContext.getString(R.string.invalid_charger_title))
                        .setContentText(mContext.getString(R.string.invalid_charger_text))
                        .setContentText(mContext.getString(R.string.invalid_charger_text))
                .setChannel(NotificationChannels.ALERTS)
                        .setColor(mContext.getColor(
                        .setColor(mContext.getColor(
                                com.android.internal.R.color.system_notification_accent_color));
                                com.android.internal.R.color.system_notification_accent_color));
        SystemUI.overrideNotificationAppName(mContext, nb);
        SystemUI.overrideNotificationAppName(mContext, nb);
@@ -164,7 +164,8 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI {
    private void showWarningNotification() {
    private void showWarningNotification() {
        final int textRes = R.string.battery_low_percent_format;
        final int textRes = R.string.battery_low_percent_format;
        final String percentage = NumberFormat.getPercentInstance().format((double) mBatteryLevel / 100.0);
        final String percentage = NumberFormat.getPercentInstance().format((double) mBatteryLevel / 100.0);
        final Notification.Builder nb = new Notification.Builder(mContext)
        final Notification.Builder nb =
                new Notification.Builder(mContext, NotificationChannels.ALERTS)
                        .setSmallIcon(R.drawable.ic_power_low)
                        .setSmallIcon(R.drawable.ic_power_low)
                        // Bump the notification when the bucket dropped.
                        // Bump the notification when the bucket dropped.
                        .setWhen(mBucketDroppedNegativeTimeMs)
                        .setWhen(mBucketDroppedNegativeTimeMs)
@@ -173,7 +174,6 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI {
                        .setContentText(mContext.getString(textRes, percentage))
                        .setContentText(mContext.getString(textRes, percentage))
                        .setOnlyAlertOnce(true)
                        .setOnlyAlertOnce(true)
                        .setDeleteIntent(pendingBroadcast(ACTION_DISMISSED_WARNING))
                        .setDeleteIntent(pendingBroadcast(ACTION_DISMISSED_WARNING))
                .setChannel(NotificationChannels.ALERTS)
                        .setVisibility(Notification.VISIBILITY_PUBLIC)
                        .setVisibility(Notification.VISIBILITY_PUBLIC)
                        .setColor(mContext.getColor(
                        .setColor(mContext.getColor(
                                com.android.internal.R.color.battery_saver_mode_color));
                                com.android.internal.R.color.battery_saver_mode_color));
@@ -235,13 +235,13 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI {
            return;
            return;
        }
        }
        mTempWarning = true;
        mTempWarning = true;
        final Notification.Builder nb = new Notification.Builder(mContext)
        final Notification.Builder nb =
                new Notification.Builder(mContext, NotificationChannels.ALERTS)
                        .setSmallIcon(R.drawable.ic_device_thermostat_24)
                        .setSmallIcon(R.drawable.ic_device_thermostat_24)
                        .setWhen(0)
                        .setWhen(0)
                        .setShowWhen(false)
                        .setShowWhen(false)
                        .setContentTitle(mContext.getString(R.string.high_temp_title))
                        .setContentTitle(mContext.getString(R.string.high_temp_title))
                        .setContentText(mContext.getString(R.string.high_temp_notif_message))
                        .setContentText(mContext.getString(R.string.high_temp_notif_message))
                .setChannel(NotificationChannels.ALERTS)
                        .setVisibility(Notification.VISIBILITY_PUBLIC)
                        .setVisibility(Notification.VISIBILITY_PUBLIC)
                        .setContentIntent(pendingBroadcast(ACTION_CLICKED_TEMP_WARNING))
                        .setContentIntent(pendingBroadcast(ACTION_CLICKED_TEMP_WARNING))
                        .setDeleteIntent(pendingBroadcast(ACTION_DISMISSED_TEMP_WARNING))
                        .setDeleteIntent(pendingBroadcast(ACTION_DISMISSED_TEMP_WARNING))
+12 −15
Original line number Original line Diff line number Diff line
@@ -178,8 +178,8 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
                .bigPicture(picture.createAshmemBitmap());
                .bigPicture(picture.createAshmemBitmap());


        // The public notification will show similar info but with the actual screenshot omitted
        // The public notification will show similar info but with the actual screenshot omitted
        mPublicNotificationBuilder = new Notification.Builder(context)
        mPublicNotificationBuilder =
                .setChannel(NotificationChannels.SCREENSHOTS)
                new Notification.Builder(context, NotificationChannels.SCREENSHOTS)
                        .setContentTitle(r.getString(R.string.screenshot_saving_title))
                        .setContentTitle(r.getString(R.string.screenshot_saving_title))
                        .setContentText(r.getString(R.string.screenshot_saving_text))
                        .setContentText(r.getString(R.string.screenshot_saving_text))
                        .setSmallIcon(R.drawable.stat_notify_image)
                        .setSmallIcon(R.drawable.stat_notify_image)
@@ -190,8 +190,7 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
                                com.android.internal.R.color.system_notification_accent_color));
                                com.android.internal.R.color.system_notification_accent_color));
        SystemUI.overrideNotificationAppName(context, mPublicNotificationBuilder);
        SystemUI.overrideNotificationAppName(context, mPublicNotificationBuilder);


        mNotificationBuilder = new Notification.Builder(context)
        mNotificationBuilder = new Notification.Builder(context, NotificationChannels.SCREENSHOTS)
            .setChannel(NotificationChannels.SCREENSHOTS)
            .setTicker(r.getString(R.string.screenshot_saving_ticker)
            .setTicker(r.getString(R.string.screenshot_saving_ticker)
                    + (mTickerAddSpace ? " " : ""))
                    + (mTickerAddSpace ? " " : ""))
            .setContentTitle(r.getString(R.string.screenshot_saving_title))
            .setContentTitle(r.getString(R.string.screenshot_saving_title))
@@ -335,7 +334,6 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {


            // Update the text and the icon for the existing notification
            // Update the text and the icon for the existing notification
            mPublicNotificationBuilder
            mPublicNotificationBuilder
                    .setChannel(NotificationChannels.SCREENSHOTS)
                    .setContentTitle(r.getString(R.string.screenshot_saved_title))
                    .setContentTitle(r.getString(R.string.screenshot_saved_title))
                    .setContentText(r.getString(R.string.screenshot_saved_text))
                    .setContentText(r.getString(R.string.screenshot_saved_text))
                    .setContentIntent(PendingIntent.getActivity(mParams.context, 0, launchIntent, 0))
                    .setContentIntent(PendingIntent.getActivity(mParams.context, 0, launchIntent, 0))
@@ -344,7 +342,6 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
                    .setColor(context.getColor(
                    .setColor(context.getColor(
                            com.android.internal.R.color.system_notification_accent_color));
                            com.android.internal.R.color.system_notification_accent_color));
            mNotificationBuilder
            mNotificationBuilder
                .setChannel(NotificationChannels.SCREENSHOTS)
                .setContentTitle(r.getString(R.string.screenshot_saved_title))
                .setContentTitle(r.getString(R.string.screenshot_saved_title))
                .setContentText(r.getString(R.string.screenshot_saved_text))
                .setContentText(r.getString(R.string.screenshot_saved_text))
                .setContentIntent(PendingIntent.getActivity(mParams.context, 0, launchIntent, 0))
                .setContentIntent(PendingIntent.getActivity(mParams.context, 0, launchIntent, 0))
@@ -858,7 +855,7 @@ class GlobalScreenshot {
        String errorMsg = r.getString(msgResId);
        String errorMsg = r.getString(msgResId);


        // Repurpose the existing notification to notify the user of the error
        // Repurpose the existing notification to notify the user of the error
        Notification.Builder b = new Notification.Builder(context)
        Notification.Builder b = new Notification.Builder(context, NotificationChannels.ALERTS)
            .setTicker(r.getString(R.string.screenshot_failed_title))
            .setTicker(r.getString(R.string.screenshot_failed_title))
            .setContentTitle(r.getString(R.string.screenshot_failed_title))
            .setContentTitle(r.getString(R.string.screenshot_failed_title))
            .setContentText(errorMsg)
            .setContentText(errorMsg)
Loading