WebViewZygoteInit: minor cleanup to handlePreloadPackage.

Make sure that the preload method returns a boolean to avoid the
possibility of a NullPointerException or a ClassCastException during
the boxing / casting of its return value.

Test: manual
Change-Id: I483edc8f8726de4359fc37304ca7019024eaf577
This commit is contained in:
Narayan Kamath
2017-07-06 12:38:55 +01:00
parent c276c79e83
commit 6f6e8945f7

View File

@@ -29,7 +29,7 @@ import android.webkit.WebViewFactoryProvider;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
* Startup class for the WebView zygote process.
@@ -92,13 +92,18 @@ class WebViewZygoteInit {
try {
Class<WebViewFactoryProvider> providerClass =
WebViewFactory.getWebViewProviderClass(loader);
Object result = providerClass.getMethod("preloadInZygote").invoke(null);
preloadSucceeded = ((Boolean) result).booleanValue();
if (!preloadSucceeded) {
Log.e(TAG, "preloadInZygote returned false");
Method preloadInZygote = providerClass.getMethod("preloadInZygote");
preloadInZygote.setAccessible(true);
if (preloadInZygote.getReturnType() != Boolean.TYPE) {
Log.e(TAG, "Unexpected return type: preloadInZygote must return boolean");
} else {
preloadSucceeded = (boolean) providerClass.getMethod("preloadInZygote")
.invoke(null);
if (!preloadSucceeded) {
Log.e(TAG, "preloadInZygote returned false");
}
}
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException |
IllegalAccessException | InvocationTargetException e) {
} catch (ReflectiveOperationException e) {
Log.e(TAG, "Exception while preloading package", e);
}