VerificationParams.java revision 13d428e8306d1bb1a3017045bc5d2f76edec32df
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 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 * 27 * @hide 28 */ 29public class VerificationParams implements Parcelable { 30 /** What we print out first when toString() is called. */ 31 private static final String TO_STRING_PREFIX = "VerificationParams{"; 32 33 /** The location of the supplementary verification file. */ 34 private final Uri mVerificationURI; 35 36 /** URI referencing where the package was downloaded from. */ 37 private final Uri mOriginatingURI; 38 39 /** HTTP referrer URI associated with the originatingURI. */ 40 private final Uri mReferrer; 41 42 /** UID of application requesting the install */ 43 private int mInstallerUid; 44 45 /** 46 * An object that holds the digest of the package which can be used to 47 * verify ownership. 48 */ 49 private final ManifestDigest mManifestDigest; 50 51 /** 52 * Creates verification specifications for installing with application verification. 53 * 54 * @param verificationURI The location of the supplementary verification 55 * file. This can be a 'file:' or a 'content:' URI. May be {@code null}. 56 * @param originatingURI URI referencing where the package was downloaded 57 * from. May be {@code null}. 58 * @param referrer HTTP referrer URI associated with the originatingURI. 59 * May be {@code null}. 60 * @param manifestDigest an object that holds the digest of the package 61 * which can be used to verify ownership. May be {@code null}. 62 */ 63 public VerificationParams(Uri verificationURI, Uri originatingURI, Uri referrer, 64 ManifestDigest manifestDigest) { 65 mVerificationURI = verificationURI; 66 mOriginatingURI = originatingURI; 67 mReferrer = referrer; 68 mManifestDigest = manifestDigest; 69 mInstallerUid = -1; 70 } 71 72 public Uri getVerificationURI() { 73 return mVerificationURI; 74 } 75 76 public Uri getOriginatingURI() { 77 return mOriginatingURI; 78 } 79 80 public Uri getReferrer() { 81 return mReferrer; 82 } 83 84 public ManifestDigest getManifestDigest() { 85 return mManifestDigest; 86 } 87 88 /** @return -1 when not set */ 89 public int getInstallerUid() { 90 return mInstallerUid; 91 } 92 93 public void setInstallerUid(int uid) { 94 mInstallerUid = uid; 95 } 96 97 @Override 98 public int describeContents() { 99 return 0; 100 } 101 102 @Override 103 public boolean equals(Object o) { 104 if (this == o) { 105 return true; 106 } 107 108 if (!(o instanceof VerificationParams)) { 109 return false; 110 } 111 112 final VerificationParams other = (VerificationParams) o; 113 114 if (mVerificationURI == null && other.mVerificationURI != null) { 115 return false; 116 } 117 if (!mVerificationURI.equals(other.mVerificationURI)) { 118 return false; 119 } 120 121 if (mOriginatingURI == null && other.mOriginatingURI != null) { 122 return false; 123 } 124 if (!mOriginatingURI.equals(other.mOriginatingURI)) { 125 return false; 126 } 127 128 if (mReferrer == null && other.mReferrer != null) { 129 return false; 130 } 131 if (!mReferrer.equals(other.mReferrer)) { 132 return false; 133 } 134 135 if (mManifestDigest == null && other.mManifestDigest != null) { 136 return false; 137 } 138 if (mManifestDigest != null && !mManifestDigest.equals(other.mManifestDigest)) { 139 return false; 140 } 141 142 if (mInstallerUid != other.mInstallerUid) { 143 return false; 144 } 145 146 return true; 147 } 148 149 @Override 150 public int hashCode() { 151 int hash = 3; 152 153 hash += 5 * (mVerificationURI==null?1:mVerificationURI.hashCode()); 154 hash += 7 * (mOriginatingURI==null?1:mOriginatingURI.hashCode()); 155 hash += 11 * (mReferrer==null?1:mReferrer.hashCode()); 156 hash += 13 * (mManifestDigest==null?1:mManifestDigest.hashCode()); 157 hash += 17 * mInstallerUid; 158 159 return hash; 160 } 161 162 @Override 163 public String toString() { 164 final StringBuilder sb = new StringBuilder(TO_STRING_PREFIX); 165 166 sb.append("mVerificationURI="); 167 sb.append(mVerificationURI.toString()); 168 sb.append(",mOriginatingURI="); 169 sb.append(mOriginatingURI.toString()); 170 sb.append(",mReferrer="); 171 sb.append(mReferrer.toString()); 172 sb.append(",mManifestDigest="); 173 sb.append(mManifestDigest.toString()); 174 sb.append(",mInstallerUid="); 175 sb.append(mInstallerUid); 176 sb.append('}'); 177 178 return sb.toString(); 179 } 180 181 @Override 182 public void writeToParcel(Parcel dest, int flags) { 183 dest.writeParcelable(mVerificationURI, 0); 184 dest.writeParcelable(mOriginatingURI, 0); 185 dest.writeParcelable(mReferrer, 0); 186 dest.writeParcelable(mManifestDigest, 0); 187 dest.writeInt(mInstallerUid); 188 } 189 190 191 private VerificationParams(Parcel source) { 192 mVerificationURI = source.readParcelable(Uri.class.getClassLoader()); 193 mOriginatingURI = source.readParcelable(Uri.class.getClassLoader()); 194 mReferrer = source.readParcelable(Uri.class.getClassLoader()); 195 mManifestDigest = source.readParcelable(ManifestDigest.class.getClassLoader()); 196 mInstallerUid = source.readInt(); 197 } 198 199 public static final Parcelable.Creator<VerificationParams> CREATOR = 200 new Parcelable.Creator<VerificationParams>() { 201 public VerificationParams createFromParcel(Parcel source) { 202 return new VerificationParams(source); 203 } 204 205 public VerificationParams[] newArray(int size) { 206 return new VerificationParams[size]; 207 } 208 }; 209} 210