GsmCellLocation.java revision 54b6cfa9a9e5b861a9930af873580d6dc20f773c
1/* 2 * Copyright (C) 2006 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.gsm; 18 19import android.os.Bundle; 20import com.android.internal.telephony.Phone; 21import android.telephony.CellLocation; 22 23/** 24 * Represents the cell location on a GSM phone. 25 */ 26public class GsmCellLocation extends CellLocation 27{ 28 private int mLac; 29 private int mCid; 30 31 /** 32 * Empty constructor. Initializes the LAC and CID to -1. 33 */ 34 public GsmCellLocation() { 35 mLac = -1; 36 mCid = -1; 37 } 38 39 /** 40 * Initialize the object from a bundle. 41 */ 42 public GsmCellLocation(Bundle bundle) { 43 mLac = bundle.getInt("lac"); 44 mCid = bundle.getInt("cid"); 45 } 46 47 /** 48 * @return gsm location area code, -1 if unknown, 0xffff max legal value 49 */ 50 public int getLac() { 51 return mLac; 52 } 53 54 /** 55 * @return gsm cell id, -1 if unknown, 0xffff max legal value 56 */ 57 public int getCid() { 58 return mCid; 59 } 60 61 /** 62 * Invalidate this object. The location area code and the cell id are set to -1. 63 */ 64 public void setStateInvalid() { 65 mLac = -1; 66 mCid = -1; 67 } 68 69 /** 70 * Set the location area code and the cell id. 71 */ 72 public void setLacAndCid(int lac, int cid) { 73 mLac = lac; 74 mCid = cid; 75 } 76 77 @Override 78 public int hashCode() { 79 return mLac ^ mCid; 80 } 81 82 @Override 83 public boolean equals(Object o) { 84 GsmCellLocation s; 85 86 try { 87 s = (GsmCellLocation)o; 88 } catch (ClassCastException ex) { 89 return false; 90 } 91 92 if (o == null) { 93 return false; 94 } 95 96 return equalsHandlesNulls(mLac, s.mLac) && equalsHandlesNulls(mCid, s.mCid); 97 } 98 99 @Override 100 public String toString() { 101 return "["+ mLac + "," + mCid + "]"; 102 } 103 104 /** 105 * Test whether two objects hold the same data values or both are null 106 * 107 * @param a first obj 108 * @param b second obj 109 * @return true if two objects equal or both are null 110 */ 111 private static boolean equalsHandlesNulls(Object a, Object b) { 112 return (a == null) ? (b == null) : a.equals (b); 113 } 114 115 /** 116 * Set intent notifier Bundle based on service state 117 * 118 * @param m intent notifier Bundle 119 */ 120 public void fillInNotifierBundle(Bundle m) { 121 m.putInt("lac", mLac); 122 m.putInt("cid", mCid); 123 } 124} 125 126 127