/** * Determines if this version is compatible with a default dialer. Can also force the version to * be lower through {@link SdkVersionOverride}. * * @return {@code true} if default dialer is a feature on this device, {@code false} otherwise. */ public static boolean isDefaultDialerCompatible() { return isMarshmallowCompatible(); }
/** * Determines if this version has access to the * {@link android.provider.CallLog.Calls.CACHED_PHOTO_URI} column * * @return {@code true} if {@link android.provider.CallLog.Calls.CACHED_PHOTO_URI} is available, * {@code false} otherwise */ public static boolean isCallsCachedPhotoUriCompatible() { return CompatUtils.isMarshmallowCompatible(); } }
/** * Gets the {@link Icon} associated with the given {@link PhoneAccount} * * @param phoneAccount the PhoneAccount from which to retrieve the Icon * @return the Icon, or null */ @Nullable public static Icon getIcon(@Nullable PhoneAccount phoneAccount) { if (phoneAccount == null) { return null; } if (CompatUtils.isMarshmallowCompatible()) { return phoneAccount.getIcon(); } return null; }
/** * Places a new outgoing call to the provided address using the system telecom service with * the specified intent. * * @param activity {@link Activity} used to start another activity for the given intent * @param telecomManager the {@link TelecomManager} used to place a call, if possible * @param intent the intent for the call */ public static void placeCall(@Nullable Activity activity, @Nullable TelecomManager telecomManager, @Nullable Intent intent) { if (activity == null || telecomManager == null || intent == null) { return; } if (CompatUtils.isMarshmallowCompatible()) { telecomManager.placeCall(intent.getData(), intent.getExtras()); return; } activity.startActivityForResult(intent, 0); }
/** * 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(); } }
/** * Compat method for addTtsSpan, see {@link PhoneNumberUtils#addTtsSpan} */ public static void addTtsSpan(Spannable s, int start, int endExclusive) { if (CompatUtils.isMarshmallowCompatible()) { PhoneNumberUtils.addTtsSpan(s, start, endExclusive); } else { addTtsSpanInternal(s, start, endExclusive); } }
/** * 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; } }
public static CharSequence createTtsSpannable(CharSequence phoneNumber) { if (CompatUtils.isMarshmallowCompatible()) { return PhoneNumberUtils.createTtsSpannable(phoneNumber); } else { return createTtsSpannableInternal(phoneNumber); } }
/** * 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<>(); }
/** * Used to check if this process is running under the system user. The system user is the * initial user that is implicitly created on first boot and hosts most of the system services. * * @return whether this process is running under the system user. */ public static boolean isSystemUser(UserManager userManager) { if (CompatUtils.isMarshmallowCompatible()) { return userManager.isSystemUser(); } // Adapted from {@link UserManager} and {@link UserHandle}. return (Process.myUid() / PER_USER_RANGE) == USER_SYSTEM; }
/** * 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"); }
/** * Return the line 1 phone number for given phone account. * * @param telecomManager the {@link TelecomManager} to use in the event that * {@link TelecomManager#getLine1Number(PhoneAccountHandle)} is available * @param telephonyManager the {@link TelephonyManager} to use if TelecomManager#getLine1Number * is unavailable * @param phoneAccountHandle the phoneAccountHandle upon which to check the line one number * @return the line one number */ @Nullable public static String getLine1Number(@Nullable TelecomManager telecomManager, @Nullable TelephonyManager telephonyManager, @Nullable PhoneAccountHandle phoneAccountHandle) { if (telecomManager != null && CompatUtils.isMarshmallowCompatible()) { return telecomManager.getLine1Number(phoneAccountHandle); } if (telephonyManager != null) { return telephonyManager.getLine1Number(); } return null; }
/** * 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); }
/** * 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; }
/** * Builds and returns an icon {@code Drawable} to represent this {@code PhoneAccount} in a user * interface. * * @param phoneAccount the PhoneAccount from which to build the icon. * @param context A {@code Context} to use for loading Drawables. * * @return An icon for this PhoneAccount, or null */ @Nullable public static Drawable createIconDrawable(@Nullable PhoneAccount phoneAccount, @Nullable Context context) { if (phoneAccount == null || context == null) { return null; } if (CompatUtils.isMarshmallowCompatible()) { return createIconDrawableMarshmallow(phoneAccount, context); } if (CompatUtils.isLollipopMr1Compatible()) { return createIconDrawableLollipopMr1(phoneAccount, context); } return null; }
/** * Processes the specified dial string as an MMI code. * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#". * Some of these sequences launch special behavior through handled by Telephony. * * @param telecomManager The {@link TelecomManager} object to use for handling MMI. * @param dialString The digits to dial. * @return {@code true} if the digits were processed as an MMI code, {@code false} otherwise. */ public static boolean handleMmi(@Nullable TelecomManager telecomManager, @Nullable String dialString, @Nullable PhoneAccountHandle accountHandle) { if (telecomManager == null || TextUtils.isEmpty(dialString)) { return false; } if (CompatUtils.isMarshmallowCompatible()) { return telecomManager.handleMmi(dialString, accountHandle); } Object handleMmiResult = CompatUtils.invokeMethod( telecomManager, "handleMmi", new Class<?>[] {PhoneAccountHandle.class, String.class}, new Object[] {accountHandle, dialString}); if (handleMmiResult != null) { return (boolean) handleMmiResult; } return telecomManager.handleMmi(dialString); }
public static TtsSpan createTtsSpan(String phoneNumber) { if (CompatUtils.isMarshmallowCompatible()) { return PhoneNumberUtils.createTtsSpan(phoneNumber); } else if (CompatUtils.isLollipopCompatible()) { return createTtsSpanLollipop(phoneNumber); } else { return null; } }