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