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 | |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 19 | import android.net.Uri; |
| 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
| 22 | |
| 23 | /** |
| 24 | * Represents verification parameters used to verify packages to be installed. |
| 25 | * |
Jeff Sharkey | a090743 | 2014-08-15 10:23:11 -0700 | [diff] [blame] | 26 | * @deprecated callers should migrate to {@link PackageInstaller}. |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 27 | * @hide |
| 28 | */ |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 29 | @Deprecated |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 30 | public class VerificationParams implements Parcelable { |
Ben Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 31 | /** A constant used to indicate that a uid value is not present. */ |
| 32 | public static final int NO_UID = -1; |
| 33 | |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 34 | /** 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 Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 46 | /** UID of the application that the install request originated from. */ |
| 47 | private final int mOriginatingUid; |
| 48 | |
rich cannings | 13d428e | 2012-09-13 13:43:07 -0700 | [diff] [blame] | 49 | /** UID of application requesting the install */ |
| 50 | private int mInstallerUid; |
| 51 | |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 52 | /** |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 53 | * 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 Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 61 | * @param originatingUid UID of the application that the install request originated |
| 62 | * from, or NO_UID if not present |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 63 | */ |
| 64 | public VerificationParams(Uri verificationURI, Uri originatingURI, Uri referrer, |
Alex Klyubin | 31ffb44 | 2015-12-21 11:32:53 -0800 | [diff] [blame^] | 65 | int originatingUid) { |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 66 | mVerificationURI = verificationURI; |
| 67 | mOriginatingURI = originatingURI; |
| 68 | mReferrer = referrer; |
Ben Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 69 | mOriginatingUid = originatingUid; |
Ben Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 70 | mInstallerUid = NO_UID; |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 71 | } |
| 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 Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 85 | /** return NO_UID if not available */ |
| 86 | public int getOriginatingUid() { |
| 87 | return mOriginatingUid; |
| 88 | } |
| 89 | |
Ben Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 90 | /** @return NO_UID when not set */ |
rich cannings | 13d428e | 2012-09-13 13:43:07 -0700 | [diff] [blame] | 91 | public int getInstallerUid() { |
| 92 | return mInstallerUid; |
| 93 | } |
| 94 | |
| 95 | public void setInstallerUid(int uid) { |
| 96 | mInstallerUid = uid; |
| 97 | } |
| 98 | |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 99 | @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 Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 116 | if (mVerificationURI == null) { |
| 117 | if (other.mVerificationURI != null) { |
| 118 | return false; |
| 119 | } |
| 120 | } else if (!mVerificationURI.equals(other.mVerificationURI)) { |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 121 | return false; |
| 122 | } |
| 123 | |
Ben Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 124 | if (mOriginatingURI == null) { |
| 125 | if (other.mOriginatingURI != null) { |
| 126 | return false; |
| 127 | } |
| 128 | } else if (!mOriginatingURI.equals(other.mOriginatingURI)) { |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 129 | return false; |
| 130 | } |
| 131 | |
Ben Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 132 | if (mReferrer == null) { |
| 133 | if (other.mReferrer != null) { |
| 134 | return false; |
| 135 | } |
| 136 | } else if (!mReferrer.equals(other.mReferrer)) { |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 137 | return false; |
| 138 | } |
| 139 | |
Ben Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 140 | if (mOriginatingUid != other.mOriginatingUid) { |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 141 | return false; |
| 142 | } |
Ben Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 143 | |
rich cannings | 13d428e | 2012-09-13 13:43:07 -0700 | [diff] [blame] | 144 | if (mInstallerUid != other.mInstallerUid) { |
| 145 | return false; |
| 146 | } |
| 147 | |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 148 | return true; |
| 149 | } |
| 150 | |
| 151 | @Override |
| 152 | public int hashCode() { |
| 153 | int hash = 3; |
| 154 | |
Ben Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 155 | 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 Klyubin | 31ffb44 | 2015-12-21 11:32:53 -0800 | [diff] [blame^] | 159 | hash += 17 * mInstallerUid; |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 160 | |
| 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 Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 174 | sb.append(",mOriginatingUid="); |
| 175 | sb.append(mOriginatingUid); |
rich cannings | 13d428e | 2012-09-13 13:43:07 -0700 | [diff] [blame] | 176 | sb.append(",mInstallerUid="); |
| 177 | sb.append(mInstallerUid); |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 178 | 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 Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 188 | dest.writeInt(mOriginatingUid); |
rich cannings | 13d428e | 2012-09-13 13:43:07 -0700 | [diff] [blame] | 189 | dest.writeInt(mInstallerUid); |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 190 | } |
| 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 Gruver | 37d83a3 | 2012-09-27 13:02:06 -0700 | [diff] [blame] | 197 | mOriginatingUid = source.readInt(); |
rich cannings | 13d428e | 2012-09-13 13:43:07 -0700 | [diff] [blame] | 198 | mInstallerUid = source.readInt(); |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | public static final Parcelable.Creator<VerificationParams> CREATOR = |
| 202 | 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 | } |