| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package android.app.admin; |
| 17 |
|
| 18 |
import static android.app.admin.DevicePolicyManager.isValidOperationSafetyReason; |
| 19 |
|
| 20 |
import android.annotation.NonNull; |
| 21 |
import android.annotation.TestApi; |
| 22 |
import android.app.admin.DevicePolicyManager.DevicePolicyOperation; |
| 23 |
import android.app.admin.DevicePolicyManager.OperationSafetyReason; |
| 24 |
import android.os.Parcel; |
| 25 |
import android.os.Parcelable; |
| 26 |
|
| 27 |
import com.android.internal.util.Preconditions; |
| 28 |
|
| 29 |
import java.util.Arrays; |
| 30 |
import java.util.List; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
@SuppressWarnings("serial") |
| 41 |
public final class UnsafeStateException extends IllegalStateException implements Parcelable { |
| 42 |
|
| 43 |
private final @DevicePolicyOperation int mOperation; |
| 44 |
private final @OperationSafetyReason int mReason; |
| 45 |
|
| 46 |
|
| 47 |
@TestApi |
| 48 |
public UnsafeStateException(@DevicePolicyOperation int operation, |
| 49 |
@OperationSafetyReason int reason) { |
| 50 |
super(); |
| 51 |
Preconditions.checkArgument(isValidOperationSafetyReason(reason), "invalid reason %d", |
| 52 |
reason); |
| 53 |
mOperation = operation; |
| 54 |
mReason = reason; |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
@TestApi |
| 59 |
public @DevicePolicyOperation int getOperation() { |
| 60 |
return mOperation; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
@NonNull |
| 70 |
public List<Integer> getReasons() { |
| 71 |
return Arrays.asList(mReason); |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
@Override |
| 76 |
public String getMessage() { |
| 77 |
return DevicePolicyManager.operationSafetyReasonToString(mReason); |
| 78 |
} |
| 79 |
|
| 80 |
@Override |
| 81 |
public int describeContents() { |
| 82 |
return 0; |
| 83 |
} |
| 84 |
|
| 85 |
@Override |
| 86 |
public void writeToParcel(@NonNull Parcel dest, int flags) { |
| 87 |
dest.writeInt(mOperation); |
| 88 |
dest.writeInt(mReason); |
| 89 |
} |
| 90 |
|
| 91 |
@NonNull |
| 92 |
public static final Creator<UnsafeStateException> CREATOR = |
| 93 |
new Creator<UnsafeStateException>() { |
| 94 |
|
| 95 |
@Override |
| 96 |
public UnsafeStateException createFromParcel(Parcel source) { |
| 97 |
return new UnsafeStateException(source.readInt(), source.readInt()); |
| 98 |
} |
| 99 |
|
| 100 |
@Override |
| 101 |
public UnsafeStateException[] newArray(int size) { |
| 102 |
return new UnsafeStateException[size]; |
| 103 |
} |
| 104 |
}; |
| 105 |
} |