1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.dialer.oem; 17 18 import android.content.Context; 19 import android.content.res.Resources; 20 import android.provider.CallLog.Calls; 21 import android.support.annotation.VisibleForTesting; 22 import android.telephony.TelephonyManager; 23 import com.android.dialer.common.LogUtil; 24 import com.android.dialer.common.PackageUtils; 25 import com.android.dialer.configprovider.ConfigProviderBindings; 26 import java.lang.reflect.InvocationTargetException; 27 import java.lang.reflect.Method; 28 29 /** Util class for Motorola OEM devices. */ 30 public class MotorolaUtils { 31 32 private static final String CONFIG_HD_CODEC_BLINKING_ICON_WHEN_CONNECTING_CALL_ENABLED = 33 "hd_codec_blinking_icon_when_connecting_enabled"; 34 private static final String CONFIG_HD_CODEC_SHOW_ICON_IN_NOTIFICATION_ENABLED = 35 "hd_codec_show_icon_in_notification_enabled"; 36 private static final String CONFIG_WIFI_CALL_SHOW_ICON_IN_CALL_LOG_ENABLED = 37 "wifi_call_show_icon_in_call_log_enabled"; 38 39 // This is used to check if a Motorola device supports HD voice call feature, which comes from 40 // system feature setting. 41 private static final String HD_CALL_FEATRURE = "com.motorola.software.sprint.hd_call"; 42 // This is used to check if a Motorola device supports WiFi call feature, by checking if a certain 43 // package is enabled. 44 @VisibleForTesting public static final String WIFI_CALL_PACKAGE_NAME = "com.motorola.sprintwfc"; 45 // Thi is used to check if a Motorola device supports hidden menu feature. 46 @VisibleForTesting 47 static final String HIDDEN_MENU_FEATURE = "com.motorola.software.sprint.hidden_menu"; 48 49 private static boolean hasCheckedSprintWifiCall; 50 private static boolean supportSprintWifiCall; 51 52 /** 53 * Returns true if SPN is specified and matched the current sim operator name. This is necessary 54 * since mcc310-mnc000 is not sufficient to identify Sprint network. 55 */ 56 private static boolean isSpnMatched(Context context) { 57 try { 58 String spnResource = context.getResources().getString(R.string.motorola_enabled_spn); 59 return spnResource.equalsIgnoreCase( 60 context.getSystemService(TelephonyManager.class).getSimOperatorName()); 61 } catch (Resources.NotFoundException exception) { 62 // If SPN is not specified we consider as not necessary to enable/disable the feature. 63 return true; 64 } 65 } 66 67 static boolean isSupportingHiddenMenu(Context context) { 68 return context.getPackageManager().hasSystemFeature(HIDDEN_MENU_FEATURE); 69 } 70 71 public static boolean shouldBlinkHdIconWhenConnectingCall(Context context) { 72 return ConfigProviderBindings.get(context) 73 .getBoolean(CONFIG_HD_CODEC_BLINKING_ICON_WHEN_CONNECTING_CALL_ENABLED, true) 74 && isSupportingSprintHdCodec(context); 75 } 76 77 public static boolean shouldShowHdIconInNotification(Context context) { 78 return ConfigProviderBindings.get(context) 79 .getBoolean(CONFIG_HD_CODEC_SHOW_ICON_IN_NOTIFICATION_ENABLED, true) 80 && isSupportingSprintHdCodec(context); 81 } 82 83 public static boolean shouldShowWifiIconInCallLog(Context context, int features) { 84 return ConfigProviderBindings.get(context) 85 .getBoolean(CONFIG_WIFI_CALL_SHOW_ICON_IN_CALL_LOG_ENABLED, true) 86 && (features & Calls.FEATURES_WIFI) == Calls.FEATURES_WIFI 87 && isSupportingSprintWifiCall(context); 88 } 89 90 /** 91 * Handle special char sequence entered in dialpad. This may launch special intent based on input. 92 * 93 * @param context context 94 * @param input input string 95 * @return true if the input is consumed and the intent is launched 96 */ 97 public static boolean handleSpecialCharSequence(Context context, String input) { 98 // TODO(a bug): Add check for Motorola devices. 99 return MotorolaHiddenMenuKeySequence.handleCharSequence(context, input); 100 } 101 102 public static boolean isWifiCallingAvailable(Context context) { 103 if (!isSupportingSprintWifiCall(context)) { 104 return false; 105 } 106 TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class); 107 try { 108 Method method = TelephonyManager.class.getMethod("isWifiCallingAvailable"); 109 boolean isWifiCallingAvailable = (boolean) method.invoke(telephonyManager); 110 LogUtil.d("MotorolaUtils.isWifiCallingAvailable", "%b", isWifiCallingAvailable); 111 return isWifiCallingAvailable; 112 } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { 113 LogUtil.e("MotorolaUtils.isWifiCallingAvailable", "", e); 114 } 115 return false; 116 } 117 118 private static boolean isSupportingSprintHdCodec(Context context) { 119 return isSpnMatched(context) 120 && context.getResources().getBoolean(R.bool.motorola_sprint_hd_codec) 121 && context.getPackageManager().hasSystemFeature(HD_CALL_FEATRURE); 122 } 123 124 private static boolean isSupportingSprintWifiCall(Context context) { 125 if (!hasCheckedSprintWifiCall) { 126 supportSprintWifiCall = PackageUtils.isPackageEnabled(WIFI_CALL_PACKAGE_NAME, context); 127 hasCheckedSprintWifiCall = true; 128 } 129 return supportSprintWifiCall; 130 } 131 132 @VisibleForTesting 133 public static void resetForTest() { 134 hasCheckedSprintWifiCall = false; 135 supportSprintWifiCall = false; 136 } 137 } 138