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.telephony;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21import android.util.Log;
22
23/**
24 * Immutable cell information from a point in time.
25 */
26public final class CellInfoGsm extends CellInfo implements Parcelable {
27
28    private static final String LOG_TAG = "CellInfoGsm";
29    private static final boolean DBG = false;
30
31    private CellIdentityGsm mCellIdentityGsm;
32    private CellSignalStrengthGsm mCellSignalStrengthGsm;
33
34    /** @hide */
35    public CellInfoGsm() {
36        super();
37        mCellIdentityGsm = new CellIdentityGsm();
38        mCellSignalStrengthGsm = new CellSignalStrengthGsm();
39    }
40
41    /** @hide */
42    public CellInfoGsm(CellInfoGsm ci) {
43        super(ci);
44        this.mCellIdentityGsm = ci.mCellIdentityGsm.copy();
45        this.mCellSignalStrengthGsm = ci.mCellSignalStrengthGsm.copy();
46    }
47
48    public CellIdentityGsm getCellIdentity() {
49        return mCellIdentityGsm;
50    }
51    /** @hide */
52    public void setCellIdentity(CellIdentityGsm cid) {
53        mCellIdentityGsm = cid;
54    }
55
56    public CellSignalStrengthGsm getCellSignalStrength() {
57        return mCellSignalStrengthGsm;
58    }
59    /** @hide */
60    public void setCellSignalStrength(CellSignalStrengthGsm css) {
61        mCellSignalStrengthGsm = css;
62    }
63
64    /**
65     * @return hash code
66     */
67    @Override
68    public int hashCode() {
69        return super.hashCode() + mCellIdentityGsm.hashCode() + mCellSignalStrengthGsm.hashCode();
70    }
71
72    @Override
73    public boolean equals(Object other) {
74        if (!super.equals(other)) {
75            return false;
76        }
77        try {
78            CellInfoGsm o = (CellInfoGsm) other;
79            return mCellIdentityGsm.equals(o.mCellIdentityGsm)
80                    && mCellSignalStrengthGsm.equals(o.mCellSignalStrengthGsm);
81        } catch (ClassCastException e) {
82            return false;
83        }
84    }
85
86    @Override
87    public String toString() {
88        StringBuffer sb = new StringBuffer();
89
90        sb.append("CellInfoGsm:");
91        sb.append(super.toString());
92        sb.append(", ").append(mCellIdentityGsm);
93        sb.append(", ").append(mCellSignalStrengthGsm);
94
95        return sb.toString();
96    }
97
98    /** Implement the Parcelable interface */
99    @Override
100    public int describeContents() {
101        return 0;
102    }
103
104    /** Implement the Parcelable interface */
105    @Override
106    public void writeToParcel(Parcel dest, int flags) {
107        super.writeToParcel(dest, flags, TYPE_GSM);
108        mCellIdentityGsm.writeToParcel(dest, flags);
109        mCellSignalStrengthGsm.writeToParcel(dest, flags);
110    }
111
112    /**
113     * Construct a CellInfoGsm object from the given parcel
114     * where the token is already been processed.
115     */
116    private CellInfoGsm(Parcel in) {
117        super(in);
118        mCellIdentityGsm = CellIdentityGsm.CREATOR.createFromParcel(in);
119        mCellSignalStrengthGsm = CellSignalStrengthGsm.CREATOR.createFromParcel(in);
120    }
121
122    /** Implement the Parcelable interface */
123    public static final Creator<CellInfoGsm> CREATOR = new Creator<CellInfoGsm>() {
124        @Override
125        public CellInfoGsm createFromParcel(Parcel in) {
126            in.readInt(); // Skip past token, we know what it is
127            return createFromParcelBody(in);
128        }
129
130        @Override
131        public CellInfoGsm[] newArray(int size) {
132            return new CellInfoGsm[size];
133        }
134    };
135
136    /** @hide */
137    protected static CellInfoGsm createFromParcelBody(Parcel in) {
138        return new CellInfoGsm(in);
139    }
140
141    /**
142     * log
143     */
144    private static void log(String s) {
145        Log.w(LOG_TAG, s);
146    }
147}
148