Index: chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java b/chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java |
index c8356b73ffd55880f02a18bf3581ac97bab3d0c8..52d95bf9dfb2f671e4ca4033e8ef1dcb40cde1dc 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java |
@@ -4,7 +4,6 @@ |
package org.chromium.chrome.browser; |
-import android.annotation.SuppressLint; |
import android.app.ActivityManager; |
import android.content.Context; |
import android.content.Intent; |
@@ -12,7 +11,6 @@ import android.content.pm.ApplicationInfo; |
import android.content.pm.PackageInfo; |
import android.content.pm.PackageManager; |
import android.content.pm.PackageManager.NameNotFoundException; |
-import android.content.pm.ResolveInfo; |
import android.graphics.Bitmap; |
import android.graphics.BitmapFactory; |
import android.graphics.Canvas; |
@@ -35,6 +33,7 @@ import org.chromium.base.VisibleForTesting; |
import org.chromium.base.annotations.CalledByNative; |
import org.chromium.blink_public.platform.WebDisplayMode; |
import org.chromium.chrome.R; |
+import org.chromium.chrome.browser.webapps.ChromeShortcutManager; |
import org.chromium.chrome.browser.webapps.ChromeWebApkHost; |
import org.chromium.chrome.browser.webapps.WebApkInfo; |
import org.chromium.chrome.browser.webapps.WebappActivity; |
@@ -91,10 +90,6 @@ public class ShortcutHelper { |
private static final String TAG = "ShortcutHelper"; |
- // There is no public string defining this intent so if Home changes the value, we |
- // have to update this string. |
- private static final String INSTALL_SHORTCUT = "com.android.launcher.action.INSTALL_SHORTCUT"; |
- |
// The activity class used for launching a WebApk. |
private static final String WEBAPK_MAIN_ACTIVITY = "org.chromium.webapk.shell_apk.MainActivity"; |
@@ -106,15 +101,17 @@ public class ShortcutHelper { |
private static final float GENERATED_ICON_PADDING_RATIO = 1.0f / 12.0f; |
private static final float GENERATED_ICON_FONT_SIZE_RATIO = 1.0f / 3.0f; |
- /** Broadcasts Intents out Android for adding the shortcut. */ |
+ /** Request Android to add a shortcut to the home screen. */ |
public static class Delegate { |
/** |
- * Broadcasts an intent to all interested BroadcastReceivers. |
- * @param context The Context to use. |
- * @param intent The intent to broadcast. |
+ * Request Android to add a shortcut to the home screen |
+ * @param title Title of the shortcut. |
+ * @param icon Image that represents the shortcut. |
+ * @param intent Intent to fire when the shortcut is activated. |
*/ |
- public void sendBroadcast(Context context, Intent intent) { |
- context.sendBroadcast(intent); |
+ public void addShortcutToHomescreen(String title, Bitmap icon, Intent shortcutIntent) { |
+ ChromeShortcutManager.getInstance().addShortcutToHomeScreen( |
+ title, icon, shortcutIntent); |
} |
/** |
@@ -166,8 +163,7 @@ public class ShortcutHelper { |
@Override |
protected void onPostExecute(final Intent resultIntent) { |
Context context = ContextUtils.getApplicationContext(); |
dominickn
2017/02/14 03:04:21
This variable is no longer used: remove.
Marti Wong
2017/02/14 04:37:51
Done. thanks!
|
- sDelegate.sendBroadcast( |
- context, createAddToHomeIntent(userTitle, icon, resultIntent)); |
+ sDelegate.addShortcutToHomescreen(userTitle, icon, resultIntent); |
// Store the webapp data so that it is accessible without the intent. Once this |
// process is complete, call back to native code to start the splash image |
@@ -180,8 +176,9 @@ public class ShortcutHelper { |
nativeOnWebappDataStored(callbackPointer); |
} |
}); |
- |
- showAddedToHomescreenToast(userTitle); |
+ if (ChromeShortcutManager.getInstance().shouldShowAddedToHomescreenToast()) { |
+ showAddedToHomescreenToast(userTitle); |
+ } |
} |
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
} |
@@ -198,7 +195,8 @@ public class ShortcutHelper { |
Intent i = new Intent(); |
i.setClassName(packageName, WEBAPK_MAIN_ACTIVITY); |
i.addCategory(Intent.CATEGORY_LAUNCHER); |
- context.sendBroadcast(createAddToHomeIntent(shortcutTitle, bitmap, i)); |
+ context.sendBroadcast( |
+ ChromeShortcutManager.createAddToHomeIntent(shortcutTitle, bitmap, i)); |
} catch (NameNotFoundException e) { |
e.printStackTrace(); |
} |
@@ -209,14 +207,17 @@ public class ShortcutHelper { |
*/ |
@SuppressWarnings("unused") |
@CalledByNative |
- private static void addShortcut(String url, String userTitle, Bitmap icon, int source) { |
+ private static void addShortcut( |
+ String id, String url, String userTitle, Bitmap icon, int source) { |
Context context = ContextUtils.getApplicationContext(); |
dominickn
2017/02/14 03:04:21
Remove context from here, and call setPackage() in
Marti Wong
2017/02/14 04:37:51
will keep getPackageName() below. So this context
|
final Intent shortcutIntent = createShortcutIntent(url); |
+ shortcutIntent.putExtra(EXTRA_ID, id); |
shortcutIntent.putExtra(EXTRA_SOURCE, source); |
shortcutIntent.setPackage(context.getPackageName()); |
- sDelegate.sendBroadcast( |
- context, createAddToHomeIntent(userTitle, icon, shortcutIntent)); |
- showAddedToHomescreenToast(userTitle); |
+ sDelegate.addShortcutToHomescreen(userTitle, icon, shortcutIntent); |
+ if (ChromeShortcutManager.getInstance().shouldShowAddedToHomescreenToast()) { |
+ showAddedToHomescreenToast(userTitle); |
+ } |
} |
/** |
@@ -273,22 +274,6 @@ public class ShortcutHelper { |
} |
/** |
- * Creates an intent that will add a shortcut to the home screen. |
- * @param title Title of the shortcut. |
- * @param icon Image that represents the shortcut. |
- * @param shortcutIntent Intent to fire when the shortcut is activated. |
- * @return Intent for the shortcut. |
- */ |
- public static Intent createAddToHomeIntent(String title, Bitmap icon, |
- Intent shortcutIntent) { |
- Intent i = new Intent(INSTALL_SHORTCUT); |
- i.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); |
- i.putExtra(Intent.EXTRA_SHORTCUT_NAME, title); |
- i.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon); |
- return i; |
- } |
Marti Wong
2017/02/14 04:37:50
Moved to ChromeShortcutManager
|
- |
- /** |
* Creates a shortcut to launch a web app on the home screen. |
* @param id Id of the web app. |
* @param action Intent action to open a full screen activity. |
@@ -361,14 +346,8 @@ public class ShortcutHelper { |
* @param context Context used to get the package manager. |
* @return if a shortcut can be added to the home screen under the current profile. |
*/ |
- // TODO(crbug.com/635567): Fix this properly. |
- @SuppressLint("WrongConstant") |
public static boolean isAddToHomeIntentSupported(Context context) { |
- PackageManager pm = context.getPackageManager(); |
- Intent i = new Intent(INSTALL_SHORTCUT); |
- List<ResolveInfo> receivers = pm.queryBroadcastReceivers( |
- i, PackageManager.GET_INTENT_FILTERS); |
- return !receivers.isEmpty(); |
+ return ChromeShortcutManager.getInstance().canAddShortcutToHomescreen(); |
} |
/** |