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 CellInfoLte extends CellInfo implements Parcelable {
27
28    private static final String LOG_TAG = "CellInfoLte";
29    private static final boolean DBG = true;
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
99        return sb.toString();
100    }
101
102    /** Implement the Parcelable interface */
103    @Override
104    public int describeContents() {
105        return 0;
106    }
107
108    /** Implement the Parcelable interface */
109    @Override
110    public void writeToParcel(Parcel dest, int flags) {
111        if (DBG) log("writeToParcel(Parcel, int): " + toString());
112        super.writeToParcel(dest, flags, TYPE_LTE);
113        mCellIdentityLte.writeToParcel(dest, flags);
114        mCellSignalStrengthLte.writeToParcel(dest, flags);
115    }
116
117    /**
118     * Construct a CellInfoLte object from the given parcel
119     * where the TYPE_LTE token is already been processed.
120     */
121    private CellInfoLte(Parcel in) {
122        super(in);
123        mCellIdentityLte = CellIdentityLte.CREATOR.createFromParcel(in);
124        mCellSignalStrengthLte = CellSignalStrengthLte.CREATOR.createFromParcel(in);
125        if (DBG) log("CellInfoLte(Parcel): " + toString());
126    }
127
128    /** Implement the Parcelable interface */
129    public static final Creator<CellInfoLte> CREATOR = new Creator<CellInfoLte>() {
130        @Override
131        public CellInfoLte createFromParcel(Parcel in) {
132            in.readInt(); // Skip past token, we know what it is
133            return createFromParcelBody(in);
134        }
135
136        @Override
137        public CellInfoLte[] newArray(int size) {
138            return new CellInfoLte[size];
139        }
140    };
141
142    /** @hide */
143    protected static CellInfoLte createFromParcelBody(Parcel in) {
144        return new CellInfoLte(in);
145    }
146
147    /**
148     * log
149     */
150    private static void log(String s) {
151        Log.w(LOG_TAG, s);
152    }
153}
154