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

Commit 17294e1a authored by Wenyi Wang's avatar Wenyi Wang Committed by Android (Google) Code Review
Browse files

Merge "Backport isVoiceCapable() using getPhoneType()" into ub-contactsdialer-b-dev

parents 04719722 8ad88302
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;
    }
}