12f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian/* 22f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian * Copyright (C) 2017 The Android Open Source Project 32f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian * 42f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian * Licensed under the Apache License, Version 2.0 (the "License"); 52f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian * you may not use this file except in compliance with the License. 62f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian * You may obtain a copy of the License at 72f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian * 82f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian * http://www.apache.org/licenses/LICENSE-2.0 92f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian * 102f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian * Unless required by applicable law or agreed to in writing, software 112f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian * distributed under the License is distributed on an "AS IS" BASIS, 122f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 132f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian * See the License for the specific language governing permissions and 142f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian * limitations under the License 152f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian */ 162f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian 172f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanianpackage com.android.dialer.notification; 182f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian 192f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanianimport android.annotation.TargetApi; 202f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanianimport android.app.NotificationChannel; 212f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanianimport android.app.NotificationManager; 222f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanianimport android.content.Context; 232f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanianimport android.media.AudioAttributes; 242f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanianimport android.os.Build.VERSION_CODES; 252f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanianimport android.provider.Settings; 262f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanianimport android.support.annotation.NonNull; 272f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanianimport android.support.annotation.Nullable; 282f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanianimport android.support.v4.os.BuildCompat; 292f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanianimport android.telecom.PhoneAccount; 302f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanianimport android.telecom.PhoneAccountHandle; 312f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanianimport android.telecom.TelecomManager; 322f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanianimport android.telephony.TelephonyManager; 332f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanianimport android.text.TextUtils; 342f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanianimport android.util.ArraySet; 352f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanianimport com.android.dialer.common.Assert; 362f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanianimport com.android.dialer.common.LogUtil; 372f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanianimport java.util.ArrayList; 382f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanianimport java.util.List; 392f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanianimport java.util.Set; 402f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian 412f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian/** Utilities for working with voicemail channels. */ 422f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian@TargetApi(VERSION_CODES.O) 432f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian/* package */ final class VoicemailChannelUtils { 442f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian private static final String GLOBAL_VOICEMAIL_CHANNEL_ID = "phone_voicemail"; 452f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian private static final String PER_ACCOUNT_VOICEMAIL_CHANNEL_ID_PREFIX = "phone_voicemail_account_"; 462f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian 472f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian static Set<String> getAllChannelIds(@NonNull Context context) { 482f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian Assert.checkArgument(BuildCompat.isAtLeastO()); 492f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian Assert.isNotNull(context); 502f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian 512f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian Set<String> result = new ArraySet<>(); 522f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian if (isSingleSimDevice(context)) { 532f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian result.add(GLOBAL_VOICEMAIL_CHANNEL_ID); 542f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian } else { 552f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian for (PhoneAccountHandle handle : getAllEligableAccounts(context)) { 562f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian result.add(getChannelIdForAccount(handle)); 572f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian } 582f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian } 592f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian return result; 602f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian } 612f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian 622f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian static void createAllChannels(@NonNull Context context) { 632f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian Assert.checkArgument(BuildCompat.isAtLeastO()); 642f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian Assert.isNotNull(context); 652f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian 662f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian if (isSingleSimDevice(context)) { 672f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian createGlobalVoicemailChannel(context); 682f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian } else { 692f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian for (PhoneAccountHandle handle : getAllEligableAccounts(context)) { 702f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian createVoicemailChannelForAccount(context, handle); 712f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian } 722f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian } 732f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian } 742f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian 752f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian @NonNull 762f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian static String getChannelId(@NonNull Context context, @Nullable PhoneAccountHandle handle) { 772f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian Assert.checkArgument(BuildCompat.isAtLeastO()); 782f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian Assert.isNotNull(context); 792f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian 802f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian // Most devices we deal with have a single SIM slot. No need to distinguish between phone 812f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian // accounts. 822f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian if (isSingleSimDevice(context)) { 832f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian return GLOBAL_VOICEMAIL_CHANNEL_ID; 842f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian } 852f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian 862f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian // We can get a null phone account at random points (modem reboot, etc...). Gracefully degrade 872f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian // by using the default channel. 882f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian if (handle == null) { 892f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian LogUtil.i( 902f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian "VoicemailChannelUtils.getChannelId", 912f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian "no phone account on a multi-SIM device, using default channel"); 922f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian return NotificationChannelId.DEFAULT; 932f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian } 942f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian 952f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian // Voicemail notifications should always be associated with a SIM based phone account. 962f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian if (!isChannelAllowedForAccount(context, handle)) { 972f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian LogUtil.i( 982f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian "VoicemailChannelUtils.getChannelId", 992f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian "phone account is not for a SIM, using default channel"); 1002f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian return NotificationChannelId.DEFAULT; 1012f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian } 1022f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian 1032f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian // Now we're in the multi-SIM case. 1042f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian String channelId = getChannelIdForAccount(handle); 1052f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian if (!doesChannelExist(context, channelId)) { 1062f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian LogUtil.i( 1072f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian "VoicemailChannelUtils.getChannelId", 1082f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian "voicemail channel not found for phone account (possible SIM swap?), creating a new one"); 1092f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian createVoicemailChannelForAccount(context, handle); 1102f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian } 1112f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian return channelId; 1122f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian } 1132f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian 1142f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian private static boolean doesChannelExist(@NonNull Context context, @NonNull String channelId) { 1152f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian return context.getSystemService(NotificationManager.class).getNotificationChannel(channelId) 1162f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian != null; 1172f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian } 1182f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian 1192f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian private static String getChannelIdForAccount(@NonNull PhoneAccountHandle handle) { 1202f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian Assert.isNotNull(handle); 1212f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian return PER_ACCOUNT_VOICEMAIL_CHANNEL_ID_PREFIX + ":" + handle.getId(); 1222f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian } 1232f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian 1242f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian /** 1252f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian * Creates a voicemail channel but doesn't associate it with a SIM. For devices with only one SIM 1262f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian * slot this is ideal because there won't be duplication in the settings UI. 1272f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian */ 1282f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian private static void createGlobalVoicemailChannel(@NonNull Context context) { 1292f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian NotificationChannel channel = newChannel(context, GLOBAL_VOICEMAIL_CHANNEL_ID, null); 1302f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian 1312f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian TelecomManager telecomManager = context.getSystemService(TelecomManager.class); 1322f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian PhoneAccountHandle handle = 1332f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian telecomManager.getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_TEL); 1342f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian if (handle == null) { 1352f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian LogUtil.i( 1362f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian "VoicemailChannelUtils.createGlobalVoicemailChannel", 1372f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian "phone account is null, not migrating sound settings"); 1382f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian } else if (!isChannelAllowedForAccount(context, handle)) { 1392f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian LogUtil.i( 1402f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian "VoicemailChannelUtils.createGlobalVoicemailChannel", 1412f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian "phone account is not eligable, not migrating sound settings"); 1422f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian } else { 1432f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian migrateVoicemailSoundSettings(context, channel, handle); 1442f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian } 1452f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian context.getSystemService(NotificationManager.class).createNotificationChannel(channel); 1462f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian } 1472f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian 1482f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian private static List<PhoneAccountHandle> getAllEligableAccounts(@NonNull Context context) { 1492f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian List<PhoneAccountHandle> handles = new ArrayList<>(); 1502f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian TelecomManager telecomManager = context.getSystemService(TelecomManager.class); 1512f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian for (PhoneAccountHandle handle : telecomManager.getCallCapablePhoneAccounts()) { 1522f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian if (isChannelAllowedForAccount(context, handle)) { 1532f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian handles.add(handle); 1542f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian } 1552f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian } 1562f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian return handles; 1572f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian } 1582f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian 1592f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian private static void createVoicemailChannelForAccount( 1602f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian @NonNull Context context, @NonNull PhoneAccountHandle handle) { 1612f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian PhoneAccount phoneAccount = 1622f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian context.getSystemService(TelecomManager.class).getPhoneAccount(handle); 1632f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian NotificationChannel channel = 1642f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian newChannel(context, getChannelIdForAccount(handle), phoneAccount.getLabel()); 1652f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian migrateVoicemailSoundSettings(context, channel, handle); 1662f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian context.getSystemService(NotificationManager.class).createNotificationChannel(channel); 1672f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian } 1682f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian 1692f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian private static void migrateVoicemailSoundSettings( 1702f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian @NonNull Context context, 1712f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian @NonNull NotificationChannel channel, 1722f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian @NonNull PhoneAccountHandle handle) { 1732f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class); 1742f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian channel.enableVibration(telephonyManager.isVoicemailVibrationEnabled(handle)); 1752f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian channel.setSound( 1762f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian telephonyManager.getVoicemailRingtoneUri(handle), 1772f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION).build()); 1782f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian } 1792f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian 1802f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian private static boolean isChannelAllowedForAccount( 1812f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian @NonNull Context context, @NonNull PhoneAccountHandle handle) { 1822f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian PhoneAccount phoneAccount = 1832f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian context.getSystemService(TelecomManager.class).getPhoneAccount(handle); 1842f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian if (phoneAccount == null) { 1852f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian return false; 1862f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian } 1872f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian if (!phoneAccount.hasCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION)) { 1882f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian return false; 1892f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian } 1902f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian return true; 1912f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian } 1922f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian 1932f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian private static NotificationChannel newChannel( 1942f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian @NonNull Context context, @NonNull String channelId, @Nullable CharSequence nameSuffix) { 1952f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian CharSequence name = context.getText(R.string.notification_channel_voicemail); 19610ae593a59aa50963e1d3159747da2d65ca79bedEric Erfanian // TODO: Use a string resource template after v10. 1972f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian if (!TextUtils.isEmpty(nameSuffix)) { 1982f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian name = TextUtils.concat(name, ": ", nameSuffix); 1992f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian } 2002f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian 2012f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian NotificationChannel channel = 2022f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian new NotificationChannel(channelId, name, NotificationManager.IMPORTANCE_DEFAULT); 2032f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian channel.setShowBadge(true); 2042f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian channel.enableLights(true); 2052f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian channel.enableVibration(true); 2062f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian channel.setSound( 2072f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian Settings.System.DEFAULT_NOTIFICATION_URI, 2082f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION).build()); 2092f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian return channel; 2102f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian } 2112f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian 2122f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian private static boolean isSingleSimDevice(@NonNull Context context) { 2132f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian return context.getSystemService(TelephonyManager.class).getPhoneCount() <= 1; 2142f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian } 2152f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian 2162f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian private VoicemailChannelUtils() {} 2172f1c7586bcce334ca69022eb8dc6d8965ceb6a05Eric Erfanian} 218