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