1 /*
2  * Copyright (C) 2022 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.permission;
18 
19 import android.annotation.CurrentTimeMillisLong;
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.annotation.SystemApi;
23 import android.os.Parcelable;
24 
25 import com.android.internal.util.DataClass;
26 
27 /**
28  * Represents the usage of a permission group by an app. Supports package name, user, permission
29  * group, whether or not the access is running or recent, whether the access is tied to a phone
30  * call, and an optional special attribution tag, label and proxy label.
31  *
32  * @hide
33  */
34 @SystemApi
35 @DataClass(
36         genHiddenConstructor = true,
37         genEqualsHashCode = true,
38         genToString = true
39 )
40 public final class PermissionGroupUsage implements Parcelable {
41 
42     private final @NonNull String mPackageName;
43     private final int mUid;
44     private final long mLastAccessTimeMillis;
45     private final @NonNull String mPermissionGroupName;
46     private final boolean mActive;
47     private final boolean mPhoneCall;
48     private final @Nullable CharSequence mAttributionTag;
49     private final @Nullable CharSequence mAttributionLabel;
50     private final @Nullable CharSequence mProxyLabel;
51 
52 
53 
54     // Code below generated by codegen v1.0.23.
55     //
56     // DO NOT MODIFY!
57     // CHECKSTYLE:OFF Generated code
58     //
59     // To regenerate run:
60     // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/permission/PermissionGroupUsage.java
61     //
62     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
63     //   Settings > Editor > Code Style > Formatter Control
64     //@formatter:off
65 
66 
67     /**
68      * Creates a new PermissionGroupUsage.
69      *
70      * @hide
71      */
72     @DataClass.Generated.Member
PermissionGroupUsage( @onNull String packageName, int uid, long lastAccessTimeMillis, @NonNull String permissionGroupName, boolean active, boolean phoneCall, @Nullable CharSequence attributionTag, @Nullable CharSequence attributionLabel, @Nullable CharSequence proxyLabel)73     public PermissionGroupUsage(
74             @NonNull String packageName,
75             int uid,
76             long lastAccessTimeMillis,
77             @NonNull String permissionGroupName,
78             boolean active,
79             boolean phoneCall,
80             @Nullable CharSequence attributionTag,
81             @Nullable CharSequence attributionLabel,
82             @Nullable CharSequence proxyLabel) {
83         this.mPackageName = packageName;
84         com.android.internal.util.AnnotationValidations.validate(
85                 NonNull.class, null, mPackageName);
86         this.mUid = uid;
87         this.mLastAccessTimeMillis = lastAccessTimeMillis;
88         this.mPermissionGroupName = permissionGroupName;
89         com.android.internal.util.AnnotationValidations.validate(
90                 NonNull.class, null, mPermissionGroupName);
91         this.mActive = active;
92         this.mPhoneCall = phoneCall;
93         this.mAttributionTag = attributionTag;
94         this.mAttributionLabel = attributionLabel;
95         this.mProxyLabel = proxyLabel;
96 
97         // onConstructed(); // You can define this method to get a callback
98     }
99 
100     /**
101      * @return Package name for the usage
102      */
103     @DataClass.Generated.Member
getPackageName()104     public @NonNull String getPackageName() {
105         return mPackageName;
106     }
107 
108     /**
109      * @return UID for the usage
110      */
111     @DataClass.Generated.Member
getUid()112     public int getUid() {
113         return mUid;
114     }
115 
116     /**
117      * @return Last access time in millis for the usage
118      */
119     @CurrentTimeMillisLong
120     @DataClass.Generated.Member
getLastAccessTimeMillis()121     public long getLastAccessTimeMillis() {
122         return mLastAccessTimeMillis;
123     }
124 
125     /**
126      * @return Permission group name for the usage
127      */
128     @DataClass.Generated.Member
getPermissionGroupName()129     public @NonNull String getPermissionGroupName() {
130         return mPermissionGroupName;
131     }
132 
133     /**
134      * @return If usage is active
135      */
136     @DataClass.Generated.Member
isActive()137     public boolean isActive() {
138         return mActive;
139     }
140 
141     /**
142      * @return If usage is a phone call
143      */
144     @DataClass.Generated.Member
isPhoneCall()145     public boolean isPhoneCall() {
146         return mPhoneCall;
147     }
148 
149     /**
150      * @return Attribution tag associated with the usage
151      */
152     @DataClass.Generated.Member
getAttributionTag()153     public @Nullable CharSequence getAttributionTag() {
154         return mAttributionTag;
155     }
156 
157     /**
158      * @return Attribution label associated with the usage
159      */
160     @DataClass.Generated.Member
getAttributionLabel()161     public @Nullable CharSequence getAttributionLabel() {
162         return mAttributionLabel;
163     }
164 
165     /**
166      * @return Proxy label associated with the usage
167      */
168     @DataClass.Generated.Member
getProxyLabel()169     public @Nullable CharSequence getProxyLabel() {
170         return mProxyLabel;
171     }
172 
173     @Override
174     @DataClass.Generated.Member
toString()175     public String toString() {
176         // You can override field toString logic by defining methods like:
177         // String fieldNameToString() { ... }
178 
179         return "PermissionGroupUsage { " +
180                 "packageName = " + mPackageName + ", " +
181                 "uid = " + mUid + ", " +
182                 "lastAccessTimeMillis = " + mLastAccessTimeMillis + ", " +
183                 "permissionGroupName = " + mPermissionGroupName + ", " +
184                 "active = " + mActive + ", " +
185                 "phoneCall = " + mPhoneCall + ", " +
186                 "attributionTag = " + mAttributionTag + ", " +
187                 "attributionLabel = " + mAttributionLabel + ", " +
188                 "proxyLabel = " + mProxyLabel +
189         " }";
190     }
191 
192     @Override
193     @DataClass.Generated.Member
equals(@ullable Object o)194     public boolean equals(@Nullable Object o) {
195         // You can override field equality logic by defining either of the methods like:
196         // boolean fieldNameEquals(PermissionGroupUsage other) { ... }
197         // boolean fieldNameEquals(FieldType otherValue) { ... }
198 
199         if (this == o) return true;
200         if (o == null || getClass() != o.getClass()) return false;
201         @SuppressWarnings("unchecked")
202         PermissionGroupUsage that = (PermissionGroupUsage) o;
203         //noinspection PointlessBooleanExpression
204         return true
205                 && java.util.Objects.equals(mPackageName, that.mPackageName)
206                 && mUid == that.mUid
207                 && mLastAccessTimeMillis == that.mLastAccessTimeMillis
208                 && java.util.Objects.equals(mPermissionGroupName, that.mPermissionGroupName)
209                 && mActive == that.mActive
210                 && mPhoneCall == that.mPhoneCall
211                 && java.util.Objects.equals(mAttributionTag, that.mAttributionTag)
212                 && java.util.Objects.equals(mAttributionLabel, that.mAttributionLabel)
213                 && java.util.Objects.equals(mProxyLabel, that.mProxyLabel);
214     }
215 
216     @Override
217     @DataClass.Generated.Member
hashCode()218     public int hashCode() {
219         // You can override field hashCode logic by defining methods like:
220         // int fieldNameHashCode() { ... }
221 
222         int _hash = 1;
223         _hash = 31 * _hash + java.util.Objects.hashCode(mPackageName);
224         _hash = 31 * _hash + mUid;
225         _hash = 31 * _hash + Long.hashCode(mLastAccessTimeMillis);
226         _hash = 31 * _hash + java.util.Objects.hashCode(mPermissionGroupName);
227         _hash = 31 * _hash + Boolean.hashCode(mActive);
228         _hash = 31 * _hash + Boolean.hashCode(mPhoneCall);
229         _hash = 31 * _hash + java.util.Objects.hashCode(mAttributionTag);
230         _hash = 31 * _hash + java.util.Objects.hashCode(mAttributionLabel);
231         _hash = 31 * _hash + java.util.Objects.hashCode(mProxyLabel);
232         return _hash;
233     }
234 
235     @Override
236     @DataClass.Generated.Member
writeToParcel(@onNull android.os.Parcel dest, int flags)237     public void writeToParcel(@NonNull android.os.Parcel dest, int flags) {
238         // You can override field parcelling by defining methods like:
239         // void parcelFieldName(Parcel dest, int flags) { ... }
240 
241         int flg = 0;
242         if (mActive) flg |= 0x10;
243         if (mPhoneCall) flg |= 0x20;
244         if (mAttributionTag != null) flg |= 0x40;
245         if (mAttributionLabel != null) flg |= 0x80;
246         if (mProxyLabel != null) flg |= 0x100;
247         dest.writeInt(flg);
248         dest.writeString(mPackageName);
249         dest.writeInt(mUid);
250         dest.writeLong(mLastAccessTimeMillis);
251         dest.writeString(mPermissionGroupName);
252         if (mAttributionTag != null) dest.writeCharSequence(mAttributionTag);
253         if (mAttributionLabel != null) dest.writeCharSequence(mAttributionLabel);
254         if (mProxyLabel != null) dest.writeCharSequence(mProxyLabel);
255     }
256 
257     @Override
258     @DataClass.Generated.Member
describeContents()259     public int describeContents() { return 0; }
260 
261     /** @hide */
262     @SuppressWarnings({"unchecked", "RedundantCast"})
263     @DataClass.Generated.Member
PermissionGroupUsage(@onNull android.os.Parcel in)264     /* package-private */ PermissionGroupUsage(@NonNull android.os.Parcel in) {
265         // You can override field unparcelling by defining methods like:
266         // static FieldType unparcelFieldName(Parcel in) { ... }
267 
268         int flg = in.readInt();
269         boolean active = (flg & 0x10) != 0;
270         boolean phoneCall = (flg & 0x20) != 0;
271         String packageName = in.readString();
272         int uid = in.readInt();
273         long lastAccessTimeMillis = in.readLong();
274         String permissionGroupName = in.readString();
275         CharSequence attributionTag = (flg & 0x40) == 0 ? null : (CharSequence) in.readCharSequence();
276         CharSequence attributionLabel = (flg & 0x80) == 0 ? null : (CharSequence) in.readCharSequence();
277         CharSequence proxyLabel = (flg & 0x100) == 0 ? null : (CharSequence) in.readCharSequence();
278 
279         this.mPackageName = packageName;
280         com.android.internal.util.AnnotationValidations.validate(
281                 NonNull.class, null, mPackageName);
282         this.mUid = uid;
283         this.mLastAccessTimeMillis = lastAccessTimeMillis;
284         this.mPermissionGroupName = permissionGroupName;
285         com.android.internal.util.AnnotationValidations.validate(
286                 NonNull.class, null, mPermissionGroupName);
287         this.mActive = active;
288         this.mPhoneCall = phoneCall;
289         this.mAttributionTag = attributionTag;
290         this.mAttributionLabel = attributionLabel;
291         this.mProxyLabel = proxyLabel;
292 
293         // onConstructed(); // You can define this method to get a callback
294     }
295 
296     @DataClass.Generated.Member
297     public static final @NonNull Parcelable.Creator<PermissionGroupUsage> CREATOR
298             = new Parcelable.Creator<PermissionGroupUsage>() {
299         @Override
300         public PermissionGroupUsage[] newArray(int size) {
301             return new PermissionGroupUsage[size];
302         }
303 
304         @Override
305         public PermissionGroupUsage createFromParcel(@NonNull android.os.Parcel in) {
306             return new PermissionGroupUsage(in);
307         }
308     };
309 
310     @DataClass.Generated(
311             time = 1645067417023L,
312             codegenVersion = "1.0.23",
313             sourceFile = "frameworks/base/core/java/android/permission/PermissionGroupUsage.java",
314             inputSignatures = "private final @android.annotation.NonNull java.lang.String mPackageName\nprivate final  int mUid\nprivate final  long mLastAccessTimeMillis\nprivate final @android.annotation.NonNull java.lang.String mPermissionGroupName\nprivate final  boolean mActive\nprivate final  boolean mPhoneCall\nprivate final @android.annotation.Nullable java.lang.CharSequence mAttributionTag\nprivate final @android.annotation.Nullable java.lang.CharSequence mAttributionLabel\nprivate final @android.annotation.Nullable java.lang.CharSequence mProxyLabel\nclass PermissionGroupUsage extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genHiddenConstructor=true, genEqualsHashCode=true, genToString=true)")
315     @Deprecated
__metadata()316     private void __metadata() {}
317 
318 
319     //@formatter:on
320     // End of generated code
321 
322 }
323