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; |
Yu-Han Yang | 639f759 | 2018-06-07 11:58:52 -0700 | [diff] [blame] | 256 | // Default update duration in milliseconds for REQUEST_LOCATION. |
Yu-Han Yang | 9e2a823 | 2018-06-14 12:10:08 -0700 | [diff] [blame] | 257 | private static final long LOCATION_UPDATE_DURATION_MILLIS = 10 * 1000; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 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 | } |
WyattRiley | a725dd6 | 2018-12-06 11:43:58 -0800 | [diff] [blame] | 726 | |
| 727 | String emergencyExtensionSecondsString |
| 728 | = properties.getProperty("ES_EXTENSION_SEC", "0"); |
| 729 | try { |
| 730 | int emergencyExtensionSeconds = |
| 731 | Integer.parseInt(emergencyExtensionSecondsString); |
| 732 | mNIHandler.setEmergencyExtensionSeconds(emergencyExtensionSeconds); |
| 733 | } catch (NumberFormatException e) { |
| 734 | Log.e(TAG, "unable to parse ES_EXTENSION_SEC: " |
| 735 | + emergencyExtensionSecondsString); |
| 736 | } |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | private void loadPropertiesFromResource(Context context, |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 740 | Properties properties) { |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 741 | String[] configValues = context.getResources().getStringArray( |
| 742 | com.android.internal.R.array.config_gpsParameters); |
| 743 | for (String item : configValues) { |
Joe Onorato | 0c48410 | 2016-02-01 18:04:24 -0800 | [diff] [blame] | 744 | if (DEBUG) Log.d(TAG, "GpsParamsResource: " + item); |
Tsuwei Chen | 7c485bf | 2014-09-10 15:33:34 -0700 | [diff] [blame] | 745 | // We need to support "KEY =", but not "=VALUE". |
Zheng Zhang | ad48bd9 | 2017-10-16 10:27:28 -0700 | [diff] [blame] | 746 | int index = item.indexOf("="); |
| 747 | if (index > 0 && index + 1 < item.length()) { |
| 748 | String key = item.substring(0, index); |
| 749 | String value = item.substring(index + 1); |
| 750 | properties.setProperty(key.trim().toUpperCase(), value); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 751 | } else { |
| 752 | Log.w(TAG, "malformed contents: " + item); |
| 753 | } |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | private boolean loadPropertiesFromFile(String filename, |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 758 | Properties properties) { |
Colin Cross | 7c030ed | 2014-01-28 09:33:53 -0800 | [diff] [blame] | 759 | try { |
| 760 | File file = new File(filename); |
| 761 | FileInputStream stream = null; |
| 762 | try { |
| 763 | stream = new FileInputStream(file); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 764 | properties.load(stream); |
Colin Cross | 7c030ed | 2014-01-28 09:33:53 -0800 | [diff] [blame] | 765 | } finally { |
| 766 | IoUtils.closeQuietly(stream); |
| 767 | } |
| 768 | |
Colin Cross | 7c030ed | 2014-01-28 09:33:53 -0800 | [diff] [blame] | 769 | } catch (IOException e) { |
Wyatt Riley | 3e1cd0b | 2017-04-19 17:57:14 -0700 | [diff] [blame] | 770 | if (DEBUG) Log.d(TAG, "Could not open GPS configuration file " + filename); |
Colin Cross | 7c030ed | 2014-01-28 09:33:53 -0800 | [diff] [blame] | 771 | return false; |
| 772 | } |
| 773 | return true; |
| 774 | } |
| 775 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 776 | public GnssLocationProvider(Context context, ILocationManager ilocationManager, |
Victoria Lease | 5cd731a | 2012-12-19 15:04:21 -0800 | [diff] [blame] | 777 | Looper looper) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 778 | mContext = context; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 779 | mILocationManager = ilocationManager; |
Mike Lockwood | 63598a0 | 2010-02-24 11:52:59 -0500 | [diff] [blame] | 780 | |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 781 | // Create a wake lock |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 782 | mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); |
| 783 | mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCK_KEY); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 784 | mWakeLock.setReferenceCounted(true); |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 785 | |
Wei Wang | b71c049 | 2017-05-01 20:24:19 -0700 | [diff] [blame] | 786 | // Create a separate wake lock for xtra downloader as it may be released due to timeout. |
| 787 | mDownloadXtraWakeLock = mPowerManager.newWakeLock( |
| 788 | PowerManager.PARTIAL_WAKE_LOCK, DOWNLOAD_EXTRA_WAKELOCK_KEY); |
| 789 | mDownloadXtraWakeLock.setReferenceCounted(true); |
| 790 | |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 791 | mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 792 | mWakeupIntent = PendingIntent.getBroadcast(mContext, 0, new Intent(ALARM_WAKEUP), 0); |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 793 | mTimeoutIntent = PendingIntent.getBroadcast(mContext, 0, new Intent(ALARM_TIMEOUT), 0); |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 794 | |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 795 | mConnMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 796 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 797 | // App ops service to keep track of who is accessing the GPS |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 798 | mAppOps = mContext.getSystemService(AppOpsManager.class); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 799 | |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 800 | // Battery statistics service to be notified when GPS turns on or off |
Dianne Hackborn | 91268cf | 2013-06-13 19:06:50 -0700 | [diff] [blame] | 801 | mBatteryStats = IBatteryStats.Stub.asInterface(ServiceManager.getService( |
| 802 | BatteryStats.SERVICE_NAME)); |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 803 | |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 804 | // Construct internal handler |
| 805 | mHandler = new ProviderHandler(looper); |
| 806 | |
| 807 | // Load GPS configuration and register listeners in the background: |
| 808 | // some operations, such as opening files and registering broadcast receivers, can take a |
| 809 | // relative long time, so the ctor() is kept to create objects needed by this instance, |
| 810 | // while IO initialization and registration is delegated to our internal handler |
| 811 | // 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] | 812 | mProperties = new Properties(); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 813 | sendMessage(INITIALIZE_HANDLER, 0, null); |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 814 | |
Tsuwei Chen | 3324e95 | 2014-09-07 01:30:42 -0700 | [diff] [blame] | 815 | // Create a GPS net-initiated handler. |
| 816 | mNIHandler = new GpsNetInitiatedHandler(context, |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 817 | mNetInitiatedListener, |
| 818 | mSuplEsEnabled); |
Tsuwei Chen | 3324e95 | 2014-09-07 01:30:42 -0700 | [diff] [blame] | 819 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 820 | mListenerHelper = new GnssStatusListenerHelper(mHandler) { |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 821 | @Override |
| 822 | protected boolean isAvailableInPlatform() { |
destradaa | 13a60b0 | 2015-01-15 18:36:01 -0800 | [diff] [blame] | 823 | return isSupported(); |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | @Override |
| 827 | protected boolean isGpsEnabled() { |
| 828 | return isEnabled(); |
| 829 | } |
| 830 | }; |
| 831 | |
Yu-Han Yang | 8de2150 | 2018-04-23 01:40:25 -0700 | [diff] [blame] | 832 | mGnssMeasurementsProvider = new GnssMeasurementsProvider(mContext, mHandler) { |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 833 | @Override |
| 834 | protected boolean isGpsEnabled() { |
| 835 | return isEnabled(); |
| 836 | } |
| 837 | }; |
| 838 | |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 839 | mGnssNavigationMessageProvider = new GnssNavigationMessageProvider(mHandler) { |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 840 | @Override |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 841 | protected boolean isGpsEnabled() { |
| 842 | return isEnabled(); |
| 843 | } |
| 844 | }; |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 845 | mGnssMetrics = new GnssMetrics(mBatteryStats); |
Yu-Han Yang | a1862b5 | 2018-02-20 17:05:59 -0800 | [diff] [blame] | 846 | |
Yu-Han Yang | 66c7ea9 | 2018-03-11 17:17:15 -0700 | [diff] [blame] | 847 | mNtpTimeHelper = new NtpTimeHelper(mContext, looper, this); |
| 848 | mGnssSatelliteBlacklistHelper = new GnssSatelliteBlacklistHelper(mContext, |
| 849 | looper, this); |
| 850 | mHandler.post(mGnssSatelliteBlacklistHelper::updateSatelliteBlacklist); |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 851 | mGnssBatchingProvider = new GnssBatchingProvider(); |
Yu-Han Yang | 890ca8b | 2018-04-16 22:11:31 -0700 | [diff] [blame] | 852 | mGnssGeofenceProvider = new GnssGeofenceProvider(looper); |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 853 | } |
| 854 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 855 | /** |
Mike Lockwood | d03ff94 | 2010-02-09 08:46:14 -0500 | [diff] [blame] | 856 | * Returns the name of this provider. |
| 857 | */ |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 858 | @Override |
Mike Lockwood | d03ff94 | 2010-02-09 08:46:14 -0500 | [diff] [blame] | 859 | public String getName() { |
| 860 | return LocationManager.GPS_PROVIDER; |
| 861 | } |
| 862 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 863 | @Override |
| 864 | public ProviderProperties getProperties() { |
| 865 | return PROPERTIES; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 866 | } |
| 867 | |
Yu-Han Yang | a1862b5 | 2018-02-20 17:05:59 -0800 | [diff] [blame] | 868 | |
| 869 | /** |
| 870 | * Implements {@link InjectNtpTimeCallback#injectTime} |
| 871 | */ |
| 872 | @Override |
| 873 | public void injectTime(long time, long timeReference, int uncertainty) { |
| 874 | native_inject_time(time, timeReference, uncertainty); |
| 875 | } |
| 876 | |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 877 | private void handleUpdateNetworkState(Network network) { |
| 878 | // retrieve NetworkInfo for this UID |
| 879 | NetworkInfo info = mConnMgr.getNetworkInfo(network); |
Kevin Tang | 71ad5fe | 2017-05-10 19:36:20 -0700 | [diff] [blame] | 880 | |
| 881 | boolean networkAvailable = false; |
| 882 | boolean isConnected = false; |
| 883 | int type = ConnectivityManager.TYPE_NONE; |
| 884 | boolean isRoaming = false; |
| 885 | String apnName = null; |
| 886 | |
| 887 | if (info != null) { |
| 888 | networkAvailable = info.isAvailable() && TelephonyManager.getDefault().getDataEnabled(); |
| 889 | isConnected = info.isConnected(); |
| 890 | type = info.getType(); |
| 891 | isRoaming = info.isRoaming(); |
| 892 | apnName = info.getExtraInfo(); |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 893 | } |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 894 | |
Joe Onorato | f5d95cb | 2010-01-07 21:48:32 -0500 | [diff] [blame] | 895 | if (DEBUG) { |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 896 | String message = String.format( |
| 897 | "UpdateNetworkState, state=%s, connected=%s, info=%s, capabilities=%S", |
| 898 | agpsDataConnStateAsString(), |
| 899 | isConnected, |
| 900 | info, |
| 901 | mConnMgr.getNetworkCapabilities(network)); |
| 902 | Log.d(TAG, message); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 903 | } |
Mike Lockwood | 03d2467 | 2009-10-08 15:45:03 -0400 | [diff] [blame] | 904 | |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 905 | if (native_is_agps_ril_supported()) { |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 906 | String defaultApn = getSelectedApn(); |
| 907 | if (defaultApn == null) { |
| 908 | defaultApn = "dummy-apn"; |
destradaa | ef752b6 | 2015-04-17 13:10:47 -0700 | [diff] [blame] | 909 | } |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 910 | |
| 911 | native_update_network_state( |
| 912 | isConnected, |
Kevin Tang | 71ad5fe | 2017-05-10 19:36:20 -0700 | [diff] [blame] | 913 | type, |
| 914 | isRoaming, |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 915 | networkAvailable, |
Kevin Tang | 71ad5fe | 2017-05-10 19:36:20 -0700 | [diff] [blame] | 916 | apnName, |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 917 | defaultApn); |
| 918 | } else if (DEBUG) { |
| 919 | 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] | 920 | } |
| 921 | |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 922 | if (mAGpsDataConnectionState == AGPS_DATA_CONNECTION_OPENING) { |
| 923 | if (isConnected) { |
Stephen Li | 83b6971 | 2011-01-25 18:47:28 -0800 | [diff] [blame] | 924 | if (apnName == null) { |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 925 | // assign a dummy value in the case of C2K as otherwise we will have a runtime |
| 926 | // exception in the following call to native_agps_data_conn_open |
Stephen Li | 83b6971 | 2011-01-25 18:47:28 -0800 | [diff] [blame] | 927 | apnName = "dummy-apn"; |
| 928 | } |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 929 | int apnIpType = getApnIpType(apnName); |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 930 | setRouting(); |
| 931 | if (DEBUG) { |
| 932 | String message = String.format( |
| 933 | "native_agps_data_conn_open: mAgpsApn=%s, mApnIpType=%s", |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 934 | apnName, |
| 935 | apnIpType); |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 936 | Log.d(TAG, message); |
Stephen Li | 8efd74d | 2011-03-01 20:56:00 -0800 | [diff] [blame] | 937 | } |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 938 | native_agps_data_conn_open(apnName, apnIpType); |
Mike Lockwood | 03d2467 | 2009-10-08 15:45:03 -0400 | [diff] [blame] | 939 | mAGpsDataConnectionState = AGPS_DATA_CONNECTION_OPEN; |
| 940 | } else { |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 941 | handleReleaseSuplConnection(GPS_AGPS_DATA_CONN_FAILED); |
Mike Lockwood | 03d2467 | 2009-10-08 15:45:03 -0400 | [diff] [blame] | 942 | } |
| 943 | } |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 944 | } |
Mike Lockwood | 03d2467 | 2009-10-08 15:45:03 -0400 | [diff] [blame] | 945 | |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 946 | private void handleRequestSuplConnection(InetAddress address) { |
| 947 | if (DEBUG) { |
| 948 | String message = String.format( |
| 949 | "requestSuplConnection, state=%s, address=%s", |
| 950 | agpsDataConnStateAsString(), |
| 951 | address); |
| 952 | Log.d(TAG, message); |
| 953 | } |
| 954 | |
| 955 | if (mAGpsDataConnectionState != AGPS_DATA_CONNECTION_CLOSED) { |
| 956 | return; |
| 957 | } |
| 958 | mAGpsDataConnectionIpAddr = address; |
| 959 | mAGpsDataConnectionState = AGPS_DATA_CONNECTION_OPENING; |
| 960 | |
| 961 | NetworkRequest.Builder requestBuilder = new NetworkRequest.Builder(); |
| 962 | requestBuilder.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR); |
| 963 | requestBuilder.addCapability(NetworkCapabilities.NET_CAPABILITY_SUPL); |
| 964 | NetworkRequest request = requestBuilder.build(); |
| 965 | mConnMgr.requestNetwork( |
| 966 | request, |
Etan Cohen | e9aea9d | 2017-02-09 18:16:58 -0800 | [diff] [blame] | 967 | mSuplConnectivityCallback); |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | private void handleReleaseSuplConnection(int agpsDataConnStatus) { |
| 971 | if (DEBUG) { |
| 972 | String message = String.format( |
| 973 | "releaseSuplConnection, state=%s, status=%s", |
| 974 | agpsDataConnStateAsString(), |
| 975 | agpsDataConnStatusAsString(agpsDataConnStatus)); |
| 976 | Log.d(TAG, message); |
| 977 | } |
| 978 | |
| 979 | if (mAGpsDataConnectionState == AGPS_DATA_CONNECTION_CLOSED) { |
| 980 | return; |
| 981 | } |
| 982 | mAGpsDataConnectionState = AGPS_DATA_CONNECTION_CLOSED; |
| 983 | |
| 984 | mConnMgr.unregisterNetworkCallback(mSuplConnectivityCallback); |
| 985 | switch (agpsDataConnStatus) { |
| 986 | case GPS_AGPS_DATA_CONN_FAILED: |
| 987 | native_agps_data_conn_failed(); |
| 988 | break; |
| 989 | case GPS_RELEASE_AGPS_DATA_CONN: |
| 990 | native_agps_data_conn_closed(); |
| 991 | break; |
| 992 | default: |
| 993 | Log.e(TAG, "Invalid status to release SUPL connection: " + agpsDataConnStatus); |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 994 | } |
| 995 | } |
Yu-Han Yang | 8de2150 | 2018-04-23 01:40:25 -0700 | [diff] [blame] | 996 | |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 997 | private void handleRequestLocation(boolean independentFromGnss) { |
| 998 | if (isRequestLocationRateLimited()) { |
| 999 | if (DEBUG) { |
| 1000 | Log.d(TAG, "RequestLocation is denied due to too frequent requests."); |
| 1001 | } |
| 1002 | return; |
| 1003 | } |
Yu-Han Yang | 74041ff | 2018-04-06 15:57:31 -0700 | [diff] [blame] | 1004 | ContentResolver resolver = mContext.getContentResolver(); |
| 1005 | long durationMillis = Settings.Global.getLong( |
| 1006 | resolver, |
| 1007 | Settings.Global.GNSS_HAL_LOCATION_REQUEST_DURATION_MILLIS, |
| 1008 | LOCATION_UPDATE_DURATION_MILLIS); |
| 1009 | if (durationMillis == 0) { |
| 1010 | Log.i(TAG, "GNSS HAL location request is disabled by Settings."); |
| 1011 | return; |
| 1012 | } |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 1013 | |
| 1014 | LocationManager locationManager = (LocationManager) mContext.getSystemService( |
| 1015 | Context.LOCATION_SERVICE); |
Yu-Han Yang | 0756138 | 2018-02-21 13:08:37 -0800 | [diff] [blame] | 1016 | String provider; |
| 1017 | LocationChangeListener locationListener; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 1018 | |
| 1019 | if (independentFromGnss) { |
| 1020 | // For fast GNSS TTFF |
Yu-Han Yang | 0756138 | 2018-02-21 13:08:37 -0800 | [diff] [blame] | 1021 | provider = LocationManager.NETWORK_PROVIDER; |
| 1022 | locationListener = mNetworkLocationListener; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 1023 | } else { |
| 1024 | // For Device-Based Hybrid (E911) |
Yu-Han Yang | 0756138 | 2018-02-21 13:08:37 -0800 | [diff] [blame] | 1025 | provider = LocationManager.FUSED_PROVIDER; |
| 1026 | locationListener = mFusedLocationListener; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 1027 | } |
Yu-Han Yang | 0756138 | 2018-02-21 13:08:37 -0800 | [diff] [blame] | 1028 | |
| 1029 | Log.i(TAG, |
Yu-Han Yang | 74041ff | 2018-04-06 15:57:31 -0700 | [diff] [blame] | 1030 | String.format( |
| 1031 | "GNSS HAL Requesting location updates from %s provider for %d millis.", |
| 1032 | provider, durationMillis)); |
Yu-Han Yang | e684dda | 2018-05-24 10:29:39 -0700 | [diff] [blame] | 1033 | try { |
| 1034 | locationManager.requestLocationUpdates(provider, |
| 1035 | LOCATION_UPDATE_MIN_TIME_INTERVAL_MILLIS, /*minDistance=*/ 0, |
| 1036 | locationListener, mHandler.getLooper()); |
| 1037 | locationListener.numLocationUpdateRequest++; |
| 1038 | mHandler.postDelayed(() -> { |
| 1039 | if (--locationListener.numLocationUpdateRequest == 0) { |
| 1040 | Log.i(TAG, |
| 1041 | String.format("Removing location updates from %s provider.", provider)); |
| 1042 | locationManager.removeUpdates(locationListener); |
| 1043 | } |
| 1044 | }, durationMillis); |
| 1045 | } catch (IllegalArgumentException e) { |
| 1046 | Log.w(TAG, "Unable to request location.", e); |
| 1047 | } |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | private void injectBestLocation(Location location) { |
| 1051 | int gnssLocationFlags = LOCATION_HAS_LAT_LONG | |
| 1052 | (location.hasAltitude() ? LOCATION_HAS_ALTITUDE : 0) | |
| 1053 | (location.hasSpeed() ? LOCATION_HAS_SPEED : 0) | |
| 1054 | (location.hasBearing() ? LOCATION_HAS_BEARING : 0) | |
| 1055 | (location.hasAccuracy() ? LOCATION_HAS_HORIZONTAL_ACCURACY : 0) | |
| 1056 | (location.hasVerticalAccuracy() ? LOCATION_HAS_VERTICAL_ACCURACY : 0) | |
| 1057 | (location.hasSpeedAccuracy() ? LOCATION_HAS_SPEED_ACCURACY : 0) | |
| 1058 | (location.hasBearingAccuracy() ? LOCATION_HAS_BEARING_ACCURACY : 0); |
| 1059 | |
| 1060 | double latitudeDegrees = location.getLatitude(); |
| 1061 | double longitudeDegrees = location.getLongitude(); |
| 1062 | double altitudeMeters = location.getAltitude(); |
| 1063 | float speedMetersPerSec = location.getSpeed(); |
| 1064 | float bearingDegrees = location.getBearing(); |
| 1065 | float horizontalAccuracyMeters = location.getAccuracy(); |
| 1066 | float verticalAccuracyMeters = location.getVerticalAccuracyMeters(); |
| 1067 | float speedAccuracyMetersPerSecond = location.getSpeedAccuracyMetersPerSecond(); |
| 1068 | float bearingAccuracyDegrees = location.getBearingAccuracyDegrees(); |
| 1069 | long timestamp = location.getTime(); |
| 1070 | native_inject_best_location(gnssLocationFlags, latitudeDegrees, longitudeDegrees, |
| 1071 | altitudeMeters, speedMetersPerSec, bearingDegrees, horizontalAccuracyMeters, |
| 1072 | verticalAccuracyMeters, speedAccuracyMetersPerSecond, bearingAccuracyDegrees, |
| 1073 | timestamp); |
| 1074 | } |
| 1075 | |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 1076 | /** Returns true if the location request is too frequent. */ |
| 1077 | private boolean isRequestLocationRateLimited() { |
| 1078 | // TODO(b/73198123): implement exponential backoff. |
| 1079 | return false; |
| 1080 | } |
| 1081 | |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 1082 | private void handleDownloadXtraData() { |
Wyatt Riley | 0d6e54e2 | 2016-10-05 12:03:03 -0700 | [diff] [blame] | 1083 | if (!mSupportsXtra) { |
| 1084 | // native code reports xtra not supported, don't try |
| 1085 | Log.d(TAG, "handleDownloadXtraData() called when Xtra not supported"); |
| 1086 | return; |
| 1087 | } |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 1088 | if (mDownloadXtraDataPending == STATE_DOWNLOADING) { |
| 1089 | // already downloading data |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 1090 | return; |
| 1091 | } |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 1092 | if (!isDataNetworkConnected()) { |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 1093 | // try again when network is up |
| 1094 | mDownloadXtraDataPending = STATE_PENDING_NETWORK; |
| 1095 | return; |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 1096 | } |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 1097 | mDownloadXtraDataPending = STATE_DOWNLOADING; |
| 1098 | |
Jeff Brown | 028872f | 2012-08-25 13:07:01 -0700 | [diff] [blame] | 1099 | // hold wake lock while task runs |
Wei Wang | b71c049 | 2017-05-01 20:24:19 -0700 | [diff] [blame] | 1100 | mDownloadXtraWakeLock.acquire(DOWNLOAD_XTRA_DATA_TIMEOUT_MS); |
Lifu Tang | cbd2a14 | 2016-06-22 10:57:55 -0700 | [diff] [blame] | 1101 | Log.i(TAG, "WakeLock acquired by handleDownloadXtraData()"); |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 1102 | AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() { |
| 1103 | @Override |
| 1104 | public void run() { |
Andreas Gampe | dfdc6ac | 2014-10-28 20:42:53 -0700 | [diff] [blame] | 1105 | GpsXtraDownloader xtraDownloader = new GpsXtraDownloader(mProperties); |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 1106 | byte[] data = xtraDownloader.downloadXtraData(); |
| 1107 | if (data != null) { |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 1108 | if (DEBUG) Log.d(TAG, "calling native_inject_xtra_data"); |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 1109 | native_inject_xtra_data(data, data.length); |
Wei Liu | 6f6326b | 2015-06-24 23:47:50 -0700 | [diff] [blame] | 1110 | mXtraBackOff.reset(); |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 1111 | } |
| 1112 | |
Jeff Brown | 028872f | 2012-08-25 13:07:01 -0700 | [diff] [blame] | 1113 | sendMessage(DOWNLOAD_XTRA_DATA_FINISHED, 0, null); |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 1114 | |
| 1115 | if (data == null) { |
| 1116 | // try again later |
| 1117 | // 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] | 1118 | mHandler.sendEmptyMessageDelayed(DOWNLOAD_XTRA_DATA, |
| 1119 | mXtraBackOff.nextBackoffMillis()); |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 1120 | } |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 1121 | |
Wei Wang | b71c049 | 2017-05-01 20:24:19 -0700 | [diff] [blame] | 1122 | // Release wake lock held by task, synchronize on mLock in case multiple |
| 1123 | // download tasks overrun. |
| 1124 | synchronized (mLock) { |
| 1125 | if (mDownloadXtraWakeLock.isHeld()) { |
Zheng Zhang | 3cceb25 | 2017-08-07 13:51:23 -0700 | [diff] [blame] | 1126 | // This wakelock may have time-out, if a timeout was specified. |
| 1127 | // Catch (and ignore) any timeout exceptions. |
| 1128 | try { |
| 1129 | mDownloadXtraWakeLock.release(); |
| 1130 | if (DEBUG) Log.d(TAG, "WakeLock released by handleDownloadXtraData()"); |
| 1131 | } catch (Exception e) { |
| 1132 | Log.i(TAG, "Wakelock timeout & release race exception in " |
| 1133 | + "handleDownloadXtraData()", e); |
| 1134 | } |
Wei Wang | b71c049 | 2017-05-01 20:24:19 -0700 | [diff] [blame] | 1135 | } else { |
| 1136 | Log.e(TAG, "WakeLock expired before release in " |
| 1137 | + "handleDownloadXtraData()"); |
| 1138 | } |
Wei Wang | c5706f6 | 2017-04-18 11:26:26 -0700 | [diff] [blame] | 1139 | } |
Jeff Brown | 028872f | 2012-08-25 13:07:01 -0700 | [diff] [blame] | 1140 | } |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 1141 | }); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1142 | } |
| 1143 | |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 1144 | private void handleUpdateLocation(Location location) { |
Mike Lockwood | d26ce0d | 2009-06-11 12:25:46 -0400 | [diff] [blame] | 1145 | if (location.hasAccuracy()) { |
| 1146 | native_inject_location(location.getLatitude(), location.getLongitude(), |
| 1147 | location.getAccuracy()); |
| 1148 | } |
Mike Lockwood | fd6e5f0 | 2009-05-21 11:28:20 -0400 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1152 | * Enables this provider. When enabled, calls to getStatus() |
Mike Lockwood | 4e50b78 | 2009-04-03 08:24:43 -0700 | [diff] [blame] | 1153 | * must be handled. Hardware may be started up |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1154 | * when the provider is enabled. |
| 1155 | */ |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1156 | @Override |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 1157 | public void enable() { |
Laurent Tu | 7b5aeca | 2013-01-24 15:10:24 -0800 | [diff] [blame] | 1158 | synchronized (mLock) { |
| 1159 | if (mEnabled) return; |
| 1160 | mEnabled = true; |
| 1161 | } |
| 1162 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1163 | sendMessage(ENABLE, 1, null); |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 1164 | } |
| 1165 | |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 1166 | private void setSuplHostPort(String hostString, String portString) { |
| 1167 | if (hostString != null) { |
| 1168 | mSuplServerHost = hostString; |
| 1169 | } |
| 1170 | if (portString != null) { |
| 1171 | try { |
| 1172 | mSuplServerPort = Integer.parseInt(portString); |
| 1173 | } catch (NumberFormatException e) { |
| 1174 | Log.e(TAG, "unable to parse SUPL_PORT: " + portString); |
| 1175 | } |
| 1176 | } |
Tsuwei Chen | 678c13c | 2014-09-22 17:48:41 -0700 | [diff] [blame] | 1177 | if (mSuplServerHost != null |
| 1178 | && mSuplServerPort > TCP_MIN_PORT |
| 1179 | && mSuplServerPort <= TCP_MAX_PORT) { |
| 1180 | native_set_agps_server(AGPS_TYPE_SUPL, mSuplServerHost, mSuplServerPort); |
| 1181 | } |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 1182 | } |
| 1183 | |
Tsuwei Chen | 462bcd8 | 2014-09-17 12:28:49 -0700 | [diff] [blame] | 1184 | /** |
| 1185 | * Checks what SUPL mode to use, according to the AGPS mode as well as the |
| 1186 | * allowed mode from properties. |
| 1187 | * |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1188 | * @param properties GPS properties |
Tsuwei Chen | 462bcd8 | 2014-09-17 12:28:49 -0700 | [diff] [blame] | 1189 | * @param agpsEnabled whether AGPS is enabled by settings value |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1190 | * @param singleShot whether "singleshot" is needed |
Tsuwei Chen | 462bcd8 | 2014-09-17 12:28:49 -0700 | [diff] [blame] | 1191 | * @return SUPL mode (MSA vs MSB vs STANDALONE) |
| 1192 | */ |
| 1193 | private int getSuplMode(Properties properties, boolean agpsEnabled, boolean singleShot) { |
| 1194 | if (agpsEnabled) { |
| 1195 | String modeString = properties.getProperty("SUPL_MODE"); |
| 1196 | int suplMode = 0; |
| 1197 | if (!TextUtils.isEmpty(modeString)) { |
| 1198 | try { |
| 1199 | suplMode = Integer.parseInt(modeString); |
| 1200 | } catch (NumberFormatException e) { |
| 1201 | Log.e(TAG, "unable to parse SUPL_MODE: " + modeString); |
| 1202 | return GPS_POSITION_MODE_STANDALONE; |
| 1203 | } |
| 1204 | } |
destradaa | bfb3bdb | 2015-04-29 14:42:35 -0700 | [diff] [blame] | 1205 | // MS-Based is the preferred mode for Assisted-GPS position computation, so we favor |
| 1206 | // such mode when it is available |
| 1207 | if (hasCapability(GPS_CAPABILITY_MSB) && (suplMode & AGPS_SUPL_MODE_MSB) != 0) { |
| 1208 | return GPS_POSITION_MODE_MS_BASED; |
| 1209 | } |
| 1210 | // for now, just as the legacy code did, we fallback to MS-Assisted if it is available, |
| 1211 | // do fallback only for single-shot requests, because it is too expensive to do for |
| 1212 | // periodic requests as well |
Tsuwei Chen | 462bcd8 | 2014-09-17 12:28:49 -0700 | [diff] [blame] | 1213 | if (singleShot |
| 1214 | && hasCapability(GPS_CAPABILITY_MSA) |
| 1215 | && (suplMode & AGPS_SUPL_MODE_MSA) != 0) { |
| 1216 | return GPS_POSITION_MODE_MS_ASSISTED; |
Tsuwei Chen | 462bcd8 | 2014-09-17 12:28:49 -0700 | [diff] [blame] | 1217 | } |
| 1218 | } |
| 1219 | return GPS_POSITION_MODE_STANDALONE; |
| 1220 | } |
| 1221 | |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 1222 | private void handleEnable() { |
| 1223 | if (DEBUG) Log.d(TAG, "handleEnable"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1224 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1225 | boolean enabled = native_init(); |
| 1226 | |
| 1227 | if (enabled) { |
Mike Lockwood | 1a1cd3a | 2010-08-17 07:42:54 -0400 | [diff] [blame] | 1228 | mSupportsXtra = native_supports_xtra(); |
Tsuwei Chen | 678c13c | 2014-09-22 17:48:41 -0700 | [diff] [blame] | 1229 | |
| 1230 | // 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] | 1231 | if (mSuplServerHost != null) { |
| 1232 | native_set_agps_server(AGPS_TYPE_SUPL, mSuplServerHost, mSuplServerPort); |
| 1233 | } |
| 1234 | if (mC2KServerHost != null) { |
| 1235 | native_set_agps_server(AGPS_TYPE_C2K, mC2KServerHost, mC2KServerPort); |
| 1236 | } |
destradaa | 13a60b0 | 2015-01-15 18:36:01 -0800 | [diff] [blame] | 1237 | |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 1238 | mGnssMeasurementsProvider.onGpsEnabledChanged(); |
| 1239 | mGnssNavigationMessageProvider.onGpsEnabledChanged(); |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 1240 | mGnssBatchingProvider.enable(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1241 | } else { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1242 | synchronized (mLock) { |
| 1243 | mEnabled = false; |
| 1244 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1245 | Log.w(TAG, "Failed to enable location provider"); |
| 1246 | } |
| 1247 | } |
| 1248 | |
| 1249 | /** |
| 1250 | * Disables this provider. When disabled, calls to getStatus() |
Mike Lockwood | 4e50b78 | 2009-04-03 08:24:43 -0700 | [diff] [blame] | 1251 | * need not be handled. Hardware may be shut |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1252 | * down while the provider is disabled. |
| 1253 | */ |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1254 | @Override |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 1255 | public void disable() { |
Laurent Tu | 7b5aeca | 2013-01-24 15:10:24 -0800 | [diff] [blame] | 1256 | synchronized (mLock) { |
| 1257 | if (!mEnabled) return; |
| 1258 | mEnabled = false; |
| 1259 | } |
| 1260 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1261 | sendMessage(ENABLE, 0, null); |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | private void handleDisable() { |
Mike Lockwood | 8909631 | 2010-03-24 10:14:55 -0400 | [diff] [blame] | 1265 | if (DEBUG) Log.d(TAG, "handleDisable"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1266 | |
David Christie | 3bc2614 | 2013-12-19 14:53:44 -0800 | [diff] [blame] | 1267 | updateClientUids(new WorkSource()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1268 | stopNavigating(); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1269 | mAlarmManager.cancel(mWakeupIntent); |
| 1270 | mAlarmManager.cancel(mTimeoutIntent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1271 | |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 1272 | mGnssBatchingProvider.disable(); |
Mike Lockwood | cf1d8cb | 2010-01-20 10:14:54 -0500 | [diff] [blame] | 1273 | // do this before releasing wakelock |
| 1274 | native_cleanup(); |
destradaa | 13a60b0 | 2015-01-15 18:36:01 -0800 | [diff] [blame] | 1275 | |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 1276 | mGnssMeasurementsProvider.onGpsEnabledChanged(); |
| 1277 | mGnssNavigationMessageProvider.onGpsEnabledChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1278 | } |
| 1279 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1280 | @Override |
Mike Lockwood | d03ff94 | 2010-02-09 08:46:14 -0500 | [diff] [blame] | 1281 | public boolean isEnabled() { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1282 | synchronized (mLock) { |
| 1283 | return mEnabled; |
| 1284 | } |
Mike Lockwood | d03ff94 | 2010-02-09 08:46:14 -0500 | [diff] [blame] | 1285 | } |
| 1286 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1287 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1288 | public int getStatus(Bundle extras) { |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 1289 | mLocationExtras.setBundle(extras); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1290 | return mStatus; |
| 1291 | } |
| 1292 | |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 1293 | private void updateStatus(int status) { |
| 1294 | if (status != mStatus) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1295 | mStatus = status; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1296 | mStatusUpdateTime = SystemClock.elapsedRealtime(); |
| 1297 | } |
| 1298 | } |
| 1299 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1300 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1301 | public long getStatusUpdateTime() { |
| 1302 | return mStatusUpdateTime; |
| 1303 | } |
| 1304 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1305 | @Override |
| 1306 | public void setRequest(ProviderRequest request, WorkSource source) { |
| 1307 | sendMessage(SET_REQUEST, 0, new GpsRequest(request, source)); |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 1308 | } |
| 1309 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1310 | private void handleSetRequest(ProviderRequest request, WorkSource source) { |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 1311 | mProviderRequest = request; |
| 1312 | mWorkSource = source; |
| 1313 | updateRequirements(); |
| 1314 | } |
| 1315 | |
| 1316 | // Called when the requirements for GPS may have changed |
| 1317 | private void updateRequirements() { |
| 1318 | if (mProviderRequest == null || mWorkSource == null) { |
| 1319 | return; |
| 1320 | } |
| 1321 | |
Stan Chesnutt | 1d72d8c | 2013-04-15 19:18:02 -0700 | [diff] [blame] | 1322 | boolean singleShot = false; |
| 1323 | |
| 1324 | // see if the request is for a single update |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 1325 | if (mProviderRequest.locationRequests != null |
| 1326 | && mProviderRequest.locationRequests.size() > 0) { |
Stan Chesnutt | 1d72d8c | 2013-04-15 19:18:02 -0700 | [diff] [blame] | 1327 | // if any request has zero or more than one updates |
| 1328 | // requested, then this is not single-shot mode |
| 1329 | singleShot = true; |
| 1330 | |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 1331 | for (LocationRequest lr : mProviderRequest.locationRequests) { |
Stan Chesnutt | 1d72d8c | 2013-04-15 19:18:02 -0700 | [diff] [blame] | 1332 | if (lr.getNumUpdates() != 1) { |
| 1333 | singleShot = false; |
| 1334 | } |
| 1335 | } |
| 1336 | } |
| 1337 | |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 1338 | if (DEBUG) Log.d(TAG, "setRequest " + mProviderRequest); |
Dante Russo | 260d667 | 2016-06-20 11:11:59 -0700 | [diff] [blame] | 1339 | if (mProviderRequest.reportLocation && !mDisableGps && isEnabled()) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1340 | // update client uids |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 1341 | updateClientUids(mWorkSource); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1342 | |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 1343 | mFixInterval = (int) mProviderRequest.interval; |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1344 | mLowPowerMode = (boolean) mProviderRequest.lowPowerMode; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1345 | // check for overflow |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 1346 | if (mFixInterval != mProviderRequest.interval) { |
| 1347 | Log.w(TAG, "interval overflow: " + mProviderRequest.interval); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1348 | mFixInterval = Integer.MAX_VALUE; |
| 1349 | } |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 1350 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1351 | // apply request to GPS engine |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 1352 | if (mStarted && hasCapability(GPS_CAPABILITY_SCHEDULING)) { |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1353 | // change period and/or lowPowerMode |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 1354 | if (!native_set_position_mode(mPositionMode, GPS_POSITION_RECURRENCE_PERIODIC, |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1355 | mFixInterval, 0, 0, mLowPowerMode)) { |
| 1356 | Log.e(TAG, "set_position_mode failed in updateRequirements"); |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 1357 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1358 | } else if (!mStarted) { |
| 1359 | // start GPS |
Stan Chesnutt | 1d72d8c | 2013-04-15 19:18:02 -0700 | [diff] [blame] | 1360 | startNavigating(singleShot); |
gomo | 300b240 | 2017-12-13 19:04:12 -0800 | [diff] [blame] | 1361 | } else { |
| 1362 | // GNSS Engine is already ON, but no GPS_CAPABILITY_SCHEDULING |
| 1363 | mAlarmManager.cancel(mTimeoutIntent); |
| 1364 | if (mFixInterval >= NO_FIX_TIMEOUT) { |
| 1365 | // set timer to give up if we do not receive a fix within NO_FIX_TIMEOUT |
| 1366 | // and our fix interval is not short |
| 1367 | mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, |
| 1368 | SystemClock.elapsedRealtime() + NO_FIX_TIMEOUT, mTimeoutIntent); } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1369 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1370 | } else { |
Dianne Hackborn | 002a54e | 2013-01-10 17:34:55 -0800 | [diff] [blame] | 1371 | updateClientUids(new WorkSource()); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1372 | |
| 1373 | stopNavigating(); |
| 1374 | mAlarmManager.cancel(mWakeupIntent); |
| 1375 | mAlarmManager.cancel(mTimeoutIntent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1376 | } |
| 1377 | } |
| 1378 | |
Dianne Hackborn | 002a54e | 2013-01-10 17:34:55 -0800 | [diff] [blame] | 1379 | private void updateClientUids(WorkSource source) { |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 1380 | if (source.equals(mClientSource)) { |
Victoria Lease | ea78b85 | 2013-01-15 10:39:28 -0800 | [diff] [blame] | 1381 | return; |
| 1382 | } |
Dianne Hackborn | 002a54e | 2013-01-10 17:34:55 -0800 | [diff] [blame] | 1383 | |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 1384 | // (1) Inform BatteryStats that the list of IDs we're tracking changed. |
| 1385 | try { |
| 1386 | mBatteryStats.noteGpsChanged(mClientSource, source); |
| 1387 | } catch (RemoteException e) { |
| 1388 | Log.w(TAG, "RemoteException", e); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1389 | } |
| 1390 | |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 1391 | // (2) Inform AppOps service about the list of changes to UIDs. |
| 1392 | |
| 1393 | List<WorkChain>[] diffs = WorkSource.diffChains(mClientSource, source); |
| 1394 | if (diffs != null) { |
| 1395 | List<WorkChain> newChains = diffs[0]; |
| 1396 | List<WorkChain> goneChains = diffs[1]; |
| 1397 | |
| 1398 | if (newChains != null) { |
| 1399 | for (int i = 0; i < newChains.size(); ++i) { |
| 1400 | final WorkChain newChain = newChains.get(i); |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 1401 | mAppOps.startOpNoThrow(AppOpsManager.OP_GPS, newChain.getAttributionUid(), |
| 1402 | newChain.getAttributionTag()); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 1403 | } |
| 1404 | } |
| 1405 | |
| 1406 | if (goneChains != null) { |
| 1407 | for (int i = 0; i < goneChains.size(); i++) { |
| 1408 | final WorkChain goneChain = goneChains.get(i); |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 1409 | mAppOps.finishOp(AppOpsManager.OP_GPS, goneChain.getAttributionUid(), |
| 1410 | goneChain.getAttributionTag()); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 1411 | } |
| 1412 | } |
| 1413 | |
| 1414 | mClientSource.transferWorkChains(source); |
| 1415 | } |
| 1416 | |
| 1417 | // Update the flat UIDs and names list and inform app-ops of all changes. |
| 1418 | WorkSource[] changes = mClientSource.setReturningDiffs(source); |
| 1419 | if (changes != null) { |
| 1420 | WorkSource newWork = changes[0]; |
| 1421 | WorkSource goneWork = changes[1]; |
| 1422 | |
| 1423 | // Update sources that were not previously tracked. |
| 1424 | if (newWork != null) { |
| 1425 | for (int i = 0; i < newWork.size(); i++) { |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 1426 | mAppOps.startOpNoThrow(AppOpsManager.OP_GPS, |
| 1427 | newWork.get(i), newWork.getName(i)); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 1428 | } |
| 1429 | } |
| 1430 | |
| 1431 | // Update sources that are no longer tracked. |
| 1432 | if (goneWork != null) { |
| 1433 | for (int i = 0; i < goneWork.size(); i++) { |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 1434 | mAppOps.finishOp(AppOpsManager.OP_GPS, goneWork.get(i), goneWork.getName(i)); |
Dianne Hackborn | 2e41842 | 2009-06-22 20:00:17 -0700 | [diff] [blame] | 1435 | } |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 1436 | } |
| 1437 | } |
| 1438 | } |
| 1439 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1440 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1441 | public boolean sendExtraCommand(String command, Bundle extras) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1442 | |
Mike Lockwood | 63aa5a6 | 2010-04-14 19:21:31 -0400 | [diff] [blame] | 1443 | long identity = Binder.clearCallingIdentity(); |
Peter Visontay | b25db36 | 2017-11-01 18:18:12 +0000 | [diff] [blame] | 1444 | try { |
| 1445 | boolean result = false; |
Mike Lockwood | 63aa5a6 | 2010-04-14 19:21:31 -0400 | [diff] [blame] | 1446 | |
Peter Visontay | b25db36 | 2017-11-01 18:18:12 +0000 | [diff] [blame] | 1447 | if ("delete_aiding_data".equals(command)) { |
| 1448 | result = deleteAidingData(extras); |
| 1449 | } else if ("force_time_injection".equals(command)) { |
| 1450 | requestUtcTime(); |
Mike Lockwood | 63aa5a6 | 2010-04-14 19:21:31 -0400 | [diff] [blame] | 1451 | result = true; |
Peter Visontay | b25db36 | 2017-11-01 18:18:12 +0000 | [diff] [blame] | 1452 | } else if ("force_xtra_injection".equals(command)) { |
| 1453 | if (mSupportsXtra) { |
| 1454 | xtraDownloadRequest(); |
| 1455 | result = true; |
| 1456 | } |
| 1457 | } else { |
| 1458 | Log.w(TAG, "sendExtraCommand: unknown command " + command); |
Mike Lockwood | 93bc44d | 2009-05-20 16:58:22 -0400 | [diff] [blame] | 1459 | } |
Peter Visontay | b25db36 | 2017-11-01 18:18:12 +0000 | [diff] [blame] | 1460 | return result; |
| 1461 | } finally { |
| 1462 | Binder.restoreCallingIdentity(identity); |
Mike Lockwood | 93bc44d | 2009-05-20 16:58:22 -0400 | [diff] [blame] | 1463 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | private boolean deleteAidingData(Bundle extras) { |
| 1467 | int flags; |
| 1468 | |
| 1469 | if (extras == null) { |
| 1470 | flags = GPS_DELETE_ALL; |
| 1471 | } else { |
| 1472 | flags = 0; |
| 1473 | if (extras.getBoolean("ephemeris")) flags |= GPS_DELETE_EPHEMERIS; |
| 1474 | if (extras.getBoolean("almanac")) flags |= GPS_DELETE_ALMANAC; |
| 1475 | if (extras.getBoolean("position")) flags |= GPS_DELETE_POSITION; |
| 1476 | if (extras.getBoolean("time")) flags |= GPS_DELETE_TIME; |
| 1477 | if (extras.getBoolean("iono")) flags |= GPS_DELETE_IONO; |
| 1478 | if (extras.getBoolean("utc")) flags |= GPS_DELETE_UTC; |
| 1479 | if (extras.getBoolean("health")) flags |= GPS_DELETE_HEALTH; |
| 1480 | if (extras.getBoolean("svdir")) flags |= GPS_DELETE_SVDIR; |
| 1481 | if (extras.getBoolean("svsteer")) flags |= GPS_DELETE_SVSTEER; |
| 1482 | if (extras.getBoolean("sadata")) flags |= GPS_DELETE_SADATA; |
| 1483 | if (extras.getBoolean("rti")) flags |= GPS_DELETE_RTI; |
| 1484 | if (extras.getBoolean("celldb-info")) flags |= GPS_DELETE_CELLDB_INFO; |
| 1485 | if (extras.getBoolean("all")) flags |= GPS_DELETE_ALL; |
| 1486 | } |
| 1487 | |
| 1488 | if (flags != 0) { |
| 1489 | native_delete_aiding_data(flags); |
| 1490 | return true; |
| 1491 | } |
| 1492 | |
| 1493 | return false; |
| 1494 | } |
| 1495 | |
Stan Chesnutt | 1d72d8c | 2013-04-15 19:18:02 -0700 | [diff] [blame] | 1496 | private void startNavigating(boolean singleShot) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1497 | if (!mStarted) { |
Stan Chesnutt | 1d72d8c | 2013-04-15 19:18:02 -0700 | [diff] [blame] | 1498 | if (DEBUG) Log.d(TAG, "startNavigating, singleShot is " + singleShot); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1499 | mTimeToFirstFix = 0; |
| 1500 | mLastFixTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1501 | mStarted = true; |
Stan Chesnutt | 1d72d8c | 2013-04-15 19:18:02 -0700 | [diff] [blame] | 1502 | mSingleShot = singleShot; |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 1503 | mPositionMode = GPS_POSITION_MODE_STANDALONE; |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1504 | // Notify about suppressed output, if speed limit was previously exceeded. |
| 1505 | // Elsewhere, we check again with every speed output reported. |
| 1506 | if (mItarSpeedLimitExceeded) { |
| 1507 | Log.i(TAG, "startNavigating with ITAR limit in place. Output limited " + |
| 1508 | "until slow enough speed reported."); |
| 1509 | } |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 1510 | |
Tsuwei Chen | 462bcd8 | 2014-09-17 12:28:49 -0700 | [diff] [blame] | 1511 | boolean agpsEnabled = |
| 1512 | (Settings.Global.getInt(mContext.getContentResolver(), |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1513 | Settings.Global.ASSISTED_GPS_ENABLED, 1) != 0); |
Tsuwei Chen | 462bcd8 | 2014-09-17 12:28:49 -0700 | [diff] [blame] | 1514 | mPositionMode = getSuplMode(mProperties, agpsEnabled, singleShot); |
Mike Lockwood | bcab8df | 2009-06-25 16:39:09 -0400 | [diff] [blame] | 1515 | |
Stan Chesnutt | 1d72d8c | 2013-04-15 19:18:02 -0700 | [diff] [blame] | 1516 | if (DEBUG) { |
| 1517 | String mode; |
| 1518 | |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1519 | switch (mPositionMode) { |
Stan Chesnutt | 1d72d8c | 2013-04-15 19:18:02 -0700 | [diff] [blame] | 1520 | case GPS_POSITION_MODE_STANDALONE: |
| 1521 | mode = "standalone"; |
| 1522 | break; |
| 1523 | case GPS_POSITION_MODE_MS_ASSISTED: |
| 1524 | mode = "MS_ASSISTED"; |
| 1525 | break; |
| 1526 | case GPS_POSITION_MODE_MS_BASED: |
| 1527 | mode = "MS_BASED"; |
| 1528 | break; |
| 1529 | default: |
| 1530 | mode = "unknown"; |
| 1531 | break; |
| 1532 | } |
| 1533 | Log.d(TAG, "setting position_mode to " + mode); |
| 1534 | } |
| 1535 | |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 1536 | int interval = (hasCapability(GPS_CAPABILITY_SCHEDULING) ? mFixInterval : 1000); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1537 | mLowPowerMode = (boolean) mProviderRequest.lowPowerMode; |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 1538 | if (!native_set_position_mode(mPositionMode, GPS_POSITION_RECURRENCE_PERIODIC, |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1539 | interval, 0, 0, mLowPowerMode)) { |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 1540 | mStarted = false; |
| 1541 | Log.e(TAG, "set_position_mode failed in startNavigating()"); |
| 1542 | return; |
| 1543 | } |
| 1544 | if (!native_start()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1545 | mStarted = false; |
| 1546 | Log.e(TAG, "native_start failed in startNavigating()"); |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 1547 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1548 | } |
| 1549 | |
| 1550 | // reset SV count to zero |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 1551 | updateStatus(LocationProvider.TEMPORARILY_UNAVAILABLE); |
| 1552 | mLocationExtras.reset(); |
Yipeng Cao | 282b594 | 2017-05-17 20:31:39 -0700 | [diff] [blame] | 1553 | mFixRequestTime = SystemClock.elapsedRealtime(); |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 1554 | if (!hasCapability(GPS_CAPABILITY_SCHEDULING)) { |
| 1555 | // set timer to give up if we do not receive a fix within NO_FIX_TIMEOUT |
| 1556 | // and our fix interval is not short |
| 1557 | if (mFixInterval >= NO_FIX_TIMEOUT) { |
| 1558 | mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, |
| 1559 | SystemClock.elapsedRealtime() + NO_FIX_TIMEOUT, mTimeoutIntent); |
| 1560 | } |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 1561 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1562 | } |
| 1563 | } |
| 1564 | |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 1565 | private void stopNavigating() { |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 1566 | if (DEBUG) Log.d(TAG, "stopNavigating"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1567 | if (mStarted) { |
| 1568 | mStarted = false; |
Stan Chesnutt | 1d72d8c | 2013-04-15 19:18:02 -0700 | [diff] [blame] | 1569 | mSingleShot = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1570 | native_stop(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1571 | mLastFixTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1572 | |
| 1573 | // reset SV count to zero |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 1574 | updateStatus(LocationProvider.TEMPORARILY_UNAVAILABLE); |
| 1575 | mLocationExtras.reset(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1576 | } |
| 1577 | } |
| 1578 | |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 1579 | private void hibernate() { |
| 1580 | // stop GPS until our next fix interval arrives |
| 1581 | stopNavigating(); |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 1582 | mAlarmManager.cancel(mTimeoutIntent); |
| 1583 | mAlarmManager.cancel(mWakeupIntent); |
| 1584 | long now = SystemClock.elapsedRealtime(); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1585 | mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, now + mFixInterval, mWakeupIntent); |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 1586 | } |
| 1587 | |
| 1588 | private boolean hasCapability(int capability) { |
| 1589 | return ((mEngineCapabilities & capability) != 0); |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 1590 | } |
| 1591 | |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1592 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1593 | /** |
| 1594 | * called from native code to update our position. |
| 1595 | */ |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 1596 | private void reportLocation(boolean hasLatLong, Location location) { |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1597 | sendMessage(REPORT_LOCATION, hasLatLong ? 1 : 0, location); |
| 1598 | } |
| 1599 | |
| 1600 | private void handleReportLocation(boolean hasLatLong, Location location) { |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 1601 | if (location.hasSpeed()) { |
| 1602 | mItarSpeedLimitExceeded = location.getSpeed() > ITAR_SPEED_LIMIT_METERS_PER_SECOND; |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1603 | } |
| 1604 | |
| 1605 | if (mItarSpeedLimitExceeded) { |
| 1606 | Log.i(TAG, "Hal reported a speed in excess of ITAR limit." + |
| 1607 | " GPS/GNSS Navigation output blocked."); |
Siddharth Ray | 53ddc80 | 2018-03-16 12:01:52 -0700 | [diff] [blame] | 1608 | if (mStarted) { |
| 1609 | mGnssMetrics.logReceivedLocationStatus(false); |
| 1610 | } |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1611 | return; // No output of location allowed |
| 1612 | } |
| 1613 | |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 1614 | if (VERBOSE) Log.v(TAG, "reportLocation " + location.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1615 | |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1616 | // It would be nice to push the elapsed real-time timestamp |
| 1617 | // further down the stack, but this is still useful |
| 1618 | location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos()); |
| 1619 | location.setExtras(mLocationExtras.getBundle()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1620 | |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1621 | try { |
| 1622 | mILocationManager.reportLocation(location, false); |
| 1623 | } catch (RemoteException e) { |
| 1624 | Log.e(TAG, "RemoteException calling reportLocation"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1625 | } |
| 1626 | |
Siddharth Ray | 53ddc80 | 2018-03-16 12:01:52 -0700 | [diff] [blame] | 1627 | if (mStarted) { |
| 1628 | mGnssMetrics.logReceivedLocationStatus(hasLatLong); |
| 1629 | if (hasLatLong) { |
| 1630 | if (location.hasAccuracy()) { |
| 1631 | mGnssMetrics.logPositionAccuracyMeters(location.getAccuracy()); |
| 1632 | } |
| 1633 | if (mTimeToFirstFix > 0) { |
| 1634 | int timeBetweenFixes = (int) (SystemClock.elapsedRealtime() - mLastFixTime); |
| 1635 | mGnssMetrics.logMissedReports(mFixInterval, timeBetweenFixes); |
| 1636 | } |
Siddharth Ray | bb608c8 | 2017-03-16 11:33:34 -0700 | [diff] [blame] | 1637 | } |
| 1638 | } |
| 1639 | |
Yipeng Cao | 282b594 | 2017-05-17 20:31:39 -0700 | [diff] [blame] | 1640 | mLastFixTime = SystemClock.elapsedRealtime(); |
Hakan Gustavsson | fa94ff0 | 2010-02-23 09:12:38 +0100 | [diff] [blame] | 1641 | // report time to first fix |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 1642 | if (mTimeToFirstFix == 0 && hasLatLong) { |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1643 | mTimeToFirstFix = (int) (mLastFixTime - mFixRequestTime); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1644 | if (DEBUG) Log.d(TAG, "TTFF: " + mTimeToFirstFix); |
Siddharth Ray | 53ddc80 | 2018-03-16 12:01:52 -0700 | [diff] [blame] | 1645 | if (mStarted) { |
| 1646 | mGnssMetrics.logTimeToFirstFixMilliSecs(mTimeToFirstFix); |
| 1647 | } |
Hakan Gustavsson | fa94ff0 | 2010-02-23 09:12:38 +0100 | [diff] [blame] | 1648 | |
| 1649 | // notify status listeners |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1650 | mListenerHelper.onFirstFix(mTimeToFirstFix); |
Hakan Gustavsson | fa94ff0 | 2010-02-23 09:12:38 +0100 | [diff] [blame] | 1651 | } |
| 1652 | |
Stan Chesnutt | 1d72d8c | 2013-04-15 19:18:02 -0700 | [diff] [blame] | 1653 | if (mSingleShot) { |
| 1654 | stopNavigating(); |
| 1655 | } |
| 1656 | |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 1657 | if (mStarted && mStatus != LocationProvider.AVAILABLE) { |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 1658 | // For devices that use framework scheduling, a timer may be set to ensure we don't |
| 1659 | // spend too much power searching for a location, when the requested update rate is slow. |
| 1660 | // As we just recievied a location, we'll cancel that timer. |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 1661 | if (!hasCapability(GPS_CAPABILITY_SCHEDULING) && mFixInterval < NO_FIX_TIMEOUT) { |
Mike Lockwood | b7be544 | 2010-02-24 14:34:50 -0500 | [diff] [blame] | 1662 | mAlarmManager.cancel(mTimeoutIntent); |
| 1663 | } |
| 1664 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1665 | // send an intent to notify that the GPS is receiving fixes. |
Mike Lockwood | 00b7427 | 2010-03-26 10:41:48 -0400 | [diff] [blame] | 1666 | Intent intent = new Intent(LocationManager.GPS_FIX_CHANGE_ACTION); |
| 1667 | intent.putExtra(LocationManager.EXTRA_GPS_ENABLED, true); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 1668 | mContext.sendBroadcastAsUser(intent, UserHandle.ALL); |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 1669 | updateStatus(LocationProvider.AVAILABLE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1670 | } |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 1671 | |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1672 | if (!hasCapability(GPS_CAPABILITY_SCHEDULING) && mStarted && |
| 1673 | mFixInterval > GPS_POLLING_THRESHOLD_INTERVAL) { |
Mike Lockwood | d53ba01 | 2010-04-15 20:41:26 -0400 | [diff] [blame] | 1674 | if (DEBUG) Log.d(TAG, "got fix, hibernating"); |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 1675 | hibernate(); |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 1676 | } |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1677 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1678 | |
| 1679 | /** |
| 1680 | * called from native code to update our status |
| 1681 | */ |
| 1682 | private void reportStatus(int status) { |
Mike Lockwood | b8d9033 | 2010-10-18 17:59:48 -0400 | [diff] [blame] | 1683 | if (DEBUG) Log.v(TAG, "reportStatus status: " + status); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1684 | |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1685 | boolean wasNavigating = mNavigating; |
| 1686 | switch (status) { |
| 1687 | case GPS_STATUS_SESSION_BEGIN: |
| 1688 | mNavigating = true; |
| 1689 | mEngineOn = true; |
| 1690 | break; |
| 1691 | case GPS_STATUS_SESSION_END: |
| 1692 | mNavigating = false; |
| 1693 | break; |
| 1694 | case GPS_STATUS_ENGINE_ON: |
| 1695 | mEngineOn = true; |
| 1696 | break; |
| 1697 | case GPS_STATUS_ENGINE_OFF: |
| 1698 | mEngineOn = false; |
| 1699 | mNavigating = false; |
| 1700 | break; |
| 1701 | } |
Mike Lockwood | dbd6fd8 | 2009-12-07 18:43:36 -0500 | [diff] [blame] | 1702 | |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1703 | if (wasNavigating != mNavigating) { |
destradaa | 13a60b0 | 2015-01-15 18:36:01 -0800 | [diff] [blame] | 1704 | mListenerHelper.onStatusChanged(mNavigating); |
Mike Lockwood | cf1d8cb | 2010-01-20 10:14:54 -0500 | [diff] [blame] | 1705 | |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1706 | // send an intent to notify that the GPS has been enabled or disabled |
| 1707 | Intent intent = new Intent(LocationManager.GPS_ENABLED_CHANGE_ACTION); |
| 1708 | intent.putExtra(LocationManager.EXTRA_GPS_ENABLED, mNavigating); |
| 1709 | mContext.sendBroadcastAsUser(intent, UserHandle.ALL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1710 | } |
| 1711 | } |
| 1712 | |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1713 | // Helper class to carry data to handler for reportSvStatus |
| 1714 | private static class SvStatusInfo { |
| 1715 | public int mSvCount; |
| 1716 | public int[] mSvidWithFlags; |
| 1717 | public float[] mCn0s; |
| 1718 | public float[] mSvElevations; |
| 1719 | public float[] mSvAzimuths; |
| 1720 | public float[] mSvCarrierFreqs; |
| 1721 | } |
| 1722 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1723 | /** |
| 1724 | * called from native code to update SV info |
| 1725 | */ |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1726 | private void reportSvStatus(int svCount, int[] svidWithFlags, float[] cn0s, |
| 1727 | float[] svElevations, float[] svAzimuths, float[] svCarrierFreqs) { |
| 1728 | SvStatusInfo svStatusInfo = new SvStatusInfo(); |
| 1729 | svStatusInfo.mSvCount = svCount; |
| 1730 | svStatusInfo.mSvidWithFlags = svidWithFlags; |
| 1731 | svStatusInfo.mCn0s = cn0s; |
| 1732 | svStatusInfo.mSvElevations = svElevations; |
| 1733 | svStatusInfo.mSvAzimuths = svAzimuths; |
| 1734 | svStatusInfo.mSvCarrierFreqs = svCarrierFreqs; |
| 1735 | |
| 1736 | sendMessage(REPORT_SV_STATUS, 0, svStatusInfo); |
| 1737 | } |
| 1738 | |
| 1739 | private void handleReportSvStatus(SvStatusInfo info) { |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1740 | mListenerHelper.onSvStatusChanged( |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1741 | info.mSvCount, |
| 1742 | info.mSvidWithFlags, |
| 1743 | info.mCn0s, |
| 1744 | info.mSvElevations, |
| 1745 | info.mSvAzimuths, |
| 1746 | info.mSvCarrierFreqs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1747 | |
Siddharth Ray | 168f12a | 2017-07-10 11:55:10 -0700 | [diff] [blame] | 1748 | // Log CN0 as part of GNSS metrics |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1749 | mGnssMetrics.logCn0(info.mCn0s, info.mSvCount); |
Siddharth Ray | 168f12a | 2017-07-10 11:55:10 -0700 | [diff] [blame] | 1750 | |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 1751 | if (VERBOSE) { |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1752 | Log.v(TAG, "SV count: " + info.mSvCount); |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1753 | } |
Wyatt Riley | c9f25dd | 2017-05-05 13:45:23 -0700 | [diff] [blame] | 1754 | // Calculate number of satellites used in fix. |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1755 | int usedInFixCount = 0; |
Wyatt Riley | c9f25dd | 2017-05-05 13:45:23 -0700 | [diff] [blame] | 1756 | int maxCn0 = 0; |
| 1757 | int meanCn0 = 0; |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1758 | for (int i = 0; i < info.mSvCount; i++) { |
| 1759 | if ((info.mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_USED_IN_FIX) != 0) { |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1760 | ++usedInFixCount; |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1761 | if (info.mCn0s[i] > maxCn0) { |
| 1762 | maxCn0 = (int) info.mCn0s[i]; |
Wyatt Riley | c9f25dd | 2017-05-05 13:45:23 -0700 | [diff] [blame] | 1763 | } |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1764 | meanCn0 += info.mCn0s[i]; |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1765 | } |
| 1766 | if (VERBOSE) { |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1767 | Log.v(TAG, "svid: " + (info.mSvidWithFlags[i] >> GnssStatus.SVID_SHIFT_WIDTH) + |
| 1768 | " cn0: " + info.mCn0s[i] + |
| 1769 | " elev: " + info.mSvElevations[i] + |
| 1770 | " azimuth: " + info.mSvAzimuths[i] + |
| 1771 | " carrier frequency: " + info.mSvCarrierFreqs[i] + |
| 1772 | ((info.mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_HAS_EPHEMERIS_DATA) == 0 |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1773 | ? " " : " E") + |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1774 | ((info.mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_HAS_ALMANAC_DATA) == 0 |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1775 | ? " " : " A") + |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1776 | ((info.mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_USED_IN_FIX) == 0 |
gomo | 4402af6 | 2017-01-11 13:20:13 -0800 | [diff] [blame] | 1777 | ? "" : "U") + |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1778 | ((info.mSvidWithFlags[i] & |
| 1779 | GnssStatus.GNSS_SV_FLAGS_HAS_CARRIER_FREQUENCY) == 0 |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1780 | ? "" : "F")); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1781 | } |
| 1782 | } |
Wyatt Riley | c9f25dd | 2017-05-05 13:45:23 -0700 | [diff] [blame] | 1783 | if (usedInFixCount > 0) { |
| 1784 | meanCn0 /= usedInFixCount; |
| 1785 | } |
| 1786 | // return number of sats used in fix instead of total reported |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 1787 | mLocationExtras.set(usedInFixCount, meanCn0, maxCn0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1788 | |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 1789 | if (mNavigating && mStatus == LocationProvider.AVAILABLE && mLastFixTime > 0 && |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1790 | SystemClock.elapsedRealtime() - mLastFixTime > RECENT_FIX_TIMEOUT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1791 | // 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] | 1792 | Intent intent = new Intent(LocationManager.GPS_FIX_CHANGE_ACTION); |
| 1793 | intent.putExtra(LocationManager.EXTRA_GPS_ENABLED, false); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 1794 | mContext.sendBroadcastAsUser(intent, UserHandle.ALL); |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 1795 | updateStatus(LocationProvider.TEMPORARILY_UNAVAILABLE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1796 | } |
| 1797 | } |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 1798 | |
| 1799 | /** |
Mike Lockwood | e3635c9 | 2009-05-11 08:38:02 -0400 | [diff] [blame] | 1800 | * called from native code to update AGPS status |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 1801 | */ |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 1802 | private void reportAGpsStatus(int type, int status, byte[] ipaddr) { |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 1803 | switch (status) { |
Mike Lockwood | e3635c9 | 2009-05-11 08:38:02 -0400 | [diff] [blame] | 1804 | case GPS_REQUEST_AGPS_DATA_CONN: |
Mike Lockwood | b6e5fa8 | 2010-10-09 20:10:46 -0400 | [diff] [blame] | 1805 | if (DEBUG) Log.d(TAG, "GPS_REQUEST_AGPS_DATA_CONN"); |
Andreas Gampe | e6748ce | 2015-12-11 18:00:38 -0800 | [diff] [blame] | 1806 | Log.v(TAG, "Received SUPL IP addr[]: " + Arrays.toString(ipaddr)); |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 1807 | InetAddress connectionIpAddress = null; |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 1808 | if (ipaddr != null) { |
| 1809 | try { |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 1810 | connectionIpAddress = InetAddress.getByAddress(ipaddr); |
| 1811 | if (DEBUG) Log.d(TAG, "IP address converted to: " + connectionIpAddress); |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 1812 | } catch (UnknownHostException e) { |
| 1813 | Log.e(TAG, "Bad IP Address: " + ipaddr, e); |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 1814 | } |
| 1815 | } |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 1816 | sendMessage(REQUEST_SUPL_CONNECTION, 0 /*arg*/, connectionIpAddress); |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 1817 | break; |
Mike Lockwood | e3635c9 | 2009-05-11 08:38:02 -0400 | [diff] [blame] | 1818 | case GPS_RELEASE_AGPS_DATA_CONN: |
Mike Lockwood | b6e5fa8 | 2010-10-09 20:10:46 -0400 | [diff] [blame] | 1819 | if (DEBUG) Log.d(TAG, "GPS_RELEASE_AGPS_DATA_CONN"); |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 1820 | releaseSuplConnection(GPS_RELEASE_AGPS_DATA_CONN); |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 1821 | break; |
Mike Lockwood | e3635c9 | 2009-05-11 08:38:02 -0400 | [diff] [blame] | 1822 | case GPS_AGPS_DATA_CONNECTED: |
Mike Lockwood | b6e5fa8 | 2010-10-09 20:10:46 -0400 | [diff] [blame] | 1823 | if (DEBUG) Log.d(TAG, "GPS_AGPS_DATA_CONNECTED"); |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 1824 | break; |
Mike Lockwood | e3635c9 | 2009-05-11 08:38:02 -0400 | [diff] [blame] | 1825 | case GPS_AGPS_DATA_CONN_DONE: |
Mike Lockwood | b6e5fa8 | 2010-10-09 20:10:46 -0400 | [diff] [blame] | 1826 | if (DEBUG) Log.d(TAG, "GPS_AGPS_DATA_CONN_DONE"); |
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_AGPS_DATA_CONN_FAILED: |
Mike Lockwood | b6e5fa8 | 2010-10-09 20:10:46 -0400 | [diff] [blame] | 1829 | if (DEBUG) Log.d(TAG, "GPS_AGPS_DATA_CONN_FAILED"); |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 1830 | break; |
destradaa | 931a37f | 2014-08-12 16:36:59 -0700 | [diff] [blame] | 1831 | default: |
Joe Onorato | 0c48410 | 2016-02-01 18:04:24 -0800 | [diff] [blame] | 1832 | if (DEBUG) Log.d(TAG, "Received Unknown AGPS status: " + status); |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 1833 | } |
| 1834 | } |
| 1835 | |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 1836 | private void releaseSuplConnection(int connStatus) { |
| 1837 | sendMessage(RELEASE_SUPL_CONNECTION, connStatus, null /*obj*/); |
| 1838 | } |
| 1839 | |
Mike Lockwood | b16e780 | 2009-08-06 09:26:02 -0400 | [diff] [blame] | 1840 | /** |
| 1841 | * called from native code to report NMEA data received |
| 1842 | */ |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 1843 | private void reportNmea(long timestamp) { |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1844 | if (!mItarSpeedLimitExceeded) { |
| 1845 | int length = native_read_nmea(mNmeaBuffer, mNmeaBuffer.length); |
| 1846 | String nmea = new String(mNmeaBuffer, 0 /* offset */, length); |
| 1847 | mListenerHelper.onNmeaReceived(timestamp, nmea); |
| 1848 | } |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1849 | } |
Mike Lockwood | b16e780 | 2009-08-06 09:26:02 -0400 | [diff] [blame] | 1850 | |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1851 | /** |
Wyatt Riley | aa420d5 | 2017-07-03 15:14:42 -0700 | [diff] [blame] | 1852 | * called from native code - GNSS measurements callback |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1853 | */ |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 1854 | private void reportMeasurementData(GnssMeasurementsEvent event) { |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1855 | if (!mItarSpeedLimitExceeded) { |
Wyatt Riley | aa420d5 | 2017-07-03 15:14:42 -0700 | [diff] [blame] | 1856 | // send to handler to allow native to return quickly |
| 1857 | mHandler.post(new Runnable() { |
| 1858 | @Override |
| 1859 | public void run() { |
| 1860 | mGnssMeasurementsProvider.onMeasurementsAvailable(event); |
| 1861 | } |
| 1862 | }); |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1863 | } |
Mike Lockwood | b16e780 | 2009-08-06 09:26:02 -0400 | [diff] [blame] | 1864 | } |
| 1865 | |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 1866 | /** |
Wyatt Riley | aa420d5 | 2017-07-03 15:14:42 -0700 | [diff] [blame] | 1867 | * called from native code - GNSS navigation message callback |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1868 | */ |
Lifu Tang | e8abe8e | 2016-04-01 10:32:05 -0700 | [diff] [blame] | 1869 | private void reportNavigationMessage(GnssNavigationMessage event) { |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1870 | if (!mItarSpeedLimitExceeded) { |
Wyatt Riley | aa420d5 | 2017-07-03 15:14:42 -0700 | [diff] [blame] | 1871 | // send to handler to allow native to return quickly |
| 1872 | mHandler.post(new Runnable() { |
| 1873 | @Override |
| 1874 | public void run() { |
| 1875 | mGnssNavigationMessageProvider.onNavigationMessageAvailable(event); |
| 1876 | } |
| 1877 | }); |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1878 | } |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1879 | } |
| 1880 | |
| 1881 | /** |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 1882 | * called from native code to inform us what the GPS engine capabilities are |
| 1883 | */ |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1884 | private void setEngineCapabilities(final int capabilities) { |
| 1885 | // send to handler thread for fast native return, and in-order handling |
| 1886 | mHandler.post(new Runnable() { |
| 1887 | @Override |
| 1888 | public void run() { |
| 1889 | mEngineCapabilities = capabilities; |
Mike Lockwood | 9b9fb5c | 2011-06-29 15:09:40 -0400 | [diff] [blame] | 1890 | |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1891 | if (hasCapability(GPS_CAPABILITY_ON_DEMAND_TIME)) { |
Yu-Han Yang | a1862b5 | 2018-02-20 17:05:59 -0800 | [diff] [blame] | 1892 | mNtpTimeHelper.enablePeriodicTimeInjection(); |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1893 | requestUtcTime(); |
| 1894 | } |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 1895 | |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1896 | mGnssMeasurementsProvider.onCapabilitiesUpdated(hasCapability( |
| 1897 | GPS_CAPABILITY_MEASUREMENTS)); |
| 1898 | mGnssNavigationMessageProvider.onCapabilitiesUpdated(hasCapability( |
| 1899 | GPS_CAPABILITY_NAV_MESSAGES)); |
Yu-Han Yang | 5205762 | 2018-04-25 00:51:22 -0700 | [diff] [blame] | 1900 | restartRequests(); |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1901 | } |
| 1902 | }); |
Yu-Han Yang | 5205762 | 2018-04-25 00:51:22 -0700 | [diff] [blame] | 1903 | } |
| 1904 | |
| 1905 | private void restartRequests() { |
| 1906 | Log.i(TAG, "restartRequests"); |
| 1907 | |
| 1908 | restartLocationRequest(); |
| 1909 | mGnssMeasurementsProvider.resumeIfStarted(); |
| 1910 | mGnssNavigationMessageProvider.resumeIfStarted(); |
| 1911 | mGnssBatchingProvider.resumeIfStarted(); |
| 1912 | mGnssGeofenceProvider.resumeIfStarted(); |
| 1913 | } |
| 1914 | |
| 1915 | private void restartLocationRequest() { |
| 1916 | if (DEBUG) Log.d(TAG, "restartLocationRequest"); |
| 1917 | mStarted = false; |
| 1918 | updateRequirements(); |
| 1919 | } |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1920 | |
| 1921 | /** |
| 1922 | * Called from native code to inform us the hardware year. |
| 1923 | */ |
| 1924 | private void setGnssYearOfHardware(final int yearOfHardware) { |
| 1925 | // mHardwareYear is simply set here, to be read elsewhere, and is volatile for safe sync |
| 1926 | if (DEBUG) Log.d(TAG, "setGnssYearOfHardware called with " + yearOfHardware); |
| 1927 | mHardwareYear = yearOfHardware; |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 1928 | } |
| 1929 | |
| 1930 | /** |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1931 | * Called from native code to inform us the hardware model name. |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 1932 | */ |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1933 | private void setGnssHardwareModelName(final String modelName) { |
| 1934 | // mHardwareModelName is simply set here, to be read elsewhere, and volatile for safe sync |
| 1935 | if (DEBUG) Log.d(TAG, "setGnssModelName called with " + modelName); |
| 1936 | mHardwareModelName = modelName; |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 1937 | } |
| 1938 | |
Yu-Han Yang | 5205762 | 2018-04-25 00:51:22 -0700 | [diff] [blame] | 1939 | /** |
| 1940 | * Called from native code to inform us GNSS HAL service died. |
| 1941 | */ |
| 1942 | private void reportGnssServiceDied() { |
| 1943 | if (DEBUG) Log.d(TAG, "reportGnssServiceDied"); |
| 1944 | mHandler.post(() -> { |
| 1945 | class_init_native(); |
| 1946 | native_init_once(); |
| 1947 | if (isEnabled()) { |
| 1948 | // re-calls native_init() and other setup. |
| 1949 | handleEnable(); |
| 1950 | // resend configuration into the restarted HAL service. |
| 1951 | reloadGpsProperties(mContext, mProperties); |
| 1952 | } |
| 1953 | }); |
| 1954 | } |
| 1955 | |
Lifu Tang | 9363b94 | 2016-02-16 18:07:00 -0800 | [diff] [blame] | 1956 | public interface GnssSystemInfoProvider { |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 1957 | /** |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1958 | * Returns the year of underlying GPS hardware. |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 1959 | */ |
Lifu Tang | 9363b94 | 2016-02-16 18:07:00 -0800 | [diff] [blame] | 1960 | int getGnssYearOfHardware(); |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1961 | /** |
| 1962 | * Returns the model name of underlying GPS hardware. |
| 1963 | */ |
| 1964 | String getGnssHardwareModelName(); |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | /** |
| 1968 | * @hide |
| 1969 | */ |
Lifu Tang | 9363b94 | 2016-02-16 18:07:00 -0800 | [diff] [blame] | 1970 | public GnssSystemInfoProvider getGnssSystemInfoProvider() { |
| 1971 | return new GnssSystemInfoProvider() { |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 1972 | @Override |
Lifu Tang | 9363b94 | 2016-02-16 18:07:00 -0800 | [diff] [blame] | 1973 | public int getGnssYearOfHardware() { |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1974 | return mHardwareYear; |
| 1975 | } |
| 1976 | @Override |
| 1977 | public String getGnssHardwareModelName() { |
| 1978 | return mHardwareModelName; |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 1979 | } |
| 1980 | }; |
| 1981 | } |
| 1982 | |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1983 | /** |
| 1984 | * @hide |
| 1985 | */ |
| 1986 | public GnssBatchingProvider getGnssBatchingProvider() { |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 1987 | return mGnssBatchingProvider; |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1988 | } |
| 1989 | |
Siddharth Ray | bb608c8 | 2017-03-16 11:33:34 -0700 | [diff] [blame] | 1990 | public interface GnssMetricsProvider { |
| 1991 | /** |
| 1992 | * Returns GNSS metrics as proto string |
| 1993 | */ |
| 1994 | String getGnssMetricsAsProtoString(); |
| 1995 | } |
| 1996 | |
| 1997 | /** |
| 1998 | * @hide |
| 1999 | */ |
| 2000 | public GnssMetricsProvider getGnssMetricsProvider() { |
| 2001 | return new GnssMetricsProvider() { |
| 2002 | @Override |
| 2003 | public String getGnssMetricsAsProtoString() { |
| 2004 | return mGnssMetrics.dumpGnssMetricsAsProtoString(); |
| 2005 | } |
| 2006 | }; |
| 2007 | } |
| 2008 | |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2009 | /** |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2010 | * called from native code - GNSS location batch callback |
| 2011 | */ |
| 2012 | private void reportLocationBatch(Location[] locationArray) { |
| 2013 | List<Location> locations = new ArrayList<>(Arrays.asList(locationArray)); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2014 | if (DEBUG) { |
| 2015 | Log.d(TAG, "Location batch of size " + locationArray.length + " reported"); |
| 2016 | } |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2017 | try { |
| 2018 | mILocationManager.reportLocationBatch(locations); |
| 2019 | } catch (RemoteException e) { |
| 2020 | Log.e(TAG, "RemoteException calling reportLocationBatch"); |
| 2021 | } |
| 2022 | } |
| 2023 | |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 2024 | /** |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 2025 | * called from native code to request XTRA data |
| 2026 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2027 | private void xtraDownloadRequest() { |
Joe Onorato | f5d95cb | 2010-01-07 21:48:32 -0500 | [diff] [blame] | 2028 | if (DEBUG) Log.d(TAG, "xtraDownloadRequest"); |
Mike Lockwood | 98e4869 | 2010-04-07 16:32:51 -0400 | [diff] [blame] | 2029 | sendMessage(DOWNLOAD_XTRA_DATA, 0, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2030 | } |
| 2031 | |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 2032 | /** |
destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 2033 | * Converts the GPS HAL status to the internal Geofence Hardware status. |
| 2034 | */ |
| 2035 | private int getGeofenceStatus(int status) { |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2036 | switch (status) { |
destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 2037 | case GPS_GEOFENCE_OPERATION_SUCCESS: |
| 2038 | return GeofenceHardware.GEOFENCE_SUCCESS; |
| 2039 | case GPS_GEOFENCE_ERROR_GENERIC: |
| 2040 | return GeofenceHardware.GEOFENCE_FAILURE; |
| 2041 | case GPS_GEOFENCE_ERROR_ID_EXISTS: |
| 2042 | return GeofenceHardware.GEOFENCE_ERROR_ID_EXISTS; |
| 2043 | case GPS_GEOFENCE_ERROR_INVALID_TRANSITION: |
| 2044 | return GeofenceHardware.GEOFENCE_ERROR_INVALID_TRANSITION; |
| 2045 | case GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES: |
| 2046 | return GeofenceHardware.GEOFENCE_ERROR_TOO_MANY_GEOFENCES; |
| 2047 | case GPS_GEOFENCE_ERROR_ID_UNKNOWN: |
| 2048 | return GeofenceHardware.GEOFENCE_ERROR_ID_UNKNOWN; |
| 2049 | default: |
| 2050 | return -1; |
| 2051 | } |
| 2052 | } |
| 2053 | |
| 2054 | /** |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 2055 | * Called from native to report GPS Geofence transition |
| 2056 | * All geofence callbacks are called on the same thread |
| 2057 | */ |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 2058 | private void reportGeofenceTransition(int geofenceId, Location location, int transition, |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2059 | long transitionTimestamp) { |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 2060 | if (mGeofenceHardwareImpl == null) { |
| 2061 | mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext); |
| 2062 | } |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 2063 | |
destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 2064 | mGeofenceHardwareImpl.reportGeofenceTransition( |
| 2065 | geofenceId, |
| 2066 | location, |
| 2067 | transition, |
| 2068 | transitionTimestamp, |
| 2069 | GeofenceHardware.MONITORING_TYPE_GPS_HARDWARE, |
| 2070 | FusedBatchOptions.SourceTechnologies.GNSS); |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 2071 | } |
| 2072 | |
| 2073 | /** |
| 2074 | * called from native code to report GPS status change. |
| 2075 | */ |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 2076 | private void reportGeofenceStatus(int status, Location location) { |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 2077 | if (mGeofenceHardwareImpl == null) { |
| 2078 | mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext); |
| 2079 | } |
destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 2080 | int monitorStatus = GeofenceHardware.MONITOR_CURRENTLY_UNAVAILABLE; |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2081 | if (status == GPS_GEOFENCE_AVAILABLE) { |
destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 2082 | monitorStatus = GeofenceHardware.MONITOR_CURRENTLY_AVAILABLE; |
| 2083 | } |
| 2084 | mGeofenceHardwareImpl.reportGeofenceMonitorStatus( |
| 2085 | GeofenceHardware.MONITORING_TYPE_GPS_HARDWARE, |
| 2086 | monitorStatus, |
| 2087 | location, |
| 2088 | FusedBatchOptions.SourceTechnologies.GNSS); |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 2089 | } |
| 2090 | |
| 2091 | /** |
| 2092 | * called from native code - Geofence Add callback |
| 2093 | */ |
| 2094 | private void reportGeofenceAddStatus(int geofenceId, int status) { |
| 2095 | if (mGeofenceHardwareImpl == null) { |
| 2096 | mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext); |
| 2097 | } |
destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 2098 | mGeofenceHardwareImpl.reportGeofenceAddStatus(geofenceId, getGeofenceStatus(status)); |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 2099 | } |
| 2100 | |
| 2101 | /** |
| 2102 | * called from native code - Geofence Remove callback |
| 2103 | */ |
| 2104 | private void reportGeofenceRemoveStatus(int geofenceId, int status) { |
| 2105 | if (mGeofenceHardwareImpl == null) { |
| 2106 | mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext); |
| 2107 | } |
destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 2108 | mGeofenceHardwareImpl.reportGeofenceRemoveStatus(geofenceId, getGeofenceStatus(status)); |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 2109 | } |
| 2110 | |
| 2111 | /** |
| 2112 | * called from native code - Geofence Pause callback |
| 2113 | */ |
| 2114 | private void reportGeofencePauseStatus(int geofenceId, int status) { |
| 2115 | if (mGeofenceHardwareImpl == null) { |
| 2116 | mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext); |
| 2117 | } |
destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 2118 | mGeofenceHardwareImpl.reportGeofencePauseStatus(geofenceId, getGeofenceStatus(status)); |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 2119 | } |
| 2120 | |
| 2121 | /** |
| 2122 | * called from native code - Geofence Resume callback |
| 2123 | */ |
| 2124 | private void reportGeofenceResumeStatus(int geofenceId, int status) { |
| 2125 | if (mGeofenceHardwareImpl == null) { |
| 2126 | mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext); |
| 2127 | } |
destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 2128 | mGeofenceHardwareImpl.reportGeofenceResumeStatus(geofenceId, getGeofenceStatus(status)); |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 2129 | } |
| 2130 | |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 2131 | //============================================================= |
| 2132 | // NI Client support |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 2133 | //============================================================= |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 2134 | private final INetInitiatedListener mNetInitiatedListener = new INetInitiatedListener.Stub() { |
destradaa | ef752b6 | 2015-04-17 13:10:47 -0700 | [diff] [blame] | 2135 | // Sends a response for an NI request to HAL. |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2136 | @Override |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2137 | public boolean sendNiResponse(int notificationId, int userResponse) { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 2138 | // TODO Add Permission check |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 2139 | |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2140 | if (DEBUG) { |
| 2141 | Log.d(TAG, "sendNiResponse, notifId: " + notificationId + |
| 2142 | ", response: " + userResponse); |
| 2143 | } |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 2144 | native_send_ni_response(notificationId, userResponse); |
| 2145 | return true; |
| 2146 | } |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 2147 | }; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2148 | |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 2149 | public INetInitiatedListener getNetInitiatedListener() { |
| 2150 | return mNetInitiatedListener; |
| 2151 | } |
| 2152 | |
| 2153 | // Called by JNI function to report an NI request. |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 2154 | public void reportNiNotification( |
| 2155 | int notificationId, |
| 2156 | int niType, |
| 2157 | int notifyFlags, |
| 2158 | int timeout, |
| 2159 | int defaultResponse, |
| 2160 | String requestorId, |
| 2161 | String text, |
| 2162 | int requestorIdEncoding, |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2163 | int textEncoding |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2164 | ) { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 2165 | Log.i(TAG, "reportNiNotification: entered"); |
| 2166 | Log.i(TAG, "notificationId: " + notificationId + |
| 2167 | ", niType: " + niType + |
| 2168 | ", notifyFlags: " + notifyFlags + |
| 2169 | ", timeout: " + timeout + |
| 2170 | ", defaultResponse: " + defaultResponse); |
| 2171 | |
| 2172 | Log.i(TAG, "requestorId: " + requestorId + |
| 2173 | ", text: " + text + |
| 2174 | ", requestorIdEncoding: " + requestorIdEncoding + |
| 2175 | ", textEncoding: " + textEncoding); |
| 2176 | |
| 2177 | GpsNiNotification notification = new GpsNiNotification(); |
| 2178 | |
| 2179 | notification.notificationId = notificationId; |
| 2180 | notification.niType = niType; |
| 2181 | notification.needNotify = (notifyFlags & GpsNetInitiatedHandler.GPS_NI_NEED_NOTIFY) != 0; |
| 2182 | notification.needVerify = (notifyFlags & GpsNetInitiatedHandler.GPS_NI_NEED_VERIFY) != 0; |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2183 | notification.privacyOverride = |
| 2184 | (notifyFlags & GpsNetInitiatedHandler.GPS_NI_PRIVACY_OVERRIDE) != 0; |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 2185 | notification.timeout = timeout; |
| 2186 | notification.defaultResponse = defaultResponse; |
| 2187 | notification.requestorId = requestorId; |
| 2188 | notification.text = text; |
| 2189 | notification.requestorIdEncoding = requestorIdEncoding; |
| 2190 | notification.textEncoding = textEncoding; |
| 2191 | |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 2192 | mNIHandler.handleNiNotification(notification); |
| 2193 | } |
| 2194 | |
| 2195 | /** |
| 2196 | * Called from native code to request set id info. |
| 2197 | * We should be careful about receiving null string from the TelephonyManager, |
| 2198 | * because sending null String to JNI function would cause a crash. |
| 2199 | */ |
| 2200 | |
| 2201 | private void requestSetID(int flags) { |
| 2202 | TelephonyManager phone = (TelephonyManager) |
| 2203 | mContext.getSystemService(Context.TELEPHONY_SERVICE); |
destradaa | ef752b6 | 2015-04-17 13:10:47 -0700 | [diff] [blame] | 2204 | int type = AGPS_SETID_TYPE_NONE; |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 2205 | String data = ""; |
| 2206 | |
| 2207 | if ((flags & AGPS_RIL_REQUEST_SETID_IMSI) == AGPS_RIL_REQUEST_SETID_IMSI) { |
| 2208 | String data_temp = phone.getSubscriberId(); |
| 2209 | if (data_temp == null) { |
| 2210 | // This means the framework does not have the SIM card ready. |
| 2211 | } else { |
| 2212 | // This means the framework has the SIM card. |
| 2213 | data = data_temp; |
| 2214 | type = AGPS_SETID_TYPE_IMSI; |
| 2215 | } |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2216 | } 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] | 2217 | String data_temp = phone.getLine1Number(); |
| 2218 | if (data_temp == null) { |
| 2219 | // This means the framework does not have the SIM card ready. |
| 2220 | } else { |
| 2221 | // This means the framework has the SIM card. |
| 2222 | data = data_temp; |
| 2223 | type = AGPS_SETID_TYPE_MSISDN; |
| 2224 | } |
| 2225 | } |
| 2226 | native_agps_set_id(type, data); |
| 2227 | } |
| 2228 | |
| 2229 | /** |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 2230 | * Called from native code to request location info. |
| 2231 | */ |
| 2232 | private void requestLocation(boolean independentFromGnss) { |
| 2233 | if (DEBUG) { |
| 2234 | Log.d(TAG, "requestLocation. independentFromGnss: " + independentFromGnss); |
| 2235 | } |
| 2236 | sendMessage(REQUEST_LOCATION, 0, independentFromGnss); |
| 2237 | } |
| 2238 | |
| 2239 | /** |
Mike Lockwood | 9b9fb5c | 2011-06-29 15:09:40 -0400 | [diff] [blame] | 2240 | * Called from native code to request utc time info |
| 2241 | */ |
Mike Lockwood | 9b9fb5c | 2011-06-29 15:09:40 -0400 | [diff] [blame] | 2242 | private void requestUtcTime() { |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 2243 | if (DEBUG) Log.d(TAG, "utcTimeRequest"); |
Mike Lockwood | 9b9fb5c | 2011-06-29 15:09:40 -0400 | [diff] [blame] | 2244 | sendMessage(INJECT_NTP_TIME, 0, null); |
| 2245 | } |
| 2246 | |
| 2247 | /** |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 2248 | * Called from native code to request reference location info |
| 2249 | */ |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2250 | private void requestRefLocation() { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 2251 | TelephonyManager phone = (TelephonyManager) |
| 2252 | mContext.getSystemService(Context.TELEPHONY_SERVICE); |
Victoria Lease | d50d0c3 | 2012-10-29 13:16:17 -0700 | [diff] [blame] | 2253 | final int phoneType = phone.getPhoneType(); |
| 2254 | if (phoneType == TelephonyManager.PHONE_TYPE_GSM) { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 2255 | GsmCellLocation gsm_cell = (GsmCellLocation) phone.getCellLocation(); |
Victoria Lease | d50d0c3 | 2012-10-29 13:16:17 -0700 | [diff] [blame] | 2256 | if ((gsm_cell != null) && (phone.getNetworkOperator() != null) |
| 2257 | && (phone.getNetworkOperator().length() > 3)) { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 2258 | int type; |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2259 | int mcc = Integer.parseInt(phone.getNetworkOperator().substring(0, 3)); |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 2260 | int mnc = Integer.parseInt(phone.getNetworkOperator().substring(3)); |
Mike Lockwood | edc0f387 | 2010-10-22 09:16:17 -0400 | [diff] [blame] | 2261 | int networkType = phone.getNetworkType(); |
| 2262 | if (networkType == TelephonyManager.NETWORK_TYPE_UMTS |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2263 | || networkType == TelephonyManager.NETWORK_TYPE_HSDPA |
| 2264 | || networkType == TelephonyManager.NETWORK_TYPE_HSUPA |
| 2265 | || networkType == TelephonyManager.NETWORK_TYPE_HSPA |
| 2266 | || networkType == TelephonyManager.NETWORK_TYPE_HSPAP) { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 2267 | type = AGPS_REF_LOCATION_TYPE_UMTS_CELLID; |
Mike Lockwood | edc0f387 | 2010-10-22 09:16:17 -0400 | [diff] [blame] | 2268 | } else { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 2269 | type = AGPS_REF_LOCATION_TYPE_GSM_CELLID; |
Mike Lockwood | edc0f387 | 2010-10-22 09:16:17 -0400 | [diff] [blame] | 2270 | } |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 2271 | native_agps_set_ref_location_cellid(type, mcc, mnc, |
| 2272 | gsm_cell.getLac(), gsm_cell.getCid()); |
Mike Lockwood | edc0f387 | 2010-10-22 09:16:17 -0400 | [diff] [blame] | 2273 | } else { |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2274 | Log.e(TAG, "Error getting cell location info."); |
Mike Lockwood | edc0f387 | 2010-10-22 09:16:17 -0400 | [diff] [blame] | 2275 | } |
Victoria Lease | d50d0c3 | 2012-10-29 13:16:17 -0700 | [diff] [blame] | 2276 | } else if (phoneType == TelephonyManager.PHONE_TYPE_CDMA) { |
| 2277 | Log.e(TAG, "CDMA not supported."); |
Mike Lockwood | edc0f387 | 2010-10-22 09:16:17 -0400 | [diff] [blame] | 2278 | } |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 2279 | } |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 2280 | |
Mike Lockwood | 98e4869 | 2010-04-07 16:32:51 -0400 | [diff] [blame] | 2281 | private void sendMessage(int message, int arg, Object obj) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2282 | // hold a wake lock until this message is delivered |
Jeff Brown | 028872f | 2012-08-25 13:07:01 -0700 | [diff] [blame] | 2283 | // note that this assumes the message will not be removed from the queue before |
| 2284 | // it is handled (otherwise the wake lock would be leaked). |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2285 | mWakeLock.acquire(); |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2286 | if (Log.isLoggable(TAG, Log.INFO)) { |
| 2287 | Log.i(TAG, "WakeLock acquired by sendMessage(" + messageIdAsString(message) + ", " + arg |
| 2288 | + ", " + obj + ")"); |
| 2289 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2290 | mHandler.obtainMessage(message, arg, 1, obj).sendToTarget(); |
Mike Lockwood | 98e4869 | 2010-04-07 16:32:51 -0400 | [diff] [blame] | 2291 | } |
| 2292 | |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 2293 | private final class ProviderHandler extends Handler { |
Victoria Lease | 5cd731a | 2012-12-19 15:04:21 -0800 | [diff] [blame] | 2294 | public ProviderHandler(Looper looper) { |
| 2295 | super(looper, null, true /*async*/); |
Jeff Brown | 028872f | 2012-08-25 13:07:01 -0700 | [diff] [blame] | 2296 | } |
| 2297 | |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 2298 | @Override |
Mike Lockwood | 4a7b65e | 2010-10-25 16:35:55 -0400 | [diff] [blame] | 2299 | public void handleMessage(Message msg) { |
Mike Lockwood | 98e4869 | 2010-04-07 16:32:51 -0400 | [diff] [blame] | 2300 | int message = msg.what; |
| 2301 | switch (message) { |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 2302 | case ENABLE: |
| 2303 | if (msg.arg1 == 1) { |
| 2304 | handleEnable(); |
| 2305 | } else { |
| 2306 | handleDisable(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2307 | } |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 2308 | break; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2309 | case SET_REQUEST: |
| 2310 | GpsRequest gpsRequest = (GpsRequest) msg.obj; |
| 2311 | handleSetRequest(gpsRequest.request, gpsRequest.source); |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 2312 | break; |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 2313 | case UPDATE_NETWORK_STATE: |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 2314 | handleUpdateNetworkState((Network) msg.obj); |
| 2315 | break; |
| 2316 | case REQUEST_SUPL_CONNECTION: |
| 2317 | handleRequestSuplConnection((InetAddress) msg.obj); |
| 2318 | break; |
| 2319 | case RELEASE_SUPL_CONNECTION: |
| 2320 | handleReleaseSuplConnection(msg.arg1); |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 2321 | break; |
| 2322 | case INJECT_NTP_TIME: |
Yu-Han Yang | a1862b5 | 2018-02-20 17:05:59 -0800 | [diff] [blame] | 2323 | mNtpTimeHelper.retrieveAndInjectNtpTime(); |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 2324 | break; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 2325 | case REQUEST_LOCATION: |
| 2326 | handleRequestLocation((boolean) msg.obj); |
| 2327 | break; |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 2328 | case DOWNLOAD_XTRA_DATA: |
Wyatt Riley | 0d6e54e2 | 2016-10-05 12:03:03 -0700 | [diff] [blame] | 2329 | handleDownloadXtraData(); |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 2330 | break; |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 2331 | case DOWNLOAD_XTRA_DATA_FINISHED: |
| 2332 | mDownloadXtraDataPending = STATE_IDLE; |
| 2333 | break; |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 2334 | case UPDATE_LOCATION: |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 2335 | handleUpdateLocation((Location) msg.obj); |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 2336 | break; |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2337 | case SUBSCRIPTION_OR_SIM_CHANGED: |
| 2338 | subscriptionOrSimChanged(mContext); |
| 2339 | break; |
| 2340 | case INITIALIZE_HANDLER: |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 2341 | handleInitialize(); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2342 | break; |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 2343 | case REPORT_LOCATION: |
| 2344 | handleReportLocation(msg.arg1 == 1, (Location) msg.obj); |
| 2345 | break; |
| 2346 | case REPORT_SV_STATUS: |
| 2347 | handleReportSvStatus((SvStatusInfo) msg.obj); |
| 2348 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2349 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2350 | if (msg.arg2 == 1) { |
| 2351 | // wakelock was taken for this message, release it |
| 2352 | mWakeLock.release(); |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2353 | if (Log.isLoggable(TAG, Log.INFO)) { |
| 2354 | Log.i(TAG, "WakeLock released by handleMessage(" + messageIdAsString(message) |
| 2355 | + ", " + msg.arg1 + ", " + msg.obj + ")"); |
| 2356 | } |
Mike Lockwood | 98e4869 | 2010-04-07 16:32:51 -0400 | [diff] [blame] | 2357 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2358 | } |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2359 | |
| 2360 | /** |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 2361 | * This method is bound to {@link #GnssLocationProvider(Context, ILocationManager, Looper)}. |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2362 | * It is in charge of loading properties and registering for events that will be posted to |
| 2363 | * this handler. |
| 2364 | */ |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 2365 | private void handleInitialize() { |
Yu-Han Yang | 6d31735 | 2018-03-15 11:53:01 -0700 | [diff] [blame] | 2366 | native_init_once(); |
| 2367 | |
Wyatt Riley | 523a0cf | 2017-10-31 14:36:52 -0700 | [diff] [blame] | 2368 | /* |
| 2369 | * A cycle of native_init() and native_cleanup() is needed so that callbacks are |
| 2370 | * registered after bootup even when location is disabled. |
| 2371 | * This will allow Emergency SUPL to work even when location is disabled before device |
| 2372 | * restart. |
| 2373 | */ |
| 2374 | boolean isInitialized = native_init(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2375 | if (!isInitialized) { |
Wyatt Riley | 523a0cf | 2017-10-31 14:36:52 -0700 | [diff] [blame] | 2376 | Log.w(TAG, "Native initialization failed at bootup"); |
| 2377 | } else { |
| 2378 | native_cleanup(); |
| 2379 | } |
| 2380 | |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2381 | // load default GPS configuration |
| 2382 | // (this configuration might change in the future based on SIM changes) |
| 2383 | reloadGpsProperties(mContext, mProperties); |
| 2384 | |
| 2385 | // TODO: When this object "finishes" we should unregister by invoking |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2386 | // SubscriptionManager.getInstance(mContext).unregister |
| 2387 | // (mOnSubscriptionsChangedListener); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2388 | // This is not strictly necessary because it will be unregistered if the |
| 2389 | // notification fails but it is good form. |
| 2390 | |
| 2391 | // Register for SubscriptionInfo list changes which is guaranteed |
| 2392 | // to invoke onSubscriptionsChanged the first time. |
| 2393 | SubscriptionManager.from(mContext) |
| 2394 | .addOnSubscriptionsChangedListener(mOnSubscriptionsChangedListener); |
| 2395 | |
| 2396 | // listen for events |
destradaa | ef752b6 | 2015-04-17 13:10:47 -0700 | [diff] [blame] | 2397 | IntentFilter intentFilter; |
| 2398 | if (native_is_agps_ril_supported()) { |
| 2399 | intentFilter = new IntentFilter(); |
| 2400 | intentFilter.addAction(Intents.DATA_SMS_RECEIVED_ACTION); |
| 2401 | intentFilter.addDataScheme("sms"); |
| 2402 | intentFilter.addDataAuthority("localhost", "7275"); |
| 2403 | mContext.registerReceiver(mBroadcastReceiver, intentFilter, null, this); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2404 | |
destradaa | ef752b6 | 2015-04-17 13:10:47 -0700 | [diff] [blame] | 2405 | intentFilter = new IntentFilter(); |
| 2406 | intentFilter.addAction(Intents.WAP_PUSH_RECEIVED_ACTION); |
| 2407 | try { |
| 2408 | intentFilter.addDataType("application/vnd.omaloc-supl-init"); |
| 2409 | } catch (IntentFilter.MalformedMimeTypeException e) { |
| 2410 | Log.w(TAG, "Malformed SUPL init mime type"); |
| 2411 | } |
| 2412 | mContext.registerReceiver(mBroadcastReceiver, intentFilter, null, this); |
| 2413 | } else if (DEBUG) { |
| 2414 | Log.d(TAG, "Skipped registration for SMS/WAP-PUSH messages because AGPS Ril in GPS" |
| 2415 | + " HAL is not supported"); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2416 | } |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2417 | |
| 2418 | intentFilter = new IntentFilter(); |
| 2419 | intentFilter.addAction(ALARM_WAKEUP); |
| 2420 | intentFilter.addAction(ALARM_TIMEOUT); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2421 | intentFilter.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED); |
Adam Lesinski | 87c17df | 2015-05-27 13:24:13 -0700 | [diff] [blame] | 2422 | intentFilter.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2423 | intentFilter.addAction(Intent.ACTION_SCREEN_OFF); |
| 2424 | intentFilter.addAction(Intent.ACTION_SCREEN_ON); |
| 2425 | intentFilter.addAction(SIM_STATE_CHANGED); |
| 2426 | mContext.registerReceiver(mBroadcastReceiver, intentFilter, null, this); |
| 2427 | |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 2428 | // register for connectivity change events, this is equivalent to the deprecated way of |
| 2429 | // registering for CONNECTIVITY_ACTION broadcasts |
| 2430 | NetworkRequest.Builder networkRequestBuilder = new NetworkRequest.Builder(); |
Jeff Sharkey | c159d52 | 2018-03-28 10:54:07 -0600 | [diff] [blame] | 2431 | networkRequestBuilder.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET); |
| 2432 | networkRequestBuilder.addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED); |
| 2433 | networkRequestBuilder.removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN); |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 2434 | NetworkRequest networkRequest = networkRequestBuilder.build(); |
| 2435 | mConnMgr.registerNetworkCallback(networkRequest, mNetworkConnectivityCallback); |
| 2436 | |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2437 | // listen for PASSIVE_PROVIDER updates |
| 2438 | LocationManager locManager = |
| 2439 | (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); |
| 2440 | long minTime = 0; |
| 2441 | float minDistance = 0; |
| 2442 | boolean oneShot = false; |
| 2443 | LocationRequest request = LocationRequest.createFromDeprecatedProvider( |
| 2444 | LocationManager.PASSIVE_PROVIDER, |
| 2445 | minTime, |
| 2446 | minDistance, |
| 2447 | oneShot); |
| 2448 | // Don't keep track of this request since it's done on behalf of other clients |
| 2449 | // (which are kept track of separately). |
| 2450 | request.setHideFromAppOps(true); |
| 2451 | locManager.requestLocationUpdates( |
| 2452 | request, |
| 2453 | new NetworkLocationListener(), |
| 2454 | getLooper()); |
| 2455 | } |
| 2456 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2457 | |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 2458 | private abstract class LocationChangeListener implements LocationListener { |
Yu-Han Yang | 0756138 | 2018-02-21 13:08:37 -0800 | [diff] [blame] | 2459 | int numLocationUpdateRequest; |
| 2460 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2461 | @Override |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2462 | public void onStatusChanged(String provider, int status, Bundle extras) { |
| 2463 | } |
| 2464 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2465 | @Override |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2466 | public void onProviderEnabled(String provider) { |
| 2467 | } |
| 2468 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2469 | @Override |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2470 | public void onProviderDisabled(String provider) { |
| 2471 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2472 | } |
| 2473 | |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 2474 | private final class NetworkLocationListener extends LocationChangeListener { |
| 2475 | @Override |
| 2476 | public void onLocationChanged(Location location) { |
| 2477 | // this callback happens on mHandler looper |
| 2478 | if (LocationManager.NETWORK_PROVIDER.equals(location.getProvider())) { |
| 2479 | handleUpdateLocation(location); |
| 2480 | } |
| 2481 | } |
| 2482 | } |
| 2483 | |
| 2484 | private final class FusedLocationListener extends LocationChangeListener { |
| 2485 | @Override |
| 2486 | public void onLocationChanged(Location location) { |
| 2487 | if (LocationManager.FUSED_PROVIDER.equals(location.getProvider())) { |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 2488 | injectBestLocation(location); |
| 2489 | } |
| 2490 | } |
| 2491 | } |
| 2492 | |
Kevin Tang | a5fe6b2 | 2011-06-05 14:25:16 -0700 | [diff] [blame] | 2493 | private String getSelectedApn() { |
| 2494 | Uri uri = Uri.parse("content://telephony/carriers/preferapn"); |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 2495 | Cursor cursor = null; |
| 2496 | try { |
| 2497 | cursor = mContext.getContentResolver().query( |
| 2498 | uri, |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2499 | new String[]{"apn"}, |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 2500 | null /* selection */, |
| 2501 | null /* selectionArgs */, |
| 2502 | Carriers.DEFAULT_SORT_ORDER); |
| 2503 | if (cursor != null && cursor.moveToFirst()) { |
| 2504 | return cursor.getString(0); |
| 2505 | } else { |
| 2506 | Log.e(TAG, "No APN found to select."); |
| 2507 | } |
| 2508 | } catch (Exception e) { |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 2509 | Log.e(TAG, "Error encountered on selecting the APN.", e); |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 2510 | } finally { |
| 2511 | if (cursor != null) { |
Kevin Tang | a5fe6b2 | 2011-06-05 14:25:16 -0700 | [diff] [blame] | 2512 | cursor.close(); |
| 2513 | } |
| 2514 | } |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 2515 | |
| 2516 | return null; |
| 2517 | } |
| 2518 | |
| 2519 | private int getApnIpType(String apn) { |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 2520 | ensureInHandlerThread(); |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 2521 | if (apn == null) { |
| 2522 | return APN_INVALID; |
| 2523 | } |
| 2524 | |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 2525 | String selection = String.format("current = 1 and apn = '%s' and carrier_enabled = 1", apn); |
| 2526 | Cursor cursor = null; |
| 2527 | try { |
| 2528 | cursor = mContext.getContentResolver().query( |
| 2529 | Carriers.CONTENT_URI, |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2530 | new String[]{Carriers.PROTOCOL}, |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 2531 | selection, |
| 2532 | null, |
| 2533 | Carriers.DEFAULT_SORT_ORDER); |
| 2534 | |
| 2535 | if (null != cursor && cursor.moveToFirst()) { |
| 2536 | return translateToApnIpType(cursor.getString(0), apn); |
| 2537 | } else { |
| 2538 | Log.e(TAG, "No entry found in query for APN: " + apn); |
| 2539 | } |
| 2540 | } catch (Exception e) { |
| 2541 | Log.e(TAG, "Error encountered on APN query for: " + apn, e); |
| 2542 | } finally { |
| 2543 | if (cursor != null) { |
| 2544 | cursor.close(); |
| 2545 | } |
| 2546 | } |
| 2547 | |
| 2548 | return APN_INVALID; |
| 2549 | } |
| 2550 | |
| 2551 | private int translateToApnIpType(String ipProtocol, String apn) { |
| 2552 | if ("IP".equals(ipProtocol)) { |
| 2553 | return APN_IPV4; |
| 2554 | } |
| 2555 | if ("IPV6".equals(ipProtocol)) { |
| 2556 | return APN_IPV6; |
| 2557 | } |
| 2558 | if ("IPV4V6".equals(ipProtocol)) { |
| 2559 | return APN_IPV4V6; |
| 2560 | } |
| 2561 | |
| 2562 | // we hit the default case so the ipProtocol is not recognized |
| 2563 | String message = String.format("Unknown IP Protocol: %s, for APN: %s", ipProtocol, apn); |
| 2564 | Log.e(TAG, message); |
| 2565 | return APN_INVALID; |
| 2566 | } |
| 2567 | |
| 2568 | private void setRouting() { |
| 2569 | if (mAGpsDataConnectionIpAddr == null) { |
| 2570 | return; |
| 2571 | } |
| 2572 | |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 2573 | // TODO: replace the use of this deprecated API |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 2574 | boolean result = mConnMgr.requestRouteToHostAddress( |
| 2575 | ConnectivityManager.TYPE_MOBILE_SUPL, |
| 2576 | mAGpsDataConnectionIpAddr); |
| 2577 | |
| 2578 | if (!result) { |
| 2579 | Log.e(TAG, "Error requesting route to host: " + mAGpsDataConnectionIpAddr); |
| 2580 | } else if (DEBUG) { |
| 2581 | Log.d(TAG, "Successfully requested route to host: " + mAGpsDataConnectionIpAddr); |
| 2582 | } |
Kevin Tang | a5fe6b2 | 2011-06-05 14:25:16 -0700 | [diff] [blame] | 2583 | } |
| 2584 | |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 2585 | /** |
| 2586 | * @return {@code true} if there is a data network available for outgoing connections, |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2587 | * {@code false} otherwise. |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 2588 | */ |
| 2589 | private boolean isDataNetworkConnected() { |
| 2590 | NetworkInfo activeNetworkInfo = mConnMgr.getActiveNetworkInfo(); |
| 2591 | return activeNetworkInfo != null && activeNetworkInfo.isConnected(); |
| 2592 | } |
| 2593 | |
| 2594 | /** |
| 2595 | * Ensures the calling function is running in the thread associated with {@link #mHandler}. |
| 2596 | */ |
| 2597 | private void ensureInHandlerThread() { |
| 2598 | if (mHandler != null && Looper.myLooper() == mHandler.getLooper()) { |
| 2599 | return; |
| 2600 | } |
| 2601 | throw new RuntimeException("This method must run on the Handler thread."); |
| 2602 | } |
| 2603 | |
| 2604 | /** |
| 2605 | * @return A string representing the current state stored in {@link #mAGpsDataConnectionState}. |
| 2606 | */ |
| 2607 | private String agpsDataConnStateAsString() { |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2608 | switch (mAGpsDataConnectionState) { |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 2609 | case AGPS_DATA_CONNECTION_CLOSED: |
| 2610 | return "CLOSED"; |
| 2611 | case AGPS_DATA_CONNECTION_OPEN: |
| 2612 | return "OPEN"; |
| 2613 | case AGPS_DATA_CONNECTION_OPENING: |
| 2614 | return "OPENING"; |
| 2615 | default: |
| 2616 | return "<Unknown>"; |
| 2617 | } |
| 2618 | } |
| 2619 | |
| 2620 | /** |
| 2621 | * @return A string representing the given GPS_AGPS_DATA status. |
| 2622 | */ |
| 2623 | private String agpsDataConnStatusAsString(int agpsDataConnStatus) { |
| 2624 | switch (agpsDataConnStatus) { |
| 2625 | case GPS_AGPS_DATA_CONNECTED: |
| 2626 | return "CONNECTED"; |
| 2627 | case GPS_AGPS_DATA_CONN_DONE: |
| 2628 | return "DONE"; |
| 2629 | case GPS_AGPS_DATA_CONN_FAILED: |
| 2630 | return "FAILED"; |
| 2631 | case GPS_RELEASE_AGPS_DATA_CONN: |
| 2632 | return "RELEASE"; |
| 2633 | case GPS_REQUEST_AGPS_DATA_CONN: |
| 2634 | return "REQUEST"; |
| 2635 | default: |
| 2636 | return "<Unknown>"; |
| 2637 | } |
| 2638 | } |
| 2639 | |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2640 | /** |
| 2641 | * @return A string representing the given message ID. |
| 2642 | */ |
| 2643 | private String messageIdAsString(int message) { |
| 2644 | switch (message) { |
| 2645 | case ENABLE: |
| 2646 | return "ENABLE"; |
| 2647 | case SET_REQUEST: |
| 2648 | return "SET_REQUEST"; |
| 2649 | case UPDATE_NETWORK_STATE: |
| 2650 | return "UPDATE_NETWORK_STATE"; |
| 2651 | case REQUEST_SUPL_CONNECTION: |
| 2652 | return "REQUEST_SUPL_CONNECTION"; |
| 2653 | case RELEASE_SUPL_CONNECTION: |
| 2654 | return "RELEASE_SUPL_CONNECTION"; |
| 2655 | case INJECT_NTP_TIME: |
| 2656 | return "INJECT_NTP_TIME"; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 2657 | case REQUEST_LOCATION: |
| 2658 | return "REQUEST_LOCATION"; |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2659 | case DOWNLOAD_XTRA_DATA: |
| 2660 | return "DOWNLOAD_XTRA_DATA"; |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2661 | case DOWNLOAD_XTRA_DATA_FINISHED: |
| 2662 | return "DOWNLOAD_XTRA_DATA_FINISHED"; |
| 2663 | case UPDATE_LOCATION: |
| 2664 | return "UPDATE_LOCATION"; |
| 2665 | case SUBSCRIPTION_OR_SIM_CHANGED: |
| 2666 | return "SUBSCRIPTION_OR_SIM_CHANGED"; |
| 2667 | case INITIALIZE_HANDLER: |
| 2668 | return "INITIALIZE_HANDLER"; |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 2669 | case REPORT_LOCATION: |
| 2670 | return "REPORT_LOCATION"; |
| 2671 | case REPORT_SV_STATUS: |
| 2672 | return "REPORT_SV_STATUS"; |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2673 | default: |
| 2674 | return "<Unknown>"; |
| 2675 | } |
| 2676 | } |
| 2677 | |
Siddharth Ray | bb608c8 | 2017-03-16 11:33:34 -0700 | [diff] [blame] | 2678 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2679 | @Override |
| 2680 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 2681 | StringBuilder s = new StringBuilder(); |
Wyatt Riley | 77ca4f8 | 2017-06-30 18:13:44 -0700 | [diff] [blame] | 2682 | s.append(" mStarted=").append(mStarted).append('\n'); |
destradaa | 25e8caf | 2015-08-24 14:14:44 -0700 | [diff] [blame] | 2683 | s.append(" mFixInterval=").append(mFixInterval).append('\n'); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2684 | s.append(" mLowPowerMode=").append(mLowPowerMode).append('\n'); |
Wyatt Riley | 74479bd | 2018-01-17 08:48:27 -0800 | [diff] [blame] | 2685 | s.append(" mGnssMeasurementsProvider.isRegistered()=") |
| 2686 | .append(mGnssMeasurementsProvider.isRegistered()).append('\n'); |
| 2687 | s.append(" mGnssNavigationMessageProvider.isRegistered()=") |
| 2688 | .append(mGnssNavigationMessageProvider.isRegistered()).append('\n'); |
destradaa | 25e8caf | 2015-08-24 14:14:44 -0700 | [diff] [blame] | 2689 | s.append(" mDisableGps (battery saver mode)=").append(mDisableGps).append('\n'); |
| 2690 | s.append(" mEngineCapabilities=0x").append(Integer.toHexString(mEngineCapabilities)); |
| 2691 | s.append(" ( "); |
| 2692 | if (hasCapability(GPS_CAPABILITY_SCHEDULING)) s.append("SCHEDULING "); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2693 | if (hasCapability(GPS_CAPABILITY_MSB)) s.append("MSB "); |
| 2694 | if (hasCapability(GPS_CAPABILITY_MSA)) s.append("MSA "); |
| 2695 | if (hasCapability(GPS_CAPABILITY_SINGLE_SHOT)) s.append("SINGLE_SHOT "); |
| 2696 | if (hasCapability(GPS_CAPABILITY_ON_DEMAND_TIME)) s.append("ON_DEMAND_TIME "); |
destradaa | 25e8caf | 2015-08-24 14:14:44 -0700 | [diff] [blame] | 2697 | if (hasCapability(GPS_CAPABILITY_GEOFENCING)) s.append("GEOFENCING "); |
| 2698 | if (hasCapability(GPS_CAPABILITY_MEASUREMENTS)) s.append("MEASUREMENTS "); |
| 2699 | if (hasCapability(GPS_CAPABILITY_NAV_MESSAGES)) s.append("NAV_MESSAGES "); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2700 | s.append(")\n"); |
Siddharth Ray | bb608c8 | 2017-03-16 11:33:34 -0700 | [diff] [blame] | 2701 | s.append(mGnssMetrics.dumpGnssMetricsAsText()); |
| 2702 | s.append(" native internal state: ").append(native_get_internal_state()); |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2703 | s.append("\n"); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2704 | pw.append(s); |
| 2705 | } |
| 2706 | |
Mike Lockwood | b16e780 | 2009-08-06 09:26:02 -0400 | [diff] [blame] | 2707 | // preallocated to avoid memory allocation in reportNmea() |
| 2708 | private byte[] mNmeaBuffer = new byte[120]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2709 | |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2710 | static { |
| 2711 | class_init_native(); |
| 2712 | } |
| 2713 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2714 | private static native void class_init_native(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2715 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2716 | private static native boolean native_is_supported(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2717 | |
destradaa | ef752b6 | 2015-04-17 13:10:47 -0700 | [diff] [blame] | 2718 | private static native boolean native_is_agps_ril_supported(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2719 | |
destradaa | ef752b6 | 2015-04-17 13:10:47 -0700 | [diff] [blame] | 2720 | private static native boolean native_is_gnss_configuration_supported(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2721 | |
Yu-Han Yang | 6d31735 | 2018-03-15 11:53:01 -0700 | [diff] [blame] | 2722 | private static native void native_init_once(); |
| 2723 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2724 | private native boolean native_init(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2725 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2726 | private native void native_cleanup(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2727 | |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 2728 | 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] | 2729 | int preferred_accuracy, int preferred_time, boolean lowPowerMode); |
| 2730 | |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 2731 | private native boolean native_start(); |
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_stop(); |
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_delete_aiding_data(int flags); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2736 | |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 2737 | private native int native_read_nmea(byte[] buffer, int bufferSize); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2738 | |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 2739 | private native void native_inject_best_location( |
| 2740 | int gnssLocationFlags, |
| 2741 | double latitudeDegrees, |
| 2742 | double longitudeDegrees, |
| 2743 | double altitudeMeters, |
| 2744 | float speedMetersPerSec, |
| 2745 | float bearingDegrees, |
| 2746 | float horizontalAccuracyMeters, |
| 2747 | float verticalAccuracyMeters, |
| 2748 | float speedAccuracyMetersPerSecond, |
| 2749 | float bearingAccuracyDegrees, |
| 2750 | long timestamp); |
| 2751 | |
Mike Lockwood | d26ce0d | 2009-06-11 12:25:46 -0400 | [diff] [blame] | 2752 | private native void native_inject_location(double latitude, double longitude, float accuracy); |
| 2753 | |
Fred Fettinger | 3c8fbdf | 2010-01-04 15:38:13 -0600 | [diff] [blame] | 2754 | // XTRA Support |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2755 | private native void native_inject_time(long time, long timeReference, int uncertainty); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2756 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2757 | private native boolean native_supports_xtra(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2758 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2759 | 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] | 2760 | |
Fred Fettinger | 3c8fbdf | 2010-01-04 15:38:13 -0600 | [diff] [blame] | 2761 | // DEBUG Support |
| 2762 | private native String native_get_internal_state(); |
| 2763 | |
| 2764 | // AGPS Support |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 2765 | private native void native_agps_data_conn_open(String apn, int apnIpType); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2766 | |
Mike Lockwood | e3635c9 | 2009-05-11 08:38:02 -0400 | [diff] [blame] | 2767 | private native void native_agps_data_conn_closed(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2768 | |
Mike Lockwood | e3635c9 | 2009-05-11 08:38:02 -0400 | [diff] [blame] | 2769 | private native void native_agps_data_conn_failed(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2770 | |
| 2771 | private native void native_agps_ni_message(byte[] msg, int length); |
| 2772 | |
Mike Lockwood | a9e5461 | 2009-06-19 14:54:42 -0400 | [diff] [blame] | 2773 | 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] | 2774 | |
| 2775 | // Network-initiated (NI) Support |
| 2776 | private native void native_send_ni_response(int notificationId, int userResponse); |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 2777 | |
| 2778 | // AGPS ril suport |
| 2779 | private native void native_agps_set_ref_location_cellid(int type, int mcc, int mnc, |
| 2780 | int lac, int cid); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2781 | |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 2782 | private native void native_agps_set_id(int type, String setid); |
Mike Lockwood | 50130bb | 2010-10-11 06:22:50 -0400 | [diff] [blame] | 2783 | |
| 2784 | private native void native_update_network_state(boolean connected, int type, |
Kevin Tang | a5fe6b2 | 2011-06-05 14:25:16 -0700 | [diff] [blame] | 2785 | boolean roaming, boolean available, String extraInfo, String defaultAPN); |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 2786 | |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 2787 | // GNSS Configuration |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2788 | private static native boolean native_set_supl_version(int version); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2789 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2790 | private static native boolean native_set_supl_mode(int mode); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2791 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2792 | private static native boolean native_set_supl_es(int es); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2793 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2794 | private static native boolean native_set_lpp_profile(int lppProfile); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2795 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2796 | private static native boolean native_set_gnss_pos_protocol_select(int gnssPosProtocolSelect); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2797 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2798 | private static native boolean native_set_gps_lock(int gpsLock); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2799 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2800 | private static native boolean native_set_emergency_supl_pdn(int emergencySuplPdn); |
| 2801 | |
Yu-Han Yang | 66c7ea9 | 2018-03-11 17:17:15 -0700 | [diff] [blame] | 2802 | 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] | 2803 | } |
Yu-Han Yang | a1862b5 | 2018-02-20 17:05:59 -0800 | [diff] [blame] | 2804 | |