Loading res/values/strings.xml +5 −0 Original line number Diff line number Diff line Loading @@ -247,4 +247,9 @@ phone call in a third-party app. Unlike cant_call_due_to_ongoing_call, this is used when the name of the other app is not known. [CHAR LIMIT=none] --> <string name="cant_call_due_to_ongoing_unknown_call">Call cannot be placed due to a call in another app.</string> <!-- Notification channel name for a channel containing incoming call notifications. --> <string name="notification_channel_incoming_call">Incoming calls</string> <!-- Notification channel name for a channel containing missed call notifications. --> <string name="notification_channel_missed_call">Missed calls</string> </resources> src/com/android/server/telecom/components/TelecomService.java +4 −0 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ import com.android.server.telecom.TelecomWakeLock; import com.android.server.telecom.Timeouts; import com.android.server.telecom.ui.IncomingCallNotifier; import com.android.server.telecom.ui.MissedCallNotifierImpl; import com.android.server.telecom.ui.NotificationChannelManager; /** * Implementation of the ITelecom interface. Loading Loading @@ -81,6 +82,9 @@ public class TelecomService extends Service implements TelecomSystem.Component { final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationChannelManager notificationChannelManager = new NotificationChannelManager(); notificationChannelManager.createChannels(context); TelecomSystem.setInstance( new TelecomSystem( context, Loading src/com/android/server/telecom/ui/IncomingCallNotifier.java +3 −1 Original line number Diff line number Diff line Loading @@ -67,7 +67,8 @@ public class IncomingCallNotifier extends CallsManagerListenerBase { // Notification for incoming calls. This is interruptive and will show up as a HUN. @VisibleForTesting public static final int NOTIFICATION_INCOMING_CALL = 1; private static final String NOTIFICATION_TAG = IncomingCallNotifier.class.getSimpleName(); @VisibleForTesting public static final String NOTIFICATION_TAG = IncomingCallNotifier.class.getSimpleName(); public final Call.ListenerBase mCallListener = new Call.ListenerBase() { Loading Loading @@ -262,6 +263,7 @@ public class IncomingCallNotifier extends CallsManagerListenerBase { builder.setContentTitle(incomingCallText); builder.setContentText(disconnectText); builder.setSmallIcon(R.drawable.ic_phone); builder.setChannel(NotificationChannelManager.CHANNEL_ID_INCOMING_CALLS); // Ensures this is a heads up notification. A heads-up notification is typically only shown // if there is a fullscreen intent. However since this notification doesn't have that we // will use this trick to get it to show as one anyways. Loading src/com/android/server/telecom/ui/MissedCallNotifierImpl.java +2 −1 Original line number Diff line number Diff line Loading @@ -331,7 +331,8 @@ public class MissedCallNotifierImpl extends CallsManagerListenerBase implements // Include a public version of the notification to be shown when the missed call // notification is shown on the user's lock screen and they have chosen to hide // sensitive notification information. .setPublicVersion(publicBuilder.build()); .setPublicVersion(publicBuilder.build()) .setChannel(NotificationChannelManager.CHANNEL_ID_MISSED_CALLS); Uri handleUri = callInfo.getHandle(); String handle = callInfo.getHandleSchemeSpecificPart(); Loading src/com/android/server/telecom/ui/NotificationChannelManager.java 0 → 100644 +94 −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.server.telecom.ui; import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; import android.media.AudioAttributes; import android.net.Uri; import com.android.server.telecom.R; /** * Manages the {@link android.app.NotificationChannel}s for Telecom. */ public class NotificationChannelManager { public static final String CHANNEL_ID_NAME = "Telecom-"; public static final String CHANNEL_ID_MISSED_CALLS = "TelecomMissedCalls"; public static final String CHANNEL_ID_INCOMING_CALLS = "TelecomIncomingCalls"; public void createChannels(Context context) { maybeCreateChannel(context, CHANNEL_ID_MISSED_CALLS); maybeCreateChannel(context, CHANNEL_ID_INCOMING_CALLS); } private void maybeCreateChannel(Context context, String channelId) { NotificationChannel channel = getNotificationManager(context).getNotificationChannel( channelId); if (channel == null) { channel = createChannel(context, channelId); getNotificationManager(context).createNotificationChannel(channel); } } private NotificationChannel createChannel(Context context, String channelId) { Uri silentRingtone = Uri.parse(""); CharSequence name = ""; int importance = NotificationManager.IMPORTANCE_DEFAULT; boolean canShowBadge = false; boolean lights = false; boolean vibration = false; Uri sound = silentRingtone; switch (channelId) { case CHANNEL_ID_INCOMING_CALLS: name = context.getText(R.string.notification_channel_incoming_call); importance = NotificationManager.IMPORTANCE_MAX; canShowBadge = false; lights = true; vibration = false; sound = silentRingtone; break; case CHANNEL_ID_MISSED_CALLS: name = context.getText(R.string.notification_channel_missed_call); importance = NotificationManager.IMPORTANCE_DEFAULT; canShowBadge = true; lights = true; vibration = true; sound = silentRingtone; break; } NotificationChannel channel = new NotificationChannel(channelId, name, importance); channel.setShowBadge(canShowBadge); if (sound != null) { channel.setSound( sound, new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION) .build()); } channel.enableLights(lights); channel.enableVibration(vibration); return channel; } private NotificationManager getNotificationManager(Context context) { return context.getSystemService(NotificationManager.class); } } Loading
res/values/strings.xml +5 −0 Original line number Diff line number Diff line Loading @@ -247,4 +247,9 @@ phone call in a third-party app. Unlike cant_call_due_to_ongoing_call, this is used when the name of the other app is not known. [CHAR LIMIT=none] --> <string name="cant_call_due_to_ongoing_unknown_call">Call cannot be placed due to a call in another app.</string> <!-- Notification channel name for a channel containing incoming call notifications. --> <string name="notification_channel_incoming_call">Incoming calls</string> <!-- Notification channel name for a channel containing missed call notifications. --> <string name="notification_channel_missed_call">Missed calls</string> </resources>
src/com/android/server/telecom/components/TelecomService.java +4 −0 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ import com.android.server.telecom.TelecomWakeLock; import com.android.server.telecom.Timeouts; import com.android.server.telecom.ui.IncomingCallNotifier; import com.android.server.telecom.ui.MissedCallNotifierImpl; import com.android.server.telecom.ui.NotificationChannelManager; /** * Implementation of the ITelecom interface. Loading Loading @@ -81,6 +82,9 @@ public class TelecomService extends Service implements TelecomSystem.Component { final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationChannelManager notificationChannelManager = new NotificationChannelManager(); notificationChannelManager.createChannels(context); TelecomSystem.setInstance( new TelecomSystem( context, Loading
src/com/android/server/telecom/ui/IncomingCallNotifier.java +3 −1 Original line number Diff line number Diff line Loading @@ -67,7 +67,8 @@ public class IncomingCallNotifier extends CallsManagerListenerBase { // Notification for incoming calls. This is interruptive and will show up as a HUN. @VisibleForTesting public static final int NOTIFICATION_INCOMING_CALL = 1; private static final String NOTIFICATION_TAG = IncomingCallNotifier.class.getSimpleName(); @VisibleForTesting public static final String NOTIFICATION_TAG = IncomingCallNotifier.class.getSimpleName(); public final Call.ListenerBase mCallListener = new Call.ListenerBase() { Loading Loading @@ -262,6 +263,7 @@ public class IncomingCallNotifier extends CallsManagerListenerBase { builder.setContentTitle(incomingCallText); builder.setContentText(disconnectText); builder.setSmallIcon(R.drawable.ic_phone); builder.setChannel(NotificationChannelManager.CHANNEL_ID_INCOMING_CALLS); // Ensures this is a heads up notification. A heads-up notification is typically only shown // if there is a fullscreen intent. However since this notification doesn't have that we // will use this trick to get it to show as one anyways. Loading
src/com/android/server/telecom/ui/MissedCallNotifierImpl.java +2 −1 Original line number Diff line number Diff line Loading @@ -331,7 +331,8 @@ public class MissedCallNotifierImpl extends CallsManagerListenerBase implements // Include a public version of the notification to be shown when the missed call // notification is shown on the user's lock screen and they have chosen to hide // sensitive notification information. .setPublicVersion(publicBuilder.build()); .setPublicVersion(publicBuilder.build()) .setChannel(NotificationChannelManager.CHANNEL_ID_MISSED_CALLS); Uri handleUri = callInfo.getHandle(); String handle = callInfo.getHandleSchemeSpecificPart(); Loading
src/com/android/server/telecom/ui/NotificationChannelManager.java 0 → 100644 +94 −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.server.telecom.ui; import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; import android.media.AudioAttributes; import android.net.Uri; import com.android.server.telecom.R; /** * Manages the {@link android.app.NotificationChannel}s for Telecom. */ public class NotificationChannelManager { public static final String CHANNEL_ID_NAME = "Telecom-"; public static final String CHANNEL_ID_MISSED_CALLS = "TelecomMissedCalls"; public static final String CHANNEL_ID_INCOMING_CALLS = "TelecomIncomingCalls"; public void createChannels(Context context) { maybeCreateChannel(context, CHANNEL_ID_MISSED_CALLS); maybeCreateChannel(context, CHANNEL_ID_INCOMING_CALLS); } private void maybeCreateChannel(Context context, String channelId) { NotificationChannel channel = getNotificationManager(context).getNotificationChannel( channelId); if (channel == null) { channel = createChannel(context, channelId); getNotificationManager(context).createNotificationChannel(channel); } } private NotificationChannel createChannel(Context context, String channelId) { Uri silentRingtone = Uri.parse(""); CharSequence name = ""; int importance = NotificationManager.IMPORTANCE_DEFAULT; boolean canShowBadge = false; boolean lights = false; boolean vibration = false; Uri sound = silentRingtone; switch (channelId) { case CHANNEL_ID_INCOMING_CALLS: name = context.getText(R.string.notification_channel_incoming_call); importance = NotificationManager.IMPORTANCE_MAX; canShowBadge = false; lights = true; vibration = false; sound = silentRingtone; break; case CHANNEL_ID_MISSED_CALLS: name = context.getText(R.string.notification_channel_missed_call); importance = NotificationManager.IMPORTANCE_DEFAULT; canShowBadge = true; lights = true; vibration = true; sound = silentRingtone; break; } NotificationChannel channel = new NotificationChannel(channelId, name, importance); channel.setShowBadge(canShowBadge); if (sound != null) { channel.setSound( sound, new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION) .build()); } channel.enableLights(lights); channel.enableVibration(vibration); return channel; } private NotificationManager getNotificationManager(Context context) { return context.getSystemService(NotificationManager.class); } }