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 final class ChangeIdStateQuery { 39 40 static final int QUERY_BY_PACKAGE_NAME = 0; 41 static final int QUERY_BY_UID = 1; 42 @IntDef({QUERY_BY_PACKAGE_NAME, QUERY_BY_UID}) 43 @Retention(RetentionPolicy.SOURCE) 44 @interface QueryType {} 45 46 public @QueryType int type; 47 public long changeId; 48 public String packageName; 49 public int uid; 50 public int userId; 51 ChangeIdStateQuery(@ueryType int type, long changeId, String packageName, int uid, int userId)52 private ChangeIdStateQuery(@QueryType int type, long changeId, String packageName, 53 int uid, int userId) { 54 this.type = type; 55 this.changeId = changeId; 56 this.packageName = packageName; 57 this.uid = uid; 58 this.userId = userId; 59 } 60 byPackageName(long changeId, @NonNull String packageName, int userId)61 static ChangeIdStateQuery byPackageName(long changeId, @NonNull String packageName, 62 int userId) { 63 return new ChangeIdStateQuery(QUERY_BY_PACKAGE_NAME, changeId, packageName, 0, userId); 64 } 65 byUid(long changeId, int uid)66 static ChangeIdStateQuery byUid(long changeId, int uid) { 67 return new ChangeIdStateQuery(QUERY_BY_UID, changeId, null, uid, 0); 68 } 69 70 @Override equals(@ullable Object other)71 public boolean equals(@Nullable Object other) { 72 if (this == other) { 73 return true; 74 } 75 if ((other == null) || !(other instanceof ChangeIdStateQuery)) { 76 return false; 77 } 78 final ChangeIdStateQuery that = (ChangeIdStateQuery) other; 79 return this.type == that.type 80 && this.changeId == that.changeId 81 && Objects.equals(this.packageName, that.packageName) 82 && this.uid == that.uid 83 && this.userId == that.userId; 84 } 85 86 @Override hashCode()87 public int hashCode() { 88 int result = 1; 89 result = 31 * result + type; 90 result = 31 * result + (int) (changeId ^ (changeId >>> 32)); 91 if (packageName != null) { 92 result = 31 * result + packageName.hashCode(); 93 } 94 result = 31 * result + uid; 95 result = 31 * result + userId; 96 return result; 97 } 98 } 99