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