summaryrefslogtreecommitdiffstats
path: root/core/java/android/content/pm/VerificationParams.java
blob: bf1f77f6826e9824855a191973b5b56264bfcf89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.content.pm;

import android.content.pm.ManifestDigest;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;

/**
 * Represents verification parameters used to verify packages to be installed.
 *
 * @deprecated callers should migrate to {@link PackageInstallerParams}.
 * @hide
 */
@Deprecated
public class VerificationParams implements Parcelable {
    /** A constant used to indicate that a uid value is not present. */
    public static final int NO_UID = -1;

    /** What we print out first when toString() is called. */
    private static final String TO_STRING_PREFIX = "VerificationParams{";

    /** The location of the supplementary verification file. */
    private final Uri mVerificationURI;

    /** URI referencing where the package was downloaded from. */
    private final Uri mOriginatingURI;

    /** HTTP referrer URI associated with the originatingURI. */
    private final Uri mReferrer;

    /** UID of the application that the install request originated from. */
    private final int mOriginatingUid;

    /** UID of application requesting the install */
    private int mInstallerUid;

    /**
     * An object that holds the digest of the package which can be used to
     * verify ownership.
     */
    private final ManifestDigest mManifestDigest;

    /**
     * Creates verification specifications for installing with application verification.
     *
     * @param verificationURI The location of the supplementary verification
     *            file. This can be a 'file:' or a 'content:' URI. May be {@code null}.
     * @param originatingURI URI referencing where the package was downloaded
     *            from. May be {@code null}.
     * @param referrer HTTP referrer URI associated with the originatingURI.
     *            May be {@code null}.
     * @param originatingUid UID of the application that the install request originated
     *            from, or NO_UID if not present
     * @param manifestDigest an object that holds the digest of the package
     *            which can be used to verify ownership. May be {@code null}.
     */
    public VerificationParams(Uri verificationURI, Uri originatingURI, Uri referrer,
            int originatingUid, ManifestDigest manifestDigest) {
        mVerificationURI = verificationURI;
        mOriginatingURI = originatingURI;
        mReferrer = referrer;
        mOriginatingUid = originatingUid;
        mManifestDigest = manifestDigest;
        mInstallerUid = NO_UID;
    }

    public Uri getVerificationURI() {
        return mVerificationURI;
    }

    public Uri getOriginatingURI() {
        return mOriginatingURI;
    }

    public Uri getReferrer() {
        return mReferrer;
    }

    /** return NO_UID if not available */
    public int getOriginatingUid() {
        return mOriginatingUid;
    }

    public ManifestDigest getManifestDigest() {
        return mManifestDigest;
    }

    /** @return NO_UID when not set */
    public int getInstallerUid() {
        return mInstallerUid;
    }

    public void setInstallerUid(int uid) {
        mInstallerUid = uid;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }

        if (!(o instanceof VerificationParams)) {
            return false;
        }

        final VerificationParams other = (VerificationParams) o;

        if (mVerificationURI == null) {
            if (other.mVerificationURI != null) {
                return false;
            }
        } else if (!mVerificationURI.equals(other.mVerificationURI)) {
            return false;
        }

        if (mOriginatingURI == null) {
            if (other.mOriginatingURI != null) {
                return false;
            }
        } else if (!mOriginatingURI.equals(other.mOriginatingURI)) {
            return false;
        }

        if (mReferrer == null) {
            if (other.mReferrer != null) {
                return false;
            }
        } else if (!mReferrer.equals(other.mReferrer)) {
            return false;
        }

        if (mOriginatingUid != other.mOriginatingUid) {
            return false;
        }

        if (mManifestDigest == null) {
            if (other.mManifestDigest != null) {
                return false;
            }
        } else if (!mManifestDigest.equals(other.mManifestDigest)) {
            return false;
        }

        if (mInstallerUid != other.mInstallerUid) {
            return false;
        }

        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;

        hash += 5 * (mVerificationURI == null ? 1 : mVerificationURI.hashCode());
        hash += 7 * (mOriginatingURI == null ? 1 : mOriginatingURI.hashCode());
        hash += 11 * (mReferrer == null ? 1 : mReferrer.hashCode());
        hash += 13 * mOriginatingUid;
        hash += 17 * (mManifestDigest == null ? 1 : mManifestDigest.hashCode());
        hash += 19 * mInstallerUid;

        return hash;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder(TO_STRING_PREFIX);

        sb.append("mVerificationURI=");
        sb.append(mVerificationURI.toString());
        sb.append(",mOriginatingURI=");
        sb.append(mOriginatingURI.toString());
        sb.append(",mReferrer=");
        sb.append(mReferrer.toString());
        sb.append(",mOriginatingUid=");
        sb.append(mOriginatingUid);
        sb.append(",mManifestDigest=");
        sb.append(mManifestDigest.toString());
        sb.append(",mInstallerUid=");
        sb.append(mInstallerUid);
        sb.append('}');

        return sb.toString();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeParcelable(mVerificationURI, 0);
        dest.writeParcelable(mOriginatingURI, 0);
        dest.writeParcelable(mReferrer, 0);
        dest.writeInt(mOriginatingUid);
        dest.writeParcelable(mManifestDigest, 0);
        dest.writeInt(mInstallerUid);
    }


    private VerificationParams(Parcel source) {
        mVerificationURI = source.readParcelable(Uri.class.getClassLoader());
        mOriginatingURI = source.readParcelable(Uri.class.getClassLoader());
        mReferrer = source.readParcelable(Uri.class.getClassLoader());
        mOriginatingUid = source.readInt();
        mManifestDigest = source.readParcelable(ManifestDigest.class.getClassLoader());
        mInstallerUid = source.readInt();
    }

    public static final Parcelable.Creator<VerificationParams> CREATOR =
            new Parcelable.Creator<VerificationParams>() {
        public VerificationParams createFromParcel(Parcel source) {
                return new VerificationParams(source);
        }

        public VerificationParams[] newArray(int size) {
            return new VerificationParams[size];
        }
    };
}