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