| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.android_webview.test; | 5 package org.chromium.android_webview.test; |
| 6 | 6 |
| 7 import android.app.ActivityManager; | 7 import android.app.ActivityManager; |
| 8 import android.content.ComponentName; | 8 import android.content.ComponentName; |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.content.Intent; | 10 import android.content.Intent; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 @Override | 110 @Override |
| 111 public Boolean call() throws Exception { | 111 public Boolean call() throws Exception { |
| 112 return !isSecondBrowserServiceRunning(); | 112 return !isSecondBrowserServiceRunning(); |
| 113 } | 113 } |
| 114 }); | 114 }); |
| 115 } | 115 } |
| 116 mSecondBrowserServicePid = 0; | 116 mSecondBrowserServicePid = 0; |
| 117 } | 117 } |
| 118 | 118 |
| 119 private boolean tryStartingBrowserProcess() { | 119 private boolean tryStartingBrowserProcess() { |
| 120 final Context context = getActivity(); | |
| 121 final Boolean success[] = new Boolean[1]; | 120 final Boolean success[] = new Boolean[1]; |
| 121 // The activity must be launched in order for proper webview statics to
be setup. |
| 122 getActivity(); |
| 122 // runOnMainSync does not catch RuntimeExceptions, they just terminate t
he test. | 123 // runOnMainSync does not catch RuntimeExceptions, they just terminate t
he test. |
| 123 getInstrumentation().runOnMainSync(new Runnable() { | 124 getInstrumentation().runOnMainSync(new Runnable() { |
| 124 @Override | 125 @Override |
| 125 public void run() { | 126 public void run() { |
| 126 try { | 127 try { |
| 127 AwBrowserProcess.start(context); | 128 AwBrowserProcess.start(); |
| 128 success[0] = true; | 129 success[0] = true; |
| 129 } catch (RuntimeException e) { | 130 } catch (RuntimeException e) { |
| 130 success[0] = false; | 131 success[0] = false; |
| 131 } | 132 } |
| 132 } | 133 } |
| 133 }); | 134 }); |
| 134 assertNotNull(success[0]); | 135 assertNotNull(success[0]); |
| 135 return success[0]; | 136 return success[0]; |
| 136 } | 137 } |
| 137 | 138 |
| 138 // Note that both onServiceDisconnected and Binder.DeathRecipient fire prema
turely for our | 139 // Note that both onServiceDisconnected and Binder.DeathRecipient fire prema
turely for our |
| 139 // purpose. We need to ensure that the service process has actually terminat
ed, releasing all | 140 // purpose. We need to ensure that the service process has actually terminat
ed, releasing all |
| 140 // the locks. The only reliable way to do that is to scan the process list. | 141 // the locks. The only reliable way to do that is to scan the process list. |
| 141 private boolean isSecondBrowserServiceRunning() { | 142 private boolean isSecondBrowserServiceRunning() { |
| 142 ActivityManager activityManager = | 143 ActivityManager activityManager = |
| 143 (ActivityManager) getActivity().getSystemService(Context.ACTIVIT
Y_SERVICE); | 144 (ActivityManager) getActivity().getSystemService(Context.ACTIVIT
Y_SERVICE); |
| 144 for (ActivityManager.RunningServiceInfo si : activityManager.getRunningS
ervices(65536)) { | 145 for (ActivityManager.RunningServiceInfo si : activityManager.getRunningS
ervices(65536)) { |
| 145 if (si.pid == mSecondBrowserServicePid) return true; | 146 if (si.pid == mSecondBrowserServicePid) return true; |
| 146 } | 147 } |
| 147 return false; | 148 return false; |
| 148 } | 149 } |
| 149 } | 150 } |
| OLD | NEW |