Expand WebView package visibility bug workaround.
The known issue with apps losing the ability to see WebView in certain cases on Android R/S/T was already being worked around for the case of trying to start a child process service, but the problem also applies to other cases where WebView looks up its own package information, such as while initializing Crashpad. Move the existing workaround to PackageUtils and use it from getApplicationPackageInfo as well, so that it's applied in those cases too. Bug: 345359075 Change-Id: I5706a99e063399d2adb63d0395bbd0b98b58d068 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5958849 Auto-Submit: Richard (Torne) Coles <torne@chromium.org> Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com> Commit-Queue: Andrew Grieve <agrieve@chromium.org> Reviewed-by: Andrew Grieve <agrieve@chromium.org> Cr-Commit-Position: refs/heads/main@{#1373071}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
bc75534e95
commit
4aa22bc5d2
base/android/java/src/org/chromium/base
@ -8,12 +8,14 @@ import android.annotation.SuppressLint;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.Signature;
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.CertificateException;
|
||||
@ -60,17 +62,48 @@ public class PackageUtils {
|
||||
return getPackageInfo(packageName, 0) != null;
|
||||
}
|
||||
|
||||
/** Returns the PackageInfo for the current app, as retrieve by PackageManager. */
|
||||
/** Returns the PackageInfo for the Chromium app, as retrieved by PackageManager. */
|
||||
public static PackageInfo getApplicationPackageInfo(int flags) {
|
||||
PackageInfo ret = getPackageInfo(BuildInfo.getInstance().packageName, flags);
|
||||
BuildInfo bi = BuildInfo.getInstance();
|
||||
|
||||
// In WebView the Chromium app is not the same package as the current app, and there is a
|
||||
// platform bug where this lookup can fail in rare cases; try to work around it.
|
||||
if (!bi.packageName.equals(bi.hostPackageName)) {
|
||||
maybeWorkAroundWebViewPackageVisibility();
|
||||
}
|
||||
|
||||
PackageInfo ret = getPackageInfo(bi.packageName, flags);
|
||||
assert ret != null;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Need to call an internal method to work around a framework bug.
|
||||
@SuppressWarnings("PrivateApi")
|
||||
public static void maybeWorkAroundWebViewPackageVisibility() {
|
||||
// On R/S/T it's possible for the app to lose visibility of the WebView package in rare
|
||||
// cases; see crbug.com/1363832 - we attempt to get re-granted visibility to work around it.
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R
|
||||
|| Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Class wvus = Class.forName("android.webkit.WebViewUpdateService");
|
||||
Method getWebViewPackageName = wvus.getDeclaredMethod("getCurrentWebViewPackageName");
|
||||
// Calling this for the side effect of granting implicit visibility..
|
||||
getWebViewPackageName.invoke(null);
|
||||
} catch (Exception e) {
|
||||
// Don't crash the host app; the workaround is only necessary in a few special cases,
|
||||
// so failing is okay.
|
||||
Log.w(TAG, "maybeWorkAroundWebViewPackageVisibility failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the SHA256 certificates for the given package name. The app with the given package
|
||||
* name has to be installed on device. The output will be a list of 30 long HEX strings with :
|
||||
* between each value. There will be one string for each signature the app is signed with.
|
||||
*
|
||||
* @param packageName The package name to query the signature for.
|
||||
* @return The SHA256 certificate for the package name.
|
||||
*/
|
||||
|
@ -21,10 +21,10 @@ import org.chromium.base.BuildInfo;
|
||||
import org.chromium.base.ContextUtils;
|
||||
import org.chromium.base.JavaUtils;
|
||||
import org.chromium.base.Log;
|
||||
import org.chromium.base.PackageUtils;
|
||||
import org.chromium.base.ResettersForTesting;
|
||||
import org.chromium.base.SysUtils;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -101,30 +101,12 @@ public abstract class ChildConnectionAllocator {
|
||||
|
||||
/* package */ ConnectionFactory mConnectionFactory = new ConnectionFactoryImpl();
|
||||
|
||||
// Need to call an internal method to work around a framework bug.
|
||||
@SuppressWarnings("PrivateApi")
|
||||
private static void workAroundWebViewPackageVisibility() {
|
||||
try {
|
||||
Class wvus = Class.forName("android.webkit.WebViewUpdateService");
|
||||
Method getWVPN = wvus.getDeclaredMethod("getCurrentWebViewPackageName");
|
||||
// Calling this for the side effect of granting implicit visibility..
|
||||
getWVPN.invoke(null);
|
||||
} catch (Exception e) {
|
||||
// Don't crash the host app; the workaround is only necessary in a few special cases,
|
||||
// so failing is okay.
|
||||
Log.w(TAG, "workAroundWebViewPackageVisibility failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkServiceExists(
|
||||
Context context, String packageName, String serviceClassName) {
|
||||
// On R/S/T it's possible for the app to lose visibility of the WebView package in rare
|
||||
// cases; see crbug.com/1363832 - we attempt to get re-granted visibility here to work
|
||||
// around it.
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R
|
||||
&& Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE
|
||||
&& !packageName.equals(context.getPackageName())) {
|
||||
workAroundWebViewPackageVisibility();
|
||||
if (!packageName.equals(context.getPackageName())) {
|
||||
// If the service isn't in our own package we may need to work
|
||||
// around crbug.com/1363832.
|
||||
PackageUtils.maybeWorkAroundWebViewPackageVisibility();
|
||||
}
|
||||
|
||||
PackageManager packageManager = context.getPackageManager();
|
||||
|
Reference in New Issue
Block a user