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