Chromium Code Reviews| Index: chrome/android/webapk/libs/client/src/org/chromium/webapk/lib/client/WebApkValidator.java |
| diff --git a/chrome/android/webapk/libs/client/src/org/chromium/webapk/lib/client/WebApkValidator.java b/chrome/android/webapk/libs/client/src/org/chromium/webapk/lib/client/WebApkValidator.java |
| index 2fc1e46694f8cdc92fbab00bdff47e7cd9de9809..65c1e680d3d365463770e26c34c7346a473f50c4 100644 |
| --- a/chrome/android/webapk/libs/client/src/org/chromium/webapk/lib/client/WebApkValidator.java |
| +++ b/chrome/android/webapk/libs/client/src/org/chromium/webapk/lib/client/WebApkValidator.java |
| @@ -14,12 +14,18 @@ import android.content.pm.PackageManager; |
| import android.content.pm.PackageManager.NameNotFoundException; |
| import android.content.pm.ResolveInfo; |
| import android.content.pm.Signature; |
| +import android.os.Bundle; |
| +import android.os.RemoteException; |
| import android.os.StrictMode; |
| import android.support.annotation.Nullable; |
| import android.text.TextUtils; |
| import android.util.Log; |
| +import org.chromium.base.ContextUtils; |
| import org.chromium.base.annotations.SuppressFBWarnings; |
| +import org.chromium.webapk.lib.common.IdentityService.IIdentityService; |
| +import org.chromium.webapk.lib.common.WebApkHelper; |
| +import org.chromium.webapk.lib.common.WebApkMetaDataKeys; |
| import java.io.IOException; |
| import java.io.RandomAccessFile; |
| @@ -39,11 +45,31 @@ import java.util.List; |
| public class WebApkValidator { |
| private static final String TAG = "WebApkValidator"; |
| private static final String KEY_FACTORY = "EC"; // aka "ECDSA" |
| + private static final int SHELL_APK_VERSION_SUPPORTING_SWITCH_RUNTIME_HOST = 6; |
| private static byte[] sExpectedSignature; |
| private static byte[] sCommentSignedPublicKeyBytes; |
| private static PublicKey sCommentSignedPublicKey; |
| + /** Used to notified the consumer after checking the WebAPK's runtime host asynchronously. */ |
| + public interface CheckRuntimeHostCallback { void onCheckedRuntimeHost(String runtimeHost); } |
| + |
| + /** Callback to call after binding to the WebAPK's Identity Service is completed or failed. */ |
| + private abstract static class IdentityServiceConnectionCallback |
| + implements WebApkIdentityServiceConnectionManager.ConnectionCallback { |
| + public abstract void onGetRuntimeHostBrowserPackageName(IIdentityService service) |
| + throws RemoteException; |
| + |
| + @Override |
| + public void onConnected(IIdentityService service) { |
| + try { |
| + onGetRuntimeHostBrowserPackageName(service); |
| + } catch (RemoteException e) { |
| + Log.w(TAG, "Failed to use WebApk Identity Service.", e); |
| + } |
| + } |
| + } |
| + |
| /** |
| * Queries the PackageManager to determine whether a WebAPK can handle the URL. Ignores whether |
| * the user has selected a default handler for the URL and whether the default handler is the |
| @@ -103,6 +129,58 @@ public class WebApkValidator { |
| return false; |
| } |
| + /** |
| + * Returns the runtime host of a WebAPK, null if the WebAPK either doesn't have an Identity |
| + * Service or hasn't bind to any browser yet. |
| + * @param webApkPackageName The package name of the WebAPK. |
| + * @param callback The callback to be called after querying the runtime host is done. |
| + */ |
| + public static void queryWebApkRuntimeHostAsync( |
| + final String webApkPackageName, final CheckRuntimeHostCallback callback) { |
| + IdentityServiceConnectionCallback identityServiceCallback = |
| + new IdentityServiceConnectionCallback() { |
| + @Override |
| + public void onGetRuntimeHostBrowserPackageName(IIdentityService identityService) |
| + throws RemoteException { |
| + if (identityService == null) { |
| + callback.onCheckedRuntimeHost(null); |
| + return; |
| + } |
| + |
| + String runtimeHost = null; |
| + try { |
| + runtimeHost = identityService.getRuntimeHostBrowserPackageName(); |
| + } catch (RemoteException e) { |
| + Log.w(TAG, "Failed to get runtime host from the Identity Service."); |
| + callback.onCheckedRuntimeHost(null); |
| + return; |
| + } |
| + |
| + if (!TextUtils.isEmpty(runtimeHost)) { |
| + callback.onCheckedRuntimeHost(runtimeHost); |
| + return; |
| + } |
| + |
| + Context context = ContextUtils.getApplicationContext(); |
|
Yaron
2017/07/10 18:09:07
is this the right place put this? I would think th
Xi Han
2017/07/12 13:49:14
Thanks for catching this! If there is no identity
|
| + Bundle metadata = WebApkHelper.readMetaData( |
| + context.getPackageManager(), webApkPackageName); |
| + if (metadata.getInt(WebApkMetaDataKeys.SHELL_APK_VERSION) |
| + < SHELL_APK_VERSION_SUPPORTING_SWITCH_RUNTIME_HOST) { |
| + String runtimeHostFromMetadata = |
| + metadata.getString(WebApkMetaDataKeys.RUNTIME_HOST); |
| + if ((TextUtils.equals( |
| + context.getPackageName(), runtimeHostFromMetadata))) { |
| + runtimeHost = runtimeHostFromMetadata; |
| + } |
| + } |
| + callback.onCheckedRuntimeHost(runtimeHost); |
| + } |
| + }; |
| + |
| + WebApkIdentityServiceConnectionManager.getInstance().connect( |
|
Yaron
2017/07/10 18:09:07
this is never disconnected
Xi Han
2017/07/12 13:49:14
I assume the disconnect is called after chrome sto
|
| + ContextUtils.getApplicationContext(), webApkPackageName, identityServiceCallback); |
| + } |
| + |
| /** |
| * Fetches the list of resolve infos from the PackageManager that can handle the URL. |
| * |