/** * 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(); } }
/** * @return the column name that stores contact id for phone lookup query. */ public static String getContactIdColumnNameForUri(Uri phoneLookupUri) { if (CompatUtils.isNCompatible()) { return PhoneLookupSdkCompat.CONTACT_ID; } // In pre-N, contact id is stored in {@link PhoneLookup#_ID} in non-sip query. boolean isSip = phoneLookupUri.getBooleanQueryParameter( ContactsContract.PhoneLookup.QUERY_PARAMETER_SIP_ADDRESS, false); return (isSip) ? PhoneLookupSdkCompat.CONTACT_ID : ContactsContract.PhoneLookup._ID; }
/** * 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; } }
/** * 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; }
/** * 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(); } }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final Uri uri = (Uri) view.getTag(); if (uri != null) { if (CompatUtils.hasPrioritizedMimeType()) { QuickContact.showQuickContact(getContext(), view, uri, null, Phone.CONTENT_ITEM_TYPE); } else { QuickContact.showQuickContact(getActivity(), view, uri, QuickContact.MODE_LARGE, null); } } }
/** * @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; }
/** * Return {@code true} if a contact ID is from the contacts provider on the enterprise profile. */ public static boolean isEnterpriseContactId(long contactId) { if (CompatUtils.isLollipopCompatible()) { return Contacts.isEnterpriseContactId(contactId); } else { // copied from ContactsContract.Contacts.isEnterpriseContactId return (contactId >= ENTERPRISE_CONTACT_ID_BASE) && (contactId < ContactsContract.Profile.MIN_ID); } } }
/** * 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; }
/** * Used to determine the currently selected default dialer package. * * @param telecomManager the {@link TelecomManager} used for method calls, if possible. * @return package name for the default dialer package or null if no package has been * selected as the default dialer. */ @Nullable public static String getDefaultDialerPackage(@Nullable TelecomManager telecomManager) { if (telecomManager != null && CompatUtils.isDefaultDialerCompatible()) { return telecomManager.getDefaultDialerPackage(); } return null; }
/** * Return the most compatible version of the TelecomCallLogCache. */ public static CallLogCache getCallLogCache(Context context) { if (CompatUtils.isClassAvailable("android.telecom.PhoneAccountHandle")) { return new CallLogCacheLollipopMr1(context); } return new CallLogCacheLollipop(context); }
/** * Determines if one of the call capable phone accounts defined supports calling with a subject * specified. * * @param context The context. * @return {@code true} if one of the call capable phone accounts supports calling with a * subject specified, {@code false} otherwise. */ public static boolean isCallWithSubjectSupported(Context context) { if (!PermissionsUtil.hasPermission(context, android.Manifest.permission.READ_PHONE_STATE) || !CompatUtils.isCallSubjectCompatible()) { return false; } TelecomManager telecommMgr = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); if (telecommMgr == null) { return false; } List<PhoneAccountHandle> accountHandles = telecommMgr.getCallCapablePhoneAccounts(); for (PhoneAccountHandle accountHandle : accountHandles) { PhoneAccount account = telecommMgr.getPhoneAccount(accountHandle); if (account != null && account.hasCapabilities(PhoneAccount.CAPABILITY_CALL_SUBJECT)) { return true; } } return false; } }
/** * 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(); }
(QuickContactBadge) view.findViewById(R.id.quick_contact_photo); quickContactBadge.setOverlay(null); if (CompatUtils.hasPrioritizedMimeType()) { quickContactBadge.setPrioritizedMimeType(Phone.CONTENT_ITEM_TYPE);
/** * Adds a rectangular outline to a view. This can be useful when you want to add a shadow * to a transparent view. See b/16856049. * @param view view that the outline is added to * @param res The resources file. */ public static void addRectangularOutlineProvider(View view, Resources res) { if (CompatUtils.isLollipopCompatible()) { view.setOutlineProvider(RECT_OUTLINE_PROVIDER); } }
/** * 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 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 String[] getPhoneLookupProjection(Uri phoneLookupUri) { if (CompatUtils.isNCompatible()) { return PHONE_LOOKUP_PROJECTION; } // Pre-N boolean isSip = phoneLookupUri.getBooleanQueryParameter( ContactsContract.PhoneLookup.QUERY_PARAMETER_SIP_ADDRESS, false); return (isSip) ? PHONE_LOOKUP_PROJECTION : BACKWARD_COMPATIBLE_NON_SIP_PHONE_LOOKUP_PROJECTION; }
/** * 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; }