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