1 /*
2  * Copyright (C) 2019 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;
18 
19 import android.annotation.IntRange;
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.annotation.SystemApi;
23 import android.annotation.TestApi;
24 import android.os.Parcel;
25 import android.os.Parcelable;
26 
27 import com.android.internal.annotations.Immutable;
28 import com.android.internal.util.DataClass;
29 
30 /**
31  * Message for noted runtime permission access.
32  * @hide
33  */
34 @Immutable
35 @TestApi
36 @SystemApi
37 /*@DataClass(genConstructor = false)
38 @DataClass.Suppress("getOpCode")*/
39 public final class RuntimeAppOpAccessMessage implements Parcelable {
40     /** Uid of package for which runtime app op access message was collected */
41     private final @IntRange(from = 0L) int mUid;
42     /** Op code of operation access which was collected */
43     private final @IntRange(from = 0L, to = AppOpsManager._NUM_OP - 1) int mOpCode;
44     /** Name of package for which runtime app op access message was collected */
45     private final @NonNull String mPackageName;
46     /** Feature of package for which runtime app op access message was collected */
47     private final @Nullable String mAttributionTag;
48     /** Message collected (including stacktrace for synchronous ops) */
49     private final @NonNull String mMessage;
50     /** Sampling strategy used to collect this message. */
51     private final @AppOpsManager.SamplingStrategy int mSamplingStrategy;
52 
getOp()53     public @NonNull String getOp() {
54         return AppOpsManager.opToPublicName(mOpCode);
55     }
56 
57     /**
58      * Creates a new RuntimeAppOpAccessMessage.
59      *
60      * @param uid
61      *   Uid of package for which runtime app op access message was collected
62      * @param opCode
63      *   Op code of operation access which was collected
64      * @param packageName
65      *   Name of package for which runtime app op access message was collected
66      * @param attributionTag
67      *   Attribution tag for which runtime app op access message was collected
68      * @param message
69      *   Message collected (including stacktrace for synchronous ops)
70      * @param samplingStrategy
71      *   Sampling strategy used to collect this message.
72      */
73     @DataClass.Generated.Member
RuntimeAppOpAccessMessage( @ntRangefrom = 0L) int uid, @IntRange(from = 0L) int opCode, @NonNull String packageName, @Nullable String attributionTag, @NonNull String message, @AppOpsManager.SamplingStrategy int samplingStrategy)74     public RuntimeAppOpAccessMessage(
75             @IntRange(from = 0L) int uid,
76             @IntRange(from = 0L) int opCode,
77             @NonNull String packageName,
78             @Nullable String attributionTag,
79             @NonNull String message,
80             @AppOpsManager.SamplingStrategy int samplingStrategy) {
81         this.mUid = uid;
82         com.android.internal.util.AnnotationValidations.validate(
83                 IntRange.class, null, mUid,
84                 "from", 0L);
85         this.mOpCode = opCode;
86         com.android.internal.util.AnnotationValidations.validate(
87                 IntRange.class, null, mOpCode,
88                 "from", 0L,
89                 "to", AppOpsManager._NUM_OP - 1);
90         this.mPackageName = packageName;
91         com.android.internal.util.AnnotationValidations.validate(
92                 NonNull.class, null, mPackageName);
93         this.mAttributionTag = attributionTag;
94         this.mMessage = message;
95         com.android.internal.util.AnnotationValidations.validate(
96                 NonNull.class, null, mMessage);
97         this.mSamplingStrategy = samplingStrategy;
98         com.android.internal.util.AnnotationValidations.validate(
99                 AppOpsManager.SamplingStrategy.class, null, mSamplingStrategy);
100 
101         // onConstructed(); // You can define this method to get a callback
102     }
103 
104 
105 
106 
107     // Code below generated by codegen v1.0.14.
108     //
109     // DO NOT MODIFY!
110     // CHECKSTYLE:OFF Generated code
111     //
112     // To regenerate run:
113     // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/app/RuntimeAppOpAccessMessage.java
114     //
115     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
116     //   Settings > Editor > Code Style > Formatter Control
117     //@formatter:off
118 
119 
120     /**
121      * Uid of package for which runtime app op access message was collected
122      */
123     @DataClass.Generated.Member
getUid()124     public @IntRange(from = 0L) int getUid() {
125         return mUid;
126     }
127 
128     /**
129      * Name of package for which runtime app op access message was collected
130      */
131     @DataClass.Generated.Member
getPackageName()132     public @NonNull String getPackageName() {
133         return mPackageName;
134     }
135 
136     /**
137      * Attribution tag for which runtime app op access message was collected
138      */
139     @DataClass.Generated.Member
getAttributionTag()140     public @Nullable String getAttributionTag() {
141         return mAttributionTag;
142     }
143 
144     /**
145      * Message collected (including stacktrace for synchronous ops)
146      */
147     @DataClass.Generated.Member
getMessage()148     public @NonNull String getMessage() {
149         return mMessage;
150     }
151 
152     /**
153      * Sampling strategy used to collect this message.
154      */
155     @DataClass.Generated.Member
getSamplingStrategy()156     public @AppOpsManager.SamplingStrategy int getSamplingStrategy() {
157         return mSamplingStrategy;
158     }
159 
160     @Override
161     @DataClass.Generated.Member
writeToParcel(@onNull Parcel dest, int flags)162     public void writeToParcel(@NonNull Parcel dest, int flags) {
163         // You can override field parcelling by defining methods like:
164         // void parcelFieldName(Parcel dest, int flags) { ... }
165 
166         byte flg = 0;
167         if (mAttributionTag != null) flg |= 0x8;
168         dest.writeByte(flg);
169         dest.writeInt(mUid);
170         dest.writeInt(mOpCode);
171         dest.writeString(mPackageName);
172         if (mAttributionTag != null) dest.writeString(mAttributionTag);
173         dest.writeString(mMessage);
174         dest.writeInt(mSamplingStrategy);
175     }
176 
177     @Override
178     @DataClass.Generated.Member
describeContents()179     public int describeContents() { return 0; }
180 
181     /** @hide */
182     @SuppressWarnings({"unchecked", "RedundantCast"})
183     @DataClass.Generated.Member
RuntimeAppOpAccessMessage(@onNull Parcel in)184     /* package-private */ RuntimeAppOpAccessMessage(@NonNull Parcel in) {
185         // You can override field unparcelling by defining methods like:
186         // static FieldType unparcelFieldName(Parcel in) { ... }
187 
188         byte flg = in.readByte();
189         int uid = in.readInt();
190         int opCode = in.readInt();
191         String packageName = in.readString();
192         String attributionTag = (flg & 0x8) == 0 ? null : in.readString();
193         String message = in.readString();
194         int samplingStrategy = in.readInt();
195 
196         this.mUid = uid;
197         com.android.internal.util.AnnotationValidations.validate(
198                 IntRange.class, null, mUid,
199                 "from", 0L);
200         this.mOpCode = opCode;
201         com.android.internal.util.AnnotationValidations.validate(
202                 IntRange.class, null, mOpCode,
203                 "from", 0L,
204                 "to", AppOpsManager._NUM_OP - 1);
205         this.mPackageName = packageName;
206         com.android.internal.util.AnnotationValidations.validate(
207                 NonNull.class, null, mPackageName);
208         this.mAttributionTag = attributionTag;
209         this.mMessage = message;
210         com.android.internal.util.AnnotationValidations.validate(
211                 NonNull.class, null, mMessage);
212         this.mSamplingStrategy = samplingStrategy;
213         com.android.internal.util.AnnotationValidations.validate(
214                 AppOpsManager.SamplingStrategy.class, null, mSamplingStrategy);
215 
216         // onConstructed(); // You can define this method to get a callback
217     }
218 
219     @DataClass.Generated.Member
220     public static final @NonNull Parcelable.Creator<RuntimeAppOpAccessMessage> CREATOR
221             = new Parcelable.Creator<RuntimeAppOpAccessMessage>() {
222         @Override
223         public RuntimeAppOpAccessMessage[] newArray(int size) {
224             return new RuntimeAppOpAccessMessage[size];
225         }
226 
227         @Override
228         public RuntimeAppOpAccessMessage createFromParcel(@NonNull Parcel in) {
229             return new RuntimeAppOpAccessMessage(in);
230         }
231     };
232 
233     /*@DataClass.Generated(
234             time = 1581517099127L,
235             codegenVersion = "1.0.14",
236             sourceFile = "frameworks/base/core/java/android/app/RuntimeAppOpAccessMessage.java",
237             inputSignatures = "private final @android.annotation.IntRange(from=0L) int mUid\nprivate final @android.annotation.IntRange(from=0L, to=AppOpsManager._NUM_OP - 1) int mOpCode\nprivate final @android.annotation.NonNull java.lang.String mPackageName\nprivate final @android.annotation.Nullable java.lang.String mAttributionTag\nprivate final @android.annotation.NonNull java.lang.String mMessage\nprivate final @android.app.AppOpsManager.SamplingStrategy int mSamplingStrategy\npublic @android.annotation.NonNull java.lang.String getOp()\nclass RuntimeAppOpAccessMessage extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genConstructor=false)")*/
238     @Deprecated
__metadata()239     private void __metadata() {}
240 
241 
242     //@formatter:on
243     // End of generated code
244 
245 }
246