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 
17 package android.telephony.gsm;
18 
19 import android.compat.annotation.UnsupportedAppUsage;
20 import android.os.Build;
21 import android.os.Bundle;
22 import android.telephony.CellLocation;
23 
24 /**
25  * Represents the cell location on a GSM phone.
26  *
27  * @deprecated use {@link android.telephony.CellIdentity CellIdentity}.
28  */
29 @Deprecated
30 public class GsmCellLocation extends CellLocation {
31     private int mLac;
32     private int mCid;
33     private int mPsc;
34 
35     /**
36      * Empty constructor.  Initializes the LAC and CID to -1.
37      */
GsmCellLocation()38     public GsmCellLocation() {
39         mLac = -1;
40         mCid = -1;
41         mPsc = -1;
42     }
43 
44     /**
45      * Initialize the object from a bundle.
46      */
GsmCellLocation(Bundle bundle)47     public GsmCellLocation(Bundle bundle) {
48         mLac = bundle.getInt("lac", -1);
49         mCid = bundle.getInt("cid", -1);
50         mPsc = bundle.getInt("psc", -1);
51     }
52 
53     /**
54      * @return gsm location area code, -1 if unknown, 0xffff max legal value
55      */
getLac()56     public int getLac() {
57         return mLac;
58     }
59 
60     /**
61      * @return gsm cell id, -1 if unknown or invalid, 0xffff max legal value
62      */
getCid()63     public int getCid() {
64         return mCid;
65     }
66 
67     /**
68      * On a UMTS network, returns the primary scrambling code of the serving
69      * cell.
70      *
71      * @return primary scrambling code for UMTS, -1 if unknown or GSM
72      */
getPsc()73     public int getPsc() {
74         return mPsc;
75     }
76 
77     /**
78      * Invalidate this object.  The location area code and the cell id are set to -1.
79      */
80     @Override
setStateInvalid()81     public void setStateInvalid() {
82         mLac = -1;
83         mCid = -1;
84         mPsc = -1;
85     }
86 
87     /**
88      * Set the location area code and the cell id.
89      */
setLacAndCid(int lac, int cid)90     public void setLacAndCid(int lac, int cid) {
91         mLac = lac;
92         mCid = cid;
93     }
94 
95     /**
96      * Set the primary scrambling code.
97      * @hide
98      */
99     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
setPsc(int psc)100     public void setPsc(int psc) {
101         mPsc = psc;
102     }
103 
104     @Override
hashCode()105     public int hashCode() {
106         return mLac ^ mCid;
107     }
108 
109     @Override
equals(Object o)110     public boolean equals(Object o) {
111         GsmCellLocation s;
112 
113         try {
114             s = (GsmCellLocation)o;
115         } catch (ClassCastException ex) {
116             return false;
117         }
118 
119         if (o == null) {
120             return false;
121         }
122 
123         return equalsHandlesNulls(mLac, s.mLac) && equalsHandlesNulls(mCid, s.mCid)
124             && equalsHandlesNulls(mPsc, s.mPsc);
125     }
126 
127     @Override
toString()128     public String toString() {
129         return "["+ mLac + "," + mCid + "," + mPsc + "]";
130     }
131 
132     /**
133      * Test whether two objects hold the same data values or both are null
134      *
135      * @param a first obj
136      * @param b second obj
137      * @return true if two objects equal or both are null
138      */
equalsHandlesNulls(Object a, Object b)139     private static boolean equalsHandlesNulls(Object a, Object b) {
140         return (a == null) ? (b == null) : a.equals (b);
141     }
142 
143     /**
144      * Set intent notifier Bundle based on service state
145      *
146      * @param m intent notifier Bundle
147      */
fillInNotifierBundle(Bundle m)148     public void fillInNotifierBundle(Bundle m) {
149         m.putInt("lac", mLac);
150         m.putInt("cid", mCid);
151         m.putInt("psc", mPsc);
152     }
153 
154     /**
155      * @hide
156      */
isEmpty()157     public boolean isEmpty() {
158         return (mLac == -1 && mCid == -1 && mPsc == -1);
159     }
160 }
161