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