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

Commit 009848b0 authored by fionaxu's avatar fionaxu
Browse files

support notification channel for defaultcarrier app

Apps posting notifications for O must supply a notification channel for
all notifications

Bug: 36895752
Change-Id: I7ec3b4cd8a6ea05c3ca9316d1f79b56e3531f5d0
parent 2ac96982
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -6,6 +6,7 @@
    <string name="no_data_notification_id">Your mobile data has been deactivated</string>
    <string name="no_data_notification_id">Your mobile data has been deactivated</string>
    <string name="portal_notification_detail">Tap to visit the %s website</string>
    <string name="portal_notification_detail">Tap to visit the %s website</string>
    <string name="no_data_notification_detail">Please contact your service provider %s</string>
    <string name="no_data_notification_detail">Please contact your service provider %s</string>
    <string name="mobile_data_status_notification_channel_name">Mobile data status</string>
    <string name="action_bar_label">Sign in to mobile network</string>
    <string name="action_bar_label">Sign in to mobile network</string>
    <string name="ssl_error_warning">The network you&#8217;re trying to join has security issues.</string>
    <string name="ssl_error_warning">The network you&#8217;re trying to join has security issues.</string>
    <string name="ssl_error_example">For example, the login page may not belong to the organization shown.</string>
    <string name="ssl_error_example">For example, the login page may not belong to the organization shown.</string>
+13 −1
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@
package com.android.carrierdefaultapp;
package com.android.carrierdefaultapp;


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;
@@ -35,6 +36,7 @@ public class CarrierActionUtils {


    private static final String PORTAL_NOTIFICATION_TAG = "CarrierDefault.Portal.Notification";
    private static final String PORTAL_NOTIFICATION_TAG = "CarrierDefault.Portal.Notification";
    private static final String NO_DATA_NOTIFICATION_TAG = "CarrierDefault.NoData.Notification";
    private static final String NO_DATA_NOTIFICATION_TAG = "CarrierDefault.NoData.Notification";
    private static final String NOTIFICATION_CHANNEL_ID_MOBILE_DATA_STATUS = "mobile_data_status";
    private static final int PORTAL_NOTIFICATION_ID = 0;
    private static final int PORTAL_NOTIFICATION_ID = 0;
    private static final int NO_DATA_NOTIFICATION_ID = 1;
    private static final int NO_DATA_NOTIFICATION_ID = 1;
    private static boolean ENABLE = true;
    private static boolean ENABLE = true;
@@ -150,9 +152,18 @@ public class CarrierActionUtils {
    private static Notification getNotification(Context context, int titleId, int textId,
    private static Notification getNotification(Context context, int titleId, int textId,
                                         PendingIntent pendingIntent) {
                                         PendingIntent pendingIntent) {
        final TelephonyManager telephonyMgr = context.getSystemService(TelephonyManager.class);
        final TelephonyManager telephonyMgr = context.getSystemService(TelephonyManager.class);
        final NotificationManager notificationManager = context.getSystemService(
                NotificationManager.class);
        final Resources resources = context.getResources();
        final Resources resources = context.getResources();
        final Bundle extras = Bundle.forPair(Notification.EXTRA_SUBSTITUTE_APP_NAME,
        final Bundle extras = Bundle.forPair(Notification.EXTRA_SUBSTITUTE_APP_NAME,
                resources.getString(R.string.android_system_label));
                resources.getString(R.string.android_system_label));
        /* Creates the notification channel and registers it with NotificationManager. If a channel
         * with the same ID is already registered, NotificationManager will ignore this call.
         */
        notificationManager.createNotificationChannel(new NotificationChannel(
                NOTIFICATION_CHANNEL_ID_MOBILE_DATA_STATUS,
                resources.getString(R.string.mobile_data_status_notification_channel_name),
                NotificationManager.IMPORTANCE_DEFAULT));
        Notification.Builder builder = new Notification.Builder(context)
        Notification.Builder builder = new Notification.Builder(context)
                .setContentTitle(resources.getString(titleId))
                .setContentTitle(resources.getString(titleId))
                .setContentText(String.format(resources.getString(textId),
                .setContentText(String.format(resources.getString(textId),
@@ -167,7 +178,8 @@ public class CarrierActionUtils {
                .setLocalOnly(true)
                .setLocalOnly(true)
                .setWhen(System.currentTimeMillis())
                .setWhen(System.currentTimeMillis())
                .setShowWhen(false)
                .setShowWhen(false)
                .setExtras(extras);
                .setExtras(extras)
                .setChannel(NOTIFICATION_CHANNEL_ID_MOBILE_DATA_STATUS);


        if (pendingIntent != null) {
        if (pendingIntent != null) {
            builder.setContentIntent(pendingIntent);
            builder.setContentIntent(pendingIntent);