1 /* 2 * Copyright (C) 2020 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.compat; 18 19 import android.annotation.IntDef; 20 import android.annotation.NonNull; 21 import android.annotation.Nullable; 22 23 import com.android.internal.annotations.Immutable; 24 25 import java.lang.annotation.Retention; 26 import java.lang.annotation.RetentionPolicy; 27 import java.util.Objects; 28 29 /** 30 * A key type for caching calls to {@link com.android.internal.compat.IPlatformCompat} 31 * 32 * <p>For {@link com.android.internal.compat.IPlatformCompat#isChangeEnabledByPackageName} 33 * and {@link com.android.internal.compat.IPlatformCompat#isChangeEnabledByUid} 34 * 35 * @hide 36 */ 37 @Immutable 38 @android.ravenwood.annotation.RavenwoodKeepWholeClass 39 final class ChangeIdStateQuery { 40 41 static final int QUERY_BY_PACKAGE_NAME = 0; 42 static final int QUERY_BY_UID = 1; 43 @IntDef({QUERY_BY_PACKAGE_NAME, QUERY_BY_UID}) 44 @Retention(RetentionPolicy.SOURCE) 45 @interface QueryType {} 46 47 public @QueryType int type; 48 public long changeId; 49 public String packageName; 50 public int uid; 51 public int userId; 52 ChangeIdStateQuery(@ueryType int type, long changeId, String packageName, int uid, int userId)53 private ChangeIdStateQuery(@QueryType int type, long changeId, String packageName, 54 int uid, int userId) { 55 this.type = type; 56 this.changeId = changeId; 57 this.packageName = packageName; 58 this.uid = uid; 59 this.userId = userId; 60 } 61 byPackageName(long changeId, @NonNull String packageName, int userId)62 static ChangeIdStateQuery byPackageName(long changeId, @NonNull String packageName, 63 int userId) { 64 return new ChangeIdStateQuery(QUERY_BY_PACKAGE_NAME, changeId, packageName, 0, userId); 65 } 66 byUid(long changeId, int uid)67 static ChangeIdStateQuery byUid(long changeId, int uid) { 68 return new ChangeIdStateQuery(QUERY_BY_UID, changeId, null, uid, 0); 69 } 70 71 @Override equals(@ullable Object other)72 public boolean equals(@Nullable Object other) { 73 if (this == other) { 74 return true; 75 } 76 if ((other == null) || !(other instanceof ChangeIdStateQuery)) { 77 return false; 78 } 79 final ChangeIdStateQuery that = (ChangeIdStateQuery) other; 80 return this.type == that.type 81 && this.changeId == that.changeId 82 && Objects.equals(this.packageName, that.packageName) 83 && this.uid == that.uid 84 && this.userId == that.userId; 85 } 86 87 @Override hashCode()88 public int hashCode() { 89 int result = 1; 90 result = 31 * result + type; 91 result = 31 * result + (int) (changeId ^ (changeId >>> 32)); 92 if (packageName != null) { 93 result = 31 * result + packageName.hashCode(); 94 } 95 result = 31 * result + uid; 96 result = 31 * result + userId; 97 return result; 98 } 99 } 100