OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser; | 5 package org.chromium.chrome.browser; |
6 | 6 |
7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
8 import android.app.ActivityManager; | 8 import android.app.ActivityManager; |
9 import android.content.Context; | 9 import android.content.Context; |
10 import android.content.Intent; | 10 import android.content.Intent; |
11 import android.content.pm.ApplicationInfo; | 11 import android.content.pm.ApplicationInfo; |
12 import android.content.pm.PackageInfo; | |
12 import android.content.pm.PackageManager; | 13 import android.content.pm.PackageManager; |
13 import android.content.pm.PackageManager.NameNotFoundException; | 14 import android.content.pm.PackageManager.NameNotFoundException; |
14 import android.content.pm.ResolveInfo; | 15 import android.content.pm.ResolveInfo; |
15 import android.graphics.Bitmap; | 16 import android.graphics.Bitmap; |
16 import android.graphics.BitmapFactory; | 17 import android.graphics.BitmapFactory; |
17 import android.graphics.Canvas; | 18 import android.graphics.Canvas; |
18 import android.graphics.Color; | 19 import android.graphics.Color; |
19 import android.graphics.Paint; | 20 import android.graphics.Paint; |
20 import android.graphics.Rect; | 21 import android.graphics.Rect; |
21 import android.graphics.drawable.BitmapDrawable; | 22 import android.graphics.drawable.BitmapDrawable; |
22 import android.graphics.drawable.Drawable; | 23 import android.graphics.drawable.Drawable; |
23 import android.net.Uri; | 24 import android.net.Uri; |
24 import android.os.AsyncTask; | 25 import android.os.AsyncTask; |
26 import android.support.annotation.NonNull; | |
25 import android.text.TextUtils; | 27 import android.text.TextUtils; |
26 import android.util.Base64; | 28 import android.util.Base64; |
27 | 29 |
28 import org.chromium.base.ApiCompatibilityUtils; | 30 import org.chromium.base.ApiCompatibilityUtils; |
29 import org.chromium.base.ContextUtils; | 31 import org.chromium.base.ContextUtils; |
30 import org.chromium.base.Log; | 32 import org.chromium.base.Log; |
31 import org.chromium.base.ThreadUtils; | 33 import org.chromium.base.ThreadUtils; |
32 import org.chromium.base.VisibleForTesting; | 34 import org.chromium.base.VisibleForTesting; |
33 import org.chromium.base.annotations.CalledByNative; | 35 import org.chromium.base.annotations.CalledByNative; |
34 import org.chromium.blink_public.platform.WebDisplayMode; | 36 import org.chromium.blink_public.platform.WebDisplayMode; |
35 import org.chromium.chrome.R; | 37 import org.chromium.chrome.R; |
36 import org.chromium.chrome.browser.webapps.ChromeWebApkHost; | 38 import org.chromium.chrome.browser.webapps.ChromeWebApkHost; |
39 import org.chromium.chrome.browser.webapps.WebApkInfo; | |
37 import org.chromium.chrome.browser.webapps.WebappActivity; | 40 import org.chromium.chrome.browser.webapps.WebappActivity; |
38 import org.chromium.chrome.browser.webapps.WebappAuthenticator; | 41 import org.chromium.chrome.browser.webapps.WebappAuthenticator; |
39 import org.chromium.chrome.browser.webapps.WebappDataStorage; | 42 import org.chromium.chrome.browser.webapps.WebappDataStorage; |
40 import org.chromium.chrome.browser.webapps.WebappLauncherActivity; | 43 import org.chromium.chrome.browser.webapps.WebappLauncherActivity; |
41 import org.chromium.chrome.browser.webapps.WebappRegistry; | 44 import org.chromium.chrome.browser.webapps.WebappRegistry; |
42 import org.chromium.chrome.browser.widget.RoundedIconGenerator; | 45 import org.chromium.chrome.browser.widget.RoundedIconGenerator; |
43 import org.chromium.content_public.common.ScreenOrientationConstants; | 46 import org.chromium.content_public.common.ScreenOrientationConstants; |
44 import org.chromium.ui.widget.Toast; | 47 import org.chromium.ui.widget.Toast; |
45 import org.chromium.webapk.lib.client.WebApkValidator; | 48 import org.chromium.webapk.lib.client.WebApkValidator; |
46 | 49 |
47 import java.io.ByteArrayOutputStream; | 50 import java.io.ByteArrayOutputStream; |
51 import java.util.LinkedList; | |
48 import java.util.List; | 52 import java.util.List; |
49 | 53 |
50 /** | 54 /** |
51 * This class contains functions related to adding shortcuts to the Android Home | 55 * This class contains functions related to adding shortcuts to the Android Home |
52 * screen. These shortcuts are used to either open a page in the main browser | 56 * screen. These shortcuts are used to either open a page in the main browser |
53 * or open a web app. | 57 * or open a web app. |
54 */ | 58 */ |
55 public class ShortcutHelper { | 59 public class ShortcutHelper { |
56 public static final String EXTRA_ICON = "org.chromium.chrome.browser.webapp_ icon"; | 60 public static final String EXTRA_ICON = "org.chromium.chrome.browser.webapp_ icon"; |
57 public static final String EXTRA_ID = "org.chromium.chrome.browser.webapp_id "; | 61 public static final String EXTRA_ID = "org.chromium.chrome.browser.webapp_id "; |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
641 context.getResources(), id, density); | 645 context.getResources(), id, density); |
642 | 646 |
643 if (drawable instanceof BitmapDrawable) { | 647 if (drawable instanceof BitmapDrawable) { |
644 BitmapDrawable bd = (BitmapDrawable) drawable; | 648 BitmapDrawable bd = (BitmapDrawable) drawable; |
645 return bd.getBitmap(); | 649 return bd.getBitmap(); |
646 } | 650 } |
647 assert false : "The drawable was not a bitmap drawable as expected"; | 651 assert false : "The drawable was not a bitmap drawable as expected"; |
648 return null; | 652 return null; |
649 } | 653 } |
650 | 654 |
655 /** | |
656 * Fetches the information of all WebAPKs installed on the device and return s them to the | |
657 * caller using a callback. | |
658 * | |
659 * @param callbackPointer Callback to be called with the information on the WebAPKs found. | |
660 */ | |
661 @CalledByNative | |
662 public static void listWebApks(long callbackPointer) { | |
663 List<String> shortNames = new LinkedList<>(); | |
pkotwicz
2017/01/18 02:08:20
Can you explain why you chose a LinkedList instead
gonzalon
2017/01/18 15:29:32
I only use ArrayList when I'm sure of the final si
| |
664 List<String> packageNames = new LinkedList<>(); | |
665 List<Integer> shellApkVersions = new LinkedList<>(); | |
666 List<Integer> versionCodes = new LinkedList<>(); | |
667 | |
668 PackageManager packageManager = ContextUtils.getApplicationContext().get PackageManager(); | |
669 for (PackageInfo packageInfo : packageManager.getInstalledPackages(0)) { | |
670 if (WebApkValidator.isValidWebApk( | |
671 ContextUtils.getApplicationContext(), packageInfo.packag eName)) { | |
672 // We need to pass in a non-null URL as second parameter to fetc h all the | |
673 // information about the WebAPK. | |
674 WebApkInfo webApkInfo = WebApkInfo.create(packageInfo.packageNam e, "", 0); | |
pkotwicz
2017/01/18 02:08:20
Nit: 0 -> ShortcutSource.UNKNOWN
gonzalon
2017/01/18 15:29:32
Done.
| |
675 if (webApkInfo != null) { | |
676 shortNames.add(webApkInfo.shortName()); | |
677 packageNames.add(packageInfo.packageName); | |
678 shellApkVersions.add(webApkInfo.shellApkVersion()); | |
679 versionCodes.add(packageInfo.versionCode); | |
680 } | |
681 } | |
682 } | |
pkotwicz
2017/01/18 02:08:20
Nit: For the sake of clarity I would do:
String[]
gonzalon
2017/01/18 15:29:32
It's not exactly the same, if the size of the arra
| |
683 nativeOnWebApksFound(callbackPointer, shortNames.toArray(new String[shor tNames.size()]), | |
684 packageNames.toArray(new String[packageNames.size()]), | |
685 integerListToIntArray(shellApkVersions), integerListToIntArray(v ersionCodes)); | |
686 } | |
687 | |
688 private static int[] integerListToIntArray(@NonNull List<Integer> list) { | |
pkotwicz
2017/01/18 02:08:20
+agrieve@
Cool! I did not know about this annotat
gonzalon
2017/01/18 15:29:32
This annotation doesn't actually enforce the argum
agrieve
2017/01/19 19:58:23
Yep, would love to see more support annotations be
| |
689 int[] array = new int[list.size()]; | |
690 int i = 0; | |
691 for (Integer integer : list) { | |
pkotwicz
2017/01/18 02:08:20
Nit: integer -> value
I'm not a fan of naming a v
gonzalon
2017/01/18 15:29:32
Done.
| |
692 array[i++] = integer; | |
693 } | |
694 return array; | |
695 } | |
696 | |
651 private static native void nativeOnWebappDataStored(long callbackPointer); | 697 private static native void nativeOnWebappDataStored(long callbackPointer); |
698 private static native void nativeOnWebApksFound(long callbackPointer, String [] shortNames, | |
699 String[] packageName, int[] shellApkVersions, int[] versionCodes); | |
652 } | 700 } |
OLD | NEW |