• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 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 
17 package com.android.internal.telephony;
18 
19 import android.annotation.NonNull;
20 import android.compat.annotation.UnsupportedAppUsage;
21 import android.content.Context;
22 import android.content.pm.PackageManager;
23 import android.os.Build;
24 import android.os.SystemProperties;
25 
26 import com.android.internal.telephony.flags.FeatureFlags;
27 import com.android.telephony.Rlog;
28 
29 /**
30  * Utilities that check if the phone supports specified capabilities.
31  */
32 public class TelephonyCapabilities {
33     private static final String LOG_TAG = "TelephonyCapabilities";
34 
35     /** This class is never instantiated. */
TelephonyCapabilities()36     private TelephonyCapabilities() {
37     }
38 
39     /**
40      * Return true if the current phone supports ECM ("Emergency Callback
41      * Mode"), which is a feature where the device goes into a special
42      * state for a short period of time after making an outgoing emergency
43      * call.
44      *
45      * (On current devices, that state lasts 5 minutes.  It prevents data
46      * usage by other apps, to avoid conflicts with any possible incoming
47      * calls.  It also puts up a notification in the status bar, showing a
48      * countdown while ECM is active, and allowing the user to exit ECM.)
49      *
50      * Currently this is assumed to be true for CDMA phones, and false
51      * otherwise.
52      */
supportsEcm(Phone phone)53     public static boolean supportsEcm(Phone phone) {
54         Rlog.d(LOG_TAG, "supportsEcm: Phone type = " + phone.getPhoneType() +
55                   " Ims Phone = " + phone.getImsPhone());
56         return (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA ||
57                 phone.getImsPhone() != null);
58     }
59 
60     /**
61      * Return true if the current phone supports Over The Air Service
62      * Provisioning (OTASP)
63      *
64      * Currently this is assumed to be true for CDMA phones, and false
65      * otherwise.
66      *
67      * TODO: Watch out: this is also highly carrier-specific, since the
68      * OTASP procedure is different from one carrier to the next, *and* the
69      * different carriers may want very different onscreen UI as well.
70      * The procedure may even be different for different devices with the
71      * same carrier.
72      *
73      * So we eventually will need a much more flexible, pluggable design.
74      * This method here is just a placeholder to reduce hardcoded
75      * "if (CDMA)" checks sprinkled throughout the phone app.
76      */
supportsOtasp(Phone phone)77     public static boolean supportsOtasp(Phone phone) {
78         return (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA);
79     }
80 
81     /**
82      * Return true if the current phone supports voice message count.
83      * and the count is available
84      * Both CDMA and GSM phones support voice message count
85      */
supportsVoiceMessageCount(Phone phone)86     public static boolean supportsVoiceMessageCount(Phone phone) {
87         return (phone.getVoiceMessageCount() != -1);
88     }
89 
90     /**
91      * Return true if this phone allows the user to select which
92      * network to use.
93      *
94      * Currently this is assumed to be true only on GSM phones.
95      *
96      * TODO: Should CDMA phones allow this as well?
97      */
supportsNetworkSelection(Phone phone)98     public static boolean supportsNetworkSelection(Phone phone) {
99         return (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_GSM);
100     }
101 
102     /**
103      * Returns a resource ID for a label to use when displaying the
104      * "device id" of the current device.  (This is currently used as the
105      * title of the "device id" dialog.)
106      *
107      * This is specific to the device's telephony technology: the device
108      * id is called "IMEI" on GSM phones and "MEID" on CDMA phones.
109      */
getDeviceIdLabel(Phone phone)110     public static int getDeviceIdLabel(Phone phone) {
111         if (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_GSM) {
112             return com.android.internal.R.string.imei;
113         } else if (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
114             return com.android.internal.R.string.meid;
115         } else {
116             Rlog.w(LOG_TAG, "getDeviceIdLabel: no known label for phone "
117                   + phone.getPhoneName());
118             return 0;
119         }
120     }
121 
122     /**
123      * Return true if the current phone supports the ability to explicitly
124      * manage the state of a conference call (i.e. view the participants,
125      * and hangup or separate individual callers.)
126      *
127      * The in-call screen's "Manage conference" UI is available only on
128      * devices that support this feature.
129      *
130      * Currently this is assumed to be true on GSM phones and false otherwise.
131      */
supportsConferenceCallManagement(Phone phone)132     public static boolean supportsConferenceCallManagement(Phone phone) {
133         return ((phone.getPhoneType() == PhoneConstants.PHONE_TYPE_GSM)
134                 || (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_SIP));
135     }
136 
137     /**
138      * Return true if the current phone supports explicit "Hold" and
139      * "Unhold" actions for an active call.  (If so, the in-call UI will
140      * provide onscreen "Hold" / "Unhold" buttons.)
141      *
142      * Currently this is assumed to be true on GSM phones and false
143      * otherwise.  (In particular, CDMA has no concept of "putting a call
144      * on hold.")
145      */
supportsHoldAndUnhold(Phone phone)146     public static boolean supportsHoldAndUnhold(Phone phone) {
147         return ((phone.getPhoneType() == PhoneConstants.PHONE_TYPE_GSM)
148                 || (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_SIP)
149                 || (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_IMS));
150     }
151 
152     /**
153      * Return true if the current phone supports distinct "Answer & Hold"
154      * and "Answer & End" behaviors in the call-waiting scenario.  If so,
155      * the in-call UI may provide separate buttons or menu items for these
156      * two actions.
157      *
158      * Currently this is assumed to be true on GSM phones and false
159      * otherwise.  (In particular, CDMA has no concept of explicitly
160      * managing the background call, or "putting a call on hold.")
161      *
162      * TODO: It might be better to expose this capability in a more
163      * generic form, like maybe "supportsExplicitMultipleLineManagement()"
164      * rather than focusing specifically on call-waiting behavior.
165      */
supportsAnswerAndHold(Phone phone)166     public static boolean supportsAnswerAndHold(Phone phone) {
167         return ((phone.getPhoneType() == PhoneConstants.PHONE_TYPE_GSM)
168                 || (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_SIP));
169     }
170 
171     /**
172      * Return true if phones with the given phone type support ADN
173      * (Abbreviated Dialing Numbers).
174      *
175      * Currently this returns true when the phone type is GSM
176      * ({@link PhoneConstants#PHONE_TYPE_GSM}).
177      *
178      * This is using int for an argument for letting apps outside
179      * Phone process access to it, while other methods in this class is
180      * using Phone object.
181      *
182      * TODO: Theoretically phones other than GSM may have the ADN capability.
183      * Consider having better check here, or have better capability as part
184      * of public API, with which the argument should be replaced with
185      * something more appropriate.
186      */
187     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
supportsAdn(int phoneType)188     public static boolean supportsAdn(int phoneType) {
189         return phoneType == PhoneConstants.PHONE_TYPE_GSM;
190     }
191 
192     /**
193      * Returns true if the device can distinguish the phone's dialing state
194      * (Call.State.DIALING/ALERTING) and connected state (Call.State.ACTIVE).
195      *
196      * Currently this returns true for GSM phones as we cannot know when a CDMA
197      * phone has transitioned from dialing/active to connected.
198      */
canDistinguishDialingAndConnected(int phoneType)199     public static boolean canDistinguishDialingAndConnected(int phoneType) {
200         return phoneType == PhoneConstants.PHONE_TYPE_GSM;
201     }
202 
203     /**
204      * Returns true if Calling/Data/Messaging features should be checked on this device.
205      */
minimalTelephonyCdmCheck(@onNull FeatureFlags featureFlags)206     public static boolean minimalTelephonyCdmCheck(@NonNull FeatureFlags featureFlags) {
207         // Check SDK version of the vendor partition.
208         final int vendorApiLevel = SystemProperties.getInt(
209                 "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT);
210         return vendorApiLevel >= Build.VERSION_CODES.VANILLA_ICE_CREAM;
211     }
212 
213     /**
214      * @return true if this device supports telephony calling, false if it does not.
215      */
supportsTelephonyCalling(@onNull FeatureFlags featureFlags, Context context)216     public static boolean supportsTelephonyCalling(@NonNull FeatureFlags featureFlags,
217             Context context) {
218         if (!TelephonyCapabilities.minimalTelephonyCdmCheck(featureFlags)) return true;
219         return context.getPackageManager().hasSystemFeature(
220                 PackageManager.FEATURE_TELEPHONY_CALLING);
221     }
222 
223     /**
224      * @return true if this device supports telephony messaging, false if it does not.
225      */
supportsTelephonyMessaging(@onNull FeatureFlags featureFlags, Context context)226     public static boolean supportsTelephonyMessaging(@NonNull FeatureFlags featureFlags,
227             Context context) {
228         if (!TelephonyCapabilities.minimalTelephonyCdmCheck(featureFlags)) return true;
229         return context.getPackageManager().hasSystemFeature(
230                 PackageManager.FEATURE_TELEPHONY_MESSAGING);
231     }
232 }
233