• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.SystemApi;
22 import android.annotation.TestApi;
23 import android.os.Parcel;
24 
25 import java.util.Objects;
26 
27 /**
28  * Class used to identify a default value for the authority of the {@link EnforcingAdmin} setting
29  * a policy, meaning it is not one of the other known subclasses of {@link Authority}, this would be
30  * the case for example for a system component setting the policy.
31  *
32  * @hide
33  */
34 @SystemApi
35 public final class UnknownAuthority extends Authority {
36     private final String mName;
37 
38     /**
39      * Object representing an unknown authority.
40      *
41      * @hide
42      */
43     @TestApi
44     @NonNull
45     public static final UnknownAuthority UNKNOWN_AUTHORITY = new UnknownAuthority();
46 
47     /**
48      * Creates an authority that represents an admin that can set a policy but
49      * doesn't have a known authority (e.g. a system components).
50      */
UnknownAuthority()51     public UnknownAuthority() {
52         mName = null;
53     }
54 
55     /** @hide */
UnknownAuthority(String name)56     public UnknownAuthority(String name) {
57         mName = name;
58     }
59 
UnknownAuthority(Parcel source)60     private UnknownAuthority(Parcel source) {
61         this(source.readString8());
62     }
63 
64     /** @hide */
getName()65     public String getName() {
66         return mName;
67     }
68 
69     @Override
toString()70     public String toString() {
71         return "DefaultAuthority {" + mName + "}";
72     }
73 
74     @Override
equals(@ullable Object o)75     public boolean equals(@Nullable Object o) {
76         if (this == o) return true;
77         if (o == null || getClass() != o.getClass()) return false;
78         UnknownAuthority other = (UnknownAuthority) o;
79         return Objects.equals(mName, other.mName);
80     }
81 
82     @Override
hashCode()83     public int hashCode() {
84         return Objects.hashCode(mName);
85     }
86 
87     @Override
describeContents()88     public int describeContents() {
89         return 0;
90     }
91 
92     @Override
writeToParcel(@onNull Parcel dest, int flags)93     public void writeToParcel(@NonNull Parcel dest, int flags) {
94         dest.writeString8(mName);
95     }
96 
97     @NonNull
98     public static final Creator<UnknownAuthority> CREATOR =
99             new Creator<UnknownAuthority>() {
100                 @Override
101                 public UnknownAuthority createFromParcel(Parcel source) {
102                     return new UnknownAuthority(source);
103                 }
104 
105                 @Override
106                 public UnknownAuthority[] newArray(int size) {
107                     return new UnknownAuthority[size];
108                 }
109             };
110 }
111