/** * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes * resources which can be used in a user interface. * * @param telecomManager the {@link TelecomManager} used for method calls, if possible. * @param account The {@link PhoneAccountHandle}. * @return The {@link PhoneAccount} object or null if it doesn't exist. */ @Nullable public static PhoneAccount getPhoneAccount(@Nullable TelecomManager telecomManager, @Nullable PhoneAccountHandle accountHandle) { if (telecomManager != null && (CompatUtils.isMethodAvailable( TELECOM_MANAGER_CLASS, "getPhoneAccount", PhoneAccountHandle.class))) { return telecomManager.getPhoneAccount(accountHandle); } return null; }
/** * Silences the ringer if a ringing call exists. Noop if {@link TelecomManager#silenceRinger()} * is unavailable. * * @param telecomManager the TelecomManager to use to silence the ringer. */ public static void silenceRinger(@Nullable TelecomManager telecomManager) { if (telecomManager != null && (CompatUtils.isMarshmallowCompatible() || CompatUtils .isMethodAvailable(TELECOM_MANAGER_CLASS, "silenceRinger"))) { telecomManager.silenceRinger(); } }
/** * Returns the current SIM call manager. Apps must be prepared for this method to return null, * indicating that there currently exists no registered SIM call manager. * * @param telecomManager the {@link TelecomManager} to use to fetch the SIM call manager. * @return The phone account handle of the current sim call manager. */ @Nullable public static PhoneAccountHandle getSimCallManager(TelecomManager telecomManager) { if (telecomManager != null && (CompatUtils.isMarshmallowCompatible() || CompatUtils .isMethodAvailable(TELECOM_MANAGER_CLASS, "getSimCallManager"))) { return telecomManager.getSimCallManager(); } return null; } }
/** * Return the voicemail number for a given phone account. * * @param telecomManager The {@link TelecomManager} object to use for retrieving the voicemail * number if accountHandle is specified. * @param telephonyManager The {@link TelephonyManager} object to use for retrieving the * voicemail number if accountHandle is null. * @param accountHandle The handle for the phone account. * @return The voicemail number for the phone account, and {@code null} if one has not been * configured. */ @Nullable public static String getVoiceMailNumber(@Nullable TelecomManager telecomManager, @Nullable TelephonyManager telephonyManager, @Nullable PhoneAccountHandle accountHandle) { if (telecomManager != null && (CompatUtils.isMethodAvailable( TELECOM_MANAGER_CLASS, "getVoiceMailNumber", PhoneAccountHandle.class))) { return telecomManager.getVoiceMailNumber(accountHandle); } else if (telephonyManager != null){ return telephonyManager.getVoiceMailNumber(); } return null; }
/** * Returns a list of {@link PhoneAccountHandle}s which can be used to make and receive phone * calls. The returned list includes only those accounts which have been explicitly enabled * by the user. * * @param telecomManager the {@link TelecomManager} used for method calls, if possible. * @return A list of PhoneAccountHandle objects. */ public static List<PhoneAccountHandle> getCallCapablePhoneAccounts( @Nullable TelecomManager telecomManager) { if (telecomManager != null && (CompatUtils.isMarshmallowCompatible() || CompatUtils.isMethodAvailable(TELECOM_MANAGER_CLASS, "getCallCapablePhoneAccounts"))) { return telecomManager.getCallCapablePhoneAccounts(); } return new ArrayList<>(); }
/** * Get the URI for running an adn query. * * @param telecomManager the {@link TelecomManager} used for method calls, if possible. * @param accountHandle The handle for the account to derive an adn query URI for or * {@code null} to return a URI which will use the default account. * @return The URI (with the content:// scheme) specific to the specified {@link PhoneAccount} * for the the content retrieve. */ public static Uri getAdnUriForPhoneAccount(@Nullable TelecomManager telecomManager, PhoneAccountHandle accountHandle) { if (telecomManager != null && (CompatUtils.isMarshmallowCompatible() || CompatUtils.isMethodAvailable(TELECOM_MANAGER_CLASS, "getAdnUriForPhoneAccount", PhoneAccountHandle.class))) { return telecomManager.getAdnUriForPhoneAccount(accountHandle); } return Uri.parse("content://icc/adn"); }
/** * Whether the phone supports TTY mode. * * @param telephonyManager The telephony manager instance to use for method calls. * @return {@code true} if the device supports TTY mode, and {@code false} otherwise. */ public static boolean isTtyModeSupported(@Nullable TelephonyManager telephonyManager) { if (telephonyManager == null) { return false; } if (CompatUtils.isMarshmallowCompatible() || CompatUtils.isMethodAvailable(TELEPHONY_MANAGER_CLASS, "isTtyModeSupported")) { return telephonyManager.isTtyModeSupported(); } return false; }
/** * Return whether a given phone number is the configured voicemail number for a * particular phone account. * * @param telecomManager the {@link TelecomManager} to use for checking the number. * @param accountHandle The handle for the account to check the voicemail number against * @param number The number to look up. */ public static boolean isVoiceMailNumber(@Nullable TelecomManager telecomManager, @Nullable PhoneAccountHandle accountHandle, @Nullable String number) { if (telecomManager != null && (CompatUtils.isMarshmallowCompatible() || CompatUtils.isMethodAvailable(TELECOM_MANAGER_CLASS, "isVoiceMailNumber", PhoneAccountHandle.class, String.class))) { return telecomManager.isVoiceMailNumber(accountHandle, number); } return PhoneNumberUtils.isVoiceMailNumber(number); }
/** * Return the {@link PhoneAccount} which will be used to place outgoing calls to addresses with * the specified {@code uriScheme}. This PhoneAccount will always be a member of the * list which is returned from invoking {@link TelecomManager#getCallCapablePhoneAccounts()}. * The specific account returned depends on the following priorities: * * 1. If the user-selected default PhoneAccount supports the specified scheme, it will * be returned. * 2. If there exists only one PhoneAccount that supports the specified scheme, it * will be returned. * * If no PhoneAccount fits the criteria above, this method will return {@code null}. * * @param telecomManager the {@link TelecomManager} used for method calls, if possible. * @param uriScheme The URI scheme. * @return The {@link PhoneAccountHandle} corresponding to the account to be used. */ @Nullable public static PhoneAccountHandle getDefaultOutgoingPhoneAccount( @Nullable TelecomManager telecomManager, @Nullable String uriScheme) { if (telecomManager != null && (CompatUtils.isMarshmallowCompatible() || CompatUtils.isMethodAvailable(TELECOM_MANAGER_CLASS, "getDefaultOutgoingPhoneAccount", String.class))) { return telecomManager.getDefaultOutgoingPhoneAccount(uriScheme); } return null; }
/** * Returns the number of phones available. * Returns 1 for Single standby mode (Single SIM functionality) * Returns 2 for Dual standby mode.(Dual SIM functionality) * * Returns 1 if the method or telephonyManager is not available. * * @param telephonyManager The telephony manager instance to use for method calls. */ public static int getPhoneCount(@Nullable TelephonyManager telephonyManager) { if (telephonyManager == null) { return 1; } if (CompatUtils.isMarshmallowCompatible() || CompatUtils .isMethodAvailable(TELEPHONY_MANAGER_CLASS, "getPhoneCount")) { return telephonyManager.getPhoneCount(); } return 1; }
/** * Whether the phone supports hearing aid compatibility. * * @param telephonyManager The telephony manager instance to use for method calls. * @return {@code true} if the device supports hearing aid compatibility, and {@code false} * otherwise. */ public static boolean isHearingAidCompatibilitySupported( @Nullable TelephonyManager telephonyManager) { if (telephonyManager == null) { return false; } if (CompatUtils.isMarshmallowCompatible() || CompatUtils.isMethodAvailable(TELEPHONY_MANAGER_CLASS, "isHearingAidCompatibilitySupported")) { return telephonyManager.isHearingAidCompatibilitySupported(); } return false; }
/** * Returns the unique device ID of a subscription, for example, the IMEI for * GSM and the MEID for CDMA phones. Return null if device ID is not available. * * <p>Requires Permission: * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} * * @param telephonyManager The telephony manager instance to use for method calls. * @param slotId of which deviceID is returned */ public static String getDeviceId(@Nullable TelephonyManager telephonyManager, int slotId) { if (telephonyManager == null) { return null; } if (CompatUtils.isMarshmallowCompatible() || CompatUtils.isMethodAvailable(TELEPHONY_MANAGER_CLASS, "getDeviceId", Integer.class)) { return telephonyManager.getDeviceId(slotId); } return null; }
static boolean handleDeviceIdDisplay(Context context, String input) { TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (telephonyManager != null && input.equals(MMI_IMEI_DISPLAY)) { int labelResId = (telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) ? R.string.imei : R.string.meid; List<String> deviceIds = new ArrayList<String>(); if (TelephonyManagerCompat.getPhoneCount(telephonyManager) > 1 && CompatUtils.isMethodAvailable(TelephonyManagerCompat.TELEPHONY_MANAGER_CLASS, "getDeviceId", Integer.TYPE)) { for (int slot = 0; slot < telephonyManager.getPhoneCount(); slot++) { String deviceId = telephonyManager.getDeviceId(slot); if (!TextUtils.isEmpty(deviceId)) { deviceIds.add(deviceId); } } } else { deviceIds.add(telephonyManager.getDeviceId()); } AlertDialog alert = new AlertDialog.Builder(context) .setTitle(labelResId) .setItems(deviceIds.toArray(new String[deviceIds.size()]), null) .setPositiveButton(android.R.string.ok, null) .setCancelable(false) .show(); return true; } return false; }
/** * @param telephonyManager The telephony manager instance to use for method calls. * @return true if the current device is "voice capable". * <p> * "Voice capable" means that this device supports circuit-switched * (i.e. voice) phone calls over the telephony network, and is allowed * to display the in-call UI while a cellular voice call is active. * This will be false on "data only" devices which can't make voice * calls and don't support any in-call UI. * <p> * Note: the meaning of this flag is subtly different from the * PackageManager.FEATURE_TELEPHONY system feature, which is available * on any device with a telephony radio, even if the device is * data-only. */ public static boolean isVoiceCapable(@Nullable TelephonyManager telephonyManager) { if (telephonyManager == null) { return false; } if (CompatUtils.isLollipopMr1Compatible() || CompatUtils.isMethodAvailable(TELEPHONY_MANAGER_CLASS, "isVoiceCapable")) { // 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; }