CellInfoCdma.java revision b208a24cf521401912cfce16fce550a995cf1250
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 17package android.telephony; 18 19import android.os.Parcel; 20import android.os.Parcelable; 21import android.util.Log; 22 23/** 24 * Immutable cell information from a point in time. 25 * 26 * @hide 27 */ 28public final class CellInfoCdma extends CellInfo implements Parcelable { 29 30 private static final String LOG_TAG = "CellInfoCdma"; 31 private static final boolean DBG = false; 32 33 private CellIdentityCdma mCellIdentityCdma; 34 private CellSignalStrengthCdma mCellSignalStrengthCdma; 35 36 /** @hide */ 37 public CellInfoCdma() { 38 super(); 39 mCellIdentityCdma = new CellIdentityCdma(); 40 mCellSignalStrengthCdma = new CellSignalStrengthCdma(); 41 } 42 43 /** @hide */ 44 public CellInfoCdma(CellInfoCdma ci) { 45 super(ci); 46 this.mCellIdentityCdma = ci.mCellIdentityCdma.copy(); 47 this.mCellSignalStrengthCdma = ci.mCellSignalStrengthCdma.copy(); 48 } 49 50 public CellIdentityCdma getCellIdentity() { 51 return mCellIdentityCdma; 52 } 53 /** @hide */ 54 public void setCellIdentity(CellIdentityCdma cid) { 55 mCellIdentityCdma = cid; 56 } 57 58 public CellSignalStrengthCdma getCellSignalStrength() { 59 return mCellSignalStrengthCdma; 60 } 61 /** @hide */ 62 public void setCellSignalStrength(CellSignalStrengthCdma css) { 63 mCellSignalStrengthCdma = css; 64 } 65 66 /** 67 * @return hash code 68 */ 69 @Override 70 public int hashCode() { 71 return super.hashCode() + mCellIdentityCdma.hashCode() + mCellSignalStrengthCdma.hashCode(); 72 } 73 74 @Override 75 public boolean equals(Object other) { 76 if (!super.equals(other)) { 77 return false; 78 } 79 try { 80 CellInfoCdma o = (CellInfoCdma) other; 81 return mCellIdentityCdma.equals(o.mCellIdentityCdma) 82 && mCellSignalStrengthCdma.equals(o.mCellSignalStrengthCdma); 83 } catch (ClassCastException e) { 84 return false; 85 } 86 } 87 88 @Override 89 public String toString() { 90 StringBuffer sb = new StringBuffer(); 91 92 sb.append("CellInfoCdma:"); 93 sb.append(super.toString()); 94 sb.append(", ").append(mCellIdentityCdma); 95 sb.append(", ").append(mCellSignalStrengthCdma); 96 97 return sb.toString(); 98 } 99 100 /** Implement the Parcelable interface */ 101 @Override 102 public int describeContents() { 103 return 0; 104 } 105 106 /** Implement the Parcelable interface */ 107 @Override 108 public void writeToParcel(Parcel dest, int flags) { 109 if (DBG) log("writeToParcel(Parcel, int): " + toString()); 110 dest.writeInt(TYPE_LTE); 111 super.writeToParcel(dest, flags); 112 mCellIdentityCdma.writeToParcel(dest, flags); 113 mCellSignalStrengthCdma.writeToParcel(dest, flags); 114 } 115 116 /** 117 * Construct a CellInfoCdma object from the given parcel 118 * where the token is already been processed. 119 */ 120 private CellInfoCdma(Parcel in) { 121 super(in); 122 mCellIdentityCdma = CellIdentityCdma.CREATOR.createFromParcel(in); 123 mCellSignalStrengthCdma = CellSignalStrengthCdma.CREATOR.createFromParcel(in); 124 if (DBG) log("CellInfoCdma(Parcel): " + toString()); 125 } 126 127 /** Implement the Parcelable interface */ 128 public static final Creator<CellInfoCdma> CREATOR = new Creator<CellInfoCdma>() { 129 @Override 130 public CellInfoCdma createFromParcel(Parcel in) { 131 in.readInt(); // Skip past token, we know what it is 132 return createFromParcelBody(in); 133 } 134 135 @Override 136 public CellInfoCdma[] newArray(int size) { 137 return new CellInfoCdma[size]; 138 } 139 }; 140 141 /** @hide */ 142 protected static CellInfoCdma createFromParcelBody(Parcel in) { 143 return new CellInfoCdma(in); 144 } 145 146 /** 147 * log 148 */ 149 private static void log(String s) { 150 Log.w(LOG_TAG, s); 151 } 152} 153