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 // - 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"}) 44 public final class AsyncNotedAppOp implements Parcelable { 45 /** Op that was noted */ 46 private final @IntRange(from = 0) int mOpCode; 47 48 /** Uid that noted the op */ 49 private final @IntRange(from = 0) int mNotingUid; 50 51 /** {@link android.content.Context#createAttributionContext attribution tag} */ 52 private final @Nullable String mAttributionTag; 53 54 /** 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 */ 58 private final @CurrentTimeMillisLong long mTime; 59 60 /** 61 * @return Op that was noted. 62 */ getOp()63 public @NonNull String getOp() { 64 return AppOpsManager.opToPublicName(mOpCode); 65 } 66 67 //TODO eugenesusla: support inlinable expressions in annotation params of @DataClass members to 68 // allow validating via @IntRange(from = 0, to = AppOpsManager._NUM_OP - 1) onConstructed()69 private void onConstructed() { 70 Preconditions.checkArgumentInRange(mOpCode, 0, AppOpsManager._NUM_OP - 1, "opCode"); 71 } 72 73 74 75 // Code below generated by codegen v1.0.20. 76 // 77 // DO NOT MODIFY! 78 // CHECKSTYLE:OFF Generated code 79 // 80 // To regenerate run: 81 // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/app/AsyncNotedAppOp.java 82 // 83 // To exclude the generated code from IntelliJ auto-formatting enable (one-time): 84 // Settings > Editor > Code Style > Formatter Control 85 //@formatter:off 86 87 88 /** 89 * Creates a new AsyncNotedAppOp. 90 * 91 * @param opCode 92 * Op that was noted 93 * @param notingUid 94 * Uid that noted the op 95 * @param attributionTag 96 * {@link android.content.Context#createAttributionContext attribution tag} 97 * @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 AsyncNotedAppOp( @ntRangefrom = 0) int opCode, @IntRange(from = 0) int notingUid, @Nullable String attributionTag, @NonNull String message, @CurrentTimeMillisLong long time)104 public AsyncNotedAppOp( 105 @IntRange(from = 0) int opCode, 106 @IntRange(from = 0) int notingUid, 107 @Nullable String attributionTag, 108 @NonNull String message, 109 @CurrentTimeMillisLong long time) { 110 this.mOpCode = opCode; 111 com.android.internal.util.AnnotationValidations.validate( 112 IntRange.class, null, mOpCode, 113 "from", 0); 114 this.mNotingUid = notingUid; 115 com.android.internal.util.AnnotationValidations.validate( 116 IntRange.class, null, mNotingUid, 117 "from", 0); 118 this.mAttributionTag = attributionTag; 119 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( 124 CurrentTimeMillisLong.class, null, mTime); 125 126 onConstructed(); 127 } 128 129 /** 130 * Uid that noted the op 131 */ 132 @DataClass.Generated.Member getNotingUid()133 public @IntRange(from = 0) int getNotingUid() { 134 return mNotingUid; 135 } 136 137 /** 138 * {@link android.content.Context#createAttributionContext attribution tag} 139 */ 140 @DataClass.Generated.Member getAttributionTag()141 public @Nullable String getAttributionTag() { 142 return mAttributionTag; 143 } 144 145 /** 146 * Message associated with the noteOp. This message is set by the app noting the op 147 */ 148 @DataClass.Generated.Member getMessage()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 getTime()157 public @CurrentTimeMillisLong long getTime() { 158 return mTime; 159 } 160 161 @Override 162 @DataClass.Generated.Member equals(@ullable Object o)163 public boolean equals(@Nullable Object o) { 164 // 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 176 && java.util.Objects.equals(mAttributionTag, that.mAttributionTag) 177 && java.util.Objects.equals(mMessage, that.mMessage) 178 && mTime == that.mTime; 179 } 180 181 @Override 182 @DataClass.Generated.Member hashCode()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; 190 _hash = 31 * _hash + java.util.Objects.hashCode(mAttributionTag); 191 _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 writeToParcel(@onNull android.os.Parcel dest, int flags)198 public void writeToParcel(@NonNull android.os.Parcel dest, int flags) { 199 // You can override field parcelling by defining methods like: 200 // void parcelFieldName(Parcel dest, int flags) { ... } 201 202 byte flg = 0; 203 if (mAttributionTag != null) flg |= 0x4; 204 dest.writeByte(flg); 205 dest.writeInt(mOpCode); 206 dest.writeInt(mNotingUid); 207 if (mAttributionTag != null) dest.writeString(mAttributionTag); 208 dest.writeString(mMessage); 209 dest.writeLong(mTime); 210 } 211 212 @Override 213 @DataClass.Generated.Member describeContents()214 public int describeContents() { return 0; } 215 216 /** @hide */ 217 @SuppressWarnings({"unchecked", "RedundantCast"}) 218 @DataClass.Generated.Member AsyncNotedAppOp(@onNull android.os.Parcel in)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(); 226 String attributionTag = (flg & 0x4) == 0 ? null : in.readString(); 227 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, 233 "from", 0); 234 this.mNotingUid = notingUid; 235 com.android.internal.util.AnnotationValidations.validate( 236 IntRange.class, null, mNotingUid, 237 "from", 0); 238 this.mAttributionTag = attributionTag; 239 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( 244 CurrentTimeMillisLong.class, null, mTime); 245 246 onConstructed(); 247 } 248 249 @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 258 public AsyncNotedAppOp createFromParcel(@NonNull android.os.Parcel in) { 259 return new AsyncNotedAppOp(in); 260 } 261 }; 262 263 @DataClass.Generated( 264 time = 1604456255752L, 265 codegenVersion = "1.0.20", 266 sourceFile = "frameworks/base/core/java/android/app/AsyncNotedAppOp.java", 267 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()\nclass AsyncNotedAppOp extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genAidl=true, genHiddenConstructor=true)") 268 @Deprecated __metadata()269 private void __metadata() {} 270 271 272 //@formatter:on 273 // End of generated code 274 275 } 276