From fd99e1005540fc3c78c0e4661126b22e86403cff Mon Sep 17 00:00:00 2001 From: Bo Liu Date: Tue, 14 Feb 2017 10:39:38 -0800 Subject: [PATCH] Revert on M57 "Bind Android ChildProcessServices to a specific client PID." Suspect cause of crbug.com/690118 > Bind Android ChildProcessServices to a specific client PID. > > A ChildProcessService may only be setup once, but nothing enforced this limit, > and a second client of the service would receive no indication of failure. This > situation could occur with Android WebView in multi-process mode, if two > android:processes in the same package tried to use WebView. > > To solve this issue, introduce an initial handshake message in > IChildProcessService that must be issued before setupConnection. This method > binds the service to the calling PID. If that binding fails, the > ChildProcessLauncher can then re-try creating a service process using the > next available slot. > > BUG=558377,683133 > > Review-Url: https://codereview.chromium.org/2626413004 > Cr-Commit-Position: refs/heads/master@{#445779} > (cherry picked from commit abd3ee77b9cfd7b3d8cf5f95c511e328645f8fde) > > Review-Url: https://codereview.chromium.org/2650013003 . > Cr-Commit-Position: refs/branch-heads/2987@{#68} > Cr-Branched-From: ad51088c0e8776e8dcd963dbe752c4035ba6dab6-refs/heads/master@{#444943} BUG=690118 Review-Url: https://codereview.chromium.org/2695083002 . Cr-Commit-Position: refs/branch-heads/2987@{#502} Cr-Branched-From: ad51088c0e8776e8dcd963dbe752c4035ba6dab6-refs/heads/master@{#444943} --- .../content/app/ChildProcessServiceImpl.java | 39 +---- .../browser/ChildProcessConnection.java | 21 +-- .../browser/ChildProcessConnectionImpl.java | 22 +-- .../content/browser/ChildProcessLauncher.java | 113 ++------------ .../content/common/IChildProcessService.aidl | 5 - .../src/org/chromium/content/common/OWNERS | 2 - .../browser/ChildProcessLauncherTest.java | 147 ------------------ .../browser/BindingManagerImplTest.java | 14 +- content/shell/android/BUILD.gn | 1 - .../shell_apk/AndroidManifest.xml.jinja2 | 2 - ...ChildProcessLauncherTestHelperService.java | 99 ------------ 11 files changed, 28 insertions(+), 437 deletions(-) delete mode 100644 content/public/android/java/src/org/chromium/content/common/OWNERS delete mode 100644 content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ChildProcessLauncherTestHelperService.java diff --git a/content/public/android/java/src/org/chromium/content/app/ChildProcessServiceImpl.java b/content/public/android/java/src/org/chromium/content/app/ChildProcessServiceImpl.java index 0deff1fa93b9..fde50c8f4b24 100644 --- a/content/public/android/java/src/org/chromium/content/app/ChildProcessServiceImpl.java +++ b/content/public/android/java/src/org/chromium/content/app/ChildProcessServiceImpl.java @@ -53,12 +53,7 @@ public class ChildProcessServiceImpl { private static final String MAIN_THREAD_NAME = "ChildProcessMain"; private static final String TAG = "ChildProcessService"; - - // Lock that protects the following members. - private final Object mBinderLock = new Object(); private IChildProcessCallback mCallback; - // PID of the client of this service, set in bindToCaller(). - private int mBoundCallingPid; // This is the native "Main" thread for the renderer / utility process. private Thread mMainThread; @@ -101,39 +96,11 @@ private Linker getLinker() { // Binder object used by clients for this service. private final IChildProcessService.Stub mBinder = new IChildProcessService.Stub() { // NOTE: Implement any IChildProcessService methods here. - @Override - public boolean bindToCaller() { - synchronized (mBinderLock) { - int callingPid = Binder.getCallingPid(); - if (mBoundCallingPid == 0) { - mBoundCallingPid = callingPid; - } else if (mBoundCallingPid != callingPid) { - Log.e(TAG, "Service is already bound by pid %d, cannot bind for pid %d", - mBoundCallingPid, callingPid); - return false; - } - } - return true; - } - @Override public int setupConnection(Bundle args, IChildProcessCallback callback) { - int callingPid = Binder.getCallingPid(); - synchronized (mBinderLock) { - if (mBoundCallingPid != callingPid) { - if (mBoundCallingPid == 0) { - Log.e(TAG, "Service has not been bound with bindToCaller()"); - } else { - Log.e(TAG, "Client pid %d does not match the bound pid %d", callingPid, - mBoundCallingPid); - } - return -1; - } - - mCallback = callback; - getServiceInfo(args); - return Process.myPid(); - } + mCallback = callback; + getServiceInfo(args); + return Process.myPid(); } @Override diff --git a/content/public/android/java/src/org/chromium/content/browser/ChildProcessConnection.java b/content/public/android/java/src/org/chromium/content/browser/ChildProcessConnection.java index 5010aa96c61a..8f935906aa8d 100644 --- a/content/public/android/java/src/org/chromium/content/browser/ChildProcessConnection.java +++ b/content/public/android/java/src/org/chromium/content/browser/ChildProcessConnection.java @@ -26,24 +26,6 @@ interface DeathCallback { void onChildProcessDied(ChildProcessConnection connection); } - /** - * Used to notify the consumer about the process start. These callbacks will be invoked before - * the ConnectionCallbacks. - */ - interface StartCallback { - /** - * Called when the child process has successfully started and is ready for connection - * setup. - */ - void onChildStarted(); - - /** - * Called when the child process failed to start. This can happen if the process is already - * in use by another client. - */ - void onChildStartFailed(); - } - /** * Used to notify the consumer about the connection being established. */ @@ -75,9 +57,8 @@ interface ConnectionCallback { * remainder later while reducing the connection setup latency. * @param commandLine (optional) command line for the child process. If omitted, then * the command line parameters must instead be passed to setupConnection(). - * @param startCallback (optional) callback when the child process starts or fails to start. */ - void start(String[] commandLine, StartCallback startCallback); + void start(String[] commandLine); /** * Setups the connection after it was started with start(). diff --git a/content/public/android/java/src/org/chromium/content/browser/ChildProcessConnectionImpl.java b/content/public/android/java/src/org/chromium/content/browser/ChildProcessConnectionImpl.java index d15a9ca287ab..9dac1747ef0d 100644 --- a/content/public/android/java/src/org/chromium/content/browser/ChildProcessConnectionImpl.java +++ b/content/public/android/java/src/org/chromium/content/browser/ChildProcessConnectionImpl.java @@ -97,9 +97,6 @@ private static class ConnectionParams { } } - // This is set in start() and is used in onServiceConnected(). - private ChildProcessConnection.StartCallback mStartCallback; - // This is set in setupConnection() and is later used in doConnectionSetupLocked(), after which // the variable is cleared. Therefore this is only valid while the connection is being set up. private ConnectionParams mConnectionParams; @@ -171,21 +168,6 @@ public void onServiceConnected(ComponentName className, IBinder service) { "ChildProcessConnectionImpl.ChildServiceConnection.onServiceConnected"); mServiceConnectComplete = true; mService = IChildProcessService.Stub.asInterface(service); - - boolean boundToUs = false; - try { - boundToUs = mService.bindToCaller(); - } catch (RemoteException ex) { - } - if (!boundToUs) { - if (mStartCallback != null) { - mStartCallback.onChildStartFailed(); - } - return; - } else if (mStartCallback != null) { - mStartCallback.onChildStarted(); - } - // Run the setup if the connection parameters have already been provided. If // not, doConnectionSetupLocked() will be called from setupConnection(). if (mConnectionParams != null) { @@ -307,7 +289,7 @@ public int getPid() { } @Override - public void start(String[] commandLine, ChildProcessConnection.StartCallback startCallback) { + public void start(String[] commandLine) { try { TraceEvent.begin("ChildProcessConnectionImpl.start"); synchronized (mLock) { @@ -315,8 +297,6 @@ public void start(String[] commandLine, ChildProcessConnection.StartCallback sta assert mConnectionParams == null : "setupConnection() called before start() in ChildProcessConnectionImpl."; - mStartCallback = startCallback; - if (!mInitialBinding.bind(commandLine)) { Log.e(TAG, "Failed to establish the service connection."); // We have to notify the caller so that they can free-up associated resources. diff --git a/content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncher.java b/content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncher.java index 3ae8def576b7..aed55c3f5328 100644 --- a/content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncher.java +++ b/content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncher.java @@ -8,7 +8,6 @@ import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; -import android.os.AsyncTask; import android.os.Bundle; import android.os.ParcelFileDescriptor; import android.os.RemoteException; @@ -414,13 +413,12 @@ private static ChromiumLinkerParams getLinkerParamsForNewConnection() { private static ChildProcessConnection allocateBoundConnection(Context context, String[] commandLine, boolean inSandbox, boolean alwaysInForeground, - ChildProcessCreationParams creationParams, - ChildProcessConnection.StartCallback startCallback) { + ChildProcessCreationParams creationParams) { ChromiumLinkerParams chromiumLinkerParams = getLinkerParamsForNewConnection(); ChildProcessConnection connection = allocateConnection( context, inSandbox, chromiumLinkerParams, alwaysInForeground, creationParams); if (connection != null) { - connection.start(commandLine, startCallback); + connection.start(commandLine); String packageName = creationParams != null ? creationParams.getPackageName() : context.getPackageName(); @@ -438,7 +436,7 @@ private static ChildProcessConnection allocateBoundConnection(Context context, private static final long FREE_CONNECTION_DELAY_MILLIS = 1; private static void freeConnection(ChildProcessConnection connection) { - synchronized (sSpareConnectionLock) { + synchronized (ChildProcessLauncher.class) { if (connection.equals(sSpareSandboxedConnection)) sSpareSandboxedConnection = null; } @@ -485,16 +483,8 @@ private static PendingSpawnData freeConnectionAndDequeuePending(ChildProcessConn private static Map sServiceMap = new ConcurrentHashMap(); - // Lock and monitor for these members {{{ - private static final Object sSpareConnectionLock = new Object(); // A pre-allocated and pre-bound connection ready for connection setup, or null. private static ChildProcessConnection sSpareSandboxedConnection; - // If sSpareSandboxedConnection is not null, this indicates whether the service is - // ready for connection setup. Wait on the monitor lock to be notified when this - // state changes. sSpareSandboxedConnection may be null after waiting, if starting - // the service failed. - private static boolean sSpareConnectionStarting; - // }}} // Manages oom bindings used to bind chind services. private static BindingManager sBindingManager = BindingManagerImpl.createBindingManager(); @@ -577,38 +567,15 @@ static boolean isApplicationInForeground() { * @param context the application context used for the connection. */ public static void warmUp(Context context) { - synchronized (sSpareConnectionLock) { + synchronized (ChildProcessLauncher.class) { assert !ThreadUtils.runningOnUiThread(); if (sSpareSandboxedConnection == null) { ChildProcessCreationParams params = ChildProcessCreationParams.get(); if (params != null) { params = params.copy(); } - - sSpareConnectionStarting = true; - - ChildProcessConnection.StartCallback startCallback = - new ChildProcessConnection.StartCallback() { - @Override - public void onChildStarted() { - synchronized (sSpareConnectionLock) { - sSpareConnectionStarting = false; - sSpareConnectionLock.notify(); - } - } - - @Override - public void onChildStartFailed() { - Log.e(TAG, "Failed to warm up the spare sandbox service"); - synchronized (sSpareConnectionLock) { - sSpareSandboxedConnection = null; - sSpareConnectionStarting = false; - sSpareConnectionLock.notify(); - } - } - }; sSpareSandboxedConnection = allocateBoundConnection(context, null, true, false, - params, startCallback); + params); } } } @@ -686,30 +653,24 @@ private static void start(Context context, final String[] commandLine, int child callbackType, inSandbox, params); } - private static ChildProcessConnection startInternal( - final Context context, + private static void startInternal( + Context context, final String[] commandLine, - final int childProcessId, - final FileDescriptorInfo[] filesToBeMapped, - final long clientContext, - final int callbackType, - final boolean inSandbox, - final ChildProcessCreationParams creationParams) { + int childProcessId, + FileDescriptorInfo[] filesToBeMapped, + long clientContext, + int callbackType, + boolean inSandbox, + ChildProcessCreationParams creationParams) { try { TraceEvent.begin("ChildProcessLauncher.startInternal"); ChildProcessConnection allocatedConnection = null; String packageName = creationParams != null ? creationParams.getPackageName() : context.getPackageName(); - synchronized (sSpareConnectionLock) { + synchronized (ChildProcessLauncher.class) { if (inSandbox && sSpareSandboxedConnection != null && sSpareSandboxedConnection.getPackageName().equals(packageName)) { - while (sSpareConnectionStarting) { - try { - sSpareConnectionLock.wait(); - } catch (InterruptedException ex) { - } - } allocatedConnection = sSpareSandboxedConnection; sSpareSandboxedConnection = null; } @@ -719,39 +680,15 @@ private static ChildProcessConnection startInternal( if (callbackType == CALLBACK_FOR_GPU_PROCESS) alwaysInForeground = true; PendingSpawnQueue pendingSpawnQueue = getPendingSpawnQueue( context, packageName, inSandbox); - ChildProcessConnection.StartCallback startCallback = - new ChildProcessConnection.StartCallback() { - @Override - public void onChildStarted() {} - - @Override - public void onChildStartFailed() { - Log.e(TAG, "ChildProcessConnection.start failed, trying again"); - AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() { - @Override - public void run() { - // The child process may already be bound to another client - // (this can happen if multi-process WebView is used in more - // than one process), so try starting the process again. - // This connection that failed to start has not been freed, - // so a new bound connection will be allocated. - startInternal(context, commandLine, childProcessId, - filesToBeMapped, clientContext, callbackType, - inSandbox, creationParams); - } - }); - } - }; synchronized (pendingSpawnQueue.mPendingSpawnsLock) { allocatedConnection = allocateBoundConnection( - context, commandLine, inSandbox, alwaysInForeground, creationParams, - startCallback); + context, commandLine, inSandbox, alwaysInForeground, creationParams); if (allocatedConnection == null) { Log.d(TAG, "Allocation of new service failed. Queuing up pending spawn."); pendingSpawnQueue.enqueueLocked(new PendingSpawnData(context, commandLine, childProcessId, filesToBeMapped, clientContext, callbackType, inSandbox, creationParams)); - return null; + return; } } } @@ -760,7 +697,6 @@ public void run() { allocatedConnection.getServiceNumber()); triggerConnectionSetup(allocatedConnection, commandLine, childProcessId, filesToBeMapped, callbackType, clientContext); - return allocatedConnection; } finally { TraceEvent.end("ChildProcessLauncher.startInternal"); } @@ -897,17 +833,10 @@ static void logPidWarning(int pid, String message) { } } - @VisibleForTesting - public static ChildProcessConnection startForTesting(Context context, String[] commandLine, - FileDescriptorInfo[] filesToMap, ChildProcessCreationParams params) { - return startInternal(context, commandLine, 0, filesToMap, 0, - CALLBACK_FOR_RENDERER_PROCESS, true, params); - } - @VisibleForTesting static ChildProcessConnection allocateBoundConnectionForTesting(Context context, ChildProcessCreationParams creationParams) { - return allocateBoundConnection(context, null, true, false, creationParams, null); + return allocateBoundConnection(context, null, true, false, creationParams); } @VisibleForTesting @@ -945,14 +874,6 @@ static int allocatedSandboxedConnectionsCountForTesting(Context context, String .allocatedConnectionsCountForTesting(); } - /** - * @return the service map of connected services - */ - @VisibleForTesting - static Map getServiceMapForTesting() { - return sServiceMap; - } - /** @return the count of services set up and working */ @VisibleForTesting static int connectedServicesCountForTesting() { diff --git a/content/public/android/java/src/org/chromium/content/common/IChildProcessService.aidl b/content/public/android/java/src/org/chromium/content/common/IChildProcessService.aidl index 1f5ec5c38ebb..dffe3adc4b19 100644 --- a/content/public/android/java/src/org/chromium/content/common/IChildProcessService.aidl +++ b/content/public/android/java/src/org/chromium/content/common/IChildProcessService.aidl @@ -10,11 +10,6 @@ import android.view.Surface; import android.os.Bundle; interface IChildProcessService { - // On the first call to this method, the service will record the calling PID - // and return true. Subsequent calls will only return true if the calling PID - // is the same as the recorded one. - boolean bindToCaller(); - // Sets up the initial IPC channel and returns the pid of the child process. int setupConnection(in Bundle args, IChildProcessCallback callback); diff --git a/content/public/android/java/src/org/chromium/content/common/OWNERS b/content/public/android/java/src/org/chromium/content/common/OWNERS deleted file mode 100644 index 8f094e0099ea..000000000000 --- a/content/public/android/java/src/org/chromium/content/common/OWNERS +++ /dev/null @@ -1,2 +0,0 @@ -per-file *.aidl=set noparent -per-file *.aidl=file://ipc/SECURITY_OWNERS diff --git a/content/public/android/javatests/src/org/chromium/content/browser/ChildProcessLauncherTest.java b/content/public/android/javatests/src/org/chromium/content/browser/ChildProcessLauncherTest.java index d6ae7c6bc69d..6e2ae99623e6 100644 --- a/content/public/android/javatests/src/org/chromium/content/browser/ChildProcessLauncherTest.java +++ b/content/public/android/javatests/src/org/chromium/content/browser/ChildProcessLauncherTest.java @@ -4,15 +4,7 @@ package org.chromium.content.browser; -import android.content.ComponentName; import android.content.Context; -import android.content.Intent; -import android.content.ServiceConnection; -import android.os.Handler; -import android.os.IBinder; -import android.os.Looper; -import android.os.Message; -import android.os.Messenger; import android.os.RemoteException; import android.support.test.filters.MediumTest; import android.test.InstrumentationTestCase; @@ -25,9 +17,7 @@ import org.chromium.content.browser.test.util.Criteria; import org.chromium.content.browser.test.util.CriteriaHelper; import org.chromium.content.common.FileDescriptorInfo; -import org.chromium.content_shell_apk.ChildProcessLauncherTestHelperService; -import java.util.Map; import java.util.concurrent.Callable; /** @@ -306,143 +296,6 @@ public void testExceedMaximumConnectionNumber() { assertNotNull(tabConnection); } - /** - * Tests binding to the same sandboxed service process from multiple processes in the - * same package. This uses the ChildProcessLauncherTestHelperService declared in - * ContentShell.apk as a separate android:process to bind the first (slot 0) service. The - * instrumentation test then tries to bind the same slot, which fails, so the - * ChildProcessLauncher retries on a new connection. - */ - @MediumTest - @Feature({"ProcessManagement"}) - public void testBindServiceFromMultipleProcesses() throws RemoteException { - final Context context = getInstrumentation().getTargetContext(); - - // Start the Helper service. - class HelperConnection implements ServiceConnection { - Messenger mMessenger = null; - - @Override - public void onServiceConnected(ComponentName name, IBinder service) { - mMessenger = new Messenger(service); - } - - @Override - public void onServiceDisconnected(ComponentName name) {} - } - final HelperConnection serviceConn = new HelperConnection(); - - Intent intent = new Intent(); - intent.setComponent(new ComponentName(context.getPackageName(), - context.getPackageName() + ".ChildProcessLauncherTestHelperService")); - assertTrue(context.bindService(intent, serviceConn, Context.BIND_AUTO_CREATE)); - - // Wait for the Helper service to connect. - CriteriaHelper.pollInstrumentationThread( - new Criteria("Failed to get helper service Messenger") { - @Override - public boolean isSatisfied() { - return serviceConn.mMessenger != null; - } - }); - - assertNotNull(serviceConn.mMessenger); - - class ReplyHandler implements Handler.Callback { - Message mMessage; - - @Override - public boolean handleMessage(Message msg) { - // Copy the message so its contents outlive this Binder transaction. - mMessage = Message.obtain(); - mMessage.copyFrom(msg); - return true; - } - } - final ReplyHandler replyHandler = new ReplyHandler(); - - // Send a message to the Helper and wait for the reply. This will cause the slot 0 - // sandboxed service connection to be bound by a different PID (i.e., not this - // process). - Message msg = Message.obtain(null, ChildProcessLauncherTestHelperService.MSG_BIND_SERVICE); - msg.replyTo = new Messenger(new Handler(Looper.getMainLooper(), replyHandler)); - serviceConn.mMessenger.send(msg); - - CriteriaHelper.pollInstrumentationThread( - new Criteria("Failed waiting for helper service reply") { - @Override - public boolean isSatisfied() { - return replyHandler.mMessage != null; - } - }); - - // Verify that the Helper was able to launch the sandboxed service. - assertNotNull(replyHandler.mMessage); - assertEquals(ChildProcessLauncherTestHelperService.MSG_BIND_SERVICE_REPLY, - replyHandler.mMessage.what); - assertEquals("Connection slot from helper service is not 0", 0, replyHandler.mMessage.arg2); - - final int helperConnPid = replyHandler.mMessage.arg1; - assertTrue(helperConnPid > 0); - - // Launch a service from this process. Since slot 0 is already bound by the Helper, it - // will fail to start and the ChildProcessLauncher will retry. - final ChildProcessConnection conn = ChildProcessLauncher.startForTesting(context, - sProcessWaitArguments, new FileDescriptorInfo[0], - getDefaultChildProcessCreationParams(context.getPackageName())); - - CriteriaHelper.pollInstrumentationThread( - new Criteria("Failed waiting for instrumentation-bound service") { - @Override - public boolean isSatisfied() { - return conn.getService() != null; - } - }); - - assertEquals(0, conn.getServiceNumber()); - assertEquals(-1, conn.getPid()); // PID gets set to -1 if service is already bound. - - final Map serviceMap = - ChildProcessLauncher.getServiceMapForTesting(); - - // Wait for the retry to succeed. - CriteriaHelper.pollInstrumentationThread( - new Criteria("Failed waiting for both child process services") { - @Override - public boolean isSatisfied() { - boolean allChildrenConnected = serviceMap.size() == 2; - for (ChildProcessConnection conn : serviceMap.values()) { - allChildrenConnected &= conn.getService() != null; - } - return allChildrenConnected; - } - }); - - assertEquals(2, serviceMap.size()); - - boolean testedSlot0 = false, testedSlot1 = false; - - for (ChildProcessConnection childProcess : serviceMap.values()) { - if (childProcess == conn) { - assertFalse(testedSlot0); - assertEquals(0, childProcess.getServiceNumber()); - assertEquals(-1, childProcess.getPid()); - assertFalse(childProcess.getService().bindToCaller()); - testedSlot0 = true; - } else { - assertFalse(testedSlot1); - assertEquals(1, childProcess.getServiceNumber()); - assertTrue(childProcess.getPid() > 0); - assertTrue(childProcess.getPid() != helperConnPid); - assertTrue(childProcess.getService().bindToCaller()); - testedSlot1 = true; - } - } - - assertTrue(testedSlot0); - assertTrue(testedSlot1); - } - private ChildProcessConnectionImpl startConnection() { // Allocate a new connection. Context context = getInstrumentation().getTargetContext(); diff --git a/content/public/android/junit/src/org/chromium/content/browser/BindingManagerImplTest.java b/content/public/android/junit/src/org/chromium/content/browser/BindingManagerImplTest.java index d2fd2dffac90..d5a3388259df 100644 --- a/content/public/android/junit/src/org/chromium/content/browser/BindingManagerImplTest.java +++ b/content/public/android/junit/src/org/chromium/content/browser/BindingManagerImplTest.java @@ -13,21 +13,19 @@ import android.os.Bundle; import android.util.Pair; +import org.chromium.base.test.util.Feature; +import org.chromium.content.common.FileDescriptorInfo; +import org.chromium.content.common.IChildProcessCallback; +import org.chromium.content.common.IChildProcessService; +import org.chromium.testing.local.LocalRobolectricTestRunner; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; - import org.robolectric.Robolectric; import org.robolectric.annotation.Config; import org.robolectric.shadows.ShadowLooper; -import org.chromium.base.test.util.Feature; -import org.chromium.content.common.FileDescriptorInfo; -import org.chromium.content.common.IChildProcessCallback; -import org.chromium.content.common.IChildProcessService; -import org.chromium.testing.local.LocalRobolectricTestRunner; - import java.util.ArrayList; /** @@ -120,7 +118,7 @@ public IChildProcessService getService() { } @Override - public void start(String[] commandLine, StartCallback startCallback) { + public void start(String[] commandLine) { throw new UnsupportedOperationException(); } diff --git a/content/shell/android/BUILD.gn b/content/shell/android/BUILD.gn index 2068125f8d55..ad17f1588434 100644 --- a/content/shell/android/BUILD.gn +++ b/content/shell/android/BUILD.gn @@ -95,7 +95,6 @@ android_library("content_shell_apk_java") { android_manifest = content_shell_manifest java_files = [ - "shell_apk/src/org/chromium/content_shell_apk/ChildProcessLauncherTestHelperService.java", "shell_apk/src/org/chromium/content_shell_apk/ContentShellActivity.java", "shell_apk/src/org/chromium/content_shell_apk/ContentShellApplication.java", ] diff --git a/content/shell/android/shell_apk/AndroidManifest.xml.jinja2 b/content/shell/android/shell_apk/AndroidManifest.xml.jinja2 index ed0e15389c3b..f2e149f4a2aa 100644 --- a/content/shell/android/shell_apk/AndroidManifest.xml.jinja2 +++ b/content/shell/android/shell_apk/AndroidManifest.xml.jinja2 @@ -61,7 +61,5 @@ - diff --git a/content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ChildProcessLauncherTestHelperService.java b/content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ChildProcessLauncherTestHelperService.java deleted file mode 100644 index 9da9eb38c4ee..000000000000 --- a/content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ChildProcessLauncherTestHelperService.java +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package org.chromium.content_shell_apk; - -import android.app.Service; -import android.content.Intent; -import android.os.Handler; -import android.os.HandlerThread; -import android.os.IBinder; -import android.os.Message; -import android.os.Messenger; -import android.os.RemoteException; - -import org.chromium.base.BaseSwitches; -import org.chromium.base.CommandLine; -import org.chromium.base.library_loader.LibraryLoader; -import org.chromium.base.library_loader.LibraryProcessType; -import org.chromium.base.library_loader.ProcessInitException; -import org.chromium.content.browser.ChildProcessConnection; -import org.chromium.content.browser.ChildProcessCreationParams; -import org.chromium.content.browser.ChildProcessLauncher; -import org.chromium.content.common.FileDescriptorInfo; - -/** - * A Service that assists the ChildProcessLauncherTest that responds to one message, which - * starts a sandboxed service process via the ChildProcessLauncher. This is required to test - * the behavior when two independent processes in the same package try and bind to the same - * sandboxed service process. - */ -public class ChildProcessLauncherTestHelperService extends Service { - public static final int MSG_BIND_SERVICE = IBinder.FIRST_CALL_TRANSACTION + 1; - public static final int MSG_BIND_SERVICE_REPLY = MSG_BIND_SERVICE + 1; - - private final Handler.Callback mHandlerCallback = new Handler.Callback() { - @Override - public boolean handleMessage(Message msg) { - switch (msg.what) { - case MSG_BIND_SERVICE: - doBindService(msg); - return true; - } - return false; - } - }; - - private final HandlerThread mHandlerThread = new HandlerThread("Helper Service Handler"); - - @Override - public void onCreate() { - CommandLine.init(null); - try { - LibraryLoader.get(LibraryProcessType.PROCESS_CHILD).ensureInitialized(); - } catch (ProcessInitException ex) { - throw new RuntimeException(ex); - } - - mHandlerThread.start(); - } - - @Override - public IBinder onBind(Intent intent) { - Messenger messenger = - new Messenger(new Handler(mHandlerThread.getLooper(), mHandlerCallback)); - return messenger.getBinder(); - } - - private void doBindService(final Message msg) { - String[] commandLine = { "_", "--" + BaseSwitches.RENDERER_WAIT_FOR_JAVA_DEBUGGER }; - ChildProcessCreationParams params = new ChildProcessCreationParams(getPackageName(), false, - LibraryProcessType.PROCESS_CHILD); - final ChildProcessConnection conn = ChildProcessLauncher.startForTesting(this, commandLine, - new FileDescriptorInfo[0], params); - - // Poll the connection until it is set up. The main test in ChildProcessLauncherTest, which - // has bound the connection to this service, manages the timeout via the lifetime of this - // service. - final Handler handler = new Handler(); - final Runnable task = new Runnable() { - final Messenger mReplyTo = msg.replyTo; - - @Override - public void run() { - if (conn.getPid() != 0) { - try { - mReplyTo.send(Message.obtain(null, MSG_BIND_SERVICE_REPLY, conn.getPid(), - conn.getServiceNumber())); - } catch (RemoteException ex) { - throw new RuntimeException(ex); - } - } else { - handler.postDelayed(this, 10 /* milliseconds */); - } - } - }; - handler.postDelayed(task, 10); - } -}