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