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