Home | History | Annotate | Download | only in oem
      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.telephony.TelephonyManager;
     21 import com.android.dialer.common.ConfigProviderBindings;
     22 import com.android.dialer.common.PackageUtils;
     23 
     24 /** Util class for Motorola OEM devices. */
     25 public class MotorolaUtils {
     26 
     27   private static final String CONFIG_HD_CODEC_BLINKING_ICON_WHEN_CONNECTING_CALL_ENABLED =
     28       "hd_codec_blinking_icon_when_connecting_enabled";
     29   private static final String CONFIG_HD_CODEC_SHOW_ICON_IN_NOTIFICATION_ENABLED =
     30       "hd_codec_show_icon_in_notification_enabled";
     31   private static final String CONFIG_HD_CODEC_SHOW_ICON_IN_CALL_LOG_ENABLED =
     32       "hd_codec_show_icon_in_call_log_enabled";
     33   private static final String CONFIG_WIFI_CALL_SHOW_ICON_IN_CALL_LOG_ENABLED =
     34       "wifi_call_show_icon_in_call_log_enabled";
     35 
     36   // This is used to check if a Motorola device supports HD voice call feature, which comes from
     37   // system feature setting.
     38   private static final String HD_CALL_FEATRURE = "com.motorola.software.sprint.hd_call";
     39   // This is used to check if a Motorola device supports WiFi call feature, by checking if a certain
     40   // package is enabled.
     41   private static final String WIFI_CALL_PACKAGE_NAME = "com.motorola.sprintwfc";
     42 
     43   // Feature flag indicates it's a HD call, currently this is only used by Motorola system build.
     44   // TODO(b/35359461): Use reference to android.provider.CallLog once it's in new SDK.
     45   private static final int FEATURES_HD_CALL = 0x4;
     46   // Feature flag indicates it's a WiFi call, currently this is only used by Motorola system build.
     47   private static final int FEATURES_WIFI = 0x8;
     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   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   public static boolean shouldBlinkHdIconWhenConnectingCall(Context context) {
     68     return ConfigProviderBindings.get(context)
     69             .getBoolean(CONFIG_HD_CODEC_BLINKING_ICON_WHEN_CONNECTING_CALL_ENABLED, true)
     70         && isSupportingSprintHdCodec(context);
     71   }
     72 
     73   public static boolean shouldShowHdIconInNotification(Context context) {
     74     return ConfigProviderBindings.get(context)
     75             .getBoolean(CONFIG_HD_CODEC_SHOW_ICON_IN_NOTIFICATION_ENABLED, true)
     76         && isSupportingSprintHdCodec(context);
     77   }
     78 
     79   public static boolean shouldShowHdIconInCallLog(Context context, int features) {
     80     return ConfigProviderBindings.get(context)
     81             .getBoolean(CONFIG_HD_CODEC_SHOW_ICON_IN_CALL_LOG_ENABLED, true)
     82         && (features & FEATURES_HD_CALL) == FEATURES_HD_CALL
     83         && isSupportingSprintHdCodec(context);
     84   }
     85 
     86   public static boolean shouldShowWifiIconInCallLog(Context context, int features) {
     87     return ConfigProviderBindings.get(context)
     88             .getBoolean(CONFIG_WIFI_CALL_SHOW_ICON_IN_CALL_LOG_ENABLED, true)
     89         && (features & FEATURES_WIFI) == FEATURES_WIFI
     90         && isSupportingSprintWifiCall(context);
     91   }
     92 
     93   /**
     94    * Handle special char sequence entered in dialpad. This may launch special intent based on input.
     95    *
     96    * @param context context
     97    * @param input input string
     98    * @return true if the input is consumed and the intent is launched
     99    */
    100   public static boolean handleSpecialCharSequence(Context context, String input) {
    101     // TODO(b/35395377): Add check for Motorola devices.
    102     return MotorolaHiddenMenuKeySequence.handleCharSequence(context, input);
    103   }
    104 
    105   private static boolean isSupportingSprintHdCodec(Context context) {
    106     return isSpnMatched(context)
    107         && context.getResources().getBoolean(R.bool.motorola_sprint_hd_codec)
    108         && context.getPackageManager().hasSystemFeature(HD_CALL_FEATRURE);
    109   }
    110 
    111   private static boolean isSupportingSprintWifiCall(Context context) {
    112     if (!hasCheckedSprintWifiCall) {
    113       supportSprintWifiCall = PackageUtils.isPackageEnabled(WIFI_CALL_PACKAGE_NAME, context);
    114       hasCheckedSprintWifiCall = true;
    115     }
    116     return supportSprintWifiCall;
    117   }
    118 }
    119