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