blob: e5119b621ee5640fe46a372f2ce546bc12c7ac2c [file] [log] [blame]
rich cannings706e8ba2012-08-20 13:20:14 -07001/*
2 * Copyright (C) 2012 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
17package android.content.pm;
18
19import android.content.pm.ManifestDigest;
20import android.net.Uri;
21import android.os.Parcel;
22import android.os.Parcelable;
23
24/**
25 * Represents verification parameters used to verify packages to be installed.
26 *
Jeff Sharkeya0907432014-08-15 10:23:11 -070027 * @deprecated callers should migrate to {@link PackageInstaller}.
rich cannings706e8ba2012-08-20 13:20:14 -070028 * @hide
29 */
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -070030@Deprecated
rich cannings706e8ba2012-08-20 13:20:14 -070031public class VerificationParams implements Parcelable {
Ben Gruver37d83a32012-09-27 13:02:06 -070032 /** A constant used to indicate that a uid value is not present. */
33 public static final int NO_UID = -1;
34
rich cannings706e8ba2012-08-20 13:20:14 -070035 /** What we print out first when toString() is called. */
36 private static final String TO_STRING_PREFIX = "VerificationParams{";
37
38 /** The location of the supplementary verification file. */
39 private final Uri mVerificationURI;
40
41 /** URI referencing where the package was downloaded from. */
42 private final Uri mOriginatingURI;
43
44 /** HTTP referrer URI associated with the originatingURI. */
45 private final Uri mReferrer;
46
Ben Gruver37d83a32012-09-27 13:02:06 -070047 /** UID of the application that the install request originated from. */
48 private final int mOriginatingUid;
49
rich cannings13d428e2012-09-13 13:43:07 -070050 /** UID of application requesting the install */
51 private int mInstallerUid;
52
rich cannings706e8ba2012-08-20 13:20:14 -070053 /**
54 * An object that holds the digest of the package which can be used to
55 * verify ownership.
56 */
57 private final ManifestDigest mManifestDigest;
58
59 /**
60 * Creates verification specifications for installing with application verification.
61 *
62 * @param verificationURI The location of the supplementary verification
63 * file. This can be a 'file:' or a 'content:' URI. May be {@code null}.
64 * @param originatingURI URI referencing where the package was downloaded
65 * from. May be {@code null}.
66 * @param referrer HTTP referrer URI associated with the originatingURI.
67 * May be {@code null}.
Ben Gruver37d83a32012-09-27 13:02:06 -070068 * @param originatingUid UID of the application that the install request originated
69 * from, or NO_UID if not present
rich cannings706e8ba2012-08-20 13:20:14 -070070 * @param manifestDigest an object that holds the digest of the package
71 * which can be used to verify ownership. May be {@code null}.
72 */
73 public VerificationParams(Uri verificationURI, Uri originatingURI, Uri referrer,
Ben Gruver37d83a32012-09-27 13:02:06 -070074 int originatingUid, ManifestDigest manifestDigest) {
rich cannings706e8ba2012-08-20 13:20:14 -070075 mVerificationURI = verificationURI;
76 mOriginatingURI = originatingURI;
77 mReferrer = referrer;
Ben Gruver37d83a32012-09-27 13:02:06 -070078 mOriginatingUid = originatingUid;
rich cannings706e8ba2012-08-20 13:20:14 -070079 mManifestDigest = manifestDigest;
Ben Gruver37d83a32012-09-27 13:02:06 -070080 mInstallerUid = NO_UID;
rich cannings706e8ba2012-08-20 13:20:14 -070081 }
82
83 public Uri getVerificationURI() {
84 return mVerificationURI;
85 }
86
87 public Uri getOriginatingURI() {
88 return mOriginatingURI;
89 }
90
91 public Uri getReferrer() {
92 return mReferrer;
93 }
94
Ben Gruver37d83a32012-09-27 13:02:06 -070095 /** return NO_UID if not available */
96 public int getOriginatingUid() {
97 return mOriginatingUid;
98 }
99
rich cannings706e8ba2012-08-20 13:20:14 -0700100 public ManifestDigest getManifestDigest() {
101 return mManifestDigest;
102 }
103
Ben Gruver37d83a32012-09-27 13:02:06 -0700104 /** @return NO_UID when not set */
rich cannings13d428e2012-09-13 13:43:07 -0700105 public int getInstallerUid() {
106 return mInstallerUid;
107 }
108
109 public void setInstallerUid(int uid) {
110 mInstallerUid = uid;
111 }
112
rich cannings706e8ba2012-08-20 13:20:14 -0700113 @Override
114 public int describeContents() {
115 return 0;
116 }
117
118 @Override
119 public boolean equals(Object o) {
120 if (this == o) {
121 return true;
122 }
123
124 if (!(o instanceof VerificationParams)) {
125 return false;
126 }
127
128 final VerificationParams other = (VerificationParams) o;
129
Ben Gruver37d83a32012-09-27 13:02:06 -0700130 if (mVerificationURI == null) {
131 if (other.mVerificationURI != null) {
132 return false;
133 }
134 } else if (!mVerificationURI.equals(other.mVerificationURI)) {
rich cannings706e8ba2012-08-20 13:20:14 -0700135 return false;
136 }
137
Ben Gruver37d83a32012-09-27 13:02:06 -0700138 if (mOriginatingURI == null) {
139 if (other.mOriginatingURI != null) {
140 return false;
141 }
142 } else if (!mOriginatingURI.equals(other.mOriginatingURI)) {
rich cannings706e8ba2012-08-20 13:20:14 -0700143 return false;
144 }
145
Ben Gruver37d83a32012-09-27 13:02:06 -0700146 if (mReferrer == null) {
147 if (other.mReferrer != null) {
148 return false;
149 }
150 } else if (!mReferrer.equals(other.mReferrer)) {
rich cannings706e8ba2012-08-20 13:20:14 -0700151 return false;
152 }
153
Ben Gruver37d83a32012-09-27 13:02:06 -0700154 if (mOriginatingUid != other.mOriginatingUid) {
rich cannings706e8ba2012-08-20 13:20:14 -0700155 return false;
156 }
Ben Gruver37d83a32012-09-27 13:02:06 -0700157
158 if (mManifestDigest == null) {
159 if (other.mManifestDigest != null) {
160 return false;
161 }
162 } else if (!mManifestDigest.equals(other.mManifestDigest)) {
rich cannings706e8ba2012-08-20 13:20:14 -0700163 return false;
164 }
165
rich cannings13d428e2012-09-13 13:43:07 -0700166 if (mInstallerUid != other.mInstallerUid) {
167 return false;
168 }
169
rich cannings706e8ba2012-08-20 13:20:14 -0700170 return true;
171 }
172
173 @Override
174 public int hashCode() {
175 int hash = 3;
176
Ben Gruver37d83a32012-09-27 13:02:06 -0700177 hash += 5 * (mVerificationURI == null ? 1 : mVerificationURI.hashCode());
178 hash += 7 * (mOriginatingURI == null ? 1 : mOriginatingURI.hashCode());
179 hash += 11 * (mReferrer == null ? 1 : mReferrer.hashCode());
180 hash += 13 * mOriginatingUid;
181 hash += 17 * (mManifestDigest == null ? 1 : mManifestDigest.hashCode());
182 hash += 19 * mInstallerUid;
rich cannings706e8ba2012-08-20 13:20:14 -0700183
184 return hash;
185 }
186
187 @Override
188 public String toString() {
189 final StringBuilder sb = new StringBuilder(TO_STRING_PREFIX);
190
191 sb.append("mVerificationURI=");
192 sb.append(mVerificationURI.toString());
193 sb.append(",mOriginatingURI=");
194 sb.append(mOriginatingURI.toString());
195 sb.append(",mReferrer=");
196 sb.append(mReferrer.toString());
Ben Gruver37d83a32012-09-27 13:02:06 -0700197 sb.append(",mOriginatingUid=");
198 sb.append(mOriginatingUid);
rich cannings706e8ba2012-08-20 13:20:14 -0700199 sb.append(",mManifestDigest=");
200 sb.append(mManifestDigest.toString());
rich cannings13d428e2012-09-13 13:43:07 -0700201 sb.append(",mInstallerUid=");
202 sb.append(mInstallerUid);
rich cannings706e8ba2012-08-20 13:20:14 -0700203 sb.append('}');
204
205 return sb.toString();
206 }
207
208 @Override
209 public void writeToParcel(Parcel dest, int flags) {
210 dest.writeParcelable(mVerificationURI, 0);
211 dest.writeParcelable(mOriginatingURI, 0);
212 dest.writeParcelable(mReferrer, 0);
Ben Gruver37d83a32012-09-27 13:02:06 -0700213 dest.writeInt(mOriginatingUid);
rich cannings706e8ba2012-08-20 13:20:14 -0700214 dest.writeParcelable(mManifestDigest, 0);
rich cannings13d428e2012-09-13 13:43:07 -0700215 dest.writeInt(mInstallerUid);
rich cannings706e8ba2012-08-20 13:20:14 -0700216 }
217
218
219 private VerificationParams(Parcel source) {
220 mVerificationURI = source.readParcelable(Uri.class.getClassLoader());
221 mOriginatingURI = source.readParcelable(Uri.class.getClassLoader());
222 mReferrer = source.readParcelable(Uri.class.getClassLoader());
Ben Gruver37d83a32012-09-27 13:02:06 -0700223 mOriginatingUid = source.readInt();
rich cannings706e8ba2012-08-20 13:20:14 -0700224 mManifestDigest = source.readParcelable(ManifestDigest.class.getClassLoader());
rich cannings13d428e2012-09-13 13:43:07 -0700225 mInstallerUid = source.readInt();
rich cannings706e8ba2012-08-20 13:20:14 -0700226 }
227
228 public static final Parcelable.Creator<VerificationParams> CREATOR =
229 new Parcelable.Creator<VerificationParams>() {
230 public VerificationParams createFromParcel(Parcel source) {
231 return new VerificationParams(source);
232 }
233
234 public VerificationParams[] newArray(int size) {
235 return new VerificationParams[size];
236 }
237 };
238}