@Test @Config(minSdk = M) public void getCallCapablePhoneAccounts() { PhoneAccountHandle callCapableHandle = createHandle("id1"); telecomService.registerPhoneAccount(PhoneAccount.builder(callCapableHandle, "enabled") .setIsEnabled(true) .build()); PhoneAccountHandle notCallCapableHandler = createHandle("id2"); telecomService.registerPhoneAccount(PhoneAccount.builder(notCallCapableHandler, "disabled") .setIsEnabled(false) .build()); List<PhoneAccountHandle> callCapablePhoneAccounts = telecomService.getCallCapablePhoneAccounts(); assertThat(callCapablePhoneAccounts).contains(callCapableHandle); assertThat(callCapablePhoneAccounts).doesNotContain(notCallCapableHandler); }
/** * 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<>(); }
/** * 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; } }
List<PhoneAccountHandle> accountHandles = telecommMgr.getCallCapablePhoneAccounts(); for (PhoneAccountHandle accountHandle : accountHandles) { PhoneAccount account = telecommMgr.getPhoneAccount(accountHandle);