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.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 * 26 * @deprecated callers should migrate to {@link PackageInstaller}. 27 * @hide 28 */ 29 @Deprecated 30 public class VerificationParams implements Parcelable { 31 /** A constant used to indicate that a uid value is not present. */ 32 public static final int NO_UID = -1; 33 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 46 /** UID of the application that the install request originated from. */ 47 private final int mOriginatingUid; 48 49 /** UID of application requesting the install */ 50 private int mInstallerUid; 51 52 /** 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}. 61 * @param originatingUid UID of the application that the install request originated 62 * from, or NO_UID if not present 63 */ VerificationParams(Uri verificationURI, Uri originatingURI, Uri referrer, int originatingUid)64 public VerificationParams(Uri verificationURI, Uri originatingURI, Uri referrer, 65 int originatingUid) { 66 mVerificationURI = verificationURI; 67 mOriginatingURI = originatingURI; 68 mReferrer = referrer; 69 mOriginatingUid = originatingUid; 70 mInstallerUid = NO_UID; 71 } 72 getVerificationURI()73 public Uri getVerificationURI() { 74 return mVerificationURI; 75 } 76 getOriginatingURI()77 public Uri getOriginatingURI() { 78 return mOriginatingURI; 79 } 80 getReferrer()81 public Uri getReferrer() { 82 return mReferrer; 83 } 84 85 /** return NO_UID if not available */ getOriginatingUid()86 public int getOriginatingUid() { 87 return mOriginatingUid; 88 } 89 90 /** @return NO_UID when not set */ getInstallerUid()91 public int getInstallerUid() { 92 return mInstallerUid; 93 } 94 setInstallerUid(int uid)95 public void setInstallerUid(int uid) { 96 mInstallerUid = uid; 97 } 98 99 @Override describeContents()100 public int describeContents() { 101 return 0; 102 } 103 104 @Override equals(Object o)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 116 if (mVerificationURI == null) { 117 if (other.mVerificationURI != null) { 118 return false; 119 } 120 } else if (!mVerificationURI.equals(other.mVerificationURI)) { 121 return false; 122 } 123 124 if (mOriginatingURI == null) { 125 if (other.mOriginatingURI != null) { 126 return false; 127 } 128 } else if (!mOriginatingURI.equals(other.mOriginatingURI)) { 129 return false; 130 } 131 132 if (mReferrer == null) { 133 if (other.mReferrer != null) { 134 return false; 135 } 136 } else if (!mReferrer.equals(other.mReferrer)) { 137 return false; 138 } 139 140 if (mOriginatingUid != other.mOriginatingUid) { 141 return false; 142 } 143 144 if (mInstallerUid != other.mInstallerUid) { 145 return false; 146 } 147 148 return true; 149 } 150 151 @Override hashCode()152 public int hashCode() { 153 int hash = 3; 154 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; 159 hash += 17 * mInstallerUid; 160 161 return hash; 162 } 163 164 @Override toString()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()); 174 sb.append(",mOriginatingUid="); 175 sb.append(mOriginatingUid); 176 sb.append(",mInstallerUid="); 177 sb.append(mInstallerUid); 178 sb.append('}'); 179 180 return sb.toString(); 181 } 182 183 @Override writeToParcel(Parcel dest, int flags)184 public void writeToParcel(Parcel dest, int flags) { 185 dest.writeParcelable(mVerificationURI, 0); 186 dest.writeParcelable(mOriginatingURI, 0); 187 dest.writeParcelable(mReferrer, 0); 188 dest.writeInt(mOriginatingUid); 189 dest.writeInt(mInstallerUid); 190 } 191 192 VerificationParams(Parcel source)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()); 197 mOriginatingUid = source.readInt(); 198 mInstallerUid = source.readInt(); 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 } 212