@Implementation protected void registerPhoneAccount(PhoneAccount account) { accounts.put(account.getAccountHandle(), account); }
@Implementation @HiddenApi public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) { List<PhoneAccountHandle> result = new ArrayList<>(); for (PhoneAccountHandle handle : accounts.keySet()) { PhoneAccount phoneAccount = accounts.get(handle); if(phoneAccount.getSupportedUriSchemes().contains(uriScheme)) { result.add(handle); } } return result; }
@Implementation(minSdk = M) @HiddenApi public List<PhoneAccountHandle> getCallCapablePhoneAccounts(boolean includeDisabledAccounts) { List<PhoneAccountHandle> result = new ArrayList<>(); for (PhoneAccountHandle handle : accounts.keySet()) { PhoneAccount phoneAccount = accounts.get(handle); if(!phoneAccount.isEnabled() && !includeDisabledAccounts) { continue; } result.add(handle); } return result; }
@Test public void registerAndUnRegister() { assertThat(shadowOf(telecomService).getAllPhoneAccountsCount()).isEqualTo(0); assertThat(shadowOf(telecomService).getAllPhoneAccounts()).hasSize(0); PhoneAccountHandle handler = createHandle("id"); PhoneAccount phoneAccount = PhoneAccount.builder(handler, "main_account").build(); telecomService.registerPhoneAccount(phoneAccount); assertThat(shadowOf(telecomService).getAllPhoneAccountsCount()).isEqualTo(1); assertThat(shadowOf(telecomService).getAllPhoneAccounts()).hasSize(1); assertThat(telecomService.getAllPhoneAccountHandles()).hasSize(1); assertThat(telecomService.getAllPhoneAccountHandles()).contains(handler); assertThat(telecomService.getPhoneAccount(handler).getLabel()).isEqualTo(phoneAccount.getLabel()); telecomService.unregisterPhoneAccount(handler); assertThat(shadowOf(telecomService).getAllPhoneAccountsCount()).isEqualTo(0); assertThat(shadowOf(telecomService).getAllPhoneAccounts()).hasSize(0); assertThat(telecomService.getAllPhoneAccountHandles()).hasSize(0); }
return rowView; holder.labelTextView.setText(account.getLabel()); if (account.getAddress() == null || TextUtils.isEmpty(account.getAddress().getSchemeSpecificPart())) { holder.numberTextView.setVisibility(View.GONE); } else { holder.numberTextView.setText( PhoneNumberUtilsCompat.createTtsSpannable( account.getAddress().getSchemeSpecificPart()));
/** * Determine whether a phone account supports call subjects. * * @return {@code true} if call subjects are supported, {@code false} otherwise. */ public static boolean getAccountSupportsCallSubject(Context context, @Nullable PhoneAccountHandle accountHandle) { final PhoneAccount account = TelecomUtil.getPhoneAccount(context, accountHandle); return account == null ? false : account.hasCapabilities(PhoneAccount.CAPABILITY_CALL_SUBJECT); }
/** * Extract account label from PhoneAccount object. */ @Nullable public static String getAccountLabel(Context context, @Nullable PhoneAccountHandle accountHandle) { PhoneAccount account = getAccountOrNull(context, accountHandle); if (account != null && account.getLabel() != null) { return account.getLabel().toString(); } return null; }
@Test @Config(minSdk = LOLLIPOP_MR1) public void getPhoneAccountsForPackage() { PhoneAccountHandle handleInThisApplicationsPackage = createHandle("id1"); telecomService.registerPhoneAccount(PhoneAccount.builder(handleInThisApplicationsPackage, "this_package") .build()); PhoneAccountHandle anotherPackageHandle = createHandle("some.other.package", "id2"); telecomService.registerPhoneAccount(PhoneAccount.builder(anotherPackageHandle, "another_package") .build()); List<PhoneAccountHandle> phoneAccountsForPackage = telecomService.getPhoneAccountsForPackage(); assertThat(phoneAccountsForPackage).contains(handleInThisApplicationsPackage); assertThat(phoneAccountsForPackage).doesNotContain(anotherPackageHandle); }
/** * Return a list of phone accounts that are subscription/SIM accounts. */ public static List<PhoneAccountHandle> getSubscriptionPhoneAccounts(Context context) { List<PhoneAccountHandle> subscriptionAccountHandles = new ArrayList<PhoneAccountHandle>(); final List<PhoneAccountHandle> accountHandles = TelecomUtil.getCallCapablePhoneAccounts(context); for (PhoneAccountHandle accountHandle : accountHandles) { PhoneAccount account = TelecomUtil.getPhoneAccount(context, accountHandle); if (account.hasCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION)) { subscriptionAccountHandles.add(accountHandle); } } return subscriptionAccountHandles; }
@Test public void clearAccounts() { PhoneAccountHandle anotherPackageHandle = createHandle("some.other.package", "id"); telecomService.registerPhoneAccount(PhoneAccount.builder(anotherPackageHandle, "another_package") .build()); }
@Implementation public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) { List<PhoneAccountHandle> result = new LinkedList<>(); for (PhoneAccountHandle handle : accounts.keySet()) { PhoneAccount phoneAccount = accounts.get(handle); if(phoneAccount.getSupportedUriSchemes().contains(uriScheme)) { result.add(handle); } } return result; }
@Implementation public void registerPhoneAccount(PhoneAccount account) { accounts.put(account.getAccountHandle(), account); }
@Implementation(minSdk = M) public List<PhoneAccountHandle> getCallCapablePhoneAccounts(boolean includeDisabledAccounts) { List<PhoneAccountHandle> result = new LinkedList<>(); for (PhoneAccountHandle handle : accounts.keySet()) { PhoneAccount phoneAccount = accounts.get(handle); if(!phoneAccount.isEnabled() && !includeDisabledAccounts) { continue; } result.add(handle); } return result; }
PhoneAccount account = telecommMgr.getPhoneAccount(accountHandle); if (account != null) { if (account.hasCapabilities(PhoneAccount.CAPABILITY_VIDEO_CALLING)) { if (account.hasCapabilities( PhoneAccountSdkCompat.CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) { videoCapabilities |= VIDEO_CALLING_PRESENCE;
@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); }
@Implementation public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) { List<PhoneAccountHandle> result = new LinkedList<>(); for (PhoneAccountHandle handle : accounts.keySet()) { PhoneAccount phoneAccount = accounts.get(handle); if(phoneAccount.getSupportedUriSchemes().contains(uriScheme)) { result.add(handle); } } return result; }
@Implementation protected void registerPhoneAccount(PhoneAccount account) { accounts.put(account.getAccountHandle(), account); }
@Implementation(minSdk = M) public List<PhoneAccountHandle> getCallCapablePhoneAccounts(boolean includeDisabledAccounts) { List<PhoneAccountHandle> result = new LinkedList<>(); for (PhoneAccountHandle handle : accounts.keySet()) { PhoneAccount phoneAccount = accounts.get(handle); if(!phoneAccount.isEnabled() && !includeDisabledAccounts) { continue; } result.add(handle); } return result; }
/** * 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; } }
@Test @Config(minSdk = LOLLIPOP_MR1) public void clearAccountsForPackage() { PhoneAccountHandle accountHandle1 = createHandle("a.package", "id1"); telecomService.registerPhoneAccount(PhoneAccount.builder(accountHandle1, "another_package") .build()); PhoneAccountHandle accountHandle2 = createHandle("some.other.package", "id2"); telecomService.registerPhoneAccount(PhoneAccount.builder(accountHandle2, "another_package") .build()); telecomService.clearAccountsForPackage(accountHandle1.getComponentName().getPackageName()); assertThat(telecomService.getPhoneAccount(accountHandle1)).isNull(); assertThat(telecomService.getPhoneAccount(accountHandle2)).isNotNull(); }