blob: 2d0bd52f84eef2d23606dde02bfa69f79824d157 [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
Artur Satayev74cb7192019-12-10 17:47:56 +000019import android.compat.annotation.UnsupportedAppUsage;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import android.os.Bundle;
21import android.os.RemoteException;
Wink Saville767a6622009-04-02 01:37:02 -070022import android.telephony.cdma.CdmaCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.telephony.gsm.GsmCellLocation;
Artur Satayev74cb7192019-12-10 17:47:56 +000024
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import 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 {
Peter Wangd9eebca2019-12-30 16:14:01 -080040 ITelephony phone = ITelephony.Stub.asInterface(
41 TelephonyFrameworkInitializer
42 .getTelephonyServiceManager()
43 .getTelephonyServiceRegisterer()
44 .get());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045 if (phone != null) {
46 phone.updateServiceLocation();
47 }
48 } catch (RemoteException ex) {
49 // ignore it
50 }
51 }
52
53 /**
54 * Create a new CellLocation from a intent notifier Bundle
55 *
Jayachandran C4eda57e2020-01-07 16:20:33 -080056 * This method maybe used by external applications.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057 *
58 * @param bundle Bundle from intent notifier
59 * @return newly created CellLocation
60 *
61 * @hide
62 */
Mathew Inwood323d08f2018-08-16 11:30:29 +010063 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064 public static CellLocation newFromBundle(Bundle bundle) {
Wink Saville9d72be32011-02-01 19:22:15 -080065 // TelephonyManager.getDefault().getCurrentPhoneType() handles the case when
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -070066 // ITelephony interface is not up yet.
Wink Saville9d72be32011-02-01 19:22:15 -080067 switch(TelephonyManager.getDefault().getCurrentPhoneType()) {
Wink Savillea639b312012-07-10 12:37:54 -070068 case PhoneConstants.PHONE_TYPE_CDMA:
Wink Saville767a6622009-04-02 01:37:02 -070069 return new CdmaCellLocation(bundle);
Wink Savillea639b312012-07-10 12:37:54 -070070 case PhoneConstants.PHONE_TYPE_GSM:
Wink Saville767a6622009-04-02 01:37:02 -070071 return new GsmCellLocation(bundle);
Tammo Spalink3cc97f82009-09-21 15:26:10 +080072 default:
73 return null;
Wink Saville767a6622009-04-02 01:37:02 -070074 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075 }
76
77 /**
78 * @hide
79 */
Mathew Inwood323d08f2018-08-16 11:30:29 +010080 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081 public abstract void fillInNotifierBundle(Bundle bundle);
82
83 /**
John Wang41a46712010-03-09 15:48:58 -080084 * @hide
85 */
Mathew Inwood323d08f2018-08-16 11:30:29 +010086 @UnsupportedAppUsage
John Wang41a46712010-03-09 15:48:58 -080087 public abstract boolean isEmpty();
88
89 /**
Amit Mahajan37c28392015-11-25 17:07:47 -080090 * Invalidate this object. The location area code and the cell id are set to -1.
91 * @hide
92 */
93 public abstract void setStateInvalid();
94
95 /**
Tammo Spalink3cc97f82009-09-21 15:26:10 +080096 * Return a new CellLocation object representing an unknown
97 * location, or null for unknown/none phone radio types.
Wink Saville767a6622009-04-02 01:37:02 -070098 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 */
100 public static CellLocation getEmpty() {
Wink Saville9d72be32011-02-01 19:22:15 -0800101 // TelephonyManager.getDefault().getCurrentPhoneType() handles the case when
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700102 // ITelephony interface is not up yet.
Wink Saville9d72be32011-02-01 19:22:15 -0800103 switch(TelephonyManager.getDefault().getCurrentPhoneType()) {
Wink Savillea639b312012-07-10 12:37:54 -0700104 case PhoneConstants.PHONE_TYPE_CDMA:
Wink Saville767a6622009-04-02 01:37:02 -0700105 return new CdmaCellLocation();
Wink Savillea639b312012-07-10 12:37:54 -0700106 case PhoneConstants.PHONE_TYPE_GSM:
Wink Saville767a6622009-04-02 01:37:02 -0700107 return new GsmCellLocation();
Tammo Spalink3cc97f82009-09-21 15:26:10 +0800108 default:
109 return null;
Wink Saville767a6622009-04-02 01:37:02 -0700110 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112}