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