Commit 583dc4d2 authored by Jarryd's avatar Jarryd Committed by Commit Bot

WebInstall: Add cpp method to get installed apps on Android.

Change-Id: I61bd62d14c82c388915f712d7309f0b4f99bc715
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2238855
Commit-Queue: Jarryd Goodman <jarrydg@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#777472}
parent 31f2a2ea
...@@ -59,6 +59,7 @@ import org.chromium.webapk.lib.client.WebApkValidator; ...@@ -59,6 +59,7 @@ import org.chromium.webapk.lib.client.WebApkValidator;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Set;
/** /**
* This class contains functions related to adding shortcuts to the Android Home * This class contains functions related to adding shortcuts to the Android Home
...@@ -602,6 +603,13 @@ public class ShortcutHelper { ...@@ -602,6 +603,13 @@ public class ShortcutHelper {
origin.toLowerCase(Locale.getDefault())); origin.toLowerCase(Locale.getDefault()));
} }
@CalledByNative
static String[] getOriginsWithInstalledWebApksOrTwas() {
Set<String> originSet = WebappRegistry.getInstance().getOriginsWithInstalledApp();
String[] output = new String[originSet.size()];
return originSet.toArray(output);
}
/** /**
* Compresses a bitmap into a PNG and converts into a Base64 encoded string. * Compresses a bitmap into a PNG and converts into a Base64 encoded string.
* The encoded string can be decoded using {@link decodeBitmapFromString(String)}. * The encoded string can be decoded using {@link decodeBitmapFromString(String)}.
......
...@@ -353,6 +353,23 @@ bool ShortcutHelper::DoesOriginContainAnyInstalledTrustedWebActivity( ...@@ -353,6 +353,23 @@ bool ShortcutHelper::DoesOriginContainAnyInstalledTrustedWebActivity(
return Java_ShortcutHelper_doesOriginContainAnyInstalledTwa(env, java_origin); return Java_ShortcutHelper_doesOriginContainAnyInstalledTwa(env, java_origin);
} }
std::set<GURL> ShortcutHelper::GetOriginsWithInstalledWebApksOrTwas() {
std::set<GURL> installed_origins;
JNIEnv* env = base::android::AttachCurrentThread();
base::android::ScopedJavaLocalRef<jobjectArray> j_installed_origins =
Java_ShortcutHelper_getOriginsWithInstalledWebApksOrTwas(env);
if (j_installed_origins) {
std::vector<std::string> installed_origins_list;
base::android::AppendJavaStringArrayToStringVector(env, j_installed_origins,
&installed_origins_list);
for (auto& origin : installed_origins_list)
installed_origins.emplace(GURL(origin));
}
return installed_origins;
}
void ShortcutHelper::SetForceWebApkUpdate(const std::string& id) { void ShortcutHelper::SetForceWebApkUpdate(const std::string& id) {
JNIEnv* env = base::android::AttachCurrentThread(); JNIEnv* env = base::android::AttachCurrentThread();
Java_ShortcutHelper_setForceWebApkUpdate( Java_ShortcutHelper_setForceWebApkUpdate(
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define CHROME_BROWSER_ANDROID_SHORTCUT_HELPER_H_ #define CHROME_BROWSER_ANDROID_SHORTCUT_HELPER_H_
#include <memory> #include <memory>
#include <set>
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -106,6 +107,9 @@ class ShortcutHelper { ...@@ -106,6 +107,9 @@ class ShortcutHelper {
static bool DoesOriginContainAnyInstalledTrustedWebActivity( static bool DoesOriginContainAnyInstalledTrustedWebActivity(
const GURL& origin); const GURL& origin);
// Returns a set of origins that have an installed WebAPK or TWA.
static std::set<GURL> GetOriginsWithInstalledWebApksOrTwas();
// Sets a flag to force an update for the WebAPK corresponding to |id| on next // Sets a flag to force an update for the WebAPK corresponding to |id| on next
// launch. // launch.
static void SetForceWebApkUpdate(const std::string& id); static void SetForceWebApkUpdate(const std::string& id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment