| Index: shared/src/main/java/org/chromium/customtabsclient/shared/CustomTabsHelper.java
|
| diff --git a/shared/src/main/java/org/chromium/customtabsclient/shared/CustomTabsHelper.java b/shared/src/main/java/org/chromium/customtabsclient/shared/CustomTabsHelper.java
|
| index 00af1e2189019aeabbcfcc4d498e22d09a2a073c..275331b63f1e87ab86de05c195614f82d0166007 100644
|
| --- a/shared/src/main/java/org/chromium/customtabsclient/shared/CustomTabsHelper.java
|
| +++ b/shared/src/main/java/org/chromium/customtabsclient/shared/CustomTabsHelper.java
|
| @@ -19,6 +19,7 @@ import android.content.Intent;
|
| import android.content.IntentFilter;
|
| import android.content.pm.PackageManager;
|
| import android.content.pm.ResolveInfo;
|
| +import android.graphics.Color;
|
| import android.net.Uri;
|
| import android.text.TextUtils;
|
| import android.util.Log;
|
| @@ -55,12 +56,12 @@ public class CustomTabsHelper {
|
| * the one chosen by the user if there is one, otherwise makes a best effort to return a
|
| * valid package name.
|
| *
|
| - * This is <strong>not</strong> threadsafe.
|
| - *
|
| * @param context {@link Context} to use for accessing {@link PackageManager}.
|
| - * @return The package name recommended to use for connecting to custom tabs related components.
|
| + * @param packagesSupportingCustomTabs All packages that support custom tabs.
|
| + * @return
|
| */
|
| - public static String getPackageNameToUse(Context context) {
|
| + public static String getPackageNameToUse(Context context,
|
| + List<String> packagesSupportingCustomTabs) {
|
| if (sPackageNameToUse != null) return sPackageNameToUse;
|
|
|
| PackageManager pm = context.getPackageManager();
|
| @@ -72,18 +73,6 @@ public class CustomTabsHelper {
|
| defaultViewHandlerPackageName = defaultViewHandlerInfo.activityInfo.packageName;
|
| }
|
|
|
| - // Get all apps that can handle VIEW intents.
|
| - List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, 0);
|
| - List<String> packagesSupportingCustomTabs = new ArrayList<>();
|
| - for (ResolveInfo info : resolvedActivityList) {
|
| - Intent serviceIntent = new Intent();
|
| - serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION);
|
| - serviceIntent.setPackage(info.activityInfo.packageName);
|
| - if (pm.resolveService(serviceIntent, 0) != null) {
|
| - packagesSupportingCustomTabs.add(info.activityInfo.packageName);
|
| - }
|
| - }
|
| -
|
| // Now packagesSupportingCustomTabs contains all apps that can handle both VIEW intents
|
| // and service calls.
|
| if (packagesSupportingCustomTabs.isEmpty()) {
|
| @@ -107,6 +96,38 @@ public class CustomTabsHelper {
|
| }
|
|
|
| /**
|
| + * @see #getPackageNameToUse(Context, List<String).
|
| + */
|
| + public static String getPackageNameToUse(Context context) {
|
| + if (sPackageNameToUse != null) return sPackageNameToUse;
|
| + return getPackageNameToUse(context, getAllPackagesSupportingCustomTabs(context));
|
| + }
|
| +
|
| + /**
|
| + * Get all apps that support custom tabs. We can tell whether an app supports custom tabs by
|
| + * sending uri visit intent.
|
| + * @param context
|
| + * @return an Arraylist of package name.
|
| + */
|
| + public static ArrayList<String> getAllPackagesSupportingCustomTabs(Context context) {
|
| + PackageManager pm = context.getPackageManager();
|
| + // Get default VIEW intent handler.
|
| + Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
|
| + // Get all apps that can handle VIEW intents.
|
| + List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, 0);
|
| + ArrayList<String> packagesSupportingCustomTabs = new ArrayList<>();
|
| + for (ResolveInfo info : resolvedActivityList) {
|
| + Intent serviceIntent = new Intent();
|
| + serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION);
|
| + serviceIntent.setPackage(info.activityInfo.packageName);
|
| + if (pm.resolveService(serviceIntent, 0) != null) {
|
| + packagesSupportingCustomTabs.add(info.activityInfo.packageName);
|
| + }
|
| + }
|
| + return packagesSupportingCustomTabs;
|
| + }
|
| +
|
| + /**
|
| * Used to check whether there is a specialized handler for a given intent.
|
| * @param intent The intent to check with.
|
| * @return Whether there is a specialized handler for the given intent.
|
|
|