diff options
author | Danny Baumann <dannybaumann@web.de> | 2018-06-25 10:47:13 +0200 |
---|---|---|
committer | Michael Bestas <mkbestas@lineageos.org> | 2020-12-12 01:23:35 +0200 |
commit | ce6bc0e203c42529c1c48df398da102e99e3f2b0 (patch) | |
tree | 52f5fd9e5cea4b41c1c5f683da938ddc81191807 | |
parent | a6593be278cc0f94387289f99607a050efe7878b (diff) |
Allow per-call account selection.
Change-Id: Ieac27294f4069b2cff17bb39a0954f74320ad943
13 files changed, 257 insertions, 24 deletions
diff --git a/java/com/android/dialer/app/AccountSelectionActivity.java b/java/com/android/dialer/app/AccountSelectionActivity.java new file mode 100644 index 000000000..de84a36b9 --- /dev/null +++ b/java/com/android/dialer/app/AccountSelectionActivity.java @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2018 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.dialer.app; + +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.telecom.PhoneAccount; +import android.telecom.PhoneAccountHandle; +import android.text.TextUtils; + +import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment; +import com.android.contacts.common.widget.SelectPhoneAccountDialogOptions; +import com.android.contacts.common.widget.SelectPhoneAccountDialogOptionsUtil; +import com.android.dialer.callintent.CallInitiationType; +import com.android.dialer.callintent.CallIntentBuilder; +import com.android.dialer.util.CallUtil; + +import java.util.ArrayList; +import java.util.List; + +public class AccountSelectionActivity extends AppCompatActivity { + public static Intent createIntent(Context context, String number, + CallInitiationType.Type initiationType) { + if (TextUtils.isEmpty(number)) { + return null; + } + + List<PhoneAccount> accounts = + CallUtil.getCallCapablePhoneAccounts(context, PhoneAccount.SCHEME_TEL); + if (accounts == null || accounts.size() <= 1) { + return null; + } + ArrayList<PhoneAccountHandle> accountHandles = new ArrayList<>(); + for (PhoneAccount account : accounts) { + accountHandles.add(account.getAccountHandle()); + } + + return new Intent(context, AccountSelectionActivity.class) + .putExtra("number", number) + .putExtra("accountHandles", accountHandles) + .putExtra("type", initiationType.ordinal()); + } + + private String number; + private CallInitiationType.Type initiationType; + + private SelectPhoneAccountDialogFragment.SelectPhoneAccountListener listener = + new SelectPhoneAccountDialogFragment.SelectPhoneAccountListener() { + @Override + public void onPhoneAccountSelected(PhoneAccountHandle selectedAccountHandle, + boolean setDefault, String callId) { + Intent intent = new CallIntentBuilder(number, initiationType) + .setPhoneAccountHandle(selectedAccountHandle) + .build(); + startActivity(intent); + finish(); + } + + @Override + public void onDialogDismissed(String callId) { + finish(); + } + }; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + number = getIntent().getStringExtra("number"); + initiationType = CallInitiationType.Type.values()[getIntent().getIntExtra("type", 0)]; + + if (getFragmentManager().findFragmentByTag("dialog") == null) { + List<PhoneAccountHandle> handles = getIntent().getParcelableArrayListExtra("accountHandles"); + SelectPhoneAccountDialogOptions options = SelectPhoneAccountDialogOptionsUtil + .builderWithAccounts(handles) + .setTitle(R.string.call_via_dialog_title) + .setCanSetDefault(false) + .build(); + SelectPhoneAccountDialogFragment dialog = + SelectPhoneAccountDialogFragment.newInstance(options, listener); + + dialog.show(getFragmentManager(), "dialog"); + } + } +} diff --git a/java/com/android/dialer/app/AndroidManifest.xml b/java/com/android/dialer/app/AndroidManifest.xml index 190f098a5..78b50b668 100644 --- a/java/com/android/dialer/app/AndroidManifest.xml +++ b/java/com/android/dialer/app/AndroidManifest.xml @@ -78,6 +78,10 @@ android:theme="@style/DialtactsTheme"> </activity> + <activity android:name="com.android.dialer.app.AccountSelectionActivity" + android:theme="@style/TransparentTheme" + android:exported="false" /> + <receiver android:name="com.android.dialer.app.calllog.CallLogReceiver"> <intent-filter> <action android:name="android.intent.action.NEW_VOICEMAIL"/> diff --git a/java/com/android/dialer/app/DialtactsActivity.java b/java/com/android/dialer/app/DialtactsActivity.java index 25a69564d..318f9a138 100644 --- a/java/com/android/dialer/app/DialtactsActivity.java +++ b/java/com/android/dialer/app/DialtactsActivity.java @@ -769,9 +769,10 @@ public class DialtactsActivity extends TransactionSafeActivity String number = data.getStringExtra(OldCallDetailsActivity.EXTRA_PHONE_NUMBER); int snackbarDurationMillis = 5_000; Snackbar.make(parentLayout, getString(R.string.ec_data_deleted), snackbarDurationMillis) - .setAction( - R.string.view_conversation, - v -> startActivity(IntentProvider.getSendSmsIntentProvider(number).getIntent(this))) + .setAction(R.string.view_conversation, v -> { + IntentProvider provider = IntentProvider.getSendSmsIntentProvider(number); + startActivity(provider.getClickIntent(this)); + }) .setActionTextColor(getResources().getColor(R.color.dialer_snackbar_action_text_color)) .show(); } diff --git a/java/com/android/dialer/app/calllog/CallLogActivity.java b/java/com/android/dialer/app/calllog/CallLogActivity.java index fdfb3ab2a..f28aa0fc7 100644 --- a/java/com/android/dialer/app/calllog/CallLogActivity.java +++ b/java/com/android/dialer/app/calllog/CallLogActivity.java @@ -284,9 +284,10 @@ public class CallLogActivity extends TransactionSafeActivity && data.getBooleanExtra(OldCallDetailsActivity.EXTRA_HAS_ENRICHED_CALL_DATA, false)) { String number = data.getStringExtra(OldCallDetailsActivity.EXTRA_PHONE_NUMBER); Snackbar.make(findViewById(R.id.calllog_frame), getString(R.string.ec_data_deleted), 5_000) - .setAction( - R.string.view_conversation, - v -> startActivity(IntentProvider.getSendSmsIntentProvider(number).getIntent(this))) + .setAction(R.string.view_conversation, v -> { + IntentProvider provider = IntentProvider.getSendSmsIntentProvider(number); + startActivity(provider.getClickIntent(this)); + }) .setActionTextColor(getResources().getColor(R.color.dialer_snackbar_action_text_color)) .show(); } diff --git a/java/com/android/dialer/app/calllog/CallLogListItemViewHolder.java b/java/com/android/dialer/app/calllog/CallLogListItemViewHolder.java index e044460c5..1d50a82ac 100644 --- a/java/com/android/dialer/app/calllog/CallLogListItemViewHolder.java +++ b/java/com/android/dialer/app/calllog/CallLogListItemViewHolder.java @@ -106,6 +106,7 @@ import java.lang.ref.WeakReference; */ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, + View.OnLongClickListener, MenuItem.OnMenuItemClickListener, View.OnCreateContextMenuListener { @@ -306,6 +307,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder quickContactView.setOverlay(null); quickContactView.setPrioritizedMimeType(Phone.CONTENT_ITEM_TYPE); primaryActionButtonView.setOnClickListener(this); + primaryActionButtonView.setOnLongClickListener(this); primaryActionView.setOnClickListener(this.expandCollapseListener); if (this.voicemailPlaybackPresenter != null && ConfigProviderComponent.get(this.context) @@ -519,6 +521,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder primaryActionButtonView.setContentDescription( TextUtils.expandTemplate( context.getString(R.string.description_voicemail_action), validNameOrNumber)); + primaryActionButtonView.setTag(null); primaryActionButtonView.setVisibility(View.VISIBLE); } else { primaryActionButtonView.setVisibility(View.GONE); @@ -1053,7 +1056,8 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder return; } intentProvider.logInteraction(context); - final Intent intent = intentProvider.getIntent(context); + + final Intent intent = intentProvider.getClickIntent(context); // See IntentProvider.getCallDetailIntentProvider() for why this may be null. if (intent == null) { return; @@ -1073,6 +1077,18 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder } } + @Override + public boolean onLongClick(View view) { + final IntentProvider intentProvider = (IntentProvider) view.getTag(); + final Intent intent = intentProvider != null + ? intentProvider.getLongClickIntent(context) : null; + if (intent != null) { + DialerUtils.startActivityWithErrorToast(context, intent); + return true; + } + return false; + } + private static boolean isNonContactEntry(ContactInfo info) { if (info == null || info.sourceType != Type.SOURCE_TYPE_DIRECTORY) { return true; diff --git a/java/com/android/dialer/app/calllog/IntentProvider.java b/java/com/android/dialer/app/calllog/IntentProvider.java index 21f341815..ed6d543d6 100644 --- a/java/com/android/dialer/app/calllog/IntentProvider.java +++ b/java/com/android/dialer/app/calllog/IntentProvider.java @@ -26,6 +26,7 @@ import android.telecom.PhoneAccountHandle; import android.telephony.TelephonyManager; import com.android.contacts.common.model.Contact; import com.android.contacts.common.model.ContactLoader; +import com.android.dialer.app.AccountSelectionActivity; import com.android.dialer.calldetails.CallDetailsEntries; import com.android.dialer.calldetails.OldCallDetailsActivity; import com.android.dialer.callintent.CallInitiationType; @@ -55,12 +56,18 @@ public abstract class IntentProvider { final String number, final PhoneAccountHandle accountHandle) { return new IntentProvider() { @Override - public Intent getIntent(Context context) { + public Intent getClickIntent(Context context) { return PreCall.getIntent( context, new CallIntentBuilder(number, CallInitiationType.Type.CALL_LOG) .setPhoneAccountHandle(accountHandle)); } + + @Override + public Intent getLongClickIntent(Context context) { + return AccountSelectionActivity.createIntent(context, number, + CallInitiationType.Type.CALL_LOG); + } }; } @@ -68,12 +75,13 @@ public abstract class IntentProvider { final String number, final Context context, final TelephonyManager telephonyManager) { return new IntentProvider() { @Override - public Intent getIntent(Context context) { + public Intent getClickIntent(Context context) { return PreCall.getIntent( context, new CallIntentBuilder(number, CallInitiationType.Type.CALL_LOG) .setAllowAssistedDial(true)); } + }; } @@ -85,7 +93,7 @@ public abstract class IntentProvider { final String number, final PhoneAccountHandle accountHandle) { return new IntentProvider() { @Override - public Intent getIntent(Context context) { + public Intent getClickIntent(Context context) { return PreCall.getIntent( context, new CallIntentBuilder(number, CallInitiationType.Type.CALL_LOG) @@ -98,7 +106,7 @@ public abstract class IntentProvider { public static IntentProvider getDuoVideoIntentProvider(String number, boolean isNonContact) { return new IntentProvider() { @Override - public Intent getIntent(Context context) { + public Intent getClickIntent(Context context) { return PreCall.getIntent( context, new CallIntentBuilder(number, CallInitiationType.Type.CALL_LOG) @@ -122,7 +130,7 @@ public abstract class IntentProvider { public static IntentProvider getInstallDuoIntentProvider() { return new IntentProvider() { @Override - public Intent getIntent(Context context) { + public Intent getClickIntent(Context context) { return DuoComponent.get(context).getDuo().getInstallDuoIntent().orNull(); } @@ -136,7 +144,7 @@ public abstract class IntentProvider { public static IntentProvider getSetUpDuoIntentProvider() { return new IntentProvider() { @Override - public Intent getIntent(Context context) { + public Intent getClickIntent(Context context) { return DuoComponent.get(context).getDuo().getActivateIntent().orNull(); } @@ -150,7 +158,7 @@ public abstract class IntentProvider { public static IntentProvider getDuoInviteIntentProvider(String number) { return new IntentProvider() { @Override - public Intent getIntent(Context context) { + public Intent getClickIntent(Context context) { return DuoComponent.get(context).getDuo().getInviteIntent(number).orNull(); } @@ -165,7 +173,7 @@ public abstract class IntentProvider { @Nullable PhoneAccountHandle phoneAccountHandle) { return new IntentProvider() { @Override - public Intent getIntent(Context context) { + public Intent getClickIntent(Context context) { return PreCall.getIntent( context, CallIntentBuilder.forVoicemail(phoneAccountHandle, CallInitiationType.Type.CALL_LOG)); @@ -176,7 +184,7 @@ public abstract class IntentProvider { public static IntentProvider getSendSmsIntentProvider(final String number) { return new IntentProvider() { @Override - public Intent getIntent(Context context) { + public Intent getClickIntent(Context context) { return IntentUtil.getSendSmsIntent(number); } }; @@ -198,7 +206,7 @@ public abstract class IntentProvider { boolean canSupportAssistedDialing) { return new IntentProvider() { @Override - public Intent getIntent(Context context) { + public Intent getClickIntent(Context context) { return OldCallDetailsActivity.newInstance( context, callDetailsEntries, contact, canReportCallerId, canSupportAssistedDialing); } @@ -214,7 +222,7 @@ public abstract class IntentProvider { final boolean isNewContact) { return new IntentProvider() { @Override - public Intent getIntent(Context context) { + public Intent getClickIntent(Context context) { Contact contactToSave = null; if (lookupUri != null) { @@ -275,7 +283,9 @@ public abstract class IntentProvider { }; } - public abstract Intent getIntent(Context context); - + public abstract Intent getClickIntent(Context context); + public Intent getLongClickIntent(Context context) { + return null; + } public void logInteraction(Context context) {} } diff --git a/java/com/android/dialer/app/res/values/cm_strings.xml b/java/com/android/dialer/app/res/values/cm_strings.xml index b28dcaeb2..1e872c4a0 100644 --- a/java/com/android/dialer/app/res/values/cm_strings.xml +++ b/java/com/android/dialer/app/res/values/cm_strings.xml @@ -38,4 +38,7 @@ <string name="call_recording_format">Audio format</string> <string name="wb_amr_format" translatable="false">AMR-WB</string> <string name="aac_format" translatable="false">AAC</string> + + <string name="call_via">Call via</string> + <string name="call_via_dialog_title">Call via\u2026</string> </resources> diff --git a/java/com/android/dialer/app/res/values/styles.xml b/java/com/android/dialer/app/res/values/styles.xml index c2cad315c..0fa3503a4 100644 --- a/java/com/android/dialer/app/res/values/styles.xml +++ b/java/com/android/dialer/app/res/values/styles.xml @@ -23,6 +23,16 @@ <item name="android:textColorPrimary">?android:attr/textColorPrimaryInverse</item> </style> + <style name="TransparentTheme" parent="DialtactsTheme"> + <item name="android:alertDialogTheme">@style/AlertDialogTheme</item> + <item name="android:windowBackground">@android:color/transparent</item> + <item name="android:windowAnimationStyle">@android:style/Animation.Translucent</item> + <item name="android:windowContentOverlay">@null</item> + <item name="android:windowIsTranslucent">true</item> + <item name="android:windowNoTitle">true</item> + <item name="android:windowIsFloating">true</item> + </style> + <style name="ActionModeStyle" parent="Widget.AppCompat.ActionMode"> <item name="android:background">?android:attr/colorPrimary</item> <item name="background">?android:attr/colorPrimary</item> diff --git a/java/com/android/dialer/calldetails/CallDetailsHeaderViewHolder.java b/java/com/android/dialer/calldetails/CallDetailsHeaderViewHolder.java index f678061c8..13b03d047 100644 --- a/java/com/android/dialer/calldetails/CallDetailsHeaderViewHolder.java +++ b/java/com/android/dialer/calldetails/CallDetailsHeaderViewHolder.java @@ -17,18 +17,22 @@ package com.android.dialer.calldetails; import android.content.Context; +import android.content.Intent; import android.net.Uri; import android.support.v7.widget.RecyclerView; import android.telecom.PhoneAccount; import android.text.TextUtils; import android.view.View; import android.view.View.OnClickListener; +import android.view.View.OnLongClickListener; import android.widget.ImageView; import android.widget.QuickContactBadge; import android.widget.RelativeLayout; import android.widget.TextView; +import com.android.dialer.app.AccountSelectionActivity; import com.android.dialer.calldetails.CallDetailsActivityCommon.AssistedDialingNumberParseWorker; import com.android.dialer.calldetails.CallDetailsEntries.CallDetailsEntry; +import com.android.dialer.callintent.CallInitiationType; import com.android.dialer.calllogutils.CallbackActionHelper.CallbackAction; import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; @@ -41,6 +45,7 @@ import com.android.dialer.glidephotomanager.GlidePhotoManagerComponent; import com.android.dialer.logging.InteractionEvent; import com.android.dialer.logging.Logger; import com.android.dialer.phonenumberutil.PhoneNumberHelper; +import com.android.dialer.util.DialerUtils; import com.android.dialer.widget.BidiTextView; /** @@ -49,7 +54,7 @@ import com.android.dialer.widget.BidiTextView; * <p>The header contains contact info and the primary callback button. */ public class CallDetailsHeaderViewHolder extends RecyclerView.ViewHolder - implements OnClickListener, FailureListener { + implements OnClickListener, OnLongClickListener, FailureListener { private final CallDetailsHeaderListener callDetailsHeaderListener; private final ImageView callbackButton; @@ -86,6 +91,7 @@ public class CallDetailsHeaderViewHolder extends RecyclerView.ViewHolder callDetailsHeaderListener::openAssistedDialingSettings); callbackButton.setOnClickListener(this); + callbackButton.setOnLongClickListener(this); this.number = number; this.postDialDigits = postDialDigits; @@ -250,6 +256,19 @@ public class CallDetailsHeaderViewHolder extends RecyclerView.ViewHolder } } + @Override + public boolean onLongClick(View view) { + if (view == callbackButton) { + Intent intent = AccountSelectionActivity.createIntent(view.getContext(), + number, CallInitiationType.Type.CALL_DETAILS); + if (intent != null) { + DialerUtils.startActivityWithErrorToast(view.getContext(), intent); + return true; + } + } + return false; + } + /** Listener for the call details header */ interface CallDetailsHeaderListener { diff --git a/java/com/android/dialer/dialpadview/DialpadFragment.java b/java/com/android/dialer/dialpadview/DialpadFragment.java index 2d0eff543..cc16658e6 100644 --- a/java/com/android/dialer/dialpadview/DialpadFragment.java +++ b/java/com/android/dialer/dialpadview/DialpadFragment.java @@ -50,6 +50,7 @@ import android.support.annotation.VisibleForTesting; import android.support.design.widget.FloatingActionButton; import android.telecom.PhoneAccount; import android.telecom.PhoneAccountHandle; +import android.telecom.TelecomManager; import android.telephony.PhoneNumberFormattingTextWatcher; import android.telephony.PhoneNumberUtils; import android.telephony.ServiceState; @@ -64,6 +65,7 @@ import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; +import android.view.SubMenu; import android.view.View; import android.view.ViewGroup; import android.view.animation.Animation; @@ -204,6 +206,8 @@ public class DialpadFragment extends Fragment private boolean isLayoutRtl; private boolean isLandscape; + private PhoneAccountHandle selectedAccount; + private DialerExecutor<String> initPhoneNumberFormattingTextWatcherExecutor; private boolean isDialpadSlideUp; @@ -1021,6 +1025,37 @@ public class DialpadFragment extends Fragment item.setVisible(CallUtil.isCallWithSubjectSupported(getContext())); } } + + final MenuItem callWithItem = menu.findItem(R.id.call_with); + List<PhoneAccount> accounts = + CallUtil.getCallCapablePhoneAccounts(getContext(), PhoneAccount.SCHEME_TEL); + if (accounts != null && accounts.size() > 1) { + final PhoneAccountHandle selected; + if (selectedAccount != null) { + selected = selectedAccount; + } else { + selected = TelecomUtil.getDefaultOutgoingPhoneAccount(getContext(), + PhoneAccount.SCHEME_TEL); + } + + SubMenu callWithMenu = callWithItem.getSubMenu(); + callWithMenu.clear(); + + for (PhoneAccount account : accounts) { + final PhoneAccountHandle handle = account.getAccountHandle(); + final Intent intent = new Intent() + .putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, handle); + + callWithMenu.add(Menu.FIRST, Menu.NONE, Menu.NONE, account.getLabel()) + .setIntent(intent) + .setChecked(handle.equals(selected)); + } + callWithMenu.setGroupCheckable(Menu.FIRST, true, true); + callWithItem.setVisible(callWithMenu.hasVisibleItems()); + } else { + callWithItem.setVisible(false); + } + super.show(); } }; @@ -1186,7 +1221,9 @@ public class DialpadFragment extends Fragment // Clear the digits just in case. clearDialpad(); } else { - PreCall.start(getContext(), new CallIntentBuilder(number, CallInitiationType.Type.DIALPAD)); + CallIntentBuilder builder = new CallIntentBuilder(number, CallInitiationType.Type.DIALPAD) + .setPhoneAccountHandle(selectedAccount); + PreCall.start(getContext(), builder); hideAndClearDialpad(); } } @@ -1196,6 +1233,7 @@ public class DialpadFragment extends Fragment if (digits != null) { digits.getText().clear(); } + selectedAccount = null; } private void handleDialButtonClickWithEmptyDigits() { @@ -1420,6 +1458,11 @@ public class DialpadFragment extends Fragment @Override public boolean onMenuItemClick(MenuItem item) { + if (item.getGroupId() == Menu.FIRST) { + Intent intent = item.getIntent(); + selectedAccount = intent.getParcelableExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE); + return true; + } int resId = item.getItemId(); if (resId == R.id.menu_2s_pause) { updateDialString(PAUSE); diff --git a/java/com/android/dialer/dialpadview/res/menu/dialpad_options.xml b/java/com/android/dialer/dialpadview/res/menu/dialpad_options.xml index 2921ea3bb..760a004b4 100644 --- a/java/com/android/dialer/dialpadview/res/menu/dialpad_options.xml +++ b/java/com/android/dialer/dialpadview/res/menu/dialpad_options.xml @@ -14,7 +14,11 @@ limitations under the License. --> <menu xmlns:android="http://schemas.android.com/apk/res/android"> - + <item + android:id="@+id/call_with" + android:title="@string/call_via"> + <menu /> + </item> <item android:id="@+id/menu_2s_pause" android:showAsAction="withText" diff --git a/java/com/android/dialer/main/impl/OldMainActivityPeer.java b/java/com/android/dialer/main/impl/OldMainActivityPeer.java index feb76acd7..a1afc6164 100644 --- a/java/com/android/dialer/main/impl/OldMainActivityPeer.java +++ b/java/com/android/dialer/main/impl/OldMainActivityPeer.java @@ -639,7 +639,7 @@ public class OldMainActivityPeer implements MainActivityPeer, FragmentUtilListen R.string.view_conversation, v -> activity.startActivity( - IntentProvider.getSendSmsIntentProvider(number).getIntent(activity))) + IntentProvider.getSendSmsIntentProvider(number).getClickIntent(activity))) .setActionTextColor( ContextCompat.getColor(activity, R.color.dialer_snackbar_action_text_color)) .show(); diff --git a/java/com/android/dialer/util/CallUtil.java b/java/com/android/dialer/util/CallUtil.java index 89af0b9bb..160a40fd8 100644 --- a/java/com/android/dialer/util/CallUtil.java +++ b/java/com/android/dialer/util/CallUtil.java @@ -24,6 +24,8 @@ import android.telecom.PhoneAccountHandle; import android.telecom.TelecomManager; import com.android.dialer.common.LogUtil; import com.android.dialer.phonenumberutil.PhoneNumberHelper; + +import java.util.ArrayList; import java.util.List; /** Utilities related to calls that can be used by non system apps. */ @@ -89,6 +91,25 @@ public class CallUtil { } /** + * Returns a list of phone accounts that are able to call to numbers with the supplied scheme + */ + public static List<PhoneAccount> getCallCapablePhoneAccounts(Context context, String scheme) { + if (!PermissionsUtil.hasPermission(context, android.Manifest.permission.READ_PHONE_STATE)) { + return null; + } + TelecomManager tm = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); + final ArrayList<PhoneAccount> accounts = new ArrayList<>(); + + for (PhoneAccountHandle handle : tm.getCallCapablePhoneAccounts()) { + final PhoneAccount account = tm.getPhoneAccount(handle); + if (account != null && account.supportsUriScheme(scheme)) { + accounts.add(account); + } + } + return accounts; + } + + /** * Determines if one of the call capable phone accounts defined supports video calling. * * @param context The context. |