The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Artur Satayev | 74cb719 | 2019-12-10 17:47:56 +0000 | [diff] [blame] | 19 | import android.compat.annotation.UnsupportedAppUsage; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | import android.os.Bundle; |
| 21 | import android.os.RemoteException; |
Wink Saville | 767a662 | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 22 | import android.telephony.cdma.CdmaCellLocation; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | import android.telephony.gsm.GsmCellLocation; |
Artur Satayev | 74cb719 | 2019-12-10 17:47:56 +0000 | [diff] [blame] | 24 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | import com.android.internal.telephony.ITelephony; |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 26 | import com.android.internal.telephony.PhoneConstants; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | |
| 28 | /** |
Tammo Spalink | 3cc97f8 | 2009-09-21 15:26:10 +0800 | [diff] [blame] | 29 | * Abstract class that represents the location of the device. {@more} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | */ |
| 31 | public abstract class CellLocation { |
| 32 | |
| 33 | /** |
| 34 | * Request an update of the current location. If the location has changed, |
| 35 | * a broadcast will be sent to everyone registered with {@link |
| 36 | * PhoneStateListener#LISTEN_CELL_LOCATION}. |
| 37 | */ |
| 38 | public static void requestLocationUpdate() { |
| 39 | try { |
Peter Wang | d9eebca | 2019-12-30 16:14:01 -0800 | [diff] [blame] | 40 | ITelephony phone = ITelephony.Stub.asInterface( |
| 41 | TelephonyFrameworkInitializer |
| 42 | .getTelephonyServiceManager() |
| 43 | .getTelephonyServiceRegisterer() |
| 44 | .get()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | if (phone != null) { |
| 46 | phone.updateServiceLocation(); |
| 47 | } |
| 48 | } catch (RemoteException ex) { |
| 49 | // ignore it |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Create a new CellLocation from a intent notifier Bundle |
| 55 | * |
Jayachandran C | 4eda57e | 2020-01-07 16:20:33 -0800 | [diff] [blame] | 56 | * This method maybe used by external applications. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | * |
| 58 | * @param bundle Bundle from intent notifier |
| 59 | * @return newly created CellLocation |
| 60 | * |
| 61 | * @hide |
| 62 | */ |
Mathew Inwood | 323d08f | 2018-08-16 11:30:29 +0100 | [diff] [blame] | 63 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | public static CellLocation newFromBundle(Bundle bundle) { |
Wink Saville | 9d72be3 | 2011-02-01 19:22:15 -0800 | [diff] [blame] | 65 | // TelephonyManager.getDefault().getCurrentPhoneType() handles the case when |
Jaikumar Ganesh | 9bfbfbd | 2009-05-15 12:05:56 -0700 | [diff] [blame] | 66 | // ITelephony interface is not up yet. |
Wink Saville | 9d72be3 | 2011-02-01 19:22:15 -0800 | [diff] [blame] | 67 | switch(TelephonyManager.getDefault().getCurrentPhoneType()) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 68 | case PhoneConstants.PHONE_TYPE_CDMA: |
Wink Saville | 767a662 | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 69 | return new CdmaCellLocation(bundle); |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 70 | case PhoneConstants.PHONE_TYPE_GSM: |
Wink Saville | 767a662 | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 71 | return new GsmCellLocation(bundle); |
Tammo Spalink | 3cc97f8 | 2009-09-21 15:26:10 +0800 | [diff] [blame] | 72 | default: |
| 73 | return null; |
Wink Saville | 767a662 | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 74 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /** |
| 78 | * @hide |
| 79 | */ |
Mathew Inwood | 323d08f | 2018-08-16 11:30:29 +0100 | [diff] [blame] | 80 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | public abstract void fillInNotifierBundle(Bundle bundle); |
| 82 | |
| 83 | /** |
John Wang | 41a4671 | 2010-03-09 15:48:58 -0800 | [diff] [blame] | 84 | * @hide |
| 85 | */ |
Mathew Inwood | 323d08f | 2018-08-16 11:30:29 +0100 | [diff] [blame] | 86 | @UnsupportedAppUsage |
John Wang | 41a4671 | 2010-03-09 15:48:58 -0800 | [diff] [blame] | 87 | public abstract boolean isEmpty(); |
| 88 | |
| 89 | /** |
Amit Mahajan | 37c2839 | 2015-11-25 17:07:47 -0800 | [diff] [blame] | 90 | * Invalidate this object. The location area code and the cell id are set to -1. |
| 91 | * @hide |
| 92 | */ |
| 93 | public abstract void setStateInvalid(); |
| 94 | |
| 95 | /** |
Tammo Spalink | 3cc97f8 | 2009-09-21 15:26:10 +0800 | [diff] [blame] | 96 | * Return a new CellLocation object representing an unknown |
| 97 | * location, or null for unknown/none phone radio types. |
Wink Saville | 767a662 | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 98 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | */ |
| 100 | public static CellLocation getEmpty() { |
Wink Saville | 9d72be3 | 2011-02-01 19:22:15 -0800 | [diff] [blame] | 101 | // TelephonyManager.getDefault().getCurrentPhoneType() handles the case when |
Jaikumar Ganesh | 9bfbfbd | 2009-05-15 12:05:56 -0700 | [diff] [blame] | 102 | // ITelephony interface is not up yet. |
Wink Saville | 9d72be3 | 2011-02-01 19:22:15 -0800 | [diff] [blame] | 103 | switch(TelephonyManager.getDefault().getCurrentPhoneType()) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 104 | case PhoneConstants.PHONE_TYPE_CDMA: |
Wink Saville | 767a662 | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 105 | return new CdmaCellLocation(); |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 106 | case PhoneConstants.PHONE_TYPE_GSM: |
Wink Saville | 767a662 | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 107 | return new GsmCellLocation(); |
Tammo Spalink | 3cc97f8 | 2009-09-21 15:26:10 +0800 | [diff] [blame] | 108 | default: |
| 109 | return null; |
Wink Saville | 767a662 | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 110 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 111 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | } |