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