@Test public void ignoresNonBrowser() { installNonBrowser(BROWSER1); TwaProviderPicker.Action action = TwaProviderPicker.pickProvider(mPackageManager); assertEquals(TwaProviderPicker.LaunchMode.BROWSER, action.launchMode); assertNull(action.provider); }
public static Action pickProvider(PackageManager pm) { Intent queryBrowsersIntent = new Intent() .setAction(Intent.ACTION_VIEW) .addCategory(Intent.CATEGORY_BROWSABLE) .setData(Uri.fromParts("http", "", null)); if (sPackageNameForTesting != null) { queryBrowsersIntent.setPackage(sPackageNameForTesting); } String bestCctProvider = null; String bestBrowserProvider = null; List<ResolveInfo> possibleProviders = pm.queryIntentActivities(queryBrowsersIntent, PackageManager.MATCH_DEFAULT_ONLY); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { possibleProviders.addAll(pm.queryIntentActivities(queryBrowsersIntent, PackageManager.MATCH_ALL)); } Map<String, Integer> customTabsServices = getLaunchModesForCustomTabsServices(pm); for (ResolveInfo possibleProvider : possibleProviders) { String providerName = possibleProvider.activityInfo.packageName; @LaunchMode int launchMode = customTabsServices.containsKey(providerName) ? customTabsServices.get(providerName) : LaunchMode.BROWSER; switch (launchMode) { case LaunchMode.TRUSTED_WEB_ACTIVITY: Log.d(TAG, "Found TWA provider, finishing search: " + providerName); return new Action(LaunchMode.TRUSTED_WEB_ACTIVITY, providerName); case LaunchMode.CUSTOM_TAB: Log.d(TAG, "Found Custom Tabs provider: " + providerName); if (bestCctProvider == null) bestCctProvider = providerName; break; case LaunchMode.BROWSER: Log.d(TAG, "Found browser: " + providerName); if (bestBrowserProvider == null) bestBrowserProvider = providerName; break; } } if (bestCctProvider != null) { Log.d(TAG, "Found no TWA providers, using first Custom Tabs provider: " + bestCctProvider); return new Action(LaunchMode.CUSTOM_TAB, bestCctProvider); } Log.d(TAG, "Found no TWA providers, using first browser: " + bestBrowserProvider); return new Action(LaunchMode.BROWSER, bestBrowserProvider); }
TwaProviderPicker { public static Action pickProvider(PackageManager pm) { Intent queryBrowsersIntent = new Intent() .setAction(Intent.ACTION_VIEW) .addCategory(Intent.CATEGORY_BROWSABLE) .setData(Uri.fromParts("http", "", null)); if (sPackageNameForTesting != null) { queryBrowsersIntent.setPackage(sPackageNameForTesting); } String bestCctProvider = null; String bestBrowserProvider = null; List<ResolveInfo> possibleProviders = pm.queryIntentActivities(queryBrowsersIntent, PackageManager.MATCH_DEFAULT_ONLY); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { possibleProviders.addAll(pm.queryIntentActivities(queryBrowsersIntent, PackageManager.MATCH_ALL)); } Map<String, Integer> customTabsServices = getLaunchModesForCustomTabsServices(pm); for (ResolveInfo possibleProvider : possibleProviders) { String providerName = possibleProvider.activityInfo.packageName; @LaunchMode int launchMode = customTabsServices.containsKey(providerName) ? customTabsServices.get(providerName) : LaunchMode.BROWSER; switch (launchMode) { case LaunchMode.TRUSTED_WEB_ACTIVITY: Log.d(TAG, "Found TWA provider, finishing search: " + providerName); return new Action(LaunchMode.TRUSTED_WEB_ACTIVITY, providerName); case LaunchMode.CUSTOM_TAB: Log.d(TAG, "Found Custom Tabs provider: " + providerName); if (bestCctProvider == null) bestCctProvider = providerName; break; case LaunchMode.BROWSER: Log.d(TAG, "Found browser: " + providerName); if (bestBrowserProvider == null) bestBrowserProvider = providerName; break; } } if (bestCctProvider != null) { Log.d(TAG, "Found no TWA providers, using first Custom Tabs provider: " + bestCctProvider); return new Action(LaunchMode.CUSTOM_TAB, bestCctProvider); } Log.d(TAG, "Found no TWA providers, using first browser: " + bestBrowserProvider); return new Action(LaunchMode.BROWSER, bestBrowserProvider); } }
TwaProviderPicker { public static Action pickProvider(PackageManager pm) { Intent queryBrowsersIntent = new Intent() .setAction(Intent.ACTION_VIEW) .addCategory(Intent.CATEGORY_BROWSABLE) .setData(Uri.fromParts("http", "", null)); if (sPackageNameForTesting != null) { queryBrowsersIntent.setPackage(sPackageNameForTesting); } String bestCctProvider = null; String bestBrowserProvider = null; List<ResolveInfo> possibleProviders = pm.queryIntentActivities(queryBrowsersIntent, PackageManager.MATCH_DEFAULT_ONLY); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { possibleProviders.addAll(pm.queryIntentActivities(queryBrowsersIntent, PackageManager.MATCH_ALL)); } Map<String, Integer> customTabsServices = getLaunchModesForCustomTabsServices(pm); for (ResolveInfo possibleProvider : possibleProviders) { String providerName = possibleProvider.activityInfo.packageName; @LaunchMode int launchMode = customTabsServices.containsKey(providerName) ? customTabsServices.get(providerName) : LaunchMode.BROWSER; switch (launchMode) { case LaunchMode.TRUSTED_WEB_ACTIVITY: Log.d(TAG, "Found TWA provider, finishing search: " + providerName); return new Action(LaunchMode.TRUSTED_WEB_ACTIVITY, providerName); case LaunchMode.CUSTOM_TAB: Log.d(TAG, "Found Custom Tabs provider: " + providerName); if (bestCctProvider == null) bestCctProvider = providerName; break; case LaunchMode.BROWSER: Log.d(TAG, "Found browser: " + providerName); if (bestBrowserProvider == null) bestBrowserProvider = providerName; break; } } if (bestCctProvider != null) { Log.d(TAG, "Found no TWA providers, using first Custom Tabs provider: " + bestCctProvider); return new Action(LaunchMode.CUSTOM_TAB, bestCctProvider); } Log.d(TAG, "Found no TWA providers, using first browser: " + bestBrowserProvider); return new Action(LaunchMode.BROWSER, bestBrowserProvider); }  }
TwaProviderPicker { public static Action pickProvider(PackageManager pm) { Intent queryBrowsersIntent = new Intent() .setAction(Intent.ACTION_VIEW) .addCategory(Intent.CATEGORY_BROWSABLE) .setData(Uri.fromParts("http", "", null)); if (sPackageNameForTesting != null) { queryBrowsersIntent.setPackage(sPackageNameForTesting); } String bestCctProvider = null; String bestBrowserProvider = null; List<ResolveInfo> possibleProviders = pm.queryIntentActivities(queryBrowsersIntent, PackageManager.MATCH_DEFAULT_ONLY); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { possibleProviders.addAll(pm.queryIntentActivities(queryBrowsersIntent, PackageManager.MATCH_ALL)); } Map<String, Integer> customTabsServices = getLaunchModesForCustomTabsServices(pm); for (ResolveInfo possibleProvider : possibleProviders) { String providerName = possibleProvider.activityInfo.packageName; @LaunchMode int launchMode = customTabsServices.containsKey(providerName) ? customTabsServices.get(providerName) : LaunchMode.BROWSER; switch (launchMode) { case LaunchMode.TRUSTED_WEB_ACTIVITY: Log.d(TAG, "Found TWA provider, finishing search: " + providerName); return new Action(LaunchMode.TRUSTED_WEB_ACTIVITY, providerName); case LaunchMode.CUSTOM_TAB: Log.d(TAG, "Found Custom Tabs provider: " + providerName); if (bestCctProvider == null) bestCctProvider = providerName; break; case LaunchMode.BROWSER: Log.d(TAG, "Found browser: " + providerName); if (bestBrowserProvider == null) bestBrowserProvider = providerName; break; } } if (bestCctProvider != null) { Log.d(TAG, "Found no TWA providers, using first Custom Tabs provider: " + bestCctProvider); return new Action(LaunchMode.CUSTOM_TAB, bestCctProvider); } Log.d(TAG, "Found no TWA providers, using first browser: " + bestBrowserProvider); return new Action(LaunchMode.BROWSER, bestBrowserProvider); }  static Action pickProvider(PackageManager pm); }
TwaProviderPicker { public static Action pickProvider(PackageManager pm) { Intent queryBrowsersIntent = new Intent() .setAction(Intent.ACTION_VIEW) .addCategory(Intent.CATEGORY_BROWSABLE) .setData(Uri.fromParts("http", "", null)); if (sPackageNameForTesting != null) { queryBrowsersIntent.setPackage(sPackageNameForTesting); } String bestCctProvider = null; String bestBrowserProvider = null; List<ResolveInfo> possibleProviders = pm.queryIntentActivities(queryBrowsersIntent, PackageManager.MATCH_DEFAULT_ONLY); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { possibleProviders.addAll(pm.queryIntentActivities(queryBrowsersIntent, PackageManager.MATCH_ALL)); } Map<String, Integer> customTabsServices = getLaunchModesForCustomTabsServices(pm); for (ResolveInfo possibleProvider : possibleProviders) { String providerName = possibleProvider.activityInfo.packageName; @LaunchMode int launchMode = customTabsServices.containsKey(providerName) ? customTabsServices.get(providerName) : LaunchMode.BROWSER; switch (launchMode) { case LaunchMode.TRUSTED_WEB_ACTIVITY: Log.d(TAG, "Found TWA provider, finishing search: " + providerName); return new Action(LaunchMode.TRUSTED_WEB_ACTIVITY, providerName); case LaunchMode.CUSTOM_TAB: Log.d(TAG, "Found Custom Tabs provider: " + providerName); if (bestCctProvider == null) bestCctProvider = providerName; break; case LaunchMode.BROWSER: Log.d(TAG, "Found browser: " + providerName); if (bestBrowserProvider == null) bestBrowserProvider = providerName; break; } } if (bestCctProvider != null) { Log.d(TAG, "Found no TWA providers, using first Custom Tabs provider: " + bestCctProvider); return new Action(LaunchMode.CUSTOM_TAB, bestCctProvider); } Log.d(TAG, "Found no TWA providers, using first browser: " + bestBrowserProvider); return new Action(LaunchMode.BROWSER, bestBrowserProvider); }  static Action pickProvider(PackageManager pm);  }