1 /* 2 * Copyright (C) 2011 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.compat.annotation.UnsupportedAppUsage; 20 import android.os.Build; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 import java.security.PublicKey; 25 26 /** 27 * Contains information about a package verifier as used by 28 * {@code PackageManagerService} during package verification. 29 * 30 * @hide 31 */ 32 public class VerifierInfo implements Parcelable { 33 /** Package name of the verifier. */ 34 public final String packageName; 35 36 /** Signatures used to sign the package verifier's package. */ 37 public final PublicKey publicKey; 38 39 /** 40 * Creates an object that represents a verifier info object. 41 * 42 * @param packageName the package name in Java-style. Must not be {@code 43 * null} or empty. 44 * @param publicKey the public key for the signer encoded in Base64. Must 45 * not be {@code null} or empty. 46 * @throws IllegalArgumentException if either argument is null or empty. 47 */ 48 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) VerifierInfo(String packageName, PublicKey publicKey)49 public VerifierInfo(String packageName, PublicKey publicKey) { 50 if (packageName == null || packageName.length() == 0) { 51 throw new IllegalArgumentException("packageName must not be null or empty"); 52 } else if (publicKey == null) { 53 throw new IllegalArgumentException("publicKey must not be null"); 54 } 55 56 this.packageName = packageName; 57 this.publicKey = publicKey; 58 } 59 VerifierInfo(Parcel source)60 private VerifierInfo(Parcel source) { 61 packageName = source.readString(); 62 publicKey = (PublicKey) source.readSerializable(java.security.PublicKey.class.getClassLoader(), java.security.PublicKey.class); 63 } 64 65 @Override describeContents()66 public int describeContents() { 67 return 0; 68 } 69 70 @Override writeToParcel(Parcel dest, int flags)71 public void writeToParcel(Parcel dest, int flags) { 72 dest.writeString(packageName); 73 dest.writeSerializable(publicKey); 74 } 75 76 public static final @android.annotation.NonNull Parcelable.Creator<VerifierInfo> CREATOR 77 = new Parcelable.Creator<VerifierInfo>() { 78 public VerifierInfo createFromParcel(Parcel source) { 79 return new VerifierInfo(source); 80 } 81 82 public VerifierInfo[] newArray(int size) { 83 return new VerifierInfo[size]; 84 } 85 }; 86 }