CellLocation.java revision 37c2839f70293d72b504cb0b84ad81d9419ad8bc
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
17package android.telephony;
18
19import android.os.Bundle;
20import android.os.RemoteException;
21import android.os.ServiceManager;
22
23import android.telephony.cdma.CdmaCellLocation;
24import android.telephony.gsm.GsmCellLocation;
25import com.android.internal.telephony.ITelephony;
26import com.android.internal.telephony.PhoneConstants;
27
28/**
29 * Abstract class that represents the location of the device.  {@more}
30 */
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) {
61        // TelephonyManager.getDefault().getCurrentPhoneType() handles the case when
62        // ITelephony interface is not up yet.
63        switch(TelephonyManager.getDefault().getCurrentPhoneType()) {
64        case PhoneConstants.PHONE_TYPE_CDMA:
65            return new CdmaCellLocation(bundle);
66        case PhoneConstants.PHONE_TYPE_GSM:
67            return new GsmCellLocation(bundle);
68        default:
69            return null;
70        }
71    }
72
73    /**
74     * @hide
75     */
76    public abstract void fillInNotifierBundle(Bundle bundle);
77
78    /**
79     * @hide
80     */
81    public abstract boolean isEmpty();
82
83    /**
84     * Invalidate this object.  The location area code and the cell id are set to -1.
85     * @hide
86     */
87    public abstract void setStateInvalid();
88
89    /**
90     * Return a new CellLocation object representing an unknown
91     * location, or null for unknown/none phone radio types.
92     *
93     */
94    public static CellLocation getEmpty() {
95        // TelephonyManager.getDefault().getCurrentPhoneType() handles the case when
96        // ITelephony interface is not up yet.
97        switch(TelephonyManager.getDefault().getCurrentPhoneType()) {
98        case PhoneConstants.PHONE_TYPE_CDMA:
99            return new CdmaCellLocation();
100        case PhoneConstants.PHONE_TYPE_GSM:
101            return new GsmCellLocation();
102        default:
103            return null;
104        }
105    }
106}
107