Resource processor has been enabled by default in BP1A. Fix all errors by importing com.android.dialer.R instead of the current imports. Change-Id: I6fe0184984de901946cbce0c4edce93b6ac03af0
126 lines
4.9 KiB
Java
126 lines
4.9 KiB
Java
/*
|
|
* Copyright (C) 2017 The Android Open Source Project
|
|
* Copyright (C) 2023-2025 The LineageOS 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.dialer.oem;
|
|
|
|
import android.content.Context;
|
|
import android.content.res.Resources;
|
|
import android.provider.CallLog.Calls;
|
|
import android.telephony.TelephonyManager;
|
|
|
|
import com.android.dialer.R;
|
|
import com.android.dialer.common.LogUtil;
|
|
import com.android.dialer.common.PackageUtils;
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.Method;
|
|
|
|
/** Util class for Motorola OEM devices. */
|
|
public class MotorolaUtils {
|
|
|
|
// This is used to check if a Motorola device supports HD voice call feature, which comes from
|
|
// system feature setting.
|
|
private static final String HD_CALL_FEATURE = "com.motorola.software.sprint.hd_call";
|
|
// This is used to check if a Motorola device supports WiFi call feature, by checking if a certain
|
|
// package is enabled.
|
|
private static final String WIFI_CALL_PACKAGE_NAME = "com.motorola.sprintwfc";
|
|
// Thi is used to check if a Motorola device supports hidden menu feature.
|
|
private static final String HIDDEN_MENU_FEATURE = "com.motorola.software.sprint.hidden_menu";
|
|
|
|
private static boolean hasCheckedSprintWifiCall;
|
|
private static boolean supportSprintWifiCall;
|
|
|
|
/**
|
|
* Returns true if SPN is specified and matched the current sim operator name. This is necessary
|
|
* since mcc310-mnc000 is not sufficient to identify Sprint network.
|
|
*/
|
|
private static boolean isSpnMatched(Context context) {
|
|
try {
|
|
for (String spnResource :
|
|
context.getResources().getStringArray(R.array.motorola_enabled_spn)) {
|
|
if (spnResource.equalsIgnoreCase(
|
|
context.getSystemService(TelephonyManager.class).getSimOperatorName())) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
} catch (Resources.NotFoundException exception) {
|
|
// If SPN is not specified we consider as not necessary to enable/disable the feature.
|
|
return true;
|
|
}
|
|
}
|
|
|
|
static boolean isSupportingHiddenMenu(Context context) {
|
|
return context.getPackageManager().hasSystemFeature(HIDDEN_MENU_FEATURE)
|
|
&& context.getResources().getBoolean(R.bool.motorola_hidden_menu_enabled);
|
|
}
|
|
|
|
public static boolean shouldBlinkHdIconWhenConnectingCall(Context context) {
|
|
return isSupportingSprintHdCodec(context);
|
|
}
|
|
|
|
public static boolean shouldShowWifiIconInCallLog(Context context, int features) {
|
|
return (features & Calls.FEATURES_WIFI) == Calls.FEATURES_WIFI
|
|
&& isSupportingSprintWifiCall(context);
|
|
}
|
|
|
|
public static boolean shouldDisablePhoneNumberFormatting(Context context) {
|
|
return context.getResources().getBoolean(R.bool.motorola_disable_phone_number_formatting);
|
|
}
|
|
|
|
/**
|
|
* Handle special char sequence entered in dialpad. This may launch special intent based on input.
|
|
*
|
|
* @param context context
|
|
* @param input input string
|
|
* @return true if the input is consumed and the intent is launched
|
|
*/
|
|
public static boolean handleSpecialCharSequence(Context context, String input) {
|
|
// TODO(a bug): Add check for Motorola devices.
|
|
return MotorolaHiddenMenuKeySequence.handleCharSequence(context, input);
|
|
}
|
|
|
|
public static boolean isWifiCallingAvailable(Context context) {
|
|
if (!isSupportingSprintWifiCall(context)) {
|
|
return false;
|
|
}
|
|
TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class);
|
|
try {
|
|
Method method = TelephonyManager.class.getMethod("isWifiCallingAvailable");
|
|
boolean isWifiCallingAvailable = (boolean) method.invoke(telephonyManager);
|
|
LogUtil.d("MotorolaUtils.isWifiCallingAvailable", "%b", isWifiCallingAvailable);
|
|
return isWifiCallingAvailable;
|
|
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
|
|
LogUtil.e("MotorolaUtils.isWifiCallingAvailable", "", e);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private static boolean isSupportingSprintHdCodec(Context context) {
|
|
return isSpnMatched(context)
|
|
&& context.getResources().getBoolean(R.bool.motorola_sprint_hd_codec)
|
|
&& context.getPackageManager().hasSystemFeature(HD_CALL_FEATURE);
|
|
}
|
|
|
|
private static boolean isSupportingSprintWifiCall(Context context) {
|
|
if (!hasCheckedSprintWifiCall) {
|
|
supportSprintWifiCall = PackageUtils.isPackageEnabled(WIFI_CALL_PACKAGE_NAME, context);
|
|
hasCheckedSprintWifiCall = true;
|
|
}
|
|
return supportSprintWifiCall;
|
|
}
|
|
}
|