blob: b0c2762c3439549eb3b038b57edb8f6fee690a50 [file] [log] [blame]
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -07001/*
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
17package android.app;
18
Philip P. Moltmann5892a8f2020-03-03 12:05:55 -080019import android.annotation.CurrentTimeMillisLong;
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -070020import android.annotation.IntRange;
21import android.annotation.NonNull;
22import android.annotation.Nullable;
23import android.os.Parcelable;
24
25import com.android.internal.annotations.Immutable;
26import com.android.internal.util.DataClass;
Eugene Susla5fc2d762020-03-04 13:53:10 -080027import com.android.internal.util.Preconditions;
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -070028
29/**
Philip P. Moltmann59076d82019-08-19 15:00:40 -070030 * When an {@link AppOpsManager#noteOp(String, int, String, String, String) app-op is noted} and the
Philip P. Moltmann5892a8f2020-03-03 12:05:55 -080031 * app the app-op is noted for has a {@link AppOpsManager.OnOpNotedCallback} registered the
32 * note-event needs to be delivered to the callback. Usually this is done via an
33 * {@link SyncNotedAppOp}, but in some cases this is not possible. In this case an
34 * {@link AsyncNotedAppOp} is send to the system server and then forwarded to the
35 * {@link AppOpsManager.OnOpNotedCallback} in the app.
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -070036 */
37@Immutable
38@DataClass(genEqualsHashCode = true,
39 genAidl = true,
40 genHiddenConstructor = true)
41// - We don't expose the opCode, but rather the public name of the op, hence use a non-standard
42// getter
43@DataClass.Suppress({"getOpCode"})
44public final class AsyncNotedAppOp implements Parcelable {
45 /** Op that was noted */
Eugene Susla5fc2d762020-03-04 13:53:10 -080046 private final @IntRange(from = 0) int mOpCode;
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -070047
48 /** Uid that noted the op */
49 private final @IntRange(from = 0) int mNotingUid;
50
Philip P. Moltmann12ac3f42020-03-05 15:01:29 -080051 /** {@link android.content.Context#createAttributionContext attribution tag} */
52 private final @Nullable String mAttributionTag;
Philip P. Moltmann59076d82019-08-19 15:00:40 -070053
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -070054 /** Message associated with the noteOp. This message is set by the app noting the op */
55 private final @NonNull String mMessage;
56
57 /** Milliseconds since epoch when the op was noted */
Philip P. Moltmann5892a8f2020-03-03 12:05:55 -080058 private final @CurrentTimeMillisLong long mTime;
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -070059
60 /**
61 * @return Op that was noted.
62 */
63 public @NonNull String getOp() {
64 return AppOpsManager.opToPublicName(mOpCode);
65 }
66
Eugene Susla5fc2d762020-03-04 13:53:10 -080067 //TODO eugenesusla: support inlinable expressions in annotation params of @DataClass members to
68 // allow validating via @IntRange(from = 0, to = AppOpsManager._NUM_OP - 1)
69 private void onConstructed() {
70 Preconditions.checkArgumentInRange(mOpCode, 0, AppOpsManager._NUM_OP - 1, "opCode");
71 }
72
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -070073
74
Philip P. Moltmann5892a8f2020-03-03 12:05:55 -080075 // Code below generated by codegen v1.0.15.
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -070076 //
77 // DO NOT MODIFY!
Eugene Susla1bfb5e72019-10-16 10:12:47 -070078 // CHECKSTYLE:OFF Generated code
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -070079 //
80 // To regenerate run:
81 // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/app/AsyncNotedAppOp.java
82 //
Eugene Susla1bfb5e72019-10-16 10:12:47 -070083 // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
84 // Settings > Editor > Code Style > Formatter Control
85 //@formatter:off
86
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -070087
88 /**
89 * Creates a new AsyncNotedAppOp.
90 *
91 * @param opCode
92 * Op that was noted
93 * @param notingUid
94 * Uid that noted the op
Philip P. Moltmann12ac3f42020-03-05 15:01:29 -080095 * @param attributionTag
96 * {@link android.content.Context#createAttributionContext attribution tag}
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -070097 * @param message
98 * Message associated with the noteOp. This message is set by the app noting the op
99 * @param time
100 * Milliseconds since epoch when the op was noted
101 * @hide
102 */
103 @DataClass.Generated.Member
104 public AsyncNotedAppOp(
Eugene Susla5fc2d762020-03-04 13:53:10 -0800105 @IntRange(from = 0) int opCode,
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -0700106 @IntRange(from = 0) int notingUid,
Philip P. Moltmann12ac3f42020-03-05 15:01:29 -0800107 @Nullable String attributionTag,
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -0700108 @NonNull String message,
Philip P. Moltmann5892a8f2020-03-03 12:05:55 -0800109 @CurrentTimeMillisLong long time) {
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -0700110 this.mOpCode = opCode;
111 com.android.internal.util.AnnotationValidations.validate(
112 IntRange.class, null, mOpCode,
Eugene Susla5fc2d762020-03-04 13:53:10 -0800113 "from", 0);
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -0700114 this.mNotingUid = notingUid;
115 com.android.internal.util.AnnotationValidations.validate(
116 IntRange.class, null, mNotingUid,
117 "from", 0);
Philip P. Moltmann12ac3f42020-03-05 15:01:29 -0800118 this.mAttributionTag = attributionTag;
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -0700119 this.mMessage = message;
120 com.android.internal.util.AnnotationValidations.validate(
121 NonNull.class, null, mMessage);
122 this.mTime = time;
123 com.android.internal.util.AnnotationValidations.validate(
Philip P. Moltmann5892a8f2020-03-03 12:05:55 -0800124 CurrentTimeMillisLong.class, null, mTime);
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -0700125
Eugene Susla5fc2d762020-03-04 13:53:10 -0800126 onConstructed();
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -0700127 }
128
129 /**
130 * Uid that noted the op
131 */
132 @DataClass.Generated.Member
133 public @IntRange(from = 0) int getNotingUid() {
134 return mNotingUid;
135 }
136
137 /**
Philip P. Moltmann12ac3f42020-03-05 15:01:29 -0800138 * {@link android.content.Context#createAttributionContext attribution tag}
Philip P. Moltmann59076d82019-08-19 15:00:40 -0700139 */
140 @DataClass.Generated.Member
Philip P. Moltmann12ac3f42020-03-05 15:01:29 -0800141 public @Nullable String getAttributionTag() {
142 return mAttributionTag;
Philip P. Moltmann59076d82019-08-19 15:00:40 -0700143 }
144
145 /**
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -0700146 * Message associated with the noteOp. This message is set by the app noting the op
147 */
148 @DataClass.Generated.Member
149 public @NonNull String getMessage() {
150 return mMessage;
151 }
152
153 /**
154 * Milliseconds since epoch when the op was noted
155 */
156 @DataClass.Generated.Member
Philip P. Moltmann5892a8f2020-03-03 12:05:55 -0800157 public @CurrentTimeMillisLong long getTime() {
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -0700158 return mTime;
159 }
160
161 @Override
162 @DataClass.Generated.Member
Eugene Susla1bfb5e72019-10-16 10:12:47 -0700163 public boolean equals(@Nullable Object o) {
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -0700164 // You can override field equality logic by defining either of the methods like:
165 // boolean fieldNameEquals(AsyncNotedAppOp other) { ... }
166 // boolean fieldNameEquals(FieldType otherValue) { ... }
167
168 if (this == o) return true;
169 if (o == null || getClass() != o.getClass()) return false;
170 @SuppressWarnings("unchecked")
171 AsyncNotedAppOp that = (AsyncNotedAppOp) o;
172 //noinspection PointlessBooleanExpression
173 return true
174 && mOpCode == that.mOpCode
175 && mNotingUid == that.mNotingUid
Philip P. Moltmann12ac3f42020-03-05 15:01:29 -0800176 && java.util.Objects.equals(mAttributionTag, that.mAttributionTag)
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -0700177 && java.util.Objects.equals(mMessage, that.mMessage)
178 && mTime == that.mTime;
179 }
180
181 @Override
182 @DataClass.Generated.Member
183 public int hashCode() {
184 // You can override field hashCode logic by defining methods like:
185 // int fieldNameHashCode() { ... }
186
187 int _hash = 1;
188 _hash = 31 * _hash + mOpCode;
189 _hash = 31 * _hash + mNotingUid;
Philip P. Moltmann12ac3f42020-03-05 15:01:29 -0800190 _hash = 31 * _hash + java.util.Objects.hashCode(mAttributionTag);
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -0700191 _hash = 31 * _hash + java.util.Objects.hashCode(mMessage);
192 _hash = 31 * _hash + Long.hashCode(mTime);
193 return _hash;
194 }
195
196 @Override
197 @DataClass.Generated.Member
Eugene Susla1bfb5e72019-10-16 10:12:47 -0700198 public void writeToParcel(@NonNull android.os.Parcel dest, int flags) {
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -0700199 // You can override field parcelling by defining methods like:
200 // void parcelFieldName(Parcel dest, int flags) { ... }
201
202 byte flg = 0;
Philip P. Moltmann12ac3f42020-03-05 15:01:29 -0800203 if (mAttributionTag != null) flg |= 0x4;
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -0700204 dest.writeByte(flg);
205 dest.writeInt(mOpCode);
206 dest.writeInt(mNotingUid);
Philip P. Moltmann12ac3f42020-03-05 15:01:29 -0800207 if (mAttributionTag != null) dest.writeString(mAttributionTag);
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -0700208 dest.writeString(mMessage);
209 dest.writeLong(mTime);
210 }
211
212 @Override
213 @DataClass.Generated.Member
214 public int describeContents() { return 0; }
215
Eugene Susla1bfb5e72019-10-16 10:12:47 -0700216 /** @hide */
217 @SuppressWarnings({"unchecked", "RedundantCast"})
218 @DataClass.Generated.Member
219 /* package-private */ AsyncNotedAppOp(@NonNull android.os.Parcel in) {
220 // You can override field unparcelling by defining methods like:
221 // static FieldType unparcelFieldName(Parcel in) { ... }
222
223 byte flg = in.readByte();
224 int opCode = in.readInt();
225 int notingUid = in.readInt();
Philip P. Moltmann12ac3f42020-03-05 15:01:29 -0800226 String attributionTag = (flg & 0x4) == 0 ? null : in.readString();
Eugene Susla1bfb5e72019-10-16 10:12:47 -0700227 String message = in.readString();
228 long time = in.readLong();
229
230 this.mOpCode = opCode;
231 com.android.internal.util.AnnotationValidations.validate(
232 IntRange.class, null, mOpCode,
Eugene Susla5fc2d762020-03-04 13:53:10 -0800233 "from", 0);
Eugene Susla1bfb5e72019-10-16 10:12:47 -0700234 this.mNotingUid = notingUid;
235 com.android.internal.util.AnnotationValidations.validate(
236 IntRange.class, null, mNotingUid,
237 "from", 0);
Philip P. Moltmann12ac3f42020-03-05 15:01:29 -0800238 this.mAttributionTag = attributionTag;
Eugene Susla1bfb5e72019-10-16 10:12:47 -0700239 this.mMessage = message;
240 com.android.internal.util.AnnotationValidations.validate(
241 NonNull.class, null, mMessage);
242 this.mTime = time;
243 com.android.internal.util.AnnotationValidations.validate(
Philip P. Moltmann5892a8f2020-03-03 12:05:55 -0800244 CurrentTimeMillisLong.class, null, mTime);
Eugene Susla1bfb5e72019-10-16 10:12:47 -0700245
Eugene Susla5fc2d762020-03-04 13:53:10 -0800246 onConstructed();
Eugene Susla1bfb5e72019-10-16 10:12:47 -0700247 }
248
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -0700249 @DataClass.Generated.Member
250 public static final @NonNull Parcelable.Creator<AsyncNotedAppOp> CREATOR
251 = new Parcelable.Creator<AsyncNotedAppOp>() {
252 @Override
253 public AsyncNotedAppOp[] newArray(int size) {
254 return new AsyncNotedAppOp[size];
255 }
256
257 @Override
Eugene Susla1bfb5e72019-10-16 10:12:47 -0700258 public AsyncNotedAppOp createFromParcel(@NonNull android.os.Parcel in) {
259 return new AsyncNotedAppOp(in);
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -0700260 }
261 };
262
263 @DataClass.Generated(
Philip P. Moltmann12ac3f42020-03-05 15:01:29 -0800264 time = 1583866239013L,
Philip P. Moltmann5892a8f2020-03-03 12:05:55 -0800265 codegenVersion = "1.0.15",
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -0700266 sourceFile = "frameworks/base/core/java/android/app/AsyncNotedAppOp.java",
Philip P. Moltmann12ac3f42020-03-05 15:01:29 -0800267 inputSignatures = "private final @android.annotation.IntRange(from=0L) int mOpCode\nprivate final @android.annotation.IntRange(from=0L) int mNotingUid\nprivate final @android.annotation.Nullable java.lang.String mAttributionTag\nprivate final @android.annotation.NonNull java.lang.String mMessage\nprivate final @android.annotation.CurrentTimeMillisLong long mTime\npublic @android.annotation.NonNull java.lang.String getOp()\nprivate void onConstructed()\nclass AsyncNotedAppOp extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genAidl=true, genHiddenConstructor=true)")
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -0700268 @Deprecated
269 private void __metadata() {}
270
Philip P. Moltmannda554e42019-12-20 11:21:02 -0800271
272 //@formatter:on
273 // End of generated code
274
Philip P. Moltmann2b08aaf2019-06-10 08:49:11 -0700275}