diff options
author | Yorke Lee <yorkelee@google.com> | 2015-04-28 18:57:45 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-04-28 18:57:46 +0000 |
commit | b7018ba66046097d81c8d3b48e58e6d8aeab893a (patch) | |
tree | 1565c12b7c90945eff855f9c482971098b6ef864 /telecomm/java/android | |
parent | c8240411c38b78ac8095f6e8067f7bcc7046f502 (diff) | |
parent | 8e0207ba5b7ca3bca9d87847eef4d00aa89d7a7a (diff) | |
download | frameworks_base-b7018ba66046097d81c8d3b48e58e6d8aeab893a.zip frameworks_base-b7018ba66046097d81c8d3b48e58e6d8aeab893a.tar.gz frameworks_base-b7018ba66046097d81c8d3b48e58e6d8aeab893a.tar.bz2 |
Merge "Simplify DefaultDialerManager" into mnc-dev
Diffstat (limited to 'telecomm/java/android')
-rw-r--r-- | telecomm/java/android/telecom/DefaultDialerManager.java | 80 |
1 files changed, 21 insertions, 59 deletions
diff --git a/telecomm/java/android/telecom/DefaultDialerManager.java b/telecomm/java/android/telecom/DefaultDialerManager.java index 93823d1..b5d566a 100644 --- a/telecomm/java/android/telecom/DefaultDialerManager.java +++ b/telecomm/java/android/telecom/DefaultDialerManager.java @@ -14,7 +14,6 @@ package android.telecom; -import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.pm.ActivityInfo; @@ -52,13 +51,12 @@ public class DefaultDialerManager { } // Only make the change if the new package belongs to a valid phone application - List<ComponentName> componentNames = getInstalledDialerApplications(context); - final ComponentName foundComponent = getComponentName(componentNames, packageName); + List<String> packageNames = getInstalledDialerApplications(context); - if (foundComponent != null) { + if (packageNames.contains(packageName)) { // Update the secure setting. Settings.Secure.putString(context.getContentResolver(), - Settings.Secure.DIALER_DEFAULT_APPLICATION, foundComponent.getPackageName()); + Settings.Secure.DIALER_DEFAULT_APPLICATION, packageName); } } @@ -73,29 +71,31 @@ public class DefaultDialerManager { * * @hide * */ - public static ComponentName getDefaultDialerApplication(Context context) { + public static String getDefaultDialerApplication(Context context) { String defaultPackageName = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.DIALER_DEFAULT_APPLICATION); - final List<ComponentName> componentNames = getInstalledDialerApplications(context); - if (!TextUtils.isEmpty(defaultPackageName)) { - final ComponentName defaultDialer = - getComponentName(componentNames, defaultPackageName); - if (defaultDialer != null) { - return defaultDialer; - } + + final List<String> packageNames = getInstalledDialerApplications(context); + + // Verify that the default dialer has not been disabled or uninstalled. + if (packageNames.contains(defaultPackageName)) { + return defaultPackageName; } // No user-set dialer found, fallback to system dialer - String systemDialer = getTelecomManager(context).getSystemDialerPackage(); + String systemDialerPackageName = getTelecomManager(context).getSystemDialerPackage(); - if (TextUtils.isEmpty(systemDialer)) { + if (TextUtils.isEmpty(systemDialerPackageName)) { // No system dialer configured at build time return null; } - // Verify that the system dialer has not been disabled. - return getComponentName(componentNames, systemDialer); + if (packageNames.contains(systemDialerPackageName)) { + return systemDialerPackageName; + } else { + return null; + } } /** @@ -109,44 +109,25 @@ public class DefaultDialerManager { * * @hide **/ - public static List<ComponentName> getInstalledDialerApplications(Context context) { + public static List<String> getInstalledDialerApplications(Context context) { PackageManager packageManager = context.getPackageManager(); // Get the list of apps registered for the DIAL intent with empty scheme Intent intent = new Intent(Intent.ACTION_DIAL); List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(intent, 0); - List<ComponentName> componentNames = new ArrayList<ComponentName> (); + List<String> packageNames = new ArrayList<>(); for (ResolveInfo resolveInfo : resolveInfoList) { final ActivityInfo activityInfo = resolveInfo.activityInfo; if (activityInfo == null) { continue; } - final ComponentName componentName = - new ComponentName(activityInfo.packageName, activityInfo.name); - componentNames.add(componentName); + packageNames.add(activityInfo.packageName); } // TODO: Filter for apps that don't handle DIAL intent with tel scheme - return componentNames; - } - - /** - * Returns the {@link ComponentName} for the installed dialer application for a given package - * name. - * - * @param context A valid context. - * @param packageName to retrieve the {@link ComponentName} for. - * - * @return The {@link ComponentName} for the installed dialer application corresponding to the - * package name, or null if none is found. - * - * @hide - */ - public static ComponentName getDialerApplicationForPackageName(Context context, - String packageName) { - return getComponentName(getInstalledDialerApplications(context), packageName); + return packageNames; } /** @@ -170,25 +151,6 @@ public class DefaultDialerManager { || packageName.equals(tm.getSystemDialerPackage()); } - /** - * Returns the component from a list of application components that corresponds to the package - * name. - * - * @param componentNames A list of component names - * @param packageName The package name to look for - * @return The {@link ComponentName} that matches the provided packageName, or null if not - * found. - */ - private static ComponentName getComponentName(List<ComponentName> componentNames, - String packageName) { - for (ComponentName componentName : componentNames) { - if (TextUtils.equals(packageName, componentName.getPackageName())) { - return componentName; - } - } - return null; - } - private static TelecomManager getTelecomManager(Context context) { return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); } |