Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 19 | import android.annotation.AppIdInt; |
Jeff Sharkey | ba4acd5 | 2019-03-05 19:46:54 -0700 | [diff] [blame] | 20 | import android.annotation.NonNull; |
Christopher Tate | cbd7a6e | 2014-08-06 14:24:14 -0700 | [diff] [blame] | 21 | import android.annotation.SystemApi; |
Jeff Sharkey | a73b8fd | 2016-01-06 17:02:08 -0700 | [diff] [blame] | 22 | import android.annotation.TestApi; |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 23 | import android.annotation.UserIdInt; |
Artur Satayev | afdb23a | 2019-12-10 17:47:53 +0000 | [diff] [blame] | 24 | import android.compat.annotation.UnsupportedAppUsage; |
Alexandra Gherghina | c1cf161 | 2014-06-05 10:49:14 +0100 | [diff] [blame] | 25 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 26 | import java.io.PrintWriter; |
| 27 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 28 | /** |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 29 | * Representation of a user on the device. |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 30 | */ |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 31 | public final class UserHandle implements Parcelable { |
Jeff Sharkey | 77a3450 | 2017-11-09 17:40:57 -0700 | [diff] [blame] | 32 | // NOTE: keep logic in sync with system/core/libcutils/multiuser.c |
| 33 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 34 | /** |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 35 | * @hide Range of uids allocated for a user. |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 36 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 37 | @UnsupportedAppUsage |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 38 | public static final int PER_USER_RANGE = 100000; |
| 39 | |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 40 | /** @hide A user id to indicate all users on the device */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 41 | @UnsupportedAppUsage |
Makoto Onuki | acf3858 | 2019-10-04 11:53:42 -0700 | [diff] [blame] | 42 | @TestApi |
Jeff Sharkey | cd65448 | 2016-01-08 17:42:11 -0700 | [diff] [blame] | 43 | public static final @UserIdInt int USER_ALL = -1; |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 44 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 45 | /** @hide A user handle to indicate all users on the device */ |
Jeff Sharkey | ec5f7d1 | 2018-08-08 09:15:04 -0600 | [diff] [blame] | 46 | @SystemApi |
| 47 | @TestApi |
Jeff Sharkey | ba4acd5 | 2019-03-05 19:46:54 -0700 | [diff] [blame] | 48 | public static final @NonNull UserHandle ALL = new UserHandle(USER_ALL); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 49 | |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 50 | /** @hide A user id to indicate the currently active user */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 51 | @UnsupportedAppUsage |
Jeff Sharkey | cd65448 | 2016-01-08 17:42:11 -0700 | [diff] [blame] | 52 | public static final @UserIdInt int USER_CURRENT = -2; |
Amith Yamasani | 8264408 | 2012-08-03 13:09:11 -0700 | [diff] [blame] | 53 | |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 54 | /** @hide A user handle to indicate the current user of the device */ |
Jeff Sharkey | ec5f7d1 | 2018-08-08 09:15:04 -0600 | [diff] [blame] | 55 | @SystemApi |
| 56 | @TestApi |
Jeff Sharkey | ba4acd5 | 2019-03-05 19:46:54 -0700 | [diff] [blame] | 57 | public static final @NonNull UserHandle CURRENT = new UserHandle(USER_CURRENT); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 58 | |
| 59 | /** @hide A user id to indicate that we would like to send to the current |
| 60 | * user, but if this is calling from a user process then we will send it |
Alan Viverette | b6e0cb9 | 2014-11-24 15:13:43 -0800 | [diff] [blame] | 61 | * to the caller's user instead of failing with a security exception */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 62 | @UnsupportedAppUsage |
Jeff Sharkey | cd65448 | 2016-01-08 17:42:11 -0700 | [diff] [blame] | 63 | public static final @UserIdInt int USER_CURRENT_OR_SELF = -3; |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 64 | |
| 65 | /** @hide A user handle to indicate that we would like to send to the current |
| 66 | * user, but if this is calling from a user process then we will send it |
Alan Viverette | b6e0cb9 | 2014-11-24 15:13:43 -0800 | [diff] [blame] | 67 | * to the caller's user instead of failing with a security exception */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 68 | @UnsupportedAppUsage |
Jeff Sharkey | ba4acd5 | 2019-03-05 19:46:54 -0700 | [diff] [blame] | 69 | public static final @NonNull UserHandle CURRENT_OR_SELF = new UserHandle(USER_CURRENT_OR_SELF); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 70 | |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 71 | /** @hide An undefined user id */ |
Mathew Inwood | 3a75f26 | 2019-06-27 12:47:38 +0100 | [diff] [blame] | 72 | @UnsupportedAppUsage |
Makoto Onuki | acf3858 | 2019-10-04 11:53:42 -0700 | [diff] [blame] | 73 | @TestApi |
Jeff Sharkey | cd65448 | 2016-01-08 17:42:11 -0700 | [diff] [blame] | 74 | public static final @UserIdInt int USER_NULL = -10000; |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 75 | |
Makoto Onuki | acf3858 | 2019-10-04 11:53:42 -0700 | [diff] [blame] | 76 | private static final @NonNull UserHandle NULL = new UserHandle(USER_NULL); |
| 77 | |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 78 | /** |
| 79 | * @hide A user id constant to indicate the "owner" user of the device |
Xiaohui Chen | 7c69636 | 2015-09-16 09:56:14 -0700 | [diff] [blame] | 80 | * @deprecated Consider using either {@link UserHandle#USER_SYSTEM} constant or |
| 81 | * check the target user's flag {@link android.content.pm.UserInfo#isAdmin}. |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 82 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 83 | @UnsupportedAppUsage |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 84 | @Deprecated |
Jeff Sharkey | cd65448 | 2016-01-08 17:42:11 -0700 | [diff] [blame] | 85 | public static final @UserIdInt int USER_OWNER = 0; |
Amith Yamasani | 8264408 | 2012-08-03 13:09:11 -0700 | [diff] [blame] | 86 | |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 87 | /** |
| 88 | * @hide A user handle to indicate the primary/owner user of the device |
Xiaohui Chen | 7c69636 | 2015-09-16 09:56:14 -0700 | [diff] [blame] | 89 | * @deprecated Consider using either {@link UserHandle#SYSTEM} constant or |
| 90 | * check the target user's flag {@link android.content.pm.UserInfo#isAdmin}. |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 91 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 92 | @UnsupportedAppUsage |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 93 | @Deprecated |
Jeff Sharkey | ba4acd5 | 2019-03-05 19:46:54 -0700 | [diff] [blame] | 94 | public static final @NonNull UserHandle OWNER = new UserHandle(USER_OWNER); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 95 | |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 96 | /** @hide A user id constant to indicate the "system" user of the device */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 97 | @UnsupportedAppUsage |
Makoto Onuki | acf3858 | 2019-10-04 11:53:42 -0700 | [diff] [blame] | 98 | @TestApi |
Jeff Sharkey | cd65448 | 2016-01-08 17:42:11 -0700 | [diff] [blame] | 99 | public static final @UserIdInt int USER_SYSTEM = 0; |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 100 | |
Jeff Sharkey | 47f7108 | 2016-02-01 17:03:54 -0700 | [diff] [blame] | 101 | /** @hide A user serial constant to indicate the "system" user of the device */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 102 | @UnsupportedAppUsage |
Jeff Sharkey | 47f7108 | 2016-02-01 17:03:54 -0700 | [diff] [blame] | 103 | public static final int USER_SERIAL_SYSTEM = 0; |
| 104 | |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 105 | /** @hide A user handle to indicate the "system" user of the device */ |
Jeff Sharkey | ec5f7d1 | 2018-08-08 09:15:04 -0600 | [diff] [blame] | 106 | @SystemApi |
Philip P. Moltmann | f80809f | 2018-04-04 11:20:44 -0700 | [diff] [blame] | 107 | @TestApi |
Jeff Sharkey | ba4acd5 | 2019-03-05 19:46:54 -0700 | [diff] [blame] | 108 | public static final @NonNull UserHandle SYSTEM = new UserHandle(USER_SYSTEM); |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 109 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 110 | /** |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 111 | * @hide Enable multi-user related side effects. Set this to false if |
| 112 | * there are problems with single user use-cases. |
| 113 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 114 | @UnsupportedAppUsage |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 115 | public static final boolean MU_ENABLED = true; |
| 116 | |
Jeff Sharkey | 77a3450 | 2017-11-09 17:40:57 -0700 | [diff] [blame] | 117 | /** @hide */ |
Makoto Onuki | acf3858 | 2019-10-04 11:53:42 -0700 | [diff] [blame] | 118 | @TestApi |
| 119 | public static final int MIN_SECONDARY_USER_ID = 10; |
| 120 | |
| 121 | /** |
| 122 | * Arbitrary user handle cache size. We use the cache even when {@link #MU_ENABLED} is false |
| 123 | * anyway, so we can always assume in CTS that UserHandle.of(10) returns a cached instance |
| 124 | * even on non-multiuser devices. |
| 125 | */ |
| 126 | private static final int NUM_CACHED_USERS = 4; |
| 127 | |
| 128 | private static final UserHandle[] CACHED_USER_INFOS = new UserHandle[NUM_CACHED_USERS]; |
| 129 | |
| 130 | static { |
| 131 | // Not lazily initializing the cache, so that we can share them across processes. |
| 132 | // (We'll create them in zygote.) |
| 133 | for (int i = 0; i < CACHED_USER_INFOS.length; i++) { |
| 134 | CACHED_USER_INFOS[i] = new UserHandle(MIN_SECONDARY_USER_ID + i); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | /** @hide */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 139 | @UnsupportedAppUsage |
Jeff Sharkey | 77a3450 | 2017-11-09 17:40:57 -0700 | [diff] [blame] | 140 | public static final int ERR_GID = -1; |
| 141 | /** @hide */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 142 | @UnsupportedAppUsage |
Jeff Sharkey | 77a3450 | 2017-11-09 17:40:57 -0700 | [diff] [blame] | 143 | public static final int AID_ROOT = android.os.Process.ROOT_UID; |
| 144 | /** @hide */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 145 | @UnsupportedAppUsage |
Jeff Sharkey | 77a3450 | 2017-11-09 17:40:57 -0700 | [diff] [blame] | 146 | public static final int AID_APP_START = android.os.Process.FIRST_APPLICATION_UID; |
| 147 | /** @hide */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 148 | @UnsupportedAppUsage |
Jeff Sharkey | 77a3450 | 2017-11-09 17:40:57 -0700 | [diff] [blame] | 149 | public static final int AID_APP_END = android.os.Process.LAST_APPLICATION_UID; |
| 150 | /** @hide */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 151 | @UnsupportedAppUsage |
Jeff Sharkey | 77a3450 | 2017-11-09 17:40:57 -0700 | [diff] [blame] | 152 | public static final int AID_SHARED_GID_START = android.os.Process.FIRST_SHARED_APPLICATION_GID; |
| 153 | /** @hide */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 154 | @UnsupportedAppUsage |
Jeff Sharkey | 77a3450 | 2017-11-09 17:40:57 -0700 | [diff] [blame] | 155 | public static final int AID_CACHE_GID_START = android.os.Process.FIRST_APPLICATION_CACHE_GID; |
| 156 | |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 157 | /** The userId represented by this UserHandle. */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 158 | @UnsupportedAppUsage |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 159 | final @UserIdInt int mHandle; |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 160 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 161 | /** |
| 162 | * Checks to see if the user id is the same for the two uids, i.e., they belong to the same |
| 163 | * user. |
| 164 | * @hide |
| 165 | */ |
Xiaohui Chen | eecb981 | 2015-09-16 11:02:18 -0700 | [diff] [blame] | 166 | public static boolean isSameUser(int uid1, int uid2) { |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 167 | return getUserId(uid1) == getUserId(uid2); |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * Checks to see if both uids are referring to the same app id, ignoring the user id part of the |
| 172 | * uids. |
| 173 | * @param uid1 uid to compare |
| 174 | * @param uid2 other uid to compare |
| 175 | * @return whether the appId is the same for both uids |
| 176 | * @hide |
| 177 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 178 | @UnsupportedAppUsage |
Xiaohui Chen | eecb981 | 2015-09-16 11:02:18 -0700 | [diff] [blame] | 179 | public static boolean isSameApp(int uid1, int uid2) { |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 180 | return getAppId(uid1) == getAppId(uid2); |
| 181 | } |
| 182 | |
Makoto Onuki | 9cc471c | 2018-01-23 12:33:56 -0800 | [diff] [blame] | 183 | /** |
| 184 | * Whether a UID is an "isolated" UID. |
| 185 | * @hide |
| 186 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 187 | @UnsupportedAppUsage |
Xiaohui Chen | eecb981 | 2015-09-16 11:02:18 -0700 | [diff] [blame] | 188 | public static boolean isIsolated(int uid) { |
Jeff Sharkey | d0c6ccb | 2012-09-14 16:26:37 -0700 | [diff] [blame] | 189 | if (uid > 0) { |
Martijn Coenen | 01e719b | 2018-12-05 16:01:38 +0100 | [diff] [blame] | 190 | return Process.isIsolated(uid); |
Jeff Sharkey | d0c6ccb | 2012-09-14 16:26:37 -0700 | [diff] [blame] | 191 | } else { |
| 192 | return false; |
| 193 | } |
Dianne Hackborn | a573f6a | 2012-02-09 16:12:18 -0800 | [diff] [blame] | 194 | } |
| 195 | |
Makoto Onuki | 9cc471c | 2018-01-23 12:33:56 -0800 | [diff] [blame] | 196 | /** |
| 197 | * Whether a UID belongs to a regular app. *Note* "Not a regular app" does not mean |
| 198 | * "it's system", because of isolated UIDs. Use {@link #isCore} for that. |
| 199 | * @hide |
| 200 | */ |
Artur Satayev | f0b7d0b | 2019-11-04 11:16:45 +0000 | [diff] [blame] | 201 | @UnsupportedAppUsage |
Philip P. Moltmann | 3311515 | 2018-04-11 13:39:36 -0700 | [diff] [blame] | 202 | @TestApi |
Jeff Sharkey | 8a8b581 | 2012-03-21 18:13:36 -0700 | [diff] [blame] | 203 | public static boolean isApp(int uid) { |
| 204 | if (uid > 0) { |
Jeff Sharkey | d0c6ccb | 2012-09-14 16:26:37 -0700 | [diff] [blame] | 205 | final int appId = getAppId(uid); |
| 206 | return appId >= Process.FIRST_APPLICATION_UID && appId <= Process.LAST_APPLICATION_UID; |
Jeff Sharkey | 8a8b581 | 2012-03-21 18:13:36 -0700 | [diff] [blame] | 207 | } else { |
| 208 | return false; |
| 209 | } |
| 210 | } |
| 211 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 212 | /** |
Makoto Onuki | 9cc471c | 2018-01-23 12:33:56 -0800 | [diff] [blame] | 213 | * Whether a UID belongs to a system core component or not. |
| 214 | * @hide |
| 215 | */ |
| 216 | public static boolean isCore(int uid) { |
Makoto Onuki | cbc3cce | 2018-03-28 16:49:47 -0700 | [diff] [blame] | 217 | if (uid >= 0) { |
Makoto Onuki | 9cc471c | 2018-01-23 12:33:56 -0800 | [diff] [blame] | 218 | final int appId = getAppId(uid); |
| 219 | return appId < Process.FIRST_APPLICATION_UID; |
| 220 | } else { |
| 221 | return false; |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | /** |
Jeff Davidson | 48aa86b | 2016-02-10 14:15:42 -0800 | [diff] [blame] | 226 | * Returns the user for a given uid. |
| 227 | * @param uid A uid for an application running in a particular user. |
| 228 | * @return A {@link UserHandle} for that user. |
| 229 | */ |
| 230 | public static UserHandle getUserHandleForUid(int uid) { |
| 231 | return of(getUserId(uid)); |
| 232 | } |
| 233 | |
| 234 | /** |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 235 | * Returns the user id for a given uid. |
| 236 | * @hide |
| 237 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 238 | @UnsupportedAppUsage |
Makoto Onuki | acf3858 | 2019-10-04 11:53:42 -0700 | [diff] [blame] | 239 | @TestApi |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 240 | public static @UserIdInt int getUserId(int uid) { |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 241 | if (MU_ENABLED) { |
| 242 | return uid / PER_USER_RANGE; |
| 243 | } else { |
Xiaohui Chen | 70f6c38 | 2015-04-28 14:21:43 -0700 | [diff] [blame] | 244 | return UserHandle.USER_SYSTEM; |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 245 | } |
| 246 | } |
| 247 | |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 248 | /** @hide */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 249 | @UnsupportedAppUsage |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 250 | public static @UserIdInt int getCallingUserId() { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 251 | return getUserId(Binder.getCallingUid()); |
| 252 | } |
| 253 | |
Alexandra Gherghina | c1cf161 | 2014-06-05 10:49:14 +0100 | [diff] [blame] | 254 | /** @hide */ |
Jeff Sharkey | b7479988 | 2017-07-28 16:55:41 -0600 | [diff] [blame] | 255 | public static @AppIdInt int getCallingAppId() { |
| 256 | return getAppId(Binder.getCallingUid()); |
| 257 | } |
| 258 | |
| 259 | /** @hide */ |
Makoto Onuki | acf3858 | 2019-10-04 11:53:42 -0700 | [diff] [blame] | 260 | @TestApi |
Fyodor Kupolov | 940e857 | 2016-01-26 12:03:51 -0800 | [diff] [blame] | 261 | @SystemApi |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 262 | public static UserHandle of(@UserIdInt int userId) { |
Makoto Onuki | acf3858 | 2019-10-04 11:53:42 -0700 | [diff] [blame] | 263 | if (userId == USER_SYSTEM) { |
| 264 | return SYSTEM; // Most common. |
| 265 | } |
| 266 | // These are sequential; so use a switch. Maybe they'll be optimized to a table lookup. |
| 267 | switch (userId) { |
| 268 | case USER_ALL: |
| 269 | return ALL; |
| 270 | |
| 271 | case USER_CURRENT: |
| 272 | return CURRENT; |
| 273 | |
| 274 | case USER_CURRENT_OR_SELF: |
| 275 | return CURRENT_OR_SELF; |
| 276 | } |
| 277 | if (userId >= MIN_SECONDARY_USER_ID |
| 278 | && userId < (MIN_SECONDARY_USER_ID + CACHED_USER_INFOS.length)) { |
| 279 | return CACHED_USER_INFOS[userId - MIN_SECONDARY_USER_ID]; |
| 280 | } |
| 281 | if (userId == USER_NULL) { // Not common. |
| 282 | return NULL; |
| 283 | } |
| 284 | return new UserHandle(userId); |
Alexandra Gherghina | c1cf161 | 2014-06-05 10:49:14 +0100 | [diff] [blame] | 285 | } |
| 286 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 287 | /** |
| 288 | * Returns the uid that is composed from the userId and the appId. |
| 289 | * @hide |
| 290 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 291 | @UnsupportedAppUsage |
Makoto Onuki | acf3858 | 2019-10-04 11:53:42 -0700 | [diff] [blame] | 292 | @TestApi |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 293 | public static int getUid(@UserIdInt int userId, @AppIdInt int appId) { |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 294 | if (MU_ENABLED) { |
| 295 | return userId * PER_USER_RANGE + (appId % PER_USER_RANGE); |
| 296 | } else { |
| 297 | return appId; |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | /** |
| 302 | * Returns the app id (or base uid) for a given uid, stripping out the user id from it. |
| 303 | * @hide |
| 304 | */ |
Jeff Sharkey | a73b8fd | 2016-01-06 17:02:08 -0700 | [diff] [blame] | 305 | @TestApi |
Remi NGUYEN VAN | 9e70a42 | 2019-01-31 12:36:54 +0900 | [diff] [blame] | 306 | @SystemApi |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 307 | public static @AppIdInt int getAppId(int uid) { |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 308 | return uid % PER_USER_RANGE; |
| 309 | } |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 310 | |
| 311 | /** |
Robin Lee | e66b689 | 2014-04-29 12:36:47 +0100 | [diff] [blame] | 312 | * Returns the gid shared between all apps with this userId. |
| 313 | * @hide |
| 314 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 315 | public static int getUserGid(@UserIdInt int userId) { |
Robin Lee | e66b689 | 2014-04-29 12:36:47 +0100 | [diff] [blame] | 316 | return getUid(userId, Process.SHARED_USER_GID); |
| 317 | } |
| 318 | |
Jeff Sharkey | 77a3450 | 2017-11-09 17:40:57 -0700 | [diff] [blame] | 319 | /** @hide */ |
| 320 | public static int getSharedAppGid(int uid) { |
| 321 | return getSharedAppGid(getUserId(uid), getAppId(uid)); |
| 322 | } |
| 323 | |
| 324 | /** @hide */ |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 325 | public static int getSharedAppGid(@UserIdInt int userId, @AppIdInt int appId) { |
Jeff Sharkey | 77a3450 | 2017-11-09 17:40:57 -0700 | [diff] [blame] | 326 | if (appId >= AID_APP_START && appId <= AID_APP_END) { |
| 327 | return (appId - AID_APP_START) + AID_SHARED_GID_START; |
| 328 | } else if (appId >= AID_ROOT && appId <= AID_APP_START) { |
| 329 | return appId; |
| 330 | } else { |
| 331 | return -1; |
| 332 | } |
Kenny Root | e091f22 | 2012-09-11 15:01:26 -0700 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | /** |
Adam Lesinski | 621e06a | 2015-08-13 22:06:31 -0700 | [diff] [blame] | 336 | * Returns the app id for a given shared app gid. Returns -1 if the ID is invalid. |
Adam Lesinski | f4216d3 | 2015-06-26 16:33:24 -0700 | [diff] [blame] | 337 | * @hide |
| 338 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 339 | @UnsupportedAppUsage |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 340 | public static @AppIdInt int getAppIdFromSharedAppGid(int gid) { |
Adam Lesinski | 621e06a | 2015-08-13 22:06:31 -0700 | [diff] [blame] | 341 | final int appId = getAppId(gid) + Process.FIRST_APPLICATION_UID |
| 342 | - Process.FIRST_SHARED_APPLICATION_GID; |
| 343 | if (appId < 0 || appId >= Process.FIRST_SHARED_APPLICATION_GID) { |
| 344 | return -1; |
Adam Lesinski | f4216d3 | 2015-06-26 16:33:24 -0700 | [diff] [blame] | 345 | } |
Adam Lesinski | 621e06a | 2015-08-13 22:06:31 -0700 | [diff] [blame] | 346 | return appId; |
Adam Lesinski | f4216d3 | 2015-06-26 16:33:24 -0700 | [diff] [blame] | 347 | } |
| 348 | |
Jeff Sharkey | 77a3450 | 2017-11-09 17:40:57 -0700 | [diff] [blame] | 349 | /** @hide */ |
| 350 | public static int getCacheAppGid(int uid) { |
| 351 | return getCacheAppGid(getUserId(uid), getAppId(uid)); |
| 352 | } |
| 353 | |
| 354 | /** @hide */ |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 355 | public static int getCacheAppGid(@UserIdInt int userId, @AppIdInt int appId) { |
Jeff Sharkey | 77a3450 | 2017-11-09 17:40:57 -0700 | [diff] [blame] | 356 | if (appId >= AID_APP_START && appId <= AID_APP_END) { |
| 357 | return getUid(userId, (appId - AID_APP_START) + AID_CACHE_GID_START); |
| 358 | } else { |
| 359 | return -1; |
| 360 | } |
Jeff Sharkey | 5eb3eb5 | 2016-12-13 08:44:51 -0700 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 364 | * Generate a text representation of the uid, breaking out its individual |
| 365 | * components -- user, app, isolated, etc. |
| 366 | * @hide |
| 367 | */ |
| 368 | public static void formatUid(StringBuilder sb, int uid) { |
| 369 | if (uid < Process.FIRST_APPLICATION_UID) { |
| 370 | sb.append(uid); |
| 371 | } else { |
| 372 | sb.append('u'); |
| 373 | sb.append(getUserId(uid)); |
| 374 | final int appId = getAppId(uid); |
Martijn Coenen | 01e719b | 2018-12-05 16:01:38 +0100 | [diff] [blame] | 375 | if (isIsolated(appId)) { |
| 376 | if (appId > Process.FIRST_ISOLATED_UID) { |
| 377 | sb.append('i'); |
| 378 | sb.append(appId - Process.FIRST_ISOLATED_UID); |
| 379 | } else { |
| 380 | sb.append("ai"); |
| 381 | sb.append(appId - Process.FIRST_APP_ZYGOTE_ISOLATED_UID); |
| 382 | } |
Dianne Hackborn | a4cc205 | 2013-07-08 17:31:25 -0700 | [diff] [blame] | 383 | } else if (appId >= Process.FIRST_APPLICATION_UID) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 384 | sb.append('a'); |
Dianne Hackborn | a4cc205 | 2013-07-08 17:31:25 -0700 | [diff] [blame] | 385 | sb.append(appId - Process.FIRST_APPLICATION_UID); |
| 386 | } else { |
| 387 | sb.append('s'); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 388 | sb.append(appId); |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | /** |
| 394 | * Generate a text representation of the uid, breaking out its individual |
| 395 | * components -- user, app, isolated, etc. |
Kweku Adams | 835283f | 2019-11-20 14:41:22 -0800 | [diff] [blame] | 396 | * |
| 397 | * @param uid The uid to format |
| 398 | * @return A string representing the UID with its individual components broken out |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 399 | * @hide |
| 400 | */ |
Kweku Adams | 835283f | 2019-11-20 14:41:22 -0800 | [diff] [blame] | 401 | @SystemApi |
| 402 | @NonNull |
Dianne Hackborn | 3b16cf4 | 2015-07-01 15:05:04 -0700 | [diff] [blame] | 403 | public static String formatUid(int uid) { |
| 404 | StringBuilder sb = new StringBuilder(); |
| 405 | formatUid(sb, uid); |
| 406 | return sb.toString(); |
| 407 | } |
| 408 | |
| 409 | /** |
| 410 | * Generate a text representation of the uid, breaking out its individual |
| 411 | * components -- user, app, isolated, etc. |
| 412 | * @hide |
| 413 | */ |
Artur Satayev | 70507ed | 2019-07-29 13:18:27 +0100 | [diff] [blame] | 414 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 415 | public static void formatUid(PrintWriter pw, int uid) { |
| 416 | if (uid < Process.FIRST_APPLICATION_UID) { |
| 417 | pw.print(uid); |
| 418 | } else { |
| 419 | pw.print('u'); |
| 420 | pw.print(getUserId(uid)); |
| 421 | final int appId = getAppId(uid); |
Martijn Coenen | 01e719b | 2018-12-05 16:01:38 +0100 | [diff] [blame] | 422 | if (isIsolated(appId)) { |
| 423 | if (appId > Process.FIRST_ISOLATED_UID) { |
| 424 | pw.print('i'); |
| 425 | pw.print(appId - Process.FIRST_ISOLATED_UID); |
| 426 | } else { |
| 427 | pw.print("ai"); |
| 428 | pw.print(appId - Process.FIRST_APP_ZYGOTE_ISOLATED_UID); |
| 429 | } |
Dianne Hackborn | a4cc205 | 2013-07-08 17:31:25 -0700 | [diff] [blame] | 430 | } else if (appId >= Process.FIRST_APPLICATION_UID) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 431 | pw.print('a'); |
Dianne Hackborn | a4cc205 | 2013-07-08 17:31:25 -0700 | [diff] [blame] | 432 | pw.print(appId - Process.FIRST_APPLICATION_UID); |
| 433 | } else { |
| 434 | pw.print('s'); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 435 | pw.print(appId); |
| 436 | } |
| 437 | } |
| 438 | } |
| 439 | |
Dianne Hackborn | 3cdb56e | 2015-11-11 12:45:44 -0800 | [diff] [blame] | 440 | /** @hide */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 441 | public static @UserIdInt int parseUserArg(String arg) { |
Dianne Hackborn | 3cdb56e | 2015-11-11 12:45:44 -0800 | [diff] [blame] | 442 | int userId; |
| 443 | if ("all".equals(arg)) { |
| 444 | userId = UserHandle.USER_ALL; |
| 445 | } else if ("current".equals(arg) || "cur".equals(arg)) { |
| 446 | userId = UserHandle.USER_CURRENT; |
| 447 | } else { |
| 448 | try { |
| 449 | userId = Integer.parseInt(arg); |
| 450 | } catch (NumberFormatException e) { |
| 451 | throw new IllegalArgumentException("Bad user number: " + arg); |
| 452 | } |
| 453 | } |
| 454 | return userId; |
| 455 | } |
| 456 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 457 | /** |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 458 | * Returns the user id of the current process |
| 459 | * @return user id of the current process |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 460 | * @hide |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 461 | */ |
Amith Yamasani | 0e8d7d6 | 2014-09-03 13:17:28 -0700 | [diff] [blame] | 462 | @SystemApi |
Makoto Onuki | acf3858 | 2019-10-04 11:53:42 -0700 | [diff] [blame] | 463 | @TestApi |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 464 | public static @UserIdInt int myUserId() { |
Andreas Gampe | d281b42 | 2016-07-08 03:50:27 +0000 | [diff] [blame] | 465 | return getUserId(Process.myUid()); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 466 | } |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 467 | |
Christopher Tate | cbd7a6e | 2014-08-06 14:24:14 -0700 | [diff] [blame] | 468 | /** |
| 469 | * Returns true if this UserHandle refers to the owner user; false otherwise. |
| 470 | * @return true if this UserHandle refers to the owner user; false otherwise. |
| 471 | * @hide |
Xiaohui Chen | 1fa7680 | 2015-10-12 15:56:25 -0700 | [diff] [blame] | 472 | * @deprecated please use {@link #isSystem()} or check for |
| 473 | * {@link android.content.pm.UserInfo#isPrimary()} |
| 474 | * {@link android.content.pm.UserInfo#isAdmin()} based on your particular use case. |
Christopher Tate | cbd7a6e | 2014-08-06 14:24:14 -0700 | [diff] [blame] | 475 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 476 | @Deprecated |
Christopher Tate | cbd7a6e | 2014-08-06 14:24:14 -0700 | [diff] [blame] | 477 | @SystemApi |
Xiaohui Chen | eecb981 | 2015-09-16 11:02:18 -0700 | [diff] [blame] | 478 | public boolean isOwner() { |
Christopher Tate | cbd7a6e | 2014-08-06 14:24:14 -0700 | [diff] [blame] | 479 | return this.equals(OWNER); |
| 480 | } |
| 481 | |
Xiaohui Chen | 1fa7680 | 2015-10-12 15:56:25 -0700 | [diff] [blame] | 482 | /** |
| 483 | * @return true if this UserHandle refers to the system user; false otherwise. |
| 484 | * @hide |
| 485 | */ |
| 486 | @SystemApi |
| 487 | public boolean isSystem() { |
| 488 | return this.equals(SYSTEM); |
| 489 | } |
| 490 | |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 491 | /** @hide */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 492 | @UnsupportedAppUsage |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 493 | public UserHandle(@UserIdInt int userId) { |
| 494 | mHandle = userId; |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 495 | } |
| 496 | |
Amith Yamasani | 0e8d7d6 | 2014-09-03 13:17:28 -0700 | [diff] [blame] | 497 | /** |
| 498 | * Returns the userId stored in this UserHandle. |
| 499 | * @hide |
| 500 | */ |
| 501 | @SystemApi |
Makoto Onuki | cb8936e | 2017-04-10 15:37:17 -0700 | [diff] [blame] | 502 | @TestApi |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 503 | public @UserIdInt int getIdentifier() { |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 504 | return mHandle; |
| 505 | } |
| 506 | |
| 507 | @Override |
| 508 | public String toString() { |
| 509 | return "UserHandle{" + mHandle + "}"; |
| 510 | } |
| 511 | |
| 512 | @Override |
| 513 | public boolean equals(Object obj) { |
| 514 | try { |
| 515 | if (obj != null) { |
| 516 | UserHandle other = (UserHandle)obj; |
| 517 | return mHandle == other.mHandle; |
| 518 | } |
| 519 | } catch (ClassCastException e) { |
| 520 | } |
| 521 | return false; |
| 522 | } |
| 523 | |
| 524 | @Override |
| 525 | public int hashCode() { |
| 526 | return mHandle; |
| 527 | } |
Kweku Adams | 835283f | 2019-11-20 14:41:22 -0800 | [diff] [blame] | 528 | |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 529 | public int describeContents() { |
| 530 | return 0; |
| 531 | } |
| 532 | |
| 533 | public void writeToParcel(Parcel out, int flags) { |
| 534 | out.writeInt(mHandle); |
| 535 | } |
| 536 | |
| 537 | /** |
| 538 | * Write a UserHandle to a Parcel, handling null pointers. Must be |
| 539 | * read with {@link #readFromParcel(Parcel)}. |
Kweku Adams | 835283f | 2019-11-20 14:41:22 -0800 | [diff] [blame] | 540 | * |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 541 | * @param h The UserHandle to be written. |
| 542 | * @param out The Parcel in which the UserHandle will be placed. |
Kweku Adams | 835283f | 2019-11-20 14:41:22 -0800 | [diff] [blame] | 543 | * |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 544 | * @see #readFromParcel(Parcel) |
| 545 | */ |
| 546 | public static void writeToParcel(UserHandle h, Parcel out) { |
| 547 | if (h != null) { |
| 548 | h.writeToParcel(out, 0); |
| 549 | } else { |
| 550 | out.writeInt(USER_NULL); |
| 551 | } |
| 552 | } |
Kweku Adams | 835283f | 2019-11-20 14:41:22 -0800 | [diff] [blame] | 553 | |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 554 | /** |
| 555 | * Read a UserHandle from a Parcel that was previously written |
| 556 | * with {@link #writeToParcel(UserHandle, Parcel)}, returning either |
| 557 | * a null or new object as appropriate. |
Kweku Adams | 835283f | 2019-11-20 14:41:22 -0800 | [diff] [blame] | 558 | * |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 559 | * @param in The Parcel from which to read the UserHandle |
| 560 | * @return Returns a new UserHandle matching the previously written |
| 561 | * object, or null if a null had been written. |
Kweku Adams | 835283f | 2019-11-20 14:41:22 -0800 | [diff] [blame] | 562 | * |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 563 | * @see #writeToParcel(UserHandle, Parcel) |
| 564 | */ |
| 565 | public static UserHandle readFromParcel(Parcel in) { |
| 566 | int h = in.readInt(); |
| 567 | return h != USER_NULL ? new UserHandle(h) : null; |
| 568 | } |
Kweku Adams | 835283f | 2019-11-20 14:41:22 -0800 | [diff] [blame] | 569 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 570 | public static final @android.annotation.NonNull Parcelable.Creator<UserHandle> CREATOR |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 571 | = new Parcelable.Creator<UserHandle>() { |
| 572 | public UserHandle createFromParcel(Parcel in) { |
Makoto Onuki | acf3858 | 2019-10-04 11:53:42 -0700 | [diff] [blame] | 573 | // Try to avoid allocation; use of() here. Keep this and the constructor below |
| 574 | // in sync. |
| 575 | return UserHandle.of(in.readInt()); |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | public UserHandle[] newArray(int size) { |
| 579 | return new UserHandle[size]; |
| 580 | } |
| 581 | }; |
| 582 | |
| 583 | /** |
| 584 | * Instantiate a new UserHandle from the data in a Parcel that was |
| 585 | * previously written with {@link #writeToParcel(Parcel, int)}. Note that you |
| 586 | * must not use this with data written by |
| 587 | * {@link #writeToParcel(UserHandle, Parcel)} since it is not possible |
| 588 | * to handle a null UserHandle here. |
Kweku Adams | 835283f | 2019-11-20 14:41:22 -0800 | [diff] [blame] | 589 | * |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 590 | * @param in The Parcel containing the previously written UserHandle, |
| 591 | * positioned at the location in the buffer where it was written. |
| 592 | */ |
| 593 | public UserHandle(Parcel in) { |
Makoto Onuki | acf3858 | 2019-10-04 11:53:42 -0700 | [diff] [blame] | 594 | mHandle = in.readInt(); // Keep this and createFromParcel() in sync. |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 595 | } |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 596 | } |