2 * Copyright (C) 2014 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 import static android.os.UserHandle.PER_USER_RANGE;
21 import android.os.Parcel;
22 import android.os.Parcelable;
24 import java.lang.IllegalArgumentException;
27 * An inclusive range of UIDs.
31 public final class UidRange implements Parcelable {
32 public final int start;
33 public final int stop;
35 public UidRange(int startUid, int stopUid) {
36 if (startUid < 0) throw new IllegalArgumentException("Invalid start UID.");
37 if (stopUid < 0) throw new IllegalArgumentException("Invalid stop UID.");
38 if (startUid > stopUid) throw new IllegalArgumentException("Invalid UID range.");
43 public static UidRange createForUser(int userId) {
44 return new UidRange(userId * PER_USER_RANGE, (userId + 1) * PER_USER_RANGE - 1);
47 public int getStartUser() {
48 return start / PER_USER_RANGE;
52 public int hashCode() {
54 result = 31 * result + start;
55 result = 31 * result + stop;
60 public boolean equals(Object o) {
64 if (o instanceof UidRange) {
65 UidRange other = (UidRange) o;
66 return start == other.start && stop == other.stop;
72 public String toString() {
73 return start + "-" + stop;
76 // implement the Parcelable interface
78 public int describeContents() {
83 public void writeToParcel(Parcel dest, int flags) {
88 public static final Creator<UidRange> CREATOR =
89 new Creator<UidRange>() {
91 public UidRange createFromParcel(Parcel in) {
92 int start = in.readInt();
93 int stop = in.readInt();
95 return new UidRange(start, stop);
98 public UidRange[] newArray(int size) {
99 return new UidRange[size];