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.annotation.NonNull; 20 import android.compat.annotation.UnsupportedAppUsage; 21 import android.os.Build; 22 import android.os.Parcel; 23 import android.os.Parcelable; 24 25 import com.android.telephony.Rlog; 26 27 /** 28 * A {@link CellInfo} representing a CDMA cell that provides identity and measurement info. 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 */ 39 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) CellInfoCdma()40 public CellInfoCdma() { 41 super(); 42 mCellIdentityCdma = new CellIdentityCdma(); 43 mCellSignalStrengthCdma = new CellSignalStrengthCdma(); 44 } 45 46 /** @hide */ 47 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) CellInfoCdma(CellInfoCdma ci)48 public CellInfoCdma(CellInfoCdma ci) { 49 super(ci); 50 this.mCellIdentityCdma = ci.mCellIdentityCdma.copy(); 51 this.mCellSignalStrengthCdma = ci.mCellSignalStrengthCdma.copy(); 52 } 53 54 /** @hide */ CellInfoCdma(int connectionStatus, boolean registered, long timeStamp, CellIdentityCdma cellIdentityCdma, CellSignalStrengthCdma cellSignalStrengthCdma)55 public CellInfoCdma(int connectionStatus, boolean registered, long timeStamp, 56 CellIdentityCdma cellIdentityCdma, CellSignalStrengthCdma cellSignalStrengthCdma) { 57 super(connectionStatus, registered, timeStamp); 58 mCellIdentityCdma = cellIdentityCdma; 59 mCellSignalStrengthCdma = cellSignalStrengthCdma; 60 } 61 62 /** 63 * @return a {@link CellIdentityCdma} instance. 64 */ 65 @Override getCellIdentity()66 public @NonNull CellIdentityCdma getCellIdentity() { 67 return mCellIdentityCdma; 68 } 69 70 /** @hide */ 71 @UnsupportedAppUsage setCellIdentity(CellIdentityCdma cid)72 public void setCellIdentity(CellIdentityCdma cid) { 73 mCellIdentityCdma = cid; 74 } 75 76 /** 77 * @return a {@link CellSignalStrengthCdma} instance. 78 */ 79 @Override getCellSignalStrength()80 public @NonNull CellSignalStrengthCdma getCellSignalStrength() { 81 return mCellSignalStrengthCdma; 82 } 83 84 /** @hide */ 85 @Override sanitizeLocationInfo()86 public CellInfo sanitizeLocationInfo() { 87 CellInfoCdma result = new CellInfoCdma(this); 88 result.mCellIdentityCdma = mCellIdentityCdma.sanitizeLocationInfo(); 89 return result; 90 } 91 92 /** @hide */ setCellSignalStrength(CellSignalStrengthCdma css)93 public void setCellSignalStrength(CellSignalStrengthCdma css) { 94 mCellSignalStrengthCdma = css; 95 } 96 97 /** 98 * @return hash code 99 */ 100 @Override hashCode()101 public int hashCode() { 102 return super.hashCode() + mCellIdentityCdma.hashCode() + mCellSignalStrengthCdma.hashCode(); 103 } 104 105 @Override equals(Object other)106 public boolean equals(Object other) { 107 if (!super.equals(other)) { 108 return false; 109 } 110 try { 111 CellInfoCdma o = (CellInfoCdma) other; 112 return mCellIdentityCdma.equals(o.mCellIdentityCdma) 113 && mCellSignalStrengthCdma.equals(o.mCellSignalStrengthCdma); 114 } catch (ClassCastException e) { 115 return false; 116 } 117 } 118 119 @Override toString()120 public String toString() { 121 StringBuffer sb = new StringBuffer(); 122 123 sb.append("CellInfoCdma:{"); 124 sb.append(super.toString()); 125 sb.append(" ").append(mCellIdentityCdma); 126 sb.append(" ").append(mCellSignalStrengthCdma); 127 sb.append("}"); 128 129 return sb.toString(); 130 } 131 132 /** Implement the Parcelable interface */ 133 @Override describeContents()134 public int describeContents() { 135 return 0; 136 } 137 138 /** Implement the Parcelable interface */ 139 @Override writeToParcel(Parcel dest, int flags)140 public void writeToParcel(Parcel dest, int flags) { 141 super.writeToParcel(dest, flags, TYPE_CDMA); 142 mCellIdentityCdma.writeToParcel(dest, flags); 143 mCellSignalStrengthCdma.writeToParcel(dest, flags); 144 } 145 146 /** 147 * Construct a CellInfoCdma object from the given parcel 148 * where the token is already been processed. 149 */ CellInfoCdma(Parcel in)150 private CellInfoCdma(Parcel in) { 151 super(in); 152 mCellIdentityCdma = CellIdentityCdma.CREATOR.createFromParcel(in); 153 mCellSignalStrengthCdma = CellSignalStrengthCdma.CREATOR.createFromParcel(in); 154 if (DBG) log("CellInfoCdma(Parcel): " + toString()); 155 } 156 157 /** Implement the Parcelable interface */ 158 public static final @android.annotation.NonNull Creator<CellInfoCdma> CREATOR = new Creator<CellInfoCdma>() { 159 @Override 160 public CellInfoCdma createFromParcel(Parcel in) { 161 in.readInt(); // Skip past token, we know what it is 162 return createFromParcelBody(in); 163 } 164 165 @Override 166 public CellInfoCdma[] newArray(int size) { 167 return new CellInfoCdma[size]; 168 } 169 }; 170 171 /** @hide */ createFromParcelBody(Parcel in)172 protected static CellInfoCdma createFromParcelBody(Parcel in) { 173 return new CellInfoCdma(in); 174 } 175 176 /** 177 * log 178 */ log(String s)179 private static void log(String s) { 180 Rlog.w(LOG_TAG, s); 181 } 182 } 183