• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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;
18 
19 import android.app.ActivityThread;
20 import android.compat.annotation.UnsupportedAppUsage;
21 import android.content.Context;
22 import android.os.Bundle;
23 import android.os.RemoteException;
24 import android.telephony.cdma.CdmaCellLocation;
25 import android.telephony.gsm.GsmCellLocation;
26 
27 import com.android.internal.telephony.ITelephony;
28 import com.android.internal.telephony.PhoneConstants;
29 
30 /**
31  * Abstract class that represents the location of the device.  {@more}
32  *
33  * @deprecated use {@link android.telephony.CellIdentity CellIdentity}.
34  */
35 @Deprecated
36 public abstract class CellLocation {
37 
38     /**
39      * Request an updated CellLocation for callers targeting SDK 30 or older.
40      *
41      * Whenever Android is aware of location changes, a callback will automatically be sent to
42      * all registrants of {@link PhoneStateListener#LISTEN_CELL_LOCATION}. This API requests an
43      * additional location update for cases where power saving might cause location updates to be
44      * missed.
45      *
46      * <p>This method is a no-op for callers targeting SDK level 31 or greater.
47      * <p>This method is a no-op for callers that target SDK level 29 or 30 and lack
48      * {@link android.Manifest.permission#ACCESS_FINE_LOCATION}.
49      * <p>This method is a no-op for callers that target SDK level 28 or below and lack
50      * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}.
51      *
52      * @deprecated use {@link TelephonyManager#requestCellInfoUpdate}.
53      */
54     @Deprecated
requestLocationUpdate()55     public static void requestLocationUpdate() {
56         // Since this object doesn't have a context, this is the best we can do.
57         final Context appContext = ActivityThread.currentApplication();
58         if (appContext == null) return; // should never happen
59 
60         try {
61             ITelephony phone = ITelephony.Stub.asInterface(
62                     TelephonyFrameworkInitializer
63                             .getTelephonyServiceManager()
64                             .getTelephonyServiceRegisterer()
65                             .get());
66             if (phone != null) {
67                 phone.updateServiceLocationWithPackageName(appContext.getOpPackageName());
68             }
69         } catch (RemoteException ex) {
70             // ignore it
71         }
72     }
73 
74     /**
75      * Create a new CellLocation from a intent notifier Bundle
76      *
77      * This method maybe used by external applications.
78      *
79      * @param bundle Bundle from intent notifier
80      * @return newly created CellLocation
81      *
82      * @hide
83      */
84     @UnsupportedAppUsage
newFromBundle(Bundle bundle)85     public static CellLocation newFromBundle(Bundle bundle) {
86         // TelephonyManager.getDefault().getCurrentPhoneType() handles the case when
87         // ITelephony interface is not up yet.
88         switch(TelephonyManager.getDefault().getCurrentPhoneType()) {
89         case PhoneConstants.PHONE_TYPE_CDMA:
90             return new CdmaCellLocation(bundle);
91         case PhoneConstants.PHONE_TYPE_GSM:
92             return new GsmCellLocation(bundle);
93         default:
94             return null;
95         }
96     }
97 
98     /**
99      * @hide
100      */
101     @SuppressWarnings("HiddenAbstractMethod")
102     @UnsupportedAppUsage
fillInNotifierBundle(Bundle bundle)103     public abstract void fillInNotifierBundle(Bundle bundle);
104 
105     /**
106      * @hide
107      */
108     @SuppressWarnings("HiddenAbstractMethod")
109     @UnsupportedAppUsage
isEmpty()110     public abstract boolean isEmpty();
111 
112     /**
113      * Invalidate this object.  The location area code and the cell id are set to -1.
114      * @hide
115      */
116     @SuppressWarnings("HiddenAbstractMethod")
setStateInvalid()117     public abstract void setStateInvalid();
118 
119     /**
120      * Return a new CellLocation object representing an unknown
121      * location, or null for unknown/none phone radio types.
122      *
123      */
getEmpty()124     public static CellLocation getEmpty() {
125         // TelephonyManager.getDefault().getCurrentPhoneType() handles the case when
126         // ITelephony interface is not up yet.
127         switch(TelephonyManager.getDefault().getCurrentPhoneType()) {
128         case PhoneConstants.PHONE_TYPE_CDMA:
129             return new CdmaCellLocation();
130         case PhoneConstants.PHONE_TYPE_GSM:
131             return new GsmCellLocation();
132         default:
133             return null;
134         }
135     }
136 }
137