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