summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/precall
diff options
context:
space:
mode:
authortwyen <twyen@google.com>2017-11-22 12:16:10 -0800
committerCopybara-Service <copybara-piper@google.com>2017-11-22 16:28:34 -0800
commite30d7d2e533f830ee638b1a727e537880b18bf66 (patch)
treec02c168cec99e036dc54d82b9ac93acb1dfb66a5 /java/com/android/dialer/precall
parentd754ea24e5fd722860aeab6391af397b07b8115d (diff)
Check Contacts support for preferred SIM
Preferred SIM can only be enabled when both dialer and the system contact app supports it. This CL checks if the app for ACTION_QUICK_CONTACT has the metadata supports_per_number_preferred_account. Also added a flag to disable the whole preferred SIM feature. Bug: 69638458 Test: CallingAccountSelectorTest PiperOrigin-RevId: 176687062 Change-Id: Id00debe2393068a422907a9eff2ac4ef0fcf6f8e
Diffstat (limited to 'java/com/android/dialer/precall')
-rw-r--r--java/com/android/dialer/precall/impl/CallingAccountSelector.java48
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 4d2e6063a..8d3df2360 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;
@@ -246,6 +254,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());
@@ -435,4 +446,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;
+ }
}