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