Skip to content

Commit 0fb1764

Browse files
tornewuffAndroid (Google) Code Review
authored andcommitted
Merge "Make WebViewFactory more robust." into lmp-dev
2 parents a3d98c2 + 27cb0d2 commit 0fb1764

1 file changed

Lines changed: 30 additions & 26 deletions

File tree

core/java/android/webkit/WebViewFactory.java

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ public static void prepareWebViewInSystemServer() {
175175
String[] nativePaths = null;
176176
try {
177177
nativePaths = getWebViewNativeLibraryPaths();
178-
} catch (PackageManager.NameNotFoundException e) {
178+
} catch (Throwable t) {
179+
// Log and discard errors at this stage as we must not crash the system server.
180+
Log.e(LOGTAG, "error preparing webview native library", t);
179181
}
180182
prepareWebViewInSystemServer(nativePaths);
181183
}
@@ -201,35 +203,37 @@ public static void onWebViewUpdateInstalled() {
201203
String[] nativeLibs = null;
202204
try {
203205
nativeLibs = WebViewFactory.getWebViewNativeLibraryPaths();
204-
} catch (PackageManager.NameNotFoundException e) {
205-
}
206-
207-
if (nativeLibs != null) {
208-
long newVmSize = 0L;
209-
210-
for (String path : nativeLibs) {
211-
if (DEBUG) Log.d(LOGTAG, "Checking file size of " + path);
212-
if (path == null) continue;
213-
File f = new File(path);
214-
if (f.exists()) {
215-
long length = f.length();
216-
if (length > newVmSize) {
217-
newVmSize = length;
206+
if (nativeLibs != null) {
207+
long newVmSize = 0L;
208+
209+
for (String path : nativeLibs) {
210+
if (DEBUG) Log.d(LOGTAG, "Checking file size of " + path);
211+
if (path == null) continue;
212+
File f = new File(path);
213+
if (f.exists()) {
214+
long length = f.length();
215+
if (length > newVmSize) {
216+
newVmSize = length;
217+
}
218218
}
219219
}
220-
}
221220

222-
if (DEBUG) {
223-
Log.v(LOGTAG, "Based on library size, need " + newVmSize +
224-
" bytes of address space.");
221+
if (DEBUG) {
222+
Log.v(LOGTAG, "Based on library size, need " + newVmSize +
223+
" bytes of address space.");
224+
}
225+
// The required memory can be larger than the file on disk (due to .bss), and an
226+
// upgraded version of the library will likely be larger, so always attempt to
227+
// reserve twice as much as we think to allow for the library to grow during this
228+
// boot cycle.
229+
newVmSize = Math.max(2 * newVmSize, CHROMIUM_WEBVIEW_DEFAULT_VMSIZE_BYTES);
230+
Log.d(LOGTAG, "Setting new address space to " + newVmSize);
231+
SystemProperties.set(CHROMIUM_WEBVIEW_VMSIZE_SIZE_PROPERTY,
232+
Long.toString(newVmSize));
225233
}
226-
// The required memory can be larger than the file on disk (due to .bss), and an
227-
// upgraded version of the library will likely be larger, so always attempt to reserve
228-
// twice as much as we think to allow for the library to grow during this boot cycle.
229-
newVmSize = Math.max(2 * newVmSize, CHROMIUM_WEBVIEW_DEFAULT_VMSIZE_BYTES);
230-
Log.d(LOGTAG, "Setting new address space to " + newVmSize);
231-
SystemProperties.set(CHROMIUM_WEBVIEW_VMSIZE_SIZE_PROPERTY,
232-
Long.toString(newVmSize));
234+
} catch (Throwable t) {
235+
// Log and discard errors at this stage as we must not crash the system server.
236+
Log.e(LOGTAG, "error preparing webview native library", t);
233237
}
234238
prepareWebViewInSystemServer(nativeLibs);
235239
}

0 commit comments

Comments
 (0)