1 /* 2 * Copyright (C) 2023 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.app.admin; 18 19 import static android.app.admin.PolicyUpdateReceiver.EXTRA_POLICY_KEY; 20 21 import android.annotation.NonNull; 22 import android.annotation.SystemApi; 23 import android.annotation.TestApi; 24 import android.os.Bundle; 25 import android.os.Parcel; 26 27 import java.util.Objects; 28 29 /** 30 * Class used to identify a policy that relates to a certain user restriction 31 * (See {@link DevicePolicyManager#addUserRestriction} and 32 * {@link DevicePolicyManager#addUserRestrictionGlobally}). 33 * 34 * @hide 35 */ 36 @SystemApi 37 public final class UserRestrictionPolicyKey extends PolicyKey { 38 39 private final String mRestriction; 40 41 /** 42 * @hide 43 */ 44 @TestApi UserRestrictionPolicyKey(@onNull String identifier, @NonNull String restriction)45 public UserRestrictionPolicyKey(@NonNull String identifier, @NonNull String restriction) { 46 super(identifier); 47 mRestriction = Objects.requireNonNull(restriction); 48 } 49 UserRestrictionPolicyKey(Parcel source)50 private UserRestrictionPolicyKey(Parcel source) { 51 this(source.readString(), source.readString()); 52 } 53 54 /** 55 * Returns the user restriction associated with this policy. 56 */ 57 @NonNull getRestriction()58 public String getRestriction() { 59 return mRestriction; 60 } 61 62 /** 63 * @hide 64 */ 65 @Override writeToBundle(Bundle bundle)66 public void writeToBundle(Bundle bundle) { 67 bundle.putString(EXTRA_POLICY_KEY, getIdentifier()); 68 } 69 70 @Override describeContents()71 public int describeContents() { 72 return 0; 73 } 74 75 @Override writeToParcel(@onNull Parcel dest, int flags)76 public void writeToParcel(@NonNull Parcel dest, int flags) { 77 dest.writeString(getIdentifier()); 78 dest.writeString(mRestriction); 79 } 80 81 @NonNull 82 public static final Creator<UserRestrictionPolicyKey> CREATOR = 83 new Creator<UserRestrictionPolicyKey>() { 84 @Override 85 public UserRestrictionPolicyKey createFromParcel(Parcel source) { 86 return new UserRestrictionPolicyKey(source); 87 } 88 89 @Override 90 public UserRestrictionPolicyKey[] newArray(int size) { 91 return new UserRestrictionPolicyKey[size]; 92 } 93 }; 94 95 @Override toString()96 public String toString() { 97 return "UserRestrictionPolicyKey " + getIdentifier(); 98 } 99 } 100