Loading src/java/com/android/internal/telephony/CarrierServiceStateTracker.java +4 −1 Original line number Diff line number Diff line Loading @@ -30,6 +30,8 @@ import android.provider.Settings; import android.telephony.CarrierConfigManager; import android.telephony.Rlog; import com.android.internal.telephony.util.TelephonyNotificationBuilder; /** * This contains Carrier specific logic based on the states/events * managed in ServiceStateTracker. Loading Loading @@ -164,7 +166,7 @@ public class CarrierServiceStateTracker extends Handler { context.getText(com.android.internal.R.string.NetworkPreferenceSwitchSummary); Notification mNotification = new Notification.Builder(context) Notification mNotification = new TelephonyNotificationBuilder(context) .setWhen(System.currentTimeMillis()) .setAutoCancel(true) .setSmallIcon(com.android.internal.R.drawable.stat_sys_warning) Loading @@ -174,6 +176,7 @@ public class CarrierServiceStateTracker extends Handler { .setStyle(new Notification.BigTextStyle().bigText(details)) .setContentText(details) .setContentIntent(settingsIntent) .setChannel(TelephonyNotificationBuilder.CHANNEL_ID_ALERT) .build(); notificationManager.notify(NOTIFICATION_ID, mNotification); Loading src/java/com/android/internal/telephony/InboundSmsHandler.java +4 −2 Original line number Diff line number Diff line Loading @@ -64,6 +64,7 @@ import android.text.TextUtils; import com.android.internal.R; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.telephony.util.TelephonyNotificationBuilder; import com.android.internal.util.HexDump; import com.android.internal.util.State; import com.android.internal.util.StateMachine; Loading Loading @@ -910,14 +911,15 @@ public abstract class InboundSmsHandler extends StateMachine { 0, new Intent(ACTION_OPEN_SMS_APP), PendingIntent.FLAG_ONE_SHOT); Notification.Builder mBuilder = new Notification.Builder(mContext) Notification.Builder mBuilder = new TelephonyNotificationBuilder(mContext) .setSmallIcon(com.android.internal.R.drawable.sym_action_chat) .setAutoCancel(true) .setVisibility(Notification.VISIBILITY_PUBLIC) .setDefaults(Notification.DEFAULT_ALL) .setContentTitle(mContext.getString(R.string.new_sms_notification_title)) .setContentText(mContext.getString(R.string.new_sms_notification_content)) .setContentIntent(intent); .setContentIntent(intent) .setChannel(TelephonyNotificationBuilder.CHANNEL_ID_SMS); NotificationManager mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify( Loading src/java/com/android/internal/telephony/ServiceStateTracker.java +3 −1 Original line number Diff line number Diff line Loading @@ -86,6 +86,7 @@ import com.android.internal.telephony.uicc.RuimRecords; import com.android.internal.telephony.uicc.SIMRecords; import com.android.internal.telephony.uicc.UiccCardApplication; import com.android.internal.telephony.uicc.UiccController; import com.android.internal.telephony.util.TelephonyNotificationBuilder; import com.android.internal.util.IndentingPrintWriter; import java.io.FileDescriptor; Loading Loading @@ -3856,7 +3857,7 @@ public class ServiceStateTracker extends Handler { + ", title: " + title + ", details: " + details); } mNotification = new Notification.Builder(context) mNotification = new TelephonyNotificationBuilder(context) .setWhen(System.currentTimeMillis()) .setAutoCancel(true) .setSmallIcon(icon) Loading @@ -3865,6 +3866,7 @@ public class ServiceStateTracker extends Handler { com.android.internal.R.color.system_notification_accent_color)) .setContentTitle(title) .setContentText(details) .setChannel(TelephonyNotificationBuilder.CHANNEL_ID_ALERT) .build(); NotificationManager notificationManager = (NotificationManager) Loading src/java/com/android/internal/telephony/imsphone/ImsPhone.java +5 −2 Original line number Diff line number Diff line Loading @@ -101,6 +101,7 @@ import com.android.internal.telephony.TelephonyProperties; import com.android.internal.telephony.UUSInfo; import com.android.internal.telephony.gsm.SuppServiceNotification; import com.android.internal.telephony.uicc.IccRecords; import com.android.internal.telephony.util.TelephonyNotificationBuilder; import java.io.FileDescriptor; import java.io.PrintWriter; Loading Loading @@ -1552,13 +1553,15 @@ public class ImsPhone extends ImsPhoneBase { ); final Notification notification = new Notification.Builder(mContext) new TelephonyNotificationBuilder(mContext) .setSmallIcon(android.R.drawable.stat_sys_warning) .setContentTitle(title) .setContentText(messageNotification) .setAutoCancel(true) .setContentIntent(resultPendingIntent) .setStyle(new Notification.BigTextStyle().bigText(messageNotification)) .setStyle(new Notification.BigTextStyle() .bigText(messageNotification)) .setChannel(TelephonyNotificationBuilder.CHANNEL_ID_WFC) .build(); final String notificationTag = "wifi_calling"; final int notificationId = 1; Loading src/java/com/android/internal/telephony/util/TelephonyNotificationBuilder.java 0 → 100644 +135 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.internal.telephony.util; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; import android.media.AudioAttributes; import android.net.Uri; import android.provider.Settings; import com.android.internal.R; public class TelephonyNotificationBuilder extends Notification.Builder { private final Context mContext; /** * list of {@link android.app.NotificationChannel} for telephony service. */ public static final String CHANNEL_ID_ALERT = "alert"; public static final String CHANNEL_ID_CALL_FORWARD = "callForward"; public static final String CHANNEL_ID_MOBILE_DATA_ALERT = "mobileDataAlert"; public static final String CHANNEL_ID_SMS = "sms"; public static final String CHANNEL_ID_VOICE_MAIL = "voiceMail"; public static final String CHANNEL_ID_WFC = "wfc"; private static NotificationChannel createChannel(Context context, String channelId) { CharSequence name; int importance; boolean canShowBadge; boolean lights; boolean vibration; Uri sound = null; switch (channelId) { case CHANNEL_ID_ALERT: name = context.getText(R.string.notification_channel_network_alert); importance = NotificationManager.IMPORTANCE_DEFAULT; canShowBadge = false; lights = false; vibration = false; sound = Settings.System.DEFAULT_NOTIFICATION_URI; break; case CHANNEL_ID_CALL_FORWARD: name = context.getText(R.string.notification_channel_call_forward); importance = NotificationManager.IMPORTANCE_LOW; canShowBadge = false; lights = false; vibration = false; break; case CHANNEL_ID_MOBILE_DATA_ALERT: name = context.getText(R.string.notification_channel_mobile_data_alert); importance = NotificationManager.IMPORTANCE_DEFAULT; canShowBadge = false; lights = false; vibration = false; break; case CHANNEL_ID_SMS: name = context.getText(R.string.notification_channel_sms); importance = NotificationManager.IMPORTANCE_HIGH; canShowBadge = false; lights = false; vibration = false; sound = Settings.System.DEFAULT_NOTIFICATION_URI; break; case CHANNEL_ID_VOICE_MAIL: name = context.getText(R.string.notification_channel_voice_mail); importance = NotificationManager.IMPORTANCE_DEFAULT; canShowBadge = false; lights = false; vibration = false; sound = Settings.System.DEFAULT_NOTIFICATION_URI; break; case CHANNEL_ID_WFC: name = context.getText(R.string.notification_channel_wfc); importance = NotificationManager.IMPORTANCE_LOW; canShowBadge = false; lights = false; vibration = false; break; default: throw new IllegalArgumentException("Unknown channel: " + channelId); } NotificationChannel channel = new NotificationChannel(channelId, name, importance); if (sound != null) { channel.setSound(sound, new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_NOTIFICATION).build()); } channel.setShowBadge(canShowBadge); channel.enableLights(lights); channel.enableVibration(vibration); /** * Creates the notification channel and registers it with NotificationManager. If a channel * with the same ID is already registered, NotificationManager will ignore this call. */ getNotificationManager(context).createNotificationChannel(channel); return channel; } private static NotificationManager getNotificationManager(Context context) { return context.getSystemService(NotificationManager.class); } /** * Specifies the channel the notification should be delivered on. * Will create the channel if it does not already exist. */ @Override public Notification.Builder setChannel(String channelId) { // check if the channel has been created and registered NotificationChannel channel = getNotificationManager(mContext) .getNotificationChannel(channelId); if (channel == null) channel = createChannel(mContext, channelId); return super.setChannel(channel.getId()); } public TelephonyNotificationBuilder(Context context) { super(context); mContext = context; } } Loading
src/java/com/android/internal/telephony/CarrierServiceStateTracker.java +4 −1 Original line number Diff line number Diff line Loading @@ -30,6 +30,8 @@ import android.provider.Settings; import android.telephony.CarrierConfigManager; import android.telephony.Rlog; import com.android.internal.telephony.util.TelephonyNotificationBuilder; /** * This contains Carrier specific logic based on the states/events * managed in ServiceStateTracker. Loading Loading @@ -164,7 +166,7 @@ public class CarrierServiceStateTracker extends Handler { context.getText(com.android.internal.R.string.NetworkPreferenceSwitchSummary); Notification mNotification = new Notification.Builder(context) Notification mNotification = new TelephonyNotificationBuilder(context) .setWhen(System.currentTimeMillis()) .setAutoCancel(true) .setSmallIcon(com.android.internal.R.drawable.stat_sys_warning) Loading @@ -174,6 +176,7 @@ public class CarrierServiceStateTracker extends Handler { .setStyle(new Notification.BigTextStyle().bigText(details)) .setContentText(details) .setContentIntent(settingsIntent) .setChannel(TelephonyNotificationBuilder.CHANNEL_ID_ALERT) .build(); notificationManager.notify(NOTIFICATION_ID, mNotification); Loading
src/java/com/android/internal/telephony/InboundSmsHandler.java +4 −2 Original line number Diff line number Diff line Loading @@ -64,6 +64,7 @@ import android.text.TextUtils; import com.android.internal.R; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.telephony.util.TelephonyNotificationBuilder; import com.android.internal.util.HexDump; import com.android.internal.util.State; import com.android.internal.util.StateMachine; Loading Loading @@ -910,14 +911,15 @@ public abstract class InboundSmsHandler extends StateMachine { 0, new Intent(ACTION_OPEN_SMS_APP), PendingIntent.FLAG_ONE_SHOT); Notification.Builder mBuilder = new Notification.Builder(mContext) Notification.Builder mBuilder = new TelephonyNotificationBuilder(mContext) .setSmallIcon(com.android.internal.R.drawable.sym_action_chat) .setAutoCancel(true) .setVisibility(Notification.VISIBILITY_PUBLIC) .setDefaults(Notification.DEFAULT_ALL) .setContentTitle(mContext.getString(R.string.new_sms_notification_title)) .setContentText(mContext.getString(R.string.new_sms_notification_content)) .setContentIntent(intent); .setContentIntent(intent) .setChannel(TelephonyNotificationBuilder.CHANNEL_ID_SMS); NotificationManager mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify( Loading
src/java/com/android/internal/telephony/ServiceStateTracker.java +3 −1 Original line number Diff line number Diff line Loading @@ -86,6 +86,7 @@ import com.android.internal.telephony.uicc.RuimRecords; import com.android.internal.telephony.uicc.SIMRecords; import com.android.internal.telephony.uicc.UiccCardApplication; import com.android.internal.telephony.uicc.UiccController; import com.android.internal.telephony.util.TelephonyNotificationBuilder; import com.android.internal.util.IndentingPrintWriter; import java.io.FileDescriptor; Loading Loading @@ -3856,7 +3857,7 @@ public class ServiceStateTracker extends Handler { + ", title: " + title + ", details: " + details); } mNotification = new Notification.Builder(context) mNotification = new TelephonyNotificationBuilder(context) .setWhen(System.currentTimeMillis()) .setAutoCancel(true) .setSmallIcon(icon) Loading @@ -3865,6 +3866,7 @@ public class ServiceStateTracker extends Handler { com.android.internal.R.color.system_notification_accent_color)) .setContentTitle(title) .setContentText(details) .setChannel(TelephonyNotificationBuilder.CHANNEL_ID_ALERT) .build(); NotificationManager notificationManager = (NotificationManager) Loading
src/java/com/android/internal/telephony/imsphone/ImsPhone.java +5 −2 Original line number Diff line number Diff line Loading @@ -101,6 +101,7 @@ import com.android.internal.telephony.TelephonyProperties; import com.android.internal.telephony.UUSInfo; import com.android.internal.telephony.gsm.SuppServiceNotification; import com.android.internal.telephony.uicc.IccRecords; import com.android.internal.telephony.util.TelephonyNotificationBuilder; import java.io.FileDescriptor; import java.io.PrintWriter; Loading Loading @@ -1552,13 +1553,15 @@ public class ImsPhone extends ImsPhoneBase { ); final Notification notification = new Notification.Builder(mContext) new TelephonyNotificationBuilder(mContext) .setSmallIcon(android.R.drawable.stat_sys_warning) .setContentTitle(title) .setContentText(messageNotification) .setAutoCancel(true) .setContentIntent(resultPendingIntent) .setStyle(new Notification.BigTextStyle().bigText(messageNotification)) .setStyle(new Notification.BigTextStyle() .bigText(messageNotification)) .setChannel(TelephonyNotificationBuilder.CHANNEL_ID_WFC) .build(); final String notificationTag = "wifi_calling"; final int notificationId = 1; Loading
src/java/com/android/internal/telephony/util/TelephonyNotificationBuilder.java 0 → 100644 +135 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.internal.telephony.util; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; import android.media.AudioAttributes; import android.net.Uri; import android.provider.Settings; import com.android.internal.R; public class TelephonyNotificationBuilder extends Notification.Builder { private final Context mContext; /** * list of {@link android.app.NotificationChannel} for telephony service. */ public static final String CHANNEL_ID_ALERT = "alert"; public static final String CHANNEL_ID_CALL_FORWARD = "callForward"; public static final String CHANNEL_ID_MOBILE_DATA_ALERT = "mobileDataAlert"; public static final String CHANNEL_ID_SMS = "sms"; public static final String CHANNEL_ID_VOICE_MAIL = "voiceMail"; public static final String CHANNEL_ID_WFC = "wfc"; private static NotificationChannel createChannel(Context context, String channelId) { CharSequence name; int importance; boolean canShowBadge; boolean lights; boolean vibration; Uri sound = null; switch (channelId) { case CHANNEL_ID_ALERT: name = context.getText(R.string.notification_channel_network_alert); importance = NotificationManager.IMPORTANCE_DEFAULT; canShowBadge = false; lights = false; vibration = false; sound = Settings.System.DEFAULT_NOTIFICATION_URI; break; case CHANNEL_ID_CALL_FORWARD: name = context.getText(R.string.notification_channel_call_forward); importance = NotificationManager.IMPORTANCE_LOW; canShowBadge = false; lights = false; vibration = false; break; case CHANNEL_ID_MOBILE_DATA_ALERT: name = context.getText(R.string.notification_channel_mobile_data_alert); importance = NotificationManager.IMPORTANCE_DEFAULT; canShowBadge = false; lights = false; vibration = false; break; case CHANNEL_ID_SMS: name = context.getText(R.string.notification_channel_sms); importance = NotificationManager.IMPORTANCE_HIGH; canShowBadge = false; lights = false; vibration = false; sound = Settings.System.DEFAULT_NOTIFICATION_URI; break; case CHANNEL_ID_VOICE_MAIL: name = context.getText(R.string.notification_channel_voice_mail); importance = NotificationManager.IMPORTANCE_DEFAULT; canShowBadge = false; lights = false; vibration = false; sound = Settings.System.DEFAULT_NOTIFICATION_URI; break; case CHANNEL_ID_WFC: name = context.getText(R.string.notification_channel_wfc); importance = NotificationManager.IMPORTANCE_LOW; canShowBadge = false; lights = false; vibration = false; break; default: throw new IllegalArgumentException("Unknown channel: " + channelId); } NotificationChannel channel = new NotificationChannel(channelId, name, importance); if (sound != null) { channel.setSound(sound, new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_NOTIFICATION).build()); } channel.setShowBadge(canShowBadge); channel.enableLights(lights); channel.enableVibration(vibration); /** * Creates the notification channel and registers it with NotificationManager. If a channel * with the same ID is already registered, NotificationManager will ignore this call. */ getNotificationManager(context).createNotificationChannel(channel); return channel; } private static NotificationManager getNotificationManager(Context context) { return context.getSystemService(NotificationManager.class); } /** * Specifies the channel the notification should be delivered on. * Will create the channel if it does not already exist. */ @Override public Notification.Builder setChannel(String channelId) { // check if the channel has been created and registered NotificationChannel channel = getNotificationManager(mContext) .getNotificationChannel(channelId); if (channel == null) channel = createChannel(mContext, channelId); return super.setChannel(channel.getId()); } public TelephonyNotificationBuilder(Context context) { super(context); mContext = context; } }