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.os.Bundle;
24 import android.os.Parcel;
25 import android.os.Parcelable;
26 
27 /**
28  * Default implementation for {@link PolicyKey} used to identify a policy that doesn't require any
29  * additional arguments to be represented.
30  *
31  * @hide
32  */
33 @SystemApi
34 public final class NoArgsPolicyKey extends PolicyKey {
35 
36     /**
37      * @hide
38      */
NoArgsPolicyKey(@onNull String identifier)39     public NoArgsPolicyKey(@NonNull String identifier) {
40         super(identifier);
41     }
42 
NoArgsPolicyKey(Parcel source)43     private NoArgsPolicyKey(Parcel source) {
44         this(source.readString());
45     }
46 
47     /**
48      * @hide
49      */
50     @Override
writeToBundle(Bundle bundle)51     public void writeToBundle(Bundle bundle) {
52         bundle.putString(EXTRA_POLICY_KEY, getIdentifier());
53     }
54 
55     @Override
describeContents()56     public int describeContents() {
57         return 0;
58     }
59 
60     @Override
writeToParcel(@onNull Parcel dest, int flags)61     public void writeToParcel(@NonNull Parcel dest, int flags) {
62         dest.writeString(getIdentifier());
63     }
64 
65     @NonNull
66     public static final Parcelable.Creator<NoArgsPolicyKey> CREATOR =
67             new Parcelable.Creator<NoArgsPolicyKey>() {
68                 @Override
69                 public NoArgsPolicyKey createFromParcel(Parcel source) {
70                     return new NoArgsPolicyKey(source);
71                 }
72 
73                 @Override
74                 public NoArgsPolicyKey[] newArray(int size) {
75                     return new NoArgsPolicyKey[size];
76                 }
77             };
78 
79     @Override
toString()80     public String toString() {
81         return "DefaultPolicyKey " + getIdentifier();
82     }
83 }
84