The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | |
Mike Lockwood | 00b7427 | 2010-03-26 10:41:48 -0400 | [diff] [blame] | 17 | package com.android.server.location; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 19 | import android.app.AlarmManager; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 20 | import android.app.AppOpsManager; |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 21 | import android.app.PendingIntent; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 22 | import android.content.BroadcastReceiver; |
Yu-Han Yang | 74041ff | 2018-04-06 15:57:31 -0700 | [diff] [blame] | 23 | import android.content.ContentResolver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.content.Context; |
| 25 | import android.content.Intent; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 26 | import android.content.IntentFilter; |
destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 27 | import android.hardware.location.GeofenceHardware; |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 28 | import android.hardware.location.GeofenceHardwareImpl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.location.Criteria; |
destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 30 | import android.location.FusedBatchOptions; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 31 | import android.location.GnssMeasurementsEvent; |
| 32 | import android.location.GnssNavigationMessage; |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 33 | import android.location.GnssStatus; |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 34 | import android.location.IGpsGeofenceHardware; |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 35 | import android.location.INetInitiatedListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.location.Location; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 37 | import android.location.LocationListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | import android.location.LocationManager; |
| 39 | import android.location.LocationProvider; |
Stan Chesnutt | 1d72d8c | 2013-04-15 19:18:02 -0700 | [diff] [blame] | 40 | import android.location.LocationRequest; |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 41 | import android.os.AsyncTask; |
Dianne Hackborn | 91268cf | 2013-06-13 19:06:50 -0700 | [diff] [blame] | 42 | import android.os.BatteryStats; |
Mike Lockwood | 63aa5a6 | 2010-04-14 19:21:31 -0400 | [diff] [blame] | 43 | import android.os.Binder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | import android.os.Bundle; |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 45 | import android.os.Handler; |
Victoria Lease | 5cd731a | 2012-12-19 15:04:21 -0800 | [diff] [blame] | 46 | import android.os.Looper; |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 47 | import android.os.Message; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 48 | import android.os.PersistableBundle; |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 49 | import android.os.PowerManager; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 50 | import android.os.PowerManager.ServiceType; |
| 51 | import android.os.PowerSaveState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | import android.os.RemoteException; |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 53 | import android.os.ServiceManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | import android.os.SystemClock; |
Colin Cross | 7c030ed | 2014-01-28 09:33:53 -0800 | [diff] [blame] | 55 | import android.os.SystemProperties; |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 56 | import android.os.UserHandle; |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 57 | import android.os.WorkSource; |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 58 | import android.os.WorkSource.WorkChain; |
Mike Lockwood | bcab8df | 2009-06-25 16:39:09 -0400 | [diff] [blame] | 59 | import android.provider.Settings; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 60 | import android.telephony.CarrierConfigManager; |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 61 | import android.telephony.SubscriptionManager; |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 62 | import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener; |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 63 | import android.telephony.TelephonyManager; |
| 64 | import android.telephony.gsm.GsmCellLocation; |
Colin Cross | 7c030ed | 2014-01-28 09:33:53 -0800 | [diff] [blame] | 65 | import android.text.TextUtils; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | import android.util.Log; |
Yu-Han Yang | a1862b5 | 2018-02-20 17:05:59 -0800 | [diff] [blame] | 67 | |
jackqdyulei | 455e90a | 2017-02-09 15:29:16 -0800 | [diff] [blame] | 68 | import com.android.internal.app.IBatteryStats; |
| 69 | import com.android.internal.location.GpsNetInitiatedHandler; |
| 70 | import com.android.internal.location.GpsNetInitiatedHandler.GpsNiNotification; |
| 71 | import com.android.internal.location.ProviderProperties; |
| 72 | import com.android.internal.location.ProviderRequest; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 73 | import com.android.internal.location.gnssmetrics.GnssMetrics; |
Yu-Han Yang | 66c7ea9 | 2018-03-11 17:17:15 -0700 | [diff] [blame] | 74 | import com.android.server.location.GnssSatelliteBlacklistHelper.GnssSatelliteBlacklistCallback; |
Yu-Han Yang | a1862b5 | 2018-02-20 17:05:59 -0800 | [diff] [blame] | 75 | import com.android.server.location.NtpTimeHelper.InjectNtpTimeCallback; |
Yu-Han Yang | 66c7ea9 | 2018-03-11 17:17:15 -0700 | [diff] [blame] | 76 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 77 | import java.io.FileDescriptor; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 78 | import java.io.PrintWriter; |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 79 | import java.lang.annotation.ElementType; |
| 80 | import java.lang.annotation.Retention; |
| 81 | import java.lang.annotation.RetentionPolicy; |
| 82 | import java.lang.annotation.Target; |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 83 | import java.util.ArrayList; |
Andreas Gampe | e6748ce | 2015-12-11 18:00:38 -0800 | [diff] [blame] | 84 | import java.util.Arrays; |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 85 | import java.util.List; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 86 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | /** |
gomo | 4402af6 | 2017-01-11 13:20:13 -0800 | [diff] [blame] | 88 | * A GNSS implementation of LocationProvider used by LocationManager. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | * |
| 90 | * {@hide} |
| 91 | */ |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 92 | public class GnssLocationProvider extends AbstractLocationProvider implements |
| 93 | InjectNtpTimeCallback, |
| 94 | GnssSatelliteBlacklistCallback { |
| 95 | |
| 96 | /** |
| 97 | * Indicates that this method is a native entry point. Useful purely for IDEs which can |
| 98 | * understand entry points, and thus eliminate incorrect warnings about methods not used. |
| 99 | */ |
| 100 | @Target(ElementType.METHOD) |
| 101 | @Retention(RetentionPolicy.SOURCE) |
| 102 | private @interface NativeEntryPoint { |
| 103 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 105 | private static final String TAG = "GnssLocationProvider"; |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 106 | |
Brian Muramatsu | 1715cb3 | 2012-08-08 17:32:21 -0700 | [diff] [blame] | 107 | private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
| 108 | private static final boolean VERBOSE = Log.isLoggable(TAG, Log.VERBOSE); |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 109 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 110 | private static final ProviderProperties PROPERTIES = new ProviderProperties( |
| 111 | true, true, false, false, true, true, true, |
| 112 | Criteria.POWER_HIGH, Criteria.ACCURACY_FINE); |
| 113 | |
gomo | 4402af6 | 2017-01-11 13:20:13 -0800 | [diff] [blame] | 114 | // these need to match GnssPositionMode enum in IGnss.hal |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 115 | private static final int GPS_POSITION_MODE_STANDALONE = 0; |
| 116 | private static final int GPS_POSITION_MODE_MS_BASED = 1; |
| 117 | private static final int GPS_POSITION_MODE_MS_ASSISTED = 2; |
| 118 | |
gomo | 4402af6 | 2017-01-11 13:20:13 -0800 | [diff] [blame] | 119 | // these need to match GnssPositionRecurrence enum in IGnss.hal |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 120 | private static final int GPS_POSITION_RECURRENCE_PERIODIC = 0; |
| 121 | private static final int GPS_POSITION_RECURRENCE_SINGLE = 1; |
| 122 | |
gomo | 4402af6 | 2017-01-11 13:20:13 -0800 | [diff] [blame] | 123 | // these need to match GnssStatusValue enum in IGnssCallback.hal |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | private static final int GPS_STATUS_NONE = 0; |
| 125 | private static final int GPS_STATUS_SESSION_BEGIN = 1; |
| 126 | private static final int GPS_STATUS_SESSION_END = 2; |
| 127 | private static final int GPS_STATUS_ENGINE_ON = 3; |
| 128 | private static final int GPS_STATUS_ENGINE_OFF = 4; |
| 129 | |
gomo | 4402af6 | 2017-01-11 13:20:13 -0800 | [diff] [blame] | 130 | // these need to match GnssLocationFlags enum in types.hal |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | private static final int LOCATION_INVALID = 0; |
| 132 | private static final int LOCATION_HAS_LAT_LONG = 1; |
| 133 | private static final int LOCATION_HAS_ALTITUDE = 2; |
| 134 | private static final int LOCATION_HAS_SPEED = 4; |
| 135 | private static final int LOCATION_HAS_BEARING = 8; |
gomo | 4402af6 | 2017-01-11 13:20:13 -0800 | [diff] [blame] | 136 | private static final int LOCATION_HAS_HORIZONTAL_ACCURACY = 16; |
| 137 | private static final int LOCATION_HAS_VERTICAL_ACCURACY = 32; |
| 138 | private static final int LOCATION_HAS_SPEED_ACCURACY = 64; |
| 139 | private static final int LOCATION_HAS_BEARING_ACCURACY = 128; |
Mike Lockwood | e3635c9 | 2009-05-11 08:38:02 -0400 | [diff] [blame] | 140 | |
gomo | 4402af6 | 2017-01-11 13:20:13 -0800 | [diff] [blame] | 141 | // IMPORTANT - the GPS_DELETE_* symbols here must match GnssAidingData enum in IGnss.hal |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | private static final int GPS_DELETE_EPHEMERIS = 0x0001; |
| 143 | private static final int GPS_DELETE_ALMANAC = 0x0002; |
| 144 | private static final int GPS_DELETE_POSITION = 0x0004; |
| 145 | private static final int GPS_DELETE_TIME = 0x0008; |
| 146 | private static final int GPS_DELETE_IONO = 0x0010; |
| 147 | private static final int GPS_DELETE_UTC = 0x0020; |
| 148 | private static final int GPS_DELETE_HEALTH = 0x0040; |
| 149 | private static final int GPS_DELETE_SVDIR = 0x0080; |
| 150 | private static final int GPS_DELETE_SVSTEER = 0x0100; |
| 151 | private static final int GPS_DELETE_SADATA = 0x0200; |
| 152 | private static final int GPS_DELETE_RTI = 0x0400; |
| 153 | private static final int GPS_DELETE_CELLDB_INFO = 0x8000; |
| 154 | private static final int GPS_DELETE_ALL = 0xFFFF; |
| 155 | |
gomo | 4402af6 | 2017-01-11 13:20:13 -0800 | [diff] [blame] | 156 | // The GPS_CAPABILITY_* flags must match Capabilities enum in IGnssCallback.hal |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 157 | private static final int GPS_CAPABILITY_SCHEDULING = 0x0000001; |
| 158 | private static final int GPS_CAPABILITY_MSB = 0x0000002; |
| 159 | private static final int GPS_CAPABILITY_MSA = 0x0000004; |
| 160 | private static final int GPS_CAPABILITY_SINGLE_SHOT = 0x0000008; |
Mike Lockwood | 9b9fb5c | 2011-06-29 15:09:40 -0400 | [diff] [blame] | 161 | private static final int GPS_CAPABILITY_ON_DEMAND_TIME = 0x0000010; |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 162 | private static final int GPS_CAPABILITY_GEOFENCING = 0x0000020; |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 163 | public static final int GPS_CAPABILITY_MEASUREMENTS = 0x0000040; |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 164 | private static final int GPS_CAPABILITY_NAV_MESSAGES = 0x0000080; |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 165 | |
Tsuwei Chen | 462bcd8 | 2014-09-17 12:28:49 -0700 | [diff] [blame] | 166 | // The AGPS SUPL mode |
| 167 | private static final int AGPS_SUPL_MODE_MSA = 0x02; |
| 168 | private static final int AGPS_SUPL_MODE_MSB = 0x01; |
| 169 | |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 170 | // Handler messages |
| 171 | private static final int CHECK_LOCATION = 1; |
| 172 | private static final int ENABLE = 2; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 173 | private static final int SET_REQUEST = 3; |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 174 | private static final int UPDATE_NETWORK_STATE = 4; |
| 175 | private static final int INJECT_NTP_TIME = 5; |
| 176 | private static final int DOWNLOAD_XTRA_DATA = 6; |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 177 | private static final int UPDATE_LOCATION = 7; // Handle external location from network listener |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 178 | private static final int ADD_LISTENER = 8; |
| 179 | private static final int REMOVE_LISTENER = 9; |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 180 | private static final int DOWNLOAD_XTRA_DATA_FINISHED = 11; |
Meng Wang | 19b214d | 2018-11-07 12:14:39 -0800 | [diff] [blame] | 181 | private static final int SUBSCRIPTION_OR_CARRIER_CONFIG_CHANGED = 12; |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 182 | private static final int INITIALIZE_HANDLER = 13; |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 183 | private static final int REQUEST_SUPL_CONNECTION = 14; |
| 184 | private static final int RELEASE_SUPL_CONNECTION = 15; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 185 | private static final int REQUEST_LOCATION = 16; |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 186 | private static final int REPORT_LOCATION = 17; // HAL reports location |
| 187 | private static final int REPORT_SV_STATUS = 18; // HAL reports SV status |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 188 | |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 189 | // Request setid |
| 190 | private static final int AGPS_RIL_REQUEST_SETID_IMSI = 1; |
| 191 | private static final int AGPS_RIL_REQUEST_SETID_MSISDN = 2; |
| 192 | |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 193 | // ref. location info |
| 194 | private static final int AGPS_REF_LOCATION_TYPE_GSM_CELLID = 1; |
| 195 | private static final int AGPS_REF_LOCATION_TYPE_UMTS_CELLID = 2; |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 196 | |
| 197 | // set id info |
| 198 | private static final int AGPS_SETID_TYPE_NONE = 0; |
| 199 | private static final int AGPS_SETID_TYPE_IMSI = 1; |
| 200 | private static final int AGPS_SETID_TYPE_MSISDN = 2; |
| 201 | |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 202 | private static final int GPS_GEOFENCE_UNAVAILABLE = 1 << 0L; |
| 203 | private static final int GPS_GEOFENCE_AVAILABLE = 1 << 1L; |
destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 204 | |
gomo | 4402af6 | 2017-01-11 13:20:13 -0800 | [diff] [blame] | 205 | // GPS Geofence errors. Should match GeofenceStatus enum in IGnssGeofenceCallback.hal. |
destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 206 | private static final int GPS_GEOFENCE_OPERATION_SUCCESS = 0; |
| 207 | private static final int GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES = 100; |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 208 | private static final int GPS_GEOFENCE_ERROR_ID_EXISTS = -101; |
destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 209 | private static final int GPS_GEOFENCE_ERROR_ID_UNKNOWN = -102; |
| 210 | private static final int GPS_GEOFENCE_ERROR_INVALID_TRANSITION = -103; |
| 211 | private static final int GPS_GEOFENCE_ERROR_GENERIC = -149; |
| 212 | |
Tsuwei Chen | 678c13c | 2014-09-22 17:48:41 -0700 | [diff] [blame] | 213 | // TCP/IP constants. |
| 214 | // Valid TCP/UDP port range is (0, 65535]. |
| 215 | private static final int TCP_MIN_PORT = 0; |
| 216 | private static final int TCP_MAX_PORT = 0xffff; |
| 217 | |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 218 | // 1 second, or 1 Hz frequency. |
| 219 | private static final long LOCATION_UPDATE_MIN_TIME_INTERVAL_MILLIS = 1000; |
Yu-Han Yang | 639f759 | 2018-06-07 11:58:52 -0700 | [diff] [blame] | 220 | // Default update duration in milliseconds for REQUEST_LOCATION. |
Yu-Han Yang | 9e2a823 | 2018-06-14 12:10:08 -0700 | [diff] [blame] | 221 | private static final long LOCATION_UPDATE_DURATION_MILLIS = 10 * 1000; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 222 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 223 | /** simpler wrapper for ProviderRequest + Worksource */ |
| 224 | private static class GpsRequest { |
| 225 | public ProviderRequest request; |
| 226 | public WorkSource source; |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 227 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 228 | public GpsRequest(ProviderRequest request, WorkSource source) { |
| 229 | this.request = request; |
| 230 | this.source = source; |
| 231 | } |
| 232 | } |
| 233 | |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 234 | // Threadsafe class to hold stats reported in the Extras Bundle |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 235 | private static class LocationExtras { |
| 236 | private int mSvCount; |
| 237 | private int mMeanCn0; |
| 238 | private int mMaxCn0; |
| 239 | private final Bundle mBundle; |
| 240 | |
| 241 | public LocationExtras() { |
| 242 | mBundle = new Bundle(); |
| 243 | } |
| 244 | |
| 245 | public void set(int svCount, int meanCn0, int maxCn0) { |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 246 | synchronized (this) { |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 247 | mSvCount = svCount; |
| 248 | mMeanCn0 = meanCn0; |
| 249 | mMaxCn0 = maxCn0; |
| 250 | } |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 251 | setBundle(mBundle); |
| 252 | } |
| 253 | |
| 254 | public void reset() { |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 255 | set(0, 0, 0); |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | // Also used by outside methods to add to other bundles |
| 259 | public void setBundle(Bundle extras) { |
| 260 | if (extras != null) { |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 261 | synchronized (this) { |
| 262 | extras.putInt("satellites", mSvCount); |
| 263 | extras.putInt("meanCn0", mMeanCn0); |
| 264 | extras.putInt("maxCn0", mMaxCn0); |
| 265 | } |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 266 | } |
| 267 | } |
| 268 | |
| 269 | public Bundle getBundle() { |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 270 | synchronized (this) { |
| 271 | return new Bundle(mBundle); |
| 272 | } |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 273 | } |
| 274 | } |
| 275 | |
Yu-Han Yang | 66c7ea9 | 2018-03-11 17:17:15 -0700 | [diff] [blame] | 276 | private final Object mLock = new Object(); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 277 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 278 | // current status |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 279 | private int mStatus = LocationProvider.TEMPORARILY_UNAVAILABLE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 280 | |
| 281 | // time for last status update |
| 282 | private long mStatusUpdateTime = SystemClock.elapsedRealtime(); |
Mike Lockwood | d53ba01 | 2010-04-15 20:41:26 -0400 | [diff] [blame] | 283 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 284 | // turn off GPS fix icon if we haven't received a fix in 10 seconds |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 285 | private static final long RECENT_FIX_TIMEOUT = 10 * 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 287 | // stop trying if we do not receive a fix within 60 seconds |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 288 | private static final int NO_FIX_TIMEOUT = 60 * 1000; |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 289 | |
Nick Pelly | b041f23 | 2012-05-07 17:12:25 -0700 | [diff] [blame] | 290 | // if the fix interval is below this we leave GPS on, |
| 291 | // if above then we cycle the GPS driver. |
| 292 | // Typical hot TTTF is ~5 seconds, so 10 seconds seems sane. |
| 293 | private static final int GPS_POLLING_THRESHOLD_INTERVAL = 10 * 1000; |
| 294 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 295 | // how long to wait if we have a network error in NTP or XTRA downloading |
Wei Liu | 6f6326b | 2015-06-24 23:47:50 -0700 | [diff] [blame] | 296 | // the initial value of the exponential backoff |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 297 | // current setting - 5 minutes |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 298 | private static final long RETRY_INTERVAL = 5 * 60 * 1000; |
Wei Liu | 6f6326b | 2015-06-24 23:47:50 -0700 | [diff] [blame] | 299 | // how long to wait if we have a network error in NTP or XTRA downloading |
| 300 | // the max value of the exponential backoff |
| 301 | // current setting - 4 hours |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 302 | private static final long MAX_RETRY_INTERVAL = 4 * 60 * 60 * 1000; |
Wei Liu | 6f6326b | 2015-06-24 23:47:50 -0700 | [diff] [blame] | 303 | |
Wei Wang | c5706f6 | 2017-04-18 11:26:26 -0700 | [diff] [blame] | 304 | // Timeout when holding wakelocks for downloading XTRA data. |
| 305 | private static final long DOWNLOAD_XTRA_DATA_TIMEOUT_MS = 60 * 1000; |
| 306 | |
Yu-Han Yang | a1862b5 | 2018-02-20 17:05:59 -0800 | [diff] [blame] | 307 | private final ExponentialBackOff mXtraBackOff = new ExponentialBackOff(RETRY_INTERVAL, |
| 308 | MAX_RETRY_INTERVAL); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 309 | |
| 310 | // true if we are enabled, protected by this |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 311 | private boolean mEnabled = true; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 312 | |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 313 | // states for injecting ntp and downloading xtra data |
| 314 | private static final int STATE_PENDING_NETWORK = 0; |
| 315 | private static final int STATE_DOWNLOADING = 1; |
| 316 | private static final int STATE_IDLE = 2; |
| 317 | |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 318 | // flags to trigger NTP or XTRA data download when network becomes available |
| 319 | // initialized to true so we do NTP and XTRA when the network comes up after booting |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 320 | private int mDownloadXtraDataPending = STATE_PENDING_NETWORK; |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 321 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 322 | // true if GPS is navigating |
| 323 | private boolean mNavigating; |
Mike Lockwood | cf1d8cb | 2010-01-20 10:14:54 -0500 | [diff] [blame] | 324 | |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 325 | // requested frequency of fixes, in milliseconds |
| 326 | private int mFixInterval = 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 327 | |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 328 | // true if low power mode for the GNSS chipset is part of the latest request. |
| 329 | private boolean mLowPowerMode = false; |
| 330 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 331 | // true if we started navigation |
| 332 | private boolean mStarted; |
| 333 | |
Stan Chesnutt | 1d72d8c | 2013-04-15 19:18:02 -0700 | [diff] [blame] | 334 | // true if single shot request is in progress |
| 335 | private boolean mSingleShot; |
| 336 | |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 337 | // capabilities of the GPS engine |
| 338 | private int mEngineCapabilities; |
| 339 | |
Mike Lockwood | 1a1cd3a | 2010-08-17 07:42:54 -0400 | [diff] [blame] | 340 | // true if XTRA is supported |
| 341 | private boolean mSupportsXtra; |
| 342 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 343 | // for calculating time to first fix |
| 344 | private long mFixRequestTime = 0; |
| 345 | // time to first fix for most recent session |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 346 | private int mTimeToFirstFix = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 347 | // time we received our last fix |
| 348 | private long mLastFixTime; |
| 349 | |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 350 | private int mPositionMode; |
Yu-Han Yang | c8b9ff7 | 2018-04-17 00:47:24 -0700 | [diff] [blame] | 351 | private GnssPositionMode mLastPositionMode; |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 352 | |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 353 | // Current request from underlying location clients. |
| 354 | private ProviderRequest mProviderRequest = null; |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 355 | // The WorkSource associated with the most recent client request (i.e, most recent call to |
| 356 | // setRequest). |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 357 | private WorkSource mWorkSource = null; |
| 358 | // True if gps should be disabled (used to support battery saver mode in settings). |
| 359 | private boolean mDisableGps = false; |
| 360 | |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 361 | /** |
| 362 | * Properties loaded from PROPERTIES_FILE. |
| 363 | * It must be accessed only inside {@link #mHandler}. |
| 364 | */ |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame^] | 365 | private GnssConfiguration mGnssConfiguration; |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 366 | |
Mike Lockwood | 734d603 | 2009-07-28 18:30:25 -0700 | [diff] [blame] | 367 | private String mSuplServerHost; |
Tsuwei Chen | 678c13c | 2014-09-22 17:48:41 -0700 | [diff] [blame] | 368 | private int mSuplServerPort = TCP_MIN_PORT; |
Mike Lockwood | 734d603 | 2009-07-28 18:30:25 -0700 | [diff] [blame] | 369 | private String mC2KServerHost; |
| 370 | private int mC2KServerPort; |
Tsuwei Chen | 3324e95 | 2014-09-07 01:30:42 -0700 | [diff] [blame] | 371 | private boolean mSuplEsEnabled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 373 | private final Context mContext; |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 374 | private final LocationExtras mLocationExtras = new LocationExtras(); |
Anil Admal | 75b9fd6 | 2018-11-28 11:22:50 -0800 | [diff] [blame] | 375 | private final GnssStatusListenerHelper mGnssStatusListenerHelper; |
Yu-Han Yang | 66c7ea9 | 2018-03-11 17:17:15 -0700 | [diff] [blame] | 376 | private final GnssSatelliteBlacklistHelper mGnssSatelliteBlacklistHelper; |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 377 | private final GnssMeasurementsProvider mGnssMeasurementsProvider; |
| 378 | private final GnssNavigationMessageProvider mGnssNavigationMessageProvider; |
Yu-Han Yang | 0756138 | 2018-02-21 13:08:37 -0800 | [diff] [blame] | 379 | private final LocationChangeListener mNetworkLocationListener = new NetworkLocationListener(); |
| 380 | private final LocationChangeListener mFusedLocationListener = new FusedLocationListener(); |
Yu-Han Yang | a1862b5 | 2018-02-20 17:05:59 -0800 | [diff] [blame] | 381 | private final NtpTimeHelper mNtpTimeHelper; |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 382 | private final GnssBatchingProvider mGnssBatchingProvider; |
Yu-Han Yang | 890ca8b | 2018-04-16 22:11:31 -0700 | [diff] [blame] | 383 | private final GnssGeofenceProvider mGnssGeofenceProvider; |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 384 | |
Victoria Lease | 5c24fd0 | 2012-10-01 11:00:50 -0700 | [diff] [blame] | 385 | // Handler for processing events |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 386 | private Handler mHandler; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 387 | |
Anil Admal | 50ba15e | 2018-11-01 16:42:42 -0700 | [diff] [blame] | 388 | private final GnssNetworkConnectivityHandler mNetworkConnectivityHandler; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 389 | private final GpsNetInitiatedHandler mNIHandler; |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 390 | |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 391 | // Wakelocks |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 392 | private final static String WAKELOCK_KEY = "GnssLocationProvider"; |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 393 | private final PowerManager.WakeLock mWakeLock; |
Wei Wang | b71c049 | 2017-05-01 20:24:19 -0700 | [diff] [blame] | 394 | private static final String DOWNLOAD_EXTRA_WAKELOCK_KEY = "GnssLocationProviderXtraDownload"; |
| 395 | private final PowerManager.WakeLock mDownloadXtraWakeLock; |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 396 | |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 397 | // Alarms |
| 398 | private final static String ALARM_WAKEUP = "com.android.internal.location.ALARM_WAKEUP"; |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 399 | private final static String ALARM_TIMEOUT = "com.android.internal.location.ALARM_TIMEOUT"; |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 400 | |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 401 | private final PowerManager mPowerManager; |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 402 | private final AlarmManager mAlarmManager; |
| 403 | private final PendingIntent mWakeupIntent; |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 404 | private final PendingIntent mTimeoutIntent; |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 405 | |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 406 | private final AppOpsManager mAppOps; |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 407 | private final IBatteryStats mBatteryStats; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 408 | |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 409 | // Current list of underlying location clients. |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 410 | // only modified on handler thread |
Dianne Hackborn | 002a54e | 2013-01-10 17:34:55 -0800 | [diff] [blame] | 411 | private WorkSource mClientSource = new WorkSource(); |
Mike Lockwood | f1218be | 2010-01-29 09:20:06 -0500 | [diff] [blame] | 412 | |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 413 | private GeofenceHardwareImpl mGeofenceHardwareImpl; |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 414 | |
| 415 | // Volatile for simple inter-thread sync on these values. |
| 416 | private volatile int mHardwareYear = 0; |
Wyatt Riley | 49097c0 | 2018-03-15 09:14:43 -0700 | [diff] [blame] | 417 | private volatile String mHardwareModelName; |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 418 | |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 419 | // Set lower than the current ITAR limit of 600m/s to allow this to trigger even if GPS HAL |
| 420 | // stops output right at 600m/s, depriving this of the information of a device that reaches |
| 421 | // greater than 600m/s, and higher than the speed of sound to avoid impacting most use cases. |
| 422 | private static final float ITAR_SPEED_LIMIT_METERS_PER_SECOND = 400.0F; |
Wyatt Riley | 042c48f | 2017-10-06 14:59:25 -0700 | [diff] [blame] | 423 | |
Wyatt Riley | 042c48f | 2017-10-06 14:59:25 -0700 | [diff] [blame] | 424 | private volatile boolean mItarSpeedLimitExceeded = false; |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 425 | |
Siddharth Ray | bb608c8 | 2017-03-16 11:33:34 -0700 | [diff] [blame] | 426 | // GNSS Metrics |
| 427 | private GnssMetrics mGnssMetrics; |
| 428 | |
Anil Admal | 75b9fd6 | 2018-11-28 11:22:50 -0800 | [diff] [blame] | 429 | public GnssStatusListenerHelper getGnssStatusProvider() { |
| 430 | return mGnssStatusListenerHelper; |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 431 | } |
| 432 | |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 433 | public IGpsGeofenceHardware getGpsGeofenceProxy() { |
Yu-Han Yang | 890ca8b | 2018-04-16 22:11:31 -0700 | [diff] [blame] | 434 | return mGnssGeofenceProvider; |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 435 | } |
| 436 | |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 437 | public GnssMeasurementsProvider getGnssMeasurementsProvider() { |
| 438 | return mGnssMeasurementsProvider; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 439 | } |
| 440 | |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 441 | public GnssNavigationMessageProvider getGnssNavigationMessageProvider() { |
| 442 | return mGnssNavigationMessageProvider; |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 443 | } |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 444 | private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 445 | @Override |
| 446 | public void onReceive(Context context, Intent intent) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 447 | String action = intent.getAction(); |
Tsuwei Chen | 48d37f9 | 2014-09-05 15:15:34 -0700 | [diff] [blame] | 448 | if (DEBUG) Log.d(TAG, "receive broadcast intent, action: " + action); |
destradaa | ee9fd34 | 2015-08-31 13:31:17 -0700 | [diff] [blame] | 449 | if (action == null) { |
| 450 | return; |
| 451 | } |
| 452 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 453 | switch (action) { |
| 454 | case ALARM_WAKEUP: |
| 455 | startNavigating(false); |
| 456 | break; |
| 457 | case ALARM_TIMEOUT: |
| 458 | hibernate(); |
| 459 | break; |
| 460 | case PowerManager.ACTION_POWER_SAVE_MODE_CHANGED: |
| 461 | case PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED: |
| 462 | case Intent.ACTION_SCREEN_OFF: |
| 463 | case Intent.ACTION_SCREEN_ON: |
| 464 | updateLowPowerMode(); |
| 465 | break; |
Meng Wang | 19b214d | 2018-11-07 12:14:39 -0800 | [diff] [blame] | 466 | case CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED: |
| 467 | subscriptionOrCarrierConfigChanged(context); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 468 | break; |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 469 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 470 | } |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 471 | }; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 472 | |
Meng Wang | 19b214d | 2018-11-07 12:14:39 -0800 | [diff] [blame] | 473 | // TODO(b/119326010): replace OnSubscriptionsChangedListener with |
| 474 | // ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED broadcast reseiver. |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 475 | private final OnSubscriptionsChangedListener mOnSubscriptionsChangedListener = |
| 476 | new OnSubscriptionsChangedListener() { |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 477 | @Override |
| 478 | public void onSubscriptionsChanged() { |
Meng Wang | 19b214d | 2018-11-07 12:14:39 -0800 | [diff] [blame] | 479 | sendMessage(SUBSCRIPTION_OR_CARRIER_CONFIG_CHANGED, 0, null); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 480 | } |
| 481 | }; |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 482 | |
Yu-Han Yang | 66c7ea9 | 2018-03-11 17:17:15 -0700 | [diff] [blame] | 483 | /** |
| 484 | * Implements {@link GnssSatelliteBlacklistCallback#onUpdateSatelliteBlacklist}. |
| 485 | */ |
| 486 | @Override |
| 487 | public void onUpdateSatelliteBlacklist(int[] constellations, int[] svids) { |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame^] | 488 | mHandler.post(() -> mGnssConfiguration.setSatelliteBlacklist(constellations, svids)); |
Yu-Han Yang | 66c7ea9 | 2018-03-11 17:17:15 -0700 | [diff] [blame] | 489 | } |
| 490 | |
Meng Wang | 19b214d | 2018-11-07 12:14:39 -0800 | [diff] [blame] | 491 | private void subscriptionOrCarrierConfigChanged(Context context) { |
Joe Onorato | 0c48410 | 2016-02-01 18:04:24 -0800 | [diff] [blame] | 492 | if (DEBUG) Log.d(TAG, "received SIM related action: "); |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 493 | TelephonyManager phone = (TelephonyManager) |
| 494 | mContext.getSystemService(Context.TELEPHONY_SERVICE); |
Ecco Park | 4fa1ab7 | 2016-10-24 13:04:52 -0700 | [diff] [blame] | 495 | CarrierConfigManager configManager = (CarrierConfigManager) |
| 496 | mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 497 | String mccMnc = phone.getSimOperator(); |
Ecco Park | 4fa1ab7 | 2016-10-24 13:04:52 -0700 | [diff] [blame] | 498 | boolean isKeepLppProfile = false; |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 499 | if (!TextUtils.isEmpty(mccMnc)) { |
Joe Onorato | 0c48410 | 2016-02-01 18:04:24 -0800 | [diff] [blame] | 500 | if (DEBUG) Log.d(TAG, "SIM MCC/MNC is available: " + mccMnc); |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 501 | synchronized (mLock) { |
Ecco Park | 4fa1ab7 | 2016-10-24 13:04:52 -0700 | [diff] [blame] | 502 | if (configManager != null) { |
| 503 | PersistableBundle b = configManager.getConfig(); |
Wyatt Riley | a8ce225 | 2017-09-01 13:31:17 -0700 | [diff] [blame] | 504 | if (b != null) { |
| 505 | isKeepLppProfile = |
Meng Wang | 19b214d | 2018-11-07 12:14:39 -0800 | [diff] [blame] | 506 | b.getBoolean(CarrierConfigManager.Gps.KEY_PERSIST_LPP_MODE_BOOL); |
Wyatt Riley | a8ce225 | 2017-09-01 13:31:17 -0700 | [diff] [blame] | 507 | } |
Ecco Park | 4fa1ab7 | 2016-10-24 13:04:52 -0700 | [diff] [blame] | 508 | } |
| 509 | if (isKeepLppProfile) { |
| 510 | // load current properties for the carrier |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame^] | 511 | mGnssConfiguration.loadPropertiesFromCarrierConfig(); |
| 512 | String lpp_profile = mGnssConfiguration.getLppProfile(); |
Ecco Park | 4fa1ab7 | 2016-10-24 13:04:52 -0700 | [diff] [blame] | 513 | // set the persist property LPP_PROFILE for the value |
Ecco Park | 8eec744 | 2017-08-04 16:21:59 -0700 | [diff] [blame] | 514 | if (lpp_profile != null) { |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame^] | 515 | SystemProperties.set(GnssConfiguration.LPP_PROFILE, lpp_profile); |
Ecco Park | 8eec744 | 2017-08-04 16:21:59 -0700 | [diff] [blame] | 516 | } |
Ecco Park | 624ac3c | 2016-07-18 14:08:05 -0700 | [diff] [blame] | 517 | } else { |
Ecco Park | 4fa1ab7 | 2016-10-24 13:04:52 -0700 | [diff] [blame] | 518 | // reset the persist property |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame^] | 519 | SystemProperties.set(GnssConfiguration.LPP_PROFILE, ""); |
Ecco Park | 624ac3c | 2016-07-18 14:08:05 -0700 | [diff] [blame] | 520 | } |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame^] | 521 | reloadGpsProperties(); |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 522 | mNIHandler.setSuplEsEnabled(mSuplEsEnabled); |
| 523 | } |
| 524 | } else { |
Joe Onorato | 0c48410 | 2016-02-01 18:04:24 -0800 | [diff] [blame] | 525 | if (DEBUG) Log.d(TAG, "SIM MCC/MNC is still not available"); |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 526 | } |
| 527 | } |
| 528 | |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 529 | private void updateLowPowerMode() { |
Adam Lesinski | 87c17df | 2015-05-27 13:24:13 -0700 | [diff] [blame] | 530 | // Disable GPS if we are in device idle mode. |
| 531 | boolean disableGps = mPowerManager.isDeviceIdleMode(); |
jackqdyulei | 455e90a | 2017-02-09 15:29:16 -0800 | [diff] [blame] | 532 | final PowerSaveState result = |
| 533 | mPowerManager.getPowerSaveState(ServiceType.GPS); |
| 534 | switch (result.gpsMode) { |
Makoto Onuki | 57f0f55 | 2017-12-11 12:22:18 -0800 | [diff] [blame] | 535 | case PowerManager.LOCATION_MODE_GPS_DISABLED_WHEN_SCREEN_OFF: |
Adam Lesinski | 87c17df | 2015-05-27 13:24:13 -0700 | [diff] [blame] | 536 | // If we are in battery saver mode and the screen is off, disable GPS. |
jackqdyulei | 455e90a | 2017-02-09 15:29:16 -0800 | [diff] [blame] | 537 | disableGps |= result.batterySaverEnabled && !mPowerManager.isInteractive(); |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 538 | break; |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 539 | } |
| 540 | if (disableGps != mDisableGps) { |
| 541 | mDisableGps = disableGps; |
| 542 | updateRequirements(); |
| 543 | } |
| 544 | } |
| 545 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 546 | public static boolean isSupported() { |
| 547 | return native_is_supported(); |
| 548 | } |
| 549 | |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame^] | 550 | private void reloadGpsProperties() { |
| 551 | mGnssConfiguration.reloadGpsProperties(); |
| 552 | setSuplHostPort(); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 553 | // TODO: we should get rid of C2K specific setting. |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame^] | 554 | mC2KServerHost = mGnssConfiguration.getC2KHost(); |
| 555 | mC2KServerPort = mGnssConfiguration.getC2KPort(TCP_MIN_PORT); |
| 556 | mNIHandler.setEmergencyExtensionSeconds(mGnssConfiguration.getEsExtensionSec()); |
| 557 | mSuplEsEnabled = mGnssConfiguration.getSuplEs(0) == 1; |
Colin Cross | 7c030ed | 2014-01-28 09:33:53 -0800 | [diff] [blame] | 558 | } |
| 559 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 560 | public GnssLocationProvider(Context context, LocationProviderManager locationProviderManager, |
Victoria Lease | 5cd731a | 2012-12-19 15:04:21 -0800 | [diff] [blame] | 561 | Looper looper) { |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 562 | super(locationProviderManager, true); |
| 563 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 564 | mContext = context; |
Mike Lockwood | 63598a0 | 2010-02-24 11:52:59 -0500 | [diff] [blame] | 565 | |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 566 | // Create a wake lock |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 567 | mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); |
| 568 | mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCK_KEY); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 569 | mWakeLock.setReferenceCounted(true); |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 570 | |
Wei Wang | b71c049 | 2017-05-01 20:24:19 -0700 | [diff] [blame] | 571 | // Create a separate wake lock for xtra downloader as it may be released due to timeout. |
| 572 | mDownloadXtraWakeLock = mPowerManager.newWakeLock( |
| 573 | PowerManager.PARTIAL_WAKE_LOCK, DOWNLOAD_EXTRA_WAKELOCK_KEY); |
| 574 | mDownloadXtraWakeLock.setReferenceCounted(true); |
| 575 | |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 576 | mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 577 | mWakeupIntent = PendingIntent.getBroadcast(mContext, 0, new Intent(ALARM_WAKEUP), 0); |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 578 | mTimeoutIntent = PendingIntent.getBroadcast(mContext, 0, new Intent(ALARM_TIMEOUT), 0); |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 579 | |
Anil Admal | 50ba15e | 2018-11-01 16:42:42 -0700 | [diff] [blame] | 580 | mNetworkConnectivityHandler = new GnssNetworkConnectivityHandler( |
| 581 | context, |
| 582 | GnssLocationProvider.this::onNetworkAvailable, |
| 583 | looper); |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 584 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 585 | // App ops service to keep track of who is accessing the GPS |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 586 | mAppOps = mContext.getSystemService(AppOpsManager.class); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 587 | |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 588 | // Battery statistics service to be notified when GPS turns on or off |
Dianne Hackborn | 91268cf | 2013-06-13 19:06:50 -0700 | [diff] [blame] | 589 | mBatteryStats = IBatteryStats.Stub.asInterface(ServiceManager.getService( |
| 590 | BatteryStats.SERVICE_NAME)); |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 591 | |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 592 | // Construct internal handler |
| 593 | mHandler = new ProviderHandler(looper); |
| 594 | |
| 595 | // Load GPS configuration and register listeners in the background: |
| 596 | // some operations, such as opening files and registering broadcast receivers, can take a |
| 597 | // relative long time, so the ctor() is kept to create objects needed by this instance, |
| 598 | // while IO initialization and registration is delegated to our internal handler |
| 599 | // this approach is just fine because events are posted to our handler anyway |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame^] | 600 | mGnssConfiguration = new GnssConfiguration(mContext); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 601 | sendMessage(INITIALIZE_HANDLER, 0, null); |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 602 | |
Tsuwei Chen | 3324e95 | 2014-09-07 01:30:42 -0700 | [diff] [blame] | 603 | // Create a GPS net-initiated handler. |
| 604 | mNIHandler = new GpsNetInitiatedHandler(context, |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 605 | mNetInitiatedListener, |
| 606 | mSuplEsEnabled); |
Tsuwei Chen | 3324e95 | 2014-09-07 01:30:42 -0700 | [diff] [blame] | 607 | |
Anil Admal | 75b9fd6 | 2018-11-28 11:22:50 -0800 | [diff] [blame] | 608 | mGnssStatusListenerHelper = new GnssStatusListenerHelper(mContext, mHandler) { |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 609 | @Override |
| 610 | protected boolean isAvailableInPlatform() { |
destradaa | 13a60b0 | 2015-01-15 18:36:01 -0800 | [diff] [blame] | 611 | return isSupported(); |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | @Override |
| 615 | protected boolean isGpsEnabled() { |
| 616 | return isEnabled(); |
| 617 | } |
| 618 | }; |
| 619 | |
Yu-Han Yang | 8de2150 | 2018-04-23 01:40:25 -0700 | [diff] [blame] | 620 | mGnssMeasurementsProvider = new GnssMeasurementsProvider(mContext, mHandler) { |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 621 | @Override |
| 622 | protected boolean isGpsEnabled() { |
| 623 | return isEnabled(); |
| 624 | } |
| 625 | }; |
| 626 | |
Anil Admal | 75b9fd6 | 2018-11-28 11:22:50 -0800 | [diff] [blame] | 627 | mGnssNavigationMessageProvider = new GnssNavigationMessageProvider(mContext, mHandler) { |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 628 | @Override |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 629 | protected boolean isGpsEnabled() { |
| 630 | return isEnabled(); |
| 631 | } |
| 632 | }; |
Yu-Han Yang | a1862b5 | 2018-02-20 17:05:59 -0800 | [diff] [blame] | 633 | |
Anil Admal | 50ba15e | 2018-11-01 16:42:42 -0700 | [diff] [blame] | 634 | mGnssMetrics = new GnssMetrics(mBatteryStats); |
Yu-Han Yang | 66c7ea9 | 2018-03-11 17:17:15 -0700 | [diff] [blame] | 635 | mNtpTimeHelper = new NtpTimeHelper(mContext, looper, this); |
| 636 | mGnssSatelliteBlacklistHelper = new GnssSatelliteBlacklistHelper(mContext, |
| 637 | looper, this); |
| 638 | mHandler.post(mGnssSatelliteBlacklistHelper::updateSatelliteBlacklist); |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 639 | mGnssBatchingProvider = new GnssBatchingProvider(); |
Yu-Han Yang | 6dc9f05 | 2018-12-04 17:11:24 -0800 | [diff] [blame] | 640 | mGnssGeofenceProvider = new GnssGeofenceProvider(); |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 641 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 642 | IntentFilter intentFilter = new IntentFilter(); |
| 643 | intentFilter.addAction(Intent.ACTION_SHUTDOWN); |
| 644 | mContext.registerReceiverAsUser(new BroadcastReceiver() { |
| 645 | @Override |
| 646 | public void onReceive(Context context, Intent intent) { |
| 647 | if (getSendingUserId() == UserHandle.USER_ALL) { |
| 648 | mEnabled = false; |
| 649 | handleDisable(); |
| 650 | } |
| 651 | } |
| 652 | }, UserHandle.ALL, intentFilter, null, mHandler); |
Mike Lockwood | d03ff94 | 2010-02-09 08:46:14 -0500 | [diff] [blame] | 653 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 654 | setProperties(PROPERTIES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 655 | } |
| 656 | |
Yu-Han Yang | a1862b5 | 2018-02-20 17:05:59 -0800 | [diff] [blame] | 657 | /** |
| 658 | * Implements {@link InjectNtpTimeCallback#injectTime} |
| 659 | */ |
| 660 | @Override |
| 661 | public void injectTime(long time, long timeReference, int uncertainty) { |
| 662 | native_inject_time(time, timeReference, uncertainty); |
| 663 | } |
| 664 | |
Anil Admal | 50ba15e | 2018-11-01 16:42:42 -0700 | [diff] [blame] | 665 | /** |
| 666 | * Implements {@link GnssNetworkConnectivityHandler.GnssNetworkListener#onNetworkAvailable()} |
| 667 | */ |
| 668 | private void onNetworkAvailable() { |
| 669 | mNtpTimeHelper.onNetworkAvailable(); |
| 670 | if (mDownloadXtraDataPending == STATE_PENDING_NETWORK) { |
| 671 | if (mSupportsXtra) { |
| 672 | // Download only if supported, (prevents an unneccesary on-boot |
| 673 | // download) |
| 674 | xtraDownloadRequest(); |
destradaa | ef752b6 | 2015-04-17 13:10:47 -0700 | [diff] [blame] | 675 | } |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 676 | } |
| 677 | } |
Yu-Han Yang | 8de2150 | 2018-04-23 01:40:25 -0700 | [diff] [blame] | 678 | |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 679 | private void handleRequestLocation(boolean independentFromGnss) { |
| 680 | if (isRequestLocationRateLimited()) { |
| 681 | if (DEBUG) { |
| 682 | Log.d(TAG, "RequestLocation is denied due to too frequent requests."); |
| 683 | } |
| 684 | return; |
| 685 | } |
Yu-Han Yang | 74041ff | 2018-04-06 15:57:31 -0700 | [diff] [blame] | 686 | ContentResolver resolver = mContext.getContentResolver(); |
| 687 | long durationMillis = Settings.Global.getLong( |
| 688 | resolver, |
| 689 | Settings.Global.GNSS_HAL_LOCATION_REQUEST_DURATION_MILLIS, |
| 690 | LOCATION_UPDATE_DURATION_MILLIS); |
| 691 | if (durationMillis == 0) { |
| 692 | Log.i(TAG, "GNSS HAL location request is disabled by Settings."); |
| 693 | return; |
| 694 | } |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 695 | |
| 696 | LocationManager locationManager = (LocationManager) mContext.getSystemService( |
| 697 | Context.LOCATION_SERVICE); |
Yu-Han Yang | 0756138 | 2018-02-21 13:08:37 -0800 | [diff] [blame] | 698 | String provider; |
| 699 | LocationChangeListener locationListener; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 700 | |
| 701 | if (independentFromGnss) { |
| 702 | // For fast GNSS TTFF |
Yu-Han Yang | 0756138 | 2018-02-21 13:08:37 -0800 | [diff] [blame] | 703 | provider = LocationManager.NETWORK_PROVIDER; |
| 704 | locationListener = mNetworkLocationListener; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 705 | } else { |
| 706 | // For Device-Based Hybrid (E911) |
Yu-Han Yang | 0756138 | 2018-02-21 13:08:37 -0800 | [diff] [blame] | 707 | provider = LocationManager.FUSED_PROVIDER; |
| 708 | locationListener = mFusedLocationListener; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 709 | } |
Yu-Han Yang | 0756138 | 2018-02-21 13:08:37 -0800 | [diff] [blame] | 710 | |
| 711 | Log.i(TAG, |
Yu-Han Yang | 74041ff | 2018-04-06 15:57:31 -0700 | [diff] [blame] | 712 | String.format( |
| 713 | "GNSS HAL Requesting location updates from %s provider for %d millis.", |
| 714 | provider, durationMillis)); |
Yu-Han Yang | e684dda | 2018-05-24 10:29:39 -0700 | [diff] [blame] | 715 | try { |
| 716 | locationManager.requestLocationUpdates(provider, |
| 717 | LOCATION_UPDATE_MIN_TIME_INTERVAL_MILLIS, /*minDistance=*/ 0, |
| 718 | locationListener, mHandler.getLooper()); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 719 | locationListener.mNumLocationUpdateRequest++; |
Yu-Han Yang | e684dda | 2018-05-24 10:29:39 -0700 | [diff] [blame] | 720 | mHandler.postDelayed(() -> { |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 721 | if (--locationListener.mNumLocationUpdateRequest == 0) { |
Yu-Han Yang | e684dda | 2018-05-24 10:29:39 -0700 | [diff] [blame] | 722 | Log.i(TAG, |
| 723 | String.format("Removing location updates from %s provider.", provider)); |
| 724 | locationManager.removeUpdates(locationListener); |
| 725 | } |
| 726 | }, durationMillis); |
| 727 | } catch (IllegalArgumentException e) { |
| 728 | Log.w(TAG, "Unable to request location.", e); |
| 729 | } |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | private void injectBestLocation(Location location) { |
| 733 | int gnssLocationFlags = LOCATION_HAS_LAT_LONG | |
| 734 | (location.hasAltitude() ? LOCATION_HAS_ALTITUDE : 0) | |
| 735 | (location.hasSpeed() ? LOCATION_HAS_SPEED : 0) | |
| 736 | (location.hasBearing() ? LOCATION_HAS_BEARING : 0) | |
| 737 | (location.hasAccuracy() ? LOCATION_HAS_HORIZONTAL_ACCURACY : 0) | |
| 738 | (location.hasVerticalAccuracy() ? LOCATION_HAS_VERTICAL_ACCURACY : 0) | |
| 739 | (location.hasSpeedAccuracy() ? LOCATION_HAS_SPEED_ACCURACY : 0) | |
| 740 | (location.hasBearingAccuracy() ? LOCATION_HAS_BEARING_ACCURACY : 0); |
| 741 | |
| 742 | double latitudeDegrees = location.getLatitude(); |
| 743 | double longitudeDegrees = location.getLongitude(); |
| 744 | double altitudeMeters = location.getAltitude(); |
| 745 | float speedMetersPerSec = location.getSpeed(); |
| 746 | float bearingDegrees = location.getBearing(); |
| 747 | float horizontalAccuracyMeters = location.getAccuracy(); |
| 748 | float verticalAccuracyMeters = location.getVerticalAccuracyMeters(); |
| 749 | float speedAccuracyMetersPerSecond = location.getSpeedAccuracyMetersPerSecond(); |
| 750 | float bearingAccuracyDegrees = location.getBearingAccuracyDegrees(); |
| 751 | long timestamp = location.getTime(); |
| 752 | native_inject_best_location(gnssLocationFlags, latitudeDegrees, longitudeDegrees, |
| 753 | altitudeMeters, speedMetersPerSec, bearingDegrees, horizontalAccuracyMeters, |
| 754 | verticalAccuracyMeters, speedAccuracyMetersPerSecond, bearingAccuracyDegrees, |
| 755 | timestamp); |
| 756 | } |
| 757 | |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 758 | /** Returns true if the location request is too frequent. */ |
| 759 | private boolean isRequestLocationRateLimited() { |
| 760 | // TODO(b/73198123): implement exponential backoff. |
| 761 | return false; |
| 762 | } |
| 763 | |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 764 | private void handleDownloadXtraData() { |
Wyatt Riley | 0d6e54e2 | 2016-10-05 12:03:03 -0700 | [diff] [blame] | 765 | if (!mSupportsXtra) { |
| 766 | // native code reports xtra not supported, don't try |
| 767 | Log.d(TAG, "handleDownloadXtraData() called when Xtra not supported"); |
| 768 | return; |
| 769 | } |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 770 | if (mDownloadXtraDataPending == STATE_DOWNLOADING) { |
| 771 | // already downloading data |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 772 | return; |
| 773 | } |
Anil Admal | 50ba15e | 2018-11-01 16:42:42 -0700 | [diff] [blame] | 774 | if (!mNetworkConnectivityHandler.isDataNetworkConnected()) { |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 775 | // try again when network is up |
| 776 | mDownloadXtraDataPending = STATE_PENDING_NETWORK; |
| 777 | return; |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 778 | } |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 779 | mDownloadXtraDataPending = STATE_DOWNLOADING; |
| 780 | |
Jeff Brown | 028872f | 2012-08-25 13:07:01 -0700 | [diff] [blame] | 781 | // hold wake lock while task runs |
Wei Wang | b71c049 | 2017-05-01 20:24:19 -0700 | [diff] [blame] | 782 | mDownloadXtraWakeLock.acquire(DOWNLOAD_XTRA_DATA_TIMEOUT_MS); |
Lifu Tang | cbd2a14 | 2016-06-22 10:57:55 -0700 | [diff] [blame] | 783 | Log.i(TAG, "WakeLock acquired by handleDownloadXtraData()"); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 784 | AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> { |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame^] | 785 | GpsXtraDownloader xtraDownloader = new GpsXtraDownloader( |
| 786 | mGnssConfiguration.getProperties()); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 787 | byte[] data = xtraDownloader.downloadXtraData(); |
| 788 | if (data != null) { |
| 789 | if (DEBUG) Log.d(TAG, "calling native_inject_xtra_data"); |
| 790 | native_inject_xtra_data(data, data.length); |
| 791 | mXtraBackOff.reset(); |
| 792 | } |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 793 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 794 | sendMessage(DOWNLOAD_XTRA_DATA_FINISHED, 0, null); |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 795 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 796 | if (data == null) { |
| 797 | // try again later |
| 798 | // since this is delayed and not urgent we do not hold a wake lock here |
| 799 | mHandler.sendEmptyMessageDelayed(DOWNLOAD_XTRA_DATA, |
| 800 | mXtraBackOff.nextBackoffMillis()); |
| 801 | } |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 802 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 803 | // Release wake lock held by task, synchronize on mLock in case multiple |
| 804 | // download tasks overrun. |
| 805 | synchronized (mLock) { |
| 806 | if (mDownloadXtraWakeLock.isHeld()) { |
| 807 | // This wakelock may have time-out, if a timeout was specified. |
| 808 | // Catch (and ignore) any timeout exceptions. |
| 809 | try { |
| 810 | mDownloadXtraWakeLock.release(); |
| 811 | if (DEBUG) Log.d(TAG, "WakeLock released by handleDownloadXtraData()"); |
| 812 | } catch (Exception e) { |
| 813 | Log.i(TAG, "Wakelock timeout & release race exception in " |
| 814 | + "handleDownloadXtraData()", e); |
Wei Wang | b71c049 | 2017-05-01 20:24:19 -0700 | [diff] [blame] | 815 | } |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 816 | } else { |
| 817 | Log.e(TAG, "WakeLock expired before release in " |
| 818 | + "handleDownloadXtraData()"); |
Wei Wang | c5706f6 | 2017-04-18 11:26:26 -0700 | [diff] [blame] | 819 | } |
Jeff Brown | 028872f | 2012-08-25 13:07:01 -0700 | [diff] [blame] | 820 | } |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 821 | }); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 822 | } |
| 823 | |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 824 | private void handleUpdateLocation(Location location) { |
Mike Lockwood | d26ce0d | 2009-06-11 12:25:46 -0400 | [diff] [blame] | 825 | if (location.hasAccuracy()) { |
| 826 | native_inject_location(location.getLatitude(), location.getLongitude(), |
| 827 | location.getAccuracy()); |
| 828 | } |
Mike Lockwood | fd6e5f0 | 2009-05-21 11:28:20 -0400 | [diff] [blame] | 829 | } |
| 830 | |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame^] | 831 | private void setSuplHostPort() { |
| 832 | mSuplServerHost = mGnssConfiguration.getSuplHost(); |
| 833 | mSuplServerPort = mGnssConfiguration.getSuplPort(TCP_MIN_PORT); |
Tsuwei Chen | 678c13c | 2014-09-22 17:48:41 -0700 | [diff] [blame] | 834 | if (mSuplServerHost != null |
| 835 | && mSuplServerPort > TCP_MIN_PORT |
| 836 | && mSuplServerPort <= TCP_MAX_PORT) { |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 837 | native_set_agps_server(GnssNetworkConnectivityHandler.AGPS_TYPE_SUPL, |
| 838 | mSuplServerHost, mSuplServerPort); |
Tsuwei Chen | 678c13c | 2014-09-22 17:48:41 -0700 | [diff] [blame] | 839 | } |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 840 | } |
| 841 | |
Tsuwei Chen | 462bcd8 | 2014-09-17 12:28:49 -0700 | [diff] [blame] | 842 | /** |
| 843 | * Checks what SUPL mode to use, according to the AGPS mode as well as the |
| 844 | * allowed mode from properties. |
| 845 | * |
Tsuwei Chen | 462bcd8 | 2014-09-17 12:28:49 -0700 | [diff] [blame] | 846 | * @param agpsEnabled whether AGPS is enabled by settings value |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 847 | * @param singleShot whether "singleshot" is needed |
Tsuwei Chen | 462bcd8 | 2014-09-17 12:28:49 -0700 | [diff] [blame] | 848 | * @return SUPL mode (MSA vs MSB vs STANDALONE) |
| 849 | */ |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame^] | 850 | private int getSuplMode(boolean agpsEnabled, boolean singleShot) { |
Tsuwei Chen | 462bcd8 | 2014-09-17 12:28:49 -0700 | [diff] [blame] | 851 | if (agpsEnabled) { |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame^] | 852 | int suplMode = mGnssConfiguration.getSuplMode(0); |
| 853 | if (suplMode == 0) { |
| 854 | return GPS_POSITION_MODE_STANDALONE; |
Tsuwei Chen | 462bcd8 | 2014-09-17 12:28:49 -0700 | [diff] [blame] | 855 | } |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame^] | 856 | |
destradaa | bfb3bdb | 2015-04-29 14:42:35 -0700 | [diff] [blame] | 857 | // MS-Based is the preferred mode for Assisted-GPS position computation, so we favor |
| 858 | // such mode when it is available |
| 859 | if (hasCapability(GPS_CAPABILITY_MSB) && (suplMode & AGPS_SUPL_MODE_MSB) != 0) { |
| 860 | return GPS_POSITION_MODE_MS_BASED; |
| 861 | } |
| 862 | // for now, just as the legacy code did, we fallback to MS-Assisted if it is available, |
| 863 | // do fallback only for single-shot requests, because it is too expensive to do for |
| 864 | // periodic requests as well |
Tsuwei Chen | 462bcd8 | 2014-09-17 12:28:49 -0700 | [diff] [blame] | 865 | if (singleShot |
| 866 | && hasCapability(GPS_CAPABILITY_MSA) |
| 867 | && (suplMode & AGPS_SUPL_MODE_MSA) != 0) { |
| 868 | return GPS_POSITION_MODE_MS_ASSISTED; |
Tsuwei Chen | 462bcd8 | 2014-09-17 12:28:49 -0700 | [diff] [blame] | 869 | } |
| 870 | } |
| 871 | return GPS_POSITION_MODE_STANDALONE; |
| 872 | } |
| 873 | |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 874 | private void handleEnable() { |
| 875 | if (DEBUG) Log.d(TAG, "handleEnable"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 876 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 877 | boolean enabled = native_init(); |
| 878 | |
| 879 | if (enabled) { |
Mike Lockwood | 1a1cd3a | 2010-08-17 07:42:54 -0400 | [diff] [blame] | 880 | mSupportsXtra = native_supports_xtra(); |
Tsuwei Chen | 678c13c | 2014-09-22 17:48:41 -0700 | [diff] [blame] | 881 | |
| 882 | // TODO: remove the following native calls if we can make sure they are redundant. |
Mike Lockwood | 734d603 | 2009-07-28 18:30:25 -0700 | [diff] [blame] | 883 | if (mSuplServerHost != null) { |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 884 | native_set_agps_server(GnssNetworkConnectivityHandler.AGPS_TYPE_SUPL, |
| 885 | mSuplServerHost, mSuplServerPort); |
Mike Lockwood | 734d603 | 2009-07-28 18:30:25 -0700 | [diff] [blame] | 886 | } |
| 887 | if (mC2KServerHost != null) { |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 888 | native_set_agps_server(GnssNetworkConnectivityHandler.AGPS_TYPE_C2K, |
| 889 | mC2KServerHost, mC2KServerPort); |
Mike Lockwood | 734d603 | 2009-07-28 18:30:25 -0700 | [diff] [blame] | 890 | } |
destradaa | 13a60b0 | 2015-01-15 18:36:01 -0800 | [diff] [blame] | 891 | |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 892 | mGnssMeasurementsProvider.onGpsEnabledChanged(); |
| 893 | mGnssNavigationMessageProvider.onGpsEnabledChanged(); |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 894 | mGnssBatchingProvider.enable(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 895 | } else { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 896 | synchronized (mLock) { |
| 897 | mEnabled = false; |
| 898 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 899 | Log.w(TAG, "Failed to enable location provider"); |
| 900 | } |
| 901 | } |
| 902 | |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 903 | private void handleDisable() { |
Mike Lockwood | 8909631 | 2010-03-24 10:14:55 -0400 | [diff] [blame] | 904 | if (DEBUG) Log.d(TAG, "handleDisable"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 905 | |
David Christie | 3bc2614 | 2013-12-19 14:53:44 -0800 | [diff] [blame] | 906 | updateClientUids(new WorkSource()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 907 | stopNavigating(); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 908 | mAlarmManager.cancel(mWakeupIntent); |
| 909 | mAlarmManager.cancel(mTimeoutIntent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 910 | |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 911 | mGnssBatchingProvider.disable(); |
Mike Lockwood | cf1d8cb | 2010-01-20 10:14:54 -0500 | [diff] [blame] | 912 | // do this before releasing wakelock |
| 913 | native_cleanup(); |
destradaa | 13a60b0 | 2015-01-15 18:36:01 -0800 | [diff] [blame] | 914 | |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 915 | mGnssMeasurementsProvider.onGpsEnabledChanged(); |
| 916 | mGnssNavigationMessageProvider.onGpsEnabledChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 917 | } |
| 918 | |
Mike Lockwood | d03ff94 | 2010-02-09 08:46:14 -0500 | [diff] [blame] | 919 | public boolean isEnabled() { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 920 | synchronized (mLock) { |
| 921 | return mEnabled; |
| 922 | } |
Mike Lockwood | d03ff94 | 2010-02-09 08:46:14 -0500 | [diff] [blame] | 923 | } |
| 924 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 925 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 926 | public int getStatus(Bundle extras) { |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 927 | mLocationExtras.setBundle(extras); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 928 | return mStatus; |
| 929 | } |
| 930 | |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 931 | private void updateStatus(int status) { |
| 932 | if (status != mStatus) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 933 | mStatus = status; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 934 | mStatusUpdateTime = SystemClock.elapsedRealtime(); |
| 935 | } |
| 936 | } |
| 937 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 938 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 939 | public long getStatusUpdateTime() { |
| 940 | return mStatusUpdateTime; |
| 941 | } |
| 942 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 943 | @Override |
| 944 | public void setRequest(ProviderRequest request, WorkSource source) { |
| 945 | sendMessage(SET_REQUEST, 0, new GpsRequest(request, source)); |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 946 | } |
| 947 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 948 | private void handleSetRequest(ProviderRequest request, WorkSource source) { |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 949 | mProviderRequest = request; |
| 950 | mWorkSource = source; |
| 951 | updateRequirements(); |
| 952 | } |
| 953 | |
| 954 | // Called when the requirements for GPS may have changed |
| 955 | private void updateRequirements() { |
| 956 | if (mProviderRequest == null || mWorkSource == null) { |
| 957 | return; |
| 958 | } |
| 959 | |
Stan Chesnutt | 1d72d8c | 2013-04-15 19:18:02 -0700 | [diff] [blame] | 960 | boolean singleShot = false; |
| 961 | |
| 962 | // see if the request is for a single update |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 963 | if (mProviderRequest.locationRequests != null |
| 964 | && mProviderRequest.locationRequests.size() > 0) { |
Stan Chesnutt | 1d72d8c | 2013-04-15 19:18:02 -0700 | [diff] [blame] | 965 | // if any request has zero or more than one updates |
| 966 | // requested, then this is not single-shot mode |
| 967 | singleShot = true; |
| 968 | |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 969 | for (LocationRequest lr : mProviderRequest.locationRequests) { |
Stan Chesnutt | 1d72d8c | 2013-04-15 19:18:02 -0700 | [diff] [blame] | 970 | if (lr.getNumUpdates() != 1) { |
| 971 | singleShot = false; |
| 972 | } |
| 973 | } |
| 974 | } |
| 975 | |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 976 | if (DEBUG) Log.d(TAG, "setRequest " + mProviderRequest); |
Dante Russo | 260d667 | 2016-06-20 11:11:59 -0700 | [diff] [blame] | 977 | if (mProviderRequest.reportLocation && !mDisableGps && isEnabled()) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 978 | // update client uids |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 979 | updateClientUids(mWorkSource); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 980 | |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 981 | mFixInterval = (int) mProviderRequest.interval; |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 982 | mLowPowerMode = mProviderRequest.lowPowerMode; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 983 | // check for overflow |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 984 | if (mFixInterval != mProviderRequest.interval) { |
| 985 | Log.w(TAG, "interval overflow: " + mProviderRequest.interval); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 986 | mFixInterval = Integer.MAX_VALUE; |
| 987 | } |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 988 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 989 | // apply request to GPS engine |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 990 | if (mStarted && hasCapability(GPS_CAPABILITY_SCHEDULING)) { |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 991 | // change period and/or lowPowerMode |
Yu-Han Yang | c8b9ff7 | 2018-04-17 00:47:24 -0700 | [diff] [blame] | 992 | if (!setPositionMode(mPositionMode, GPS_POSITION_RECURRENCE_PERIODIC, |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 993 | mFixInterval, 0, 0, mLowPowerMode)) { |
| 994 | Log.e(TAG, "set_position_mode failed in updateRequirements"); |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 995 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 996 | } else if (!mStarted) { |
| 997 | // start GPS |
Stan Chesnutt | 1d72d8c | 2013-04-15 19:18:02 -0700 | [diff] [blame] | 998 | startNavigating(singleShot); |
gomo | 300b240 | 2017-12-13 19:04:12 -0800 | [diff] [blame] | 999 | } else { |
| 1000 | // GNSS Engine is already ON, but no GPS_CAPABILITY_SCHEDULING |
| 1001 | mAlarmManager.cancel(mTimeoutIntent); |
| 1002 | if (mFixInterval >= NO_FIX_TIMEOUT) { |
| 1003 | // set timer to give up if we do not receive a fix within NO_FIX_TIMEOUT |
| 1004 | // and our fix interval is not short |
| 1005 | mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1006 | SystemClock.elapsedRealtime() + NO_FIX_TIMEOUT, mTimeoutIntent); |
| 1007 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1008 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1009 | } else { |
Dianne Hackborn | 002a54e | 2013-01-10 17:34:55 -0800 | [diff] [blame] | 1010 | updateClientUids(new WorkSource()); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1011 | |
| 1012 | stopNavigating(); |
| 1013 | mAlarmManager.cancel(mWakeupIntent); |
| 1014 | mAlarmManager.cancel(mTimeoutIntent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1015 | } |
| 1016 | } |
| 1017 | |
Yu-Han Yang | c8b9ff7 | 2018-04-17 00:47:24 -0700 | [diff] [blame] | 1018 | private boolean setPositionMode(int mode, int recurrence, int minInterval, |
| 1019 | int preferredAccuracy, int preferredTime, boolean lowPowerMode) { |
| 1020 | GnssPositionMode positionMode = new GnssPositionMode(mode, recurrence, minInterval, |
| 1021 | preferredAccuracy, preferredTime, lowPowerMode); |
| 1022 | if (mLastPositionMode != null && mLastPositionMode.equals(positionMode)) { |
| 1023 | return true; |
| 1024 | } |
| 1025 | |
| 1026 | boolean result = native_set_position_mode(mode, recurrence, minInterval, |
| 1027 | preferredAccuracy, preferredTime, lowPowerMode); |
| 1028 | if (result) { |
| 1029 | mLastPositionMode = positionMode; |
| 1030 | } else { |
| 1031 | mLastPositionMode = null; |
| 1032 | } |
| 1033 | return result; |
| 1034 | } |
| 1035 | |
Dianne Hackborn | 002a54e | 2013-01-10 17:34:55 -0800 | [diff] [blame] | 1036 | private void updateClientUids(WorkSource source) { |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 1037 | if (source.equals(mClientSource)) { |
Victoria Lease | ea78b85 | 2013-01-15 10:39:28 -0800 | [diff] [blame] | 1038 | return; |
| 1039 | } |
Dianne Hackborn | 002a54e | 2013-01-10 17:34:55 -0800 | [diff] [blame] | 1040 | |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 1041 | // (1) Inform BatteryStats that the list of IDs we're tracking changed. |
| 1042 | try { |
| 1043 | mBatteryStats.noteGpsChanged(mClientSource, source); |
| 1044 | } catch (RemoteException e) { |
| 1045 | Log.w(TAG, "RemoteException", e); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 1048 | // (2) Inform AppOps service about the list of changes to UIDs. |
| 1049 | |
| 1050 | List<WorkChain>[] diffs = WorkSource.diffChains(mClientSource, source); |
| 1051 | if (diffs != null) { |
| 1052 | List<WorkChain> newChains = diffs[0]; |
| 1053 | List<WorkChain> goneChains = diffs[1]; |
| 1054 | |
| 1055 | if (newChains != null) { |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1056 | for (WorkChain newChain : newChains) { |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 1057 | mAppOps.startOpNoThrow(AppOpsManager.OP_GPS, newChain.getAttributionUid(), |
| 1058 | newChain.getAttributionTag()); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 1059 | } |
| 1060 | } |
| 1061 | |
| 1062 | if (goneChains != null) { |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1063 | for (WorkChain goneChain : goneChains) { |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 1064 | mAppOps.finishOp(AppOpsManager.OP_GPS, goneChain.getAttributionUid(), |
| 1065 | goneChain.getAttributionTag()); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 1066 | } |
| 1067 | } |
| 1068 | |
| 1069 | mClientSource.transferWorkChains(source); |
| 1070 | } |
| 1071 | |
| 1072 | // Update the flat UIDs and names list and inform app-ops of all changes. |
| 1073 | WorkSource[] changes = mClientSource.setReturningDiffs(source); |
| 1074 | if (changes != null) { |
| 1075 | WorkSource newWork = changes[0]; |
| 1076 | WorkSource goneWork = changes[1]; |
| 1077 | |
| 1078 | // Update sources that were not previously tracked. |
| 1079 | if (newWork != null) { |
| 1080 | for (int i = 0; i < newWork.size(); i++) { |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 1081 | mAppOps.startOpNoThrow(AppOpsManager.OP_GPS, |
| 1082 | newWork.get(i), newWork.getName(i)); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 1083 | } |
| 1084 | } |
| 1085 | |
| 1086 | // Update sources that are no longer tracked. |
| 1087 | if (goneWork != null) { |
| 1088 | for (int i = 0; i < goneWork.size(); i++) { |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 1089 | mAppOps.finishOp(AppOpsManager.OP_GPS, goneWork.get(i), goneWork.getName(i)); |
Dianne Hackborn | 2e41842 | 2009-06-22 20:00:17 -0700 | [diff] [blame] | 1090 | } |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 1091 | } |
| 1092 | } |
| 1093 | } |
| 1094 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1095 | @Override |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1096 | public void sendExtraCommand(String command, Bundle extras) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1097 | |
Mike Lockwood | 63aa5a6 | 2010-04-14 19:21:31 -0400 | [diff] [blame] | 1098 | long identity = Binder.clearCallingIdentity(); |
Peter Visontay | b25db36 | 2017-11-01 18:18:12 +0000 | [diff] [blame] | 1099 | try { |
Peter Visontay | b25db36 | 2017-11-01 18:18:12 +0000 | [diff] [blame] | 1100 | if ("delete_aiding_data".equals(command)) { |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1101 | deleteAidingData(extras); |
Peter Visontay | b25db36 | 2017-11-01 18:18:12 +0000 | [diff] [blame] | 1102 | } else if ("force_time_injection".equals(command)) { |
| 1103 | requestUtcTime(); |
Peter Visontay | b25db36 | 2017-11-01 18:18:12 +0000 | [diff] [blame] | 1104 | } else if ("force_xtra_injection".equals(command)) { |
| 1105 | if (mSupportsXtra) { |
| 1106 | xtraDownloadRequest(); |
Peter Visontay | b25db36 | 2017-11-01 18:18:12 +0000 | [diff] [blame] | 1107 | } |
| 1108 | } else { |
| 1109 | Log.w(TAG, "sendExtraCommand: unknown command " + command); |
Mike Lockwood | 93bc44d | 2009-05-20 16:58:22 -0400 | [diff] [blame] | 1110 | } |
Peter Visontay | b25db36 | 2017-11-01 18:18:12 +0000 | [diff] [blame] | 1111 | } finally { |
| 1112 | Binder.restoreCallingIdentity(identity); |
Mike Lockwood | 93bc44d | 2009-05-20 16:58:22 -0400 | [diff] [blame] | 1113 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1114 | } |
| 1115 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1116 | private void deleteAidingData(Bundle extras) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1117 | int flags; |
| 1118 | |
| 1119 | if (extras == null) { |
| 1120 | flags = GPS_DELETE_ALL; |
| 1121 | } else { |
| 1122 | flags = 0; |
| 1123 | if (extras.getBoolean("ephemeris")) flags |= GPS_DELETE_EPHEMERIS; |
| 1124 | if (extras.getBoolean("almanac")) flags |= GPS_DELETE_ALMANAC; |
| 1125 | if (extras.getBoolean("position")) flags |= GPS_DELETE_POSITION; |
| 1126 | if (extras.getBoolean("time")) flags |= GPS_DELETE_TIME; |
| 1127 | if (extras.getBoolean("iono")) flags |= GPS_DELETE_IONO; |
| 1128 | if (extras.getBoolean("utc")) flags |= GPS_DELETE_UTC; |
| 1129 | if (extras.getBoolean("health")) flags |= GPS_DELETE_HEALTH; |
| 1130 | if (extras.getBoolean("svdir")) flags |= GPS_DELETE_SVDIR; |
| 1131 | if (extras.getBoolean("svsteer")) flags |= GPS_DELETE_SVSTEER; |
| 1132 | if (extras.getBoolean("sadata")) flags |= GPS_DELETE_SADATA; |
| 1133 | if (extras.getBoolean("rti")) flags |= GPS_DELETE_RTI; |
| 1134 | if (extras.getBoolean("celldb-info")) flags |= GPS_DELETE_CELLDB_INFO; |
| 1135 | if (extras.getBoolean("all")) flags |= GPS_DELETE_ALL; |
| 1136 | } |
| 1137 | |
| 1138 | if (flags != 0) { |
| 1139 | native_delete_aiding_data(flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1140 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1141 | } |
| 1142 | |
Stan Chesnutt | 1d72d8c | 2013-04-15 19:18:02 -0700 | [diff] [blame] | 1143 | private void startNavigating(boolean singleShot) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1144 | if (!mStarted) { |
Stan Chesnutt | 1d72d8c | 2013-04-15 19:18:02 -0700 | [diff] [blame] | 1145 | if (DEBUG) Log.d(TAG, "startNavigating, singleShot is " + singleShot); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1146 | mTimeToFirstFix = 0; |
| 1147 | mLastFixTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1148 | mStarted = true; |
Stan Chesnutt | 1d72d8c | 2013-04-15 19:18:02 -0700 | [diff] [blame] | 1149 | mSingleShot = singleShot; |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 1150 | mPositionMode = GPS_POSITION_MODE_STANDALONE; |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1151 | // Notify about suppressed output, if speed limit was previously exceeded. |
| 1152 | // Elsewhere, we check again with every speed output reported. |
| 1153 | if (mItarSpeedLimitExceeded) { |
| 1154 | Log.i(TAG, "startNavigating with ITAR limit in place. Output limited " + |
| 1155 | "until slow enough speed reported."); |
| 1156 | } |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 1157 | |
Tsuwei Chen | 462bcd8 | 2014-09-17 12:28:49 -0700 | [diff] [blame] | 1158 | boolean agpsEnabled = |
| 1159 | (Settings.Global.getInt(mContext.getContentResolver(), |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1160 | Settings.Global.ASSISTED_GPS_ENABLED, 1) != 0); |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame^] | 1161 | mPositionMode = getSuplMode(agpsEnabled, singleShot); |
Mike Lockwood | bcab8df | 2009-06-25 16:39:09 -0400 | [diff] [blame] | 1162 | |
Stan Chesnutt | 1d72d8c | 2013-04-15 19:18:02 -0700 | [diff] [blame] | 1163 | if (DEBUG) { |
| 1164 | String mode; |
| 1165 | |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1166 | switch (mPositionMode) { |
Stan Chesnutt | 1d72d8c | 2013-04-15 19:18:02 -0700 | [diff] [blame] | 1167 | case GPS_POSITION_MODE_STANDALONE: |
| 1168 | mode = "standalone"; |
| 1169 | break; |
| 1170 | case GPS_POSITION_MODE_MS_ASSISTED: |
| 1171 | mode = "MS_ASSISTED"; |
| 1172 | break; |
| 1173 | case GPS_POSITION_MODE_MS_BASED: |
| 1174 | mode = "MS_BASED"; |
| 1175 | break; |
| 1176 | default: |
| 1177 | mode = "unknown"; |
| 1178 | break; |
| 1179 | } |
| 1180 | Log.d(TAG, "setting position_mode to " + mode); |
| 1181 | } |
| 1182 | |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 1183 | int interval = (hasCapability(GPS_CAPABILITY_SCHEDULING) ? mFixInterval : 1000); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1184 | mLowPowerMode = mProviderRequest.lowPowerMode; |
Yu-Han Yang | c8b9ff7 | 2018-04-17 00:47:24 -0700 | [diff] [blame] | 1185 | if (!setPositionMode(mPositionMode, GPS_POSITION_RECURRENCE_PERIODIC, |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1186 | interval, 0, 0, mLowPowerMode)) { |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 1187 | mStarted = false; |
| 1188 | Log.e(TAG, "set_position_mode failed in startNavigating()"); |
| 1189 | return; |
| 1190 | } |
| 1191 | if (!native_start()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1192 | mStarted = false; |
| 1193 | Log.e(TAG, "native_start failed in startNavigating()"); |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 1194 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | // reset SV count to zero |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 1198 | updateStatus(LocationProvider.TEMPORARILY_UNAVAILABLE); |
| 1199 | mLocationExtras.reset(); |
Yipeng Cao | 282b594 | 2017-05-17 20:31:39 -0700 | [diff] [blame] | 1200 | mFixRequestTime = SystemClock.elapsedRealtime(); |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 1201 | if (!hasCapability(GPS_CAPABILITY_SCHEDULING)) { |
| 1202 | // set timer to give up if we do not receive a fix within NO_FIX_TIMEOUT |
| 1203 | // and our fix interval is not short |
| 1204 | if (mFixInterval >= NO_FIX_TIMEOUT) { |
| 1205 | mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, |
| 1206 | SystemClock.elapsedRealtime() + NO_FIX_TIMEOUT, mTimeoutIntent); |
| 1207 | } |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 1208 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1209 | } |
| 1210 | } |
| 1211 | |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 1212 | private void stopNavigating() { |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 1213 | if (DEBUG) Log.d(TAG, "stopNavigating"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1214 | if (mStarted) { |
| 1215 | mStarted = false; |
Stan Chesnutt | 1d72d8c | 2013-04-15 19:18:02 -0700 | [diff] [blame] | 1216 | mSingleShot = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1217 | native_stop(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1218 | mLastFixTime = 0; |
Yu-Han Yang | a50cd60 | 2018-08-28 12:33:24 -0700 | [diff] [blame] | 1219 | // native_stop() may reset the position mode in hardware. |
| 1220 | mLastPositionMode = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1221 | |
| 1222 | // reset SV count to zero |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 1223 | updateStatus(LocationProvider.TEMPORARILY_UNAVAILABLE); |
| 1224 | mLocationExtras.reset(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1225 | } |
| 1226 | } |
| 1227 | |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 1228 | private void hibernate() { |
| 1229 | // stop GPS until our next fix interval arrives |
| 1230 | stopNavigating(); |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 1231 | mAlarmManager.cancel(mTimeoutIntent); |
| 1232 | mAlarmManager.cancel(mWakeupIntent); |
| 1233 | long now = SystemClock.elapsedRealtime(); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1234 | mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, now + mFixInterval, mWakeupIntent); |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | private boolean hasCapability(int capability) { |
| 1238 | return ((mEngineCapabilities & capability) != 0); |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 1239 | } |
| 1240 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1241 | @NativeEntryPoint |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 1242 | private void reportLocation(boolean hasLatLong, Location location) { |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1243 | sendMessage(REPORT_LOCATION, hasLatLong ? 1 : 0, location); |
| 1244 | } |
| 1245 | |
| 1246 | private void handleReportLocation(boolean hasLatLong, Location location) { |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 1247 | if (location.hasSpeed()) { |
| 1248 | mItarSpeedLimitExceeded = location.getSpeed() > ITAR_SPEED_LIMIT_METERS_PER_SECOND; |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | if (mItarSpeedLimitExceeded) { |
| 1252 | Log.i(TAG, "Hal reported a speed in excess of ITAR limit." + |
| 1253 | " GPS/GNSS Navigation output blocked."); |
Siddharth Ray | 53ddc80 | 2018-03-16 12:01:52 -0700 | [diff] [blame] | 1254 | if (mStarted) { |
| 1255 | mGnssMetrics.logReceivedLocationStatus(false); |
| 1256 | } |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1257 | return; // No output of location allowed |
| 1258 | } |
| 1259 | |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 1260 | if (VERBOSE) Log.v(TAG, "reportLocation " + location.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1261 | |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1262 | // It would be nice to push the elapsed real-time timestamp |
| 1263 | // further down the stack, but this is still useful |
| 1264 | location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos()); |
| 1265 | location.setExtras(mLocationExtras.getBundle()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1266 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1267 | reportLocation(location); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1268 | |
Siddharth Ray | 53ddc80 | 2018-03-16 12:01:52 -0700 | [diff] [blame] | 1269 | if (mStarted) { |
| 1270 | mGnssMetrics.logReceivedLocationStatus(hasLatLong); |
| 1271 | if (hasLatLong) { |
| 1272 | if (location.hasAccuracy()) { |
| 1273 | mGnssMetrics.logPositionAccuracyMeters(location.getAccuracy()); |
| 1274 | } |
| 1275 | if (mTimeToFirstFix > 0) { |
| 1276 | int timeBetweenFixes = (int) (SystemClock.elapsedRealtime() - mLastFixTime); |
| 1277 | mGnssMetrics.logMissedReports(mFixInterval, timeBetweenFixes); |
| 1278 | } |
Siddharth Ray | bb608c8 | 2017-03-16 11:33:34 -0700 | [diff] [blame] | 1279 | } |
| 1280 | } |
| 1281 | |
Yipeng Cao | 282b594 | 2017-05-17 20:31:39 -0700 | [diff] [blame] | 1282 | mLastFixTime = SystemClock.elapsedRealtime(); |
Hakan Gustavsson | fa94ff0 | 2010-02-23 09:12:38 +0100 | [diff] [blame] | 1283 | // report time to first fix |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 1284 | if (mTimeToFirstFix == 0 && hasLatLong) { |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1285 | mTimeToFirstFix = (int) (mLastFixTime - mFixRequestTime); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1286 | if (DEBUG) Log.d(TAG, "TTFF: " + mTimeToFirstFix); |
Siddharth Ray | 53ddc80 | 2018-03-16 12:01:52 -0700 | [diff] [blame] | 1287 | if (mStarted) { |
| 1288 | mGnssMetrics.logTimeToFirstFixMilliSecs(mTimeToFirstFix); |
| 1289 | } |
Hakan Gustavsson | fa94ff0 | 2010-02-23 09:12:38 +0100 | [diff] [blame] | 1290 | |
| 1291 | // notify status listeners |
Anil Admal | 75b9fd6 | 2018-11-28 11:22:50 -0800 | [diff] [blame] | 1292 | mGnssStatusListenerHelper.onFirstFix(mTimeToFirstFix); |
Hakan Gustavsson | fa94ff0 | 2010-02-23 09:12:38 +0100 | [diff] [blame] | 1293 | } |
| 1294 | |
Stan Chesnutt | 1d72d8c | 2013-04-15 19:18:02 -0700 | [diff] [blame] | 1295 | if (mSingleShot) { |
| 1296 | stopNavigating(); |
| 1297 | } |
| 1298 | |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 1299 | if (mStarted && mStatus != LocationProvider.AVAILABLE) { |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 1300 | // For devices that use framework scheduling, a timer may be set to ensure we don't |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1301 | // spend too much power searching for a location, when the requested update rate is |
| 1302 | // slow. |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 1303 | // As we just recievied a location, we'll cancel that timer. |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 1304 | if (!hasCapability(GPS_CAPABILITY_SCHEDULING) && mFixInterval < NO_FIX_TIMEOUT) { |
Mike Lockwood | b7be544 | 2010-02-24 14:34:50 -0500 | [diff] [blame] | 1305 | mAlarmManager.cancel(mTimeoutIntent); |
| 1306 | } |
| 1307 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1308 | // send an intent to notify that the GPS is receiving fixes. |
Mike Lockwood | 00b7427 | 2010-03-26 10:41:48 -0400 | [diff] [blame] | 1309 | Intent intent = new Intent(LocationManager.GPS_FIX_CHANGE_ACTION); |
| 1310 | intent.putExtra(LocationManager.EXTRA_GPS_ENABLED, true); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 1311 | mContext.sendBroadcastAsUser(intent, UserHandle.ALL); |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 1312 | updateStatus(LocationProvider.AVAILABLE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1313 | } |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 1314 | |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1315 | if (!hasCapability(GPS_CAPABILITY_SCHEDULING) && mStarted && |
| 1316 | mFixInterval > GPS_POLLING_THRESHOLD_INTERVAL) { |
Mike Lockwood | d53ba01 | 2010-04-15 20:41:26 -0400 | [diff] [blame] | 1317 | if (DEBUG) Log.d(TAG, "got fix, hibernating"); |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 1318 | hibernate(); |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 1319 | } |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1320 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1321 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1322 | @NativeEntryPoint |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1323 | private void reportStatus(int status) { |
Mike Lockwood | b8d9033 | 2010-10-18 17:59:48 -0400 | [diff] [blame] | 1324 | if (DEBUG) Log.v(TAG, "reportStatus status: " + status); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1325 | |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1326 | boolean wasNavigating = mNavigating; |
| 1327 | switch (status) { |
| 1328 | case GPS_STATUS_SESSION_BEGIN: |
| 1329 | mNavigating = true; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1330 | break; |
| 1331 | case GPS_STATUS_SESSION_END: |
| 1332 | mNavigating = false; |
| 1333 | break; |
| 1334 | case GPS_STATUS_ENGINE_ON: |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1335 | break; |
| 1336 | case GPS_STATUS_ENGINE_OFF: |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1337 | mNavigating = false; |
| 1338 | break; |
| 1339 | } |
Mike Lockwood | dbd6fd8 | 2009-12-07 18:43:36 -0500 | [diff] [blame] | 1340 | |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1341 | if (wasNavigating != mNavigating) { |
Anil Admal | 75b9fd6 | 2018-11-28 11:22:50 -0800 | [diff] [blame] | 1342 | mGnssStatusListenerHelper.onStatusChanged(mNavigating); |
Mike Lockwood | cf1d8cb | 2010-01-20 10:14:54 -0500 | [diff] [blame] | 1343 | |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1344 | // send an intent to notify that the GPS has been enabled or disabled |
| 1345 | Intent intent = new Intent(LocationManager.GPS_ENABLED_CHANGE_ACTION); |
| 1346 | intent.putExtra(LocationManager.EXTRA_GPS_ENABLED, mNavigating); |
| 1347 | mContext.sendBroadcastAsUser(intent, UserHandle.ALL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1348 | } |
| 1349 | } |
| 1350 | |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1351 | // Helper class to carry data to handler for reportSvStatus |
| 1352 | private static class SvStatusInfo { |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1353 | private int mSvCount; |
| 1354 | private int[] mSvidWithFlags; |
| 1355 | private float[] mCn0s; |
| 1356 | private float[] mSvElevations; |
| 1357 | private float[] mSvAzimuths; |
| 1358 | private float[] mSvCarrierFreqs; |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1359 | } |
| 1360 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1361 | @NativeEntryPoint |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1362 | private void reportSvStatus(int svCount, int[] svidWithFlags, float[] cn0s, |
| 1363 | float[] svElevations, float[] svAzimuths, float[] svCarrierFreqs) { |
| 1364 | SvStatusInfo svStatusInfo = new SvStatusInfo(); |
| 1365 | svStatusInfo.mSvCount = svCount; |
| 1366 | svStatusInfo.mSvidWithFlags = svidWithFlags; |
| 1367 | svStatusInfo.mCn0s = cn0s; |
| 1368 | svStatusInfo.mSvElevations = svElevations; |
| 1369 | svStatusInfo.mSvAzimuths = svAzimuths; |
| 1370 | svStatusInfo.mSvCarrierFreqs = svCarrierFreqs; |
| 1371 | |
| 1372 | sendMessage(REPORT_SV_STATUS, 0, svStatusInfo); |
| 1373 | } |
| 1374 | |
| 1375 | private void handleReportSvStatus(SvStatusInfo info) { |
Anil Admal | 75b9fd6 | 2018-11-28 11:22:50 -0800 | [diff] [blame] | 1376 | mGnssStatusListenerHelper.onSvStatusChanged( |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1377 | info.mSvCount, |
| 1378 | info.mSvidWithFlags, |
| 1379 | info.mCn0s, |
| 1380 | info.mSvElevations, |
| 1381 | info.mSvAzimuths, |
| 1382 | info.mSvCarrierFreqs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1383 | |
Siddharth Ray | 168f12a | 2017-07-10 11:55:10 -0700 | [diff] [blame] | 1384 | // Log CN0 as part of GNSS metrics |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1385 | mGnssMetrics.logCn0(info.mCn0s, info.mSvCount); |
Siddharth Ray | 168f12a | 2017-07-10 11:55:10 -0700 | [diff] [blame] | 1386 | |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 1387 | if (VERBOSE) { |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1388 | Log.v(TAG, "SV count: " + info.mSvCount); |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1389 | } |
Wyatt Riley | c9f25dd | 2017-05-05 13:45:23 -0700 | [diff] [blame] | 1390 | // Calculate number of satellites used in fix. |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1391 | int usedInFixCount = 0; |
Wyatt Riley | c9f25dd | 2017-05-05 13:45:23 -0700 | [diff] [blame] | 1392 | int maxCn0 = 0; |
| 1393 | int meanCn0 = 0; |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1394 | for (int i = 0; i < info.mSvCount; i++) { |
| 1395 | if ((info.mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_USED_IN_FIX) != 0) { |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1396 | ++usedInFixCount; |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1397 | if (info.mCn0s[i] > maxCn0) { |
| 1398 | maxCn0 = (int) info.mCn0s[i]; |
Wyatt Riley | c9f25dd | 2017-05-05 13:45:23 -0700 | [diff] [blame] | 1399 | } |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1400 | meanCn0 += info.mCn0s[i]; |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1401 | } |
| 1402 | if (VERBOSE) { |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1403 | Log.v(TAG, "svid: " + (info.mSvidWithFlags[i] >> GnssStatus.SVID_SHIFT_WIDTH) + |
| 1404 | " cn0: " + info.mCn0s[i] + |
| 1405 | " elev: " + info.mSvElevations[i] + |
| 1406 | " azimuth: " + info.mSvAzimuths[i] + |
| 1407 | " carrier frequency: " + info.mSvCarrierFreqs[i] + |
| 1408 | ((info.mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_HAS_EPHEMERIS_DATA) == 0 |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1409 | ? " " : " E") + |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1410 | ((info.mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_HAS_ALMANAC_DATA) == 0 |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1411 | ? " " : " A") + |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1412 | ((info.mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_USED_IN_FIX) == 0 |
gomo | 4402af6 | 2017-01-11 13:20:13 -0800 | [diff] [blame] | 1413 | ? "" : "U") + |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1414 | ((info.mSvidWithFlags[i] & |
| 1415 | GnssStatus.GNSS_SV_FLAGS_HAS_CARRIER_FREQUENCY) == 0 |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1416 | ? "" : "F")); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1417 | } |
| 1418 | } |
Wyatt Riley | c9f25dd | 2017-05-05 13:45:23 -0700 | [diff] [blame] | 1419 | if (usedInFixCount > 0) { |
| 1420 | meanCn0 /= usedInFixCount; |
| 1421 | } |
| 1422 | // return number of sats used in fix instead of total reported |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 1423 | mLocationExtras.set(usedInFixCount, meanCn0, maxCn0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1424 | |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 1425 | if (mNavigating && mStatus == LocationProvider.AVAILABLE && mLastFixTime > 0 && |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1426 | SystemClock.elapsedRealtime() - mLastFixTime > RECENT_FIX_TIMEOUT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1427 | // send an intent to notify that the GPS is no longer receiving fixes. |
Mike Lockwood | 00b7427 | 2010-03-26 10:41:48 -0400 | [diff] [blame] | 1428 | Intent intent = new Intent(LocationManager.GPS_FIX_CHANGE_ACTION); |
| 1429 | intent.putExtra(LocationManager.EXTRA_GPS_ENABLED, false); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 1430 | mContext.sendBroadcastAsUser(intent, UserHandle.ALL); |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 1431 | updateStatus(LocationProvider.TEMPORARILY_UNAVAILABLE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1432 | } |
| 1433 | } |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 1434 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1435 | @NativeEntryPoint |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 1436 | private void reportAGpsStatus(int agpsType, int agpsStatus, byte[] suplIpAddr) { |
| 1437 | mNetworkConnectivityHandler.onReportAGpsStatus(agpsType, agpsStatus, suplIpAddr); |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 1438 | } |
| 1439 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1440 | @NativeEntryPoint |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 1441 | private void reportNmea(long timestamp) { |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1442 | if (!mItarSpeedLimitExceeded) { |
| 1443 | int length = native_read_nmea(mNmeaBuffer, mNmeaBuffer.length); |
| 1444 | String nmea = new String(mNmeaBuffer, 0 /* offset */, length); |
Anil Admal | 75b9fd6 | 2018-11-28 11:22:50 -0800 | [diff] [blame] | 1445 | mGnssStatusListenerHelper.onNmeaReceived(timestamp, nmea); |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1446 | } |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1447 | } |
Mike Lockwood | b16e780 | 2009-08-06 09:26:02 -0400 | [diff] [blame] | 1448 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1449 | @NativeEntryPoint |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 1450 | private void reportMeasurementData(GnssMeasurementsEvent event) { |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1451 | if (!mItarSpeedLimitExceeded) { |
Wyatt Riley | aa420d5 | 2017-07-03 15:14:42 -0700 | [diff] [blame] | 1452 | // send to handler to allow native to return quickly |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1453 | mHandler.post(() -> mGnssMeasurementsProvider.onMeasurementsAvailable(event)); |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1454 | } |
Mike Lockwood | b16e780 | 2009-08-06 09:26:02 -0400 | [diff] [blame] | 1455 | } |
| 1456 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1457 | @NativeEntryPoint |
Lifu Tang | e8abe8e | 2016-04-01 10:32:05 -0700 | [diff] [blame] | 1458 | private void reportNavigationMessage(GnssNavigationMessage event) { |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1459 | if (!mItarSpeedLimitExceeded) { |
Wyatt Riley | aa420d5 | 2017-07-03 15:14:42 -0700 | [diff] [blame] | 1460 | // send to handler to allow native to return quickly |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1461 | mHandler.post(() -> mGnssNavigationMessageProvider.onNavigationMessageAvailable(event)); |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1462 | } |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1463 | } |
| 1464 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1465 | @NativeEntryPoint |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1466 | private void setEngineCapabilities(final int capabilities) { |
| 1467 | // send to handler thread for fast native return, and in-order handling |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 1468 | mHandler.post( |
| 1469 | () -> { |
| 1470 | mEngineCapabilities = capabilities; |
Mike Lockwood | 9b9fb5c | 2011-06-29 15:09:40 -0400 | [diff] [blame] | 1471 | |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 1472 | if (hasCapability(GPS_CAPABILITY_ON_DEMAND_TIME)) { |
| 1473 | mNtpTimeHelper.enablePeriodicTimeInjection(); |
| 1474 | requestUtcTime(); |
| 1475 | } |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1476 | |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 1477 | mGnssMeasurementsProvider.onCapabilitiesUpdated(capabilities); |
| 1478 | mGnssNavigationMessageProvider.onCapabilitiesUpdated( |
| 1479 | hasCapability(GPS_CAPABILITY_NAV_MESSAGES)); |
| 1480 | restartRequests(); |
| 1481 | }); |
Yu-Han Yang | 5205762 | 2018-04-25 00:51:22 -0700 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | private void restartRequests() { |
| 1485 | Log.i(TAG, "restartRequests"); |
| 1486 | |
| 1487 | restartLocationRequest(); |
| 1488 | mGnssMeasurementsProvider.resumeIfStarted(); |
| 1489 | mGnssNavigationMessageProvider.resumeIfStarted(); |
| 1490 | mGnssBatchingProvider.resumeIfStarted(); |
| 1491 | mGnssGeofenceProvider.resumeIfStarted(); |
| 1492 | } |
| 1493 | |
| 1494 | private void restartLocationRequest() { |
| 1495 | if (DEBUG) Log.d(TAG, "restartLocationRequest"); |
| 1496 | mStarted = false; |
| 1497 | updateRequirements(); |
| 1498 | } |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1499 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1500 | @NativeEntryPoint |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1501 | private void setGnssYearOfHardware(final int yearOfHardware) { |
| 1502 | // mHardwareYear is simply set here, to be read elsewhere, and is volatile for safe sync |
| 1503 | if (DEBUG) Log.d(TAG, "setGnssYearOfHardware called with " + yearOfHardware); |
| 1504 | mHardwareYear = yearOfHardware; |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 1505 | } |
| 1506 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1507 | @NativeEntryPoint |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1508 | private void setGnssHardwareModelName(final String modelName) { |
| 1509 | // mHardwareModelName is simply set here, to be read elsewhere, and volatile for safe sync |
| 1510 | if (DEBUG) Log.d(TAG, "setGnssModelName called with " + modelName); |
| 1511 | mHardwareModelName = modelName; |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 1512 | } |
| 1513 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1514 | @NativeEntryPoint |
Yu-Han Yang | 5205762 | 2018-04-25 00:51:22 -0700 | [diff] [blame] | 1515 | private void reportGnssServiceDied() { |
| 1516 | if (DEBUG) Log.d(TAG, "reportGnssServiceDied"); |
| 1517 | mHandler.post(() -> { |
| 1518 | class_init_native(); |
| 1519 | native_init_once(); |
| 1520 | if (isEnabled()) { |
| 1521 | // re-calls native_init() and other setup. |
| 1522 | handleEnable(); |
| 1523 | // resend configuration into the restarted HAL service. |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame^] | 1524 | reloadGpsProperties(); |
Yu-Han Yang | 5205762 | 2018-04-25 00:51:22 -0700 | [diff] [blame] | 1525 | } |
| 1526 | }); |
| 1527 | } |
| 1528 | |
Lifu Tang | 9363b94 | 2016-02-16 18:07:00 -0800 | [diff] [blame] | 1529 | public interface GnssSystemInfoProvider { |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 1530 | /** |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1531 | * Returns the year of underlying GPS hardware. |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 1532 | */ |
Lifu Tang | 9363b94 | 2016-02-16 18:07:00 -0800 | [diff] [blame] | 1533 | int getGnssYearOfHardware(); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1534 | |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1535 | /** |
| 1536 | * Returns the model name of underlying GPS hardware. |
| 1537 | */ |
| 1538 | String getGnssHardwareModelName(); |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 1539 | } |
| 1540 | |
| 1541 | /** |
| 1542 | * @hide |
| 1543 | */ |
Lifu Tang | 9363b94 | 2016-02-16 18:07:00 -0800 | [diff] [blame] | 1544 | public GnssSystemInfoProvider getGnssSystemInfoProvider() { |
| 1545 | return new GnssSystemInfoProvider() { |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 1546 | @Override |
Lifu Tang | 9363b94 | 2016-02-16 18:07:00 -0800 | [diff] [blame] | 1547 | public int getGnssYearOfHardware() { |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1548 | return mHardwareYear; |
| 1549 | } |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1550 | |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1551 | @Override |
| 1552 | public String getGnssHardwareModelName() { |
| 1553 | return mHardwareModelName; |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 1554 | } |
| 1555 | }; |
| 1556 | } |
| 1557 | |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1558 | /** |
| 1559 | * @hide |
| 1560 | */ |
| 1561 | public GnssBatchingProvider getGnssBatchingProvider() { |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 1562 | return mGnssBatchingProvider; |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1563 | } |
| 1564 | |
Siddharth Ray | bb608c8 | 2017-03-16 11:33:34 -0700 | [diff] [blame] | 1565 | public interface GnssMetricsProvider { |
| 1566 | /** |
| 1567 | * Returns GNSS metrics as proto string |
| 1568 | */ |
| 1569 | String getGnssMetricsAsProtoString(); |
| 1570 | } |
| 1571 | |
| 1572 | /** |
| 1573 | * @hide |
| 1574 | */ |
| 1575 | public GnssMetricsProvider getGnssMetricsProvider() { |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1576 | return () -> mGnssMetrics.dumpGnssMetricsAsProtoString(); |
Siddharth Ray | bb608c8 | 2017-03-16 11:33:34 -0700 | [diff] [blame] | 1577 | } |
| 1578 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1579 | @NativeEntryPoint |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1580 | private void reportLocationBatch(Location[] locationArray) { |
| 1581 | List<Location> locations = new ArrayList<>(Arrays.asList(locationArray)); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1582 | if (DEBUG) { |
| 1583 | Log.d(TAG, "Location batch of size " + locationArray.length + " reported"); |
| 1584 | } |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1585 | reportLocation(locations); |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1586 | } |
| 1587 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1588 | @NativeEntryPoint |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1589 | private void xtraDownloadRequest() { |
Joe Onorato | f5d95cb | 2010-01-07 21:48:32 -0500 | [diff] [blame] | 1590 | if (DEBUG) Log.d(TAG, "xtraDownloadRequest"); |
Mike Lockwood | 98e4869 | 2010-04-07 16:32:51 -0400 | [diff] [blame] | 1591 | sendMessage(DOWNLOAD_XTRA_DATA, 0, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1592 | } |
| 1593 | |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1594 | /** |
destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 1595 | * Converts the GPS HAL status to the internal Geofence Hardware status. |
| 1596 | */ |
Yu-Han Yang | 6dc9f05 | 2018-12-04 17:11:24 -0800 | [diff] [blame] | 1597 | private static int getGeofenceStatus(int status) { |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1598 | switch (status) { |
destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 1599 | case GPS_GEOFENCE_OPERATION_SUCCESS: |
| 1600 | return GeofenceHardware.GEOFENCE_SUCCESS; |
| 1601 | case GPS_GEOFENCE_ERROR_GENERIC: |
| 1602 | return GeofenceHardware.GEOFENCE_FAILURE; |
| 1603 | case GPS_GEOFENCE_ERROR_ID_EXISTS: |
| 1604 | return GeofenceHardware.GEOFENCE_ERROR_ID_EXISTS; |
| 1605 | case GPS_GEOFENCE_ERROR_INVALID_TRANSITION: |
| 1606 | return GeofenceHardware.GEOFENCE_ERROR_INVALID_TRANSITION; |
| 1607 | case GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES: |
| 1608 | return GeofenceHardware.GEOFENCE_ERROR_TOO_MANY_GEOFENCES; |
| 1609 | case GPS_GEOFENCE_ERROR_ID_UNKNOWN: |
| 1610 | return GeofenceHardware.GEOFENCE_ERROR_ID_UNKNOWN; |
| 1611 | default: |
| 1612 | return -1; |
| 1613 | } |
| 1614 | } |
| 1615 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1616 | @NativeEntryPoint |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 1617 | private void reportGeofenceTransition(int geofenceId, Location location, int transition, |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1618 | long transitionTimestamp) { |
Yu-Han Yang | 6dc9f05 | 2018-12-04 17:11:24 -0800 | [diff] [blame] | 1619 | mHandler.post(() -> { |
| 1620 | if (mGeofenceHardwareImpl == null) { |
| 1621 | mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext); |
| 1622 | } |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 1623 | |
Yu-Han Yang | 6dc9f05 | 2018-12-04 17:11:24 -0800 | [diff] [blame] | 1624 | mGeofenceHardwareImpl.reportGeofenceTransition( |
| 1625 | geofenceId, |
| 1626 | location, |
| 1627 | transition, |
| 1628 | transitionTimestamp, |
| 1629 | GeofenceHardware.MONITORING_TYPE_GPS_HARDWARE, |
| 1630 | FusedBatchOptions.SourceTechnologies.GNSS); |
| 1631 | }); |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1632 | } |
| 1633 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1634 | @NativeEntryPoint |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 1635 | private void reportGeofenceStatus(int status, Location location) { |
Yu-Han Yang | 6dc9f05 | 2018-12-04 17:11:24 -0800 | [diff] [blame] | 1636 | mHandler.post(() -> { |
| 1637 | if (mGeofenceHardwareImpl == null) { |
| 1638 | mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext); |
| 1639 | } |
| 1640 | int monitorStatus = GeofenceHardware.MONITOR_CURRENTLY_UNAVAILABLE; |
| 1641 | if (status == GPS_GEOFENCE_AVAILABLE) { |
| 1642 | monitorStatus = GeofenceHardware.MONITOR_CURRENTLY_AVAILABLE; |
| 1643 | } |
| 1644 | mGeofenceHardwareImpl.reportGeofenceMonitorStatus( |
| 1645 | GeofenceHardware.MONITORING_TYPE_GPS_HARDWARE, |
| 1646 | monitorStatus, |
| 1647 | location, |
| 1648 | FusedBatchOptions.SourceTechnologies.GNSS); |
| 1649 | }); |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1650 | } |
| 1651 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1652 | @NativeEntryPoint |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1653 | private void reportGeofenceAddStatus(int geofenceId, int status) { |
Yu-Han Yang | 6dc9f05 | 2018-12-04 17:11:24 -0800 | [diff] [blame] | 1654 | mHandler.post(() -> { |
| 1655 | if (mGeofenceHardwareImpl == null) { |
| 1656 | mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext); |
| 1657 | } |
| 1658 | mGeofenceHardwareImpl.reportGeofenceAddStatus(geofenceId, getGeofenceStatus(status)); |
| 1659 | }); |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1660 | } |
| 1661 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1662 | @NativeEntryPoint |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1663 | private void reportGeofenceRemoveStatus(int geofenceId, int status) { |
Yu-Han Yang | 6dc9f05 | 2018-12-04 17:11:24 -0800 | [diff] [blame] | 1664 | mHandler.post(() -> { |
| 1665 | if (mGeofenceHardwareImpl == null) { |
| 1666 | mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext); |
| 1667 | } |
| 1668 | mGeofenceHardwareImpl.reportGeofenceRemoveStatus(geofenceId, getGeofenceStatus(status)); |
| 1669 | }); |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1670 | } |
| 1671 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1672 | @NativeEntryPoint |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1673 | private void reportGeofencePauseStatus(int geofenceId, int status) { |
Yu-Han Yang | 6dc9f05 | 2018-12-04 17:11:24 -0800 | [diff] [blame] | 1674 | mHandler.post(() -> { |
| 1675 | if (mGeofenceHardwareImpl == null) { |
| 1676 | mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext); |
| 1677 | } |
| 1678 | mGeofenceHardwareImpl.reportGeofencePauseStatus(geofenceId, getGeofenceStatus(status)); |
| 1679 | }); |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1680 | } |
| 1681 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1682 | @NativeEntryPoint |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1683 | private void reportGeofenceResumeStatus(int geofenceId, int status) { |
Yu-Han Yang | 6dc9f05 | 2018-12-04 17:11:24 -0800 | [diff] [blame] | 1684 | mHandler.post(() -> { |
| 1685 | if (mGeofenceHardwareImpl == null) { |
| 1686 | mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext); |
| 1687 | } |
| 1688 | mGeofenceHardwareImpl.reportGeofenceResumeStatus(geofenceId, getGeofenceStatus(status)); |
| 1689 | }); |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1690 | } |
| 1691 | |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 1692 | //============================================================= |
| 1693 | // NI Client support |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1694 | //============================================================= |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 1695 | private final INetInitiatedListener mNetInitiatedListener = new INetInitiatedListener.Stub() { |
destradaa | ef752b6 | 2015-04-17 13:10:47 -0700 | [diff] [blame] | 1696 | // Sends a response for an NI request to HAL. |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1697 | @Override |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1698 | public boolean sendNiResponse(int notificationId, int userResponse) { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1699 | // TODO Add Permission check |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 1700 | |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1701 | if (DEBUG) { |
| 1702 | Log.d(TAG, "sendNiResponse, notifId: " + notificationId + |
| 1703 | ", response: " + userResponse); |
| 1704 | } |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1705 | native_send_ni_response(notificationId, userResponse); |
| 1706 | return true; |
| 1707 | } |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 1708 | }; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1709 | |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 1710 | public INetInitiatedListener getNetInitiatedListener() { |
| 1711 | return mNetInitiatedListener; |
| 1712 | } |
| 1713 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1714 | /** Reports a NI notification. */ |
| 1715 | @NativeEntryPoint |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1716 | public void reportNiNotification( |
| 1717 | int notificationId, |
| 1718 | int niType, |
| 1719 | int notifyFlags, |
| 1720 | int timeout, |
| 1721 | int defaultResponse, |
| 1722 | String requestorId, |
| 1723 | String text, |
| 1724 | int requestorIdEncoding, |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1725 | int textEncoding |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1726 | ) { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1727 | Log.i(TAG, "reportNiNotification: entered"); |
| 1728 | Log.i(TAG, "notificationId: " + notificationId + |
| 1729 | ", niType: " + niType + |
| 1730 | ", notifyFlags: " + notifyFlags + |
| 1731 | ", timeout: " + timeout + |
| 1732 | ", defaultResponse: " + defaultResponse); |
| 1733 | |
| 1734 | Log.i(TAG, "requestorId: " + requestorId + |
| 1735 | ", text: " + text + |
| 1736 | ", requestorIdEncoding: " + requestorIdEncoding + |
| 1737 | ", textEncoding: " + textEncoding); |
| 1738 | |
| 1739 | GpsNiNotification notification = new GpsNiNotification(); |
| 1740 | |
| 1741 | notification.notificationId = notificationId; |
| 1742 | notification.niType = niType; |
| 1743 | notification.needNotify = (notifyFlags & GpsNetInitiatedHandler.GPS_NI_NEED_NOTIFY) != 0; |
| 1744 | notification.needVerify = (notifyFlags & GpsNetInitiatedHandler.GPS_NI_NEED_VERIFY) != 0; |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1745 | notification.privacyOverride = |
| 1746 | (notifyFlags & GpsNetInitiatedHandler.GPS_NI_PRIVACY_OVERRIDE) != 0; |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1747 | notification.timeout = timeout; |
| 1748 | notification.defaultResponse = defaultResponse; |
| 1749 | notification.requestorId = requestorId; |
| 1750 | notification.text = text; |
| 1751 | notification.requestorIdEncoding = requestorIdEncoding; |
| 1752 | notification.textEncoding = textEncoding; |
| 1753 | |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1754 | mNIHandler.handleNiNotification(notification); |
| 1755 | } |
| 1756 | |
| 1757 | /** |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1758 | * We should be careful about receiving null string from the TelephonyManager, |
| 1759 | * because sending null String to JNI function would cause a crash. |
| 1760 | */ |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1761 | @NativeEntryPoint |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1762 | private void requestSetID(int flags) { |
| 1763 | TelephonyManager phone = (TelephonyManager) |
| 1764 | mContext.getSystemService(Context.TELEPHONY_SERVICE); |
destradaa | ef752b6 | 2015-04-17 13:10:47 -0700 | [diff] [blame] | 1765 | int type = AGPS_SETID_TYPE_NONE; |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1766 | String data = ""; |
| 1767 | |
| 1768 | if ((flags & AGPS_RIL_REQUEST_SETID_IMSI) == AGPS_RIL_REQUEST_SETID_IMSI) { |
| 1769 | String data_temp = phone.getSubscriberId(); |
| 1770 | if (data_temp == null) { |
| 1771 | // This means the framework does not have the SIM card ready. |
| 1772 | } else { |
| 1773 | // This means the framework has the SIM card. |
| 1774 | data = data_temp; |
| 1775 | type = AGPS_SETID_TYPE_IMSI; |
| 1776 | } |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1777 | } else if ((flags & AGPS_RIL_REQUEST_SETID_MSISDN) == AGPS_RIL_REQUEST_SETID_MSISDN) { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1778 | String data_temp = phone.getLine1Number(); |
| 1779 | if (data_temp == null) { |
| 1780 | // This means the framework does not have the SIM card ready. |
| 1781 | } else { |
| 1782 | // This means the framework has the SIM card. |
| 1783 | data = data_temp; |
| 1784 | type = AGPS_SETID_TYPE_MSISDN; |
| 1785 | } |
| 1786 | } |
| 1787 | native_agps_set_id(type, data); |
| 1788 | } |
| 1789 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1790 | @NativeEntryPoint |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 1791 | private void requestLocation(boolean independentFromGnss) { |
| 1792 | if (DEBUG) { |
| 1793 | Log.d(TAG, "requestLocation. independentFromGnss: " + independentFromGnss); |
| 1794 | } |
| 1795 | sendMessage(REQUEST_LOCATION, 0, independentFromGnss); |
| 1796 | } |
| 1797 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1798 | @NativeEntryPoint |
Mike Lockwood | 9b9fb5c | 2011-06-29 15:09:40 -0400 | [diff] [blame] | 1799 | private void requestUtcTime() { |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 1800 | if (DEBUG) Log.d(TAG, "utcTimeRequest"); |
Mike Lockwood | 9b9fb5c | 2011-06-29 15:09:40 -0400 | [diff] [blame] | 1801 | sendMessage(INJECT_NTP_TIME, 0, null); |
| 1802 | } |
| 1803 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1804 | @NativeEntryPoint |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1805 | private void requestRefLocation() { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1806 | TelephonyManager phone = (TelephonyManager) |
| 1807 | mContext.getSystemService(Context.TELEPHONY_SERVICE); |
Victoria Lease | d50d0c3 | 2012-10-29 13:16:17 -0700 | [diff] [blame] | 1808 | final int phoneType = phone.getPhoneType(); |
| 1809 | if (phoneType == TelephonyManager.PHONE_TYPE_GSM) { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1810 | GsmCellLocation gsm_cell = (GsmCellLocation) phone.getCellLocation(); |
Victoria Lease | d50d0c3 | 2012-10-29 13:16:17 -0700 | [diff] [blame] | 1811 | if ((gsm_cell != null) && (phone.getNetworkOperator() != null) |
| 1812 | && (phone.getNetworkOperator().length() > 3)) { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1813 | int type; |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1814 | int mcc = Integer.parseInt(phone.getNetworkOperator().substring(0, 3)); |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1815 | int mnc = Integer.parseInt(phone.getNetworkOperator().substring(3)); |
Mike Lockwood | edc0f387 | 2010-10-22 09:16:17 -0400 | [diff] [blame] | 1816 | int networkType = phone.getNetworkType(); |
| 1817 | if (networkType == TelephonyManager.NETWORK_TYPE_UMTS |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1818 | || networkType == TelephonyManager.NETWORK_TYPE_HSDPA |
| 1819 | || networkType == TelephonyManager.NETWORK_TYPE_HSUPA |
| 1820 | || networkType == TelephonyManager.NETWORK_TYPE_HSPA |
| 1821 | || networkType == TelephonyManager.NETWORK_TYPE_HSPAP) { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1822 | type = AGPS_REF_LOCATION_TYPE_UMTS_CELLID; |
Mike Lockwood | edc0f387 | 2010-10-22 09:16:17 -0400 | [diff] [blame] | 1823 | } else { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1824 | type = AGPS_REF_LOCATION_TYPE_GSM_CELLID; |
Mike Lockwood | edc0f387 | 2010-10-22 09:16:17 -0400 | [diff] [blame] | 1825 | } |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1826 | native_agps_set_ref_location_cellid(type, mcc, mnc, |
| 1827 | gsm_cell.getLac(), gsm_cell.getCid()); |
Mike Lockwood | edc0f387 | 2010-10-22 09:16:17 -0400 | [diff] [blame] | 1828 | } else { |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1829 | Log.e(TAG, "Error getting cell location info."); |
Mike Lockwood | edc0f387 | 2010-10-22 09:16:17 -0400 | [diff] [blame] | 1830 | } |
Victoria Lease | d50d0c3 | 2012-10-29 13:16:17 -0700 | [diff] [blame] | 1831 | } else if (phoneType == TelephonyManager.PHONE_TYPE_CDMA) { |
| 1832 | Log.e(TAG, "CDMA not supported."); |
Mike Lockwood | edc0f387 | 2010-10-22 09:16:17 -0400 | [diff] [blame] | 1833 | } |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1834 | } |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 1835 | |
Mike Lockwood | 98e4869 | 2010-04-07 16:32:51 -0400 | [diff] [blame] | 1836 | private void sendMessage(int message, int arg, Object obj) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1837 | // hold a wake lock until this message is delivered |
Jeff Brown | 028872f | 2012-08-25 13:07:01 -0700 | [diff] [blame] | 1838 | // note that this assumes the message will not be removed from the queue before |
| 1839 | // it is handled (otherwise the wake lock would be leaked). |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1840 | mWakeLock.acquire(); |
Anil Admal | 4f97c94 | 2018-11-12 10:52:46 -0800 | [diff] [blame] | 1841 | if (DEBUG) { |
| 1842 | Log.d(TAG, "WakeLock acquired by sendMessage(" + messageIdAsString(message) + ", " + arg |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1843 | + ", " + obj + ")"); |
| 1844 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1845 | mHandler.obtainMessage(message, arg, 1, obj).sendToTarget(); |
Mike Lockwood | 98e4869 | 2010-04-07 16:32:51 -0400 | [diff] [blame] | 1846 | } |
| 1847 | |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 1848 | private final class ProviderHandler extends Handler { |
Victoria Lease | 5cd731a | 2012-12-19 15:04:21 -0800 | [diff] [blame] | 1849 | public ProviderHandler(Looper looper) { |
| 1850 | super(looper, null, true /*async*/); |
Jeff Brown | 028872f | 2012-08-25 13:07:01 -0700 | [diff] [blame] | 1851 | } |
| 1852 | |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 1853 | @Override |
Mike Lockwood | 4a7b65e | 2010-10-25 16:35:55 -0400 | [diff] [blame] | 1854 | public void handleMessage(Message msg) { |
Mike Lockwood | 98e4869 | 2010-04-07 16:32:51 -0400 | [diff] [blame] | 1855 | int message = msg.what; |
| 1856 | switch (message) { |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 1857 | case ENABLE: |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1858 | handleEnable(); |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 1859 | break; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1860 | case SET_REQUEST: |
| 1861 | GpsRequest gpsRequest = (GpsRequest) msg.obj; |
| 1862 | handleSetRequest(gpsRequest.request, gpsRequest.source); |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 1863 | break; |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 1864 | case INJECT_NTP_TIME: |
Yu-Han Yang | a1862b5 | 2018-02-20 17:05:59 -0800 | [diff] [blame] | 1865 | mNtpTimeHelper.retrieveAndInjectNtpTime(); |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 1866 | break; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 1867 | case REQUEST_LOCATION: |
| 1868 | handleRequestLocation((boolean) msg.obj); |
| 1869 | break; |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 1870 | case DOWNLOAD_XTRA_DATA: |
Wyatt Riley | 0d6e54e2 | 2016-10-05 12:03:03 -0700 | [diff] [blame] | 1871 | handleDownloadXtraData(); |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 1872 | break; |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 1873 | case DOWNLOAD_XTRA_DATA_FINISHED: |
| 1874 | mDownloadXtraDataPending = STATE_IDLE; |
| 1875 | break; |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 1876 | case UPDATE_LOCATION: |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 1877 | handleUpdateLocation((Location) msg.obj); |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 1878 | break; |
Meng Wang | 19b214d | 2018-11-07 12:14:39 -0800 | [diff] [blame] | 1879 | case SUBSCRIPTION_OR_CARRIER_CONFIG_CHANGED: |
| 1880 | subscriptionOrCarrierConfigChanged(mContext); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 1881 | break; |
| 1882 | case INITIALIZE_HANDLER: |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 1883 | handleInitialize(); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 1884 | break; |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1885 | case REPORT_LOCATION: |
| 1886 | handleReportLocation(msg.arg1 == 1, (Location) msg.obj); |
| 1887 | break; |
| 1888 | case REPORT_SV_STATUS: |
| 1889 | handleReportSvStatus((SvStatusInfo) msg.obj); |
| 1890 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1891 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1892 | if (msg.arg2 == 1) { |
| 1893 | // wakelock was taken for this message, release it |
| 1894 | mWakeLock.release(); |
Anil Admal | 4f97c94 | 2018-11-12 10:52:46 -0800 | [diff] [blame] | 1895 | if (DEBUG) { |
| 1896 | Log.d(TAG, "WakeLock released by handleMessage(" + messageIdAsString(message) |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1897 | + ", " + msg.arg1 + ", " + msg.obj + ")"); |
| 1898 | } |
Mike Lockwood | 98e4869 | 2010-04-07 16:32:51 -0400 | [diff] [blame] | 1899 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1900 | } |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 1901 | |
| 1902 | /** |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1903 | * This method is bound to {@link #GnssLocationProvider(Context, LocationProviderManager, |
| 1904 | * Looper)}. |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 1905 | * It is in charge of loading properties and registering for events that will be posted to |
| 1906 | * this handler. |
| 1907 | */ |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 1908 | private void handleInitialize() { |
Yu-Han Yang | 6d31735 | 2018-03-15 11:53:01 -0700 | [diff] [blame] | 1909 | native_init_once(); |
| 1910 | |
Wyatt Riley | 523a0cf | 2017-10-31 14:36:52 -0700 | [diff] [blame] | 1911 | /* |
| 1912 | * A cycle of native_init() and native_cleanup() is needed so that callbacks are |
| 1913 | * registered after bootup even when location is disabled. |
| 1914 | * This will allow Emergency SUPL to work even when location is disabled before device |
| 1915 | * restart. |
| 1916 | */ |
| 1917 | boolean isInitialized = native_init(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1918 | if (!isInitialized) { |
Wyatt Riley | 523a0cf | 2017-10-31 14:36:52 -0700 | [diff] [blame] | 1919 | Log.w(TAG, "Native initialization failed at bootup"); |
| 1920 | } else { |
| 1921 | native_cleanup(); |
| 1922 | } |
| 1923 | |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 1924 | // load default GPS configuration |
| 1925 | // (this configuration might change in the future based on SIM changes) |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame^] | 1926 | reloadGpsProperties(); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 1927 | |
| 1928 | // TODO: When this object "finishes" we should unregister by invoking |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1929 | // SubscriptionManager.getInstance(mContext).unregister |
| 1930 | // (mOnSubscriptionsChangedListener); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 1931 | // This is not strictly necessary because it will be unregistered if the |
| 1932 | // notification fails but it is good form. |
| 1933 | |
| 1934 | // Register for SubscriptionInfo list changes which is guaranteed |
| 1935 | // to invoke onSubscriptionsChanged the first time. |
| 1936 | SubscriptionManager.from(mContext) |
| 1937 | .addOnSubscriptionsChangedListener(mOnSubscriptionsChangedListener); |
| 1938 | |
| 1939 | // listen for events |
WyattRiley | 6593cf1 | 2018-06-23 10:37:48 -0700 | [diff] [blame] | 1940 | IntentFilter intentFilter = new IntentFilter(); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 1941 | intentFilter.addAction(ALARM_WAKEUP); |
| 1942 | intentFilter.addAction(ALARM_TIMEOUT); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 1943 | intentFilter.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED); |
Adam Lesinski | 87c17df | 2015-05-27 13:24:13 -0700 | [diff] [blame] | 1944 | intentFilter.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 1945 | intentFilter.addAction(Intent.ACTION_SCREEN_OFF); |
| 1946 | intentFilter.addAction(Intent.ACTION_SCREEN_ON); |
Meng Wang | 19b214d | 2018-11-07 12:14:39 -0800 | [diff] [blame] | 1947 | intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 1948 | mContext.registerReceiver(mBroadcastReceiver, intentFilter, null, this); |
| 1949 | |
Anil Admal | 50ba15e | 2018-11-01 16:42:42 -0700 | [diff] [blame] | 1950 | mNetworkConnectivityHandler.registerNetworkCallbacks(); |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 1951 | |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 1952 | // listen for PASSIVE_PROVIDER updates |
| 1953 | LocationManager locManager = |
| 1954 | (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); |
| 1955 | long minTime = 0; |
| 1956 | float minDistance = 0; |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 1957 | LocationRequest request = LocationRequest.createFromDeprecatedProvider( |
| 1958 | LocationManager.PASSIVE_PROVIDER, |
| 1959 | minTime, |
| 1960 | minDistance, |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1961 | false); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 1962 | // Don't keep track of this request since it's done on behalf of other clients |
| 1963 | // (which are kept track of separately). |
| 1964 | request.setHideFromAppOps(true); |
| 1965 | locManager.requestLocationUpdates( |
| 1966 | request, |
| 1967 | new NetworkLocationListener(), |
| 1968 | getLooper()); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1969 | |
| 1970 | // enable gps provider, it will never be disabled (legacy behavior) |
| 1971 | sendEmptyMessage(ENABLE); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 1972 | } |
| 1973 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1974 | |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 1975 | private abstract class LocationChangeListener implements LocationListener { |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1976 | private int mNumLocationUpdateRequest; |
Yu-Han Yang | 0756138 | 2018-02-21 13:08:37 -0800 | [diff] [blame] | 1977 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1978 | @Override |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1979 | public void onStatusChanged(String provider, int status, Bundle extras) { |
| 1980 | } |
| 1981 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1982 | @Override |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1983 | public void onProviderEnabled(String provider) { |
| 1984 | } |
| 1985 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1986 | @Override |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1987 | public void onProviderDisabled(String provider) { |
| 1988 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1989 | } |
| 1990 | |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 1991 | private final class NetworkLocationListener extends LocationChangeListener { |
| 1992 | @Override |
| 1993 | public void onLocationChanged(Location location) { |
| 1994 | // this callback happens on mHandler looper |
| 1995 | if (LocationManager.NETWORK_PROVIDER.equals(location.getProvider())) { |
| 1996 | handleUpdateLocation(location); |
| 1997 | } |
| 1998 | } |
| 1999 | } |
| 2000 | |
| 2001 | private final class FusedLocationListener extends LocationChangeListener { |
| 2002 | @Override |
| 2003 | public void onLocationChanged(Location location) { |
| 2004 | if (LocationManager.FUSED_PROVIDER.equals(location.getProvider())) { |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 2005 | injectBestLocation(location); |
| 2006 | } |
| 2007 | } |
| 2008 | } |
| 2009 | |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2010 | /** |
| 2011 | * @return A string representing the given message ID. |
| 2012 | */ |
| 2013 | private String messageIdAsString(int message) { |
| 2014 | switch (message) { |
| 2015 | case ENABLE: |
| 2016 | return "ENABLE"; |
| 2017 | case SET_REQUEST: |
| 2018 | return "SET_REQUEST"; |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2019 | case INJECT_NTP_TIME: |
| 2020 | return "INJECT_NTP_TIME"; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 2021 | case REQUEST_LOCATION: |
| 2022 | return "REQUEST_LOCATION"; |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2023 | case DOWNLOAD_XTRA_DATA: |
| 2024 | return "DOWNLOAD_XTRA_DATA"; |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2025 | case DOWNLOAD_XTRA_DATA_FINISHED: |
| 2026 | return "DOWNLOAD_XTRA_DATA_FINISHED"; |
| 2027 | case UPDATE_LOCATION: |
| 2028 | return "UPDATE_LOCATION"; |
Meng Wang | 19b214d | 2018-11-07 12:14:39 -0800 | [diff] [blame] | 2029 | case SUBSCRIPTION_OR_CARRIER_CONFIG_CHANGED: |
| 2030 | return "SUBSCRIPTION_OR_CARRIER_CONFIG_CHANGED"; |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2031 | case INITIALIZE_HANDLER: |
| 2032 | return "INITIALIZE_HANDLER"; |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 2033 | case REPORT_LOCATION: |
| 2034 | return "REPORT_LOCATION"; |
| 2035 | case REPORT_SV_STATUS: |
| 2036 | return "REPORT_SV_STATUS"; |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2037 | default: |
| 2038 | return "<Unknown>"; |
| 2039 | } |
| 2040 | } |
| 2041 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2042 | @Override |
| 2043 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 2044 | StringBuilder s = new StringBuilder(); |
Wyatt Riley | 77ca4f8 | 2017-06-30 18:13:44 -0700 | [diff] [blame] | 2045 | s.append(" mStarted=").append(mStarted).append('\n'); |
destradaa | 25e8caf | 2015-08-24 14:14:44 -0700 | [diff] [blame] | 2046 | s.append(" mFixInterval=").append(mFixInterval).append('\n'); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2047 | s.append(" mLowPowerMode=").append(mLowPowerMode).append('\n'); |
Wyatt Riley | 74479bd | 2018-01-17 08:48:27 -0800 | [diff] [blame] | 2048 | s.append(" mGnssMeasurementsProvider.isRegistered()=") |
| 2049 | .append(mGnssMeasurementsProvider.isRegistered()).append('\n'); |
| 2050 | s.append(" mGnssNavigationMessageProvider.isRegistered()=") |
| 2051 | .append(mGnssNavigationMessageProvider.isRegistered()).append('\n'); |
destradaa | 25e8caf | 2015-08-24 14:14:44 -0700 | [diff] [blame] | 2052 | s.append(" mDisableGps (battery saver mode)=").append(mDisableGps).append('\n'); |
| 2053 | s.append(" mEngineCapabilities=0x").append(Integer.toHexString(mEngineCapabilities)); |
| 2054 | s.append(" ( "); |
| 2055 | if (hasCapability(GPS_CAPABILITY_SCHEDULING)) s.append("SCHEDULING "); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2056 | if (hasCapability(GPS_CAPABILITY_MSB)) s.append("MSB "); |
| 2057 | if (hasCapability(GPS_CAPABILITY_MSA)) s.append("MSA "); |
| 2058 | if (hasCapability(GPS_CAPABILITY_SINGLE_SHOT)) s.append("SINGLE_SHOT "); |
| 2059 | if (hasCapability(GPS_CAPABILITY_ON_DEMAND_TIME)) s.append("ON_DEMAND_TIME "); |
destradaa | 25e8caf | 2015-08-24 14:14:44 -0700 | [diff] [blame] | 2060 | if (hasCapability(GPS_CAPABILITY_GEOFENCING)) s.append("GEOFENCING "); |
| 2061 | if (hasCapability(GPS_CAPABILITY_MEASUREMENTS)) s.append("MEASUREMENTS "); |
| 2062 | if (hasCapability(GPS_CAPABILITY_NAV_MESSAGES)) s.append("NAV_MESSAGES "); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2063 | s.append(")\n"); |
Siddharth Ray | bb608c8 | 2017-03-16 11:33:34 -0700 | [diff] [blame] | 2064 | s.append(mGnssMetrics.dumpGnssMetricsAsText()); |
| 2065 | s.append(" native internal state: ").append(native_get_internal_state()); |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2066 | s.append("\n"); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2067 | pw.append(s); |
| 2068 | } |
| 2069 | |
Mike Lockwood | b16e780 | 2009-08-06 09:26:02 -0400 | [diff] [blame] | 2070 | // preallocated to avoid memory allocation in reportNmea() |
| 2071 | private byte[] mNmeaBuffer = new byte[120]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2072 | |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2073 | static { |
| 2074 | class_init_native(); |
| 2075 | } |
| 2076 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2077 | private static native void class_init_native(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2078 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2079 | private static native boolean native_is_supported(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2080 | |
Yu-Han Yang | 6d31735 | 2018-03-15 11:53:01 -0700 | [diff] [blame] | 2081 | private static native void native_init_once(); |
| 2082 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2083 | private native boolean native_init(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2084 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2085 | private native void native_cleanup(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2086 | |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 2087 | private native boolean native_set_position_mode(int mode, int recurrence, int min_interval, |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2088 | int preferred_accuracy, int preferred_time, boolean lowPowerMode); |
| 2089 | |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 2090 | private native boolean native_start(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2091 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2092 | private native boolean native_stop(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2093 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2094 | private native void native_delete_aiding_data(int flags); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2095 | |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 2096 | private native int native_read_nmea(byte[] buffer, int bufferSize); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2097 | |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 2098 | private native void native_inject_best_location( |
| 2099 | int gnssLocationFlags, |
| 2100 | double latitudeDegrees, |
| 2101 | double longitudeDegrees, |
| 2102 | double altitudeMeters, |
| 2103 | float speedMetersPerSec, |
| 2104 | float bearingDegrees, |
| 2105 | float horizontalAccuracyMeters, |
| 2106 | float verticalAccuracyMeters, |
| 2107 | float speedAccuracyMetersPerSecond, |
| 2108 | float bearingAccuracyDegrees, |
| 2109 | long timestamp); |
| 2110 | |
Mike Lockwood | d26ce0d | 2009-06-11 12:25:46 -0400 | [diff] [blame] | 2111 | private native void native_inject_location(double latitude, double longitude, float accuracy); |
| 2112 | |
Fred Fettinger | 3c8fbdf | 2010-01-04 15:38:13 -0600 | [diff] [blame] | 2113 | // XTRA Support |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2114 | private native void native_inject_time(long time, long timeReference, int uncertainty); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2115 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2116 | private native boolean native_supports_xtra(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2117 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2118 | private native void native_inject_xtra_data(byte[] data, int length); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2119 | |
Fred Fettinger | 3c8fbdf | 2010-01-04 15:38:13 -0600 | [diff] [blame] | 2120 | // DEBUG Support |
| 2121 | private native String native_get_internal_state(); |
| 2122 | |
| 2123 | // AGPS Support |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2124 | private native void native_agps_ni_message(byte[] msg, int length); |
| 2125 | |
Mike Lockwood | a9e5461 | 2009-06-19 14:54:42 -0400 | [diff] [blame] | 2126 | private native void native_set_agps_server(int type, String hostname, int port); |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 2127 | |
| 2128 | // Network-initiated (NI) Support |
| 2129 | private native void native_send_ni_response(int notificationId, int userResponse); |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 2130 | |
Anil Admal | 50ba15e | 2018-11-01 16:42:42 -0700 | [diff] [blame] | 2131 | // AGPS ril support |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 2132 | private native void native_agps_set_ref_location_cellid(int type, int mcc, int mnc, |
| 2133 | int lac, int cid); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2134 | |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 2135 | private native void native_agps_set_id(int type, String setid); |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame^] | 2136 | } |