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