CdmaCellLocation.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.cdma;
18
19import android.os.Bundle;
20import android.telephony.CellLocation;
21
22/**
23 * Represents the cell location on a GSM phone.
24 * @hide
25 */
26public class CdmaCellLocation extends CellLocation {
27    private int mBaseStationId = -1;
28    private int mBaseStationLatitude = -1;
29    private int mBaseStationLongitude = -1;
30
31    /**
32     * Empty constructor.  Initializes the LAC and CID to -1.
33     */
34    public CdmaCellLocation() {
35        this.mBaseStationId = -1;
36        this.mBaseStationLatitude = -1;
37        this.mBaseStationLongitude = -1;
38    }
39
40    /**
41     * Initialize the object from a bundle.
42     */
43    public CdmaCellLocation(Bundle bundleWithValues) {
44        this.mBaseStationId = bundleWithValues.getInt("baseStationId");
45        this.mBaseStationLatitude = bundleWithValues.getInt("baseStationLatitude");
46        this.mBaseStationLongitude = bundleWithValues.getInt("baseStationLongitude");
47    }
48
49    /**
50     * @return cdma base station identification number, -1 if unknown
51     */
52    public int getBaseStationId() {
53        return this.mBaseStationId;
54    }
55
56    /**
57     * @return cdma base station latitude, -1 if unknown
58     */
59    public int getBaseStationLatitude() {
60        return this.mBaseStationLatitude;
61    }
62
63    /**
64     * @return cdma base station longitude, -1 if unknown
65     */
66    public int getBaseStationLongitude() {
67        return this.mBaseStationLongitude;
68    }
69
70    /**
71     * Invalidate this object.  The cell location data is set to -1.
72     */
73    public void setStateInvalid() {
74        this.mBaseStationId = -1;
75        this.mBaseStationLatitude = -1;
76        this.mBaseStationLongitude = -1;
77    }
78
79    /**
80     * Set the cell location data.
81     */
82     public void setCellLocationData(int baseStationId, int baseStationLatitude,
83         int baseStationLongitude) {
84         // The following values have to be written in the correct sequence
85         this.mBaseStationId = baseStationId;
86         this.mBaseStationLatitude = baseStationLatitude;   //values[2];
87         this.mBaseStationLongitude = baseStationLongitude; //values[3];
88    }
89
90    @Override
91    public int hashCode() {
92        return this.mBaseStationId ^ this.mBaseStationLatitude ^ this.mBaseStationLongitude;
93    }
94
95    @Override
96    public boolean equals(Object o) {
97        CdmaCellLocation s;
98
99        try {
100            s = (CdmaCellLocation)o;
101        } catch (ClassCastException ex) {
102            return false;
103        }
104
105        if (o == null) {
106            return false;
107        }
108
109        return (equalsHandlesNulls(this.mBaseStationId, s.mBaseStationId) &&
110                equalsHandlesNulls(this.mBaseStationLatitude, s.mBaseStationLatitude) &&
111                equalsHandlesNulls(this.mBaseStationLongitude, s.mBaseStationLongitude)
112        );
113    }
114
115    @Override
116    public String toString() {
117        return "[" + this.mBaseStationId + ","
118                   + this.mBaseStationLatitude + ","
119                   + this.mBaseStationLongitude + "]";
120    }
121
122    /**
123     * Test whether two objects hold the same data values or both are null
124     *
125     * @param a first obj
126     * @param b second obj
127     * @return true if two objects equal or both are null
128     */
129    private static boolean equalsHandlesNulls(Object a, Object b) {
130        return (a == null) ? (b == null) : a.equals (b);
131    }
132
133    /**
134     * Fill the cell location data into the intent notifier Bundle based on service state
135     *
136     * @param bundleToFill intent notifier Bundle
137     */
138    public void fillInNotifierBundle(Bundle bundleToFill) {
139        bundleToFill.putInt("baseStationId", this.mBaseStationId);
140        bundleToFill.putInt("baseStationLatitude", this.mBaseStationLatitude);
141        bundleToFill.putInt("baseStationLongitude", this.mBaseStationLongitude);
142    }
143
144}
145
146
147