Debian Codegraph @

core/java/android/content/pm/ApkChecksum.java

raw symbols SCIP
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.content.pm;
18
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23
24 import com.android.internal.util.DataClass;
25
26 import java.io.ByteArrayInputStream;
27 import java.io.InputStream;
28 import java.security.cert.Certificate;
29 import java.security.cert.CertificateEncodingException;
30 import java.security.cert.CertificateException;
31 import java.security.cert.CertificateFactory;
32 import java.security.cert.X509Certificate;
33
34 /**
35 * A typed checksum of an APK.
36 *
37 * @see PackageManager#requestChecksums
38 */
39 @DataClass(genHiddenConstructor = true)
40 @DataClass.Suppress({"getChecksum"})
41 public final class ApkChecksum implements Parcelable {
42 /**
43 * Checksum for which split. Null indicates base.apk.
44 */
45 private final @Nullable String mSplitName;
46 /**
47 * Checksum.
48 */
49 private final @NonNull Checksum mChecksum;
50 /**
51 * For Installer-provided checksums, package name of the Installer.
52 */
53 private final @Nullable String mInstallerPackageName;
54 /**
55 * For Installer-provided checksums, certificate of the Installer.
56 */
57 private final @Nullable byte[] mInstallerCertificate;
58
59 /**
60 * Constructor, internal use only.
61 *
62 * @hide
63 */
64 public ApkChecksum(@Nullable String splitName, @Checksum.Type int type,
65 @NonNull byte[] value) {
66 this(splitName, new Checksum(type, value), (String) null, (byte[]) null);
67 }
68
69 /**
70 * Constructor, internal use only.
71 *
72 * @hide
73 */
74 public ApkChecksum(@Nullable String splitName, @Checksum.Type int type, @NonNull byte[] value,
75 @Nullable String sourcePackageName, @Nullable Certificate sourceCertificate)
76 throws CertificateEncodingException {
77 this(splitName, new Checksum(type, value), sourcePackageName,
78 (sourceCertificate != null) ? sourceCertificate.getEncoded() : null);
79 }
80
81
82 /**
83 * Checksum type.
84 */
85 public @Checksum.Type int getType() {
86 return mChecksum.getType();
87 }
88
89 /**
90 * Checksum value.
91 */
92 public @NonNull byte[] getValue() {
93 return mChecksum.getValue();
94 }
95
96 /**
97 * Returns raw bytes representing encoded certificate of the Installer.
98 * @hide
99 */
100 public @Nullable byte[] getInstallerCertificateBytes() {
101 return mInstallerCertificate;
102 }
103
104 /**
105 * For Installer-provided checksums, certificate of the Installer.
106 * @throws CertificateException in case when certificate can't be re-created from serialized
107 * data.
108 */
109 public @Nullable Certificate getInstallerCertificate() throws CertificateException {
110 if (mInstallerCertificate == null) {
111 return null;
112 }
113 final CertificateFactory cf = CertificateFactory.getInstance("X.509");
114 final InputStream is = new ByteArrayInputStream(mInstallerCertificate);
115 final X509Certificate cert = (X509Certificate) cf.generateCertificate(is);
116 return cert;
117 }
118
119
120
121 // Code below generated by codegen v1.0.23.
122 //
123 // DO NOT MODIFY!
124 // CHECKSTYLE:OFF Generated code
125 //
126 // To regenerate run:
127 // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/content/pm/ApkChecksum.java
128 //
129 // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
130 // Settings > Editor > Code Style > Formatter Control
131 //@formatter:off
132
133
134 /**
135 * Creates a new ApkChecksum.
136 *
137 * @param splitName
138 * Checksum for which split. Null indicates base.apk.
139 * @param checksum
140 * Checksum.
141 * @param installerPackageName
142 * For Installer-provided checksums, package name of the Installer.
143 * @param installerCertificate
144 * For Installer-provided checksums, certificate of the Installer.
145 * @hide
146 */
147 @DataClass.Generated.Member
148 public ApkChecksum(
149 @Nullable String splitName,
150 @NonNull Checksum checksum,
151 @Nullable String installerPackageName,
152 @Nullable byte[] installerCertificate) {
153 this.mSplitName = splitName;
154 this.mChecksum = checksum;
155 com.android.internal.util.AnnotationValidations.validate(
156 NonNull.class, null, mChecksum);
157 this.mInstallerPackageName = installerPackageName;
158 this.mInstallerCertificate = installerCertificate;
159
160 // onConstructed(); // You can define this method to get a callback
161 }
162
163 /**
164 * Checksum for which split. Null indicates base.apk.
165 */
166 @DataClass.Generated.Member
167 public @Nullable String getSplitName() {
168 return mSplitName;
169 }
170
171 /**
172 * For Installer-provided checksums, package name of the Installer.
173 */
174 @DataClass.Generated.Member
175 public @Nullable String getInstallerPackageName() {
176 return mInstallerPackageName;
177 }
178
179 @Override
180 @DataClass.Generated.Member
181 public void writeToParcel(@NonNull Parcel dest, int flags) {
182 // You can override field parcelling by defining methods like:
183 // void parcelFieldName(Parcel dest, int flags) { ... }
184
185 byte flg = 0;
186 if (mSplitName != null) flg |= 0x1;
187 if (mInstallerPackageName != null) flg |= 0x4;
188 if (mInstallerCertificate != null) flg |= 0x8;
189 dest.writeByte(flg);
190 if (mSplitName != null) dest.writeString(mSplitName);
191 dest.writeTypedObject(mChecksum, flags);
192 if (mInstallerPackageName != null) dest.writeString(mInstallerPackageName);
193 if (mInstallerCertificate != null) dest.writeByteArray(mInstallerCertificate);
194 }
195
196 @Override
197 @DataClass.Generated.Member
198 public int describeContents() { return 0; }
199
200 /** @hide */
201 @SuppressWarnings({"unchecked", "RedundantCast"})
202 @DataClass.Generated.Member
203 /* package-private */ ApkChecksum(@NonNull Parcel in) {
204 // You can override field unparcelling by defining methods like:
205 // static FieldType unparcelFieldName(Parcel in) { ... }
206
207 byte flg = in.readByte();
208 String splitName = (flg & 0x1) == 0 ? null : in.readString();
209 Checksum checksum = (Checksum) in.readTypedObject(Checksum.CREATOR);
210 String installerPackageName = (flg & 0x4) == 0 ? null : in.readString();
211 byte[] installerCertificate = (flg & 0x8) == 0 ? null : in.createByteArray();
212
213 this.mSplitName = splitName;
214 this.mChecksum = checksum;
215 com.android.internal.util.AnnotationValidations.validate(
216 NonNull.class, null, mChecksum);
217 this.mInstallerPackageName = installerPackageName;
218 this.mInstallerCertificate = installerCertificate;
219
220 // onConstructed(); // You can define this method to get a callback
221 }
222
223 @DataClass.Generated.Member
224 public static final @NonNull Parcelable.Creator<ApkChecksum> CREATOR
225 = new Parcelable.Creator<ApkChecksum>() {
226 @Override
227 public ApkChecksum[] newArray(int size) {
228 return new ApkChecksum[size];
229 }
230
231 @Override
232 public ApkChecksum createFromParcel(@NonNull Parcel in) {
233 return new ApkChecksum(in);
234 }
235 };
236
237 @DataClass.Generated(
238 time = 1619810171079L,
239 codegenVersion = "1.0.23",
240 sourceFile = "frameworks/base/core/java/android/content/pm/ApkChecksum.java",
241 inputSignatures = "private final @android.annotation.Nullable java.lang.String mSplitName\nprivate final @android.annotation.NonNull android.content.pm.Checksum mChecksum\nprivate final @android.annotation.Nullable java.lang.String mInstallerPackageName\nprivate final @android.annotation.Nullable byte[] mInstallerCertificate\npublic @android.content.pm.Checksum.Type int getType()\npublic @android.annotation.NonNull byte[] getValue()\npublic @android.annotation.Nullable byte[] getInstallerCertificateBytes()\npublic @android.annotation.Nullable java.security.cert.Certificate getInstallerCertificate()\nclass ApkChecksum extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genHiddenConstructor=true)")
242 @Deprecated
243 private void __metadata() {}
244
245
246 //@formatter:on
247 // End of generated code
248
249 }