| 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 | |
| 19 | import android.os.Bundle; |
| 20 | import android.os.RemoteException; |
| 21 | import android.os.ServiceManager; |
| Wink Saville | 767a662 | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 22 | |
| 23 | import android.telephony.cdma.CdmaCellLocation; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.telephony.gsm.GsmCellLocation; |
| 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 { |
| 40 | ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.getService("phone")); |
| 41 | if (phone != null) { |
| 42 | phone.updateServiceLocation(); |
| 43 | } |
| 44 | } catch (RemoteException ex) { |
| 45 | // ignore it |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Create a new CellLocation from a intent notifier Bundle |
| 51 | * |
| 52 | * This method is used by PhoneStateIntentReceiver and maybe by |
| 53 | * external applications. |
| 54 | * |
| 55 | * @param bundle Bundle from intent notifier |
| 56 | * @return newly created CellLocation |
| 57 | * |
| 58 | * @hide |
| 59 | */ |
| 60 | public static CellLocation newFromBundle(Bundle bundle) { |
| Wink Saville | 9d72be3 | 2011-02-01 19:22:15 -0800 | [diff] [blame] | 61 | // TelephonyManager.getDefault().getCurrentPhoneType() handles the case when |
| Jaikumar Ganesh | 9bfbfbd | 2009-05-15 12:05:56 -0700 | [diff] [blame] | 62 | // ITelephony interface is not up yet. |
| Wink Saville | 9d72be3 | 2011-02-01 19:22:15 -0800 | [diff] [blame] | 63 | switch(TelephonyManager.getDefault().getCurrentPhoneType()) { |
| Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 64 | case PhoneConstants.PHONE_TYPE_CDMA: |
| Wink Saville | 767a662 | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 65 | return new CdmaCellLocation(bundle); |
| Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 66 | case PhoneConstants.PHONE_TYPE_GSM: |
| Wink Saville | 767a662 | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 67 | return new GsmCellLocation(bundle); |
| Tammo Spalink | 3cc97f8 | 2009-09-21 15:26:10 +0800 | [diff] [blame] | 68 | default: |
| 69 | return null; |
| Wink Saville | 767a662 | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 70 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | /** |
| 74 | * @hide |
| 75 | */ |
| 76 | public abstract void fillInNotifierBundle(Bundle bundle); |
| 77 | |
| 78 | /** |
| John Wang | 41a4671 | 2010-03-09 15:48:58 -0800 | [diff] [blame] | 79 | * @hide |
| 80 | */ |
| 81 | public abstract boolean isEmpty(); |
| 82 | |
| 83 | /** |
| Tammo Spalink | 3cc97f8 | 2009-09-21 15:26:10 +0800 | [diff] [blame] | 84 | * Return a new CellLocation object representing an unknown |
| 85 | * location, or null for unknown/none phone radio types. |
| Wink Saville | 767a662 | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 86 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | */ |
| 88 | public static CellLocation getEmpty() { |
| Wink Saville | 9d72be3 | 2011-02-01 19:22:15 -0800 | [diff] [blame] | 89 | // TelephonyManager.getDefault().getCurrentPhoneType() handles the case when |
| Jaikumar Ganesh | 9bfbfbd | 2009-05-15 12:05:56 -0700 | [diff] [blame] | 90 | // ITelephony interface is not up yet. |
| Wink Saville | 9d72be3 | 2011-02-01 19:22:15 -0800 | [diff] [blame] | 91 | switch(TelephonyManager.getDefault().getCurrentPhoneType()) { |
| Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 92 | case PhoneConstants.PHONE_TYPE_CDMA: |
| Wink Saville | 767a662 | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 93 | return new CdmaCellLocation(); |
| Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 94 | case PhoneConstants.PHONE_TYPE_GSM: |
| Wink Saville | 767a662 | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 95 | return new GsmCellLocation(); |
| Tammo Spalink | 3cc97f8 | 2009-09-21 15:26:10 +0800 | [diff] [blame] | 96 | default: |
| 97 | return null; |
| 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 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | } |