1742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani/* 2742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani * Copyright (C) 2011 The Android Open Source Project 3742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani * 4742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani * Licensed under the Apache License, Version 2.0 (the "License"); 5742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani * you may not use this file except in compliance with the License. 6742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani * You may obtain a copy of the License at 7742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani * 8742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani * http://www.apache.org/licenses/LICENSE-2.0 9742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani * 10742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani * Unless required by applicable law or agreed to in writing, software 11742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani * distributed under the License is distributed on an "AS IS" BASIS, 12742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani * See the License for the specific language governing permissions and 14742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani * limitations under the License. 15742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani */ 16742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani 17742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasanipackage android.os; 18742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani 19742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani/** 20f02b60aa4f367516f40cf3d60fffae0c6fe3e1b8Dianne Hackborn * Representation of a user on the device. 21742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani */ 2279af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackbornpublic final class UserHandle implements Parcelable { 23742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani /** 2479af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn * @hide Range of uids allocated for a user. 25742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani */ 26742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani public static final int PER_USER_RANGE = 100000; 27742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani 2879af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn /** @hide A user id to indicate all users on the device */ 29742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani public static final int USER_ALL = -1; 30742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani 317767eac3232ba2fb9828766813cdb481d6a97584Dianne Hackborn /** @hide A user handle to indicate all users on the device */ 327767eac3232ba2fb9828766813cdb481d6a97584Dianne Hackborn public static final UserHandle ALL = new UserHandle(USER_ALL); 337767eac3232ba2fb9828766813cdb481d6a97584Dianne Hackborn 3479af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn /** @hide A user id to indicate the currently active user */ 358264408f5995534f8e3147b001664ea0df52aaa5Amith Yamasani public static final int USER_CURRENT = -2; 368264408f5995534f8e3147b001664ea0df52aaa5Amith Yamasani 375ac72a29593ab9a20337a2225df52bdf4754be02Dianne Hackborn /** @hide A user handle to indicate the current user of the device */ 385ac72a29593ab9a20337a2225df52bdf4754be02Dianne Hackborn public static final UserHandle CURRENT = new UserHandle(USER_CURRENT); 395ac72a29593ab9a20337a2225df52bdf4754be02Dianne Hackborn 405ac72a29593ab9a20337a2225df52bdf4754be02Dianne Hackborn /** @hide A user id to indicate that we would like to send to the current 415ac72a29593ab9a20337a2225df52bdf4754be02Dianne Hackborn * user, but if this is calling from a user process then we will send it 425ac72a29593ab9a20337a2225df52bdf4754be02Dianne Hackborn * to the caller's user instead of failing wiht a security exception */ 438a9f5d42a5cc373439ee8bbb9185dcce9086770dDianne Hackborn public static final int USER_CURRENT_OR_SELF = -3; 445ac72a29593ab9a20337a2225df52bdf4754be02Dianne Hackborn 455ac72a29593ab9a20337a2225df52bdf4754be02Dianne Hackborn /** @hide A user handle to indicate that we would like to send to the current 465ac72a29593ab9a20337a2225df52bdf4754be02Dianne Hackborn * user, but if this is calling from a user process then we will send it 475ac72a29593ab9a20337a2225df52bdf4754be02Dianne Hackborn * to the caller's user instead of failing wiht a security exception */ 485ac72a29593ab9a20337a2225df52bdf4754be02Dianne Hackborn public static final UserHandle CURRENT_OR_SELF = new UserHandle(USER_CURRENT_OR_SELF); 495ac72a29593ab9a20337a2225df52bdf4754be02Dianne Hackborn 5079af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn /** @hide An undefined user id */ 5179af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn public static final int USER_NULL = -10000; 5279af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn 5379af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn /** @hide A user id constant to indicate the "owner" user of the device */ 54aac71ff465399251fa8e830407f2917b986988d9Christopher Tate public static final int USER_OWNER = 0; 558264408f5995534f8e3147b001664ea0df52aaa5Amith Yamasani 565ac72a29593ab9a20337a2225df52bdf4754be02Dianne Hackborn /** @hide A user handle to indicate the primary/owner user of the device */ 575ac72a29593ab9a20337a2225df52bdf4754be02Dianne Hackborn public static final UserHandle OWNER = new UserHandle(USER_OWNER); 585ac72a29593ab9a20337a2225df52bdf4754be02Dianne Hackborn 59742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani /** 6079af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn * @hide Enable multi-user related side effects. Set this to false if 6179af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn * there are problems with single user use-cases. 6279af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn */ 63742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani public static final boolean MU_ENABLED = true; 64742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani 6579af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn final int mHandle; 6679af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn 67742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani /** 68742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani * Checks to see if the user id is the same for the two uids, i.e., they belong to the same 69742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani * user. 70742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani * @hide 71742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani */ 72742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani public static final boolean isSameUser(int uid1, int uid2) { 73742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani return getUserId(uid1) == getUserId(uid2); 74742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani } 75742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani 76742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani /** 77742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani * Checks to see if both uids are referring to the same app id, ignoring the user id part of the 78742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani * uids. 79742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani * @param uid1 uid to compare 80742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani * @param uid2 other uid to compare 81742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani * @return whether the appId is the same for both uids 82742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani * @hide 83742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani */ 84742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani public static final boolean isSameApp(int uid1, int uid2) { 85742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani return getAppId(uid1) == getAppId(uid2); 86742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani } 87742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani 8879af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn /** @hide */ 89a573f6a1d9b12393fbdfd2c0850499973849854bDianne Hackborn public static final boolean isIsolated(int uid) { 90d0c6ccbafdebc73d03cf3cd47f02f9f6c78a69ffJeff Sharkey if (uid > 0) { 91d0c6ccbafdebc73d03cf3cd47f02f9f6c78a69ffJeff Sharkey final int appId = getAppId(uid); 92d0c6ccbafdebc73d03cf3cd47f02f9f6c78a69ffJeff Sharkey return appId >= Process.FIRST_ISOLATED_UID && appId <= Process.LAST_ISOLATED_UID; 93d0c6ccbafdebc73d03cf3cd47f02f9f6c78a69ffJeff Sharkey } else { 94d0c6ccbafdebc73d03cf3cd47f02f9f6c78a69ffJeff Sharkey return false; 95d0c6ccbafdebc73d03cf3cd47f02f9f6c78a69ffJeff Sharkey } 96a573f6a1d9b12393fbdfd2c0850499973849854bDianne Hackborn } 97a573f6a1d9b12393fbdfd2c0850499973849854bDianne Hackborn 9879af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn /** @hide */ 998a8b581e669f6187b397f856a567a76ed8aba2c2Jeff Sharkey public static boolean isApp(int uid) { 1008a8b581e669f6187b397f856a567a76ed8aba2c2Jeff Sharkey if (uid > 0) { 101d0c6ccbafdebc73d03cf3cd47f02f9f6c78a69ffJeff Sharkey final int appId = getAppId(uid); 102d0c6ccbafdebc73d03cf3cd47f02f9f6c78a69ffJeff Sharkey return appId >= Process.FIRST_APPLICATION_UID && appId <= Process.LAST_APPLICATION_UID; 1038a8b581e669f6187b397f856a567a76ed8aba2c2Jeff Sharkey } else { 1048a8b581e669f6187b397f856a567a76ed8aba2c2Jeff Sharkey return false; 1058a8b581e669f6187b397f856a567a76ed8aba2c2Jeff Sharkey } 1068a8b581e669f6187b397f856a567a76ed8aba2c2Jeff Sharkey } 1078a8b581e669f6187b397f856a567a76ed8aba2c2Jeff Sharkey 108742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani /** 109742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani * Returns the user id for a given uid. 110742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani * @hide 111742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani */ 112742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani public static final int getUserId(int uid) { 113742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani if (MU_ENABLED) { 114742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani return uid / PER_USER_RANGE; 115742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani } else { 116742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani return 0; 117742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani } 118742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani } 119742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani 12079af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn /** @hide */ 12137ce3a8af6faab675319d0803b288ab1dddc76beAmith Yamasani public static final int getCallingUserId() { 12237ce3a8af6faab675319d0803b288ab1dddc76beAmith Yamasani return getUserId(Binder.getCallingUid()); 12337ce3a8af6faab675319d0803b288ab1dddc76beAmith Yamasani } 12437ce3a8af6faab675319d0803b288ab1dddc76beAmith Yamasani 125742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani /** 126742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani * Returns the uid that is composed from the userId and the appId. 127742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani * @hide 128742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani */ 129742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani public static final int getUid(int userId, int appId) { 130742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani if (MU_ENABLED) { 131742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani return userId * PER_USER_RANGE + (appId % PER_USER_RANGE); 132742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani } else { 133742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani return appId; 134742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani } 135742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani } 136742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani 137742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani /** 138742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani * Returns the app id (or base uid) for a given uid, stripping out the user id from it. 139742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani * @hide 140742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani */ 141742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani public static final int getAppId(int uid) { 142742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani return uid % PER_USER_RANGE; 143742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani } 144483f3b06ea84440a082e21b68ec2c2e54046f5a6Amith Yamasani 145483f3b06ea84440a082e21b68ec2c2e54046f5a6Amith Yamasani /** 146e091f22e226f7177e45e23850670c1ad9b63fd75Kenny Root * Returns the shared app gid for a given uid or appId. 147e091f22e226f7177e45e23850670c1ad9b63fd75Kenny Root * @hide 148e091f22e226f7177e45e23850670c1ad9b63fd75Kenny Root */ 149e091f22e226f7177e45e23850670c1ad9b63fd75Kenny Root public static final int getSharedAppGid(int id) { 150e091f22e226f7177e45e23850670c1ad9b63fd75Kenny Root return Process.FIRST_SHARED_APPLICATION_GID + (id % PER_USER_RANGE) 151e091f22e226f7177e45e23850670c1ad9b63fd75Kenny Root - Process.FIRST_APPLICATION_UID; 152e091f22e226f7177e45e23850670c1ad9b63fd75Kenny Root } 153e091f22e226f7177e45e23850670c1ad9b63fd75Kenny Root 154e091f22e226f7177e45e23850670c1ad9b63fd75Kenny Root /** 155483f3b06ea84440a082e21b68ec2c2e54046f5a6Amith Yamasani * Returns the user id of the current process 156483f3b06ea84440a082e21b68ec2c2e54046f5a6Amith Yamasani * @return user id of the current process 15779af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn * @hide 158483f3b06ea84440a082e21b68ec2c2e54046f5a6Amith Yamasani */ 159483f3b06ea84440a082e21b68ec2c2e54046f5a6Amith Yamasani public static final int myUserId() { 160483f3b06ea84440a082e21b68ec2c2e54046f5a6Amith Yamasani return getUserId(Process.myUid()); 161483f3b06ea84440a082e21b68ec2c2e54046f5a6Amith Yamasani } 16279af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn 16379af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn /** @hide */ 16479af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn public UserHandle(int h) { 16579af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn mHandle = h; 16679af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn } 16779af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn 16879af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn /** @hide */ 16979af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn public int getIdentifier() { 17079af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn return mHandle; 17179af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn } 17279af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn 17379af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn @Override 17479af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn public String toString() { 17579af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn return "UserHandle{" + mHandle + "}"; 17679af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn } 17779af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn 17879af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn @Override 17979af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn public boolean equals(Object obj) { 18079af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn try { 18179af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn if (obj != null) { 18279af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn UserHandle other = (UserHandle)obj; 18379af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn return mHandle == other.mHandle; 18479af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn } 18579af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn } catch (ClassCastException e) { 18679af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn } 18779af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn return false; 18879af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn } 18979af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn 19079af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn @Override 19179af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn public int hashCode() { 19279af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn return mHandle; 19379af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn } 19479af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn 19579af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn public int describeContents() { 19679af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn return 0; 19779af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn } 19879af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn 19979af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn public void writeToParcel(Parcel out, int flags) { 20079af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn out.writeInt(mHandle); 20179af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn } 20279af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn 20379af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn /** 20479af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn * Write a UserHandle to a Parcel, handling null pointers. Must be 20579af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn * read with {@link #readFromParcel(Parcel)}. 20679af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn * 20779af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn * @param h The UserHandle to be written. 20879af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn * @param out The Parcel in which the UserHandle will be placed. 20979af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn * 21079af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn * @see #readFromParcel(Parcel) 21179af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn */ 21279af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn public static void writeToParcel(UserHandle h, Parcel out) { 21379af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn if (h != null) { 21479af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn h.writeToParcel(out, 0); 21579af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn } else { 21679af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn out.writeInt(USER_NULL); 21779af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn } 21879af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn } 21979af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn 22079af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn /** 22179af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn * Read a UserHandle from a Parcel that was previously written 22279af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn * with {@link #writeToParcel(UserHandle, Parcel)}, returning either 22379af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn * a null or new object as appropriate. 22479af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn * 22579af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn * @param in The Parcel from which to read the UserHandle 22679af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn * @return Returns a new UserHandle matching the previously written 22779af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn * object, or null if a null had been written. 22879af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn * 22979af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn * @see #writeToParcel(UserHandle, Parcel) 23079af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn */ 23179af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn public static UserHandle readFromParcel(Parcel in) { 23279af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn int h = in.readInt(); 23379af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn return h != USER_NULL ? new UserHandle(h) : null; 23479af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn } 23579af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn 23679af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn public static final Parcelable.Creator<UserHandle> CREATOR 23779af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn = new Parcelable.Creator<UserHandle>() { 23879af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn public UserHandle createFromParcel(Parcel in) { 23979af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn return new UserHandle(in); 24079af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn } 24179af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn 24279af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn public UserHandle[] newArray(int size) { 24379af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn return new UserHandle[size]; 24479af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn } 24579af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn }; 24679af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn 24779af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn /** 24879af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn * Instantiate a new UserHandle from the data in a Parcel that was 24979af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn * previously written with {@link #writeToParcel(Parcel, int)}. Note that you 25079af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn * must not use this with data written by 25179af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn * {@link #writeToParcel(UserHandle, Parcel)} since it is not possible 25279af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn * to handle a null UserHandle here. 25379af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn * 25479af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn * @param in The Parcel containing the previously written UserHandle, 25579af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn * positioned at the location in the buffer where it was written. 25679af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn */ 25779af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn public UserHandle(Parcel in) { 25879af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn mHandle = in.readInt(); 25979af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn } 260742a67127366c376fdf188ff99ba30b27d3bf90cAmith Yamasani} 261