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