Use UserHandles instead of userId integers.
userId integers are not public API and code should use UserHandle instead. Bug: 170598012 Test: passes existing tests Change-Id: Ic27b93ccfe6bbc97e7419293ce165fee6cd51e6d
This commit is contained in:
parent
073dfc4c88
commit
8876a3da0c
1 changed files with 63 additions and 64 deletions
|
|
@ -21,6 +21,7 @@ import static android.os.UserHandle.PER_USER_RANGE;
|
|||
import android.annotation.Nullable;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
|
|
@ -45,6 +46,14 @@ public final class UidRange implements Parcelable {
|
|||
return new UidRange(userId * PER_USER_RANGE, (userId + 1) * PER_USER_RANGE - 1);
|
||||
}
|
||||
|
||||
/** Creates a UidRange for the specified user. */
|
||||
public static UidRange createForUser(UserHandle user) {
|
||||
final UserHandle nextUser = UserHandle.of(user.getIdentifier() + 1);
|
||||
final int start = UserHandle.getUid(user, 0 /* appId */);
|
||||
final int end = UserHandle.getUid(nextUser, 0) - 1;
|
||||
return new UidRange(start, end);
|
||||
}
|
||||
|
||||
/** Returns the smallest user Id which is contained in this UidRange */
|
||||
public int getStartUser() {
|
||||
return start / PER_USER_RANGE;
|
||||
|
|
|
|||
Loading…
Reference in a new issue