Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8ad88302 authored by Wenyi Wang's avatar Wenyi Wang
Browse files

Backport isVoiceCapable() using getPhoneType()

isVoiceCapable() was unhidden in API 22. We couldn't copy the code to
backport it because the app doesn't have access to
com.android.internal.R.bool.config_voice_capable. So we use getPhoneType()
as a workaround since it also calls isVoiceCapable().

Bug: 25629359

Change-Id: Ia117823ae871c7132014d10c5475eba5dbfda009
parent 0f8dbd85
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import android.net.Uri;
import android.net.sip.SipManager;
import android.provider.MediaStore;
import android.provider.Telephony;
import android.telephony.TelephonyManager;

import com.android.contacts.common.ContactsUtils;

@@ -61,9 +60,7 @@ public final class PhoneCapabilityTester {
    }

    private static void initialize(Context context) {
        final TelephonyManager telephonyManager
                = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        sIsPhone = telephonyManager.isVoiceCapable();
        sIsPhone = TelephonyManagerCompat.isVoiceCapable(context);
        sIsSipPhone = sIsPhone && SipManager.isVoipSupported(context);
        sIsInitialized = true;
    }
+41 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 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.contacts.util;

import android.content.Context;
import android.os.Build;
import android.telephony.TelephonyManager;

import com.android.contacts.common.compat.SdkVersionOverride;

public class TelephonyManagerCompat {
    public static boolean isVoiceCapable(Context context) {
        final TelephonyManager telephonyManager
                = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        if (telephonyManager == null) {
            return false;
        }
        if (SdkVersionOverride.getSdkVersion(Build.VERSION_CODES.M)
                >= Build.VERSION_CODES.LOLLIPOP_MR1) {
            // isVoiceCapable was unhidden in L-MR1
            return telephonyManager.isVoiceCapable();
        }
        final int phoneType = telephonyManager.getPhoneType();
        return phoneType == TelephonyManager.PHONE_TYPE_CDMA ||
                phoneType == TelephonyManager.PHONE_TYPE_GSM;
    }
}