diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2017-11-23 00:47:24 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-11-23 00:47:24 +0000 |
commit | 6c773cbf112e5bef6074776d8cd91139d810f0ec (patch) | |
tree | 864af958509967249c92a2c0196a51ed66482574 /java/com/android/dialer/precall/impl/CallingAccountSelector.java | |
parent | ecbcc5c8cce01c70480e73284a9e5e1115fc6649 (diff) | |
parent | 572a77ed339b5a511f9dc20680939dbb7bf5e085 (diff) |
Merge changes I50da0d2d,Id00debe2,I2807510e,I3f7836d8,I2e31cd11, ...
* changes:
Automated rollback of changelist 176587256
Check Contacts support for preferred SIM
Add SpamJobType for all spam job IDs.
Bubble v2 UI changes.
Allow deleting a call log entry in the call log UI and the call details UI.
Fix showing CallingAccountSelector in lock screen
Diffstat (limited to 'java/com/android/dialer/precall/impl/CallingAccountSelector.java')
-rw-r--r-- | java/com/android/dialer/precall/impl/CallingAccountSelector.java | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/java/com/android/dialer/precall/impl/CallingAccountSelector.java b/java/com/android/dialer/precall/impl/CallingAccountSelector.java index 144d94e20..4308df73a 100644 --- a/java/com/android/dialer/precall/impl/CallingAccountSelector.java +++ b/java/com/android/dialer/precall/impl/CallingAccountSelector.java @@ -20,11 +20,16 @@ import android.app.Activity; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; import android.database.Cursor; import android.net.Uri; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; +import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.PhoneLookup; +import android.provider.ContactsContract.QuickContact; import android.support.annotation.MainThread; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -60,6 +65,9 @@ public class CallingAccountSelector implements PreCallAction { @VisibleForTesting static final String TAG_CALLING_ACCOUNT_SELECTOR = "CallingAccountSelector"; + @VisibleForTesting + static final String METADATA_SUPPORTS_PREFERRED_SIM = "supports_per_number_preferred_account"; + private SelectPhoneAccountDialogFragment selectPhoneAccountDialogFragment; private boolean isDiscarding; @@ -244,6 +252,9 @@ public class CallingAccountSelector implements PreCallAction { @WorkerThread public PreferredAccountWorkerResult doInBackground(Context context) throws Throwable { PreferredAccountWorkerResult result = new PreferredAccountWorkerResult(); + if (!isPreferredSimEnabled(context)) { + return result; + } result.dataId = getDataId(context.getContentResolver(), phoneNumber); if (result.dataId.isPresent()) { result.phoneAccountHandle = getPreferredAccount(context, result.dataId.get()); @@ -431,4 +442,41 @@ public class CallingAccountSelector implements PreCallAction { return null; } } + + @WorkerThread + private static boolean isPreferredSimEnabled(Context context) { + Assert.isWorkerThread(); + if (!ConfigProviderBindings.get(context).getBoolean("preferred_sim_enabled", true)) { + return false; + } + + Intent quickContactIntent = getQuickContactIntent(); + ResolveInfo resolveInfo = + context + .getPackageManager() + .resolveActivity(quickContactIntent, PackageManager.GET_META_DATA); + if (resolveInfo == null + || resolveInfo.activityInfo == null + || resolveInfo.activityInfo.applicationInfo == null + || resolveInfo.activityInfo.applicationInfo.metaData == null) { + LogUtil.e("CallingAccountSelector.isPreferredSimEnabled", "cannot resolve quick contact app"); + return false; + } + if (!resolveInfo.activityInfo.applicationInfo.metaData.getBoolean( + METADATA_SUPPORTS_PREFERRED_SIM, false)) { + LogUtil.i( + "CallingAccountSelector.isPreferredSimEnabled", + "system contacts does not support preferred SIM"); + return false; + } + return true; + } + + @VisibleForTesting + static Intent getQuickContactIntent() { + Intent intent = new Intent(QuickContact.ACTION_QUICK_CONTACT); + intent.addCategory(Intent.CATEGORY_DEFAULT); + intent.setData(Contacts.CONTENT_URI.buildUpon().appendPath("1").build()); + return intent; + } } |