diff options
15 files changed, 66 insertions, 58 deletions
diff --git a/java/com/android/dialer/app/calllog/CallLogAdapter.java b/java/com/android/dialer/app/calllog/CallLogAdapter.java index 963967ffc..9e1d4a7b9 100644 --- a/java/com/android/dialer/app/calllog/CallLogAdapter.java +++ b/java/com/android/dialer/app/calllog/CallLogAdapter.java @@ -66,7 +66,6 @@ import com.android.dialer.calldetails.CallDetailsEntries; import com.android.dialer.calldetails.CallDetailsEntries.CallDetailsEntry; import com.android.dialer.callintent.CallIntentBuilder; import com.android.dialer.calllogutils.CallbackActionHelper.CallbackAction; -import com.android.dialer.calllogutils.PhoneAccountUtils; import com.android.dialer.calllogutils.PhoneCallDetails; import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; @@ -91,6 +90,7 @@ import com.android.dialer.phonenumbercache.ContactInfo; import com.android.dialer.phonenumbercache.ContactInfoHelper; import com.android.dialer.phonenumberutil.PhoneNumberHelper; import com.android.dialer.spam.SpamComponent; +import com.android.dialer.telecom.TelecomUtil; import com.android.dialer.util.PermissionsUtil; import java.util.ArrayList; import java.util.Map; @@ -1020,7 +1020,7 @@ public class CallLogAdapter extends GroupingListAdapter } final PhoneAccountHandle accountHandle = - PhoneAccountUtils.getAccount(details.accountComponentName, details.accountId); + TelecomUtil.composePhoneAccountHandle(details.accountComponentName, details.accountId); final boolean isVoicemailNumber = callLogCache.isVoicemailNumber(accountHandle, details.number); diff --git a/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java b/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java index a0bbfa0f1..0ddfb9f3b 100644 --- a/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java +++ b/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java @@ -31,11 +31,11 @@ import android.telephony.PhoneNumberUtils; import android.telephony.TelephonyManager; import android.text.TextUtils; import com.android.dialer.app.R; -import com.android.dialer.calllogutils.PhoneAccountUtils; import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; import com.android.dialer.notification.DialerNotificationManager; import com.android.dialer.notification.NotificationChannelManager; +import com.android.dialer.telecom.TelecomUtil; /** Shows a notification in the status bar for legacy vociemail. */ @TargetApi(VERSION_CODES.O) @@ -137,7 +137,7 @@ public final class LegacyVoicemailNotifier { @NonNull private static String getNotificationText( @NonNull Context context, PhoneAccountHandle handle, String voicemailNumber) { - if (PhoneAccountUtils.getSubscriptionPhoneAccounts(context).size() > 1) { + if (TelecomUtil.getCallCapablePhoneAccounts(context).size() > 1) { TelecomManager telecomManager = context.getSystemService(TelecomManager.class); PhoneAccount phoneAccount = telecomManager.getPhoneAccount(handle); return phoneAccount.getShortDescription().toString(); diff --git a/java/com/android/dialer/calllog/database/Coalescer.java b/java/com/android/dialer/calllog/database/Coalescer.java index b10dea24a..e301c9f72 100644 --- a/java/com/android/dialer/calllog/database/Coalescer.java +++ b/java/com/android/dialer/calllog/database/Coalescer.java @@ -27,10 +27,10 @@ import com.android.dialer.calllog.database.contract.AnnotatedCallLogContract.Ann import com.android.dialer.calllog.database.contract.AnnotatedCallLogContract.CoalescedAnnotatedCallLog; import com.android.dialer.calllog.datasources.CallLogDataSource; import com.android.dialer.calllog.datasources.DataSources; -import com.android.dialer.calllogutils.PhoneAccountUtils; import com.android.dialer.common.Assert; import com.android.dialer.compat.telephony.TelephonyManagerCompat; import com.android.dialer.phonenumberproto.DialerPhoneNumberUtil; +import com.android.dialer.telecom.TelecomUtil; import com.google.common.base.Preconditions; import com.google.i18n.phonenumbers.PhoneNumberUtil; import com.google.protobuf.InvalidProtocolBufferException; @@ -144,11 +144,11 @@ public class Coalescer { DialerPhoneNumberUtil dialerPhoneNumberUtil, ContentValues row1, ContentValues row2) { // Don't combine rows which don't use the same phone account. PhoneAccountHandle phoneAccount1 = - PhoneAccountUtils.getAccount( + TelecomUtil.composePhoneAccountHandle( row1.getAsString(AnnotatedCallLog.PHONE_ACCOUNT_COMPONENT_NAME), row1.getAsString(AnnotatedCallLog.PHONE_ACCOUNT_ID)); PhoneAccountHandle phoneAccount2 = - PhoneAccountUtils.getAccount( + TelecomUtil.composePhoneAccountHandle( row2.getAsString(AnnotatedCallLog.PHONE_ACCOUNT_COMPONENT_NAME), row2.getAsString(AnnotatedCallLog.PHONE_ACCOUNT_ID)); diff --git a/java/com/android/dialer/calllog/datasources/systemcalllog/SystemCallLogDataSource.java b/java/com/android/dialer/calllog/datasources/systemcalllog/SystemCallLogDataSource.java index 14cde46dd..93c35c5fa 100644 --- a/java/com/android/dialer/calllog/datasources/systemcalllog/SystemCallLogDataSource.java +++ b/java/com/android/dialer/calllog/datasources/systemcalllog/SystemCallLogDataSource.java @@ -51,6 +51,7 @@ import com.android.dialer.common.concurrent.Annotations.BackgroundExecutor; import com.android.dialer.common.concurrent.ThreadUtil; import com.android.dialer.phonenumberproto.DialerPhoneNumberUtil; import com.android.dialer.storage.StorageComponent; +import com.android.dialer.telecom.TelecomUtil; import com.android.dialer.theme.R; import com.android.dialer.util.PermissionsUtil; import com.google.common.collect.Iterables; @@ -363,7 +364,7 @@ public class SystemCallLogDataSource implements CallLogDataSource { String phoneAccountComponentName, String phoneAccountId) { PhoneAccountHandle phoneAccountHandle = - PhoneAccountUtils.getAccount(phoneAccountComponentName, phoneAccountId); + TelecomUtil.composePhoneAccountHandle(phoneAccountComponentName, phoneAccountId); if (phoneAccountHandle == null) { return; } diff --git a/java/com/android/dialer/calllog/ui/menu/Modules.java b/java/com/android/dialer/calllog/ui/menu/Modules.java index 67e51689d..beb2cf0db 100644 --- a/java/com/android/dialer/calllog/ui/menu/Modules.java +++ b/java/com/android/dialer/calllog/ui/menu/Modules.java @@ -24,12 +24,12 @@ import com.android.dialer.calldetails.CallDetailsActivity; import com.android.dialer.callintent.CallInitiationType; import com.android.dialer.calllog.model.CoalescedRow; import com.android.dialer.calllogutils.CallLogContactTypes; -import com.android.dialer.calllogutils.PhoneAccountUtils; import com.android.dialer.contactactions.ContactActionModule; import com.android.dialer.contactactions.DividerModule; import com.android.dialer.contactactions.IntentModule; import com.android.dialer.contactactions.SharedModules; import com.android.dialer.dialercontact.DialerContact; +import com.android.dialer.telecom.TelecomUtil; import java.util.ArrayList; import java.util.List; @@ -82,7 +82,8 @@ final class Modules { } PhoneAccountHandle phoneAccountHandle = - PhoneAccountUtils.getAccount(row.phoneAccountComponentName(), row.phoneAccountId()); + TelecomUtil.composePhoneAccountHandle( + row.phoneAccountComponentName(), row.phoneAccountId()); if ((row.features() & Calls.FEATURES_VIDEO) == Calls.FEATURES_VIDEO) { // Add an audio call item for video calls. Clicking the top entry on the bottom sheet will diff --git a/java/com/android/dialer/calllogutils/CallLogIntents.java b/java/com/android/dialer/calllogutils/CallLogIntents.java index b06fe6e93..05af8bfc7 100644 --- a/java/com/android/dialer/calllogutils/CallLogIntents.java +++ b/java/com/android/dialer/calllogutils/CallLogIntents.java @@ -24,6 +24,7 @@ import com.android.dialer.callintent.CallInitiationType; import com.android.dialer.callintent.CallIntentBuilder; import com.android.dialer.calllog.model.CoalescedRow; import com.android.dialer.precall.PreCall; +import com.android.dialer.telecom.TelecomUtil; /** Provides intents related to call log entries. */ public final class CallLogIntents { @@ -51,7 +52,8 @@ public final class CallLogIntents { context, new CallIntentBuilder(originalNumber, CallInitiationType.Type.CALL_LOG) .setPhoneAccountHandle( - PhoneAccountUtils.getAccount(row.phoneAccountComponentName(), row.phoneAccountId())) + TelecomUtil.composePhoneAccountHandle( + row.phoneAccountComponentName(), row.phoneAccountId())) .setIsVideoCall((row.features() & Calls.FEATURES_VIDEO) == Calls.FEATURES_VIDEO)); } } diff --git a/java/com/android/dialer/calllogutils/PhoneAccountUtils.java b/java/com/android/dialer/calllogutils/PhoneAccountUtils.java index 153f29185..2ee50a134 100644 --- a/java/com/android/dialer/calllogutils/PhoneAccountUtils.java +++ b/java/com/android/dialer/calllogutils/PhoneAccountUtils.java @@ -16,47 +16,15 @@ package com.android.dialer.calllogutils; -import android.content.ComponentName; import android.content.Context; import android.support.annotation.Nullable; import android.telecom.PhoneAccount; import android.telecom.PhoneAccountHandle; -import android.text.TextUtils; import com.android.dialer.telecom.TelecomUtil; -import java.util.ArrayList; -import java.util.List; /** Methods to help extract {@code PhoneAccount} information from database and Telecomm sources. */ public class PhoneAccountUtils { - /** Return a list of phone accounts that are subscription/SIM accounts. */ - public static List<PhoneAccountHandle> getSubscriptionPhoneAccounts(Context context) { - List<PhoneAccountHandle> subscriptionAccountHandles = new ArrayList<>(); - 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; - } - - /** Compose PhoneAccount object from component name and account id. */ - @Nullable - public static PhoneAccountHandle getAccount( - @Nullable String componentString, @Nullable String accountId) { - if (TextUtils.isEmpty(componentString) || TextUtils.isEmpty(accountId)) { - return null; - } - final ComponentName componentName = ComponentName.unflattenFromString(componentString); - if (componentName == null) { - return null; - } - return new PhoneAccountHandle(componentName, accountId); - } - /** Extract account label from PhoneAccount object. */ @Nullable public static String getAccountLabel( diff --git a/java/com/android/dialer/dialpadview/DialpadFragment.java b/java/com/android/dialer/dialpadview/DialpadFragment.java index 9cee7bc2f..6b8401e6b 100644 --- a/java/com/android/dialer/dialpadview/DialpadFragment.java +++ b/java/com/android/dialer/dialpadview/DialpadFragment.java @@ -77,7 +77,6 @@ import com.android.contacts.common.util.StopWatch; import com.android.dialer.animation.AnimUtils; import com.android.dialer.callintent.CallInitiationType; import com.android.dialer.callintent.CallIntentBuilder; -import com.android.dialer.calllogutils.PhoneAccountUtils; import com.android.dialer.common.Assert; import com.android.dialer.common.FragmentUtils; import com.android.dialer.common.LogUtil; @@ -967,7 +966,7 @@ public class DialpadFragment extends Fragment removePreviousDigitIfPossible('1'); List<PhoneAccountHandle> subscriptionAccountHandles = - PhoneAccountUtils.getSubscriptionPhoneAccounts(getActivity()); + TelecomUtil.getSubscriptionPhoneAccounts(getActivity()); boolean hasUserSelectedDefault = subscriptionAccountHandles.contains( TelecomUtil.getDefaultOutgoingPhoneAccount( diff --git a/java/com/android/dialer/dialpadview/SpecialCharSequenceMgr.java b/java/com/android/dialer/dialpadview/SpecialCharSequenceMgr.java index 76892552b..2e4caa920 100644 --- a/java/com/android/dialer/dialpadview/SpecialCharSequenceMgr.java +++ b/java/com/android/dialer/dialpadview/SpecialCharSequenceMgr.java @@ -44,7 +44,6 @@ import com.android.contacts.common.database.NoNullCursorAsyncQueryHandler; import com.android.contacts.common.util.ContactDisplayUtils; import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment; import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment.SelectPhoneAccountListener; -import com.android.dialer.calllogutils.PhoneAccountUtils; import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; import com.android.dialer.compat.telephony.TelephonyManagerCompat; @@ -215,7 +214,7 @@ public class SpecialCharSequenceMgr { sc.progressDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND); List<PhoneAccountHandle> subscriptionAccountHandles = - PhoneAccountUtils.getSubscriptionPhoneAccounts(context); + TelecomUtil.getSubscriptionPhoneAccounts(context); Context applicationContext = context.getApplicationContext(); boolean hasUserSelectedDefault = subscriptionAccountHandles.contains( @@ -272,7 +271,7 @@ public class SpecialCharSequenceMgr { static boolean handlePinEntry(final Context context, final String input) { if ((input.startsWith("**04") || input.startsWith("**05")) && input.endsWith("#")) { List<PhoneAccountHandle> subscriptionAccountHandles = - PhoneAccountUtils.getSubscriptionPhoneAccounts(context); + TelecomUtil.getSubscriptionPhoneAccounts(context); boolean hasUserSelectedDefault = subscriptionAccountHandles.contains( TelecomUtil.getDefaultOutgoingPhoneAccount(context, PhoneAccount.SCHEME_TEL)); diff --git a/java/com/android/dialer/precall/impl/CallingAccountSelector.java b/java/com/android/dialer/precall/impl/CallingAccountSelector.java index 9397d1848..d5ee0f278 100644 --- a/java/com/android/dialer/precall/impl/CallingAccountSelector.java +++ b/java/com/android/dialer/precall/impl/CallingAccountSelector.java @@ -56,6 +56,7 @@ import com.android.dialer.logging.Logger; import com.android.dialer.precall.PreCallAction; import com.android.dialer.precall.PreCallCoordinator; import com.android.dialer.precall.PreCallCoordinator.PendingAction; +import com.android.dialer.preferredsim.PreferredAccountUtil; import com.android.dialer.preferredsim.PreferredSimFallbackContract; import com.android.dialer.preferredsim.PreferredSimFallbackContract.PreferredSim; import com.android.dialer.preferredsim.suggestion.SimSuggestionComponent; @@ -483,7 +484,8 @@ public class CallingAccountSelector implements PreCallAction { if (number != null) { DialerExecutorComponent.get(coordinator.getActivity()) .dialerExecutorFactory() - .createNonUiTaskBuilder(new UserSelectionReporter(selectedAccountHandle, number)) + .createNonUiTaskBuilder( + new UserSelectionReporter(selectedAccountHandle, number, setDefault)) .build() .executeParallel(coordinator.getActivity()); } @@ -505,11 +507,13 @@ public class CallingAccountSelector implements PreCallAction { private final String number; private final PhoneAccountHandle phoneAccountHandle; + private final boolean remember; public UserSelectionReporter( - @NonNull PhoneAccountHandle phoneAccountHandle, @Nullable String number) { + @NonNull PhoneAccountHandle phoneAccountHandle, @Nullable String number, boolean remember) { this.phoneAccountHandle = Assert.isNotNull(phoneAccountHandle); this.number = Assert.isNotNull(number); + this.remember = remember; } @Nullable @@ -517,7 +521,7 @@ public class CallingAccountSelector implements PreCallAction { public Void doInBackground(@NonNull Context context) throws Throwable { SimSuggestionComponent.get(context) .getSuggestionProvider() - .reportUserSelection(context, number, phoneAccountHandle); + .reportUserSelection(context, number, phoneAccountHandle, remember); return null; } } diff --git a/java/com/android/dialer/precall/impl/PreferredAccountUtil.java b/java/com/android/dialer/preferredsim/PreferredAccountUtil.java index 650588829..1cfdbb161 100644 --- a/java/com/android/dialer/precall/impl/PreferredAccountUtil.java +++ b/java/com/android/dialer/preferredsim/PreferredAccountUtil.java @@ -14,7 +14,7 @@ * limitations under the License */ -package com.android.dialer.precall.impl; +package com.android.dialer.preferredsim; import android.content.ComponentName; import android.content.Context; @@ -64,7 +64,7 @@ public class PreferredAccountUtil { return Optional.absent(); } - private static boolean isPhoneAccountValid( + public static boolean isPhoneAccountValid( Context context, PhoneAccountHandle phoneAccountHandle) { if (VERSION.SDK_INT >= VERSION_CODES.O) { return context diff --git a/java/com/android/dialer/preferredsim/suggestion/SuggestionProvider.java b/java/com/android/dialer/preferredsim/suggestion/SuggestionProvider.java index c1114b3f3..bb50889ec 100644 --- a/java/com/android/dialer/preferredsim/suggestion/SuggestionProvider.java +++ b/java/com/android/dialer/preferredsim/suggestion/SuggestionProvider.java @@ -62,8 +62,10 @@ public interface SuggestionProvider { void reportUserSelection( @NonNull Context context, @NonNull String number, - @NonNull PhoneAccountHandle phoneAccountHandle); + @NonNull PhoneAccountHandle phoneAccountHandle, + boolean rememberSelection); @WorkerThread - void reportIncorrectSuggestion(@NonNull Context context, @NonNull String number); + void reportIncorrectSuggestion( + @NonNull Context context, @NonNull String number, @NonNull PhoneAccountHandle newAccount); } diff --git a/java/com/android/dialer/preferredsim/suggestion/stub/StubSuggestionProvider.java b/java/com/android/dialer/preferredsim/suggestion/stub/StubSuggestionProvider.java index 6fb73ac5d..bd54ddb3a 100644 --- a/java/com/android/dialer/preferredsim/suggestion/stub/StubSuggestionProvider.java +++ b/java/com/android/dialer/preferredsim/suggestion/stub/StubSuggestionProvider.java @@ -40,8 +40,10 @@ public class StubSuggestionProvider implements SuggestionProvider { public void reportUserSelection( @NonNull Context context, @NonNull String number, - @NonNull PhoneAccountHandle phoneAccountHandle) {} + @NonNull PhoneAccountHandle phoneAccountHandle, + boolean rememberSelection) {} @Override - public void reportIncorrectSuggestion(@NonNull Context context, @NonNull String number) {} + public void reportIncorrectSuggestion( + @NonNull Context context, @NonNull String number, PhoneAccountHandle newAccount) {} } diff --git a/java/com/android/dialer/telecom/TelecomUtil.java b/java/com/android/dialer/telecom/TelecomUtil.java index f79ca8607..56349b651 100644 --- a/java/com/android/dialer/telecom/TelecomUtil.java +++ b/java/com/android/dialer/telecom/TelecomUtil.java @@ -18,6 +18,7 @@ package com.android.dialer.telecom; import android.Manifest; import android.Manifest.permission; +import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; @@ -49,6 +50,7 @@ import java.util.concurrent.ConcurrentHashMap; * perform the required check and return the fallback default if the permission is missing, * otherwise return the value from TelecomManager. */ +@SuppressWarnings("MissingPermission") public abstract class TelecomUtil { private static final String TAG = "TelecomUtil"; @@ -148,6 +150,34 @@ public abstract class TelecomUtil { return new ArrayList<>(); } + /** Return a list of phone accounts that are subscription/SIM accounts. */ + public static List<PhoneAccountHandle> getSubscriptionPhoneAccounts(Context context) { + List<PhoneAccountHandle> subscriptionAccountHandles = new ArrayList<>(); + 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; + } + + /** Compose {@link PhoneAccountHandle} object from component name and account id. */ + @Nullable + public static PhoneAccountHandle composePhoneAccountHandle( + @Nullable String componentString, @Nullable String accountId) { + if (TextUtils.isEmpty(componentString) || TextUtils.isEmpty(accountId)) { + return null; + } + final ComponentName componentName = ComponentName.unflattenFromString(componentString); + if (componentName == null) { + return null; + } + return new PhoneAccountHandle(componentName, accountId); + } + /** * @return the {@link SubscriptionInfo} of the SIM if {@code phoneAccountHandle} corresponds to a * valid SIM. Absent otherwise. diff --git a/java/com/android/incallui/multisim/SwapSimWorker.java b/java/com/android/incallui/multisim/SwapSimWorker.java index 28cf293b0..1014d824a 100644 --- a/java/com/android/incallui/multisim/SwapSimWorker.java +++ b/java/com/android/incallui/multisim/SwapSimWorker.java @@ -102,7 +102,7 @@ public class SwapSimWorker implements Worker<Void, Void>, DialerCallListener, Ca try { SimSuggestionComponent.get(context) .getSuggestionProvider() - .reportIncorrectSuggestion(context, number); + .reportIncorrectSuggestion(context, number, otherAccount); if (!PermissionsUtil.hasPhonePermissions(context)) { LogUtil.e("SwapSimWorker.doInBackground", "missing phone permission"); |