Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 161536b5 authored by Primiano Tucci's avatar Primiano Tucci Committed by Ben Murdoch
Browse files

Cherry pick Refactor ActivityManagerService and make WebViewFactory more pedantic. DO NOT MERGE

This CL adds more robustness to the logic in WebViewFactory, checking
whether the isolated process did start at all and catching exceptions
in its java side.
Also, this addresses the refactor comments received in CL 509840.

Original BUG:16403706
Original Change-Id: Iaaea6d36142ece6d974c2438259edf421fce9f2e

Bug: 16723226
Change-Id: Id308f2ffde9b67a3eb4719c7b81b4f46421f0c2e
parent 1b7977b6
Loading
Loading
Loading
Loading
+14 −13
Original line number Diff line number Diff line
@@ -215,9 +215,10 @@ public final class WebViewFactory {

        try {
            String[] args = getWebViewNativeLibraryPaths();
            LocalServices.getService(ActivityManagerInternal.class).startIsolatedProcess(
            int pid = LocalServices.getService(ActivityManagerInternal.class).startIsolatedProcess(
                    RelroFileCreator.class.getName(), args, "WebViewLoader-" + abi, abi,
                    Process.SHARED_RELRO_UID, crashHandler);
            if (pid <= 0) throw new Exception("Failed to start the isolated process");
        } catch (Throwable t) {
            // Log and discard errors as we must not crash the system server.
            Log.e(LOGTAG, "error starting relro file creator for abi " + abi, t);
@@ -228,34 +229,34 @@ public final class WebViewFactory {
    private static class RelroFileCreator {
        // Called in an unprivileged child process to create the relro file.
        public static void main(String[] args) {
            boolean result = false;
            boolean is64Bit = VMRuntime.getRuntime().is64Bit();
            try{
                if (args.length != 2 || args[0] == null || args[1] == null) {
                    Log.e(LOGTAG, "Invalid RelroFileCreator args: " + Arrays.toString(args));
                    return;
                }

                boolean is64Bit = VMRuntime.getRuntime().is64Bit();
                Log.v(LOGTAG, "RelroFileCreator (64bit = " + is64Bit + "), " +
                        " 32-bit lib: " + args[0] + ", 64-bit lib: " + args[1]);
                if (!sAddressSpaceReserved) {
                    Log.e(LOGTAG, "can't create relro file; address space not reserved");
                    return;
                }
                boolean result = nativeCreateRelroFile(args[0] /* path32 */,
                result = nativeCreateRelroFile(args[0] /* path32 */,
                                               args[1] /* path64 */,
                                               CHROMIUM_WEBVIEW_NATIVE_RELRO_32,
                                               CHROMIUM_WEBVIEW_NATIVE_RELRO_64);
                if (!result) {
                    Log.e(LOGTAG, "failed to create relro file");
                } else if (DEBUG) {
                    Log.v(LOGTAG, "created relro file");
                }
                if (DEBUG) Log.v(LOGTAG, "created relro file");
            } finally {
                // We must do our best to always notify the update service, even if something fails.
                try {
                    getUpdateService().notifyRelroCreationCompleted(is64Bit, result);
                } catch (RemoteException e) {
                    Log.e(LOGTAG, "error notifying update service", e);
                }
            } finally {

                if (!result) Log.e(LOGTAG, "failed to create relro file");

                // Must explicitly exit or else this process will just sit around after we return.
                System.exit(0);
            }
+17 −15
Original line number Diff line number Diff line
@@ -2952,10 +2952,14 @@ public final class ActivityManagerService extends ActivityManagerNative
        return (ai.flags&ApplicationInfo.FLAG_PERSISTENT) != 0;
    }
    private final void startProcessLocked(ProcessRecord app,
            String hostingType, String hostingNameStr) {
        startProcessLocked(app, hostingType, hostingNameStr, null /* abiOverride */,
                null /* entryPoint */, null /* entryPointArgs */);
    }
    private final void startProcessLocked(ProcessRecord app, String hostingType,
            String hostingNameStr, String abiOverride, String entryPoint, String[] entryPointArgs) {
        boolean isActivityProcess = (entryPoint == null);
        if (entryPoint == null) entryPoint = "android.app.ActivityThread";
        if (app.pid > 0 && app.pid != MY_PID) {
            synchronized (mPidsSelfLocked) {
                mPidsSelfLocked.remove(app.pid);
@@ -3048,6 +3052,8 @@ public final class ActivityManagerService extends ActivityManagerNative
            // Start the process.  It will either succeed and return a result containing
            // the PID of the new process, or else throw a RuntimeException.
            boolean isActivityProcess = (entryPoint == null);
            if (entryPoint == null) entryPoint = "android.app.ActivityThread";
            Process.ProcessStartResult startResult = Process.start(entryPoint,
                    app.processName, uid, uid, gids, debugFlags, mountExternal,
                    app.info.targetSdkVersion, app.info.seinfo, requiredAbi, entryPointArgs);
@@ -5380,8 +5386,7 @@ public final class ActivityManagerService extends ActivityManagerNative
            app.deathRecipient = adr;
        } catch (RemoteException e) {
            app.resetPackageList(mProcessStats);
            startProcessLocked(app, "link fail", processName, null /* ABI override */,
                    null /* entryPoint */, null /* entryPointArgs */);
            startProcessLocked(app, "link fail", processName);
            return false;
        }
@@ -5474,8 +5479,7 @@ public final class ActivityManagerService extends ActivityManagerNative
            app.resetPackageList(mProcessStats);
            app.unlinkDeathRecipient();
            startProcessLocked(app, "bind fail", processName, null /* ABI override */,
                    null /* entryPoint */, null /* entryPointArgs */);
            startProcessLocked(app, "bind fail", processName);
            return false;
        }
@@ -5630,8 +5634,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                for (int ip=0; ip<NP; ip++) {
                    if (DEBUG_PROCESSES) Slog.v(TAG, "Starting process on hold: "
                            + procs.get(ip));
                    startProcessLocked(procs.get(ip), "on-hold", null, null /* ABI override */,
                            null /* entryPoint */, null /* entryPointArgs */);
                    startProcessLocked(procs.get(ip), "on-hold", null);
                }
            }
            
@@ -13548,8 +13551,7 @@ public final class ActivityManagerService extends ActivityManagerNative
            // We have components that still need to be running in the
            // process, so re-launch it.
            mProcessNames.put(app.processName, app.uid, app);
            startProcessLocked(app, "restart", app.processName, null /* ABI override */,
                    null /* entryPoint */, null /* entryPointArgs */);
            startProcessLocked(app, "restart", app.processName);
        } else if (app.pid > 0 && app.pid != MY_PID) {
            // Goodbye!
            boolean removed;
@@ -17899,12 +17901,12 @@ public final class ActivityManagerService extends ActivityManagerNative
                info.processName = processName;
                info.className = entryPoint;
                info.packageName = "android";
                startProcessLocked(processName, info /* info */, false /* knownToBeDead */,
                        0 /* intentFlags */, ""  /* hostingType */, null /* hostingName */,
                        true /* allowWhileBooting */, true /* isolated */, uid,
                        true /* keepIfLarge */, abiOverride, entryPoint, entryPointArgs,
                ProcessRecord proc = startProcessLocked(processName, info /* info */,
                        false /* knownToBeDead */, 0 /* intentFlags */, ""  /* hostingType */,
                        null /* hostingName */, true /* allowWhileBooting */, true /* isolated */,
                        uid, true /* keepIfLarge */, abiOverride, entryPoint, entryPointArgs,
                        crashHandler);
                return 0;
                return proc.pid;
            }
        }
    }