blob: f9a222f22640ac2760677b2bafbdd61ce9a1a965 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package android.telephony;
18
19import android.os.Bundle;
20import android.os.RemoteException;
21import android.os.ServiceManager;
Wink Saville767a6622009-04-02 01:37:02 -070022
23import android.telephony.cdma.CdmaCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.telephony.gsm.GsmCellLocation;
25import com.android.internal.telephony.ITelephony;
Wink Savillea639b312012-07-10 12:37:54 -070026import com.android.internal.telephony.PhoneConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027
28/**
Tammo Spalink3cc97f82009-09-21 15:26:10 +080029 * Abstract class that represents the location of the device. {@more}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030 */
31public 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 Saville9d72be32011-02-01 19:22:15 -080061 // TelephonyManager.getDefault().getCurrentPhoneType() handles the case when
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -070062 // ITelephony interface is not up yet.
Wink Saville9d72be32011-02-01 19:22:15 -080063 switch(TelephonyManager.getDefault().getCurrentPhoneType()) {
Wink Savillea639b312012-07-10 12:37:54 -070064 case PhoneConstants.PHONE_TYPE_CDMA:
Wink Saville767a6622009-04-02 01:37:02 -070065 return new CdmaCellLocation(bundle);
Wink Savillea639b312012-07-10 12:37:54 -070066 case PhoneConstants.PHONE_TYPE_GSM:
Wink Saville767a6622009-04-02 01:37:02 -070067 return new GsmCellLocation(bundle);
Tammo Spalink3cc97f82009-09-21 15:26:10 +080068 default:
69 return null;
Wink Saville767a6622009-04-02 01:37:02 -070070 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071 }
72
73 /**
74 * @hide
75 */
76 public abstract void fillInNotifierBundle(Bundle bundle);
77
78 /**
John Wang41a46712010-03-09 15:48:58 -080079 * @hide
80 */
81 public abstract boolean isEmpty();
82
83 /**
Tammo Spalink3cc97f82009-09-21 15:26:10 +080084 * Return a new CellLocation object representing an unknown
85 * location, or null for unknown/none phone radio types.
Wink Saville767a6622009-04-02 01:37:02 -070086 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087 */
88 public static CellLocation getEmpty() {
Wink Saville9d72be32011-02-01 19:22:15 -080089 // TelephonyManager.getDefault().getCurrentPhoneType() handles the case when
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -070090 // ITelephony interface is not up yet.
Wink Saville9d72be32011-02-01 19:22:15 -080091 switch(TelephonyManager.getDefault().getCurrentPhoneType()) {
Wink Savillea639b312012-07-10 12:37:54 -070092 case PhoneConstants.PHONE_TYPE_CDMA:
Wink Saville767a6622009-04-02 01:37:02 -070093 return new CdmaCellLocation();
Wink Savillea639b312012-07-10 12:37:54 -070094 case PhoneConstants.PHONE_TYPE_GSM:
Wink Saville767a6622009-04-02 01:37:02 -070095 return new GsmCellLocation();
Tammo Spalink3cc97f82009-09-21 15:26:10 +080096 default:
97 return null;
Wink Saville767a6622009-04-02 01:37:02 -070098 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100}