Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 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 | |
Nathan Harold | 78cf8ac | 2019-04-08 19:21:02 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Artur Satayev | 74cb719 | 2019-12-10 17:47:56 +0000 | [diff] [blame] | 20 | import android.compat.annotation.UnsupportedAppUsage; |
Mathew Inwood | 55418ea | 2018-12-20 15:30:45 +0000 | [diff] [blame] | 21 | import android.os.Build; |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 22 | import android.os.Parcel; |
| 23 | import android.os.Parcelable; |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 24 | |
Meng Wang | 1dbea2f | 2020-01-30 12:25:08 -0800 | [diff] [blame] | 25 | import com.android.telephony.Rlog; |
| 26 | |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 27 | /** |
Nathan Harold | 054b79d | 2018-03-28 08:39:43 -0700 | [diff] [blame] | 28 | * A {@link CellInfo} representing a CDMA cell that provides identity and measurement info. |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 29 | */ |
| 30 | public final class CellInfoCdma extends CellInfo implements Parcelable { |
| 31 | |
| 32 | private static final String LOG_TAG = "CellInfoCdma"; |
| 33 | private static final boolean DBG = false; |
| 34 | |
| 35 | private CellIdentityCdma mCellIdentityCdma; |
| 36 | private CellSignalStrengthCdma mCellSignalStrengthCdma; |
| 37 | |
| 38 | /** @hide */ |
Mathew Inwood | a838206 | 2018-08-16 17:01:12 +0100 | [diff] [blame] | 39 | @UnsupportedAppUsage |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 40 | public CellInfoCdma() { |
| 41 | super(); |
| 42 | mCellIdentityCdma = new CellIdentityCdma(); |
| 43 | mCellSignalStrengthCdma = new CellSignalStrengthCdma(); |
| 44 | } |
| 45 | |
| 46 | /** @hide */ |
Mathew Inwood | 55418ea | 2018-12-20 15:30:45 +0000 | [diff] [blame] | 47 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 48 | public CellInfoCdma(CellInfoCdma ci) { |
| 49 | super(ci); |
| 50 | this.mCellIdentityCdma = ci.mCellIdentityCdma.copy(); |
| 51 | this.mCellSignalStrengthCdma = ci.mCellSignalStrengthCdma.copy(); |
| 52 | } |
| 53 | |
Nathan Harold | 7ce5baf | 2018-12-10 13:39:40 -0800 | [diff] [blame] | 54 | /** @hide */ |
| 55 | public CellInfoCdma(android.hardware.radio.V1_0.CellInfo ci) { |
| 56 | super(ci); |
| 57 | final android.hardware.radio.V1_0.CellInfoCdma cic = ci.cdma.get(0); |
| 58 | mCellIdentityCdma = new CellIdentityCdma(cic.cellIdentityCdma); |
| 59 | mCellSignalStrengthCdma = |
| 60 | new CellSignalStrengthCdma(cic.signalStrengthCdma, cic.signalStrengthEvdo); |
| 61 | } |
| 62 | |
| 63 | /** @hide */ |
| 64 | public CellInfoCdma(android.hardware.radio.V1_2.CellInfo ci) { |
| 65 | super(ci); |
| 66 | final android.hardware.radio.V1_2.CellInfoCdma cic = ci.cdma.get(0); |
| 67 | mCellIdentityCdma = new CellIdentityCdma(cic.cellIdentityCdma); |
| 68 | mCellSignalStrengthCdma = |
| 69 | new CellSignalStrengthCdma(cic.signalStrengthCdma, cic.signalStrengthEvdo); |
| 70 | } |
| 71 | |
Pengquan Meng | 629f116 | 2019-01-14 17:14:58 -0800 | [diff] [blame] | 72 | /** @hide */ |
Nathan Harold | 6e3d94b | 2019-03-04 15:15:24 -0800 | [diff] [blame] | 73 | public CellInfoCdma(android.hardware.radio.V1_4.CellInfo ci, long timeStamp) { |
| 74 | super(ci, timeStamp); |
Pengquan Meng | 629f116 | 2019-01-14 17:14:58 -0800 | [diff] [blame] | 75 | final android.hardware.radio.V1_2.CellInfoCdma cic = ci.info.cdma(); |
| 76 | mCellIdentityCdma = new CellIdentityCdma(cic.cellIdentityCdma); |
| 77 | mCellSignalStrengthCdma = |
| 78 | new CellSignalStrengthCdma(cic.signalStrengthCdma, cic.signalStrengthEvdo); |
| 79 | } |
| 80 | |
Sarah Chin | e9ce2ea | 2020-03-17 17:48:36 -0700 | [diff] [blame] | 81 | /** @hide */ |
| 82 | public CellInfoCdma(android.hardware.radio.V1_5.CellInfo ci, long timeStamp) { |
| 83 | super(ci, timeStamp); |
| 84 | final android.hardware.radio.V1_2.CellInfoCdma cic = ci.ratSpecificInfo.cdma(); |
| 85 | mCellIdentityCdma = new CellIdentityCdma(cic.cellIdentityCdma); |
| 86 | mCellSignalStrengthCdma = |
| 87 | new CellSignalStrengthCdma(cic.signalStrengthCdma, cic.signalStrengthEvdo); |
| 88 | } |
| 89 | |
Nathan Harold | 78cf8ac | 2019-04-08 19:21:02 -0700 | [diff] [blame] | 90 | /** |
| 91 | * @return a {@link CellIdentityCdma} instance. |
| 92 | */ |
Nathan Harold | 7b3f7a4 | 2018-07-09 11:59:53 -0700 | [diff] [blame] | 93 | @Override |
Nathan Harold | 78cf8ac | 2019-04-08 19:21:02 -0700 | [diff] [blame] | 94 | public @NonNull CellIdentityCdma getCellIdentity() { |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 95 | return mCellIdentityCdma; |
| 96 | } |
Nathan Harold | 78cf8ac | 2019-04-08 19:21:02 -0700 | [diff] [blame] | 97 | |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 98 | /** @hide */ |
Mathew Inwood | a838206 | 2018-08-16 17:01:12 +0100 | [diff] [blame] | 99 | @UnsupportedAppUsage |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 100 | public void setCellIdentity(CellIdentityCdma cid) { |
| 101 | mCellIdentityCdma = cid; |
| 102 | } |
| 103 | |
Nathan Harold | 78cf8ac | 2019-04-08 19:21:02 -0700 | [diff] [blame] | 104 | /** |
| 105 | * @return a {@link CellSignalStrengthCdma} instance. |
| 106 | */ |
Nathan Harold | 7b3f7a4 | 2018-07-09 11:59:53 -0700 | [diff] [blame] | 107 | @Override |
Nathan Harold | 78cf8ac | 2019-04-08 19:21:02 -0700 | [diff] [blame] | 108 | public @NonNull CellSignalStrengthCdma getCellSignalStrength() { |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 109 | return mCellSignalStrengthCdma; |
| 110 | } |
Hall Liu | c9d7430 | 2019-02-28 15:29:19 -0800 | [diff] [blame] | 111 | |
| 112 | /** @hide */ |
| 113 | @Override |
| 114 | public CellInfo sanitizeLocationInfo() { |
| 115 | CellInfoCdma result = new CellInfoCdma(this); |
| 116 | result.mCellIdentityCdma = mCellIdentityCdma.sanitizeLocationInfo(); |
| 117 | return result; |
| 118 | } |
| 119 | |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 120 | /** @hide */ |
| 121 | public void setCellSignalStrength(CellSignalStrengthCdma css) { |
| 122 | mCellSignalStrengthCdma = css; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * @return hash code |
| 127 | */ |
| 128 | @Override |
| 129 | public int hashCode() { |
| 130 | return super.hashCode() + mCellIdentityCdma.hashCode() + mCellSignalStrengthCdma.hashCode(); |
| 131 | } |
| 132 | |
| 133 | @Override |
| 134 | public boolean equals(Object other) { |
| 135 | if (!super.equals(other)) { |
| 136 | return false; |
| 137 | } |
| 138 | try { |
| 139 | CellInfoCdma o = (CellInfoCdma) other; |
| 140 | return mCellIdentityCdma.equals(o.mCellIdentityCdma) |
| 141 | && mCellSignalStrengthCdma.equals(o.mCellSignalStrengthCdma); |
| 142 | } catch (ClassCastException e) { |
| 143 | return false; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | @Override |
| 148 | public String toString() { |
| 149 | StringBuffer sb = new StringBuffer(); |
| 150 | |
Wink Saville | 094beec | 2013-04-05 15:03:31 -0700 | [diff] [blame] | 151 | sb.append("CellInfoCdma:{"); |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 152 | sb.append(super.toString()); |
Wink Saville | 094beec | 2013-04-05 15:03:31 -0700 | [diff] [blame] | 153 | sb.append(" ").append(mCellIdentityCdma); |
| 154 | sb.append(" ").append(mCellSignalStrengthCdma); |
| 155 | sb.append("}"); |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 156 | |
| 157 | return sb.toString(); |
| 158 | } |
| 159 | |
| 160 | /** Implement the Parcelable interface */ |
| 161 | @Override |
| 162 | public int describeContents() { |
| 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | /** Implement the Parcelable interface */ |
| 167 | @Override |
| 168 | public void writeToParcel(Parcel dest, int flags) { |
Wink Saville | c6e4917a | 2012-09-21 13:54:05 -0700 | [diff] [blame] | 169 | super.writeToParcel(dest, flags, TYPE_CDMA); |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 170 | mCellIdentityCdma.writeToParcel(dest, flags); |
| 171 | mCellSignalStrengthCdma.writeToParcel(dest, flags); |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Construct a CellInfoCdma object from the given parcel |
| 176 | * where the token is already been processed. |
| 177 | */ |
| 178 | private CellInfoCdma(Parcel in) { |
| 179 | super(in); |
| 180 | mCellIdentityCdma = CellIdentityCdma.CREATOR.createFromParcel(in); |
| 181 | mCellSignalStrengthCdma = CellSignalStrengthCdma.CREATOR.createFromParcel(in); |
| 182 | if (DBG) log("CellInfoCdma(Parcel): " + toString()); |
| 183 | } |
| 184 | |
| 185 | /** Implement the Parcelable interface */ |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 186 | public static final @android.annotation.NonNull Creator<CellInfoCdma> CREATOR = new Creator<CellInfoCdma>() { |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 187 | @Override |
| 188 | public CellInfoCdma createFromParcel(Parcel in) { |
| 189 | in.readInt(); // Skip past token, we know what it is |
| 190 | return createFromParcelBody(in); |
| 191 | } |
| 192 | |
| 193 | @Override |
| 194 | public CellInfoCdma[] newArray(int size) { |
| 195 | return new CellInfoCdma[size]; |
| 196 | } |
| 197 | }; |
| 198 | |
| 199 | /** @hide */ |
| 200 | protected static CellInfoCdma createFromParcelBody(Parcel in) { |
| 201 | return new CellInfoCdma(in); |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * log |
| 206 | */ |
| 207 | private static void log(String s) { |
Wink Saville | 599a90c | 2012-11-27 12:29:13 -0800 | [diff] [blame] | 208 | Rlog.w(LOG_TAG, s); |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 209 | } |
| 210 | } |