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.CurrentTimeMillisLong; 20 import android.annotation.IntRange; 21 import android.annotation.NonNull; 22 import android.annotation.Nullable; 23 import android.os.Parcelable; 24 25 import com.android.internal.annotations.Immutable; 26 import com.android.internal.util.DataClass; 27 import com.android.internal.util.Preconditions; 28 29 /** 30 * When an {@link AppOpsManager#noteOp(String, int, String, String, String) app-op is noted} and the 31 * 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. 36 */ 37 @Immutable 38 @DataClass(genEqualsHashCode = true, 39 genAidl = true, 40 genHiddenConstructor = true, 41 genToString = true) 42 // - We don't expose the opCode, but rather the public name of the op, hence use a non-standard 43 // getter 44 @DataClass.Suppress({"getOpCode"}) 45 public final class AsyncNotedAppOp implements Parcelable { 46 /** Op that was noted */ 47 private final @IntRange(from = 0) int mOpCode; 48 49 /** Uid that noted the op */ 50 private final @IntRange(from = 0) int mNotingUid; 51 52 /** {@link android.content.Context#createAttributionContext attribution tag} */ 53 private final @Nullable String mAttributionTag; 54 55 /** Message associated with the noteOp. This message is set by the app noting the op */ 56 private final @NonNull String mMessage; 57 58 /** Milliseconds since epoch when the op was noted */ 59 private final @CurrentTimeMillisLong long mTime; 60 61 /** 62 * @return Op that was noted. 63 */ getOp()64 public @NonNull String getOp() { 65 return AppOpsManager.opToPublicName(mOpCode); 66 } 67 68 //TODO eugenesusla: support inlinable expressions in annotation params of @DataClass members to 69 // allow validating via @IntRange(from = 0, to = AppOpsManager._NUM_OP - 1) onConstructed()70 private void onConstructed() { 71 Preconditions.checkArgumentInRange(mOpCode, 0, AppOpsManager._NUM_OP - 1, "opCode"); 72 } 73 opCodeToString()74 private String opCodeToString() { 75 return getOp(); 76 } 77 78 79 80 // Code below generated by codegen v1.0.23. 81 // 82 // DO NOT MODIFY! 83 // CHECKSTYLE:OFF Generated code 84 // 85 // To regenerate run: 86 // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/app/AsyncNotedAppOp.java 87 // 88 // To exclude the generated code from IntelliJ auto-formatting enable (one-time): 89 // Settings > Editor > Code Style > Formatter Control 90 //@formatter:off 91 92 93 /** 94 * Creates a new AsyncNotedAppOp. 95 * 96 * @param opCode 97 * Op that was noted 98 * @param notingUid 99 * Uid that noted the op 100 * @param attributionTag 101 * {@link android.content.Context#createAttributionContext attribution tag} 102 * @param message 103 * Message associated with the noteOp. This message is set by the app noting the op 104 * @param time 105 * Milliseconds since epoch when the op was noted 106 * @hide 107 */ 108 @DataClass.Generated.Member AsyncNotedAppOp( @ntRangefrom = 0) int opCode, @IntRange(from = 0) int notingUid, @Nullable String attributionTag, @NonNull String message, @CurrentTimeMillisLong long time)109 public AsyncNotedAppOp( 110 @IntRange(from = 0) int opCode, 111 @IntRange(from = 0) int notingUid, 112 @Nullable String attributionTag, 113 @NonNull String message, 114 @CurrentTimeMillisLong long time) { 115 this.mOpCode = opCode; 116 com.android.internal.util.AnnotationValidations.validate( 117 IntRange.class, null, mOpCode, 118 "from", 0); 119 this.mNotingUid = notingUid; 120 com.android.internal.util.AnnotationValidations.validate( 121 IntRange.class, null, mNotingUid, 122 "from", 0); 123 this.mAttributionTag = attributionTag; 124 this.mMessage = message; 125 com.android.internal.util.AnnotationValidations.validate( 126 NonNull.class, null, mMessage); 127 this.mTime = time; 128 com.android.internal.util.AnnotationValidations.validate( 129 CurrentTimeMillisLong.class, null, mTime); 130 131 onConstructed(); 132 } 133 134 /** 135 * Uid that noted the op 136 */ 137 @DataClass.Generated.Member getNotingUid()138 public @IntRange(from = 0) int getNotingUid() { 139 return mNotingUid; 140 } 141 142 /** 143 * {@link android.content.Context#createAttributionContext attribution tag} 144 */ 145 @DataClass.Generated.Member getAttributionTag()146 public @Nullable String getAttributionTag() { 147 return mAttributionTag; 148 } 149 150 /** 151 * Message associated with the noteOp. This message is set by the app noting the op 152 */ 153 @DataClass.Generated.Member getMessage()154 public @NonNull String getMessage() { 155 return mMessage; 156 } 157 158 /** 159 * Milliseconds since epoch when the op was noted 160 */ 161 @DataClass.Generated.Member getTime()162 public @CurrentTimeMillisLong long getTime() { 163 return mTime; 164 } 165 166 @Override 167 @DataClass.Generated.Member toString()168 public String toString() { 169 // You can override field toString logic by defining methods like: 170 // String fieldNameToString() { ... } 171 172 return "AsyncNotedAppOp { " + 173 "opCode = " + opCodeToString() + ", " + 174 "notingUid = " + mNotingUid + ", " + 175 "attributionTag = " + mAttributionTag + ", " + 176 "message = " + mMessage + ", " + 177 "time = " + mTime + 178 " }"; 179 } 180 181 @Override 182 @DataClass.Generated.Member equals(@ullable Object o)183 public boolean equals(@Nullable Object o) { 184 // You can override field equality logic by defining either of the methods like: 185 // boolean fieldNameEquals(AsyncNotedAppOp other) { ... } 186 // boolean fieldNameEquals(FieldType otherValue) { ... } 187 188 if (this == o) return true; 189 if (o == null || getClass() != o.getClass()) return false; 190 @SuppressWarnings("unchecked") 191 AsyncNotedAppOp that = (AsyncNotedAppOp) o; 192 //noinspection PointlessBooleanExpression 193 return true 194 && mOpCode == that.mOpCode 195 && mNotingUid == that.mNotingUid 196 && java.util.Objects.equals(mAttributionTag, that.mAttributionTag) 197 && java.util.Objects.equals(mMessage, that.mMessage) 198 && mTime == that.mTime; 199 } 200 201 @Override 202 @DataClass.Generated.Member hashCode()203 public int hashCode() { 204 // You can override field hashCode logic by defining methods like: 205 // int fieldNameHashCode() { ... } 206 207 int _hash = 1; 208 _hash = 31 * _hash + mOpCode; 209 _hash = 31 * _hash + mNotingUid; 210 _hash = 31 * _hash + java.util.Objects.hashCode(mAttributionTag); 211 _hash = 31 * _hash + java.util.Objects.hashCode(mMessage); 212 _hash = 31 * _hash + Long.hashCode(mTime); 213 return _hash; 214 } 215 216 @Override 217 @DataClass.Generated.Member writeToParcel(@onNull android.os.Parcel dest, int flags)218 public void writeToParcel(@NonNull android.os.Parcel dest, int flags) { 219 // You can override field parcelling by defining methods like: 220 // void parcelFieldName(Parcel dest, int flags) { ... } 221 222 byte flg = 0; 223 if (mAttributionTag != null) flg |= 0x4; 224 dest.writeByte(flg); 225 dest.writeInt(mOpCode); 226 dest.writeInt(mNotingUid); 227 if (mAttributionTag != null) dest.writeString(mAttributionTag); 228 dest.writeString(mMessage); 229 dest.writeLong(mTime); 230 } 231 232 @Override 233 @DataClass.Generated.Member describeContents()234 public int describeContents() { return 0; } 235 236 /** @hide */ 237 @SuppressWarnings({"unchecked", "RedundantCast"}) 238 @DataClass.Generated.Member AsyncNotedAppOp(@onNull android.os.Parcel in)239 /* package-private */ AsyncNotedAppOp(@NonNull android.os.Parcel in) { 240 // You can override field unparcelling by defining methods like: 241 // static FieldType unparcelFieldName(Parcel in) { ... } 242 243 byte flg = in.readByte(); 244 int opCode = in.readInt(); 245 int notingUid = in.readInt(); 246 String attributionTag = (flg & 0x4) == 0 ? null : in.readString(); 247 String message = in.readString(); 248 long time = in.readLong(); 249 250 this.mOpCode = opCode; 251 com.android.internal.util.AnnotationValidations.validate( 252 IntRange.class, null, mOpCode, 253 "from", 0); 254 this.mNotingUid = notingUid; 255 com.android.internal.util.AnnotationValidations.validate( 256 IntRange.class, null, mNotingUid, 257 "from", 0); 258 this.mAttributionTag = attributionTag; 259 this.mMessage = message; 260 com.android.internal.util.AnnotationValidations.validate( 261 NonNull.class, null, mMessage); 262 this.mTime = time; 263 com.android.internal.util.AnnotationValidations.validate( 264 CurrentTimeMillisLong.class, null, mTime); 265 266 onConstructed(); 267 } 268 269 @DataClass.Generated.Member 270 public static final @NonNull Parcelable.Creator<AsyncNotedAppOp> CREATOR 271 = new Parcelable.Creator<AsyncNotedAppOp>() { 272 @Override 273 public AsyncNotedAppOp[] newArray(int size) { 274 return new AsyncNotedAppOp[size]; 275 } 276 277 @Override 278 public AsyncNotedAppOp createFromParcel(@NonNull android.os.Parcel in) { 279 return new AsyncNotedAppOp(in); 280 } 281 }; 282 283 @DataClass.Generated( 284 time = 1643320606160L, 285 codegenVersion = "1.0.23", 286 sourceFile = "frameworks/base/core/java/android/app/AsyncNotedAppOp.java", 287 inputSignatures = "private final @android.annotation.IntRange int mOpCode\nprivate final @android.annotation.IntRange 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()\nprivate java.lang.String opCodeToString()\nclass AsyncNotedAppOp extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genAidl=true, genHiddenConstructor=true, genToString=true)") 288 @Deprecated __metadata()289 private void __metadata() {} 290 291 292 //@formatter:on 293 // End of generated code 294 295 } 296