From 8e0207ba5b7ca3bca9d87847eef4d00aa89d7a7a Mon Sep 17 00:00:00 2001 From: Yorke Lee Date: Tue, 28 Apr 2015 09:39:20 -0700 Subject: Simplify DefaultDialerManager The previous code worked with ComponentNames because it was based off existing code for the default SMS application. We only really need the package name however, so simplify the code by storing and retrieving the package name directly. Bug: 20304458 Change-Id: Icabd3a9f0f8166c105360494b601160d13767fad --- .../java/android/telecom/DefaultDialerManager.java | 80 ++++++---------------- 1 file changed, 21 insertions(+), 59 deletions(-) (limited to 'telecomm') diff --git a/telecomm/java/android/telecom/DefaultDialerManager.java b/telecomm/java/android/telecom/DefaultDialerManager.java index 537c3f7..657e699 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 componentNames = getInstalledDialerApplications(context); - final ComponentName foundComponent = getComponentName(componentNames, packageName); + List 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 componentNames = getInstalledDialerApplications(context); - if (!TextUtils.isEmpty(defaultPackageName)) { - final ComponentName defaultDialer = - getComponentName(componentNames, defaultPackageName); - if (defaultDialer != null) { - return defaultDialer; - } + + final List 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 getInstalledDialerApplications(Context context) { + public static List 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 resolveInfoList = packageManager.queryIntentActivities(intent, 0); - List componentNames = new ArrayList (); + List 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 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); } -- cgit v1.1