CellInfoCdma.java revision 3caf66d2ea63c75039daf43af30d3727e5ce6b58
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 CellInfoCdma extends CellInfo implements Parcelable {
27
28    private static final String LOG_TAG = "CellInfoCdma";
29    private static final boolean DBG = false;
30
31    private CellIdentityCdma mCellIdentityCdma;
32    private CellSignalStrengthCdma mCellSignalStrengthCdma;
33
34    /** @hide */
35    public CellInfoCdma() {
36        super();
37        mCellIdentityCdma = new CellIdentityCdma();
38        mCellSignalStrengthCdma = new CellSignalStrengthCdma();
39    }
40
41    /** @hide */
42    public CellInfoCdma(CellInfoCdma ci) {
43        super(ci);
44        this.mCellIdentityCdma = ci.mCellIdentityCdma.copy();
45        this.mCellSignalStrengthCdma = ci.mCellSignalStrengthCdma.copy();
46    }
47
48    public CellIdentityCdma getCellIdentity() {
49        return mCellIdentityCdma;
50    }
51    /** @hide */
52    public void setCellIdentity(CellIdentityCdma cid) {
53        mCellIdentityCdma = cid;
54    }
55
56    public CellSignalStrengthCdma getCellSignalStrength() {
57        return mCellSignalStrengthCdma;
58    }
59    /** @hide */
60    public void setCellSignalStrength(CellSignalStrengthCdma css) {
61        mCellSignalStrengthCdma = css;
62    }
63
64    /**
65     * @return hash code
66     */
67    @Override
68    public int hashCode() {
69        return super.hashCode() + mCellIdentityCdma.hashCode() + mCellSignalStrengthCdma.hashCode();
70    }
71
72    @Override
73    public boolean equals(Object other) {
74        if (!super.equals(other)) {
75            return false;
76        }
77        try {
78            CellInfoCdma o = (CellInfoCdma) other;
79            return mCellIdentityCdma.equals(o.mCellIdentityCdma)
80                    && mCellSignalStrengthCdma.equals(o.mCellSignalStrengthCdma);
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("CellInfoCdma:");
91        sb.append(super.toString());
92        sb.append(", ").append(mCellIdentityCdma);
93        sb.append(", ").append(mCellSignalStrengthCdma);
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        if (DBG) log("writeToParcel(Parcel, int): " + toString());
108        dest.writeInt(TYPE_LTE);
109        super.writeToParcel(dest, flags);
110        mCellIdentityCdma.writeToParcel(dest, flags);
111        mCellSignalStrengthCdma.writeToParcel(dest, flags);
112    }
113
114    /**
115     * Construct a CellInfoCdma object from the given parcel
116     * where the token is already been processed.
117     */
118    private CellInfoCdma(Parcel in) {
119        super(in);
120        mCellIdentityCdma = CellIdentityCdma.CREATOR.createFromParcel(in);
121        mCellSignalStrengthCdma = CellSignalStrengthCdma.CREATOR.createFromParcel(in);
122        if (DBG) log("CellInfoCdma(Parcel): " + toString());
123    }
124
125    /** Implement the Parcelable interface */
126    public static final Creator<CellInfoCdma> CREATOR = new Creator<CellInfoCdma>() {
127        @Override
128        public CellInfoCdma createFromParcel(Parcel in) {
129            in.readInt(); // Skip past token, we know what it is
130            return createFromParcelBody(in);
131        }
132
133        @Override
134        public CellInfoCdma[] newArray(int size) {
135            return new CellInfoCdma[size];
136        }
137    };
138
139    /** @hide */
140    protected static CellInfoCdma createFromParcelBody(Parcel in) {
141        return new CellInfoCdma(in);
142    }
143
144    /**
145     * log
146     */
147    private static void log(String s) {
148        Log.w(LOG_TAG, s);
149    }
150}
151