blob: f07216796eb90bd4d59233f7867c3cab556276e3 [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
rich cannings706e8ba2012-08-20 13:20:14 -070019import android.net.Uri;
20import android.os.Parcel;
21import android.os.Parcelable;
22
23/**
24 * Represents verification parameters used to verify packages to be installed.
25 *
Jeff Sharkeya0907432014-08-15 10:23:11 -070026 * @deprecated callers should migrate to {@link PackageInstaller}.
rich cannings706e8ba2012-08-20 13:20:14 -070027 * @hide
28 */
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -070029@Deprecated
rich cannings706e8ba2012-08-20 13:20:14 -070030public class VerificationParams implements Parcelable {
Ben Gruver37d83a32012-09-27 13:02:06 -070031 /** A constant used to indicate that a uid value is not present. */
32 public static final int NO_UID = -1;
33
rich cannings706e8ba2012-08-20 13:20:14 -070034 /** What we print out first when toString() is called. */
35 private static final String TO_STRING_PREFIX = "VerificationParams{";
36
37 /** The location of the supplementary verification file. */
38 private final Uri mVerificationURI;
39
40 /** URI referencing where the package was downloaded from. */
41 private final Uri mOriginatingURI;
42
43 /** HTTP referrer URI associated with the originatingURI. */
44 private final Uri mReferrer;
45
Ben Gruver37d83a32012-09-27 13:02:06 -070046 /** UID of the application that the install request originated from. */
47 private final int mOriginatingUid;
48
rich cannings13d428e2012-09-13 13:43:07 -070049 /** UID of application requesting the install */
50 private int mInstallerUid;
51
rich cannings706e8ba2012-08-20 13:20:14 -070052 /**
rich cannings706e8ba2012-08-20 13:20:14 -070053 * Creates verification specifications for installing with application verification.
54 *
55 * @param verificationURI The location of the supplementary verification
56 * file. This can be a 'file:' or a 'content:' URI. May be {@code null}.
57 * @param originatingURI URI referencing where the package was downloaded
58 * from. May be {@code null}.
59 * @param referrer HTTP referrer URI associated with the originatingURI.
60 * May be {@code null}.
Ben Gruver37d83a32012-09-27 13:02:06 -070061 * @param originatingUid UID of the application that the install request originated
62 * from, or NO_UID if not present
rich cannings706e8ba2012-08-20 13:20:14 -070063 */
64 public VerificationParams(Uri verificationURI, Uri originatingURI, Uri referrer,
Alex Klyubin31ffb442015-12-21 11:32:53 -080065 int originatingUid) {
rich cannings706e8ba2012-08-20 13:20:14 -070066 mVerificationURI = verificationURI;
67 mOriginatingURI = originatingURI;
68 mReferrer = referrer;
Ben Gruver37d83a32012-09-27 13:02:06 -070069 mOriginatingUid = originatingUid;
Ben Gruver37d83a32012-09-27 13:02:06 -070070 mInstallerUid = NO_UID;
rich cannings706e8ba2012-08-20 13:20:14 -070071 }
72
73 public Uri getVerificationURI() {
74 return mVerificationURI;
75 }
76
77 public Uri getOriginatingURI() {
78 return mOriginatingURI;
79 }
80
81 public Uri getReferrer() {
82 return mReferrer;
83 }
84
Ben Gruver37d83a32012-09-27 13:02:06 -070085 /** return NO_UID if not available */
86 public int getOriginatingUid() {
87 return mOriginatingUid;
88 }
89
Ben Gruver37d83a32012-09-27 13:02:06 -070090 /** @return NO_UID when not set */
rich cannings13d428e2012-09-13 13:43:07 -070091 public int getInstallerUid() {
92 return mInstallerUid;
93 }
94
95 public void setInstallerUid(int uid) {
96 mInstallerUid = uid;
97 }
98
rich cannings706e8ba2012-08-20 13:20:14 -070099 @Override
100 public int describeContents() {
101 return 0;
102 }
103
104 @Override
105 public boolean equals(Object o) {
106 if (this == o) {
107 return true;
108 }
109
110 if (!(o instanceof VerificationParams)) {
111 return false;
112 }
113
114 final VerificationParams other = (VerificationParams) o;
115
Ben Gruver37d83a32012-09-27 13:02:06 -0700116 if (mVerificationURI == null) {
117 if (other.mVerificationURI != null) {
118 return false;
119 }
120 } else if (!mVerificationURI.equals(other.mVerificationURI)) {
rich cannings706e8ba2012-08-20 13:20:14 -0700121 return false;
122 }
123
Ben Gruver37d83a32012-09-27 13:02:06 -0700124 if (mOriginatingURI == null) {
125 if (other.mOriginatingURI != null) {
126 return false;
127 }
128 } else if (!mOriginatingURI.equals(other.mOriginatingURI)) {
rich cannings706e8ba2012-08-20 13:20:14 -0700129 return false;
130 }
131
Ben Gruver37d83a32012-09-27 13:02:06 -0700132 if (mReferrer == null) {
133 if (other.mReferrer != null) {
134 return false;
135 }
136 } else if (!mReferrer.equals(other.mReferrer)) {
rich cannings706e8ba2012-08-20 13:20:14 -0700137 return false;
138 }
139
Ben Gruver37d83a32012-09-27 13:02:06 -0700140 if (mOriginatingUid != other.mOriginatingUid) {
rich cannings706e8ba2012-08-20 13:20:14 -0700141 return false;
142 }
Ben Gruver37d83a32012-09-27 13:02:06 -0700143
rich cannings13d428e2012-09-13 13:43:07 -0700144 if (mInstallerUid != other.mInstallerUid) {
145 return false;
146 }
147
rich cannings706e8ba2012-08-20 13:20:14 -0700148 return true;
149 }
150
151 @Override
152 public int hashCode() {
153 int hash = 3;
154
Ben Gruver37d83a32012-09-27 13:02:06 -0700155 hash += 5 * (mVerificationURI == null ? 1 : mVerificationURI.hashCode());
156 hash += 7 * (mOriginatingURI == null ? 1 : mOriginatingURI.hashCode());
157 hash += 11 * (mReferrer == null ? 1 : mReferrer.hashCode());
158 hash += 13 * mOriginatingUid;
Alex Klyubin31ffb442015-12-21 11:32:53 -0800159 hash += 17 * mInstallerUid;
rich cannings706e8ba2012-08-20 13:20:14 -0700160
161 return hash;
162 }
163
164 @Override
165 public String toString() {
166 final StringBuilder sb = new StringBuilder(TO_STRING_PREFIX);
167
168 sb.append("mVerificationURI=");
169 sb.append(mVerificationURI.toString());
170 sb.append(",mOriginatingURI=");
171 sb.append(mOriginatingURI.toString());
172 sb.append(",mReferrer=");
173 sb.append(mReferrer.toString());
Ben Gruver37d83a32012-09-27 13:02:06 -0700174 sb.append(",mOriginatingUid=");
175 sb.append(mOriginatingUid);
rich cannings13d428e2012-09-13 13:43:07 -0700176 sb.append(",mInstallerUid=");
177 sb.append(mInstallerUid);
rich cannings706e8ba2012-08-20 13:20:14 -0700178 sb.append('}');
179
180 return sb.toString();
181 }
182
183 @Override
184 public void writeToParcel(Parcel dest, int flags) {
185 dest.writeParcelable(mVerificationURI, 0);
186 dest.writeParcelable(mOriginatingURI, 0);
187 dest.writeParcelable(mReferrer, 0);
Ben Gruver37d83a32012-09-27 13:02:06 -0700188 dest.writeInt(mOriginatingUid);
rich cannings13d428e2012-09-13 13:43:07 -0700189 dest.writeInt(mInstallerUid);
rich cannings706e8ba2012-08-20 13:20:14 -0700190 }
191
192
193 private VerificationParams(Parcel source) {
194 mVerificationURI = source.readParcelable(Uri.class.getClassLoader());
195 mOriginatingURI = source.readParcelable(Uri.class.getClassLoader());
196 mReferrer = source.readParcelable(Uri.class.getClassLoader());
Ben Gruver37d83a32012-09-27 13:02:06 -0700197 mOriginatingUid = source.readInt();
rich cannings13d428e2012-09-13 13:43:07 -0700198 mInstallerUid = source.readInt();
rich cannings706e8ba2012-08-20 13:20:14 -0700199 }
200
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700201 public static final @android.annotation.NonNull Parcelable.Creator<VerificationParams> CREATOR =
rich cannings706e8ba2012-08-20 13:20:14 -0700202 new Parcelable.Creator<VerificationParams>() {
203 public VerificationParams createFromParcel(Parcel source) {
204 return new VerificationParams(source);
205 }
206
207 public VerificationParams[] newArray(int size) {
208 return new VerificationParams[size];
209 }
210 };
211}