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.os.IBinder;
20import android.os.Parcel;
21import android.os.Parcelable;
22
23/**
24 * Represents a {@code KeySet} that has been declared in the AndroidManifest.xml
25 * file for the application.  A {@code KeySet} can be used explicitly to
26 * represent a trust relationship with other applications on the device.
27 * @hide
28 */
29public class KeySet implements Parcelable {
30
31    private IBinder token;
32
33    /** @hide */
34    public KeySet(IBinder token) {
35        if (token == null) {
36            throw new NullPointerException("null value for KeySet IBinder token");
37        }
38        this.token = token;
39    }
40
41    /** @hide */
42    public IBinder getToken() {
43        return token;
44    }
45
46    /** @hide */
47    @Override
48    public boolean equals(Object o) {
49        if (o instanceof KeySet) {
50            KeySet ks = (KeySet) o;
51            return token == ks.token;
52        }
53        return false;
54    }
55
56    /** @hide */
57    @Override
58    public int hashCode() {
59        return token.hashCode();
60    }
61
62    /**
63     * Implement Parcelable
64     * @hide
65     */
66    public static final Parcelable.Creator<KeySet> CREATOR
67            = new Parcelable.Creator<KeySet>() {
68
69        /**
70         * Create a KeySet from a Parcel
71         *
72         * @param in The parcel containing the KeySet
73         */
74        public KeySet createFromParcel(Parcel source) {
75            return readFromParcel(source);
76        }
77
78        /**
79         * Create an array of null KeySets
80         */
81        public KeySet[] newArray(int size) {
82            return new KeySet[size];
83        }
84    };
85
86    /**
87     * @hide
88     */
89    private static KeySet readFromParcel(Parcel in) {
90        IBinder token = in.readStrongBinder();
91        return new KeySet(token);
92    }
93
94    /**
95     * @hide
96     */
97    @Override
98    public void writeToParcel(Parcel out, int flags) {
99        out.writeStrongBinder(token);
100    }
101
102    /**
103     * @hide
104     */
105    @Override
106    public int describeContents() {
107        return 0;
108    }
109}