1 /* 2 * Copyright (C) 2024 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.content.pm; 18 19 import android.annotation.FlaggedApi; 20 import android.annotation.NonNull; 21 import android.annotation.SystemApi; 22 23 import java.util.Arrays; 24 import java.util.Objects; 25 26 /** 27 * A data class representing a package and (SHA-256 hash of) a signing certificate. 28 * 29 * @hide 30 */ 31 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) 32 @FlaggedApi(android.permission.flags.Flags.FLAG_ENHANCED_CONFIRMATION_MODE_APIS_ENABLED) 33 public class SignedPackage { 34 @NonNull 35 private final SignedPackageParcel mData; 36 37 /** @hide */ SignedPackage(@onNull String packageName, @NonNull byte[] certificateDigest)38 public SignedPackage(@NonNull String packageName, @NonNull byte[] certificateDigest) { 39 SignedPackageParcel data = new SignedPackageParcel(); 40 data.packageName = packageName; 41 data.certificateDigest = certificateDigest; 42 mData = data; 43 } 44 45 /** @hide */ SignedPackage(@onNull SignedPackageParcel data)46 public SignedPackage(@NonNull SignedPackageParcel data) { 47 mData = data; 48 } 49 50 /** @hide */ getData()51 public final @NonNull SignedPackageParcel getData() { 52 return mData; 53 } 54 getPackageName()55 public @NonNull String getPackageName() { 56 return mData.packageName; 57 } 58 getCertificateDigest()59 public @NonNull byte[] getCertificateDigest() { 60 return mData.certificateDigest; 61 } 62 63 @Override equals(Object o)64 public boolean equals(Object o) { 65 if (this == o) return true; 66 if (!(o instanceof SignedPackage that)) return false; 67 return mData.packageName.equals(that.mData.packageName) && Arrays.equals( 68 mData.certificateDigest, that.mData.certificateDigest); 69 } 70 71 @Override hashCode()72 public int hashCode() { 73 return Objects.hash(mData.packageName, Arrays.hashCode(mData.certificateDigest)); 74 } 75 } 76