rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.content.pm; |
| 18 | |
| 19 | import android.content.pm.ManifestDigest; |
| 20 | import android.net.Uri; |
| 21 | import android.os.Parcel; |
| 22 | import android.os.Parcelable; |
| 23 | |
| 24 | /** |
| 25 | * Represents verification parameters used to verify packages to be installed. |
| 26 | * |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame^] | 27 | * @deprecated callers should migrate to {@link PackageInstaller}. |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 28 | * @hide |
| 29 | */ |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 30 | @Deprecated |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 31 | public class VerificationParams implements Parcelable { |
Ben Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 32 | /** A constant used to indicate that a uid value is not present. */ |
| 33 | public static final int NO_UID = -1; |
| 34 | |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 35 | /** 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 Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 47 | /** UID of the application that the install request originated from. */ |
| 48 | private final int mOriginatingUid; |
| 49 | |
rich cannings | 13d428e | 2012-09-13 13:43:07 -0700 | [diff] [blame] | 50 | /** UID of application requesting the install */ |
| 51 | private int mInstallerUid; |
| 52 | |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 53 | /** |
| 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 Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 68 | * @param originatingUid UID of the application that the install request originated |
| 69 | * from, or NO_UID if not present |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 70 | * @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 Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 74 | int originatingUid, ManifestDigest manifestDigest) { |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 75 | mVerificationURI = verificationURI; |
| 76 | mOriginatingURI = originatingURI; |
| 77 | mReferrer = referrer; |
Ben Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 78 | mOriginatingUid = originatingUid; |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 79 | mManifestDigest = manifestDigest; |
Ben Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 80 | mInstallerUid = NO_UID; |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 81 | } |
| 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 Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 95 | /** return NO_UID if not available */ |
| 96 | public int getOriginatingUid() { |
| 97 | return mOriginatingUid; |
| 98 | } |
| 99 | |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 100 | public ManifestDigest getManifestDigest() { |
| 101 | return mManifestDigest; |
| 102 | } |
| 103 | |
Ben Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 104 | /** @return NO_UID when not set */ |
rich cannings | 13d428e | 2012-09-13 13:43:07 -0700 | [diff] [blame] | 105 | public int getInstallerUid() { |
| 106 | return mInstallerUid; |
| 107 | } |
| 108 | |
| 109 | public void setInstallerUid(int uid) { |
| 110 | mInstallerUid = uid; |
| 111 | } |
| 112 | |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 113 | @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 Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 130 | if (mVerificationURI == null) { |
| 131 | if (other.mVerificationURI != null) { |
| 132 | return false; |
| 133 | } |
| 134 | } else if (!mVerificationURI.equals(other.mVerificationURI)) { |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 135 | return false; |
| 136 | } |
| 137 | |
Ben Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 138 | if (mOriginatingURI == null) { |
| 139 | if (other.mOriginatingURI != null) { |
| 140 | return false; |
| 141 | } |
| 142 | } else if (!mOriginatingURI.equals(other.mOriginatingURI)) { |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 143 | return false; |
| 144 | } |
| 145 | |
Ben Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 146 | if (mReferrer == null) { |
| 147 | if (other.mReferrer != null) { |
| 148 | return false; |
| 149 | } |
| 150 | } else if (!mReferrer.equals(other.mReferrer)) { |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 151 | return false; |
| 152 | } |
| 153 | |
Ben Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 154 | if (mOriginatingUid != other.mOriginatingUid) { |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 155 | return false; |
| 156 | } |
Ben Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 157 | |
| 158 | if (mManifestDigest == null) { |
| 159 | if (other.mManifestDigest != null) { |
| 160 | return false; |
| 161 | } |
| 162 | } else if (!mManifestDigest.equals(other.mManifestDigest)) { |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 163 | return false; |
| 164 | } |
| 165 | |
rich cannings | 13d428e | 2012-09-13 13:43:07 -0700 | [diff] [blame] | 166 | if (mInstallerUid != other.mInstallerUid) { |
| 167 | return false; |
| 168 | } |
| 169 | |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 170 | return true; |
| 171 | } |
| 172 | |
| 173 | @Override |
| 174 | public int hashCode() { |
| 175 | int hash = 3; |
| 176 | |
Ben Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 177 | 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 cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 183 | |
| 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 Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 197 | sb.append(",mOriginatingUid="); |
| 198 | sb.append(mOriginatingUid); |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 199 | sb.append(",mManifestDigest="); |
| 200 | sb.append(mManifestDigest.toString()); |
rich cannings | 13d428e | 2012-09-13 13:43:07 -0700 | [diff] [blame] | 201 | sb.append(",mInstallerUid="); |
| 202 | sb.append(mInstallerUid); |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 203 | 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 Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 213 | dest.writeInt(mOriginatingUid); |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 214 | dest.writeParcelable(mManifestDigest, 0); |
rich cannings | 13d428e | 2012-09-13 13:43:07 -0700 | [diff] [blame] | 215 | dest.writeInt(mInstallerUid); |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 216 | } |
| 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 Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 223 | mOriginatingUid = source.readInt(); |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 224 | mManifestDigest = source.readParcelable(ManifestDigest.class.getClassLoader()); |
rich cannings | 13d428e | 2012-09-13 13:43:07 -0700 | [diff] [blame] | 225 | mInstallerUid = source.readInt(); |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 226 | } |
| 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 | } |