Merge "Add an API for retrieving information about the current WebView package."

This commit is contained in:
TreeHugger Robot
2016-10-17 18:06:43 +00:00
committed by Android (Google) Code Review
9 changed files with 118 additions and 15 deletions

View File

@@ -63,6 +63,11 @@ interface IWebViewUpdateService {
*/
String getCurrentWebViewPackageName();
/**
* Used by public API for debugging purposes.
*/
PackageInfo getCurrentWebViewPackage();
/**
* Used by Settings to determine whether a certain package can be enabled/disabled by the user -
* the package should not be modifiable in this way if it is a fallback package.

View File

@@ -21,6 +21,7 @@ import android.annotation.SystemApi;
import android.annotation.Widget;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Canvas;
@@ -36,6 +37,7 @@ import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.StrictMode;
import android.os.RemoteException;
import android.print.PrintDocumentAdapter;
import android.security.KeyChain;
import android.util.AttributeSet;
@@ -2673,6 +2675,26 @@ public class WebView extends AbsoluteLayout
return mProvider.getViewDelegate().findFocus(super.findFocus());
}
/**
* If WebView has already been loaded into the current process this method will return the
* package that was used to load it. Otherwise, the package that would be used if the WebView
* was loaded right now will be returned; this does not cause WebView to be loaded, so this
* information may become outdated at any time.
* @return the current WebView package, or null if there is none.
*/
public static PackageInfo getCurrentWebViewPackage() {
PackageInfo webviewPackage = WebViewFactory.getLoadedPackageInfo();
if (webviewPackage != null) {
return webviewPackage;
}
try {
return WebViewFactory.getUpdateService().getCurrentWebViewPackage();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Receive the result from a previous call to {@link #startActivityForResult(Intent, int)}.
*

View File

@@ -135,7 +135,9 @@ public final class WebViewFactory {
}
public static PackageInfo getLoadedPackageInfo() {
return sPackageInfo;
synchronized (sProviderLock) {
return sPackageInfo;
}
}
/**
@@ -170,9 +172,8 @@ public final class WebViewFactory {
Log.e(LOGTAG, "Couldn't find package " + packageName);
return LIBLOAD_WRONG_PACKAGE_NAME;
}
sPackageInfo = packageInfo;
int loadNativeRet = loadNativeLibrary(clazzLoader);
int loadNativeRet = loadNativeLibrary(clazzLoader, packageInfo);
// If we failed waiting for relro we want to return that fact even if we successfully load
// the relro file.
if (loadNativeRet == LIBLOAD_SUCCESS) return response.status;
@@ -358,7 +359,7 @@ public final class WebViewFactory {
ClassLoader clazzLoader = webViewContext.getClassLoader();
Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "WebViewFactory.loadNativeLibrary()");
loadNativeLibrary(clazzLoader);
loadNativeLibrary(clazzLoader, sPackageInfo);
Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "Class.forName()");
@@ -637,14 +638,14 @@ public final class WebViewFactory {
}
}
// Assumes that we have waited for relro creation and set sPackageInfo
private static int loadNativeLibrary(ClassLoader clazzLoader) {
// Assumes that we have waited for relro creation
private static int loadNativeLibrary(ClassLoader clazzLoader, PackageInfo packageInfo) {
if (!sAddressSpaceReserved) {
Log.e(LOGTAG, "can't load with relro file; address space not reserved");
return LIBLOAD_ADDRESS_SPACE_NOT_RESERVED;
}
String[] args = getWebViewNativeLibraryPaths(sPackageInfo);
String[] args = getWebViewNativeLibraryPaths(packageInfo);
int result = nativeLoadWithRelroFile(args[0] /* path32 */,
args[1] /* path64 */,
CHROMIUM_WEBVIEW_NATIVE_RELRO_32,