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