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