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 
22 import com.android.telephony.Rlog;
23 
24 import java.util.Objects;
25 
26 /**
27  * A {@link CellInfo} representing a WCDMA cell that provides identity and measurement info.
28  */
29 public final class CellInfoWcdma extends CellInfo implements Parcelable {
30 
31     private static final String LOG_TAG = "CellInfoWcdma";
32     private static final boolean DBG = false;
33 
34     private CellIdentityWcdma mCellIdentityWcdma;
35     private CellSignalStrengthWcdma mCellSignalStrengthWcdma;
36 
37     /** @hide */
CellInfoWcdma()38     public CellInfoWcdma() {
39         super();
40         mCellIdentityWcdma = new CellIdentityWcdma();
41         mCellSignalStrengthWcdma = new CellSignalStrengthWcdma();
42     }
43 
44     /** @hide */
CellInfoWcdma(CellInfoWcdma ci)45     public CellInfoWcdma(CellInfoWcdma ci) {
46         super(ci);
47         this.mCellIdentityWcdma = ci.mCellIdentityWcdma.copy();
48         this.mCellSignalStrengthWcdma = ci.mCellSignalStrengthWcdma.copy();
49     }
50 
51     /** @hide */
CellInfoWcdma(android.hardware.radio.V1_0.CellInfo ci)52     public CellInfoWcdma(android.hardware.radio.V1_0.CellInfo ci) {
53         super(ci);
54         final android.hardware.radio.V1_0.CellInfoWcdma ciw = ci.wcdma.get(0);
55         mCellIdentityWcdma = new CellIdentityWcdma(ciw.cellIdentityWcdma);
56         mCellSignalStrengthWcdma = new CellSignalStrengthWcdma(ciw.signalStrengthWcdma);
57     }
58 
59     /** @hide */
CellInfoWcdma(android.hardware.radio.V1_2.CellInfo ci)60     public CellInfoWcdma(android.hardware.radio.V1_2.CellInfo ci) {
61         super(ci);
62         final android.hardware.radio.V1_2.CellInfoWcdma ciw = ci.wcdma.get(0);
63         mCellIdentityWcdma = new CellIdentityWcdma(ciw.cellIdentityWcdma);
64         mCellSignalStrengthWcdma = new CellSignalStrengthWcdma(ciw.signalStrengthWcdma);
65     }
66 
67     /** @hide */
CellInfoWcdma(android.hardware.radio.V1_4.CellInfo ci, long timeStamp)68     public CellInfoWcdma(android.hardware.radio.V1_4.CellInfo ci, long timeStamp) {
69         super(ci, timeStamp);
70         final android.hardware.radio.V1_2.CellInfoWcdma ciw = ci.info.wcdma();
71         mCellIdentityWcdma = new CellIdentityWcdma(ciw.cellIdentityWcdma);
72         mCellSignalStrengthWcdma = new CellSignalStrengthWcdma(ciw.signalStrengthWcdma);
73     }
74 
75     /** @hide */
CellInfoWcdma(android.hardware.radio.V1_5.CellInfo ci, long timeStamp)76     public CellInfoWcdma(android.hardware.radio.V1_5.CellInfo ci, long timeStamp) {
77         super(ci, timeStamp);
78         final android.hardware.radio.V1_5.CellInfoWcdma ciw = ci.ratSpecificInfo.wcdma();
79         mCellIdentityWcdma = new CellIdentityWcdma(ciw.cellIdentityWcdma);
80         mCellSignalStrengthWcdma = new CellSignalStrengthWcdma(ciw.signalStrengthWcdma);
81     }
82 
83     /**
84      * @return a {@link CellIdentityWcdma} instance.
85      */
86     @Override
getCellIdentity()87     public CellIdentityWcdma getCellIdentity() {
88         return mCellIdentityWcdma;
89     }
90 
91     /** @hide */
setCellIdentity(CellIdentityWcdma cid)92     public void setCellIdentity(CellIdentityWcdma cid) {
93         mCellIdentityWcdma = cid;
94     }
95 
96     /**
97      * @return a {@link CellSignalStrengthWcdma} instance.
98      */
99     @Override
getCellSignalStrength()100     public CellSignalStrengthWcdma getCellSignalStrength() {
101         return mCellSignalStrengthWcdma;
102     }
103 
104     /** @hide */
105     @Override
sanitizeLocationInfo()106     public CellInfo sanitizeLocationInfo() {
107         CellInfoWcdma result = new CellInfoWcdma(this);
108         result.mCellIdentityWcdma = mCellIdentityWcdma.sanitizeLocationInfo();
109         return result;
110     }
111 
112     /** @hide */
setCellSignalStrength(CellSignalStrengthWcdma css)113     public void setCellSignalStrength(CellSignalStrengthWcdma css) {
114         mCellSignalStrengthWcdma = css;
115     }
116 
117     /**
118      * @return hash code
119      */
120     @Override
hashCode()121     public int hashCode() {
122         return Objects.hash(super.hashCode(), mCellIdentityWcdma, mCellSignalStrengthWcdma);
123     }
124 
125     @Override
equals(Object other)126     public boolean equals(Object other) {
127         if (!super.equals(other)) {
128             return false;
129         }
130         try {
131             CellInfoWcdma o = (CellInfoWcdma) other;
132             return mCellIdentityWcdma.equals(o.mCellIdentityWcdma)
133                     && mCellSignalStrengthWcdma.equals(o.mCellSignalStrengthWcdma);
134         } catch (ClassCastException e) {
135             return false;
136         }
137     }
138 
139     @Override
toString()140     public String toString() {
141         StringBuffer sb = new StringBuffer();
142 
143         sb.append("CellInfoWcdma:{");
144         sb.append(super.toString());
145         sb.append(" ").append(mCellIdentityWcdma);
146         sb.append(" ").append(mCellSignalStrengthWcdma);
147         sb.append("}");
148 
149         return sb.toString();
150     }
151 
152     /** Implement the Parcelable interface */
153     @Override
describeContents()154     public int describeContents() {
155         return 0;
156     }
157 
158     /** Implement the Parcelable interface */
159     @Override
writeToParcel(Parcel dest, int flags)160     public void writeToParcel(Parcel dest, int flags) {
161         super.writeToParcel(dest, flags, TYPE_WCDMA);
162         mCellIdentityWcdma.writeToParcel(dest, flags);
163         mCellSignalStrengthWcdma.writeToParcel(dest, flags);
164     }
165 
166     /**
167      * Construct a CellInfoWcdma object from the given parcel
168      * where the token is already been processed.
169      */
CellInfoWcdma(Parcel in)170     private CellInfoWcdma(Parcel in) {
171         super(in);
172         mCellIdentityWcdma = CellIdentityWcdma.CREATOR.createFromParcel(in);
173         mCellSignalStrengthWcdma = CellSignalStrengthWcdma.CREATOR.createFromParcel(in);
174     }
175 
176     /** Implement the Parcelable interface */
177     public static final @android.annotation.NonNull Creator<CellInfoWcdma> CREATOR = new Creator<CellInfoWcdma>() {
178         @Override
179         public CellInfoWcdma createFromParcel(Parcel in) {
180             in.readInt(); // Skip past token, we know what it is
181             return createFromParcelBody(in);
182         }
183 
184         @Override
185         public CellInfoWcdma[] newArray(int size) {
186             return new CellInfoWcdma[size];
187         }
188     };
189 
190     /** @hide */
createFromParcelBody(Parcel in)191     protected static CellInfoWcdma createFromParcelBody(Parcel in) {
192         return new CellInfoWcdma(in);
193     }
194 
195     /**
196      * log
197      */
log(String s)198     private static void log(String s) {
199         Rlog.w(LOG_TAG, s);
200     }
201 }
202