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.TestApi; 23 import android.os.Parcelable; 24 25 import com.android.internal.annotations.Immutable; 26 import com.android.internal.util.DataClass; 27 28 /** 29 * Description of an app-op that was noted for the current process. 30 * 31 * Note: package name is currently unused in the system. 32 * 33 * <p>This is either delivered after a 34 * {@link AppOpsManager.OnOpNotedCallback#onNoted(SyncNotedAppOp) two way binder call} or 35 * when the app 36 * {@link AppOpsManager.OnOpNotedCallback#onSelfNoted(SyncNotedAppOp) notes an app-op for 37 * itself}. 38 */ 39 @Immutable 40 @DataClass( 41 genEqualsHashCode = true, 42 genAidl = true, 43 genConstructor = false 44 ) 45 @DataClass.Suppress({"getOpCode", "getOpMode"}) 46 public final class SyncNotedAppOp implements Parcelable { 47 48 /** mode returned by the system on a call to note/startOp, if applicable */ 49 private final int mOpMode; 50 /** op code of synchronous appop noted */ 51 private final @IntRange(from = 0L, to = AppOpsManager._NUM_OP - 1) int mOpCode; 52 /** attributionTag of synchronous appop noted */ 53 private final @Nullable String mAttributionTag; 54 /** 55 * The package this op applies to 56 * @hide 57 */ 58 private final @NonNull String mPackageName; 59 60 /** 61 * Native code relies on parcel ordering, do not change 62 * @hide 63 */ 64 @TestApi SyncNotedAppOp(int opMode, @IntRange(from = 0L) int opCode, @Nullable String attributionTag, @NonNull String packageName)65 public SyncNotedAppOp(int opMode, @IntRange(from = 0L) int opCode, 66 @Nullable String attributionTag, @NonNull String packageName) { 67 this.mOpCode = opCode; 68 com.android.internal.util.AnnotationValidations.validate( 69 IntRange.class, null, mOpCode, 70 "from", 0, 71 "to", AppOpsManager._NUM_OP - 1); 72 this.mAttributionTag = attributionTag; 73 this.mOpMode = opMode; 74 this.mPackageName = packageName; 75 } 76 77 /** 78 * Creates a new SyncNotedAppOp. 79 * 80 * @param opCode 81 * op code of synchronous appop noted 82 * @param attributionTag 83 * attributionTag of synchronous appop noted 84 */ SyncNotedAppOp(@ntRangefrom = 0L) int opCode, @Nullable String attributionTag)85 public SyncNotedAppOp(@IntRange(from = 0L) int opCode, @Nullable String attributionTag) { 86 this(AppOpsManager.MODE_IGNORED, opCode, attributionTag, ActivityThread 87 .currentPackageName()); 88 } 89 90 /** 91 * Creates a new SyncNotedAppOp. 92 * 93 * @param opCode 94 * op code of synchronous appop noted 95 * @param attributionTag 96 * attributionTag of synchronous appop noted 97 * @param packageName 98 * The package this op applies to 99 * 100 * @hide 101 */ SyncNotedAppOp(@ntRangefrom = 0L) int opCode, @Nullable String attributionTag, @NonNull String packageName)102 public SyncNotedAppOp(@IntRange(from = 0L) int opCode, @Nullable String attributionTag, 103 @NonNull String packageName) { 104 this(AppOpsManager.MODE_IGNORED, opCode, attributionTag, packageName); 105 } 106 107 /** 108 * @return The op that was noted. 109 */ getOp()110 public @NonNull String getOp() { 111 return AppOpsManager.opToPublicName(mOpCode); 112 } 113 114 /** 115 * @hide 116 */ getOpMode()117 public int getOpMode() { 118 return mOpMode; 119 } 120 121 122 123 // Code below generated by codegen v1.0.23. 124 // 125 // DO NOT MODIFY! 126 // CHECKSTYLE:OFF Generated code 127 // 128 // To regenerate run: 129 // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/app/SyncNotedAppOp.java 130 // 131 // To exclude the generated code from IntelliJ auto-formatting enable (one-time): 132 // Settings > Editor > Code Style > Formatter Control 133 //@formatter:off 134 135 136 /** 137 * attributionTag of synchronous appop noted 138 */ 139 @DataClass.Generated.Member getAttributionTag()140 public @Nullable String getAttributionTag() { 141 return mAttributionTag; 142 } 143 144 /** 145 * The package this op applies to 146 * 147 * @hide 148 */ 149 @DataClass.Generated.Member getPackageName()150 public @NonNull String getPackageName() { 151 return mPackageName; 152 } 153 154 @Override 155 @DataClass.Generated.Member equals(@ullable Object o)156 public boolean equals(@Nullable Object o) { 157 // You can override field equality logic by defining either of the methods like: 158 // boolean fieldNameEquals(SyncNotedAppOp other) { ... } 159 // boolean fieldNameEquals(FieldType otherValue) { ... } 160 161 if (this == o) return true; 162 if (o == null || getClass() != o.getClass()) return false; 163 @SuppressWarnings("unchecked") 164 SyncNotedAppOp that = (SyncNotedAppOp) o; 165 //noinspection PointlessBooleanExpression 166 return true 167 && mOpMode == that.mOpMode 168 && mOpCode == that.mOpCode 169 && java.util.Objects.equals(mAttributionTag, that.mAttributionTag) 170 && java.util.Objects.equals(mPackageName, that.mPackageName); 171 } 172 173 @Override 174 @DataClass.Generated.Member hashCode()175 public int hashCode() { 176 // You can override field hashCode logic by defining methods like: 177 // int fieldNameHashCode() { ... } 178 179 int _hash = 1; 180 _hash = 31 * _hash + mOpMode; 181 _hash = 31 * _hash + mOpCode; 182 _hash = 31 * _hash + java.util.Objects.hashCode(mAttributionTag); 183 _hash = 31 * _hash + java.util.Objects.hashCode(mPackageName); 184 return _hash; 185 } 186 187 @Override 188 @DataClass.Generated.Member writeToParcel(@onNull android.os.Parcel dest, int flags)189 public void writeToParcel(@NonNull android.os.Parcel dest, int flags) { 190 // You can override field parcelling by defining methods like: 191 // void parcelFieldName(Parcel dest, int flags) { ... } 192 193 byte flg = 0; 194 if (mAttributionTag != null) flg |= 0x4; 195 dest.writeByte(flg); 196 dest.writeInt(mOpMode); 197 dest.writeInt(mOpCode); 198 if (mAttributionTag != null) dest.writeString(mAttributionTag); 199 dest.writeString(mPackageName); 200 } 201 202 @Override 203 @DataClass.Generated.Member describeContents()204 public int describeContents() { return 0; } 205 206 /** @hide */ 207 @SuppressWarnings({"unchecked", "RedundantCast"}) 208 @DataClass.Generated.Member SyncNotedAppOp(@onNull android.os.Parcel in)209 /* package-private */ SyncNotedAppOp(@NonNull android.os.Parcel in) { 210 // You can override field unparcelling by defining methods like: 211 // static FieldType unparcelFieldName(Parcel in) { ... } 212 213 byte flg = in.readByte(); 214 int opMode = in.readInt(); 215 int opCode = in.readInt(); 216 String attributionTag = (flg & 0x4) == 0 ? null : in.readString(); 217 String packageName = in.readString(); 218 219 this.mOpMode = opMode; 220 this.mOpCode = opCode; 221 com.android.internal.util.AnnotationValidations.validate( 222 IntRange.class, null, mOpCode, 223 "from", 0L, 224 "to", AppOpsManager._NUM_OP - 1); 225 this.mAttributionTag = attributionTag; 226 this.mPackageName = packageName; 227 com.android.internal.util.AnnotationValidations.validate( 228 NonNull.class, null, mPackageName); 229 230 // onConstructed(); // You can define this method to get a callback 231 } 232 233 @DataClass.Generated.Member 234 public static final @NonNull Parcelable.Creator<SyncNotedAppOp> CREATOR 235 = new Parcelable.Creator<SyncNotedAppOp>() { 236 @Override 237 public SyncNotedAppOp[] newArray(int size) { 238 return new SyncNotedAppOp[size]; 239 } 240 241 @Override 242 public SyncNotedAppOp createFromParcel(@NonNull android.os.Parcel in) { 243 return new SyncNotedAppOp(in); 244 } 245 }; 246 247 @DataClass.Generated( 248 time = 1619711733947L, 249 codegenVersion = "1.0.23", 250 sourceFile = "frameworks/base/core/java/android/app/SyncNotedAppOp.java", 251 inputSignatures = "private final int mOpMode\nprivate final @android.annotation.IntRange int mOpCode\nprivate final @android.annotation.Nullable java.lang.String mAttributionTag\nprivate final @android.annotation.NonNull java.lang.String mPackageName\npublic @android.annotation.NonNull java.lang.String getOp()\npublic int getOpMode()\nclass SyncNotedAppOp extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genAidl=true, genConstructor=false)") 252 @Deprecated __metadata()253 private void __metadata() {} 254 255 256 //@formatter:on 257 // End of generated code 258 259 } 260