The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.os; |
| 18 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | import android.net.LocalSocket; |
Narayan Kamath | 973b466 | 2014-03-31 13:41:26 +0100 | [diff] [blame] | 20 | import android.net.LocalSocketAddress; |
Elliott Hughes | 34385d3 | 2014-04-28 11:11:32 -0700 | [diff] [blame] | 21 | import android.system.Os; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.util.Log; |
Narayan Kamath | 973b466 | 2014-03-31 13:41:26 +0100 | [diff] [blame] | 23 | import com.android.internal.os.Zygote; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import java.io.BufferedWriter; |
| 25 | import java.io.DataInputStream; |
| 26 | import java.io.IOException; |
| 27 | import java.io.OutputStreamWriter; |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 28 | import java.nio.charset.StandardCharsets; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import java.util.ArrayList; |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 30 | import java.util.Arrays; |
| 31 | import java.util.List; |
Jeff Hao | 406ec15 | 2013-07-30 10:13:41 -0700 | [diff] [blame] | 32 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | /*package*/ class ZygoteStartFailedEx extends Exception { |
Narayan Kamath | 64cd907 | 2014-05-13 13:35:14 +0100 | [diff] [blame] | 34 | ZygoteStartFailedEx(String s) { |
| 35 | super(s); |
| 36 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | |
Narayan Kamath | 64cd907 | 2014-05-13 13:35:14 +0100 | [diff] [blame] | 38 | ZygoteStartFailedEx(Throwable cause) { |
| 39 | super(cause); |
| 40 | } |
| 41 | |
| 42 | ZygoteStartFailedEx(String s, Throwable cause) { |
| 43 | super(s, cause); |
| 44 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Tools for managing OS processes. |
| 49 | */ |
| 50 | public class Process { |
| 51 | private static final String LOG_TAG = "Process"; |
| 52 | |
Narayan Kamath | 64cd907 | 2014-05-13 13:35:14 +0100 | [diff] [blame] | 53 | /** |
| 54 | * @hide for internal use only. |
| 55 | */ |
| 56 | public static final String ZYGOTE_SOCKET = "zygote"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | |
Narayan Kamath | 64cd907 | 2014-05-13 13:35:14 +0100 | [diff] [blame] | 58 | /** |
| 59 | * @hide for internal use only. |
| 60 | */ |
| 61 | public static final String SECONDARY_ZYGOTE_SOCKET = "zygote_secondary"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | |
| 63 | /** |
| 64 | * Defines the UID/GID under which system code runs. |
| 65 | */ |
| 66 | public static final int SYSTEM_UID = 1000; |
| 67 | |
| 68 | /** |
| 69 | * Defines the UID/GID under which the telephony code runs. |
| 70 | */ |
| 71 | public static final int PHONE_UID = 1001; |
| 72 | |
| 73 | /** |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 74 | * Defines the UID/GID for the user shell. |
| 75 | * @hide |
| 76 | */ |
| 77 | public static final int SHELL_UID = 2000; |
| 78 | |
| 79 | /** |
Mike Lockwood | d42685d | 2009-09-03 09:25:22 -0400 | [diff] [blame] | 80 | * Defines the UID/GID for the log group. |
| 81 | * @hide |
| 82 | */ |
| 83 | public static final int LOG_UID = 1007; |
| 84 | |
| 85 | /** |
Amith Yamasani | d158214 | 2009-07-08 20:04:55 -0700 | [diff] [blame] | 86 | * Defines the UID/GID for the WIFI supplicant process. |
| 87 | * @hide |
| 88 | */ |
| 89 | public static final int WIFI_UID = 1010; |
| 90 | |
| 91 | /** |
Glenn Kasten | 8b7d1b4 | 2011-07-13 16:23:22 -0700 | [diff] [blame] | 92 | * Defines the UID/GID for the mediaserver process. |
| 93 | * @hide |
| 94 | */ |
| 95 | public static final int MEDIA_UID = 1013; |
| 96 | |
| 97 | /** |
Jeff Sharkey | 5294a2f | 2012-04-24 17:07:22 -0700 | [diff] [blame] | 98 | * Defines the UID/GID for the DRM process. |
| 99 | * @hide |
| 100 | */ |
| 101 | public static final int DRM_UID = 1019; |
| 102 | |
| 103 | /** |
Kenny Root | 26993b3 | 2012-03-19 15:07:51 -0700 | [diff] [blame] | 104 | * Defines the UID/GID for the group that controls VPN services. |
| 105 | * @hide |
| 106 | */ |
| 107 | public static final int VPN_UID = 1016; |
| 108 | |
| 109 | /** |
Nick Pelly | cd0e839 | 2010-10-13 17:25:24 -0700 | [diff] [blame] | 110 | * Defines the UID/GID for the NFC service process. |
| 111 | * @hide |
| 112 | */ |
Nick Pelly | a5cb9f4 | 2011-11-21 14:54:46 -0800 | [diff] [blame] | 113 | public static final int NFC_UID = 1027; |
Nick Pelly | cd0e839 | 2010-10-13 17:25:24 -0700 | [diff] [blame] | 114 | |
| 115 | /** |
Jaikumar Ganesh | 1abb1cb | 2012-01-25 16:14:50 -0800 | [diff] [blame] | 116 | * Defines the UID/GID for the Bluetooth service process. |
| 117 | * @hide |
| 118 | */ |
| 119 | public static final int BLUETOOTH_UID = 1002; |
| 120 | |
| 121 | /** |
Mike Lockwood | dcaa10c | 2010-12-16 12:50:44 -0800 | [diff] [blame] | 122 | * Defines the GID for the group that allows write access to the internal media storage. |
| 123 | * @hide |
| 124 | */ |
| 125 | public static final int MEDIA_RW_GID = 1023; |
| 126 | |
| 127 | /** |
Jeff Sharkey | 184a010 | 2013-07-10 16:19:52 -0700 | [diff] [blame] | 128 | * Access to installed package details |
| 129 | * @hide |
| 130 | */ |
| 131 | public static final int PACKAGE_INFO_GID = 1032; |
| 132 | |
| 133 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | * Defines the start of a range of UIDs (and GIDs), going from this |
| 135 | * number to {@link #LAST_APPLICATION_UID} that are reserved for assigning |
| 136 | * to applications. |
| 137 | */ |
| 138 | public static final int FIRST_APPLICATION_UID = 10000; |
Jeff Sharkey | 184a010 | 2013-07-10 16:19:52 -0700 | [diff] [blame] | 139 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | /** |
| 141 | * Last of application-specific UIDs starting at |
| 142 | * {@link #FIRST_APPLICATION_UID}. |
| 143 | */ |
Dianne Hackborn | 21fbd1f | 2012-02-10 10:38:10 -0800 | [diff] [blame] | 144 | public static final int LAST_APPLICATION_UID = 19999; |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 145 | |
| 146 | /** |
| 147 | * First uid used for fully isolated sandboxed processes (with no permissions of their own) |
| 148 | * @hide |
| 149 | */ |
| 150 | public static final int FIRST_ISOLATED_UID = 99000; |
| 151 | |
| 152 | /** |
| 153 | * Last uid used for fully isolated sandboxed processes (with no permissions of their own) |
| 154 | * @hide |
| 155 | */ |
| 156 | public static final int LAST_ISOLATED_UID = 99999; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | |
| 158 | /** |
Robin Lee | e66b689 | 2014-04-29 12:36:47 +0100 | [diff] [blame] | 159 | * Defines the gid shared by all applications running under the same profile. |
| 160 | * @hide |
| 161 | */ |
| 162 | public static final int SHARED_USER_GID = 9997; |
| 163 | |
| 164 | /** |
Kenny Root | e091f22 | 2012-09-11 15:01:26 -0700 | [diff] [blame] | 165 | * First gid for applications to share resources. Used when forward-locking |
| 166 | * is enabled but all UserHandles need to be able to read the resources. |
| 167 | * @hide |
| 168 | */ |
| 169 | public static final int FIRST_SHARED_APPLICATION_GID = 50000; |
| 170 | |
| 171 | /** |
| 172 | * Last gid for applications to share resources. Used when forward-locking |
| 173 | * is enabled but all UserHandles need to be able to read the resources. |
| 174 | * @hide |
| 175 | */ |
| 176 | public static final int LAST_SHARED_APPLICATION_GID = 59999; |
| 177 | |
| 178 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | * Standard priority of application threads. |
| 180 | * Use with {@link #setThreadPriority(int)} and |
| 181 | * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal |
| 182 | * {@link java.lang.Thread} class. |
| 183 | */ |
| 184 | public static final int THREAD_PRIORITY_DEFAULT = 0; |
| 185 | |
| 186 | /* |
| 187 | * *************************************** |
| 188 | * ** Keep in sync with utils/threads.h ** |
| 189 | * *************************************** |
| 190 | */ |
| 191 | |
| 192 | /** |
| 193 | * Lowest available thread priority. Only for those who really, really |
| 194 | * don't want to run if anything else is happening. |
| 195 | * Use with {@link #setThreadPriority(int)} and |
| 196 | * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal |
| 197 | * {@link java.lang.Thread} class. |
| 198 | */ |
| 199 | public static final int THREAD_PRIORITY_LOWEST = 19; |
| 200 | |
| 201 | /** |
| 202 | * Standard priority background threads. This gives your thread a slightly |
| 203 | * lower than normal priority, so that it will have less chance of impacting |
| 204 | * the responsiveness of the user interface. |
| 205 | * Use with {@link #setThreadPriority(int)} and |
| 206 | * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal |
| 207 | * {@link java.lang.Thread} class. |
| 208 | */ |
| 209 | public static final int THREAD_PRIORITY_BACKGROUND = 10; |
| 210 | |
| 211 | /** |
| 212 | * Standard priority of threads that are currently running a user interface |
| 213 | * that the user is interacting with. Applications can not normally |
| 214 | * change to this priority; the system will automatically adjust your |
| 215 | * application threads as the user moves through the UI. |
| 216 | * Use with {@link #setThreadPriority(int)} and |
| 217 | * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal |
| 218 | * {@link java.lang.Thread} class. |
| 219 | */ |
| 220 | public static final int THREAD_PRIORITY_FOREGROUND = -2; |
| 221 | |
| 222 | /** |
| 223 | * Standard priority of system display threads, involved in updating |
| 224 | * the user interface. Applications can not |
| 225 | * normally change to this priority. |
| 226 | * Use with {@link #setThreadPriority(int)} and |
| 227 | * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal |
| 228 | * {@link java.lang.Thread} class. |
| 229 | */ |
| 230 | public static final int THREAD_PRIORITY_DISPLAY = -4; |
| 231 | |
| 232 | /** |
| 233 | * Standard priority of the most important display threads, for compositing |
| 234 | * the screen and retrieving input events. Applications can not normally |
| 235 | * change to this priority. |
| 236 | * Use with {@link #setThreadPriority(int)} and |
| 237 | * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal |
| 238 | * {@link java.lang.Thread} class. |
| 239 | */ |
| 240 | public static final int THREAD_PRIORITY_URGENT_DISPLAY = -8; |
| 241 | |
| 242 | /** |
| 243 | * Standard priority of audio threads. Applications can not normally |
| 244 | * change to this priority. |
| 245 | * Use with {@link #setThreadPriority(int)} and |
| 246 | * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal |
| 247 | * {@link java.lang.Thread} class. |
| 248 | */ |
| 249 | public static final int THREAD_PRIORITY_AUDIO = -16; |
| 250 | |
| 251 | /** |
| 252 | * Standard priority of the most important audio threads. |
| 253 | * Applications can not normally change to this priority. |
| 254 | * Use with {@link #setThreadPriority(int)} and |
| 255 | * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal |
| 256 | * {@link java.lang.Thread} class. |
| 257 | */ |
| 258 | public static final int THREAD_PRIORITY_URGENT_AUDIO = -19; |
| 259 | |
| 260 | /** |
| 261 | * Minimum increment to make a priority more favorable. |
| 262 | */ |
| 263 | public static final int THREAD_PRIORITY_MORE_FAVORABLE = -1; |
| 264 | |
| 265 | /** |
| 266 | * Minimum increment to make a priority less favorable. |
| 267 | */ |
| 268 | public static final int THREAD_PRIORITY_LESS_FAVORABLE = +1; |
| 269 | |
San Mehat | e9d376b | 2009-04-21 14:06:36 -0700 | [diff] [blame] | 270 | /** |
Glenn Kasten | 6793ac9 | 2011-07-13 12:44:12 -0700 | [diff] [blame] | 271 | * Default scheduling policy |
| 272 | * @hide |
| 273 | */ |
| 274 | public static final int SCHED_OTHER = 0; |
| 275 | |
| 276 | /** |
| 277 | * First-In First-Out scheduling policy |
| 278 | * @hide |
| 279 | */ |
| 280 | public static final int SCHED_FIFO = 1; |
| 281 | |
| 282 | /** |
| 283 | * Round-Robin scheduling policy |
| 284 | * @hide |
| 285 | */ |
| 286 | public static final int SCHED_RR = 2; |
| 287 | |
| 288 | /** |
| 289 | * Batch scheduling policy |
| 290 | * @hide |
| 291 | */ |
| 292 | public static final int SCHED_BATCH = 3; |
| 293 | |
| 294 | /** |
| 295 | * Idle scheduling policy |
| 296 | * @hide |
| 297 | */ |
| 298 | public static final int SCHED_IDLE = 5; |
| 299 | |
Glenn Kasten | f1b5644 | 2012-03-15 16:33:43 -0700 | [diff] [blame] | 300 | // Keep in sync with SP_* constants of enum type SchedPolicy |
| 301 | // declared in system/core/include/cutils/sched_policy.h, |
| 302 | // except THREAD_GROUP_DEFAULT does not correspond to any SP_* value. |
San Mehat | e9d376b | 2009-04-21 14:06:36 -0700 | [diff] [blame] | 303 | |
| 304 | /** |
Glenn Kasten | f1b5644 | 2012-03-15 16:33:43 -0700 | [diff] [blame] | 305 | * Default thread group - |
| 306 | * has meaning with setProcessGroup() only, cannot be used with setThreadGroup(). |
| 307 | * When used with setProcessGroup(), the group of each thread in the process |
| 308 | * is conditionally changed based on that thread's current priority, as follows: |
| 309 | * threads with priority numerically less than THREAD_PRIORITY_BACKGROUND |
| 310 | * are moved to foreground thread group. All other threads are left unchanged. |
| 311 | * @hide |
| 312 | */ |
| 313 | public static final int THREAD_GROUP_DEFAULT = -1; |
| 314 | |
| 315 | /** |
| 316 | * Background thread group - All threads in |
San Mehat | e9d376b | 2009-04-21 14:06:36 -0700 | [diff] [blame] | 317 | * this group are scheduled with a reduced share of the CPU. |
Glenn Kasten | f1b5644 | 2012-03-15 16:33:43 -0700 | [diff] [blame] | 318 | * Value is same as constant SP_BACKGROUND of enum SchedPolicy. |
| 319 | * FIXME rename to THREAD_GROUP_BACKGROUND. |
San Mehat | e9d376b | 2009-04-21 14:06:36 -0700 | [diff] [blame] | 320 | * @hide |
| 321 | */ |
Glenn Kasten | f1b5644 | 2012-03-15 16:33:43 -0700 | [diff] [blame] | 322 | public static final int THREAD_GROUP_BG_NONINTERACTIVE = 0; |
San Mehat | e9d376b | 2009-04-21 14:06:36 -0700 | [diff] [blame] | 323 | |
| 324 | /** |
Glenn Kasten | f1b5644 | 2012-03-15 16:33:43 -0700 | [diff] [blame] | 325 | * Foreground thread group - All threads in |
| 326 | * this group are scheduled with a normal share of the CPU. |
| 327 | * Value is same as constant SP_FOREGROUND of enum SchedPolicy. |
| 328 | * Not used at this level. |
San Mehat | e9d376b | 2009-04-21 14:06:36 -0700 | [diff] [blame] | 329 | * @hide |
| 330 | **/ |
Glenn Kasten | f1b5644 | 2012-03-15 16:33:43 -0700 | [diff] [blame] | 331 | private static final int THREAD_GROUP_FOREGROUND = 1; |
San Mehat | e9d376b | 2009-04-21 14:06:36 -0700 | [diff] [blame] | 332 | |
Glenn Kasten | 07b0465 | 2012-04-23 15:00:43 -0700 | [diff] [blame] | 333 | /** |
| 334 | * System thread group. |
| 335 | * @hide |
| 336 | **/ |
| 337 | public static final int THREAD_GROUP_SYSTEM = 2; |
| 338 | |
| 339 | /** |
| 340 | * Application audio thread group. |
| 341 | * @hide |
| 342 | **/ |
| 343 | public static final int THREAD_GROUP_AUDIO_APP = 3; |
| 344 | |
| 345 | /** |
| 346 | * System audio thread group. |
| 347 | * @hide |
| 348 | **/ |
| 349 | public static final int THREAD_GROUP_AUDIO_SYS = 4; |
| 350 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 351 | public static final int SIGNAL_QUIT = 3; |
| 352 | public static final int SIGNAL_KILL = 9; |
| 353 | public static final int SIGNAL_USR1 = 10; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 354 | |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 355 | /** |
| 356 | * State for communicating with the zygote process. |
Narayan Kamath | 64cd907 | 2014-05-13 13:35:14 +0100 | [diff] [blame] | 357 | * |
| 358 | * @hide for internal use only. |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 359 | */ |
Narayan Kamath | 64cd907 | 2014-05-13 13:35:14 +0100 | [diff] [blame] | 360 | public static class ZygoteState { |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 361 | final LocalSocket socket; |
| 362 | final DataInputStream inputStream; |
| 363 | final BufferedWriter writer; |
| 364 | final List<String> abiList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 365 | |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 366 | boolean mClosed; |
| 367 | |
| 368 | private ZygoteState(LocalSocket socket, DataInputStream inputStream, |
| 369 | BufferedWriter writer, List<String> abiList) { |
| 370 | this.socket = socket; |
| 371 | this.inputStream = inputStream; |
| 372 | this.writer = writer; |
| 373 | this.abiList = abiList; |
| 374 | } |
| 375 | |
Narayan Kamath | 64cd907 | 2014-05-13 13:35:14 +0100 | [diff] [blame] | 376 | public static ZygoteState connect(String socketAddress) throws IOException { |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 377 | DataInputStream zygoteInputStream = null; |
| 378 | BufferedWriter zygoteWriter = null; |
Narayan Kamath | 64cd907 | 2014-05-13 13:35:14 +0100 | [diff] [blame] | 379 | final LocalSocket zygoteSocket = new LocalSocket(); |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 380 | |
Narayan Kamath | 64cd907 | 2014-05-13 13:35:14 +0100 | [diff] [blame] | 381 | try { |
| 382 | zygoteSocket.connect(new LocalSocketAddress(socketAddress, |
| 383 | LocalSocketAddress.Namespace.RESERVED)); |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 384 | |
Narayan Kamath | 64cd907 | 2014-05-13 13:35:14 +0100 | [diff] [blame] | 385 | zygoteInputStream = new DataInputStream(zygoteSocket.getInputStream()); |
| 386 | |
| 387 | zygoteWriter = new BufferedWriter(new OutputStreamWriter( |
| 388 | zygoteSocket.getOutputStream()), 256); |
| 389 | } catch (IOException ex) { |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 390 | try { |
Narayan Kamath | 64cd907 | 2014-05-13 13:35:14 +0100 | [diff] [blame] | 391 | zygoteSocket.close(); |
| 392 | } catch (IOException ignore) { |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 393 | } |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 394 | |
Narayan Kamath | 64cd907 | 2014-05-13 13:35:14 +0100 | [diff] [blame] | 395 | throw ex; |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | String abiListString = getAbiList(zygoteWriter, zygoteInputStream); |
| 399 | Log.i("Zygote", "Process: zygote socket opened, supported ABIS: " + abiListString); |
| 400 | |
| 401 | return new ZygoteState(zygoteSocket, zygoteInputStream, zygoteWriter, |
| 402 | Arrays.asList(abiListString.split(","))); |
| 403 | } |
| 404 | |
| 405 | boolean matches(String abi) { |
| 406 | return abiList.contains(abi); |
| 407 | } |
| 408 | |
Narayan Kamath | 64cd907 | 2014-05-13 13:35:14 +0100 | [diff] [blame] | 409 | public void close() { |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 410 | try { |
| 411 | socket.close(); |
| 412 | } catch (IOException ex) { |
| 413 | Log.e(LOG_TAG,"I/O exception on routine close", ex); |
| 414 | } |
| 415 | |
| 416 | mClosed = true; |
| 417 | } |
| 418 | |
| 419 | boolean isClosed() { |
| 420 | return mClosed; |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | /** |
| 425 | * The state of the connection to the primary zygote. |
| 426 | */ |
| 427 | static ZygoteState primaryZygoteState; |
| 428 | |
| 429 | /** |
| 430 | * The state of the connection to the secondary zygote. |
| 431 | */ |
| 432 | static ZygoteState secondaryZygoteState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | |
| 434 | /** |
| 435 | * Start a new process. |
| 436 | * |
| 437 | * <p>If processes are enabled, a new process is created and the |
| 438 | * static main() function of a <var>processClass</var> is executed there. |
| 439 | * The process will continue running after this function returns. |
| 440 | * |
| 441 | * <p>If processes are not enabled, a new thread in the caller's |
| 442 | * process is created and main() of <var>processClass</var> called there. |
| 443 | * |
| 444 | * <p>The niceName parameter, if not an empty string, is a custom name to |
| 445 | * give to the process instead of using processClass. This allows you to |
| 446 | * make easily identifyable processes even if you are using the same base |
| 447 | * <var>processClass</var> to start them. |
| 448 | * |
| 449 | * @param processClass The class to use as the process's main entry |
| 450 | * point. |
| 451 | * @param niceName A more readable name to use for the process. |
| 452 | * @param uid The user-id under which the process will run. |
| 453 | * @param gid The group-id under which the process will run. |
| 454 | * @param gids Additional group-ids associated with the process. |
Elliott Hughes | e1dfcb7 | 2011-07-08 11:08:07 -0700 | [diff] [blame] | 455 | * @param debugFlags Additional flags. |
| 456 | * @param targetSdkVersion The target SDK version for the app. |
Stephen Smalley | bd19b9e | 2013-04-12 14:49:38 -0400 | [diff] [blame] | 457 | * @param seInfo null-ok SELinux information for the new process. |
Ramin Zaghi | ff0c470 | 2014-04-01 15:02:29 +0100 | [diff] [blame] | 458 | * @param abi non-null the ABI this app should be started with. |
Andreas Gampe | aec67dc | 2014-09-02 21:23:06 -0700 | [diff] [blame] | 459 | * @param instructionSet null-ok the instruction set to use. |
jgu21 | 2eacd06 | 2014-09-10 06:55:07 -0400 | [diff] [blame^] | 460 | * @param appDataDir null-ok the data directory of the app. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 461 | * @param zygoteArgs Additional arguments to supply to the zygote process. |
| 462 | * |
Jeff Brown | 3f9dd28 | 2011-07-08 20:02:19 -0700 | [diff] [blame] | 463 | * @return An object that describes the result of the attempt to start the process. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 464 | * @throws RuntimeException on fatal start failure |
| 465 | * |
| 466 | * {@hide} |
| 467 | */ |
Jeff Brown | 3f9dd28 | 2011-07-08 20:02:19 -0700 | [diff] [blame] | 468 | public static final ProcessStartResult start(final String processClass, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 469 | final String niceName, |
| 470 | int uid, int gid, int[] gids, |
Jeff Sharkey | 5b1ada2 | 2012-08-14 18:47:09 -0700 | [diff] [blame] | 471 | int debugFlags, int mountExternal, |
| 472 | int targetSdkVersion, |
Stephen Smalley | 83d9eda | 2012-01-13 08:34:17 -0500 | [diff] [blame] | 473 | String seInfo, |
Ramin Zaghi | ff0c470 | 2014-04-01 15:02:29 +0100 | [diff] [blame] | 474 | String abi, |
Andreas Gampe | aec67dc | 2014-09-02 21:23:06 -0700 | [diff] [blame] | 475 | String instructionSet, |
jgu21 | 2eacd06 | 2014-09-10 06:55:07 -0400 | [diff] [blame^] | 476 | String appDataDir, |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 477 | String[] zygoteArgs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 478 | try { |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 479 | return startViaZygote(processClass, niceName, uid, gid, gids, |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 480 | debugFlags, mountExternal, targetSdkVersion, seInfo, |
jgu21 | 2eacd06 | 2014-09-10 06:55:07 -0400 | [diff] [blame^] | 481 | abi, instructionSet, appDataDir, zygoteArgs); |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 482 | } catch (ZygoteStartFailedEx ex) { |
| 483 | Log.e(LOG_TAG, |
| 484 | "Starting VM process through Zygote failed"); |
| 485 | throw new RuntimeException( |
| 486 | "Starting VM process through Zygote failed", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 487 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | /** retry interval for opening a zygote socket */ |
| 491 | static final int ZYGOTE_RETRY_MILLIS = 500; |
| 492 | |
| 493 | /** |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 494 | * Queries the zygote for the list of ABIS it supports. |
| 495 | * |
| 496 | * @throws ZygoteStartFailedEx if the query failed. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 497 | */ |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 498 | private static String getAbiList(BufferedWriter writer, DataInputStream inputStream) |
Narayan Kamath | 64cd907 | 2014-05-13 13:35:14 +0100 | [diff] [blame] | 499 | throws IOException { |
| 500 | // Each query starts with the argument count (1 in this case) |
| 501 | writer.write("1"); |
| 502 | // ... followed by a new-line. |
| 503 | writer.newLine(); |
| 504 | // ... followed by our only argument. |
| 505 | writer.write("--query-abi-list"); |
| 506 | writer.newLine(); |
| 507 | writer.flush(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 508 | |
Narayan Kamath | 64cd907 | 2014-05-13 13:35:14 +0100 | [diff] [blame] | 509 | // The response is a length prefixed stream of ASCII bytes. |
| 510 | int numBytes = inputStream.readInt(); |
| 511 | byte[] bytes = new byte[numBytes]; |
| 512 | inputStream.readFully(bytes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 513 | |
Narayan Kamath | 64cd907 | 2014-05-13 13:35:14 +0100 | [diff] [blame] | 514 | return new String(bytes, StandardCharsets.US_ASCII); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | /** |
| 518 | * Sends an argument list to the zygote process, which starts a new child |
| 519 | * and returns the child's pid. Please note: the present implementation |
| 520 | * replaces newlines in the argument list with spaces. |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 521 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 522 | * @throws ZygoteStartFailedEx if process start failed for any reason |
| 523 | */ |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 524 | private static ProcessStartResult zygoteSendArgsAndGetResult( |
| 525 | ZygoteState zygoteState, ArrayList<String> args) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 526 | throws ZygoteStartFailedEx { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 527 | try { |
| 528 | /** |
| 529 | * See com.android.internal.os.ZygoteInit.readArgumentList() |
| 530 | * Presently the wire format to the zygote process is: |
| 531 | * a) a count of arguments (argc, in essence) |
| 532 | * b) a number of newline-separated argument strings equal to count |
| 533 | * |
| 534 | * After the zygote process reads these it will write the pid of |
Jeff Brown | 3f9dd28 | 2011-07-08 20:02:19 -0700 | [diff] [blame] | 535 | * the child or -1 on failure, followed by boolean to |
| 536 | * indicate whether a wrapper process was used. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 537 | */ |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 538 | final BufferedWriter writer = zygoteState.writer; |
| 539 | final DataInputStream inputStream = zygoteState.inputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 540 | |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 541 | writer.write(Integer.toString(args.size())); |
| 542 | writer.newLine(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 543 | |
| 544 | int sz = args.size(); |
| 545 | for (int i = 0; i < sz; i++) { |
| 546 | String arg = args.get(i); |
| 547 | if (arg.indexOf('\n') >= 0) { |
| 548 | throw new ZygoteStartFailedEx( |
| 549 | "embedded newlines not allowed"); |
| 550 | } |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 551 | writer.write(arg); |
| 552 | writer.newLine(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 553 | } |
| 554 | |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 555 | writer.flush(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 556 | |
| 557 | // Should there be a timeout on this? |
Jeff Brown | 3f9dd28 | 2011-07-08 20:02:19 -0700 | [diff] [blame] | 558 | ProcessStartResult result = new ProcessStartResult(); |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 559 | result.pid = inputStream.readInt(); |
Jeff Brown | 3f9dd28 | 2011-07-08 20:02:19 -0700 | [diff] [blame] | 560 | if (result.pid < 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 561 | throw new ZygoteStartFailedEx("fork() failed"); |
| 562 | } |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 563 | result.usingWrapper = inputStream.readBoolean(); |
Jeff Brown | 3f9dd28 | 2011-07-08 20:02:19 -0700 | [diff] [blame] | 564 | return result; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 565 | } catch (IOException ex) { |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 566 | zygoteState.close(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 567 | throw new ZygoteStartFailedEx(ex); |
| 568 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | /** |
| 572 | * Starts a new process via the zygote mechanism. |
| 573 | * |
| 574 | * @param processClass Class name whose static main() to run |
| 575 | * @param niceName 'nice' process name to appear in ps |
| 576 | * @param uid a POSIX uid that the new process should setuid() to |
| 577 | * @param gid a POSIX gid that the new process shuold setgid() to |
| 578 | * @param gids null-ok; a list of supplementary group IDs that the |
| 579 | * new process should setgroup() to. |
Elliott Hughes | e1dfcb7 | 2011-07-08 11:08:07 -0700 | [diff] [blame] | 580 | * @param debugFlags Additional flags. |
| 581 | * @param targetSdkVersion The target SDK version for the app. |
Stephen Smalley | bd19b9e | 2013-04-12 14:49:38 -0400 | [diff] [blame] | 582 | * @param seInfo null-ok SELinux information for the new process. |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 583 | * @param abi the ABI the process should use. |
Andreas Gampe | aec67dc | 2014-09-02 21:23:06 -0700 | [diff] [blame] | 584 | * @param instructionSet null-ok the instruction set to use. |
jgu21 | 2eacd06 | 2014-09-10 06:55:07 -0400 | [diff] [blame^] | 585 | * @param appDataDir null-ok the data directory of the app. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 586 | * @param extraArgs Additional arguments to supply to the zygote process. |
Jeff Brown | 3f9dd28 | 2011-07-08 20:02:19 -0700 | [diff] [blame] | 587 | * @return An object that describes the result of the attempt to start the process. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 588 | * @throws ZygoteStartFailedEx if process start failed for any reason |
| 589 | */ |
Jeff Brown | 3f9dd28 | 2011-07-08 20:02:19 -0700 | [diff] [blame] | 590 | private static ProcessStartResult startViaZygote(final String processClass, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 591 | final String niceName, |
| 592 | final int uid, final int gid, |
| 593 | final int[] gids, |
Jeff Sharkey | 5b1ada2 | 2012-08-14 18:47:09 -0700 | [diff] [blame] | 594 | int debugFlags, int mountExternal, |
| 595 | int targetSdkVersion, |
Stephen Smalley | 83d9eda | 2012-01-13 08:34:17 -0500 | [diff] [blame] | 596 | String seInfo, |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 597 | String abi, |
Andreas Gampe | aec67dc | 2014-09-02 21:23:06 -0700 | [diff] [blame] | 598 | String instructionSet, |
jgu21 | 2eacd06 | 2014-09-10 06:55:07 -0400 | [diff] [blame^] | 599 | String appDataDir, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 600 | String[] extraArgs) |
| 601 | throws ZygoteStartFailedEx { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 602 | synchronized(Process.class) { |
| 603 | ArrayList<String> argsForZygote = new ArrayList<String>(); |
| 604 | |
| 605 | // --runtime-init, --setuid=, --setgid=, |
| 606 | // and --setgroups= must go first |
| 607 | argsForZygote.add("--runtime-init"); |
| 608 | argsForZygote.add("--setuid=" + uid); |
| 609 | argsForZygote.add("--setgid=" + gid); |
Elliott Hughes | ae07ecf | 2011-07-06 17:33:27 -0700 | [diff] [blame] | 610 | if ((debugFlags & Zygote.DEBUG_ENABLE_JNI_LOGGING) != 0) { |
| 611 | argsForZygote.add("--enable-jni-logging"); |
| 612 | } |
Ben Cheng | 23085b7 | 2010-02-08 16:06:32 -0800 | [diff] [blame] | 613 | if ((debugFlags & Zygote.DEBUG_ENABLE_SAFEMODE) != 0) { |
| 614 | argsForZygote.add("--enable-safemode"); |
| 615 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 616 | if ((debugFlags & Zygote.DEBUG_ENABLE_DEBUGGER) != 0) { |
| 617 | argsForZygote.add("--enable-debugger"); |
| 618 | } |
| 619 | if ((debugFlags & Zygote.DEBUG_ENABLE_CHECKJNI) != 0) { |
| 620 | argsForZygote.add("--enable-checkjni"); |
| 621 | } |
| 622 | if ((debugFlags & Zygote.DEBUG_ENABLE_ASSERT) != 0) { |
| 623 | argsForZygote.add("--enable-assert"); |
| 624 | } |
Jeff Sharkey | 2bca868 | 2012-08-22 13:59:58 -0700 | [diff] [blame] | 625 | if (mountExternal == Zygote.MOUNT_EXTERNAL_MULTIUSER) { |
Jeff Sharkey | 5b1ada2 | 2012-08-14 18:47:09 -0700 | [diff] [blame] | 626 | argsForZygote.add("--mount-external-multiuser"); |
Jeff Sharkey | e217ee4 | 2012-08-28 16:23:01 -0700 | [diff] [blame] | 627 | } else if (mountExternal == Zygote.MOUNT_EXTERNAL_MULTIUSER_ALL) { |
| 628 | argsForZygote.add("--mount-external-multiuser-all"); |
Jeff Sharkey | 5b1ada2 | 2012-08-14 18:47:09 -0700 | [diff] [blame] | 629 | } |
Elliott Hughes | e1dfcb7 | 2011-07-08 11:08:07 -0700 | [diff] [blame] | 630 | argsForZygote.add("--target-sdk-version=" + targetSdkVersion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 631 | |
| 632 | //TODO optionally enable debuger |
| 633 | //argsForZygote.add("--enable-debugger"); |
| 634 | |
| 635 | // --setgroups is a comma-separated list |
| 636 | if (gids != null && gids.length > 0) { |
| 637 | StringBuilder sb = new StringBuilder(); |
| 638 | sb.append("--setgroups="); |
| 639 | |
| 640 | int sz = gids.length; |
| 641 | for (int i = 0; i < sz; i++) { |
| 642 | if (i != 0) { |
| 643 | sb.append(','); |
| 644 | } |
| 645 | sb.append(gids[i]); |
| 646 | } |
| 647 | |
| 648 | argsForZygote.add(sb.toString()); |
| 649 | } |
| 650 | |
| 651 | if (niceName != null) { |
| 652 | argsForZygote.add("--nice-name=" + niceName); |
| 653 | } |
| 654 | |
Stephen Smalley | 83d9eda | 2012-01-13 08:34:17 -0500 | [diff] [blame] | 655 | if (seInfo != null) { |
| 656 | argsForZygote.add("--seinfo=" + seInfo); |
| 657 | } |
| 658 | |
Andreas Gampe | aec67dc | 2014-09-02 21:23:06 -0700 | [diff] [blame] | 659 | if (instructionSet != null) { |
| 660 | argsForZygote.add("--instruction-set=" + instructionSet); |
| 661 | } |
| 662 | |
jgu21 | 2eacd06 | 2014-09-10 06:55:07 -0400 | [diff] [blame^] | 663 | if (appDataDir != null) { |
| 664 | argsForZygote.add("--app-data-dir=" + appDataDir); |
| 665 | } |
| 666 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 667 | argsForZygote.add(processClass); |
| 668 | |
| 669 | if (extraArgs != null) { |
| 670 | for (String arg : extraArgs) { |
| 671 | argsForZygote.add(arg); |
| 672 | } |
| 673 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 674 | |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 675 | return zygoteSendArgsAndGetResult(openZygoteSocketIfNeeded(abi), argsForZygote); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 676 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 677 | } |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 678 | |
| 679 | /** |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 680 | * Tries to open socket to Zygote process if not already open. If |
| 681 | * already open, does nothing. May block and retry. |
| 682 | */ |
| 683 | private static ZygoteState openZygoteSocketIfNeeded(String abi) throws ZygoteStartFailedEx { |
| 684 | if (primaryZygoteState == null || primaryZygoteState.isClosed()) { |
Narayan Kamath | 64cd907 | 2014-05-13 13:35:14 +0100 | [diff] [blame] | 685 | try { |
| 686 | primaryZygoteState = ZygoteState.connect(ZYGOTE_SOCKET); |
| 687 | } catch (IOException ioe) { |
| 688 | throw new ZygoteStartFailedEx("Error connecting to primary zygote", ioe); |
| 689 | } |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 690 | } |
| 691 | |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 692 | if (primaryZygoteState.matches(abi)) { |
| 693 | return primaryZygoteState; |
| 694 | } |
| 695 | |
| 696 | // The primary zygote didn't match. Try the secondary. |
| 697 | if (secondaryZygoteState == null || secondaryZygoteState.isClosed()) { |
Narayan Kamath | 64cd907 | 2014-05-13 13:35:14 +0100 | [diff] [blame] | 698 | try { |
| 699 | secondaryZygoteState = ZygoteState.connect(SECONDARY_ZYGOTE_SOCKET); |
| 700 | } catch (IOException ioe) { |
| 701 | throw new ZygoteStartFailedEx("Error connecting to secondary zygote", ioe); |
| 702 | } |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | if (secondaryZygoteState.matches(abi)) { |
| 706 | return secondaryZygoteState; |
| 707 | } |
| 708 | |
| 709 | throw new ZygoteStartFailedEx("Unsupported zygote ABI: " + abi); |
| 710 | } |
| 711 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 712 | /** |
| 713 | * Returns elapsed milliseconds of the time this process has run. |
| 714 | * @return Returns the number of milliseconds this process has return. |
| 715 | */ |
| 716 | public static final native long getElapsedCpuTime(); |
| 717 | |
| 718 | /** |
| 719 | * Returns the identifier of this process, which can be used with |
| 720 | * {@link #killProcess} and {@link #sendSignal}. |
| 721 | */ |
Jeff Hao | 406ec15 | 2013-07-30 10:13:41 -0700 | [diff] [blame] | 722 | public static final int myPid() { |
Elliott Hughes | 34385d3 | 2014-04-28 11:11:32 -0700 | [diff] [blame] | 723 | return Os.getpid(); |
Jeff Hao | 406ec15 | 2013-07-30 10:13:41 -0700 | [diff] [blame] | 724 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 725 | |
| 726 | /** |
Romain Guy | 80b12fc | 2013-05-29 15:54:25 -0700 | [diff] [blame] | 727 | * Returns the identifier of this process' parent. |
| 728 | * @hide |
| 729 | */ |
Elliott Hughes | 2a805f9 | 2013-07-31 18:25:47 -0700 | [diff] [blame] | 730 | public static final int myPpid() { |
Elliott Hughes | 34385d3 | 2014-04-28 11:11:32 -0700 | [diff] [blame] | 731 | return Os.getppid(); |
Elliott Hughes | 2a805f9 | 2013-07-31 18:25:47 -0700 | [diff] [blame] | 732 | } |
Romain Guy | 80b12fc | 2013-05-29 15:54:25 -0700 | [diff] [blame] | 733 | |
| 734 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 735 | * Returns the identifier of the calling thread, which be used with |
| 736 | * {@link #setThreadPriority(int, int)}. |
| 737 | */ |
Elliott Hughes | 6d4b1e2 | 2013-07-31 17:38:11 -0700 | [diff] [blame] | 738 | public static final int myTid() { |
Elliott Hughes | 34385d3 | 2014-04-28 11:11:32 -0700 | [diff] [blame] | 739 | return Os.gettid(); |
Elliott Hughes | 6d4b1e2 | 2013-07-31 17:38:11 -0700 | [diff] [blame] | 740 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 741 | |
| 742 | /** |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 743 | * Returns the identifier of this process's uid. This is the kernel uid |
| 744 | * that the process is running under, which is the identity of its |
| 745 | * app-specific sandbox. It is different from {@link #myUserHandle} in that |
| 746 | * a uid identifies a specific app sandbox in a specific user. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 747 | */ |
Jeff Hao | 406ec15 | 2013-07-30 10:13:41 -0700 | [diff] [blame] | 748 | public static final int myUid() { |
Elliott Hughes | 34385d3 | 2014-04-28 11:11:32 -0700 | [diff] [blame] | 749 | return Os.getuid(); |
Jeff Hao | 406ec15 | 2013-07-30 10:13:41 -0700 | [diff] [blame] | 750 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 751 | |
| 752 | /** |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 753 | * Returns this process's user handle. This is the |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 754 | * user the process is running under. It is distinct from |
| 755 | * {@link #myUid()} in that a particular user will have multiple |
| 756 | * distinct apps running under it each with their own uid. |
| 757 | */ |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 758 | public static final UserHandle myUserHandle() { |
| 759 | return new UserHandle(UserHandle.getUserId(myUid())); |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | /** |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 763 | * Returns whether the current process is in an isolated sandbox. |
| 764 | * @hide |
| 765 | */ |
| 766 | public static final boolean isIsolated() { |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 767 | int uid = UserHandle.getAppId(myUid()); |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 768 | return uid >= FIRST_ISOLATED_UID && uid <= LAST_ISOLATED_UID; |
| 769 | } |
| 770 | |
| 771 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 772 | * Returns the UID assigned to a particular user name, or -1 if there is |
| 773 | * none. If the given string consists of only numbers, it is converted |
| 774 | * directly to a uid. |
| 775 | */ |
| 776 | public static final native int getUidForName(String name); |
| 777 | |
| 778 | /** |
| 779 | * Returns the GID assigned to a particular user name, or -1 if there is |
| 780 | * none. If the given string consists of only numbers, it is converted |
| 781 | * directly to a gid. |
| 782 | */ |
| 783 | public static final native int getGidForName(String name); |
Amith Yamasani | 819f928 | 2009-06-24 23:18:15 -0700 | [diff] [blame] | 784 | |
| 785 | /** |
| 786 | * Returns a uid for a currently running process. |
| 787 | * @param pid the process id |
| 788 | * @return the uid of the process, or -1 if the process is not running. |
| 789 | * @hide pending API council review |
| 790 | */ |
| 791 | public static final int getUidForPid(int pid) { |
| 792 | String[] procStatusLabels = { "Uid:" }; |
| 793 | long[] procStatusValues = new long[1]; |
| 794 | procStatusValues[0] = -1; |
| 795 | Process.readProcLines("/proc/" + pid + "/status", procStatusLabels, procStatusValues); |
| 796 | return (int) procStatusValues[0]; |
| 797 | } |
| 798 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 799 | /** |
Jeff Brown | ebed7d6 | 2011-05-16 17:08:42 -0700 | [diff] [blame] | 800 | * Returns the parent process id for a currently running process. |
| 801 | * @param pid the process id |
| 802 | * @return the parent process id of the process, or -1 if the process is not running. |
| 803 | * @hide |
| 804 | */ |
| 805 | public static final int getParentPid(int pid) { |
| 806 | String[] procStatusLabels = { "PPid:" }; |
| 807 | long[] procStatusValues = new long[1]; |
| 808 | procStatusValues[0] = -1; |
| 809 | Process.readProcLines("/proc/" + pid + "/status", procStatusLabels, procStatusValues); |
| 810 | return (int) procStatusValues[0]; |
| 811 | } |
| 812 | |
| 813 | /** |
Glenn Kasten | 07b0465 | 2012-04-23 15:00:43 -0700 | [diff] [blame] | 814 | * Returns the thread group leader id for a currently running thread. |
| 815 | * @param tid the thread id |
| 816 | * @return the thread group leader id of the thread, or -1 if the thread is not running. |
| 817 | * This is same as what getpid(2) would return if called by tid. |
| 818 | * @hide |
| 819 | */ |
| 820 | public static final int getThreadGroupLeader(int tid) { |
| 821 | String[] procStatusLabels = { "Tgid:" }; |
| 822 | long[] procStatusValues = new long[1]; |
| 823 | procStatusValues[0] = -1; |
| 824 | Process.readProcLines("/proc/" + tid + "/status", procStatusLabels, procStatusValues); |
| 825 | return (int) procStatusValues[0]; |
| 826 | } |
| 827 | |
| 828 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 829 | * Set the priority of a thread, based on Linux priorities. |
| 830 | * |
| 831 | * @param tid The identifier of the thread/process to change. |
| 832 | * @param priority A Linux priority level, from -20 for highest scheduling |
| 833 | * priority to 19 for lowest scheduling priority. |
| 834 | * |
| 835 | * @throws IllegalArgumentException Throws IllegalArgumentException if |
| 836 | * <var>tid</var> does not exist. |
| 837 | * @throws SecurityException Throws SecurityException if your process does |
| 838 | * not have permission to modify the given thread, or to use the given |
| 839 | * priority. |
| 840 | */ |
| 841 | public static final native void setThreadPriority(int tid, int priority) |
| 842 | throws IllegalArgumentException, SecurityException; |
San Mehat | e9d376b | 2009-04-21 14:06:36 -0700 | [diff] [blame] | 843 | |
| 844 | /** |
Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 845 | * Call with 'false' to cause future calls to {@link #setThreadPriority(int)} to |
| 846 | * throw an exception if passed a background-level thread priority. This is only |
| 847 | * effective if the JNI layer is built with GUARD_THREAD_PRIORITY defined to 1. |
| 848 | * |
| 849 | * @hide |
| 850 | */ |
| 851 | public static final native void setCanSelfBackground(boolean backgroundOk); |
| 852 | |
| 853 | /** |
San Mehat | e9d376b | 2009-04-21 14:06:36 -0700 | [diff] [blame] | 854 | * Sets the scheduling group for a thread. |
| 855 | * @hide |
Glenn Kasten | f1b5644 | 2012-03-15 16:33:43 -0700 | [diff] [blame] | 856 | * @param tid The identifier of the thread to change. |
| 857 | * @param group The target group for this thread from THREAD_GROUP_*. |
San Mehat | e9d376b | 2009-04-21 14:06:36 -0700 | [diff] [blame] | 858 | * |
| 859 | * @throws IllegalArgumentException Throws IllegalArgumentException if |
| 860 | * <var>tid</var> does not exist. |
| 861 | * @throws SecurityException Throws SecurityException if your process does |
| 862 | * not have permission to modify the given thread, or to use the given |
| 863 | * priority. |
Glenn Kasten | f1b5644 | 2012-03-15 16:33:43 -0700 | [diff] [blame] | 864 | * If the thread is a thread group leader, that is it's gettid() == getpid(), |
| 865 | * then the other threads in the same thread group are _not_ affected. |
San Mehat | e9d376b | 2009-04-21 14:06:36 -0700 | [diff] [blame] | 866 | */ |
| 867 | public static final native void setThreadGroup(int tid, int group) |
| 868 | throws IllegalArgumentException, SecurityException; |
Glenn Kasten | f1b5644 | 2012-03-15 16:33:43 -0700 | [diff] [blame] | 869 | |
San Mehat | 3e45824 | 2009-05-19 14:44:16 -0700 | [diff] [blame] | 870 | /** |
| 871 | * Sets the scheduling group for a process and all child threads |
| 872 | * @hide |
Glenn Kasten | f1b5644 | 2012-03-15 16:33:43 -0700 | [diff] [blame] | 873 | * @param pid The identifier of the process to change. |
| 874 | * @param group The target group for this process from THREAD_GROUP_*. |
San Mehat | 3e45824 | 2009-05-19 14:44:16 -0700 | [diff] [blame] | 875 | * |
| 876 | * @throws IllegalArgumentException Throws IllegalArgumentException if |
| 877 | * <var>tid</var> does not exist. |
| 878 | * @throws SecurityException Throws SecurityException if your process does |
| 879 | * not have permission to modify the given thread, or to use the given |
| 880 | * priority. |
Glenn Kasten | f1b5644 | 2012-03-15 16:33:43 -0700 | [diff] [blame] | 881 | * |
| 882 | * group == THREAD_GROUP_DEFAULT means to move all non-background priority |
| 883 | * threads to the foreground scheduling group, but to leave background |
| 884 | * priority threads alone. group == THREAD_GROUP_BG_NONINTERACTIVE moves all |
| 885 | * threads, regardless of priority, to the background scheduling group. |
| 886 | * group == THREAD_GROUP_FOREGROUND is not allowed. |
San Mehat | 3e45824 | 2009-05-19 14:44:16 -0700 | [diff] [blame] | 887 | */ |
| 888 | public static final native void setProcessGroup(int pid, int group) |
| 889 | throws IllegalArgumentException, SecurityException; |
Jeff Sharkey | 9e57c41 | 2013-01-17 14:12:41 -0800 | [diff] [blame] | 890 | |
| 891 | /** |
| 892 | * Return the scheduling group of requested process. |
| 893 | * |
| 894 | * @hide |
| 895 | */ |
| 896 | public static final native int getProcessGroup(int pid) |
| 897 | throws IllegalArgumentException, SecurityException; |
| 898 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 899 | /** |
| 900 | * Set the priority of the calling thread, based on Linux priorities. See |
| 901 | * {@link #setThreadPriority(int, int)} for more information. |
| 902 | * |
| 903 | * @param priority A Linux priority level, from -20 for highest scheduling |
| 904 | * priority to 19 for lowest scheduling priority. |
| 905 | * |
| 906 | * @throws IllegalArgumentException Throws IllegalArgumentException if |
| 907 | * <var>tid</var> does not exist. |
| 908 | * @throws SecurityException Throws SecurityException if your process does |
| 909 | * not have permission to modify the given thread, or to use the given |
| 910 | * priority. |
| 911 | * |
| 912 | * @see #setThreadPriority(int, int) |
| 913 | */ |
| 914 | public static final native void setThreadPriority(int priority) |
| 915 | throws IllegalArgumentException, SecurityException; |
| 916 | |
| 917 | /** |
| 918 | * Return the current priority of a thread, based on Linux priorities. |
| 919 | * |
| 920 | * @param tid The identifier of the thread/process to change. |
| 921 | * |
| 922 | * @return Returns the current priority, as a Linux priority level, |
| 923 | * from -20 for highest scheduling priority to 19 for lowest scheduling |
| 924 | * priority. |
| 925 | * |
| 926 | * @throws IllegalArgumentException Throws IllegalArgumentException if |
| 927 | * <var>tid</var> does not exist. |
| 928 | */ |
| 929 | public static final native int getThreadPriority(int tid) |
| 930 | throws IllegalArgumentException; |
| 931 | |
| 932 | /** |
Glenn Kasten | 6793ac9 | 2011-07-13 12:44:12 -0700 | [diff] [blame] | 933 | * Set the scheduling policy and priority of a thread, based on Linux. |
| 934 | * |
| 935 | * @param tid The identifier of the thread/process to change. |
| 936 | * @param policy A Linux scheduling policy such as SCHED_OTHER etc. |
| 937 | * @param priority A Linux priority level in a range appropriate for the given policy. |
| 938 | * |
| 939 | * @throws IllegalArgumentException Throws IllegalArgumentException if |
| 940 | * <var>tid</var> does not exist, or if <var>priority</var> is out of range for the policy. |
| 941 | * @throws SecurityException Throws SecurityException if your process does |
| 942 | * not have permission to modify the given thread, or to use the given |
| 943 | * scheduling policy or priority. |
| 944 | * |
| 945 | * {@hide} |
| 946 | */ |
| 947 | public static final native void setThreadScheduler(int tid, int policy, int priority) |
| 948 | throws IllegalArgumentException; |
| 949 | |
| 950 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 951 | * Determine whether the current environment supports multiple processes. |
| 952 | * |
| 953 | * @return Returns true if the system can run in multiple processes, else |
| 954 | * false if everything is running in a single process. |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 955 | * |
| 956 | * @deprecated This method always returns true. Do not use. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 957 | */ |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 958 | @Deprecated |
| 959 | public static final boolean supportsProcesses() { |
| 960 | return true; |
| 961 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 962 | |
| 963 | /** |
| 964 | * Set the out-of-memory badness adjustment for a process. |
| 965 | * |
| 966 | * @param pid The process identifier to set. |
| 967 | * @param amt Adjustment value -- linux allows -16 to +15. |
| 968 | * |
| 969 | * @return Returns true if the underlying system supports this |
| 970 | * feature, else false. |
| 971 | * |
| 972 | * {@hide} |
| 973 | */ |
| 974 | public static final native boolean setOomAdj(int pid, int amt); |
| 975 | |
| 976 | /** |
Rom Lemarchand | 5534ba9 | 2013-07-12 16:15:36 -0700 | [diff] [blame] | 977 | * Adjust the swappiness level for a process. |
| 978 | * |
| 979 | * @param pid The process identifier to set. |
| 980 | * @param is_increased Whether swappiness should be increased or default. |
| 981 | * |
| 982 | * @return Returns true if the underlying system supports this |
| 983 | * feature, else false. |
| 984 | * |
| 985 | * {@hide} |
| 986 | */ |
| 987 | public static final native boolean setSwappiness(int pid, boolean is_increased); |
| 988 | |
| 989 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 990 | * Change this process's argv[0] parameter. This can be useful to show |
| 991 | * more descriptive information in things like the 'ps' command. |
| 992 | * |
| 993 | * @param text The new name of this process. |
| 994 | * |
| 995 | * {@hide} |
| 996 | */ |
| 997 | public static final native void setArgV0(String text); |
| 998 | |
| 999 | /** |
| 1000 | * Kill the process with the given PID. |
| 1001 | * Note that, though this API allows us to request to |
| 1002 | * kill any process based on its PID, the kernel will |
| 1003 | * still impose standard restrictions on which PIDs you |
| 1004 | * are actually able to kill. Typically this means only |
| 1005 | * the process running the caller's packages/application |
| 1006 | * and any additional processes created by that app; packages |
| 1007 | * sharing a common UID will also be able to kill each |
| 1008 | * other's processes. |
| 1009 | */ |
| 1010 | public static final void killProcess(int pid) { |
| 1011 | sendSignal(pid, SIGNAL_KILL); |
| 1012 | } |
| 1013 | |
| 1014 | /** @hide */ |
| 1015 | public static final native int setUid(int uid); |
| 1016 | |
| 1017 | /** @hide */ |
| 1018 | public static final native int setGid(int uid); |
| 1019 | |
| 1020 | /** |
| 1021 | * Send a signal to the given process. |
| 1022 | * |
| 1023 | * @param pid The pid of the target process. |
| 1024 | * @param signal The signal to send. |
| 1025 | */ |
| 1026 | public static final native void sendSignal(int pid, int signal); |
| 1027 | |
Dianne Hackborn | 906497c | 2010-05-10 15:57:38 -0700 | [diff] [blame] | 1028 | /** |
| 1029 | * @hide |
| 1030 | * Private impl for avoiding a log message... DO NOT USE without doing |
| 1031 | * your own log, or the Android Illuminati will find you some night and |
| 1032 | * beat you up. |
| 1033 | */ |
| 1034 | public static final void killProcessQuiet(int pid) { |
| 1035 | sendSignalQuiet(pid, SIGNAL_KILL); |
| 1036 | } |
| 1037 | |
| 1038 | /** |
| 1039 | * @hide |
| 1040 | * Private impl for avoiding a log message... DO NOT USE without doing |
| 1041 | * your own log, or the Android Illuminati will find you some night and |
| 1042 | * beat you up. |
| 1043 | */ |
| 1044 | public static final native void sendSignalQuiet(int pid, int signal); |
| 1045 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1046 | /** @hide */ |
Marco Nelissen | 0bca96b | 2009-07-17 12:59:25 -0700 | [diff] [blame] | 1047 | public static final native long getFreeMemory(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1048 | |
| 1049 | /** @hide */ |
Dianne Hackborn | 59325eb | 2012-05-09 18:45:20 -0700 | [diff] [blame] | 1050 | public static final native long getTotalMemory(); |
| 1051 | |
| 1052 | /** @hide */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1053 | public static final native void readProcLines(String path, |
| 1054 | String[] reqFields, long[] outSizes); |
| 1055 | |
| 1056 | /** @hide */ |
| 1057 | public static final native int[] getPids(String path, int[] lastArray); |
| 1058 | |
| 1059 | /** @hide */ |
| 1060 | public static final int PROC_TERM_MASK = 0xff; |
| 1061 | /** @hide */ |
| 1062 | public static final int PROC_ZERO_TERM = 0; |
| 1063 | /** @hide */ |
| 1064 | public static final int PROC_SPACE_TERM = (int)' '; |
| 1065 | /** @hide */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1066 | public static final int PROC_TAB_TERM = (int)'\t'; |
| 1067 | /** @hide */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1068 | public static final int PROC_COMBINE = 0x100; |
| 1069 | /** @hide */ |
| 1070 | public static final int PROC_PARENS = 0x200; |
| 1071 | /** @hide */ |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 1072 | public static final int PROC_QUOTES = 0x400; |
| 1073 | /** @hide */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1074 | public static final int PROC_OUT_STRING = 0x1000; |
| 1075 | /** @hide */ |
| 1076 | public static final int PROC_OUT_LONG = 0x2000; |
| 1077 | /** @hide */ |
| 1078 | public static final int PROC_OUT_FLOAT = 0x4000; |
| 1079 | |
| 1080 | /** @hide */ |
| 1081 | public static final native boolean readProcFile(String file, int[] format, |
| 1082 | String[] outStrings, long[] outLongs, float[] outFloats); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1083 | |
| 1084 | /** @hide */ |
| 1085 | public static final native boolean parseProcLine(byte[] buffer, int startIndex, |
| 1086 | int endIndex, int[] format, String[] outStrings, long[] outLongs, float[] outFloats); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1087 | |
Dianne Hackborn | f72467a | 2012-06-08 17:23:59 -0700 | [diff] [blame] | 1088 | /** @hide */ |
| 1089 | public static final native int[] getPidsForCommands(String[] cmds); |
| 1090 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1091 | /** |
| 1092 | * Gets the total Pss value for a given process, in bytes. |
| 1093 | * |
| 1094 | * @param pid the process to the Pss for |
| 1095 | * @return the total Pss value for the given process in bytes, |
| 1096 | * or -1 if the value cannot be determined |
| 1097 | * @hide |
| 1098 | */ |
| 1099 | public static final native long getPss(int pid); |
Jeff Brown | 3f9dd28 | 2011-07-08 20:02:19 -0700 | [diff] [blame] | 1100 | |
| 1101 | /** |
| 1102 | * Specifies the outcome of having started a process. |
| 1103 | * @hide |
| 1104 | */ |
| 1105 | public static final class ProcessStartResult { |
| 1106 | /** |
| 1107 | * The PID of the newly started process. |
| 1108 | * Always >= 0. (If the start failed, an exception will have been thrown instead.) |
| 1109 | */ |
| 1110 | public int pid; |
| 1111 | |
| 1112 | /** |
| 1113 | * True if the process was started with a wrapper attached. |
| 1114 | */ |
| 1115 | public boolean usingWrapper; |
| 1116 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1117 | } |