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