CellInfoGsm.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 CellInfoGsm extends CellInfo implements Parcelable { 29 30 private static final String LOG_TAG = "CellInfoGsm"; 31 private static final boolean DBG = false; 32 33 private CellIdentityGsm mCellIdentityGsm; 34 private CellSignalStrengthGsm mCellSignalStrengthGsm; 35 36 /** @hide */ 37 public CellInfoGsm() { 38 super(); 39 mCellIdentityGsm = new CellIdentityGsm(); 40 mCellSignalStrengthGsm = new CellSignalStrengthGsm(); 41 } 42 43 /** @hide */ 44 public CellInfoGsm(CellInfoGsm ci) { 45 super(ci); 46 this.mCellIdentityGsm = ci.mCellIdentityGsm.copy(); 47 this.mCellSignalStrengthGsm = ci.mCellSignalStrengthGsm.copy(); 48 } 49 50 public CellIdentityGsm getCellIdentity() { 51 return mCellIdentityGsm; 52 } 53 /** @hide */ 54 public void setCellIdentity(CellIdentityGsm cid) { 55 mCellIdentityGsm = cid; 56 } 57 58 public CellSignalStrengthGsm getCellSignalStrength() { 59 return mCellSignalStrengthGsm; 60 } 61 /** @hide */ 62 public void setCellSignalStrength(CellSignalStrengthGsm css) { 63 mCellSignalStrengthGsm = css; 64 } 65 66 /** 67 * @return hash code 68 */ 69 @Override 70 public int hashCode() { 71 return super.hashCode() + mCellIdentityGsm.hashCode() + mCellSignalStrengthGsm.hashCode(); 72 } 73 74 @Override 75 public boolean equals(Object other) { 76 if (!super.equals(other)) { 77 return false; 78 } 79 try { 80 CellInfoGsm o = (CellInfoGsm) other; 81 return mCellIdentityGsm.equals(o.mCellIdentityGsm) 82 && mCellSignalStrengthGsm.equals(o.mCellSignalStrengthGsm); 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("CellInfoGsm:"); 93 sb.append(super.toString()); 94 sb.append(", ").append(mCellIdentityGsm); 95 sb.append(", ").append(mCellSignalStrengthGsm); 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 dest.writeInt(TYPE_LTE); 110 super.writeToParcel(dest, flags); 111 mCellIdentityGsm.writeToParcel(dest, flags); 112 mCellSignalStrengthGsm.writeToParcel(dest, flags); 113 } 114 115 /** 116 * Construct a CellInfoGsm object from the given parcel 117 * where the token is already been processed. 118 */ 119 private CellInfoGsm(Parcel in) { 120 super(in); 121 mCellIdentityGsm = CellIdentityGsm.CREATOR.createFromParcel(in); 122 mCellSignalStrengthGsm = CellSignalStrengthGsm.CREATOR.createFromParcel(in); 123 } 124 125 /** Implement the Parcelable interface */ 126 public static final Creator<CellInfoGsm> CREATOR = new Creator<CellInfoGsm>() { 127 @Override 128 public CellInfoGsm createFromParcel(Parcel in) { 129 in.readInt(); // Skip past token, we know what it is 130 return createFromParcelBody(in); 131 } 132 133 @Override 134 public CellInfoGsm[] newArray(int size) { 135 return new CellInfoGsm[size]; 136 } 137 }; 138 139 /** @hide */ 140 protected static CellInfoGsm createFromParcelBody(Parcel in) { 141 return new CellInfoGsm(in); 142 } 143 144 /** 145 * log 146 */ 147 private static void log(String s) { 148 Log.w(LOG_TAG, s); 149 } 150} 151