Loading telecomm/java/android/telecom/DefaultDialerManager.java +21 −59 Original line number Original line Diff line number Diff line Loading @@ -14,7 +14,6 @@ package android.telecom; package android.telecom; import android.content.ComponentName; import android.content.Context; import android.content.Context; import android.content.Intent; import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo; Loading Loading @@ -52,13 +51,12 @@ public class DefaultDialerManager { } } // Only make the change if the new package belongs to a valid phone application // Only make the change if the new package belongs to a valid phone application List<ComponentName> componentNames = getInstalledDialerApplications(context); List<String> packageNames = getInstalledDialerApplications(context); final ComponentName foundComponent = getComponentName(componentNames, packageName); if (foundComponent != null) { if (packageNames.contains(packageName)) { // Update the secure setting. // Update the secure setting. Settings.Secure.putString(context.getContentResolver(), Settings.Secure.putString(context.getContentResolver(), Settings.Secure.DIALER_DEFAULT_APPLICATION, foundComponent.getPackageName()); Settings.Secure.DIALER_DEFAULT_APPLICATION, packageName); } } } } Loading @@ -73,29 +71,31 @@ public class DefaultDialerManager { * * * @hide * @hide * */ * */ public static ComponentName getDefaultDialerApplication(Context context) { public static String getDefaultDialerApplication(Context context) { String defaultPackageName = Settings.Secure.getString(context.getContentResolver(), String defaultPackageName = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.DIALER_DEFAULT_APPLICATION); Settings.Secure.DIALER_DEFAULT_APPLICATION); final List<ComponentName> componentNames = getInstalledDialerApplications(context); if (!TextUtils.isEmpty(defaultPackageName)) { final List<String> packageNames = getInstalledDialerApplications(context); final ComponentName defaultDialer = getComponentName(componentNames, defaultPackageName); // Verify that the default dialer has not been disabled or uninstalled. if (defaultDialer != null) { if (packageNames.contains(defaultPackageName)) { return defaultDialer; return defaultPackageName; } } } // No user-set dialer found, fallback to system dialer // 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 // No system dialer configured at build time return null; return null; } } // Verify that the system dialer has not been disabled. if (packageNames.contains(systemDialerPackageName)) { return getComponentName(componentNames, systemDialer); return systemDialerPackageName; } else { return null; } } } /** /** Loading @@ -109,44 +109,25 @@ public class DefaultDialerManager { * * * @hide * @hide **/ **/ public static List<ComponentName> getInstalledDialerApplications(Context context) { public static List<String> getInstalledDialerApplications(Context context) { PackageManager packageManager = context.getPackageManager(); PackageManager packageManager = context.getPackageManager(); // Get the list of apps registered for the DIAL intent with empty scheme // Get the list of apps registered for the DIAL intent with empty scheme Intent intent = new Intent(Intent.ACTION_DIAL); Intent intent = new Intent(Intent.ACTION_DIAL); List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(intent, 0); List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(intent, 0); List<ComponentName> componentNames = new ArrayList<ComponentName> (); List<String> packageNames = new ArrayList<>(); for (ResolveInfo resolveInfo : resolveInfoList) { for (ResolveInfo resolveInfo : resolveInfoList) { final ActivityInfo activityInfo = resolveInfo.activityInfo; final ActivityInfo activityInfo = resolveInfo.activityInfo; if (activityInfo == null) { if (activityInfo == null) { continue; continue; } } final ComponentName componentName = packageNames.add(activityInfo.packageName); new ComponentName(activityInfo.packageName, activityInfo.name); componentNames.add(componentName); } } // TODO: Filter for apps that don't handle DIAL intent with tel scheme // TODO: Filter for apps that don't handle DIAL intent with tel scheme return componentNames; return packageNames; } /** * 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); } } /** /** Loading @@ -170,25 +151,6 @@ public class DefaultDialerManager { || packageName.equals(tm.getSystemDialerPackage()); || 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) { private static TelecomManager getTelecomManager(Context context) { return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); } } Loading Loading
telecomm/java/android/telecom/DefaultDialerManager.java +21 −59 Original line number Original line Diff line number Diff line Loading @@ -14,7 +14,6 @@ package android.telecom; package android.telecom; import android.content.ComponentName; import android.content.Context; import android.content.Context; import android.content.Intent; import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo; Loading Loading @@ -52,13 +51,12 @@ public class DefaultDialerManager { } } // Only make the change if the new package belongs to a valid phone application // Only make the change if the new package belongs to a valid phone application List<ComponentName> componentNames = getInstalledDialerApplications(context); List<String> packageNames = getInstalledDialerApplications(context); final ComponentName foundComponent = getComponentName(componentNames, packageName); if (foundComponent != null) { if (packageNames.contains(packageName)) { // Update the secure setting. // Update the secure setting. Settings.Secure.putString(context.getContentResolver(), Settings.Secure.putString(context.getContentResolver(), Settings.Secure.DIALER_DEFAULT_APPLICATION, foundComponent.getPackageName()); Settings.Secure.DIALER_DEFAULT_APPLICATION, packageName); } } } } Loading @@ -73,29 +71,31 @@ public class DefaultDialerManager { * * * @hide * @hide * */ * */ public static ComponentName getDefaultDialerApplication(Context context) { public static String getDefaultDialerApplication(Context context) { String defaultPackageName = Settings.Secure.getString(context.getContentResolver(), String defaultPackageName = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.DIALER_DEFAULT_APPLICATION); Settings.Secure.DIALER_DEFAULT_APPLICATION); final List<ComponentName> componentNames = getInstalledDialerApplications(context); if (!TextUtils.isEmpty(defaultPackageName)) { final List<String> packageNames = getInstalledDialerApplications(context); final ComponentName defaultDialer = getComponentName(componentNames, defaultPackageName); // Verify that the default dialer has not been disabled or uninstalled. if (defaultDialer != null) { if (packageNames.contains(defaultPackageName)) { return defaultDialer; return defaultPackageName; } } } // No user-set dialer found, fallback to system dialer // 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 // No system dialer configured at build time return null; return null; } } // Verify that the system dialer has not been disabled. if (packageNames.contains(systemDialerPackageName)) { return getComponentName(componentNames, systemDialer); return systemDialerPackageName; } else { return null; } } } /** /** Loading @@ -109,44 +109,25 @@ public class DefaultDialerManager { * * * @hide * @hide **/ **/ public static List<ComponentName> getInstalledDialerApplications(Context context) { public static List<String> getInstalledDialerApplications(Context context) { PackageManager packageManager = context.getPackageManager(); PackageManager packageManager = context.getPackageManager(); // Get the list of apps registered for the DIAL intent with empty scheme // Get the list of apps registered for the DIAL intent with empty scheme Intent intent = new Intent(Intent.ACTION_DIAL); Intent intent = new Intent(Intent.ACTION_DIAL); List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(intent, 0); List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(intent, 0); List<ComponentName> componentNames = new ArrayList<ComponentName> (); List<String> packageNames = new ArrayList<>(); for (ResolveInfo resolveInfo : resolveInfoList) { for (ResolveInfo resolveInfo : resolveInfoList) { final ActivityInfo activityInfo = resolveInfo.activityInfo; final ActivityInfo activityInfo = resolveInfo.activityInfo; if (activityInfo == null) { if (activityInfo == null) { continue; continue; } } final ComponentName componentName = packageNames.add(activityInfo.packageName); new ComponentName(activityInfo.packageName, activityInfo.name); componentNames.add(componentName); } } // TODO: Filter for apps that don't handle DIAL intent with tel scheme // TODO: Filter for apps that don't handle DIAL intent with tel scheme return componentNames; return packageNames; } /** * 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); } } /** /** Loading @@ -170,25 +151,6 @@ public class DefaultDialerManager { || packageName.equals(tm.getSystemDialerPackage()); || 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) { private static TelecomManager getTelecomManager(Context context) { return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); } } Loading