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; 22 23 import android.annotation.UnsupportedAppUsage; 24 import android.telephony.cdma.CdmaCellLocation; 25 import android.telephony.gsm.GsmCellLocation; 26 import com.android.internal.telephony.ITelephony; 27 import com.android.internal.telephony.PhoneConstants; 28 29 /** 30 * Abstract class that represents the location of the device. {@more} 31 */ 32 public abstract class CellLocation { 33 34 /** 35 * Request an update of the current location. If the location has changed, 36 * a broadcast will be sent to everyone registered with {@link 37 * PhoneStateListener#LISTEN_CELL_LOCATION}. 38 */ requestLocationUpdate()39 public static void requestLocationUpdate() { 40 try { 41 ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.getService("phone")); 42 if (phone != null) { 43 phone.updateServiceLocation(); 44 } 45 } catch (RemoteException ex) { 46 // ignore it 47 } 48 } 49 50 /** 51 * Create a new CellLocation from a intent notifier Bundle 52 * 53 * This method is used by PhoneStateIntentReceiver and maybe by 54 * external applications. 55 * 56 * @param bundle Bundle from intent notifier 57 * @return newly created CellLocation 58 * 59 * @hide 60 */ 61 @UnsupportedAppUsage newFromBundle(Bundle bundle)62 public static CellLocation newFromBundle(Bundle bundle) { 63 // TelephonyManager.getDefault().getCurrentPhoneType() handles the case when 64 // ITelephony interface is not up yet. 65 switch(TelephonyManager.getDefault().getCurrentPhoneType()) { 66 case PhoneConstants.PHONE_TYPE_CDMA: 67 return new CdmaCellLocation(bundle); 68 case PhoneConstants.PHONE_TYPE_GSM: 69 return new GsmCellLocation(bundle); 70 default: 71 return null; 72 } 73 } 74 75 /** 76 * @hide 77 */ 78 @UnsupportedAppUsage fillInNotifierBundle(Bundle bundle)79 public abstract void fillInNotifierBundle(Bundle bundle); 80 81 /** 82 * @hide 83 */ 84 @UnsupportedAppUsage isEmpty()85 public abstract boolean isEmpty(); 86 87 /** 88 * Invalidate this object. The location area code and the cell id are set to -1. 89 * @hide 90 */ setStateInvalid()91 public abstract void setStateInvalid(); 92 93 /** 94 * Return a new CellLocation object representing an unknown 95 * location, or null for unknown/none phone radio types. 96 * 97 */ getEmpty()98 public static CellLocation getEmpty() { 99 // TelephonyManager.getDefault().getCurrentPhoneType() handles the case when 100 // ITelephony interface is not up yet. 101 switch(TelephonyManager.getDefault().getCurrentPhoneType()) { 102 case PhoneConstants.PHONE_TYPE_CDMA: 103 return new CdmaCellLocation(); 104 case PhoneConstants.PHONE_TYPE_GSM: 105 return new GsmCellLocation(); 106 default: 107 return null; 108 } 109 } 110 } 111