Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(767)

Side by Side Diff: customtabs/src/android/support/customtabs/CustomTabsClient.java

Issue 2961203002: Support library changes to allow a callback notifying the selection of default items for Browser Ac… (Closed)
Patch Set: Update based on Yusuf's comments. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2015 The Android Open Source Project 2 * Copyright (C) 2015 The Android Open Source Project
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at 6 * You may obtain a copy of the License at
7 * 7 *
8 * http://www.apache.org/licenses/LICENSE-2.0 8 * http://www.apache.org/licenses/LICENSE-2.0
9 * 9 *
10 * Unless required by applicable law or agreed to in writing, software 10 * Unless required by applicable law or agreed to in writing, software
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 * @return The preferred package name for handling Custom Tabs, or <code>nul l</code>. 91 * @return The preferred package name for handling Custom Tabs, or <code>nul l</code>.
92 */ 92 */
93 public static String getPackageName( 93 public static String getPackageName(
94 Context context, @Nullable List<String> packages, boolean ignoreDefault) { 94 Context context, @Nullable List<String> packages, boolean ignoreDefault) {
95 PackageManager pm = context.getPackageManager(); 95 PackageManager pm = context.getPackageManager();
96 96
97 List<String> packageNames = packages == null ? new ArrayList<String>() : packages; 97 List<String> packageNames = packages == null ? new ArrayList<String>() : packages;
98 Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http:/ /")); 98 Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http:/ /"));
99 99
100 if (!ignoreDefault) { 100 if (!ignoreDefault) {
101 ResolveInfo defaultViewHandlerInfo = pm.resolveActivity(activityInte nt, 0); 101 ResolveInfo defaultViewHandlerInfo = getDefaultHandlerForIntent(pm, activityIntent);
102 if (defaultViewHandlerInfo != null) { 102 if (defaultViewHandlerInfo != null) {
103 String packageName = defaultViewHandlerInfo.activityInfo.package Name; 103 String packageName = defaultViewHandlerInfo.activityInfo.package Name;
104 packageNames = new ArrayList<String>(packageNames.size() + 1); 104 packageNames = new ArrayList<String>(packageNames.size() + 1);
105 packageNames.add(packageName); 105 packageNames.add(packageName);
106 if (packages != null) packageNames.addAll(packages); 106 if (packages != null) packageNames.addAll(packages);
107 } 107 }
108 } 108 }
109 109
110 Intent serviceIntent = new Intent(CustomTabsService.ACTION_CUSTOM_TABS_C ONNECTION); 110 Intent serviceIntent = new Intent(CustomTabsService.ACTION_CUSTOM_TABS_C ONNECTION);
111 for (String packageName : packageNames) { 111 for (String packageName : packageNames) {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 return new CustomTabsSession(mService, wrapper, mServiceComponentName); 241 return new CustomTabsSession(mService, wrapper, mServiceComponentName);
242 } 242 }
243 243
244 public Bundle extraCommand(String commandName, Bundle args) { 244 public Bundle extraCommand(String commandName, Bundle args) {
245 try { 245 try {
246 return mService.extraCommand(commandName, args); 246 return mService.extraCommand(commandName, args);
247 } catch (RemoteException e) { 247 } catch (RemoteException e) {
248 return null; 248 return null;
249 } 249 }
250 } 250 }
251
252 /**
253 * Returns the default handler for given intent.
254 * @param pm {@link PackageManager} to use for retriving the handlers.
255 * @param intent {@link Intent} to be handled.
256 */
257 public static ResolveInfo getDefaultHandlerForIntent(PackageManager pm, Inte nt intent) {
Yusuf 2017/07/14 05:35:34 I know I said to do this, but now that we have it
ltian 2017/07/14 22:15:02 Done.
258 return pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
259 }
251 } 260 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698