Home | History | Annotate | Download | only in pm
      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  *
     27  * @deprecated callers should migrate to {@link PackageInstaller}.
     28  * @hide
     29  */
     30 @Deprecated
     31 public class VerificationParams implements Parcelable {
     32     /** A constant used to indicate that a uid value is not present. */
     33     public static final int NO_UID = -1;
     34 
     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 
     47     /** UID of the application that the install request originated from. */
     48     private final int mOriginatingUid;
     49 
     50     /** UID of application requesting the install */
     51     private int mInstallerUid;
     52 
     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}.
     68      * @param originatingUid UID of the application that the install request originated
     69      *            from, or NO_UID if not present
     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,
     74             int originatingUid, ManifestDigest manifestDigest) {
     75         mVerificationURI = verificationURI;
     76         mOriginatingURI = originatingURI;
     77         mReferrer = referrer;
     78         mOriginatingUid = originatingUid;
     79         mManifestDigest = manifestDigest;
     80         mInstallerUid = NO_UID;
     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 
     95     /** return NO_UID if not available */
     96     public int getOriginatingUid() {
     97         return mOriginatingUid;
     98     }
     99 
    100     public ManifestDigest getManifestDigest() {
    101         return mManifestDigest;
    102     }
    103 
    104     /** @return NO_UID when not set */
    105     public int getInstallerUid() {
    106         return mInstallerUid;
    107     }
    108 
    109     public void setInstallerUid(int uid) {
    110         mInstallerUid = uid;
    111     }
    112 
    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 
    130         if (mVerificationURI == null) {
    131             if (other.mVerificationURI != null) {
    132                 return false;
    133             }
    134         } else if (!mVerificationURI.equals(other.mVerificationURI)) {
    135             return false;
    136         }
    137 
    138         if (mOriginatingURI == null) {
    139             if (other.mOriginatingURI != null) {
    140                 return false;
    141             }
    142         } else if (!mOriginatingURI.equals(other.mOriginatingURI)) {
    143             return false;
    144         }
    145 
    146         if (mReferrer == null) {
    147             if (other.mReferrer != null) {
    148                 return false;
    149             }
    150         } else if (!mReferrer.equals(other.mReferrer)) {
    151             return false;
    152         }
    153 
    154         if (mOriginatingUid != other.mOriginatingUid) {
    155             return false;
    156         }
    157 
    158         if (mManifestDigest == null) {
    159             if (other.mManifestDigest != null) {
    160                 return false;
    161             }
    162         } else if (!mManifestDigest.equals(other.mManifestDigest)) {
    163             return false;
    164         }
    165 
    166         if (mInstallerUid != other.mInstallerUid) {
    167             return false;
    168         }
    169 
    170         return true;
    171     }
    172 
    173     @Override
    174     public int hashCode() {
    175         int hash = 3;
    176 
    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;
    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());
    197         sb.append(",mOriginatingUid=");
    198         sb.append(mOriginatingUid);
    199         sb.append(",mManifestDigest=");
    200         sb.append(mManifestDigest.toString());
    201         sb.append(",mInstallerUid=");
    202         sb.append(mInstallerUid);
    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);
    213         dest.writeInt(mOriginatingUid);
    214         dest.writeParcelable(mManifestDigest, 0);
    215         dest.writeInt(mInstallerUid);
    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());
    223         mOriginatingUid = source.readInt();
    224         mManifestDigest = source.readParcelable(ManifestDigest.class.getClassLoader());
    225         mInstallerUid = source.readInt();
    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 }
    239