diff options
author | Yorke Lee <yorkelee@google.com> | 2015-05-07 17:34:53 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-05-07 17:34:54 +0000 |
commit | e0895660dac3fc87665d2cf7b0ca6906ab89cec1 (patch) | |
tree | 142e98953c4c4eac1842cc4268992bb38bddbd87 /telecomm | |
parent | f555887237665fd2cd16182e63dd7ff5f4b7e708 (diff) | |
parent | 856a5ac70474e9f57f71699ad934c701b01c1c7b (diff) | |
download | frameworks_base-e0895660dac3fc87665d2cf7b0ca6906ab89cec1.zip frameworks_base-e0895660dac3fc87665d2cf7b0ca6906ab89cec1.tar.gz frameworks_base-e0895660dac3fc87665d2cf7b0ca6906ab89cec1.tar.bz2 |
Merge "Filter list of possible default dialers" into mnc-dev
Diffstat (limited to 'telecomm')
-rw-r--r-- | telecomm/java/android/telecom/DefaultDialerManager.java | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/telecomm/java/android/telecom/DefaultDialerManager.java b/telecomm/java/android/telecom/DefaultDialerManager.java index fd0c06d..d3df151 100644 --- a/telecomm/java/android/telecom/DefaultDialerManager.java +++ b/telecomm/java/android/telecom/DefaultDialerManager.java @@ -20,6 +20,7 @@ import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; +import android.net.Uri; import android.provider.Settings; import android.text.TextUtils; @@ -151,14 +152,14 @@ public class DefaultDialerManager { for (ResolveInfo resolveInfo : resolveInfoList) { final ActivityInfo activityInfo = resolveInfo.activityInfo; - if (activityInfo == null) { - continue; + if (activityInfo != null && !packageNames.contains(activityInfo.packageName)) { + packageNames.add(activityInfo.packageName); } - packageNames.add(activityInfo.packageName); } - // TODO: Filter for apps that don't handle DIAL intent with tel scheme - return packageNames; + final Intent dialIntentWithTelScheme = new Intent(Intent.ACTION_DIAL); + dialIntentWithTelScheme.setData(Uri.fromParts(PhoneAccount.SCHEME_TEL, "", null)); + return filterByIntent(context, packageNames, dialIntentWithTelScheme); } /** @@ -182,6 +183,36 @@ public class DefaultDialerManager { || packageName.equals(tm.getSystemDialerPackage()); } + /** + * Filter a given list of package names for those packages that contain an activity that has + * an intent filter for a given intent. + * + * @param context A valid context + * @param packageNames List of package names to filter. + * @return The filtered list. + */ + private static List<String> filterByIntent(Context context, List<String> packageNames, + Intent intent) { + if (packageNames == null || packageNames.isEmpty()) { + return new ArrayList<>(); + } + + final List<String> result = new ArrayList<>(); + final List<ResolveInfo> resolveInfoList = + context.getPackageManager().queryIntentActivities(intent, 0); + final int length = resolveInfoList.size(); + for (int i = 0; i < length; i++) { + final ActivityInfo info = resolveInfoList.get(i).activityInfo; + if (info != null && packageNames.contains(info.packageName) + && !result.contains(info.packageName)) { + result.add(info.packageName); + } + } + + return result; + } + + private static TelecomManager getTelecomManager(Context context) { return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); } |