Commit 6e0dc1f3 authored by Clark DuVall's avatar Clark DuVall Committed by Commit Bot

[WebLayer] Add package names to shared library exception

This will help debug why exactly WebLayer is not getting package id
0x02.

Bug: 1045262
Change-Id: Ib05d3eb81bf25120bf34d4997440c73cbbbdedb1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2080779Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Commit-Queue: Clark DuVall <cduvall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#745993}
parent 1d939748
......@@ -12,6 +12,7 @@ import android.content.res.AssetManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.AndroidRuntimeException;
import android.util.SparseArray;
import android.webkit.ValueCallback;
......@@ -52,6 +53,8 @@ import org.chromium.weblayer_private.metrics.UmaUtils;
import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
/**
* Root implementation class for WebLayer.
......@@ -179,7 +182,9 @@ public final class WebLayerImpl extends IWebLayer.Stub {
BuildInfo.setBrowserPackageInfo(packageInfo);
int resourcesPackageId = getPackageId(appContext, packageInfo.packageName);
if (resourcesPackageId < 0x7f && resourcesPackageId != 2) {
throw new AndroidRuntimeException("WebLayer can't be used with another shared library");
throw new AndroidRuntimeException(
"WebLayer can't be used with another shared library. Loaded packages: "
+ getLoadedPackageNames(appContext));
}
// TODO: The call to onResourcesLoaded() can be slow, we may need to parallelize this with
// other expensive startup tasks.
......@@ -348,6 +353,29 @@ public final class WebLayerImpl extends IWebLayer.Stub {
}
}
/** Gets a string with all the loaded package names in this context. */
private static String getLoadedPackageNames(Context appContext) {
try {
Method getAssignedPackageIdentifiers =
AssetManager.class.getMethod("getAssignedPackageIdentifiers");
SparseArray packageIdentifiers = (SparseArray) getAssignedPackageIdentifiers.invoke(
appContext.getResources().getAssets());
List<String> packageNames = new ArrayList<>();
for (int i = 0; i < packageIdentifiers.size(); i++) {
String name = (String) packageIdentifiers.valueAt(i);
int key = packageIdentifiers.keyAt(i);
// This is the android package.
if (key == 1) {
continue;
}
packageNames.add(name + ":" + key);
}
return TextUtils.join(",", packageNames);
} catch (ReflectiveOperationException e) {
return "unknown";
}
}
private void loadNativeLibrary(String packageName) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
WebViewFactory.loadWebViewNativeLibraryFromPackage(
......
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