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 | |
Sudheer Shanka | d81b1d7 | 2018-09-05 16:37:30 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.Nullable; |
Srinath Sridharan | 1b15d13 | 2016-07-19 15:16:11 -0700 | [diff] [blame] | 21 | import android.annotation.TestApi; |
Elliott Hughes | 34385d3 | 2014-04-28 11:11:32 -0700 | [diff] [blame] | 22 | import android.system.Os; |
Tim Murray | b89970e | 2016-07-01 10:42:20 -0700 | [diff] [blame] | 23 | import android.system.OsConstants; |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 24 | import android.webkit.WebViewZygote; |
Nicolas Geoffray | 81edac4 | 2017-09-07 14:13:29 +0100 | [diff] [blame] | 25 | |
Andreas Gampe | ee0cdce | 2015-06-08 20:47:50 -0700 | [diff] [blame] | 26 | import dalvik.system.VMRuntime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Tools for managing OS processes. |
| 30 | */ |
| 31 | public class Process { |
| 32 | private static final String LOG_TAG = "Process"; |
| 33 | |
Narayan Kamath | 64cd907 | 2014-05-13 13:35:14 +0100 | [diff] [blame] | 34 | /** |
Jeff Vander Stoep | 0ac2c09 | 2018-07-23 10:57:53 -0700 | [diff] [blame] | 35 | * An invalid UID value. |
| 36 | */ |
| 37 | public static final int INVALID_UID = -1; |
| 38 | |
| 39 | /** |
Jeff Sharkey | 1cb2d0d | 2014-07-30 16:45:01 -0700 | [diff] [blame] | 40 | * Defines the root UID. |
Jeff Sharkey | 1cb2d0d | 2014-07-30 16:45:01 -0700 | [diff] [blame] | 41 | */ |
| 42 | public static final int ROOT_UID = 0; |
| 43 | |
| 44 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | * Defines the UID/GID under which system code runs. |
| 46 | */ |
| 47 | public static final int SYSTEM_UID = 1000; |
| 48 | |
| 49 | /** |
| 50 | * Defines the UID/GID under which the telephony code runs. |
| 51 | */ |
| 52 | public static final int PHONE_UID = 1001; |
| 53 | |
| 54 | /** |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 55 | * Defines the UID/GID for the user shell. |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 56 | */ |
| 57 | public static final int SHELL_UID = 2000; |
| 58 | |
| 59 | /** |
Mike Lockwood | d42685d | 2009-09-03 09:25:22 -0400 | [diff] [blame] | 60 | * Defines the UID/GID for the log group. |
| 61 | * @hide |
| 62 | */ |
| 63 | public static final int LOG_UID = 1007; |
| 64 | |
| 65 | /** |
Amith Yamasani | d158214 | 2009-07-08 20:04:55 -0700 | [diff] [blame] | 66 | * Defines the UID/GID for the WIFI supplicant process. |
| 67 | * @hide |
| 68 | */ |
| 69 | public static final int WIFI_UID = 1010; |
| 70 | |
| 71 | /** |
Glenn Kasten | 8b7d1b4 | 2011-07-13 16:23:22 -0700 | [diff] [blame] | 72 | * Defines the UID/GID for the mediaserver process. |
| 73 | * @hide |
| 74 | */ |
| 75 | public static final int MEDIA_UID = 1013; |
| 76 | |
| 77 | /** |
Jeff Sharkey | 5294a2f | 2012-04-24 17:07:22 -0700 | [diff] [blame] | 78 | * Defines the UID/GID for the DRM process. |
| 79 | * @hide |
| 80 | */ |
| 81 | public static final int DRM_UID = 1019; |
| 82 | |
| 83 | /** |
Kenny Root | 26993b3 | 2012-03-19 15:07:51 -0700 | [diff] [blame] | 84 | * Defines the UID/GID for the group that controls VPN services. |
| 85 | * @hide |
| 86 | */ |
| 87 | public static final int VPN_UID = 1016; |
| 88 | |
| 89 | /** |
Janis Danisevskis | 6ab9bb6 | 2017-03-08 10:35:00 -0800 | [diff] [blame] | 90 | * Defines the UID/GID for keystore. |
| 91 | * @hide |
| 92 | */ |
| 93 | public static final int KEYSTORE_UID = 1017; |
| 94 | |
| 95 | /** |
Nick Pelly | cd0e839 | 2010-10-13 17:25:24 -0700 | [diff] [blame] | 96 | * Defines the UID/GID for the NFC service process. |
| 97 | * @hide |
| 98 | */ |
Nick Pelly | a5cb9f4 | 2011-11-21 14:54:46 -0800 | [diff] [blame] | 99 | public static final int NFC_UID = 1027; |
Nick Pelly | cd0e839 | 2010-10-13 17:25:24 -0700 | [diff] [blame] | 100 | |
| 101 | /** |
junyulai | f6ebf4a | 2018-10-30 21:49:38 +0800 | [diff] [blame] | 102 | * Defines the UID/GID for the clatd process. |
| 103 | * @hide |
| 104 | * */ |
| 105 | public static final int CLAT_UID = 1029; |
| 106 | |
| 107 | /** |
Jaikumar Ganesh | 1abb1cb | 2012-01-25 16:14:50 -0800 | [diff] [blame] | 108 | * Defines the UID/GID for the Bluetooth service process. |
Jaikumar Ganesh | 1abb1cb | 2012-01-25 16:14:50 -0800 | [diff] [blame] | 109 | */ |
| 110 | public static final int BLUETOOTH_UID = 1002; |
| 111 | |
| 112 | /** |
Mike Lockwood | dcaa10c | 2010-12-16 12:50:44 -0800 | [diff] [blame] | 113 | * Defines the GID for the group that allows write access to the internal media storage. |
| 114 | * @hide |
| 115 | */ |
| 116 | public static final int MEDIA_RW_GID = 1023; |
| 117 | |
| 118 | /** |
Jeff Sharkey | 184a010 | 2013-07-10 16:19:52 -0700 | [diff] [blame] | 119 | * Access to installed package details |
| 120 | * @hide |
| 121 | */ |
| 122 | public static final int PACKAGE_INFO_GID = 1032; |
| 123 | |
| 124 | /** |
Torne (Richard Coles) | 08cfaf6 | 2014-05-08 16:07:05 +0100 | [diff] [blame] | 125 | * Defines the UID/GID for the shared RELRO file updater process. |
| 126 | * @hide |
| 127 | */ |
| 128 | public static final int SHARED_RELRO_UID = 1037; |
| 129 | |
| 130 | /** |
Andy Hung | ed0ea40 | 2015-10-30 14:11:46 -0700 | [diff] [blame] | 131 | * Defines the UID/GID for the audioserver process. |
| 132 | * @hide |
| 133 | */ |
| 134 | public static final int AUDIOSERVER_UID = 1041; |
| 135 | |
| 136 | /** |
Chien-Yu Chen | 75cade0 | 2016-01-11 10:56:21 -0800 | [diff] [blame] | 137 | * Defines the UID/GID for the cameraserver process |
| 138 | * @hide |
| 139 | */ |
Chien-Yu Chen | b8b4e85 | 2016-01-29 12:02:28 -0800 | [diff] [blame] | 140 | public static final int CAMERASERVER_UID = 1047; |
Chien-Yu Chen | 75cade0 | 2016-01-11 10:56:21 -0800 | [diff] [blame] | 141 | |
| 142 | /** |
Lorenzo Colitti | f4b4f4d | 2018-03-01 21:06:11 +0900 | [diff] [blame] | 143 | * Defines the UID/GID for the tethering DNS resolver (currently dnsmasq). |
| 144 | * @hide |
| 145 | */ |
| 146 | public static final int DNS_TETHER_UID = 1052; |
| 147 | |
| 148 | /** |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 149 | * Defines the UID/GID for the WebView zygote process. |
| 150 | * @hide |
| 151 | */ |
Robert Sesek | bceb382 | 2018-01-22 12:26:39 -0500 | [diff] [blame] | 152 | public static final int WEBVIEW_ZYGOTE_UID = 1053; |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 153 | |
| 154 | /** |
Jeff Sharkey | 07c5c6f | 2017-03-21 10:09:50 -0600 | [diff] [blame] | 155 | * Defines the UID used for resource tracking for OTA updates. |
| 156 | * @hide |
| 157 | */ |
| 158 | public static final int OTA_UPDATE_UID = 1061; |
| 159 | |
Yi Jin | 4bab3a1 | 2018-01-10 16:50:59 -0800 | [diff] [blame] | 160 | /** |
| 161 | * Defines the UID used for incidentd. |
| 162 | * @hide |
| 163 | */ |
| 164 | public static final int INCIDENTD_UID = 1067; |
| 165 | |
Ruchi Kandoi | 6149b0f | 2018-01-03 16:14:57 -0800 | [diff] [blame] | 166 | /** |
| 167 | * Defines the UID/GID for the Secure Element service process. |
| 168 | * @hide |
| 169 | */ |
| 170 | public static final int SE_UID = 1068; |
| 171 | |
Remi NGUYEN VAN | c094a54 | 2018-12-07 16:52:24 +0900 | [diff] [blame] | 172 | /** |
| 173 | * Defines the UID/GID for the NetworkStack app. |
| 174 | * @hide |
| 175 | */ |
| 176 | public static final int NETWORK_STACK_UID = 1073; |
| 177 | |
Jeff Sharkey | a73e165 | 2017-11-15 19:07:14 -0700 | [diff] [blame] | 178 | /** {@hide} */ |
| 179 | public static final int NOBODY_UID = 9999; |
| 180 | |
Jeff Sharkey | 07c5c6f | 2017-03-21 10:09:50 -0600 | [diff] [blame] | 181 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | * Defines the start of a range of UIDs (and GIDs), going from this |
| 183 | * number to {@link #LAST_APPLICATION_UID} that are reserved for assigning |
| 184 | * to applications. |
| 185 | */ |
| 186 | public static final int FIRST_APPLICATION_UID = 10000; |
Jeff Sharkey | 184a010 | 2013-07-10 16:19:52 -0700 | [diff] [blame] | 187 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | /** |
| 189 | * Last of application-specific UIDs starting at |
| 190 | * {@link #FIRST_APPLICATION_UID}. |
| 191 | */ |
Dianne Hackborn | 21fbd1f | 2012-02-10 10:38:10 -0800 | [diff] [blame] | 192 | public static final int LAST_APPLICATION_UID = 19999; |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 193 | |
| 194 | /** |
Martijn Coenen | 01e719b | 2018-12-05 16:01:38 +0100 | [diff] [blame] | 195 | * First uid used for fully isolated sandboxed processes spawned from an app zygote |
| 196 | * @hide |
| 197 | */ |
Martijn Coenen | dbf6abc | 2019-01-10 08:37:45 +0100 | [diff] [blame] | 198 | @TestApi |
Martijn Coenen | 01e719b | 2018-12-05 16:01:38 +0100 | [diff] [blame] | 199 | public static final int FIRST_APP_ZYGOTE_ISOLATED_UID = 90000; |
| 200 | |
| 201 | /** |
| 202 | * Number of UIDs we allocate per application zygote |
| 203 | * @hide |
| 204 | */ |
Martijn Coenen | dbf6abc | 2019-01-10 08:37:45 +0100 | [diff] [blame] | 205 | @TestApi |
Martijn Coenen | 01e719b | 2018-12-05 16:01:38 +0100 | [diff] [blame] | 206 | public static final int NUM_UIDS_PER_APP_ZYGOTE = 100; |
| 207 | |
| 208 | /** |
| 209 | * Last uid used for fully isolated sandboxed processes spawned from an app zygote |
| 210 | * @hide |
| 211 | */ |
Martijn Coenen | dbf6abc | 2019-01-10 08:37:45 +0100 | [diff] [blame] | 212 | @TestApi |
Martijn Coenen | 01e719b | 2018-12-05 16:01:38 +0100 | [diff] [blame] | 213 | public static final int LAST_APP_ZYGOTE_ISOLATED_UID = 98999; |
| 214 | |
| 215 | /** |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 216 | * First uid used for fully isolated sandboxed processes (with no permissions of their own) |
| 217 | * @hide |
| 218 | */ |
Martijn Coenen | dbf6abc | 2019-01-10 08:37:45 +0100 | [diff] [blame] | 219 | @TestApi |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 220 | public static final int FIRST_ISOLATED_UID = 99000; |
| 221 | |
| 222 | /** |
| 223 | * Last uid used for fully isolated sandboxed processes (with no permissions of their own) |
| 224 | * @hide |
| 225 | */ |
Martijn Coenen | dbf6abc | 2019-01-10 08:37:45 +0100 | [diff] [blame] | 226 | @TestApi |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 227 | public static final int LAST_ISOLATED_UID = 99999; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | |
| 229 | /** |
Robin Lee | e66b689 | 2014-04-29 12:36:47 +0100 | [diff] [blame] | 230 | * Defines the gid shared by all applications running under the same profile. |
| 231 | * @hide |
| 232 | */ |
| 233 | public static final int SHARED_USER_GID = 9997; |
| 234 | |
| 235 | /** |
Kenny Root | e091f22 | 2012-09-11 15:01:26 -0700 | [diff] [blame] | 236 | * First gid for applications to share resources. Used when forward-locking |
| 237 | * is enabled but all UserHandles need to be able to read the resources. |
| 238 | * @hide |
| 239 | */ |
| 240 | public static final int FIRST_SHARED_APPLICATION_GID = 50000; |
| 241 | |
| 242 | /** |
| 243 | * Last gid for applications to share resources. Used when forward-locking |
| 244 | * is enabled but all UserHandles need to be able to read the resources. |
| 245 | * @hide |
| 246 | */ |
| 247 | public static final int LAST_SHARED_APPLICATION_GID = 59999; |
| 248 | |
Jeff Sharkey | 5eb3eb5 | 2016-12-13 08:44:51 -0700 | [diff] [blame] | 249 | /** {@hide} */ |
| 250 | public static final int FIRST_APPLICATION_CACHE_GID = 20000; |
| 251 | /** {@hide} */ |
| 252 | public static final int LAST_APPLICATION_CACHE_GID = 29999; |
| 253 | |
Kenny Root | e091f22 | 2012-09-11 15:01:26 -0700 | [diff] [blame] | 254 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | * Standard priority of application threads. |
| 256 | * Use with {@link #setThreadPriority(int)} and |
| 257 | * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal |
| 258 | * {@link java.lang.Thread} class. |
| 259 | */ |
| 260 | public static final int THREAD_PRIORITY_DEFAULT = 0; |
| 261 | |
| 262 | /* |
| 263 | * *************************************** |
| 264 | * ** Keep in sync with utils/threads.h ** |
| 265 | * *************************************** |
| 266 | */ |
| 267 | |
| 268 | /** |
| 269 | * Lowest available thread priority. Only for those who really, really |
| 270 | * don't want to run if anything else is happening. |
| 271 | * Use with {@link #setThreadPriority(int)} and |
| 272 | * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal |
| 273 | * {@link java.lang.Thread} class. |
| 274 | */ |
| 275 | public static final int THREAD_PRIORITY_LOWEST = 19; |
| 276 | |
| 277 | /** |
| 278 | * Standard priority background threads. This gives your thread a slightly |
| 279 | * lower than normal priority, so that it will have less chance of impacting |
| 280 | * the responsiveness of the user interface. |
| 281 | * Use with {@link #setThreadPriority(int)} and |
| 282 | * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal |
| 283 | * {@link java.lang.Thread} class. |
| 284 | */ |
| 285 | public static final int THREAD_PRIORITY_BACKGROUND = 10; |
| 286 | |
| 287 | /** |
| 288 | * Standard priority of threads that are currently running a user interface |
| 289 | * that the user is interacting with. Applications can not normally |
| 290 | * change to this priority; the system will automatically adjust your |
| 291 | * application threads as the user moves through the UI. |
| 292 | * Use with {@link #setThreadPriority(int)} and |
| 293 | * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal |
| 294 | * {@link java.lang.Thread} class. |
| 295 | */ |
| 296 | public static final int THREAD_PRIORITY_FOREGROUND = -2; |
| 297 | |
| 298 | /** |
| 299 | * Standard priority of system display threads, involved in updating |
| 300 | * the user interface. Applications can not |
| 301 | * normally change to this priority. |
| 302 | * Use with {@link #setThreadPriority(int)} and |
| 303 | * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal |
| 304 | * {@link java.lang.Thread} class. |
| 305 | */ |
| 306 | public static final int THREAD_PRIORITY_DISPLAY = -4; |
| 307 | |
| 308 | /** |
| 309 | * Standard priority of the most important display threads, for compositing |
| 310 | * the screen and retrieving input events. Applications can not normally |
| 311 | * change to this priority. |
| 312 | * Use with {@link #setThreadPriority(int)} and |
| 313 | * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal |
| 314 | * {@link java.lang.Thread} class. |
| 315 | */ |
| 316 | public static final int THREAD_PRIORITY_URGENT_DISPLAY = -8; |
| 317 | |
| 318 | /** |
Jeff Tinker | 9765e20 | 2018-01-08 15:05:48 -0800 | [diff] [blame] | 319 | * Standard priority of video threads. Applications can not normally |
| 320 | * change to this priority. |
| 321 | * Use with {@link #setThreadPriority(int)} and |
| 322 | * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal |
| 323 | * {@link java.lang.Thread} class. |
| 324 | */ |
| 325 | public static final int THREAD_PRIORITY_VIDEO = -10; |
| 326 | |
| 327 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 328 | * Standard priority of audio threads. Applications can not normally |
| 329 | * change to this priority. |
| 330 | * Use with {@link #setThreadPriority(int)} and |
| 331 | * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal |
| 332 | * {@link java.lang.Thread} class. |
| 333 | */ |
| 334 | public static final int THREAD_PRIORITY_AUDIO = -16; |
| 335 | |
| 336 | /** |
| 337 | * Standard priority of the most important audio threads. |
| 338 | * Applications can not normally change to this priority. |
| 339 | * Use with {@link #setThreadPriority(int)} and |
| 340 | * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal |
| 341 | * {@link java.lang.Thread} class. |
| 342 | */ |
| 343 | public static final int THREAD_PRIORITY_URGENT_AUDIO = -19; |
| 344 | |
| 345 | /** |
| 346 | * Minimum increment to make a priority more favorable. |
| 347 | */ |
| 348 | public static final int THREAD_PRIORITY_MORE_FAVORABLE = -1; |
| 349 | |
| 350 | /** |
| 351 | * Minimum increment to make a priority less favorable. |
| 352 | */ |
| 353 | public static final int THREAD_PRIORITY_LESS_FAVORABLE = +1; |
| 354 | |
San Mehat | e9d376b | 2009-04-21 14:06:36 -0700 | [diff] [blame] | 355 | /** |
Glenn Kasten | 6793ac9 | 2011-07-13 12:44:12 -0700 | [diff] [blame] | 356 | * Default scheduling policy |
| 357 | * @hide |
| 358 | */ |
| 359 | public static final int SCHED_OTHER = 0; |
| 360 | |
| 361 | /** |
| 362 | * First-In First-Out scheduling policy |
| 363 | * @hide |
| 364 | */ |
| 365 | public static final int SCHED_FIFO = 1; |
| 366 | |
| 367 | /** |
| 368 | * Round-Robin scheduling policy |
| 369 | * @hide |
| 370 | */ |
| 371 | public static final int SCHED_RR = 2; |
| 372 | |
| 373 | /** |
| 374 | * Batch scheduling policy |
| 375 | * @hide |
| 376 | */ |
| 377 | public static final int SCHED_BATCH = 3; |
| 378 | |
| 379 | /** |
| 380 | * Idle scheduling policy |
| 381 | * @hide |
| 382 | */ |
| 383 | public static final int SCHED_IDLE = 5; |
| 384 | |
Srinath Sridharan | e535a58 | 2016-06-27 18:13:47 -0700 | [diff] [blame] | 385 | /** |
| 386 | * Reset scheduler choice on fork. |
| 387 | * @hide |
| 388 | */ |
| 389 | public static final int SCHED_RESET_ON_FORK = 0x40000000; |
| 390 | |
Glenn Kasten | f1b5644 | 2012-03-15 16:33:43 -0700 | [diff] [blame] | 391 | // Keep in sync with SP_* constants of enum type SchedPolicy |
| 392 | // declared in system/core/include/cutils/sched_policy.h, |
| 393 | // except THREAD_GROUP_DEFAULT does not correspond to any SP_* value. |
San Mehat | e9d376b | 2009-04-21 14:06:36 -0700 | [diff] [blame] | 394 | |
| 395 | /** |
Glenn Kasten | f1b5644 | 2012-03-15 16:33:43 -0700 | [diff] [blame] | 396 | * Default thread group - |
| 397 | * has meaning with setProcessGroup() only, cannot be used with setThreadGroup(). |
| 398 | * When used with setProcessGroup(), the group of each thread in the process |
| 399 | * is conditionally changed based on that thread's current priority, as follows: |
| 400 | * threads with priority numerically less than THREAD_PRIORITY_BACKGROUND |
| 401 | * are moved to foreground thread group. All other threads are left unchanged. |
| 402 | * @hide |
| 403 | */ |
| 404 | public static final int THREAD_GROUP_DEFAULT = -1; |
| 405 | |
| 406 | /** |
| 407 | * Background thread group - All threads in |
San Mehat | e9d376b | 2009-04-21 14:06:36 -0700 | [diff] [blame] | 408 | * this group are scheduled with a reduced share of the CPU. |
Glenn Kasten | f1b5644 | 2012-03-15 16:33:43 -0700 | [diff] [blame] | 409 | * Value is same as constant SP_BACKGROUND of enum SchedPolicy. |
| 410 | * FIXME rename to THREAD_GROUP_BACKGROUND. |
San Mehat | e9d376b | 2009-04-21 14:06:36 -0700 | [diff] [blame] | 411 | * @hide |
| 412 | */ |
Glenn Kasten | f1b5644 | 2012-03-15 16:33:43 -0700 | [diff] [blame] | 413 | public static final int THREAD_GROUP_BG_NONINTERACTIVE = 0; |
San Mehat | e9d376b | 2009-04-21 14:06:36 -0700 | [diff] [blame] | 414 | |
| 415 | /** |
Glenn Kasten | f1b5644 | 2012-03-15 16:33:43 -0700 | [diff] [blame] | 416 | * Foreground thread group - All threads in |
| 417 | * this group are scheduled with a normal share of the CPU. |
| 418 | * Value is same as constant SP_FOREGROUND of enum SchedPolicy. |
| 419 | * Not used at this level. |
San Mehat | e9d376b | 2009-04-21 14:06:36 -0700 | [diff] [blame] | 420 | * @hide |
| 421 | **/ |
Glenn Kasten | f1b5644 | 2012-03-15 16:33:43 -0700 | [diff] [blame] | 422 | private static final int THREAD_GROUP_FOREGROUND = 1; |
San Mehat | e9d376b | 2009-04-21 14:06:36 -0700 | [diff] [blame] | 423 | |
Glenn Kasten | 07b0465 | 2012-04-23 15:00:43 -0700 | [diff] [blame] | 424 | /** |
| 425 | * System thread group. |
| 426 | * @hide |
| 427 | **/ |
| 428 | public static final int THREAD_GROUP_SYSTEM = 2; |
| 429 | |
| 430 | /** |
| 431 | * Application audio thread group. |
| 432 | * @hide |
| 433 | **/ |
| 434 | public static final int THREAD_GROUP_AUDIO_APP = 3; |
| 435 | |
| 436 | /** |
| 437 | * System audio thread group. |
| 438 | * @hide |
| 439 | **/ |
| 440 | public static final int THREAD_GROUP_AUDIO_SYS = 4; |
| 441 | |
Tim Murray | ece6a22 | 2016-01-14 11:22:57 -0800 | [diff] [blame] | 442 | /** |
| 443 | * Thread group for top foreground app. |
| 444 | * @hide |
| 445 | **/ |
| 446 | public static final int THREAD_GROUP_TOP_APP = 5; |
| 447 | |
Joel Fernandes | 5977600 | 2017-04-17 13:40:16 -0700 | [diff] [blame] | 448 | /** |
| 449 | * Thread group for RT app. |
| 450 | * @hide |
| 451 | **/ |
| 452 | public static final int THREAD_GROUP_RT_APP = 6; |
| 453 | |
Tim Murray | fef10a4 | 2018-04-13 10:15:17 -0700 | [diff] [blame] | 454 | /** |
| 455 | * Thread group for bound foreground services that should |
| 456 | * have additional CPU restrictions during screen off |
| 457 | * @hide |
| 458 | **/ |
| 459 | public static final int THREAD_GROUP_RESTRICTED = 7; |
| 460 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 461 | public static final int SIGNAL_QUIT = 3; |
| 462 | public static final int SIGNAL_KILL = 9; |
| 463 | public static final int SIGNAL_USR1 = 10; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 464 | |
Dianne Hackborn | d98885c | 2016-03-01 17:13:03 -0800 | [diff] [blame] | 465 | private static long sStartElapsedRealtime; |
| 466 | private static long sStartUptimeMillis; |
| 467 | |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 468 | /** |
Robert Sesek | 8f8d187 | 2016-03-18 16:52:57 -0400 | [diff] [blame] | 469 | * State associated with the zygote process. |
| 470 | * @hide |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 471 | */ |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 472 | public static final ZygoteProcess ZYGOTE_PROCESS = new ZygoteProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 473 | |
| 474 | /** |
| 475 | * Start a new process. |
| 476 | * |
| 477 | * <p>If processes are enabled, a new process is created and the |
| 478 | * static main() function of a <var>processClass</var> is executed there. |
| 479 | * The process will continue running after this function returns. |
| 480 | * |
| 481 | * <p>If processes are not enabled, a new thread in the caller's |
| 482 | * process is created and main() of <var>processClass</var> called there. |
| 483 | * |
| 484 | * <p>The niceName parameter, if not an empty string, is a custom name to |
| 485 | * give to the process instead of using processClass. This allows you to |
| 486 | * make easily identifyable processes even if you are using the same base |
| 487 | * <var>processClass</var> to start them. |
| 488 | * |
Tamas Berghammer | b8f7c35 | 2016-11-11 16:08:26 +0000 | [diff] [blame] | 489 | * When invokeWith is not null, the process will be started as a fresh app |
Tamas Berghammer | 0ca16fa | 2016-11-11 16:08:26 +0000 | [diff] [blame] | 490 | * and not a zygote fork. Note that this is only allowed for uid 0 or when |
Nicolas Geoffray | 81edac4 | 2017-09-07 14:13:29 +0100 | [diff] [blame] | 491 | * runtimeFlags contains DEBUG_ENABLE_DEBUGGER. |
Tamas Berghammer | b8f7c35 | 2016-11-11 16:08:26 +0000 | [diff] [blame] | 492 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 493 | * @param processClass The class to use as the process's main entry |
| 494 | * point. |
| 495 | * @param niceName A more readable name to use for the process. |
| 496 | * @param uid The user-id under which the process will run. |
| 497 | * @param gid The group-id under which the process will run. |
| 498 | * @param gids Additional group-ids associated with the process. |
Nicolas Geoffray | 81edac4 | 2017-09-07 14:13:29 +0100 | [diff] [blame] | 499 | * @param runtimeFlags Additional flags for the runtime. |
Elliott Hughes | e1dfcb7 | 2011-07-08 11:08:07 -0700 | [diff] [blame] | 500 | * @param targetSdkVersion The target SDK version for the app. |
Stephen Smalley | bd19b9e | 2013-04-12 14:49:38 -0400 | [diff] [blame] | 501 | * @param seInfo null-ok SELinux information for the new process. |
Ramin Zaghi | ff0c470 | 2014-04-01 15:02:29 +0100 | [diff] [blame] | 502 | * @param abi non-null the ABI this app should be started with. |
Andreas Gampe | aec67dc | 2014-09-02 21:23:06 -0700 | [diff] [blame] | 503 | * @param instructionSet null-ok the instruction set to use. |
jgu21 | 2eacd06 | 2014-09-10 06:55:07 -0400 | [diff] [blame] | 504 | * @param appDataDir null-ok the data directory of the app. |
Tamas Berghammer | b8f7c35 | 2016-11-11 16:08:26 +0000 | [diff] [blame] | 505 | * @param invokeWith null-ok the command to invoke with. |
Sudheer Shanka | d81b1d7 | 2018-09-05 16:37:30 -0700 | [diff] [blame] | 506 | * @param packageName null-ok the name of the package this process belongs to. |
Sudheer Shanka | 3f0645b | 2018-09-18 13:07:59 -0700 | [diff] [blame] | 507 | * @param packagesForUid null-ok all the packages with the same uid as this process. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 508 | * @param zygoteArgs Additional arguments to supply to the zygote process. |
| 509 | * |
Jeff Brown | 3f9dd28 | 2011-07-08 20:02:19 -0700 | [diff] [blame] | 510 | * @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] | 511 | * @throws RuntimeException on fatal start failure |
| 512 | * |
| 513 | * {@hide} |
| 514 | */ |
Sudheer Shanka | d81b1d7 | 2018-09-05 16:37:30 -0700 | [diff] [blame] | 515 | public static final ProcessStartResult start(@NonNull final String processClass, |
| 516 | @Nullable final String niceName, |
| 517 | int uid, int gid, @Nullable int[] gids, |
Nicolas Geoffray | 81edac4 | 2017-09-07 14:13:29 +0100 | [diff] [blame] | 518 | int runtimeFlags, int mountExternal, |
Jeff Sharkey | 5b1ada2 | 2012-08-14 18:47:09 -0700 | [diff] [blame] | 519 | int targetSdkVersion, |
Sudheer Shanka | d81b1d7 | 2018-09-05 16:37:30 -0700 | [diff] [blame] | 520 | @Nullable String seInfo, |
| 521 | @NonNull String abi, |
| 522 | @Nullable String instructionSet, |
| 523 | @Nullable String appDataDir, |
| 524 | @Nullable String invokeWith, |
| 525 | @Nullable String packageName, |
Sudheer Shanka | 3f0645b | 2018-09-18 13:07:59 -0700 | [diff] [blame] | 526 | @Nullable String[] packagesForUid, |
Sudheer Shanka | 03fd40b | 2019-02-06 12:39:14 -0800 | [diff] [blame] | 527 | @Nullable String sandboxId, |
Sudheer Shanka | d81b1d7 | 2018-09-05 16:37:30 -0700 | [diff] [blame] | 528 | @Nullable String[] zygoteArgs) { |
Chris Wailes | efce929 | 2019-01-11 13:19:20 -0800 | [diff] [blame] | 529 | return ZYGOTE_PROCESS.start(processClass, niceName, uid, gid, gids, |
Nicolas Geoffray | 81edac4 | 2017-09-07 14:13:29 +0100 | [diff] [blame] | 530 | runtimeFlags, mountExternal, targetSdkVersion, seInfo, |
Sudheer Shanka | 3f0645b | 2018-09-18 13:07:59 -0700 | [diff] [blame] | 531 | abi, instructionSet, appDataDir, invokeWith, packageName, |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 532 | packagesForUid, sandboxId, /*useUnspecializedAppProcessPool=*/ true, |
| 533 | zygoteArgs); |
Narayan Kamath | 4444dcd | 2014-04-03 20:15:15 +0100 | [diff] [blame] | 534 | } |
| 535 | |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 536 | /** @hide */ |
Sudheer Shanka | d81b1d7 | 2018-09-05 16:37:30 -0700 | [diff] [blame] | 537 | public static final ProcessStartResult startWebView(@NonNull final String processClass, |
| 538 | @Nullable final String niceName, |
| 539 | int uid, int gid, @Nullable int[] gids, |
Nicolas Geoffray | 81edac4 | 2017-09-07 14:13:29 +0100 | [diff] [blame] | 540 | int runtimeFlags, int mountExternal, |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 541 | int targetSdkVersion, |
Sudheer Shanka | d81b1d7 | 2018-09-05 16:37:30 -0700 | [diff] [blame] | 542 | @Nullable String seInfo, |
| 543 | @NonNull String abi, |
| 544 | @Nullable String instructionSet, |
| 545 | @Nullable String appDataDir, |
| 546 | @Nullable String invokeWith, |
| 547 | @Nullable String packageName, |
Sudheer Shanka | 3f0645b | 2018-09-18 13:07:59 -0700 | [diff] [blame] | 548 | @Nullable String[] packagesForUid, |
Sudheer Shanka | 03fd40b | 2019-02-06 12:39:14 -0800 | [diff] [blame] | 549 | @Nullable String sandboxId, |
Sudheer Shanka | d81b1d7 | 2018-09-05 16:37:30 -0700 | [diff] [blame] | 550 | @Nullable String[] zygoteArgs) { |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 551 | return WebViewZygote.getProcess().start(processClass, niceName, uid, gid, gids, |
Nicolas Geoffray | 81edac4 | 2017-09-07 14:13:29 +0100 | [diff] [blame] | 552 | runtimeFlags, mountExternal, targetSdkVersion, seInfo, |
Sudheer Shanka | 3f0645b | 2018-09-18 13:07:59 -0700 | [diff] [blame] | 553 | abi, instructionSet, appDataDir, invokeWith, packageName, |
Chris Wailes | 7e797b6 | 2019-02-22 18:29:22 -0800 | [diff] [blame] | 554 | packagesForUid, sandboxId, /*useUnspecializedAppProcessPool=*/ false, |
| 555 | zygoteArgs); |
Robert Sesek | ded2098 | 2016-08-15 13:59:13 -0400 | [diff] [blame] | 556 | } |
| 557 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 558 | /** |
| 559 | * Returns elapsed milliseconds of the time this process has run. |
| 560 | * @return Returns the number of milliseconds this process has return. |
| 561 | */ |
| 562 | public static final native long getElapsedCpuTime(); |
Andreas Gampe | ee0cdce | 2015-06-08 20:47:50 -0700 | [diff] [blame] | 563 | |
| 564 | /** |
Dianne Hackborn | d98885c | 2016-03-01 17:13:03 -0800 | [diff] [blame] | 565 | * Return the {@link SystemClock#elapsedRealtime()} at which this process was started. |
| 566 | */ |
| 567 | public static final long getStartElapsedRealtime() { |
| 568 | return sStartElapsedRealtime; |
| 569 | } |
| 570 | |
| 571 | /** |
| 572 | * Return the {@link SystemClock#uptimeMillis()} at which this process was started. |
| 573 | */ |
| 574 | public static final long getStartUptimeMillis() { |
| 575 | return sStartUptimeMillis; |
| 576 | } |
| 577 | |
| 578 | /** @hide */ |
| 579 | public static final void setStartTimes(long elapsedRealtime, long uptimeMillis) { |
| 580 | sStartElapsedRealtime = elapsedRealtime; |
| 581 | sStartUptimeMillis = uptimeMillis; |
| 582 | } |
| 583 | |
| 584 | /** |
Andreas Gampe | ee0cdce | 2015-06-08 20:47:50 -0700 | [diff] [blame] | 585 | * Returns true if the current process is a 64-bit runtime. |
| 586 | */ |
| 587 | public static final boolean is64Bit() { |
| 588 | return VMRuntime.getRuntime().is64Bit(); |
| 589 | } |
| 590 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 591 | /** |
| 592 | * Returns the identifier of this process, which can be used with |
| 593 | * {@link #killProcess} and {@link #sendSignal}. |
| 594 | */ |
Jeff Hao | 406ec15 | 2013-07-30 10:13:41 -0700 | [diff] [blame] | 595 | public static final int myPid() { |
Elliott Hughes | 34385d3 | 2014-04-28 11:11:32 -0700 | [diff] [blame] | 596 | return Os.getpid(); |
Jeff Hao | 406ec15 | 2013-07-30 10:13:41 -0700 | [diff] [blame] | 597 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 598 | |
| 599 | /** |
Romain Guy | 80b12fc | 2013-05-29 15:54:25 -0700 | [diff] [blame] | 600 | * Returns the identifier of this process' parent. |
| 601 | * @hide |
| 602 | */ |
Elliott Hughes | 2a805f9 | 2013-07-31 18:25:47 -0700 | [diff] [blame] | 603 | public static final int myPpid() { |
Elliott Hughes | 34385d3 | 2014-04-28 11:11:32 -0700 | [diff] [blame] | 604 | return Os.getppid(); |
Elliott Hughes | 2a805f9 | 2013-07-31 18:25:47 -0700 | [diff] [blame] | 605 | } |
Romain Guy | 80b12fc | 2013-05-29 15:54:25 -0700 | [diff] [blame] | 606 | |
| 607 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 608 | * Returns the identifier of the calling thread, which be used with |
| 609 | * {@link #setThreadPriority(int, int)}. |
| 610 | */ |
Elliott Hughes | 6d4b1e2 | 2013-07-31 17:38:11 -0700 | [diff] [blame] | 611 | public static final int myTid() { |
Elliott Hughes | 34385d3 | 2014-04-28 11:11:32 -0700 | [diff] [blame] | 612 | return Os.gettid(); |
Elliott Hughes | 6d4b1e2 | 2013-07-31 17:38:11 -0700 | [diff] [blame] | 613 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 614 | |
| 615 | /** |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 616 | * Returns the identifier of this process's uid. This is the kernel uid |
| 617 | * that the process is running under, which is the identity of its |
| 618 | * app-specific sandbox. It is different from {@link #myUserHandle} in that |
| 619 | * 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] | 620 | */ |
Jeff Hao | 406ec15 | 2013-07-30 10:13:41 -0700 | [diff] [blame] | 621 | public static final int myUid() { |
Elliott Hughes | 34385d3 | 2014-04-28 11:11:32 -0700 | [diff] [blame] | 622 | return Os.getuid(); |
Jeff Hao | 406ec15 | 2013-07-30 10:13:41 -0700 | [diff] [blame] | 623 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 624 | |
| 625 | /** |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 626 | * Returns this process's user handle. This is the |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 627 | * user the process is running under. It is distinct from |
| 628 | * {@link #myUid()} in that a particular user will have multiple |
| 629 | * distinct apps running under it each with their own uid. |
| 630 | */ |
Fyodor Kupolov | 02cb6e7 | 2015-09-18 18:20:55 -0700 | [diff] [blame] | 631 | public static UserHandle myUserHandle() { |
| 632 | return UserHandle.of(UserHandle.getUserId(myUid())); |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | /** |
Makoto Onuki | 9cc471c | 2018-01-23 12:33:56 -0800 | [diff] [blame] | 636 | * Returns whether the given uid belongs to a system core component or not. |
| 637 | * @hide |
| 638 | */ |
| 639 | public static boolean isCoreUid(int uid) { |
| 640 | return UserHandle.isCore(uid); |
| 641 | } |
| 642 | |
| 643 | /** |
Jeff Davidson | 48aa86b | 2016-02-10 14:15:42 -0800 | [diff] [blame] | 644 | * Returns whether the given uid belongs to an application. |
| 645 | * @param uid A kernel uid. |
| 646 | * @return Whether the uid corresponds to an application sandbox running in |
| 647 | * a specific user. |
| 648 | */ |
| 649 | public static boolean isApplicationUid(int uid) { |
| 650 | return UserHandle.isApp(uid); |
| 651 | } |
| 652 | |
| 653 | /** |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 654 | * Returns whether the current process is in an isolated sandbox. |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 655 | */ |
| 656 | public static final boolean isIsolated() { |
Jeff Sharkey | 9527b22 | 2015-06-24 15:24:48 -0700 | [diff] [blame] | 657 | return isIsolated(myUid()); |
| 658 | } |
| 659 | |
| 660 | /** {@hide} */ |
| 661 | public static final boolean isIsolated(int uid) { |
| 662 | uid = UserHandle.getAppId(uid); |
Martijn Coenen | 01e719b | 2018-12-05 16:01:38 +0100 | [diff] [blame] | 663 | return (uid >= FIRST_ISOLATED_UID && uid <= LAST_ISOLATED_UID) |
| 664 | || (uid >= FIRST_APP_ZYGOTE_ISOLATED_UID && uid <= LAST_APP_ZYGOTE_ISOLATED_UID); |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 668 | * Returns the UID assigned to a particular user name, or -1 if there is |
| 669 | * none. If the given string consists of only numbers, it is converted |
| 670 | * directly to a uid. |
| 671 | */ |
| 672 | public static final native int getUidForName(String name); |
| 673 | |
| 674 | /** |
| 675 | * Returns the GID assigned to a particular user name, or -1 if there is |
| 676 | * none. If the given string consists of only numbers, it is converted |
| 677 | * directly to a gid. |
| 678 | */ |
| 679 | public static final native int getGidForName(String name); |
Amith Yamasani | 819f928 | 2009-06-24 23:18:15 -0700 | [diff] [blame] | 680 | |
| 681 | /** |
| 682 | * Returns a uid for a currently running process. |
| 683 | * @param pid the process id |
| 684 | * @return the uid of the process, or -1 if the process is not running. |
| 685 | * @hide pending API council review |
| 686 | */ |
| 687 | public static final int getUidForPid(int pid) { |
| 688 | String[] procStatusLabels = { "Uid:" }; |
| 689 | long[] procStatusValues = new long[1]; |
| 690 | procStatusValues[0] = -1; |
| 691 | Process.readProcLines("/proc/" + pid + "/status", procStatusLabels, procStatusValues); |
| 692 | return (int) procStatusValues[0]; |
| 693 | } |
| 694 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 695 | /** |
Jeff Brown | ebed7d6 | 2011-05-16 17:08:42 -0700 | [diff] [blame] | 696 | * Returns the parent process id for a currently running process. |
| 697 | * @param pid the process id |
| 698 | * @return the parent process id of the process, or -1 if the process is not running. |
| 699 | * @hide |
| 700 | */ |
| 701 | public static final int getParentPid(int pid) { |
| 702 | String[] procStatusLabels = { "PPid:" }; |
| 703 | long[] procStatusValues = new long[1]; |
| 704 | procStatusValues[0] = -1; |
| 705 | Process.readProcLines("/proc/" + pid + "/status", procStatusLabels, procStatusValues); |
| 706 | return (int) procStatusValues[0]; |
| 707 | } |
| 708 | |
| 709 | /** |
Glenn Kasten | 07b0465 | 2012-04-23 15:00:43 -0700 | [diff] [blame] | 710 | * Returns the thread group leader id for a currently running thread. |
| 711 | * @param tid the thread id |
| 712 | * @return the thread group leader id of the thread, or -1 if the thread is not running. |
| 713 | * This is same as what getpid(2) would return if called by tid. |
| 714 | * @hide |
| 715 | */ |
| 716 | public static final int getThreadGroupLeader(int tid) { |
| 717 | String[] procStatusLabels = { "Tgid:" }; |
| 718 | long[] procStatusValues = new long[1]; |
| 719 | procStatusValues[0] = -1; |
| 720 | Process.readProcLines("/proc/" + tid + "/status", procStatusLabels, procStatusValues); |
| 721 | return (int) procStatusValues[0]; |
| 722 | } |
| 723 | |
| 724 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 725 | * Set the priority of a thread, based on Linux priorities. |
| 726 | * |
| 727 | * @param tid The identifier of the thread/process to change. |
| 728 | * @param priority A Linux priority level, from -20 for highest scheduling |
| 729 | * priority to 19 for lowest scheduling priority. |
| 730 | * |
| 731 | * @throws IllegalArgumentException Throws IllegalArgumentException if |
| 732 | * <var>tid</var> does not exist. |
| 733 | * @throws SecurityException Throws SecurityException if your process does |
| 734 | * not have permission to modify the given thread, or to use the given |
| 735 | * priority. |
| 736 | */ |
| 737 | public static final native void setThreadPriority(int tid, int priority) |
| 738 | throws IllegalArgumentException, SecurityException; |
San Mehat | e9d376b | 2009-04-21 14:06:36 -0700 | [diff] [blame] | 739 | |
| 740 | /** |
Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 741 | * Call with 'false' to cause future calls to {@link #setThreadPriority(int)} to |
| 742 | * throw an exception if passed a background-level thread priority. This is only |
| 743 | * effective if the JNI layer is built with GUARD_THREAD_PRIORITY defined to 1. |
| 744 | * |
| 745 | * @hide |
| 746 | */ |
| 747 | public static final native void setCanSelfBackground(boolean backgroundOk); |
| 748 | |
| 749 | /** |
San Mehat | e9d376b | 2009-04-21 14:06:36 -0700 | [diff] [blame] | 750 | * Sets the scheduling group for a thread. |
| 751 | * @hide |
Glenn Kasten | f1b5644 | 2012-03-15 16:33:43 -0700 | [diff] [blame] | 752 | * @param tid The identifier of the thread to change. |
| 753 | * @param group The target group for this thread from THREAD_GROUP_*. |
Joel Fernandes | 474d311 | 2017-04-04 16:32:15 -0700 | [diff] [blame] | 754 | * |
San Mehat | e9d376b | 2009-04-21 14:06:36 -0700 | [diff] [blame] | 755 | * @throws IllegalArgumentException Throws IllegalArgumentException if |
| 756 | * <var>tid</var> does not exist. |
| 757 | * @throws SecurityException Throws SecurityException if your process does |
| 758 | * not have permission to modify the given thread, or to use the given |
| 759 | * priority. |
Glenn Kasten | f1b5644 | 2012-03-15 16:33:43 -0700 | [diff] [blame] | 760 | * If the thread is a thread group leader, that is it's gettid() == getpid(), |
| 761 | * then the other threads in the same thread group are _not_ affected. |
Tim Murray | 4074ad0 | 2016-07-08 15:45:45 -0700 | [diff] [blame] | 762 | * |
| 763 | * Does not set cpuset for some historical reason, just calls |
| 764 | * libcutils::set_sched_policy(). |
San Mehat | e9d376b | 2009-04-21 14:06:36 -0700 | [diff] [blame] | 765 | */ |
| 766 | public static final native void setThreadGroup(int tid, int group) |
| 767 | throws IllegalArgumentException, SecurityException; |
Glenn Kasten | f1b5644 | 2012-03-15 16:33:43 -0700 | [diff] [blame] | 768 | |
San Mehat | 3e45824 | 2009-05-19 14:44:16 -0700 | [diff] [blame] | 769 | /** |
Joel Fernandes | 474d311 | 2017-04-04 16:32:15 -0700 | [diff] [blame] | 770 | * Sets the scheduling group and the corresponding cpuset group |
| 771 | * @hide |
| 772 | * @param tid The identifier of the thread to change. |
| 773 | * @param group The target group for this thread from THREAD_GROUP_*. |
| 774 | * |
| 775 | * @throws IllegalArgumentException Throws IllegalArgumentException if |
| 776 | * <var>tid</var> does not exist. |
| 777 | * @throws SecurityException Throws SecurityException if your process does |
| 778 | * not have permission to modify the given thread, or to use the given |
| 779 | * priority. |
| 780 | */ |
| 781 | public static final native void setThreadGroupAndCpuset(int tid, int group) |
| 782 | throws IllegalArgumentException, SecurityException; |
| 783 | |
| 784 | /** |
San Mehat | 3e45824 | 2009-05-19 14:44:16 -0700 | [diff] [blame] | 785 | * Sets the scheduling group for a process and all child threads |
| 786 | * @hide |
Glenn Kasten | f1b5644 | 2012-03-15 16:33:43 -0700 | [diff] [blame] | 787 | * @param pid The identifier of the process to change. |
| 788 | * @param group The target group for this process from THREAD_GROUP_*. |
San Mehat | 3e45824 | 2009-05-19 14:44:16 -0700 | [diff] [blame] | 789 | * |
| 790 | * @throws IllegalArgumentException Throws IllegalArgumentException if |
| 791 | * <var>tid</var> does not exist. |
| 792 | * @throws SecurityException Throws SecurityException if your process does |
| 793 | * not have permission to modify the given thread, or to use the given |
| 794 | * priority. |
Glenn Kasten | f1b5644 | 2012-03-15 16:33:43 -0700 | [diff] [blame] | 795 | * |
| 796 | * group == THREAD_GROUP_DEFAULT means to move all non-background priority |
| 797 | * threads to the foreground scheduling group, but to leave background |
| 798 | * priority threads alone. group == THREAD_GROUP_BG_NONINTERACTIVE moves all |
| 799 | * threads, regardless of priority, to the background scheduling group. |
| 800 | * group == THREAD_GROUP_FOREGROUND is not allowed. |
Tim Murray | 4074ad0 | 2016-07-08 15:45:45 -0700 | [diff] [blame] | 801 | * |
| 802 | * Always sets cpusets. |
San Mehat | 3e45824 | 2009-05-19 14:44:16 -0700 | [diff] [blame] | 803 | */ |
| 804 | public static final native void setProcessGroup(int pid, int group) |
| 805 | throws IllegalArgumentException, SecurityException; |
Jeff Sharkey | 9e57c41 | 2013-01-17 14:12:41 -0800 | [diff] [blame] | 806 | |
| 807 | /** |
| 808 | * Return the scheduling group of requested process. |
| 809 | * |
| 810 | * @hide |
| 811 | */ |
| 812 | public static final native int getProcessGroup(int pid) |
| 813 | throws IllegalArgumentException, SecurityException; |
| 814 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 815 | /** |
Martijn Coenen | cd4bdf3 | 2016-03-03 17:30:52 +0100 | [diff] [blame] | 816 | * On some devices, the foreground process may have one or more CPU |
| 817 | * cores exclusively reserved for it. This method can be used to |
| 818 | * retrieve which cores that are (if any), so the calling process |
| 819 | * can then use sched_setaffinity() to lock a thread to these cores. |
| 820 | * Note that the calling process must currently be running in the |
| 821 | * foreground for this method to return any cores. |
| 822 | * |
| 823 | * The CPU core(s) exclusively reserved for the foreground process will |
| 824 | * stay reserved for as long as the process stays in the foreground. |
| 825 | * |
| 826 | * As soon as a process leaves the foreground, those CPU cores will |
| 827 | * no longer be reserved for it, and will most likely be reserved for |
| 828 | * the new foreground process. It's not necessary to change the affinity |
| 829 | * of your process when it leaves the foreground (if you had previously |
| 830 | * set it to use a reserved core); the OS will automatically take care |
| 831 | * of resetting the affinity at that point. |
| 832 | * |
| 833 | * @return an array of integers, indicating the CPU cores exclusively |
| 834 | * reserved for this process. The array will have length zero if no |
| 835 | * CPU cores are exclusively reserved for this process at this point |
| 836 | * in time. |
| 837 | */ |
| 838 | public static final native int[] getExclusiveCores(); |
| 839 | |
| 840 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 841 | * Set the priority of the calling thread, based on Linux priorities. See |
| 842 | * {@link #setThreadPriority(int, int)} for more information. |
| 843 | * |
| 844 | * @param priority A Linux priority level, from -20 for highest scheduling |
| 845 | * priority to 19 for lowest scheduling priority. |
| 846 | * |
| 847 | * @throws IllegalArgumentException Throws IllegalArgumentException if |
| 848 | * <var>tid</var> does not exist. |
| 849 | * @throws SecurityException Throws SecurityException if your process does |
| 850 | * not have permission to modify the given thread, or to use the given |
| 851 | * priority. |
| 852 | * |
| 853 | * @see #setThreadPriority(int, int) |
| 854 | */ |
| 855 | public static final native void setThreadPriority(int priority) |
| 856 | throws IllegalArgumentException, SecurityException; |
| 857 | |
| 858 | /** |
| 859 | * Return the current priority of a thread, based on Linux priorities. |
| 860 | * |
Alessio Balsini | 68ae301 | 2017-06-07 11:41:33 +0200 | [diff] [blame] | 861 | * @param tid The identifier of the thread/process. If tid equals zero, the priority of the |
| 862 | * calling process/thread will be returned. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 863 | * |
| 864 | * @return Returns the current priority, as a Linux priority level, |
| 865 | * from -20 for highest scheduling priority to 19 for lowest scheduling |
| 866 | * priority. |
| 867 | * |
| 868 | * @throws IllegalArgumentException Throws IllegalArgumentException if |
| 869 | * <var>tid</var> does not exist. |
| 870 | */ |
| 871 | public static final native int getThreadPriority(int tid) |
| 872 | throws IllegalArgumentException; |
| 873 | |
| 874 | /** |
Srinath Sridharan | 1b15d13 | 2016-07-19 15:16:11 -0700 | [diff] [blame] | 875 | * Return the current scheduling policy of a thread, based on Linux. |
| 876 | * |
| 877 | * @param tid The identifier of the thread/process to get the scheduling policy. |
| 878 | * |
| 879 | * @throws IllegalArgumentException Throws IllegalArgumentException if |
| 880 | * <var>tid</var> does not exist, or if <var>priority</var> is out of range for the policy. |
| 881 | * @throws SecurityException Throws SecurityException if your process does |
| 882 | * not have permission to modify the given thread, or to use the given |
| 883 | * scheduling policy or priority. |
| 884 | * |
| 885 | * {@hide} |
| 886 | */ |
| 887 | |
| 888 | @TestApi |
| 889 | public static final native int getThreadScheduler(int tid) |
| 890 | throws IllegalArgumentException; |
| 891 | |
| 892 | /** |
Glenn Kasten | 6793ac9 | 2011-07-13 12:44:12 -0700 | [diff] [blame] | 893 | * Set the scheduling policy and priority of a thread, based on Linux. |
| 894 | * |
| 895 | * @param tid The identifier of the thread/process to change. |
| 896 | * @param policy A Linux scheduling policy such as SCHED_OTHER etc. |
| 897 | * @param priority A Linux priority level in a range appropriate for the given policy. |
| 898 | * |
| 899 | * @throws IllegalArgumentException Throws IllegalArgumentException if |
| 900 | * <var>tid</var> does not exist, or if <var>priority</var> is out of range for the policy. |
| 901 | * @throws SecurityException Throws SecurityException if your process does |
| 902 | * not have permission to modify the given thread, or to use the given |
| 903 | * scheduling policy or priority. |
| 904 | * |
| 905 | * {@hide} |
| 906 | */ |
Srinath Sridharan | 1b15d13 | 2016-07-19 15:16:11 -0700 | [diff] [blame] | 907 | |
Glenn Kasten | 6793ac9 | 2011-07-13 12:44:12 -0700 | [diff] [blame] | 908 | public static final native void setThreadScheduler(int tid, int policy, int priority) |
| 909 | throws IllegalArgumentException; |
| 910 | |
| 911 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 912 | * Determine whether the current environment supports multiple processes. |
| 913 | * |
| 914 | * @return Returns true if the system can run in multiple processes, else |
| 915 | * false if everything is running in a single process. |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 916 | * |
| 917 | * @deprecated This method always returns true. Do not use. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 918 | */ |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 919 | @Deprecated |
| 920 | public static final boolean supportsProcesses() { |
| 921 | return true; |
| 922 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 923 | |
| 924 | /** |
Rom Lemarchand | 5534ba9 | 2013-07-12 16:15:36 -0700 | [diff] [blame] | 925 | * Adjust the swappiness level for a process. |
| 926 | * |
| 927 | * @param pid The process identifier to set. |
| 928 | * @param is_increased Whether swappiness should be increased or default. |
| 929 | * |
| 930 | * @return Returns true if the underlying system supports this |
| 931 | * feature, else false. |
| 932 | * |
| 933 | * {@hide} |
| 934 | */ |
| 935 | public static final native boolean setSwappiness(int pid, boolean is_increased); |
| 936 | |
| 937 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 938 | * Change this process's argv[0] parameter. This can be useful to show |
| 939 | * more descriptive information in things like the 'ps' command. |
| 940 | * |
| 941 | * @param text The new name of this process. |
| 942 | * |
| 943 | * {@hide} |
| 944 | */ |
| 945 | public static final native void setArgV0(String text); |
| 946 | |
| 947 | /** |
| 948 | * Kill the process with the given PID. |
| 949 | * Note that, though this API allows us to request to |
| 950 | * kill any process based on its PID, the kernel will |
| 951 | * still impose standard restrictions on which PIDs you |
| 952 | * are actually able to kill. Typically this means only |
| 953 | * the process running the caller's packages/application |
| 954 | * and any additional processes created by that app; packages |
| 955 | * sharing a common UID will also be able to kill each |
| 956 | * other's processes. |
| 957 | */ |
| 958 | public static final void killProcess(int pid) { |
| 959 | sendSignal(pid, SIGNAL_KILL); |
| 960 | } |
| 961 | |
| 962 | /** @hide */ |
| 963 | public static final native int setUid(int uid); |
| 964 | |
| 965 | /** @hide */ |
| 966 | public static final native int setGid(int uid); |
| 967 | |
| 968 | /** |
| 969 | * Send a signal to the given process. |
| 970 | * |
| 971 | * @param pid The pid of the target process. |
| 972 | * @param signal The signal to send. |
| 973 | */ |
| 974 | public static final native void sendSignal(int pid, int signal); |
| 975 | |
Dianne Hackborn | 906497c | 2010-05-10 15:57:38 -0700 | [diff] [blame] | 976 | /** |
| 977 | * @hide |
| 978 | * Private impl for avoiding a log message... DO NOT USE without doing |
| 979 | * your own log, or the Android Illuminati will find you some night and |
| 980 | * beat you up. |
| 981 | */ |
| 982 | public static final void killProcessQuiet(int pid) { |
| 983 | sendSignalQuiet(pid, SIGNAL_KILL); |
| 984 | } |
| 985 | |
| 986 | /** |
| 987 | * @hide |
| 988 | * Private impl for avoiding a log message... DO NOT USE without doing |
| 989 | * your own log, or the Android Illuminati will find you some night and |
| 990 | * beat you up. |
| 991 | */ |
| 992 | public static final native void sendSignalQuiet(int pid, int signal); |
| 993 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 994 | /** @hide */ |
Marco Nelissen | 0bca96b | 2009-07-17 12:59:25 -0700 | [diff] [blame] | 995 | public static final native long getFreeMemory(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 996 | |
| 997 | /** @hide */ |
Dianne Hackborn | 59325eb | 2012-05-09 18:45:20 -0700 | [diff] [blame] | 998 | public static final native long getTotalMemory(); |
| 999 | |
| 1000 | /** @hide */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1001 | public static final native void readProcLines(String path, |
| 1002 | String[] reqFields, long[] outSizes); |
| 1003 | |
| 1004 | /** @hide */ |
| 1005 | public static final native int[] getPids(String path, int[] lastArray); |
| 1006 | |
| 1007 | /** @hide */ |
| 1008 | public static final int PROC_TERM_MASK = 0xff; |
| 1009 | /** @hide */ |
| 1010 | public static final int PROC_ZERO_TERM = 0; |
| 1011 | /** @hide */ |
| 1012 | public static final int PROC_SPACE_TERM = (int)' '; |
| 1013 | /** @hide */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1014 | public static final int PROC_TAB_TERM = (int)'\t'; |
| 1015 | /** @hide */ |
Misha Wagner | 566903a | 2018-10-02 10:50:12 +0100 | [diff] [blame] | 1016 | public static final int PROC_NEWLINE_TERM = (int) '\n'; |
| 1017 | /** @hide */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1018 | public static final int PROC_COMBINE = 0x100; |
| 1019 | /** @hide */ |
| 1020 | public static final int PROC_PARENS = 0x200; |
| 1021 | /** @hide */ |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 1022 | public static final int PROC_QUOTES = 0x400; |
| 1023 | /** @hide */ |
Dianne Hackborn | 4de5a3a | 2016-06-20 15:20:15 -0700 | [diff] [blame] | 1024 | public static final int PROC_CHAR = 0x800; |
| 1025 | /** @hide */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1026 | public static final int PROC_OUT_STRING = 0x1000; |
| 1027 | /** @hide */ |
| 1028 | public static final int PROC_OUT_LONG = 0x2000; |
| 1029 | /** @hide */ |
| 1030 | public static final int PROC_OUT_FLOAT = 0x4000; |
Misha Wagner | cc065fb | 2018-10-15 10:45:44 +0100 | [diff] [blame] | 1031 | |
| 1032 | /** |
| 1033 | * Read and parse a {@code proc} file in the given format. |
| 1034 | * |
| 1035 | * <p>The format is a list of integers, where every integer describes a variable in the file. It |
| 1036 | * specifies how the variable is syntactically terminated (e.g. {@link Process#PROC_SPACE_TERM}, |
Misha Wagner | 566903a | 2018-10-02 10:50:12 +0100 | [diff] [blame] | 1037 | * {@link Process#PROC_TAB_TERM}, {@link Process#PROC_ZERO_TERM}, {@link |
| 1038 | * Process#PROC_NEWLINE_TERM}). |
Misha Wagner | cc065fb | 2018-10-15 10:45:44 +0100 | [diff] [blame] | 1039 | * |
| 1040 | * <p>If the variable should be parsed and returned to the caller, the termination type should |
| 1041 | * be binary OR'd with the type of output (e.g. {@link Process#PROC_OUT_STRING}, {@link |
| 1042 | * Process#PROC_OUT_LONG}, {@link Process#PROC_OUT_FLOAT}. |
| 1043 | * |
| 1044 | * <p>If the variable is wrapped in quotation marks it should be binary OR'd with {@link |
| 1045 | * Process#PROC_QUOTES}. If the variable is wrapped in parentheses it should be binary OR'd with |
| 1046 | * {@link Process#PROC_PARENS}. |
| 1047 | * |
| 1048 | * <p>If the variable is not formatted as a string and should be cast directly from characters |
| 1049 | * to a long, the {@link Process#PROC_CHAR} integer should be binary OR'd. |
| 1050 | * |
| 1051 | * <p>If the terminating character can be repeated, the {@link Process#PROC_COMBINE} integer |
| 1052 | * should be binary OR'd. |
| 1053 | * |
| 1054 | * @param file the path of the {@code proc} file to read |
| 1055 | * @param format the format of the file |
| 1056 | * @param outStrings the parsed {@code String}s from the file |
| 1057 | * @param outLongs the parsed {@code long}s from the file |
| 1058 | * @param outFloats the parsed {@code float}s from the file |
| 1059 | * @hide |
| 1060 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1061 | public static final native boolean readProcFile(String file, int[] format, |
| 1062 | String[] outStrings, long[] outLongs, float[] outFloats); |
Misha Wagner | cc065fb | 2018-10-15 10:45:44 +0100 | [diff] [blame] | 1063 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1064 | /** @hide */ |
| 1065 | public static final native boolean parseProcLine(byte[] buffer, int startIndex, |
| 1066 | 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] | 1067 | |
Dianne Hackborn | f72467a | 2012-06-08 17:23:59 -0700 | [diff] [blame] | 1068 | /** @hide */ |
| 1069 | public static final native int[] getPidsForCommands(String[] cmds); |
| 1070 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1071 | /** |
| 1072 | * Gets the total Pss value for a given process, in bytes. |
| 1073 | * |
| 1074 | * @param pid the process to the Pss for |
| 1075 | * @return the total Pss value for the given process in bytes, |
| 1076 | * or -1 if the value cannot be determined |
| 1077 | * @hide |
| 1078 | */ |
| 1079 | public static final native long getPss(int pid); |
Jeff Brown | 3f9dd28 | 2011-07-08 20:02:19 -0700 | [diff] [blame] | 1080 | |
Tim Murray | fb07678 | 2018-11-27 12:22:22 -0800 | [diff] [blame] | 1081 | /** @hide */ |
| 1082 | public static final native long[] getRss(int pid); |
| 1083 | |
Jeff Brown | 3f9dd28 | 2011-07-08 20:02:19 -0700 | [diff] [blame] | 1084 | /** |
| 1085 | * Specifies the outcome of having started a process. |
| 1086 | * @hide |
| 1087 | */ |
| 1088 | public static final class ProcessStartResult { |
| 1089 | /** |
| 1090 | * The PID of the newly started process. |
| 1091 | * Always >= 0. (If the start failed, an exception will have been thrown instead.) |
| 1092 | */ |
| 1093 | public int pid; |
| 1094 | |
| 1095 | /** |
| 1096 | * True if the process was started with a wrapper attached. |
| 1097 | */ |
| 1098 | public boolean usingWrapper; |
| 1099 | } |
Colin Cross | 0769e55 | 2014-06-03 13:25:35 -0700 | [diff] [blame] | 1100 | |
| 1101 | /** |
| 1102 | * Kill all processes in a process group started for the given |
| 1103 | * pid. |
| 1104 | * @hide |
| 1105 | */ |
| 1106 | public static final native int killProcessGroup(int uid, int pid); |
| 1107 | |
| 1108 | /** |
| 1109 | * Remove all process groups. Expected to be called when ActivityManager |
| 1110 | * is restarted. |
| 1111 | * @hide |
| 1112 | */ |
| 1113 | public static final native void removeAllProcessGroups(); |
Tim Murray | b89970e | 2016-07-01 10:42:20 -0700 | [diff] [blame] | 1114 | |
| 1115 | /** |
| 1116 | * Check to see if a thread belongs to a given process. This may require |
| 1117 | * more permissions than apps generally have. |
| 1118 | * @return true if this thread belongs to a process |
| 1119 | * @hide |
| 1120 | */ |
| 1121 | public static final boolean isThreadInProcess(int tid, int pid) { |
Tim Murray | 9bc12a8 | 2016-07-16 11:28:40 -0700 | [diff] [blame] | 1122 | StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
Tim Murray | b89970e | 2016-07-01 10:42:20 -0700 | [diff] [blame] | 1123 | try { |
| 1124 | if (Os.access("/proc/" + tid + "/task/" + pid, OsConstants.F_OK)) { |
| 1125 | return true; |
| 1126 | } else { |
| 1127 | return false; |
| 1128 | } |
| 1129 | } catch (Exception e) { |
| 1130 | return false; |
Tim Murray | 9bc12a8 | 2016-07-16 11:28:40 -0700 | [diff] [blame] | 1131 | } finally { |
| 1132 | StrictMode.setThreadPolicy(oldPolicy); |
Tim Murray | b89970e | 2016-07-01 10:42:20 -0700 | [diff] [blame] | 1133 | } |
Tim Murray | 9bc12a8 | 2016-07-16 11:28:40 -0700 | [diff] [blame] | 1134 | |
Tim Murray | b89970e | 2016-07-01 10:42:20 -0700 | [diff] [blame] | 1135 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1136 | } |