The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Mike Lockwood | 00b7427 | 2010-03-26 10:41:48 -0400 | [diff] [blame] | 17 | package com.android.server.location; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 19 | import android.app.AlarmManager; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 20 | import android.app.AppOpsManager; |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 21 | import android.app.PendingIntent; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 22 | import android.content.BroadcastReceiver; |
Yu-Han Yang | 74041ff | 2018-04-06 15:57:31 -0700 | [diff] [blame] | 23 | import android.content.ContentResolver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.content.Context; |
| 25 | import android.content.Intent; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 26 | import android.content.IntentFilter; |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 27 | import android.database.ContentObserver; |
destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 28 | import android.hardware.location.GeofenceHardware; |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 29 | import android.hardware.location.GeofenceHardwareImpl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.location.Criteria; |
destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 31 | import android.location.FusedBatchOptions; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 32 | import android.location.GnssMeasurementsEvent; |
| 33 | import android.location.GnssNavigationMessage; |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 34 | import android.location.GnssStatus; |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 35 | import android.location.IGpsGeofenceHardware; |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 36 | import android.location.INetInitiatedListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.location.Location; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 38 | import android.location.LocationListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | import android.location.LocationManager; |
| 40 | import android.location.LocationProvider; |
Stan Chesnutt | 1d72d8c | 2013-04-15 19:18:02 -0700 | [diff] [blame] | 41 | import android.location.LocationRequest; |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 42 | import android.os.AsyncTask; |
Dianne Hackborn | 91268cf | 2013-06-13 19:06:50 -0700 | [diff] [blame] | 43 | import android.os.BatteryStats; |
Mike Lockwood | 63aa5a6 | 2010-04-14 19:21:31 -0400 | [diff] [blame] | 44 | import android.os.Binder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | import android.os.Bundle; |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 46 | import android.os.Handler; |
Victoria Lease | 5cd731a | 2012-12-19 15:04:21 -0800 | [diff] [blame] | 47 | import android.os.Looper; |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 48 | import android.os.Message; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 49 | import android.os.PersistableBundle; |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 50 | import android.os.PowerManager; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 51 | import android.os.PowerManager.ServiceType; |
| 52 | import android.os.PowerSaveState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | import android.os.RemoteException; |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 54 | import android.os.ServiceManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | import android.os.SystemClock; |
Colin Cross | 7c030ed | 2014-01-28 09:33:53 -0800 | [diff] [blame] | 56 | import android.os.SystemProperties; |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 57 | import android.os.UserHandle; |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 58 | import android.os.WorkSource; |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 59 | import android.os.WorkSource.WorkChain; |
Mike Lockwood | bcab8df | 2009-06-25 16:39:09 -0400 | [diff] [blame] | 60 | import android.provider.Settings; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 61 | import android.telephony.CarrierConfigManager; |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 62 | import android.telephony.SubscriptionManager; |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 63 | import android.telephony.TelephonyManager; |
| 64 | import android.telephony.gsm.GsmCellLocation; |
Colin Cross | 7c030ed | 2014-01-28 09:33:53 -0800 | [diff] [blame] | 65 | import android.text.TextUtils; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | import android.util.Log; |
Yu-Han Yang | 8a1b51d | 2018-12-26 22:18:31 -0800 | [diff] [blame] | 67 | import android.util.StatsLog; |
WyattRiley | ba6072f | 2019-04-18 07:37:52 -0700 | [diff] [blame] | 68 | import android.util.TimeUtils; |
Yu-Han Yang | a1862b5 | 2018-02-20 17:05:59 -0800 | [diff] [blame] | 69 | |
Anil Admal | 032aa81 | 2019-03-06 19:23:25 -0800 | [diff] [blame] | 70 | import com.android.internal.annotations.GuardedBy; |
jackqdyulei | 455e90a | 2017-02-09 15:29:16 -0800 | [diff] [blame] | 71 | import com.android.internal.app.IBatteryStats; |
| 72 | import com.android.internal.location.GpsNetInitiatedHandler; |
| 73 | import com.android.internal.location.GpsNetInitiatedHandler.GpsNiNotification; |
| 74 | import com.android.internal.location.ProviderProperties; |
| 75 | import com.android.internal.location.ProviderRequest; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 76 | import com.android.internal.location.gnssmetrics.GnssMetrics; |
Anil Admal | e1539e8 | 2019-05-09 15:05:04 -0700 | [diff] [blame] | 77 | import com.android.internal.telephony.TelephonyIntents; |
Kweku Adams | b8bb9fb | 2019-08-28 07:45:00 -0700 | [diff] [blame] | 78 | import com.android.server.DeviceIdleController; |
| 79 | import com.android.server.LocalServices; |
Yu-Han Yang | 66c7ea9 | 2018-03-11 17:17:15 -0700 | [diff] [blame] | 80 | import com.android.server.location.GnssSatelliteBlacklistHelper.GnssSatelliteBlacklistCallback; |
Yu-Han Yang | a1862b5 | 2018-02-20 17:05:59 -0800 | [diff] [blame] | 81 | import com.android.server.location.NtpTimeHelper.InjectNtpTimeCallback; |
Yu-Han Yang | 66c7ea9 | 2018-03-11 17:17:15 -0700 | [diff] [blame] | 82 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 83 | import java.io.FileDescriptor; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 84 | import java.io.PrintWriter; |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 85 | import java.lang.annotation.ElementType; |
| 86 | import java.lang.annotation.Retention; |
| 87 | import java.lang.annotation.RetentionPolicy; |
| 88 | import java.lang.annotation.Target; |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 89 | import java.util.ArrayList; |
Andreas Gampe | e6748ce | 2015-12-11 18:00:38 -0800 | [diff] [blame] | 90 | import java.util.Arrays; |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 91 | import java.util.List; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 92 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | /** |
gomo | 4402af6 | 2017-01-11 13:20:13 -0800 | [diff] [blame] | 94 | * A GNSS implementation of LocationProvider used by LocationManager. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | * |
| 96 | * {@hide} |
| 97 | */ |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 98 | public class GnssLocationProvider extends AbstractLocationProvider implements |
| 99 | InjectNtpTimeCallback, |
| 100 | GnssSatelliteBlacklistCallback { |
| 101 | |
| 102 | /** |
| 103 | * Indicates that this method is a native entry point. Useful purely for IDEs which can |
| 104 | * understand entry points, and thus eliminate incorrect warnings about methods not used. |
| 105 | */ |
| 106 | @Target(ElementType.METHOD) |
| 107 | @Retention(RetentionPolicy.SOURCE) |
| 108 | private @interface NativeEntryPoint { |
| 109 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 111 | private static final String TAG = "GnssLocationProvider"; |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 112 | |
Brian Muramatsu | 1715cb3 | 2012-08-08 17:32:21 -0700 | [diff] [blame] | 113 | private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
| 114 | private static final boolean VERBOSE = Log.isLoggable(TAG, Log.VERBOSE); |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 115 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 116 | private static final ProviderProperties PROPERTIES = new ProviderProperties( |
| 117 | true, true, false, false, true, true, true, |
| 118 | Criteria.POWER_HIGH, Criteria.ACCURACY_FINE); |
| 119 | |
gomo | 4402af6 | 2017-01-11 13:20:13 -0800 | [diff] [blame] | 120 | // these need to match GnssPositionMode enum in IGnss.hal |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 121 | private static final int GPS_POSITION_MODE_STANDALONE = 0; |
| 122 | private static final int GPS_POSITION_MODE_MS_BASED = 1; |
| 123 | private static final int GPS_POSITION_MODE_MS_ASSISTED = 2; |
| 124 | |
gomo | 4402af6 | 2017-01-11 13:20:13 -0800 | [diff] [blame] | 125 | // these need to match GnssPositionRecurrence enum in IGnss.hal |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 126 | private static final int GPS_POSITION_RECURRENCE_PERIODIC = 0; |
| 127 | private static final int GPS_POSITION_RECURRENCE_SINGLE = 1; |
| 128 | |
gomo | 4402af6 | 2017-01-11 13:20:13 -0800 | [diff] [blame] | 129 | // these need to match GnssStatusValue enum in IGnssCallback.hal |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | private static final int GPS_STATUS_NONE = 0; |
| 131 | private static final int GPS_STATUS_SESSION_BEGIN = 1; |
| 132 | private static final int GPS_STATUS_SESSION_END = 2; |
| 133 | private static final int GPS_STATUS_ENGINE_ON = 3; |
| 134 | private static final int GPS_STATUS_ENGINE_OFF = 4; |
| 135 | |
gomo | 4402af6 | 2017-01-11 13:20:13 -0800 | [diff] [blame] | 136 | // these need to match GnssLocationFlags enum in types.hal |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | private static final int LOCATION_INVALID = 0; |
| 138 | private static final int LOCATION_HAS_LAT_LONG = 1; |
| 139 | private static final int LOCATION_HAS_ALTITUDE = 2; |
| 140 | private static final int LOCATION_HAS_SPEED = 4; |
| 141 | private static final int LOCATION_HAS_BEARING = 8; |
gomo | 4402af6 | 2017-01-11 13:20:13 -0800 | [diff] [blame] | 142 | private static final int LOCATION_HAS_HORIZONTAL_ACCURACY = 16; |
| 143 | private static final int LOCATION_HAS_VERTICAL_ACCURACY = 32; |
| 144 | private static final int LOCATION_HAS_SPEED_ACCURACY = 64; |
| 145 | private static final int LOCATION_HAS_BEARING_ACCURACY = 128; |
Mike Lockwood | e3635c9 | 2009-05-11 08:38:02 -0400 | [diff] [blame] | 146 | |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 147 | // these need to match ElapsedRealtimeFlags enum in types.hal |
| 148 | private static final int ELAPSED_REALTIME_HAS_TIMESTAMP_NS = 1; |
Pierre Fite-Georgel | 9e96c57 | 2019-02-25 16:12:53 -0800 | [diff] [blame] | 149 | private static final int ELAPSED_REALTIME_HAS_TIME_UNCERTAINTY_NS = 2; |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 150 | |
gomo | 4402af6 | 2017-01-11 13:20:13 -0800 | [diff] [blame] | 151 | // 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] | 152 | private static final int GPS_DELETE_EPHEMERIS = 0x0001; |
| 153 | private static final int GPS_DELETE_ALMANAC = 0x0002; |
| 154 | private static final int GPS_DELETE_POSITION = 0x0004; |
| 155 | private static final int GPS_DELETE_TIME = 0x0008; |
| 156 | private static final int GPS_DELETE_IONO = 0x0010; |
| 157 | private static final int GPS_DELETE_UTC = 0x0020; |
| 158 | private static final int GPS_DELETE_HEALTH = 0x0040; |
| 159 | private static final int GPS_DELETE_SVDIR = 0x0080; |
| 160 | private static final int GPS_DELETE_SVSTEER = 0x0100; |
| 161 | private static final int GPS_DELETE_SADATA = 0x0200; |
| 162 | private static final int GPS_DELETE_RTI = 0x0400; |
| 163 | private static final int GPS_DELETE_CELLDB_INFO = 0x8000; |
| 164 | private static final int GPS_DELETE_ALL = 0xFFFF; |
| 165 | |
gomo | 4402af6 | 2017-01-11 13:20:13 -0800 | [diff] [blame] | 166 | // The GPS_CAPABILITY_* flags must match Capabilities enum in IGnssCallback.hal |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 167 | private static final int GPS_CAPABILITY_SCHEDULING = 0x0000001; |
| 168 | private static final int GPS_CAPABILITY_MSB = 0x0000002; |
| 169 | private static final int GPS_CAPABILITY_MSA = 0x0000004; |
| 170 | private static final int GPS_CAPABILITY_SINGLE_SHOT = 0x0000008; |
Mike Lockwood | 9b9fb5c | 2011-06-29 15:09:40 -0400 | [diff] [blame] | 171 | private static final int GPS_CAPABILITY_ON_DEMAND_TIME = 0x0000010; |
Anil Admal | efd9dc6 | 2019-03-12 17:39:20 -0700 | [diff] [blame] | 172 | public static final int GPS_CAPABILITY_GEOFENCING = 0x0000020; |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 173 | public static final int GPS_CAPABILITY_MEASUREMENTS = 0x0000040; |
Anil Admal | efd9dc6 | 2019-03-12 17:39:20 -0700 | [diff] [blame] | 174 | public static final int GPS_CAPABILITY_NAV_MESSAGES = 0x0000080; |
Anil Admal | 62c42dc | 2019-04-03 15:39:22 -0700 | [diff] [blame] | 175 | public static final int GPS_CAPABILITY_LOW_POWER_MODE = 0x0000100; |
| 176 | public static final int GPS_CAPABILITY_SATELLITE_BLACKLIST = 0x0000200; |
| 177 | public static final int GPS_CAPABILITY_MEASUREMENT_CORRECTIONS = 0x0000400; |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 178 | |
Tsuwei Chen | 462bcd8 | 2014-09-17 12:28:49 -0700 | [diff] [blame] | 179 | // The AGPS SUPL mode |
| 180 | private static final int AGPS_SUPL_MODE_MSA = 0x02; |
| 181 | private static final int AGPS_SUPL_MODE_MSB = 0x01; |
| 182 | |
Kweku Adams | b8bb9fb | 2019-08-28 07:45:00 -0700 | [diff] [blame] | 183 | private static final int UPDATE_LOW_POWER_MODE = 1; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 184 | private static final int SET_REQUEST = 3; |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 185 | private static final int INJECT_NTP_TIME = 5; |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 186 | // PSDS stands for Predicted Satellite Data Service |
| 187 | private static final int DOWNLOAD_PSDS_DATA = 6; |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 188 | private static final int UPDATE_LOCATION = 7; // Handle external location from network listener |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 189 | private static final int DOWNLOAD_PSDS_DATA_FINISHED = 11; |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 190 | private static final int INITIALIZE_HANDLER = 13; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 191 | private static final int REQUEST_LOCATION = 16; |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 192 | private static final int REPORT_LOCATION = 17; // HAL reports location |
| 193 | private static final int REPORT_SV_STATUS = 18; // HAL reports SV status |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 194 | |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 195 | // Request setid |
| 196 | private static final int AGPS_RIL_REQUEST_SETID_IMSI = 1; |
| 197 | private static final int AGPS_RIL_REQUEST_SETID_MSISDN = 2; |
| 198 | |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 199 | // ref. location info |
| 200 | private static final int AGPS_REF_LOCATION_TYPE_GSM_CELLID = 1; |
| 201 | private static final int AGPS_REF_LOCATION_TYPE_UMTS_CELLID = 2; |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 202 | |
| 203 | // set id info |
| 204 | private static final int AGPS_SETID_TYPE_NONE = 0; |
| 205 | private static final int AGPS_SETID_TYPE_IMSI = 1; |
| 206 | private static final int AGPS_SETID_TYPE_MSISDN = 2; |
| 207 | |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 208 | private static final int GPS_GEOFENCE_UNAVAILABLE = 1 << 0L; |
| 209 | private static final int GPS_GEOFENCE_AVAILABLE = 1 << 1L; |
destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 210 | |
gomo | 4402af6 | 2017-01-11 13:20:13 -0800 | [diff] [blame] | 211 | // GPS Geofence errors. Should match GeofenceStatus enum in IGnssGeofenceCallback.hal. |
destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 212 | private static final int GPS_GEOFENCE_OPERATION_SUCCESS = 0; |
| 213 | private static final int GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES = 100; |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 214 | private static final int GPS_GEOFENCE_ERROR_ID_EXISTS = -101; |
destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 215 | private static final int GPS_GEOFENCE_ERROR_ID_UNKNOWN = -102; |
| 216 | private static final int GPS_GEOFENCE_ERROR_INVALID_TRANSITION = -103; |
| 217 | private static final int GPS_GEOFENCE_ERROR_GENERIC = -149; |
| 218 | |
Tsuwei Chen | 678c13c | 2014-09-22 17:48:41 -0700 | [diff] [blame] | 219 | // TCP/IP constants. |
| 220 | // Valid TCP/UDP port range is (0, 65535]. |
| 221 | private static final int TCP_MIN_PORT = 0; |
| 222 | private static final int TCP_MAX_PORT = 0xffff; |
| 223 | |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 224 | // 1 second, or 1 Hz frequency. |
| 225 | private static final long LOCATION_UPDATE_MIN_TIME_INTERVAL_MILLIS = 1000; |
Yu-Han Yang | 639f759 | 2018-06-07 11:58:52 -0700 | [diff] [blame] | 226 | // Default update duration in milliseconds for REQUEST_LOCATION. |
Yu-Han Yang | 9e2a823 | 2018-06-14 12:10:08 -0700 | [diff] [blame] | 227 | private static final long LOCATION_UPDATE_DURATION_MILLIS = 10 * 1000; |
Anil Admal | b1c6c0d | 2019-06-20 12:00:16 -0700 | [diff] [blame] | 228 | // Update duration extension multiplier for emergency REQUEST_LOCATION. |
| 229 | private static final int EMERGENCY_LOCATION_UPDATE_DURATION_MULTIPLIER = 3; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 230 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 231 | /** simpler wrapper for ProviderRequest + Worksource */ |
| 232 | private static class GpsRequest { |
| 233 | public ProviderRequest request; |
| 234 | public WorkSource source; |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 235 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 236 | public GpsRequest(ProviderRequest request, WorkSource source) { |
| 237 | this.request = request; |
| 238 | this.source = source; |
| 239 | } |
| 240 | } |
| 241 | |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 242 | // Threadsafe class to hold stats reported in the Extras Bundle |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 243 | private static class LocationExtras { |
| 244 | private int mSvCount; |
| 245 | private int mMeanCn0; |
| 246 | private int mMaxCn0; |
| 247 | private final Bundle mBundle; |
| 248 | |
| 249 | public LocationExtras() { |
| 250 | mBundle = new Bundle(); |
| 251 | } |
| 252 | |
| 253 | public void set(int svCount, int meanCn0, int maxCn0) { |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 254 | synchronized (this) { |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 255 | mSvCount = svCount; |
| 256 | mMeanCn0 = meanCn0; |
| 257 | mMaxCn0 = maxCn0; |
| 258 | } |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 259 | setBundle(mBundle); |
| 260 | } |
| 261 | |
| 262 | public void reset() { |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 263 | set(0, 0, 0); |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | // Also used by outside methods to add to other bundles |
| 267 | public void setBundle(Bundle extras) { |
| 268 | if (extras != null) { |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 269 | synchronized (this) { |
| 270 | extras.putInt("satellites", mSvCount); |
| 271 | extras.putInt("meanCn0", mMeanCn0); |
| 272 | extras.putInt("maxCn0", mMaxCn0); |
| 273 | } |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 274 | } |
| 275 | } |
| 276 | |
| 277 | public Bundle getBundle() { |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 278 | synchronized (this) { |
| 279 | return new Bundle(mBundle); |
| 280 | } |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | |
Yu-Han Yang | 66c7ea9 | 2018-03-11 17:17:15 -0700 | [diff] [blame] | 284 | private final Object mLock = new Object(); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 285 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | // current status |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 287 | private int mStatus = LocationProvider.TEMPORARILY_UNAVAILABLE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 288 | |
| 289 | // time for last status update |
| 290 | private long mStatusUpdateTime = SystemClock.elapsedRealtime(); |
Mike Lockwood | d53ba01 | 2010-04-15 20:41:26 -0400 | [diff] [blame] | 291 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 292 | // 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] | 293 | private static final long RECENT_FIX_TIMEOUT = 10 * 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 294 | |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 295 | // stop trying if we do not receive a fix within 60 seconds |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 296 | private static final int NO_FIX_TIMEOUT = 60 * 1000; |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 297 | |
Nick Pelly | b041f23 | 2012-05-07 17:12:25 -0700 | [diff] [blame] | 298 | // if the fix interval is below this we leave GPS on, |
| 299 | // if above then we cycle the GPS driver. |
| 300 | // Typical hot TTTF is ~5 seconds, so 10 seconds seems sane. |
| 301 | private static final int GPS_POLLING_THRESHOLD_INTERVAL = 10 * 1000; |
| 302 | |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 303 | // how long to wait if we have a network error in NTP or PSDS downloading |
Wei Liu | 6f6326b | 2015-06-24 23:47:50 -0700 | [diff] [blame] | 304 | // the initial value of the exponential backoff |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 305 | // current setting - 5 minutes |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 306 | private static final long RETRY_INTERVAL = 5 * 60 * 1000; |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 307 | // how long to wait if we have a network error in NTP or PSDS downloading |
Wei Liu | 6f6326b | 2015-06-24 23:47:50 -0700 | [diff] [blame] | 308 | // the max value of the exponential backoff |
| 309 | // current setting - 4 hours |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 310 | private static final long MAX_RETRY_INTERVAL = 4 * 60 * 60 * 1000; |
Wei Liu | 6f6326b | 2015-06-24 23:47:50 -0700 | [diff] [blame] | 311 | |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 312 | // Timeout when holding wakelocks for downloading PSDS data. |
| 313 | private static final long DOWNLOAD_PSDS_DATA_TIMEOUT_MS = 60 * 1000; |
Wei Wang | c5706f6 | 2017-04-18 11:26:26 -0700 | [diff] [blame] | 314 | |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 315 | private final ExponentialBackOff mPsdsBackOff = new ExponentialBackOff(RETRY_INTERVAL, |
Yu-Han Yang | a1862b5 | 2018-02-20 17:05:59 -0800 | [diff] [blame] | 316 | MAX_RETRY_INTERVAL); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 317 | |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 318 | // True if we are enabled |
| 319 | @GuardedBy("mLock") |
| 320 | private boolean mGpsEnabled; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 321 | |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 322 | private boolean mShutdown; |
| 323 | |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 324 | // states for injecting ntp and downloading psds data |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 325 | private static final int STATE_PENDING_NETWORK = 0; |
| 326 | private static final int STATE_DOWNLOADING = 1; |
| 327 | private static final int STATE_IDLE = 2; |
| 328 | |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 329 | // flags to trigger NTP or PSDS data download when network becomes available |
| 330 | // initialized to true so we do NTP and PSDS when the network comes up after booting |
| 331 | private int mDownloadPsdsDataPending = STATE_PENDING_NETWORK; |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 332 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 333 | // true if GPS is navigating |
| 334 | private boolean mNavigating; |
Mike Lockwood | cf1d8cb | 2010-01-20 10:14:54 -0500 | [diff] [blame] | 335 | |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 336 | // requested frequency of fixes, in milliseconds |
| 337 | private int mFixInterval = 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 338 | |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 339 | // true if low power mode for the GNSS chipset is part of the latest request. |
| 340 | private boolean mLowPowerMode = false; |
| 341 | |
WyattRiley | ba6072f | 2019-04-18 07:37:52 -0700 | [diff] [blame] | 342 | // true if we started navigation in the HAL, only change value of this in setStarted |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 343 | private boolean mStarted; |
| 344 | |
WyattRiley | ba6072f | 2019-04-18 07:37:52 -0700 | [diff] [blame] | 345 | // for logging of latest change, and warning of ongoing location after a stop |
| 346 | private long mStartedChangedElapsedRealtime; |
| 347 | |
| 348 | // threshold for delay in GNSS engine turning off before warning & error |
| 349 | private static final long LOCATION_OFF_DELAY_THRESHOLD_WARN_MILLIS = 2 * 1000; |
| 350 | private static final long LOCATION_OFF_DELAY_THRESHOLD_ERROR_MILLIS = 15 * 1000; |
| 351 | |
Anil Admal | 312fddb | 2019-03-25 12:15:43 -0700 | [diff] [blame] | 352 | // capabilities reported through the top level IGnssCallback.hal |
| 353 | private volatile int mTopHalCapabilities; |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 354 | |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 355 | // true if PSDS is supported |
| 356 | private boolean mSupportsPsds; |
Mike Lockwood | 1a1cd3a | 2010-08-17 07:42:54 -0400 | [diff] [blame] | 357 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 358 | // for calculating time to first fix |
| 359 | private long mFixRequestTime = 0; |
| 360 | // time to first fix for most recent session |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 361 | private int mTimeToFirstFix = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 362 | // time we received our last fix |
| 363 | private long mLastFixTime; |
| 364 | |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 365 | private int mPositionMode; |
Yu-Han Yang | c8b9ff7 | 2018-04-17 00:47:24 -0700 | [diff] [blame] | 366 | private GnssPositionMode mLastPositionMode; |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 367 | |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 368 | // Current request from underlying location clients. |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 369 | private ProviderRequest mProviderRequest; |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 370 | // The WorkSource associated with the most recent client request (i.e, most recent call to |
| 371 | // setRequest). |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 372 | private WorkSource mWorkSource = null; |
WyattRiley | b244607 | 2019-03-01 07:41:49 -0800 | [diff] [blame] | 373 | // True if gps should be disabled because of PowerManager controls |
| 374 | private boolean mDisableGpsForPowerManager = false; |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 375 | |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 376 | /** |
Kweku Adams | b8bb9fb | 2019-08-28 07:45:00 -0700 | [diff] [blame] | 377 | * True if the device idle controller has determined that the device is stationary. This is only |
| 378 | * updated when the device enters idle mode. |
| 379 | */ |
| 380 | private volatile boolean mIsDeviceStationary = false; |
| 381 | |
| 382 | /** |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 383 | * Properties loaded from PROPERTIES_FILE. |
| 384 | * It must be accessed only inside {@link #mHandler}. |
| 385 | */ |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 386 | private GnssConfiguration mGnssConfiguration; |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 387 | |
Mike Lockwood | 734d603 | 2009-07-28 18:30:25 -0700 | [diff] [blame] | 388 | private String mSuplServerHost; |
Tsuwei Chen | 678c13c | 2014-09-22 17:48:41 -0700 | [diff] [blame] | 389 | private int mSuplServerPort = TCP_MIN_PORT; |
Mike Lockwood | 734d603 | 2009-07-28 18:30:25 -0700 | [diff] [blame] | 390 | private String mC2KServerHost; |
| 391 | private int mC2KServerPort; |
Tsuwei Chen | 3324e95 | 2014-09-07 01:30:42 -0700 | [diff] [blame] | 392 | private boolean mSuplEsEnabled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 393 | |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 394 | private final Looper mLooper; |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 395 | private final LocationExtras mLocationExtras = new LocationExtras(); |
Anil Admal | 75b9fd6 | 2018-11-28 11:22:50 -0800 | [diff] [blame] | 396 | private final GnssStatusListenerHelper mGnssStatusListenerHelper; |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 397 | private final GnssMeasurementsProvider mGnssMeasurementsProvider; |
Anil Admal | efd9dc6 | 2019-03-12 17:39:20 -0700 | [diff] [blame] | 398 | private final GnssMeasurementCorrectionsProvider mGnssMeasurementCorrectionsProvider; |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 399 | private final GnssNavigationMessageProvider mGnssNavigationMessageProvider; |
Yu-Han Yang | 0756138 | 2018-02-21 13:08:37 -0800 | [diff] [blame] | 400 | private final LocationChangeListener mNetworkLocationListener = new NetworkLocationListener(); |
| 401 | private final LocationChangeListener mFusedLocationListener = new FusedLocationListener(); |
Yu-Han Yang | a1862b5 | 2018-02-20 17:05:59 -0800 | [diff] [blame] | 402 | private final NtpTimeHelper mNtpTimeHelper; |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 403 | private final GnssBatchingProvider mGnssBatchingProvider; |
Yu-Han Yang | 890ca8b | 2018-04-16 22:11:31 -0700 | [diff] [blame] | 404 | private final GnssGeofenceProvider mGnssGeofenceProvider; |
Anil Admal | 312fddb | 2019-03-25 12:15:43 -0700 | [diff] [blame] | 405 | private final GnssCapabilitiesProvider mGnssCapabilitiesProvider; |
| 406 | |
Anil Admal | 316f948 | 2019-02-12 18:57:18 -0800 | [diff] [blame] | 407 | // Available only on GNSS HAL 2.0 implementations and later. |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 408 | private GnssVisibilityControl mGnssVisibilityControl; |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 409 | |
Victoria Lease | 5c24fd0 | 2012-10-01 11:00:50 -0700 | [diff] [blame] | 410 | // Handler for processing events |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 411 | private Handler mHandler; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 412 | |
Anil Admal | 50ba15e | 2018-11-01 16:42:42 -0700 | [diff] [blame] | 413 | private final GnssNetworkConnectivityHandler mNetworkConnectivityHandler; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 414 | private final GpsNetInitiatedHandler mNIHandler; |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 415 | |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 416 | // Wakelocks |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 417 | private final static String WAKELOCK_KEY = "GnssLocationProvider"; |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 418 | private final PowerManager.WakeLock mWakeLock; |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 419 | private static final String DOWNLOAD_EXTRA_WAKELOCK_KEY = "GnssLocationProviderPsdsDownload"; |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 420 | @GuardedBy("mLock") |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 421 | private final PowerManager.WakeLock mDownloadPsdsWakeLock; |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 422 | |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 423 | // Alarms |
| 424 | private final static String ALARM_WAKEUP = "com.android.internal.location.ALARM_WAKEUP"; |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 425 | private final static String ALARM_TIMEOUT = "com.android.internal.location.ALARM_TIMEOUT"; |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 426 | |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 427 | private final PowerManager mPowerManager; |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 428 | private final AlarmManager mAlarmManager; |
| 429 | private final PendingIntent mWakeupIntent; |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 430 | private final PendingIntent mTimeoutIntent; |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 431 | |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 432 | private final AppOpsManager mAppOps; |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 433 | private final IBatteryStats mBatteryStats; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 434 | |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 435 | // Current list of underlying location clients. |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 436 | // only modified on handler thread |
Dianne Hackborn | 002a54e | 2013-01-10 17:34:55 -0800 | [diff] [blame] | 437 | private WorkSource mClientSource = new WorkSource(); |
Mike Lockwood | f1218be | 2010-01-29 09:20:06 -0500 | [diff] [blame] | 438 | |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 439 | private GeofenceHardwareImpl mGeofenceHardwareImpl; |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 440 | |
| 441 | // Volatile for simple inter-thread sync on these values. |
| 442 | private volatile int mHardwareYear = 0; |
Wyatt Riley | 49097c0 | 2018-03-15 09:14:43 -0700 | [diff] [blame] | 443 | private volatile String mHardwareModelName; |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 444 | |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 445 | // Set lower than the current ITAR limit of 600m/s to allow this to trigger even if GPS HAL |
| 446 | // stops output right at 600m/s, depriving this of the information of a device that reaches |
| 447 | // greater than 600m/s, and higher than the speed of sound to avoid impacting most use cases. |
| 448 | private static final float ITAR_SPEED_LIMIT_METERS_PER_SECOND = 400.0F; |
Wyatt Riley | 042c48f | 2017-10-06 14:59:25 -0700 | [diff] [blame] | 449 | |
Wyatt Riley | 042c48f | 2017-10-06 14:59:25 -0700 | [diff] [blame] | 450 | private volatile boolean mItarSpeedLimitExceeded = false; |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 451 | |
Siddharth Ray | bb608c8 | 2017-03-16 11:33:34 -0700 | [diff] [blame] | 452 | // GNSS Metrics |
| 453 | private GnssMetrics mGnssMetrics; |
| 454 | |
Anil Admal | 75b9fd6 | 2018-11-28 11:22:50 -0800 | [diff] [blame] | 455 | public GnssStatusListenerHelper getGnssStatusProvider() { |
| 456 | return mGnssStatusListenerHelper; |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 457 | } |
| 458 | |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 459 | public IGpsGeofenceHardware getGpsGeofenceProxy() { |
Yu-Han Yang | 890ca8b | 2018-04-16 22:11:31 -0700 | [diff] [blame] | 460 | return mGnssGeofenceProvider; |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 461 | } |
| 462 | |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 463 | public GnssMeasurementsProvider getGnssMeasurementsProvider() { |
| 464 | return mGnssMeasurementsProvider; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 465 | } |
| 466 | |
Anil Admal | efd9dc6 | 2019-03-12 17:39:20 -0700 | [diff] [blame] | 467 | public GnssMeasurementCorrectionsProvider getGnssMeasurementCorrectionsProvider() { |
| 468 | return mGnssMeasurementCorrectionsProvider; |
| 469 | } |
| 470 | |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 471 | public GnssNavigationMessageProvider getGnssNavigationMessageProvider() { |
| 472 | return mGnssNavigationMessageProvider; |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 473 | } |
Kweku Adams | b8bb9fb | 2019-08-28 07:45:00 -0700 | [diff] [blame] | 474 | |
| 475 | private final DeviceIdleController.StationaryListener mDeviceIdleStationaryListener = |
| 476 | isStationary -> { |
| 477 | mIsDeviceStationary = isStationary; |
| 478 | // Call updateLowPowerMode on handler thread so it's always called from the same |
| 479 | // thread. |
| 480 | mHandler.sendEmptyMessage(UPDATE_LOW_POWER_MODE); |
| 481 | }; |
| 482 | |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 483 | private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 484 | @Override |
| 485 | public void onReceive(Context context, Intent intent) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 486 | String action = intent.getAction(); |
Tsuwei Chen | 48d37f9 | 2014-09-05 15:15:34 -0700 | [diff] [blame] | 487 | if (DEBUG) Log.d(TAG, "receive broadcast intent, action: " + action); |
destradaa | ee9fd34 | 2015-08-31 13:31:17 -0700 | [diff] [blame] | 488 | if (action == null) { |
| 489 | return; |
| 490 | } |
| 491 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 492 | switch (action) { |
| 493 | case ALARM_WAKEUP: |
Yu-Han Yang | 6a5f0b7 | 2019-01-24 18:34:28 -0800 | [diff] [blame] | 494 | startNavigating(); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 495 | break; |
| 496 | case ALARM_TIMEOUT: |
| 497 | hibernate(); |
| 498 | break; |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 499 | case PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED: |
Kweku Adams | b8bb9fb | 2019-08-28 07:45:00 -0700 | [diff] [blame] | 500 | DeviceIdleController.LocalService deviceIdleService = LocalServices.getService( |
| 501 | DeviceIdleController.LocalService.class); |
| 502 | if (mPowerManager.isDeviceIdleMode()) { |
| 503 | deviceIdleService.registerStationaryListener(mDeviceIdleStationaryListener); |
| 504 | } else { |
| 505 | deviceIdleService.unregisterStationaryListener( |
| 506 | mDeviceIdleStationaryListener); |
| 507 | } |
| 508 | // Intentional fall-through. |
| 509 | case PowerManager.ACTION_POWER_SAVE_MODE_CHANGED: |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 510 | case Intent.ACTION_SCREEN_OFF: |
| 511 | case Intent.ACTION_SCREEN_ON: |
Kweku Adams | b8bb9fb | 2019-08-28 07:45:00 -0700 | [diff] [blame] | 512 | // Call updateLowPowerMode on handler thread so it's always called from the |
| 513 | // same thread. |
| 514 | mHandler.sendEmptyMessage(UPDATE_LOW_POWER_MODE); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 515 | break; |
Meng Wang | 19b214d | 2018-11-07 12:14:39 -0800 | [diff] [blame] | 516 | case CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED: |
Anil Admal | e1539e8 | 2019-05-09 15:05:04 -0700 | [diff] [blame] | 517 | case TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED: |
Meng Wang | 19b214d | 2018-11-07 12:14:39 -0800 | [diff] [blame] | 518 | subscriptionOrCarrierConfigChanged(context); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 519 | break; |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 520 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 521 | } |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 522 | }; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 523 | |
Yu-Han Yang | 66c7ea9 | 2018-03-11 17:17:15 -0700 | [diff] [blame] | 524 | /** |
| 525 | * Implements {@link GnssSatelliteBlacklistCallback#onUpdateSatelliteBlacklist}. |
| 526 | */ |
| 527 | @Override |
| 528 | public void onUpdateSatelliteBlacklist(int[] constellations, int[] svids) { |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 529 | mHandler.post(() -> mGnssConfiguration.setSatelliteBlacklist(constellations, svids)); |
Yu-Han Yang | 284234e | 2019-03-28 19:35:57 -0700 | [diff] [blame] | 530 | mGnssMetrics.resetConstellationTypes(); |
Yu-Han Yang | 66c7ea9 | 2018-03-11 17:17:15 -0700 | [diff] [blame] | 531 | } |
| 532 | |
Meng Wang | 19b214d | 2018-11-07 12:14:39 -0800 | [diff] [blame] | 533 | private void subscriptionOrCarrierConfigChanged(Context context) { |
Joe Onorato | 0c48410 | 2016-02-01 18:04:24 -0800 | [diff] [blame] | 534 | if (DEBUG) Log.d(TAG, "received SIM related action: "); |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 535 | TelephonyManager phone = (TelephonyManager) |
| 536 | mContext.getSystemService(Context.TELEPHONY_SERVICE); |
Ecco Park | 4fa1ab7 | 2016-10-24 13:04:52 -0700 | [diff] [blame] | 537 | CarrierConfigManager configManager = (CarrierConfigManager) |
| 538 | mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Anil Admal | e1539e8 | 2019-05-09 15:05:04 -0700 | [diff] [blame] | 539 | int ddSubId = SubscriptionManager.getDefaultDataSubscriptionId(); |
| 540 | String mccMnc = SubscriptionManager.isValidSubscriptionId(ddSubId) |
| 541 | ? phone.getSimOperator(ddSubId) : phone.getSimOperator(); |
Ecco Park | 4fa1ab7 | 2016-10-24 13:04:52 -0700 | [diff] [blame] | 542 | boolean isKeepLppProfile = false; |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 543 | if (!TextUtils.isEmpty(mccMnc)) { |
Joe Onorato | 0c48410 | 2016-02-01 18:04:24 -0800 | [diff] [blame] | 544 | if (DEBUG) Log.d(TAG, "SIM MCC/MNC is available: " + mccMnc); |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 545 | if (configManager != null) { |
Anil Admal | e1539e8 | 2019-05-09 15:05:04 -0700 | [diff] [blame] | 546 | PersistableBundle b = SubscriptionManager.isValidSubscriptionId(ddSubId) |
| 547 | ? configManager.getConfigForSubId(ddSubId) : null; |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 548 | if (b != null) { |
| 549 | isKeepLppProfile = |
| 550 | b.getBoolean(CarrierConfigManager.Gps.KEY_PERSIST_LPP_MODE_BOOL); |
Ecco Park | 4fa1ab7 | 2016-10-24 13:04:52 -0700 | [diff] [blame] | 551 | } |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 552 | } |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 553 | if (isKeepLppProfile) { |
| 554 | // load current properties for the carrier |
| 555 | mGnssConfiguration.loadPropertiesFromCarrierConfig(); |
| 556 | String lpp_profile = mGnssConfiguration.getLppProfile(); |
| 557 | // set the persist property LPP_PROFILE for the value |
| 558 | if (lpp_profile != null) { |
| 559 | SystemProperties.set(GnssConfiguration.LPP_PROFILE, lpp_profile); |
| 560 | } |
| 561 | } else { |
| 562 | // reset the persist property |
| 563 | SystemProperties.set(GnssConfiguration.LPP_PROFILE, ""); |
| 564 | } |
| 565 | reloadGpsProperties(); |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 566 | } else { |
Joe Onorato | 0c48410 | 2016-02-01 18:04:24 -0800 | [diff] [blame] | 567 | if (DEBUG) Log.d(TAG, "SIM MCC/MNC is still not available"); |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 568 | } |
| 569 | } |
| 570 | |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 571 | private void updateLowPowerMode() { |
Kweku Adams | b8bb9fb | 2019-08-28 07:45:00 -0700 | [diff] [blame] | 572 | // Disable GPS if we are in device idle mode and the device is stationary. |
| 573 | boolean disableGpsForPowerManager = mPowerManager.isDeviceIdleMode() && mIsDeviceStationary; |
| 574 | final PowerSaveState result = mPowerManager.getPowerSaveState(ServiceType.LOCATION); |
Kweku Adams | 731a103 | 2019-02-04 14:05:41 -0800 | [diff] [blame] | 575 | switch (result.locationMode) { |
Makoto Onuki | 57f0f55 | 2017-12-11 12:22:18 -0800 | [diff] [blame] | 576 | case PowerManager.LOCATION_MODE_GPS_DISABLED_WHEN_SCREEN_OFF: |
Kweku Adams | 5e0052b | 2019-02-22 15:17:52 -0800 | [diff] [blame] | 577 | case PowerManager.LOCATION_MODE_ALL_DISABLED_WHEN_SCREEN_OFF: |
Adam Lesinski | 87c17df | 2015-05-27 13:24:13 -0700 | [diff] [blame] | 578 | // If we are in battery saver mode and the screen is off, disable GPS. |
WyattRiley | b244607 | 2019-03-01 07:41:49 -0800 | [diff] [blame] | 579 | disableGpsForPowerManager |= |
| 580 | result.batterySaverEnabled && !mPowerManager.isInteractive(); |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 581 | break; |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 582 | } |
WyattRiley | b244607 | 2019-03-01 07:41:49 -0800 | [diff] [blame] | 583 | if (disableGpsForPowerManager != mDisableGpsForPowerManager) { |
| 584 | mDisableGpsForPowerManager = disableGpsForPowerManager; |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 585 | updateEnabled(); |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 586 | updateRequirements(); |
| 587 | } |
| 588 | } |
| 589 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 590 | public static boolean isSupported() { |
| 591 | return native_is_supported(); |
| 592 | } |
| 593 | |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 594 | private void reloadGpsProperties() { |
| 595 | mGnssConfiguration.reloadGpsProperties(); |
| 596 | setSuplHostPort(); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 597 | // TODO: we should get rid of C2K specific setting. |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 598 | mC2KServerHost = mGnssConfiguration.getC2KHost(); |
| 599 | mC2KServerPort = mGnssConfiguration.getC2KPort(TCP_MIN_PORT); |
| 600 | mNIHandler.setEmergencyExtensionSeconds(mGnssConfiguration.getEsExtensionSec()); |
| 601 | mSuplEsEnabled = mGnssConfiguration.getSuplEs(0) == 1; |
Anil Admal | e1539e8 | 2019-05-09 15:05:04 -0700 | [diff] [blame] | 602 | mNIHandler.setSuplEsEnabled(mSuplEsEnabled); |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 603 | if (mGnssVisibilityControl != null) { |
Anil Admal | e1539e8 | 2019-05-09 15:05:04 -0700 | [diff] [blame] | 604 | mGnssVisibilityControl.onConfigurationUpdated(mGnssConfiguration); |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 605 | } |
Colin Cross | 7c030ed | 2014-01-28 09:33:53 -0800 | [diff] [blame] | 606 | } |
| 607 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 608 | public GnssLocationProvider(Context context, LocationProviderManager locationProviderManager, |
Victoria Lease | 5cd731a | 2012-12-19 15:04:21 -0800 | [diff] [blame] | 609 | Looper looper) { |
Soonil Nagarkar | 0d77ea6 | 2019-01-31 14:36:56 -0800 | [diff] [blame] | 610 | super(context, locationProviderManager); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 611 | |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 612 | mLooper = looper; |
Mike Lockwood | 63598a0 | 2010-02-24 11:52:59 -0500 | [diff] [blame] | 613 | |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 614 | // Create a wake lock |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 615 | mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); |
| 616 | mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCK_KEY); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 617 | mWakeLock.setReferenceCounted(true); |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 618 | |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 619 | // Create a separate wake lock for psds downloader as it may be released due to timeout. |
| 620 | mDownloadPsdsWakeLock = mPowerManager.newWakeLock( |
Wei Wang | b71c049 | 2017-05-01 20:24:19 -0700 | [diff] [blame] | 621 | PowerManager.PARTIAL_WAKE_LOCK, DOWNLOAD_EXTRA_WAKELOCK_KEY); |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 622 | mDownloadPsdsWakeLock.setReferenceCounted(true); |
Wei Wang | b71c049 | 2017-05-01 20:24:19 -0700 | [diff] [blame] | 623 | |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 624 | mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 625 | mWakeupIntent = PendingIntent.getBroadcast(mContext, 0, new Intent(ALARM_WAKEUP), 0); |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 626 | mTimeoutIntent = PendingIntent.getBroadcast(mContext, 0, new Intent(ALARM_TIMEOUT), 0); |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 627 | |
Anil Admal | 312fddb | 2019-03-25 12:15:43 -0700 | [diff] [blame] | 628 | mNetworkConnectivityHandler = new GnssNetworkConnectivityHandler(context, |
| 629 | GnssLocationProvider.this::onNetworkAvailable, looper); |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 630 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 631 | // App ops service to keep track of who is accessing the GPS |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 632 | mAppOps = mContext.getSystemService(AppOpsManager.class); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 633 | |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 634 | // Battery statistics service to be notified when GPS turns on or off |
Dianne Hackborn | 91268cf | 2013-06-13 19:06:50 -0700 | [diff] [blame] | 635 | mBatteryStats = IBatteryStats.Stub.asInterface(ServiceManager.getService( |
| 636 | BatteryStats.SERVICE_NAME)); |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 637 | |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 638 | // Construct internal handler |
| 639 | mHandler = new ProviderHandler(looper); |
| 640 | |
| 641 | // Load GPS configuration and register listeners in the background: |
| 642 | // some operations, such as opening files and registering broadcast receivers, can take a |
| 643 | // relative long time, so the ctor() is kept to create objects needed by this instance, |
| 644 | // while IO initialization and registration is delegated to our internal handler |
| 645 | // this approach is just fine because events are posted to our handler anyway |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 646 | mGnssConfiguration = new GnssConfiguration(mContext); |
Anil Admal | 312fddb | 2019-03-25 12:15:43 -0700 | [diff] [blame] | 647 | mGnssCapabilitiesProvider = new GnssCapabilitiesProvider(); |
WyattRiley | d130931 | 2019-02-28 12:11:45 -0800 | [diff] [blame] | 648 | // Create a GPS net-initiated handler (also needed by handleInitialize) |
Tsuwei Chen | 3324e95 | 2014-09-07 01:30:42 -0700 | [diff] [blame] | 649 | mNIHandler = new GpsNetInitiatedHandler(context, |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 650 | mNetInitiatedListener, |
| 651 | mSuplEsEnabled); |
WyattRiley | d130931 | 2019-02-28 12:11:45 -0800 | [diff] [blame] | 652 | sendMessage(INITIALIZE_HANDLER, 0, null); |
Tsuwei Chen | 3324e95 | 2014-09-07 01:30:42 -0700 | [diff] [blame] | 653 | |
Anil Admal | 75b9fd6 | 2018-11-28 11:22:50 -0800 | [diff] [blame] | 654 | mGnssStatusListenerHelper = new GnssStatusListenerHelper(mContext, mHandler) { |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 655 | @Override |
| 656 | protected boolean isAvailableInPlatform() { |
destradaa | 13a60b0 | 2015-01-15 18:36:01 -0800 | [diff] [blame] | 657 | return isSupported(); |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | @Override |
| 661 | protected boolean isGpsEnabled() { |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 662 | return GnssLocationProvider.this.isGpsEnabled(); |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 663 | } |
| 664 | }; |
| 665 | |
Yu-Han Yang | 8de2150 | 2018-04-23 01:40:25 -0700 | [diff] [blame] | 666 | mGnssMeasurementsProvider = new GnssMeasurementsProvider(mContext, mHandler) { |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 667 | @Override |
| 668 | protected boolean isGpsEnabled() { |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 669 | return GnssLocationProvider.this.isGpsEnabled(); |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 670 | } |
| 671 | }; |
| 672 | |
Anil Admal | efd9dc6 | 2019-03-12 17:39:20 -0700 | [diff] [blame] | 673 | mGnssMeasurementCorrectionsProvider = new GnssMeasurementCorrectionsProvider(mHandler); |
| 674 | |
Anil Admal | 75b9fd6 | 2018-11-28 11:22:50 -0800 | [diff] [blame] | 675 | mGnssNavigationMessageProvider = new GnssNavigationMessageProvider(mContext, mHandler) { |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 676 | @Override |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 677 | protected boolean isGpsEnabled() { |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 678 | return GnssLocationProvider.this.isGpsEnabled(); |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 679 | } |
| 680 | }; |
Yu-Han Yang | a1862b5 | 2018-02-20 17:05:59 -0800 | [diff] [blame] | 681 | |
Anil Admal | 50ba15e | 2018-11-01 16:42:42 -0700 | [diff] [blame] | 682 | mGnssMetrics = new GnssMetrics(mBatteryStats); |
Yu-Han Yang | 66c7ea9 | 2018-03-11 17:17:15 -0700 | [diff] [blame] | 683 | mNtpTimeHelper = new NtpTimeHelper(mContext, looper, this); |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 684 | GnssSatelliteBlacklistHelper gnssSatelliteBlacklistHelper = |
| 685 | new GnssSatelliteBlacklistHelper(mContext, |
| 686 | looper, this); |
| 687 | mHandler.post(gnssSatelliteBlacklistHelper::updateSatelliteBlacklist); |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 688 | mGnssBatchingProvider = new GnssBatchingProvider(); |
Yu-Han Yang | 6dc9f05 | 2018-12-04 17:11:24 -0800 | [diff] [blame] | 689 | mGnssGeofenceProvider = new GnssGeofenceProvider(); |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 690 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 691 | mContext.registerReceiverAsUser(new BroadcastReceiver() { |
| 692 | @Override |
| 693 | public void onReceive(Context context, Intent intent) { |
| 694 | if (getSendingUserId() == UserHandle.USER_ALL) { |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 695 | mShutdown = true; |
| 696 | updateEnabled(); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 697 | } |
| 698 | } |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 699 | }, UserHandle.ALL, new IntentFilter(Intent.ACTION_SHUTDOWN), null, mHandler); |
| 700 | |
| 701 | mContext.getContentResolver().registerContentObserver( |
| 702 | Settings.Secure.getUriFor(Settings.Secure.LOCATION_MODE), |
| 703 | true, |
| 704 | new ContentObserver(mHandler) { |
| 705 | @Override |
| 706 | public void onChange(boolean selfChange) { |
| 707 | updateEnabled(); |
| 708 | } |
| 709 | }, UserHandle.USER_ALL); |
Mike Lockwood | d03ff94 | 2010-02-09 08:46:14 -0500 | [diff] [blame] | 710 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 711 | setProperties(PROPERTIES); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 712 | setEnabled(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 713 | } |
| 714 | |
Yu-Han Yang | a1862b5 | 2018-02-20 17:05:59 -0800 | [diff] [blame] | 715 | /** |
| 716 | * Implements {@link InjectNtpTimeCallback#injectTime} |
| 717 | */ |
| 718 | @Override |
| 719 | public void injectTime(long time, long timeReference, int uncertainty) { |
| 720 | native_inject_time(time, timeReference, uncertainty); |
| 721 | } |
| 722 | |
Anil Admal | 50ba15e | 2018-11-01 16:42:42 -0700 | [diff] [blame] | 723 | /** |
| 724 | * Implements {@link GnssNetworkConnectivityHandler.GnssNetworkListener#onNetworkAvailable()} |
| 725 | */ |
| 726 | private void onNetworkAvailable() { |
| 727 | mNtpTimeHelper.onNetworkAvailable(); |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 728 | if (mDownloadPsdsDataPending == STATE_PENDING_NETWORK) { |
| 729 | if (mSupportsPsds) { |
Anil Admal | 316f948 | 2019-02-12 18:57:18 -0800 | [diff] [blame] | 730 | // Download only if supported, (prevents an unnecessary on-boot download) |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 731 | psdsDownloadRequest(); |
destradaa | ef752b6 | 2015-04-17 13:10:47 -0700 | [diff] [blame] | 732 | } |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 733 | } |
| 734 | } |
Yu-Han Yang | 8de2150 | 2018-04-23 01:40:25 -0700 | [diff] [blame] | 735 | |
Yu-Han Yang | 53f4d6d | 2019-02-13 21:47:41 -0800 | [diff] [blame] | 736 | private void handleRequestLocation(boolean independentFromGnss, boolean isUserEmergency) { |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 737 | if (isRequestLocationRateLimited()) { |
| 738 | if (DEBUG) { |
| 739 | Log.d(TAG, "RequestLocation is denied due to too frequent requests."); |
| 740 | } |
| 741 | return; |
| 742 | } |
Yu-Han Yang | 74041ff | 2018-04-06 15:57:31 -0700 | [diff] [blame] | 743 | ContentResolver resolver = mContext.getContentResolver(); |
| 744 | long durationMillis = Settings.Global.getLong( |
| 745 | resolver, |
| 746 | Settings.Global.GNSS_HAL_LOCATION_REQUEST_DURATION_MILLIS, |
| 747 | LOCATION_UPDATE_DURATION_MILLIS); |
| 748 | if (durationMillis == 0) { |
| 749 | Log.i(TAG, "GNSS HAL location request is disabled by Settings."); |
| 750 | return; |
| 751 | } |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 752 | |
| 753 | LocationManager locationManager = (LocationManager) mContext.getSystemService( |
| 754 | Context.LOCATION_SERVICE); |
Yu-Han Yang | 0756138 | 2018-02-21 13:08:37 -0800 | [diff] [blame] | 755 | String provider; |
| 756 | LocationChangeListener locationListener; |
Anil Admal | b1c6c0d | 2019-06-20 12:00:16 -0700 | [diff] [blame] | 757 | LocationRequest locationRequest = new LocationRequest() |
| 758 | .setInterval(LOCATION_UPDATE_MIN_TIME_INTERVAL_MILLIS) |
| 759 | .setFastestInterval(LOCATION_UPDATE_MIN_TIME_INTERVAL_MILLIS); |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 760 | |
| 761 | if (independentFromGnss) { |
| 762 | // For fast GNSS TTFF |
Yu-Han Yang | 0756138 | 2018-02-21 13:08:37 -0800 | [diff] [blame] | 763 | provider = LocationManager.NETWORK_PROVIDER; |
| 764 | locationListener = mNetworkLocationListener; |
Anil Admal | b1c6c0d | 2019-06-20 12:00:16 -0700 | [diff] [blame] | 765 | locationRequest.setQuality(LocationRequest.POWER_LOW); |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 766 | } else { |
| 767 | // For Device-Based Hybrid (E911) |
Yu-Han Yang | 0756138 | 2018-02-21 13:08:37 -0800 | [diff] [blame] | 768 | provider = LocationManager.FUSED_PROVIDER; |
| 769 | locationListener = mFusedLocationListener; |
Anil Admal | b1c6c0d | 2019-06-20 12:00:16 -0700 | [diff] [blame] | 770 | locationRequest.setQuality(LocationRequest.ACCURACY_FINE); |
| 771 | } |
| 772 | |
| 773 | locationRequest.setProvider(provider); |
| 774 | |
| 775 | // Ignore location settings if in emergency mode. |
| 776 | if (isUserEmergency && mNIHandler.getInEmergency()) { |
| 777 | locationRequest.setLocationSettingsIgnored(true); |
| 778 | durationMillis *= EMERGENCY_LOCATION_UPDATE_DURATION_MULTIPLIER; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 779 | } |
Yu-Han Yang | 0756138 | 2018-02-21 13:08:37 -0800 | [diff] [blame] | 780 | |
| 781 | Log.i(TAG, |
Yu-Han Yang | 74041ff | 2018-04-06 15:57:31 -0700 | [diff] [blame] | 782 | String.format( |
| 783 | "GNSS HAL Requesting location updates from %s provider for %d millis.", |
| 784 | provider, durationMillis)); |
Yu-Han Yang | 53f4d6d | 2019-02-13 21:47:41 -0800 | [diff] [blame] | 785 | |
Yu-Han Yang | e684dda | 2018-05-24 10:29:39 -0700 | [diff] [blame] | 786 | try { |
Yu-Han Yang | 53f4d6d | 2019-02-13 21:47:41 -0800 | [diff] [blame] | 787 | locationManager.requestLocationUpdates(locationRequest, |
Yu-Han Yang | e684dda | 2018-05-24 10:29:39 -0700 | [diff] [blame] | 788 | locationListener, mHandler.getLooper()); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 789 | locationListener.mNumLocationUpdateRequest++; |
Yu-Han Yang | e684dda | 2018-05-24 10:29:39 -0700 | [diff] [blame] | 790 | mHandler.postDelayed(() -> { |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 791 | if (--locationListener.mNumLocationUpdateRequest == 0) { |
Yu-Han Yang | e684dda | 2018-05-24 10:29:39 -0700 | [diff] [blame] | 792 | Log.i(TAG, |
| 793 | String.format("Removing location updates from %s provider.", provider)); |
| 794 | locationManager.removeUpdates(locationListener); |
| 795 | } |
| 796 | }, durationMillis); |
| 797 | } catch (IllegalArgumentException e) { |
| 798 | Log.w(TAG, "Unable to request location.", e); |
| 799 | } |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | private void injectBestLocation(Location location) { |
Anil Admal | b1c6c0d | 2019-06-20 12:00:16 -0700 | [diff] [blame] | 803 | if (DEBUG) { |
| 804 | Log.d(TAG, "injectBestLocation: " + location); |
| 805 | } |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 806 | int gnssLocationFlags = LOCATION_HAS_LAT_LONG | |
| 807 | (location.hasAltitude() ? LOCATION_HAS_ALTITUDE : 0) | |
| 808 | (location.hasSpeed() ? LOCATION_HAS_SPEED : 0) | |
| 809 | (location.hasBearing() ? LOCATION_HAS_BEARING : 0) | |
| 810 | (location.hasAccuracy() ? LOCATION_HAS_HORIZONTAL_ACCURACY : 0) | |
| 811 | (location.hasVerticalAccuracy() ? LOCATION_HAS_VERTICAL_ACCURACY : 0) | |
| 812 | (location.hasSpeedAccuracy() ? LOCATION_HAS_SPEED_ACCURACY : 0) | |
| 813 | (location.hasBearingAccuracy() ? LOCATION_HAS_BEARING_ACCURACY : 0); |
| 814 | |
| 815 | double latitudeDegrees = location.getLatitude(); |
| 816 | double longitudeDegrees = location.getLongitude(); |
| 817 | double altitudeMeters = location.getAltitude(); |
| 818 | float speedMetersPerSec = location.getSpeed(); |
| 819 | float bearingDegrees = location.getBearing(); |
| 820 | float horizontalAccuracyMeters = location.getAccuracy(); |
| 821 | float verticalAccuracyMeters = location.getVerticalAccuracyMeters(); |
| 822 | float speedAccuracyMetersPerSecond = location.getSpeedAccuracyMetersPerSecond(); |
| 823 | float bearingAccuracyDegrees = location.getBearingAccuracyDegrees(); |
| 824 | long timestamp = location.getTime(); |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 825 | |
Pierre Fite-Georgel | 9e96c57 | 2019-02-25 16:12:53 -0800 | [diff] [blame] | 826 | int elapsedRealtimeFlags = ELAPSED_REALTIME_HAS_TIMESTAMP_NS |
| 827 | | (location.hasElapsedRealtimeUncertaintyNanos() |
| 828 | ? ELAPSED_REALTIME_HAS_TIME_UNCERTAINTY_NS : 0); |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 829 | long elapsedRealtimeNanos = location.getElapsedRealtimeNanos(); |
Yu-Han Yang | 3cd9a86 | 2019-03-25 17:00:03 -0700 | [diff] [blame] | 830 | double elapsedRealtimeUncertaintyNanos = location.getElapsedRealtimeUncertaintyNanos(); |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 831 | |
| 832 | native_inject_best_location( |
| 833 | gnssLocationFlags, latitudeDegrees, longitudeDegrees, |
| 834 | altitudeMeters, speedMetersPerSec, bearingDegrees, |
| 835 | horizontalAccuracyMeters, verticalAccuracyMeters, |
| 836 | speedAccuracyMetersPerSecond, bearingAccuracyDegrees, timestamp, |
Pierre Fite-Georgel | 9e96c57 | 2019-02-25 16:12:53 -0800 | [diff] [blame] | 837 | elapsedRealtimeFlags, elapsedRealtimeNanos, elapsedRealtimeUncertaintyNanos); |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 838 | } |
| 839 | |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 840 | /** Returns true if the location request is too frequent. */ |
| 841 | private boolean isRequestLocationRateLimited() { |
Anil Admal | 316f948 | 2019-02-12 18:57:18 -0800 | [diff] [blame] | 842 | // TODO: implement exponential backoff. |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 843 | return false; |
| 844 | } |
| 845 | |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 846 | private void handleDownloadPsdsData() { |
| 847 | if (!mSupportsPsds) { |
| 848 | // native code reports psds not supported, don't try |
| 849 | Log.d(TAG, "handleDownloadPsdsData() called when PSDS not supported"); |
Wyatt Riley | 0d6e54e2 | 2016-10-05 12:03:03 -0700 | [diff] [blame] | 850 | return; |
| 851 | } |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 852 | if (mDownloadPsdsDataPending == STATE_DOWNLOADING) { |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 853 | // already downloading data |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 854 | return; |
| 855 | } |
Anil Admal | 50ba15e | 2018-11-01 16:42:42 -0700 | [diff] [blame] | 856 | if (!mNetworkConnectivityHandler.isDataNetworkConnected()) { |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 857 | // try again when network is up |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 858 | mDownloadPsdsDataPending = STATE_PENDING_NETWORK; |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 859 | return; |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 860 | } |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 861 | mDownloadPsdsDataPending = STATE_DOWNLOADING; |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 862 | |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 863 | synchronized (mLock) { |
| 864 | // hold wake lock while task runs |
| 865 | mDownloadPsdsWakeLock.acquire(DOWNLOAD_PSDS_DATA_TIMEOUT_MS); |
| 866 | } |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 867 | Log.i(TAG, "WakeLock acquired by handleDownloadPsdsData()"); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 868 | AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> { |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 869 | GpsPsdsDownloader psdsDownloader = new GpsPsdsDownloader( |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 870 | mGnssConfiguration.getProperties()); |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 871 | byte[] data = psdsDownloader.downloadPsdsData(); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 872 | if (data != null) { |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 873 | if (DEBUG) Log.d(TAG, "calling native_inject_psds_data"); |
| 874 | native_inject_psds_data(data, data.length); |
| 875 | mPsdsBackOff.reset(); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 876 | } |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 877 | |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 878 | sendMessage(DOWNLOAD_PSDS_DATA_FINISHED, 0, null); |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 879 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 880 | if (data == null) { |
| 881 | // try again later |
| 882 | // since this is delayed and not urgent we do not hold a wake lock here |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 883 | mHandler.sendEmptyMessageDelayed(DOWNLOAD_PSDS_DATA, |
| 884 | mPsdsBackOff.nextBackoffMillis()); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 885 | } |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 886 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 887 | // Release wake lock held by task, synchronize on mLock in case multiple |
| 888 | // download tasks overrun. |
| 889 | synchronized (mLock) { |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 890 | if (mDownloadPsdsWakeLock.isHeld()) { |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 891 | // This wakelock may have time-out, if a timeout was specified. |
| 892 | // Catch (and ignore) any timeout exceptions. |
| 893 | try { |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 894 | mDownloadPsdsWakeLock.release(); |
| 895 | if (DEBUG) Log.d(TAG, "WakeLock released by handleDownloadPsdsData()"); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 896 | } catch (Exception e) { |
| 897 | Log.i(TAG, "Wakelock timeout & release race exception in " |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 898 | + "handleDownloadPsdsData()", e); |
Wei Wang | b71c049 | 2017-05-01 20:24:19 -0700 | [diff] [blame] | 899 | } |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 900 | } else { |
| 901 | Log.e(TAG, "WakeLock expired before release in " |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 902 | + "handleDownloadPsdsData()"); |
Wei Wang | c5706f6 | 2017-04-18 11:26:26 -0700 | [diff] [blame] | 903 | } |
Jeff Brown | 028872f | 2012-08-25 13:07:01 -0700 | [diff] [blame] | 904 | } |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 905 | }); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 906 | } |
| 907 | |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 908 | private void handleUpdateLocation(Location location) { |
Mike Lockwood | d26ce0d | 2009-06-11 12:25:46 -0400 | [diff] [blame] | 909 | if (location.hasAccuracy()) { |
Anil Admal | b1c6c0d | 2019-06-20 12:00:16 -0700 | [diff] [blame] | 910 | if (DEBUG) { |
| 911 | Log.d(TAG, "injectLocation: " + location); |
| 912 | } |
Mike Lockwood | d26ce0d | 2009-06-11 12:25:46 -0400 | [diff] [blame] | 913 | native_inject_location(location.getLatitude(), location.getLongitude(), |
| 914 | location.getAccuracy()); |
| 915 | } |
Mike Lockwood | fd6e5f0 | 2009-05-21 11:28:20 -0400 | [diff] [blame] | 916 | } |
| 917 | |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 918 | private void setSuplHostPort() { |
| 919 | mSuplServerHost = mGnssConfiguration.getSuplHost(); |
| 920 | mSuplServerPort = mGnssConfiguration.getSuplPort(TCP_MIN_PORT); |
Tsuwei Chen | 678c13c | 2014-09-22 17:48:41 -0700 | [diff] [blame] | 921 | if (mSuplServerHost != null |
| 922 | && mSuplServerPort > TCP_MIN_PORT |
| 923 | && mSuplServerPort <= TCP_MAX_PORT) { |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 924 | native_set_agps_server(GnssNetworkConnectivityHandler.AGPS_TYPE_SUPL, |
| 925 | mSuplServerHost, mSuplServerPort); |
Tsuwei Chen | 678c13c | 2014-09-22 17:48:41 -0700 | [diff] [blame] | 926 | } |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 927 | } |
| 928 | |
Tsuwei Chen | 462bcd8 | 2014-09-17 12:28:49 -0700 | [diff] [blame] | 929 | /** |
| 930 | * Checks what SUPL mode to use, according to the AGPS mode as well as the |
| 931 | * allowed mode from properties. |
| 932 | * |
Tsuwei Chen | 462bcd8 | 2014-09-17 12:28:49 -0700 | [diff] [blame] | 933 | * @param agpsEnabled whether AGPS is enabled by settings value |
Tsuwei Chen | 462bcd8 | 2014-09-17 12:28:49 -0700 | [diff] [blame] | 934 | * @return SUPL mode (MSA vs MSB vs STANDALONE) |
| 935 | */ |
Yu-Han Yang | 6a5f0b7 | 2019-01-24 18:34:28 -0800 | [diff] [blame] | 936 | private int getSuplMode(boolean agpsEnabled) { |
Tsuwei Chen | 462bcd8 | 2014-09-17 12:28:49 -0700 | [diff] [blame] | 937 | if (agpsEnabled) { |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 938 | int suplMode = mGnssConfiguration.getSuplMode(0); |
| 939 | if (suplMode == 0) { |
| 940 | return GPS_POSITION_MODE_STANDALONE; |
Tsuwei Chen | 462bcd8 | 2014-09-17 12:28:49 -0700 | [diff] [blame] | 941 | } |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 942 | |
destradaa | bfb3bdb | 2015-04-29 14:42:35 -0700 | [diff] [blame] | 943 | // MS-Based is the preferred mode for Assisted-GPS position computation, so we favor |
| 944 | // such mode when it is available |
| 945 | if (hasCapability(GPS_CAPABILITY_MSB) && (suplMode & AGPS_SUPL_MODE_MSB) != 0) { |
| 946 | return GPS_POSITION_MODE_MS_BASED; |
| 947 | } |
Tsuwei Chen | 462bcd8 | 2014-09-17 12:28:49 -0700 | [diff] [blame] | 948 | } |
| 949 | return GPS_POSITION_MODE_STANDALONE; |
| 950 | } |
| 951 | |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 952 | private void setGpsEnabled(boolean enabled) { |
| 953 | synchronized (mLock) { |
| 954 | mGpsEnabled = enabled; |
| 955 | } |
| 956 | } |
| 957 | |
| 958 | private void handleEnable() { |
| 959 | if (DEBUG) Log.d(TAG, "handleEnable"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 960 | |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 961 | boolean inited = native_init(); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 962 | |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 963 | if (inited) { |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 964 | setGpsEnabled(true); |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 965 | mSupportsPsds = native_supports_psds(); |
Tsuwei Chen | 678c13c | 2014-09-22 17:48:41 -0700 | [diff] [blame] | 966 | |
| 967 | // 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] | 968 | if (mSuplServerHost != null) { |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 969 | native_set_agps_server(GnssNetworkConnectivityHandler.AGPS_TYPE_SUPL, |
| 970 | mSuplServerHost, mSuplServerPort); |
Mike Lockwood | 734d603 | 2009-07-28 18:30:25 -0700 | [diff] [blame] | 971 | } |
| 972 | if (mC2KServerHost != null) { |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 973 | native_set_agps_server(GnssNetworkConnectivityHandler.AGPS_TYPE_C2K, |
| 974 | mC2KServerHost, mC2KServerPort); |
Mike Lockwood | 734d603 | 2009-07-28 18:30:25 -0700 | [diff] [blame] | 975 | } |
destradaa | 13a60b0 | 2015-01-15 18:36:01 -0800 | [diff] [blame] | 976 | |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 977 | mGnssMeasurementsProvider.onGpsEnabledChanged(); |
| 978 | mGnssNavigationMessageProvider.onGpsEnabledChanged(); |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 979 | mGnssBatchingProvider.enable(); |
Anil Admal | 138cdc3 | 2019-04-16 10:07:43 -0700 | [diff] [blame] | 980 | if (mGnssVisibilityControl != null) { |
Anil Admal | 8b83dc1 | 2019-06-12 13:55:42 -0700 | [diff] [blame] | 981 | mGnssVisibilityControl.onGpsEnabledChanged(/* isEnabled= */ true); |
Anil Admal | 138cdc3 | 2019-04-16 10:07:43 -0700 | [diff] [blame] | 982 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 983 | } else { |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 984 | setGpsEnabled(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 985 | Log.w(TAG, "Failed to enable location provider"); |
| 986 | } |
| 987 | } |
| 988 | |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 989 | private void handleDisable() { |
| 990 | if (DEBUG) Log.d(TAG, "handleDisable"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 991 | |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 992 | setGpsEnabled(false); |
David Christie | 3bc2614 | 2013-12-19 14:53:44 -0800 | [diff] [blame] | 993 | updateClientUids(new WorkSource()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 994 | stopNavigating(); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 995 | mAlarmManager.cancel(mWakeupIntent); |
| 996 | mAlarmManager.cancel(mTimeoutIntent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 997 | |
Anil Admal | 138cdc3 | 2019-04-16 10:07:43 -0700 | [diff] [blame] | 998 | if (mGnssVisibilityControl != null) { |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 999 | mGnssVisibilityControl.onGpsEnabledChanged(/* isEnabled= */ false); |
Anil Admal | 138cdc3 | 2019-04-16 10:07:43 -0700 | [diff] [blame] | 1000 | } |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 1001 | mGnssBatchingProvider.disable(); |
Mike Lockwood | cf1d8cb | 2010-01-20 10:14:54 -0500 | [diff] [blame] | 1002 | // do this before releasing wakelock |
| 1003 | native_cleanup(); |
destradaa | 13a60b0 | 2015-01-15 18:36:01 -0800 | [diff] [blame] | 1004 | |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 1005 | mGnssMeasurementsProvider.onGpsEnabledChanged(); |
| 1006 | mGnssNavigationMessageProvider.onGpsEnabledChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1007 | } |
| 1008 | |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 1009 | private void updateEnabled() { |
Tyler Trephan | 037ef9d | 2019-05-17 13:41:18 -0700 | [diff] [blame] | 1010 | // Generally follow location setting for current user |
| 1011 | boolean enabled = mContext.getSystemService(LocationManager.class) |
| 1012 | .isLocationEnabledForUser(UserHandle.CURRENT); |
WyattRiley | b244607 | 2019-03-01 07:41:49 -0800 | [diff] [blame] | 1013 | |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 1014 | // ... but disable if PowerManager overrides |
| 1015 | enabled &= !mDisableGpsForPowerManager; |
WyattRiley | b244607 | 2019-03-01 07:41:49 -0800 | [diff] [blame] | 1016 | |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 1017 | // .. but enable anyway, if there's an active settings-ignored request (e.g. ELS) |
| 1018 | enabled |= (mProviderRequest != null && mProviderRequest.reportLocation |
| 1019 | && mProviderRequest.locationSettingsIgnored); |
WyattRiley | b244607 | 2019-03-01 07:41:49 -0800 | [diff] [blame] | 1020 | |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 1021 | // ... and, finally, disable anyway, if device is being shut down |
| 1022 | enabled &= !mShutdown; |
WyattRiley | b244607 | 2019-03-01 07:41:49 -0800 | [diff] [blame] | 1023 | |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 1024 | if (enabled == isGpsEnabled()) { |
| 1025 | return; |
| 1026 | } |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 1027 | |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 1028 | if (enabled) { |
| 1029 | handleEnable(); |
| 1030 | } else { |
| 1031 | handleDisable(); |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 1032 | } |
| 1033 | } |
| 1034 | |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 1035 | private boolean isGpsEnabled() { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1036 | synchronized (mLock) { |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 1037 | return mGpsEnabled; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1038 | } |
Mike Lockwood | d03ff94 | 2010-02-09 08:46:14 -0500 | [diff] [blame] | 1039 | } |
| 1040 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1041 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1042 | public int getStatus(Bundle extras) { |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 1043 | mLocationExtras.setBundle(extras); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1044 | return mStatus; |
| 1045 | } |
| 1046 | |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 1047 | private void updateStatus(int status) { |
| 1048 | if (status != mStatus) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1049 | mStatus = status; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1050 | mStatusUpdateTime = SystemClock.elapsedRealtime(); |
| 1051 | } |
| 1052 | } |
| 1053 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1054 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1055 | public long getStatusUpdateTime() { |
| 1056 | return mStatusUpdateTime; |
| 1057 | } |
| 1058 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1059 | @Override |
| 1060 | public void setRequest(ProviderRequest request, WorkSource source) { |
| 1061 | sendMessage(SET_REQUEST, 0, new GpsRequest(request, source)); |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 1062 | } |
| 1063 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1064 | private void handleSetRequest(ProviderRequest request, WorkSource source) { |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 1065 | mProviderRequest = request; |
| 1066 | mWorkSource = source; |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 1067 | updateEnabled(); |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 1068 | updateRequirements(); |
| 1069 | } |
| 1070 | |
| 1071 | // Called when the requirements for GPS may have changed |
| 1072 | private void updateRequirements() { |
| 1073 | if (mProviderRequest == null || mWorkSource == null) { |
| 1074 | return; |
| 1075 | } |
| 1076 | |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 1077 | if (DEBUG) Log.d(TAG, "setRequest " + mProviderRequest); |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 1078 | if (mProviderRequest.reportLocation && isGpsEnabled()) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1079 | // update client uids |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 1080 | updateClientUids(mWorkSource); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1081 | |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 1082 | mFixInterval = (int) mProviderRequest.interval; |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1083 | mLowPowerMode = mProviderRequest.lowPowerMode; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1084 | // check for overflow |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 1085 | if (mFixInterval != mProviderRequest.interval) { |
| 1086 | Log.w(TAG, "interval overflow: " + mProviderRequest.interval); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1087 | mFixInterval = Integer.MAX_VALUE; |
| 1088 | } |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 1089 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1090 | // apply request to GPS engine |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 1091 | if (mStarted && hasCapability(GPS_CAPABILITY_SCHEDULING)) { |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1092 | // change period and/or lowPowerMode |
Yu-Han Yang | c8b9ff7 | 2018-04-17 00:47:24 -0700 | [diff] [blame] | 1093 | if (!setPositionMode(mPositionMode, GPS_POSITION_RECURRENCE_PERIODIC, |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1094 | mFixInterval, 0, 0, mLowPowerMode)) { |
| 1095 | Log.e(TAG, "set_position_mode failed in updateRequirements"); |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 1096 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1097 | } else if (!mStarted) { |
| 1098 | // start GPS |
Yu-Han Yang | 6a5f0b7 | 2019-01-24 18:34:28 -0800 | [diff] [blame] | 1099 | startNavigating(); |
gomo | 300b240 | 2017-12-13 19:04:12 -0800 | [diff] [blame] | 1100 | } else { |
| 1101 | // GNSS Engine is already ON, but no GPS_CAPABILITY_SCHEDULING |
| 1102 | mAlarmManager.cancel(mTimeoutIntent); |
| 1103 | if (mFixInterval >= NO_FIX_TIMEOUT) { |
| 1104 | // set timer to give up if we do not receive a fix within NO_FIX_TIMEOUT |
| 1105 | // and our fix interval is not short |
| 1106 | mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1107 | SystemClock.elapsedRealtime() + NO_FIX_TIMEOUT, mTimeoutIntent); |
| 1108 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1109 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1110 | } else { |
Dianne Hackborn | 002a54e | 2013-01-10 17:34:55 -0800 | [diff] [blame] | 1111 | updateClientUids(new WorkSource()); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1112 | |
| 1113 | stopNavigating(); |
| 1114 | mAlarmManager.cancel(mWakeupIntent); |
| 1115 | mAlarmManager.cancel(mTimeoutIntent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1116 | } |
| 1117 | } |
| 1118 | |
Yu-Han Yang | c8b9ff7 | 2018-04-17 00:47:24 -0700 | [diff] [blame] | 1119 | private boolean setPositionMode(int mode, int recurrence, int minInterval, |
| 1120 | int preferredAccuracy, int preferredTime, boolean lowPowerMode) { |
| 1121 | GnssPositionMode positionMode = new GnssPositionMode(mode, recurrence, minInterval, |
| 1122 | preferredAccuracy, preferredTime, lowPowerMode); |
| 1123 | if (mLastPositionMode != null && mLastPositionMode.equals(positionMode)) { |
| 1124 | return true; |
| 1125 | } |
| 1126 | |
| 1127 | boolean result = native_set_position_mode(mode, recurrence, minInterval, |
| 1128 | preferredAccuracy, preferredTime, lowPowerMode); |
| 1129 | if (result) { |
| 1130 | mLastPositionMode = positionMode; |
| 1131 | } else { |
| 1132 | mLastPositionMode = null; |
| 1133 | } |
| 1134 | return result; |
| 1135 | } |
| 1136 | |
Dianne Hackborn | 002a54e | 2013-01-10 17:34:55 -0800 | [diff] [blame] | 1137 | private void updateClientUids(WorkSource source) { |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 1138 | if (source.equals(mClientSource)) { |
Victoria Lease | ea78b85 | 2013-01-15 10:39:28 -0800 | [diff] [blame] | 1139 | return; |
| 1140 | } |
Dianne Hackborn | 002a54e | 2013-01-10 17:34:55 -0800 | [diff] [blame] | 1141 | |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 1142 | // (1) Inform BatteryStats that the list of IDs we're tracking changed. |
| 1143 | try { |
| 1144 | mBatteryStats.noteGpsChanged(mClientSource, source); |
| 1145 | } catch (RemoteException e) { |
| 1146 | Log.w(TAG, "RemoteException", e); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1147 | } |
| 1148 | |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 1149 | // (2) Inform AppOps service about the list of changes to UIDs. |
| 1150 | |
| 1151 | List<WorkChain>[] diffs = WorkSource.diffChains(mClientSource, source); |
| 1152 | if (diffs != null) { |
| 1153 | List<WorkChain> newChains = diffs[0]; |
| 1154 | List<WorkChain> goneChains = diffs[1]; |
| 1155 | |
| 1156 | if (newChains != null) { |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1157 | for (WorkChain newChain : newChains) { |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 1158 | mAppOps.startOpNoThrow(AppOpsManager.OP_GPS, newChain.getAttributionUid(), |
| 1159 | newChain.getAttributionTag()); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 1160 | } |
| 1161 | } |
| 1162 | |
| 1163 | if (goneChains != null) { |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1164 | for (WorkChain goneChain : goneChains) { |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 1165 | mAppOps.finishOp(AppOpsManager.OP_GPS, goneChain.getAttributionUid(), |
| 1166 | goneChain.getAttributionTag()); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 1167 | } |
| 1168 | } |
| 1169 | |
| 1170 | mClientSource.transferWorkChains(source); |
| 1171 | } |
| 1172 | |
| 1173 | // Update the flat UIDs and names list and inform app-ops of all changes. |
| 1174 | WorkSource[] changes = mClientSource.setReturningDiffs(source); |
| 1175 | if (changes != null) { |
| 1176 | WorkSource newWork = changes[0]; |
| 1177 | WorkSource goneWork = changes[1]; |
| 1178 | |
| 1179 | // Update sources that were not previously tracked. |
| 1180 | if (newWork != null) { |
| 1181 | for (int i = 0; i < newWork.size(); i++) { |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 1182 | mAppOps.startOpNoThrow(AppOpsManager.OP_GPS, |
| 1183 | newWork.get(i), newWork.getName(i)); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | // Update sources that are no longer tracked. |
| 1188 | if (goneWork != null) { |
| 1189 | for (int i = 0; i < goneWork.size(); i++) { |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 1190 | mAppOps.finishOp(AppOpsManager.OP_GPS, goneWork.get(i), goneWork.getName(i)); |
Dianne Hackborn | 2e41842 | 2009-06-22 20:00:17 -0700 | [diff] [blame] | 1191 | } |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 1192 | } |
| 1193 | } |
| 1194 | } |
| 1195 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1196 | @Override |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1197 | public void sendExtraCommand(String command, Bundle extras) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1198 | |
Mike Lockwood | 63aa5a6 | 2010-04-14 19:21:31 -0400 | [diff] [blame] | 1199 | long identity = Binder.clearCallingIdentity(); |
Peter Visontay | b25db36 | 2017-11-01 18:18:12 +0000 | [diff] [blame] | 1200 | try { |
Peter Visontay | b25db36 | 2017-11-01 18:18:12 +0000 | [diff] [blame] | 1201 | if ("delete_aiding_data".equals(command)) { |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1202 | deleteAidingData(extras); |
Peter Visontay | b25db36 | 2017-11-01 18:18:12 +0000 | [diff] [blame] | 1203 | } else if ("force_time_injection".equals(command)) { |
| 1204 | requestUtcTime(); |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 1205 | } else if ("force_psds_injection".equals(command)) { |
| 1206 | if (mSupportsPsds) { |
| 1207 | psdsDownloadRequest(); |
Peter Visontay | b25db36 | 2017-11-01 18:18:12 +0000 | [diff] [blame] | 1208 | } |
| 1209 | } else { |
| 1210 | Log.w(TAG, "sendExtraCommand: unknown command " + command); |
Mike Lockwood | 93bc44d | 2009-05-20 16:58:22 -0400 | [diff] [blame] | 1211 | } |
Peter Visontay | b25db36 | 2017-11-01 18:18:12 +0000 | [diff] [blame] | 1212 | } finally { |
| 1213 | Binder.restoreCallingIdentity(identity); |
Mike Lockwood | 93bc44d | 2009-05-20 16:58:22 -0400 | [diff] [blame] | 1214 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1215 | } |
| 1216 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1217 | private void deleteAidingData(Bundle extras) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1218 | int flags; |
| 1219 | |
| 1220 | if (extras == null) { |
| 1221 | flags = GPS_DELETE_ALL; |
| 1222 | } else { |
| 1223 | flags = 0; |
| 1224 | if (extras.getBoolean("ephemeris")) flags |= GPS_DELETE_EPHEMERIS; |
| 1225 | if (extras.getBoolean("almanac")) flags |= GPS_DELETE_ALMANAC; |
| 1226 | if (extras.getBoolean("position")) flags |= GPS_DELETE_POSITION; |
| 1227 | if (extras.getBoolean("time")) flags |= GPS_DELETE_TIME; |
| 1228 | if (extras.getBoolean("iono")) flags |= GPS_DELETE_IONO; |
| 1229 | if (extras.getBoolean("utc")) flags |= GPS_DELETE_UTC; |
| 1230 | if (extras.getBoolean("health")) flags |= GPS_DELETE_HEALTH; |
| 1231 | if (extras.getBoolean("svdir")) flags |= GPS_DELETE_SVDIR; |
| 1232 | if (extras.getBoolean("svsteer")) flags |= GPS_DELETE_SVSTEER; |
| 1233 | if (extras.getBoolean("sadata")) flags |= GPS_DELETE_SADATA; |
| 1234 | if (extras.getBoolean("rti")) flags |= GPS_DELETE_RTI; |
| 1235 | if (extras.getBoolean("celldb-info")) flags |= GPS_DELETE_CELLDB_INFO; |
| 1236 | if (extras.getBoolean("all")) flags |= GPS_DELETE_ALL; |
| 1237 | } |
| 1238 | |
| 1239 | if (flags != 0) { |
| 1240 | native_delete_aiding_data(flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1241 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1242 | } |
| 1243 | |
Yu-Han Yang | 6a5f0b7 | 2019-01-24 18:34:28 -0800 | [diff] [blame] | 1244 | private void startNavigating() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1245 | if (!mStarted) { |
Yu-Han Yang | 6a5f0b7 | 2019-01-24 18:34:28 -0800 | [diff] [blame] | 1246 | if (DEBUG) Log.d(TAG, "startNavigating"); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1247 | mTimeToFirstFix = 0; |
| 1248 | mLastFixTime = 0; |
WyattRiley | ba6072f | 2019-04-18 07:37:52 -0700 | [diff] [blame] | 1249 | setStarted(true); |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 1250 | mPositionMode = GPS_POSITION_MODE_STANDALONE; |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1251 | // Notify about suppressed output, if speed limit was previously exceeded. |
| 1252 | // Elsewhere, we check again with every speed output reported. |
| 1253 | if (mItarSpeedLimitExceeded) { |
| 1254 | Log.i(TAG, "startNavigating with ITAR limit in place. Output limited " + |
| 1255 | "until slow enough speed reported."); |
| 1256 | } |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 1257 | |
Tsuwei Chen | 462bcd8 | 2014-09-17 12:28:49 -0700 | [diff] [blame] | 1258 | boolean agpsEnabled = |
| 1259 | (Settings.Global.getInt(mContext.getContentResolver(), |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1260 | Settings.Global.ASSISTED_GPS_ENABLED, 1) != 0); |
Yu-Han Yang | 6a5f0b7 | 2019-01-24 18:34:28 -0800 | [diff] [blame] | 1261 | mPositionMode = getSuplMode(agpsEnabled); |
Mike Lockwood | bcab8df | 2009-06-25 16:39:09 -0400 | [diff] [blame] | 1262 | |
Stan Chesnutt | 1d72d8c | 2013-04-15 19:18:02 -0700 | [diff] [blame] | 1263 | if (DEBUG) { |
| 1264 | String mode; |
| 1265 | |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1266 | switch (mPositionMode) { |
Stan Chesnutt | 1d72d8c | 2013-04-15 19:18:02 -0700 | [diff] [blame] | 1267 | case GPS_POSITION_MODE_STANDALONE: |
| 1268 | mode = "standalone"; |
| 1269 | break; |
| 1270 | case GPS_POSITION_MODE_MS_ASSISTED: |
| 1271 | mode = "MS_ASSISTED"; |
| 1272 | break; |
| 1273 | case GPS_POSITION_MODE_MS_BASED: |
| 1274 | mode = "MS_BASED"; |
| 1275 | break; |
| 1276 | default: |
| 1277 | mode = "unknown"; |
| 1278 | break; |
| 1279 | } |
| 1280 | Log.d(TAG, "setting position_mode to " + mode); |
| 1281 | } |
| 1282 | |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 1283 | int interval = (hasCapability(GPS_CAPABILITY_SCHEDULING) ? mFixInterval : 1000); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1284 | mLowPowerMode = mProviderRequest.lowPowerMode; |
Yu-Han Yang | c8b9ff7 | 2018-04-17 00:47:24 -0700 | [diff] [blame] | 1285 | if (!setPositionMode(mPositionMode, GPS_POSITION_RECURRENCE_PERIODIC, |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1286 | interval, 0, 0, mLowPowerMode)) { |
WyattRiley | ba6072f | 2019-04-18 07:37:52 -0700 | [diff] [blame] | 1287 | setStarted(false); |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 1288 | Log.e(TAG, "set_position_mode failed in startNavigating()"); |
| 1289 | return; |
| 1290 | } |
| 1291 | if (!native_start()) { |
WyattRiley | ba6072f | 2019-04-18 07:37:52 -0700 | [diff] [blame] | 1292 | setStarted(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1293 | Log.e(TAG, "native_start failed in startNavigating()"); |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 1294 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1295 | } |
| 1296 | |
| 1297 | // reset SV count to zero |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 1298 | updateStatus(LocationProvider.TEMPORARILY_UNAVAILABLE); |
| 1299 | mLocationExtras.reset(); |
Yipeng Cao | 282b594 | 2017-05-17 20:31:39 -0700 | [diff] [blame] | 1300 | mFixRequestTime = SystemClock.elapsedRealtime(); |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 1301 | if (!hasCapability(GPS_CAPABILITY_SCHEDULING)) { |
| 1302 | // set timer to give up if we do not receive a fix within NO_FIX_TIMEOUT |
| 1303 | // and our fix interval is not short |
| 1304 | if (mFixInterval >= NO_FIX_TIMEOUT) { |
| 1305 | mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, |
| 1306 | SystemClock.elapsedRealtime() + NO_FIX_TIMEOUT, mTimeoutIntent); |
| 1307 | } |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 1308 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1309 | } |
| 1310 | } |
| 1311 | |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 1312 | private void stopNavigating() { |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 1313 | if (DEBUG) Log.d(TAG, "stopNavigating"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1314 | if (mStarted) { |
WyattRiley | ba6072f | 2019-04-18 07:37:52 -0700 | [diff] [blame] | 1315 | setStarted(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1316 | native_stop(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1317 | mLastFixTime = 0; |
Yu-Han Yang | a50cd60 | 2018-08-28 12:33:24 -0700 | [diff] [blame] | 1318 | // native_stop() may reset the position mode in hardware. |
| 1319 | mLastPositionMode = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1320 | |
| 1321 | // reset SV count to zero |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 1322 | updateStatus(LocationProvider.TEMPORARILY_UNAVAILABLE); |
| 1323 | mLocationExtras.reset(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1324 | } |
| 1325 | } |
| 1326 | |
WyattRiley | ba6072f | 2019-04-18 07:37:52 -0700 | [diff] [blame] | 1327 | private void setStarted(boolean started) { |
| 1328 | if (mStarted != started) { |
| 1329 | mStarted = started; |
| 1330 | mStartedChangedElapsedRealtime = SystemClock.elapsedRealtime(); |
| 1331 | } |
| 1332 | } |
| 1333 | |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 1334 | private void hibernate() { |
| 1335 | // stop GPS until our next fix interval arrives |
| 1336 | stopNavigating(); |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 1337 | mAlarmManager.cancel(mTimeoutIntent); |
| 1338 | mAlarmManager.cancel(mWakeupIntent); |
| 1339 | long now = SystemClock.elapsedRealtime(); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1340 | mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, now + mFixInterval, mWakeupIntent); |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 1341 | } |
| 1342 | |
| 1343 | private boolean hasCapability(int capability) { |
Anil Admal | 312fddb | 2019-03-25 12:15:43 -0700 | [diff] [blame] | 1344 | return (mTopHalCapabilities & capability) != 0; |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 1345 | } |
| 1346 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1347 | @NativeEntryPoint |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 1348 | private void reportLocation(boolean hasLatLong, Location location) { |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1349 | sendMessage(REPORT_LOCATION, hasLatLong ? 1 : 0, location); |
| 1350 | } |
| 1351 | |
| 1352 | private void handleReportLocation(boolean hasLatLong, Location location) { |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 1353 | if (location.hasSpeed()) { |
| 1354 | mItarSpeedLimitExceeded = location.getSpeed() > ITAR_SPEED_LIMIT_METERS_PER_SECOND; |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | if (mItarSpeedLimitExceeded) { |
| 1358 | Log.i(TAG, "Hal reported a speed in excess of ITAR limit." + |
| 1359 | " GPS/GNSS Navigation output blocked."); |
Siddharth Ray | 53ddc80 | 2018-03-16 12:01:52 -0700 | [diff] [blame] | 1360 | if (mStarted) { |
| 1361 | mGnssMetrics.logReceivedLocationStatus(false); |
| 1362 | } |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1363 | return; // No output of location allowed |
| 1364 | } |
| 1365 | |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 1366 | if (VERBOSE) Log.v(TAG, "reportLocation " + location.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1367 | |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1368 | location.setExtras(mLocationExtras.getBundle()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1369 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1370 | reportLocation(location); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1371 | |
Siddharth Ray | 53ddc80 | 2018-03-16 12:01:52 -0700 | [diff] [blame] | 1372 | if (mStarted) { |
| 1373 | mGnssMetrics.logReceivedLocationStatus(hasLatLong); |
| 1374 | if (hasLatLong) { |
| 1375 | if (location.hasAccuracy()) { |
| 1376 | mGnssMetrics.logPositionAccuracyMeters(location.getAccuracy()); |
| 1377 | } |
| 1378 | if (mTimeToFirstFix > 0) { |
| 1379 | int timeBetweenFixes = (int) (SystemClock.elapsedRealtime() - mLastFixTime); |
| 1380 | mGnssMetrics.logMissedReports(mFixInterval, timeBetweenFixes); |
| 1381 | } |
Siddharth Ray | bb608c8 | 2017-03-16 11:33:34 -0700 | [diff] [blame] | 1382 | } |
WyattRiley | ba6072f | 2019-04-18 07:37:52 -0700 | [diff] [blame] | 1383 | } else { |
| 1384 | // Warn or error about long delayed GNSS engine shutdown as this generally wastes |
| 1385 | // power and sends location when not expected. |
| 1386 | long locationAfterStartedFalseMillis = |
| 1387 | SystemClock.elapsedRealtime() - mStartedChangedElapsedRealtime; |
| 1388 | if (locationAfterStartedFalseMillis > LOCATION_OFF_DELAY_THRESHOLD_WARN_MILLIS) { |
| 1389 | String logMessage = "Unexpected GNSS Location report " |
| 1390 | + TimeUtils.formatDuration(locationAfterStartedFalseMillis) |
| 1391 | + " after location turned off"; |
| 1392 | if (locationAfterStartedFalseMillis > LOCATION_OFF_DELAY_THRESHOLD_ERROR_MILLIS) { |
| 1393 | Log.e(TAG, logMessage); |
| 1394 | } else { |
| 1395 | Log.w(TAG, logMessage); |
| 1396 | } |
| 1397 | } |
Siddharth Ray | bb608c8 | 2017-03-16 11:33:34 -0700 | [diff] [blame] | 1398 | } |
| 1399 | |
Yipeng Cao | 282b594 | 2017-05-17 20:31:39 -0700 | [diff] [blame] | 1400 | mLastFixTime = SystemClock.elapsedRealtime(); |
Hakan Gustavsson | fa94ff0 | 2010-02-23 09:12:38 +0100 | [diff] [blame] | 1401 | // report time to first fix |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 1402 | if (mTimeToFirstFix == 0 && hasLatLong) { |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1403 | mTimeToFirstFix = (int) (mLastFixTime - mFixRequestTime); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1404 | if (DEBUG) Log.d(TAG, "TTFF: " + mTimeToFirstFix); |
Siddharth Ray | 53ddc80 | 2018-03-16 12:01:52 -0700 | [diff] [blame] | 1405 | if (mStarted) { |
| 1406 | mGnssMetrics.logTimeToFirstFixMilliSecs(mTimeToFirstFix); |
| 1407 | } |
Hakan Gustavsson | fa94ff0 | 2010-02-23 09:12:38 +0100 | [diff] [blame] | 1408 | |
| 1409 | // notify status listeners |
Anil Admal | 75b9fd6 | 2018-11-28 11:22:50 -0800 | [diff] [blame] | 1410 | mGnssStatusListenerHelper.onFirstFix(mTimeToFirstFix); |
Hakan Gustavsson | fa94ff0 | 2010-02-23 09:12:38 +0100 | [diff] [blame] | 1411 | } |
| 1412 | |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 1413 | if (mStarted && mStatus != LocationProvider.AVAILABLE) { |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 1414 | // For devices that use framework scheduling, a timer may be set to ensure we don't |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1415 | // spend too much power searching for a location, when the requested update rate is |
| 1416 | // slow. |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 1417 | // As we just recievied a location, we'll cancel that timer. |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 1418 | if (!hasCapability(GPS_CAPABILITY_SCHEDULING) && mFixInterval < NO_FIX_TIMEOUT) { |
Mike Lockwood | b7be544 | 2010-02-24 14:34:50 -0500 | [diff] [blame] | 1419 | mAlarmManager.cancel(mTimeoutIntent); |
| 1420 | } |
| 1421 | |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 1422 | updateStatus(LocationProvider.AVAILABLE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1423 | } |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 1424 | |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1425 | if (!hasCapability(GPS_CAPABILITY_SCHEDULING) && mStarted && |
| 1426 | mFixInterval > GPS_POLLING_THRESHOLD_INTERVAL) { |
Mike Lockwood | d53ba01 | 2010-04-15 20:41:26 -0400 | [diff] [blame] | 1427 | if (DEBUG) Log.d(TAG, "got fix, hibernating"); |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 1428 | hibernate(); |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 1429 | } |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1430 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1431 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1432 | @NativeEntryPoint |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1433 | private void reportStatus(int status) { |
Mike Lockwood | b8d9033 | 2010-10-18 17:59:48 -0400 | [diff] [blame] | 1434 | if (DEBUG) Log.v(TAG, "reportStatus status: " + status); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1435 | |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1436 | boolean wasNavigating = mNavigating; |
| 1437 | switch (status) { |
| 1438 | case GPS_STATUS_SESSION_BEGIN: |
| 1439 | mNavigating = true; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1440 | break; |
| 1441 | case GPS_STATUS_SESSION_END: |
| 1442 | mNavigating = false; |
| 1443 | break; |
| 1444 | case GPS_STATUS_ENGINE_ON: |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1445 | break; |
| 1446 | case GPS_STATUS_ENGINE_OFF: |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1447 | mNavigating = false; |
| 1448 | break; |
| 1449 | } |
Mike Lockwood | dbd6fd8 | 2009-12-07 18:43:36 -0500 | [diff] [blame] | 1450 | |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1451 | if (wasNavigating != mNavigating) { |
Anil Admal | 75b9fd6 | 2018-11-28 11:22:50 -0800 | [diff] [blame] | 1452 | mGnssStatusListenerHelper.onStatusChanged(mNavigating); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1453 | } |
| 1454 | } |
| 1455 | |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1456 | // Helper class to carry data to handler for reportSvStatus |
| 1457 | private static class SvStatusInfo { |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1458 | private int mSvCount; |
| 1459 | private int[] mSvidWithFlags; |
| 1460 | private float[] mCn0s; |
| 1461 | private float[] mSvElevations; |
| 1462 | private float[] mSvAzimuths; |
| 1463 | private float[] mSvCarrierFreqs; |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1464 | } |
| 1465 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1466 | @NativeEntryPoint |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1467 | private void reportSvStatus(int svCount, int[] svidWithFlags, float[] cn0s, |
| 1468 | float[] svElevations, float[] svAzimuths, float[] svCarrierFreqs) { |
| 1469 | SvStatusInfo svStatusInfo = new SvStatusInfo(); |
| 1470 | svStatusInfo.mSvCount = svCount; |
| 1471 | svStatusInfo.mSvidWithFlags = svidWithFlags; |
| 1472 | svStatusInfo.mCn0s = cn0s; |
| 1473 | svStatusInfo.mSvElevations = svElevations; |
| 1474 | svStatusInfo.mSvAzimuths = svAzimuths; |
| 1475 | svStatusInfo.mSvCarrierFreqs = svCarrierFreqs; |
| 1476 | |
| 1477 | sendMessage(REPORT_SV_STATUS, 0, svStatusInfo); |
| 1478 | } |
| 1479 | |
| 1480 | private void handleReportSvStatus(SvStatusInfo info) { |
Anil Admal | 75b9fd6 | 2018-11-28 11:22:50 -0800 | [diff] [blame] | 1481 | mGnssStatusListenerHelper.onSvStatusChanged( |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1482 | info.mSvCount, |
| 1483 | info.mSvidWithFlags, |
| 1484 | info.mCn0s, |
| 1485 | info.mSvElevations, |
| 1486 | info.mSvAzimuths, |
| 1487 | info.mSvCarrierFreqs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1488 | |
Siddharth Ray | 168f12a | 2017-07-10 11:55:10 -0700 | [diff] [blame] | 1489 | // Log CN0 as part of GNSS metrics |
Blake Kragten | 025aabe | 2019-08-28 16:21:35 -0700 | [diff] [blame] | 1490 | mGnssMetrics.logCn0(info.mCn0s, info.mSvCount, info.mSvCarrierFreqs); |
Siddharth Ray | 168f12a | 2017-07-10 11:55:10 -0700 | [diff] [blame] | 1491 | |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 1492 | if (VERBOSE) { |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1493 | Log.v(TAG, "SV count: " + info.mSvCount); |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1494 | } |
Wyatt Riley | c9f25dd | 2017-05-05 13:45:23 -0700 | [diff] [blame] | 1495 | // Calculate number of satellites used in fix. |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1496 | int usedInFixCount = 0; |
Wyatt Riley | c9f25dd | 2017-05-05 13:45:23 -0700 | [diff] [blame] | 1497 | int maxCn0 = 0; |
| 1498 | int meanCn0 = 0; |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1499 | for (int i = 0; i < info.mSvCount; i++) { |
| 1500 | if ((info.mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_USED_IN_FIX) != 0) { |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1501 | ++usedInFixCount; |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1502 | if (info.mCn0s[i] > maxCn0) { |
| 1503 | maxCn0 = (int) info.mCn0s[i]; |
Wyatt Riley | c9f25dd | 2017-05-05 13:45:23 -0700 | [diff] [blame] | 1504 | } |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1505 | meanCn0 += info.mCn0s[i]; |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1506 | } |
| 1507 | if (VERBOSE) { |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1508 | Log.v(TAG, "svid: " + (info.mSvidWithFlags[i] >> GnssStatus.SVID_SHIFT_WIDTH) + |
| 1509 | " cn0: " + info.mCn0s[i] + |
| 1510 | " elev: " + info.mSvElevations[i] + |
| 1511 | " azimuth: " + info.mSvAzimuths[i] + |
| 1512 | " carrier frequency: " + info.mSvCarrierFreqs[i] + |
| 1513 | ((info.mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_HAS_EPHEMERIS_DATA) == 0 |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1514 | ? " " : " E") + |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1515 | ((info.mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_HAS_ALMANAC_DATA) == 0 |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1516 | ? " " : " A") + |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1517 | ((info.mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_USED_IN_FIX) == 0 |
gomo | 4402af6 | 2017-01-11 13:20:13 -0800 | [diff] [blame] | 1518 | ? "" : "U") + |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1519 | ((info.mSvidWithFlags[i] & |
| 1520 | GnssStatus.GNSS_SV_FLAGS_HAS_CARRIER_FREQUENCY) == 0 |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1521 | ? "" : "F")); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1522 | } |
Yu-Han Yang | 284234e | 2019-03-28 19:35:57 -0700 | [diff] [blame] | 1523 | |
| 1524 | if ((info.mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_USED_IN_FIX) != 0) { |
| 1525 | int constellationType = |
| 1526 | (info.mSvidWithFlags[i] >> GnssStatus.CONSTELLATION_TYPE_SHIFT_WIDTH) |
| 1527 | & GnssStatus.CONSTELLATION_TYPE_MASK; |
| 1528 | mGnssMetrics.logConstellationType(constellationType); |
| 1529 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1530 | } |
Wyatt Riley | c9f25dd | 2017-05-05 13:45:23 -0700 | [diff] [blame] | 1531 | if (usedInFixCount > 0) { |
| 1532 | meanCn0 /= usedInFixCount; |
| 1533 | } |
| 1534 | // return number of sats used in fix instead of total reported |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 1535 | mLocationExtras.set(usedInFixCount, meanCn0, maxCn0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1536 | |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 1537 | if (mNavigating && mStatus == LocationProvider.AVAILABLE && mLastFixTime > 0 && |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1538 | SystemClock.elapsedRealtime() - mLastFixTime > RECENT_FIX_TIMEOUT) { |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 1539 | updateStatus(LocationProvider.TEMPORARILY_UNAVAILABLE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1540 | } |
Blake Kragten | 025aabe | 2019-08-28 16:21:35 -0700 | [diff] [blame] | 1541 | |
| 1542 | mGnssMetrics.logSvStatus(info.mSvCount, info.mSvidWithFlags, info.mSvCarrierFreqs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1543 | } |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 1544 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1545 | @NativeEntryPoint |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 1546 | private void reportAGpsStatus(int agpsType, int agpsStatus, byte[] suplIpAddr) { |
| 1547 | mNetworkConnectivityHandler.onReportAGpsStatus(agpsType, agpsStatus, suplIpAddr); |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 1548 | } |
| 1549 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1550 | @NativeEntryPoint |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 1551 | private void reportNmea(long timestamp) { |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1552 | if (!mItarSpeedLimitExceeded) { |
| 1553 | int length = native_read_nmea(mNmeaBuffer, mNmeaBuffer.length); |
| 1554 | String nmea = new String(mNmeaBuffer, 0 /* offset */, length); |
Anil Admal | 75b9fd6 | 2018-11-28 11:22:50 -0800 | [diff] [blame] | 1555 | mGnssStatusListenerHelper.onNmeaReceived(timestamp, nmea); |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1556 | } |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1557 | } |
Mike Lockwood | b16e780 | 2009-08-06 09:26:02 -0400 | [diff] [blame] | 1558 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1559 | @NativeEntryPoint |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 1560 | private void reportMeasurementData(GnssMeasurementsEvent event) { |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1561 | if (!mItarSpeedLimitExceeded) { |
Wyatt Riley | aa420d5 | 2017-07-03 15:14:42 -0700 | [diff] [blame] | 1562 | // send to handler to allow native to return quickly |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1563 | mHandler.post(() -> mGnssMeasurementsProvider.onMeasurementsAvailable(event)); |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1564 | } |
Mike Lockwood | b16e780 | 2009-08-06 09:26:02 -0400 | [diff] [blame] | 1565 | } |
| 1566 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1567 | @NativeEntryPoint |
Lifu Tang | e8abe8e | 2016-04-01 10:32:05 -0700 | [diff] [blame] | 1568 | private void reportNavigationMessage(GnssNavigationMessage event) { |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1569 | if (!mItarSpeedLimitExceeded) { |
Wyatt Riley | aa420d5 | 2017-07-03 15:14:42 -0700 | [diff] [blame] | 1570 | // send to handler to allow native to return quickly |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1571 | mHandler.post(() -> mGnssNavigationMessageProvider.onNavigationMessageAvailable(event)); |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1572 | } |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1573 | } |
| 1574 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1575 | @NativeEntryPoint |
Anil Admal | 62c42dc | 2019-04-03 15:39:22 -0700 | [diff] [blame] | 1576 | private void setTopHalCapabilities(int topHalCapabilities) { |
Anil Admal | efd9dc6 | 2019-03-12 17:39:20 -0700 | [diff] [blame] | 1577 | mHandler.post(() -> { |
Anil Admal | 312fddb | 2019-03-25 12:15:43 -0700 | [diff] [blame] | 1578 | mTopHalCapabilities = topHalCapabilities; |
Mike Lockwood | 9b9fb5c | 2011-06-29 15:09:40 -0400 | [diff] [blame] | 1579 | |
Anil Admal | efd9dc6 | 2019-03-12 17:39:20 -0700 | [diff] [blame] | 1580 | if (hasCapability(GPS_CAPABILITY_ON_DEMAND_TIME)) { |
| 1581 | mNtpTimeHelper.enablePeriodicTimeInjection(); |
| 1582 | requestUtcTime(); |
| 1583 | } |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1584 | |
Anil Admal | 62c42dc | 2019-04-03 15:39:22 -0700 | [diff] [blame] | 1585 | mGnssMeasurementsProvider.onCapabilitiesUpdated( |
| 1586 | hasCapability(GPS_CAPABILITY_MEASUREMENTS)); |
| 1587 | mGnssNavigationMessageProvider.onCapabilitiesUpdated( |
| 1588 | hasCapability(GPS_CAPABILITY_NAV_MESSAGES)); |
Anil Admal | efd9dc6 | 2019-03-12 17:39:20 -0700 | [diff] [blame] | 1589 | restartRequests(); |
Anil Admal | 312fddb | 2019-03-25 12:15:43 -0700 | [diff] [blame] | 1590 | |
Anil Admal | 62c42dc | 2019-04-03 15:39:22 -0700 | [diff] [blame] | 1591 | mGnssCapabilitiesProvider.setTopHalCapabilities(mTopHalCapabilities); |
Anil Admal | efd9dc6 | 2019-03-12 17:39:20 -0700 | [diff] [blame] | 1592 | }); |
| 1593 | } |
| 1594 | |
| 1595 | @NativeEntryPoint |
Anil Admal | 312fddb | 2019-03-25 12:15:43 -0700 | [diff] [blame] | 1596 | private void setSubHalMeasurementCorrectionsCapabilities(int subHalCapabilities) { |
| 1597 | mHandler.post(() -> { |
| 1598 | if (!mGnssMeasurementCorrectionsProvider.onCapabilitiesUpdated(subHalCapabilities)) { |
| 1599 | return; |
| 1600 | } |
| 1601 | |
| 1602 | mGnssCapabilitiesProvider.setSubHalMeasurementCorrectionsCapabilities( |
| 1603 | subHalCapabilities); |
| 1604 | }); |
Yu-Han Yang | 5205762 | 2018-04-25 00:51:22 -0700 | [diff] [blame] | 1605 | } |
| 1606 | |
| 1607 | private void restartRequests() { |
| 1608 | Log.i(TAG, "restartRequests"); |
| 1609 | |
| 1610 | restartLocationRequest(); |
| 1611 | mGnssMeasurementsProvider.resumeIfStarted(); |
| 1612 | mGnssNavigationMessageProvider.resumeIfStarted(); |
| 1613 | mGnssBatchingProvider.resumeIfStarted(); |
| 1614 | mGnssGeofenceProvider.resumeIfStarted(); |
| 1615 | } |
| 1616 | |
| 1617 | private void restartLocationRequest() { |
| 1618 | if (DEBUG) Log.d(TAG, "restartLocationRequest"); |
WyattRiley | ba6072f | 2019-04-18 07:37:52 -0700 | [diff] [blame] | 1619 | setStarted(false); |
Yu-Han Yang | 5205762 | 2018-04-25 00:51:22 -0700 | [diff] [blame] | 1620 | updateRequirements(); |
| 1621 | } |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1622 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1623 | @NativeEntryPoint |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1624 | private void setGnssYearOfHardware(final int yearOfHardware) { |
| 1625 | // mHardwareYear is simply set here, to be read elsewhere, and is volatile for safe sync |
| 1626 | if (DEBUG) Log.d(TAG, "setGnssYearOfHardware called with " + yearOfHardware); |
| 1627 | mHardwareYear = yearOfHardware; |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 1628 | } |
| 1629 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1630 | @NativeEntryPoint |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1631 | private void setGnssHardwareModelName(final String modelName) { |
| 1632 | // mHardwareModelName is simply set here, to be read elsewhere, and volatile for safe sync |
| 1633 | if (DEBUG) Log.d(TAG, "setGnssModelName called with " + modelName); |
| 1634 | mHardwareModelName = modelName; |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 1635 | } |
| 1636 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1637 | @NativeEntryPoint |
Yu-Han Yang | 5205762 | 2018-04-25 00:51:22 -0700 | [diff] [blame] | 1638 | private void reportGnssServiceDied() { |
| 1639 | if (DEBUG) Log.d(TAG, "reportGnssServiceDied"); |
| 1640 | mHandler.post(() -> { |
Anil Admal | 0c2b21bd | 2019-05-03 18:29:02 -0700 | [diff] [blame] | 1641 | setupNativeGnssService(/* reinitializeGnssServiceHandle = */ true); |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 1642 | if (isGpsEnabled()) { |
| 1643 | setGpsEnabled(false); |
| 1644 | |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 1645 | updateEnabled(); |
| 1646 | |
Yu-Han Yang | 5205762 | 2018-04-25 00:51:22 -0700 | [diff] [blame] | 1647 | // resend configuration into the restarted HAL service. |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 1648 | reloadGpsProperties(); |
Yu-Han Yang | 5205762 | 2018-04-25 00:51:22 -0700 | [diff] [blame] | 1649 | } |
| 1650 | }); |
| 1651 | } |
| 1652 | |
Lifu Tang | 9363b94 | 2016-02-16 18:07:00 -0800 | [diff] [blame] | 1653 | public interface GnssSystemInfoProvider { |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 1654 | /** |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1655 | * Returns the year of underlying GPS hardware. |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 1656 | */ |
Lifu Tang | 9363b94 | 2016-02-16 18:07:00 -0800 | [diff] [blame] | 1657 | int getGnssYearOfHardware(); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1658 | |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1659 | /** |
| 1660 | * Returns the model name of underlying GPS hardware. |
| 1661 | */ |
| 1662 | String getGnssHardwareModelName(); |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | /** |
| 1666 | * @hide |
| 1667 | */ |
Lifu Tang | 9363b94 | 2016-02-16 18:07:00 -0800 | [diff] [blame] | 1668 | public GnssSystemInfoProvider getGnssSystemInfoProvider() { |
| 1669 | return new GnssSystemInfoProvider() { |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 1670 | @Override |
Lifu Tang | 9363b94 | 2016-02-16 18:07:00 -0800 | [diff] [blame] | 1671 | public int getGnssYearOfHardware() { |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1672 | return mHardwareYear; |
| 1673 | } |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1674 | |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1675 | @Override |
| 1676 | public String getGnssHardwareModelName() { |
| 1677 | return mHardwareModelName; |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 1678 | } |
| 1679 | }; |
| 1680 | } |
| 1681 | |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1682 | /** |
| 1683 | * @hide |
| 1684 | */ |
| 1685 | public GnssBatchingProvider getGnssBatchingProvider() { |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 1686 | return mGnssBatchingProvider; |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1687 | } |
| 1688 | |
Siddharth Ray | bb608c8 | 2017-03-16 11:33:34 -0700 | [diff] [blame] | 1689 | public interface GnssMetricsProvider { |
| 1690 | /** |
| 1691 | * Returns GNSS metrics as proto string |
| 1692 | */ |
| 1693 | String getGnssMetricsAsProtoString(); |
| 1694 | } |
| 1695 | |
| 1696 | /** |
| 1697 | * @hide |
| 1698 | */ |
| 1699 | public GnssMetricsProvider getGnssMetricsProvider() { |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1700 | return () -> mGnssMetrics.dumpGnssMetricsAsProtoString(); |
Siddharth Ray | bb608c8 | 2017-03-16 11:33:34 -0700 | [diff] [blame] | 1701 | } |
| 1702 | |
Anil Admal | 312fddb | 2019-03-25 12:15:43 -0700 | [diff] [blame] | 1703 | /** |
| 1704 | * @hide |
| 1705 | */ |
| 1706 | public GnssCapabilitiesProvider getGnssCapabilitiesProvider() { |
| 1707 | return mGnssCapabilitiesProvider; |
| 1708 | } |
| 1709 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1710 | @NativeEntryPoint |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1711 | private void reportLocationBatch(Location[] locationArray) { |
| 1712 | List<Location> locations = new ArrayList<>(Arrays.asList(locationArray)); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1713 | if (DEBUG) { |
| 1714 | Log.d(TAG, "Location batch of size " + locationArray.length + " reported"); |
| 1715 | } |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1716 | reportLocation(locations); |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1717 | } |
| 1718 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1719 | @NativeEntryPoint |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 1720 | private void psdsDownloadRequest() { |
| 1721 | if (DEBUG) Log.d(TAG, "psdsDownloadRequest"); |
| 1722 | sendMessage(DOWNLOAD_PSDS_DATA, 0, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1723 | } |
| 1724 | |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1725 | /** |
destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 1726 | * Converts the GPS HAL status to the internal Geofence Hardware status. |
| 1727 | */ |
Yu-Han Yang | 6dc9f05 | 2018-12-04 17:11:24 -0800 | [diff] [blame] | 1728 | private static int getGeofenceStatus(int status) { |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1729 | switch (status) { |
destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 1730 | case GPS_GEOFENCE_OPERATION_SUCCESS: |
| 1731 | return GeofenceHardware.GEOFENCE_SUCCESS; |
| 1732 | case GPS_GEOFENCE_ERROR_GENERIC: |
| 1733 | return GeofenceHardware.GEOFENCE_FAILURE; |
| 1734 | case GPS_GEOFENCE_ERROR_ID_EXISTS: |
| 1735 | return GeofenceHardware.GEOFENCE_ERROR_ID_EXISTS; |
| 1736 | case GPS_GEOFENCE_ERROR_INVALID_TRANSITION: |
| 1737 | return GeofenceHardware.GEOFENCE_ERROR_INVALID_TRANSITION; |
| 1738 | case GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES: |
| 1739 | return GeofenceHardware.GEOFENCE_ERROR_TOO_MANY_GEOFENCES; |
| 1740 | case GPS_GEOFENCE_ERROR_ID_UNKNOWN: |
| 1741 | return GeofenceHardware.GEOFENCE_ERROR_ID_UNKNOWN; |
| 1742 | default: |
| 1743 | return -1; |
| 1744 | } |
| 1745 | } |
| 1746 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1747 | @NativeEntryPoint |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 1748 | private void reportGeofenceTransition(int geofenceId, Location location, int transition, |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1749 | long transitionTimestamp) { |
Yu-Han Yang | 6dc9f05 | 2018-12-04 17:11:24 -0800 | [diff] [blame] | 1750 | mHandler.post(() -> { |
| 1751 | if (mGeofenceHardwareImpl == null) { |
| 1752 | mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext); |
| 1753 | } |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 1754 | |
Yu-Han Yang | 6dc9f05 | 2018-12-04 17:11:24 -0800 | [diff] [blame] | 1755 | mGeofenceHardwareImpl.reportGeofenceTransition( |
| 1756 | geofenceId, |
| 1757 | location, |
| 1758 | transition, |
| 1759 | transitionTimestamp, |
| 1760 | GeofenceHardware.MONITORING_TYPE_GPS_HARDWARE, |
| 1761 | FusedBatchOptions.SourceTechnologies.GNSS); |
| 1762 | }); |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1763 | } |
| 1764 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1765 | @NativeEntryPoint |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 1766 | private void reportGeofenceStatus(int status, Location location) { |
Yu-Han Yang | 6dc9f05 | 2018-12-04 17:11:24 -0800 | [diff] [blame] | 1767 | mHandler.post(() -> { |
| 1768 | if (mGeofenceHardwareImpl == null) { |
| 1769 | mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext); |
| 1770 | } |
| 1771 | int monitorStatus = GeofenceHardware.MONITOR_CURRENTLY_UNAVAILABLE; |
| 1772 | if (status == GPS_GEOFENCE_AVAILABLE) { |
| 1773 | monitorStatus = GeofenceHardware.MONITOR_CURRENTLY_AVAILABLE; |
| 1774 | } |
| 1775 | mGeofenceHardwareImpl.reportGeofenceMonitorStatus( |
| 1776 | GeofenceHardware.MONITORING_TYPE_GPS_HARDWARE, |
| 1777 | monitorStatus, |
| 1778 | location, |
| 1779 | FusedBatchOptions.SourceTechnologies.GNSS); |
| 1780 | }); |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1781 | } |
| 1782 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1783 | @NativeEntryPoint |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1784 | private void reportGeofenceAddStatus(int geofenceId, int status) { |
Yu-Han Yang | 6dc9f05 | 2018-12-04 17:11:24 -0800 | [diff] [blame] | 1785 | mHandler.post(() -> { |
| 1786 | if (mGeofenceHardwareImpl == null) { |
| 1787 | mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext); |
| 1788 | } |
| 1789 | mGeofenceHardwareImpl.reportGeofenceAddStatus(geofenceId, getGeofenceStatus(status)); |
| 1790 | }); |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1793 | @NativeEntryPoint |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1794 | private void reportGeofenceRemoveStatus(int geofenceId, int status) { |
Yu-Han Yang | 6dc9f05 | 2018-12-04 17:11:24 -0800 | [diff] [blame] | 1795 | mHandler.post(() -> { |
| 1796 | if (mGeofenceHardwareImpl == null) { |
| 1797 | mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext); |
| 1798 | } |
| 1799 | mGeofenceHardwareImpl.reportGeofenceRemoveStatus(geofenceId, getGeofenceStatus(status)); |
| 1800 | }); |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1801 | } |
| 1802 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1803 | @NativeEntryPoint |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1804 | private void reportGeofencePauseStatus(int geofenceId, int status) { |
Yu-Han Yang | 6dc9f05 | 2018-12-04 17:11:24 -0800 | [diff] [blame] | 1805 | mHandler.post(() -> { |
| 1806 | if (mGeofenceHardwareImpl == null) { |
| 1807 | mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext); |
| 1808 | } |
| 1809 | mGeofenceHardwareImpl.reportGeofencePauseStatus(geofenceId, getGeofenceStatus(status)); |
| 1810 | }); |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1813 | @NativeEntryPoint |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1814 | private void reportGeofenceResumeStatus(int geofenceId, int status) { |
Yu-Han Yang | 6dc9f05 | 2018-12-04 17:11:24 -0800 | [diff] [blame] | 1815 | mHandler.post(() -> { |
| 1816 | if (mGeofenceHardwareImpl == null) { |
| 1817 | mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext); |
| 1818 | } |
| 1819 | mGeofenceHardwareImpl.reportGeofenceResumeStatus(geofenceId, getGeofenceStatus(status)); |
| 1820 | }); |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1821 | } |
| 1822 | |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 1823 | //============================================================= |
| 1824 | // NI Client support |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1825 | //============================================================= |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 1826 | private final INetInitiatedListener mNetInitiatedListener = new INetInitiatedListener.Stub() { |
destradaa | ef752b6 | 2015-04-17 13:10:47 -0700 | [diff] [blame] | 1827 | // Sends a response for an NI request to HAL. |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1828 | @Override |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1829 | public boolean sendNiResponse(int notificationId, int userResponse) { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1830 | // TODO Add Permission check |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 1831 | |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1832 | if (DEBUG) { |
| 1833 | Log.d(TAG, "sendNiResponse, notifId: " + notificationId + |
| 1834 | ", response: " + userResponse); |
| 1835 | } |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1836 | native_send_ni_response(notificationId, userResponse); |
Yu-Han Yang | 8a1b51d | 2018-12-26 22:18:31 -0800 | [diff] [blame] | 1837 | |
| 1838 | StatsLog.write(StatsLog.GNSS_NI_EVENT_REPORTED, |
| 1839 | StatsLog.GNSS_NI_EVENT_REPORTED__EVENT_TYPE__NI_RESPONSE, |
| 1840 | notificationId, |
| 1841 | /* niType= */ 0, |
| 1842 | /* needNotify= */ false, |
| 1843 | /* needVerify= */ false, |
| 1844 | /* privacyOverride= */ false, |
| 1845 | /* timeout= */ 0, |
| 1846 | /* defaultResponse= */ 0, |
| 1847 | /* requestorId= */ null, |
| 1848 | /* text= */ null, |
| 1849 | /* requestorIdEncoding= */ 0, |
| 1850 | /* textEncoding= */ 0, |
| 1851 | mSuplEsEnabled, |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 1852 | isGpsEnabled(), |
Yu-Han Yang | 8a1b51d | 2018-12-26 22:18:31 -0800 | [diff] [blame] | 1853 | userResponse); |
| 1854 | |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1855 | return true; |
| 1856 | } |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 1857 | }; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1858 | |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 1859 | public INetInitiatedListener getNetInitiatedListener() { |
| 1860 | return mNetInitiatedListener; |
| 1861 | } |
| 1862 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1863 | /** Reports a NI notification. */ |
| 1864 | @NativeEntryPoint |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1865 | public void reportNiNotification( |
| 1866 | int notificationId, |
| 1867 | int niType, |
| 1868 | int notifyFlags, |
| 1869 | int timeout, |
| 1870 | int defaultResponse, |
| 1871 | String requestorId, |
| 1872 | String text, |
| 1873 | int requestorIdEncoding, |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1874 | int textEncoding |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1875 | ) { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1876 | Log.i(TAG, "reportNiNotification: entered"); |
| 1877 | Log.i(TAG, "notificationId: " + notificationId + |
| 1878 | ", niType: " + niType + |
| 1879 | ", notifyFlags: " + notifyFlags + |
| 1880 | ", timeout: " + timeout + |
| 1881 | ", defaultResponse: " + defaultResponse); |
| 1882 | |
| 1883 | Log.i(TAG, "requestorId: " + requestorId + |
| 1884 | ", text: " + text + |
| 1885 | ", requestorIdEncoding: " + requestorIdEncoding + |
| 1886 | ", textEncoding: " + textEncoding); |
| 1887 | |
| 1888 | GpsNiNotification notification = new GpsNiNotification(); |
| 1889 | |
| 1890 | notification.notificationId = notificationId; |
| 1891 | notification.niType = niType; |
| 1892 | notification.needNotify = (notifyFlags & GpsNetInitiatedHandler.GPS_NI_NEED_NOTIFY) != 0; |
| 1893 | notification.needVerify = (notifyFlags & GpsNetInitiatedHandler.GPS_NI_NEED_VERIFY) != 0; |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1894 | notification.privacyOverride = |
| 1895 | (notifyFlags & GpsNetInitiatedHandler.GPS_NI_PRIVACY_OVERRIDE) != 0; |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1896 | notification.timeout = timeout; |
| 1897 | notification.defaultResponse = defaultResponse; |
| 1898 | notification.requestorId = requestorId; |
| 1899 | notification.text = text; |
| 1900 | notification.requestorIdEncoding = requestorIdEncoding; |
| 1901 | notification.textEncoding = textEncoding; |
| 1902 | |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1903 | mNIHandler.handleNiNotification(notification); |
Yu-Han Yang | 8a1b51d | 2018-12-26 22:18:31 -0800 | [diff] [blame] | 1904 | StatsLog.write(StatsLog.GNSS_NI_EVENT_REPORTED, |
| 1905 | StatsLog.GNSS_NI_EVENT_REPORTED__EVENT_TYPE__NI_REQUEST, |
| 1906 | notification.notificationId, |
| 1907 | notification.niType, |
| 1908 | notification.needNotify, |
| 1909 | notification.needVerify, |
| 1910 | notification.privacyOverride, |
| 1911 | notification.timeout, |
| 1912 | notification.defaultResponse, |
| 1913 | notification.requestorId, |
| 1914 | notification.text, |
| 1915 | notification.requestorIdEncoding, |
| 1916 | notification.textEncoding, |
| 1917 | mSuplEsEnabled, |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 1918 | isGpsEnabled(), |
Yu-Han Yang | 8a1b51d | 2018-12-26 22:18:31 -0800 | [diff] [blame] | 1919 | /* userResponse= */ 0); |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1920 | } |
| 1921 | |
| 1922 | /** |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1923 | * We should be careful about receiving null string from the TelephonyManager, |
| 1924 | * because sending null String to JNI function would cause a crash. |
| 1925 | */ |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1926 | @NativeEntryPoint |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1927 | private void requestSetID(int flags) { |
| 1928 | TelephonyManager phone = (TelephonyManager) |
| 1929 | mContext.getSystemService(Context.TELEPHONY_SERVICE); |
destradaa | ef752b6 | 2015-04-17 13:10:47 -0700 | [diff] [blame] | 1930 | int type = AGPS_SETID_TYPE_NONE; |
Anil Admal | e1539e8 | 2019-05-09 15:05:04 -0700 | [diff] [blame] | 1931 | String setId = null; |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1932 | |
Anil Admal | e1539e8 | 2019-05-09 15:05:04 -0700 | [diff] [blame] | 1933 | int ddSubId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1934 | if ((flags & AGPS_RIL_REQUEST_SETID_IMSI) == AGPS_RIL_REQUEST_SETID_IMSI) { |
Anil Admal | e1539e8 | 2019-05-09 15:05:04 -0700 | [diff] [blame] | 1935 | if (SubscriptionManager.isValidSubscriptionId(ddSubId)) { |
| 1936 | setId = phone.getSubscriberId(ddSubId); |
| 1937 | } |
| 1938 | if (setId == null) { |
| 1939 | setId = phone.getSubscriberId(); |
| 1940 | } |
| 1941 | if (setId != null) { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1942 | // This means the framework has the SIM card. |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1943 | type = AGPS_SETID_TYPE_IMSI; |
| 1944 | } |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1945 | } else if ((flags & AGPS_RIL_REQUEST_SETID_MSISDN) == AGPS_RIL_REQUEST_SETID_MSISDN) { |
Anil Admal | e1539e8 | 2019-05-09 15:05:04 -0700 | [diff] [blame] | 1946 | if (SubscriptionManager.isValidSubscriptionId(ddSubId)) { |
| 1947 | setId = phone.getLine1Number(ddSubId); |
| 1948 | } |
| 1949 | if (setId == null) { |
| 1950 | setId = phone.getLine1Number(); |
| 1951 | } |
| 1952 | if (setId != null) { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1953 | // This means the framework has the SIM card. |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1954 | type = AGPS_SETID_TYPE_MSISDN; |
| 1955 | } |
| 1956 | } |
Anil Admal | e1539e8 | 2019-05-09 15:05:04 -0700 | [diff] [blame] | 1957 | |
| 1958 | native_agps_set_id(type, (setId == null) ? "" : setId); |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1959 | } |
| 1960 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1961 | @NativeEntryPoint |
Yu-Han Yang | 53f4d6d | 2019-02-13 21:47:41 -0800 | [diff] [blame] | 1962 | private void requestLocation(boolean independentFromGnss, boolean isUserEmergency) { |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 1963 | if (DEBUG) { |
Yu-Han Yang | 53f4d6d | 2019-02-13 21:47:41 -0800 | [diff] [blame] | 1964 | Log.d(TAG, "requestLocation. independentFromGnss: " + independentFromGnss |
| 1965 | + ", isUserEmergency: " |
| 1966 | + isUserEmergency); |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 1967 | } |
Yu-Han Yang | 53f4d6d | 2019-02-13 21:47:41 -0800 | [diff] [blame] | 1968 | sendMessage(REQUEST_LOCATION, independentFromGnss ? 1 : 0, isUserEmergency); |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 1969 | } |
| 1970 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1971 | @NativeEntryPoint |
Mike Lockwood | 9b9fb5c | 2011-06-29 15:09:40 -0400 | [diff] [blame] | 1972 | private void requestUtcTime() { |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 1973 | if (DEBUG) Log.d(TAG, "utcTimeRequest"); |
Mike Lockwood | 9b9fb5c | 2011-06-29 15:09:40 -0400 | [diff] [blame] | 1974 | sendMessage(INJECT_NTP_TIME, 0, null); |
| 1975 | } |
| 1976 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1977 | @NativeEntryPoint |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1978 | private void requestRefLocation() { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1979 | TelephonyManager phone = (TelephonyManager) |
| 1980 | mContext.getSystemService(Context.TELEPHONY_SERVICE); |
Victoria Lease | d50d0c3 | 2012-10-29 13:16:17 -0700 | [diff] [blame] | 1981 | final int phoneType = phone.getPhoneType(); |
| 1982 | if (phoneType == TelephonyManager.PHONE_TYPE_GSM) { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1983 | GsmCellLocation gsm_cell = (GsmCellLocation) phone.getCellLocation(); |
Victoria Lease | d50d0c3 | 2012-10-29 13:16:17 -0700 | [diff] [blame] | 1984 | if ((gsm_cell != null) && (phone.getNetworkOperator() != null) |
| 1985 | && (phone.getNetworkOperator().length() > 3)) { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1986 | int type; |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1987 | int mcc = Integer.parseInt(phone.getNetworkOperator().substring(0, 3)); |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1988 | int mnc = Integer.parseInt(phone.getNetworkOperator().substring(3)); |
Mike Lockwood | edc0f387 | 2010-10-22 09:16:17 -0400 | [diff] [blame] | 1989 | int networkType = phone.getNetworkType(); |
| 1990 | if (networkType == TelephonyManager.NETWORK_TYPE_UMTS |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1991 | || networkType == TelephonyManager.NETWORK_TYPE_HSDPA |
| 1992 | || networkType == TelephonyManager.NETWORK_TYPE_HSUPA |
| 1993 | || networkType == TelephonyManager.NETWORK_TYPE_HSPA |
| 1994 | || networkType == TelephonyManager.NETWORK_TYPE_HSPAP) { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1995 | type = AGPS_REF_LOCATION_TYPE_UMTS_CELLID; |
Mike Lockwood | edc0f387 | 2010-10-22 09:16:17 -0400 | [diff] [blame] | 1996 | } else { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1997 | type = AGPS_REF_LOCATION_TYPE_GSM_CELLID; |
Mike Lockwood | edc0f387 | 2010-10-22 09:16:17 -0400 | [diff] [blame] | 1998 | } |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1999 | native_agps_set_ref_location_cellid(type, mcc, mnc, |
| 2000 | gsm_cell.getLac(), gsm_cell.getCid()); |
Mike Lockwood | edc0f387 | 2010-10-22 09:16:17 -0400 | [diff] [blame] | 2001 | } else { |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2002 | Log.e(TAG, "Error getting cell location info."); |
Mike Lockwood | edc0f387 | 2010-10-22 09:16:17 -0400 | [diff] [blame] | 2003 | } |
Victoria Lease | d50d0c3 | 2012-10-29 13:16:17 -0700 | [diff] [blame] | 2004 | } else if (phoneType == TelephonyManager.PHONE_TYPE_CDMA) { |
| 2005 | Log.e(TAG, "CDMA not supported."); |
Mike Lockwood | edc0f387 | 2010-10-22 09:16:17 -0400 | [diff] [blame] | 2006 | } |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 2007 | } |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 2008 | |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 2009 | // Implements method nfwNotifyCb() in IGnssVisibilityControlCallback.hal. |
| 2010 | @NativeEntryPoint |
| 2011 | private void reportNfwNotification(String proxyAppPackageName, byte protocolStack, |
| 2012 | String otherProtocolStackName, byte requestor, String requestorId, byte responseType, |
| 2013 | boolean inEmergencyMode, boolean isCachedLocation) { |
| 2014 | if (mGnssVisibilityControl == null) { |
| 2015 | Log.e(TAG, "reportNfwNotification: mGnssVisibilityControl is not initialized."); |
| 2016 | return; |
| 2017 | } |
| 2018 | |
| 2019 | mGnssVisibilityControl.reportNfwNotification(proxyAppPackageName, protocolStack, |
| 2020 | otherProtocolStackName, requestor, requestorId, responseType, inEmergencyMode, |
| 2021 | isCachedLocation); |
| 2022 | } |
| 2023 | |
| 2024 | // Implements method isInEmergencySession() in IGnssVisibilityControlCallback.hal. |
| 2025 | @NativeEntryPoint |
| 2026 | boolean isInEmergencySession() { |
| 2027 | return mNIHandler.getInEmergency(); |
| 2028 | } |
| 2029 | |
Mike Lockwood | 98e4869 | 2010-04-07 16:32:51 -0400 | [diff] [blame] | 2030 | private void sendMessage(int message, int arg, Object obj) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2031 | // hold a wake lock until this message is delivered |
Jeff Brown | 028872f | 2012-08-25 13:07:01 -0700 | [diff] [blame] | 2032 | // note that this assumes the message will not be removed from the queue before |
| 2033 | // it is handled (otherwise the wake lock would be leaked). |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2034 | mWakeLock.acquire(); |
Anil Admal | 4f97c94 | 2018-11-12 10:52:46 -0800 | [diff] [blame] | 2035 | if (DEBUG) { |
| 2036 | Log.d(TAG, "WakeLock acquired by sendMessage(" + messageIdAsString(message) + ", " + arg |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2037 | + ", " + obj + ")"); |
| 2038 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2039 | mHandler.obtainMessage(message, arg, 1, obj).sendToTarget(); |
Mike Lockwood | 98e4869 | 2010-04-07 16:32:51 -0400 | [diff] [blame] | 2040 | } |
| 2041 | |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 2042 | private final class ProviderHandler extends Handler { |
Victoria Lease | 5cd731a | 2012-12-19 15:04:21 -0800 | [diff] [blame] | 2043 | public ProviderHandler(Looper looper) { |
| 2044 | super(looper, null, true /*async*/); |
Jeff Brown | 028872f | 2012-08-25 13:07:01 -0700 | [diff] [blame] | 2045 | } |
| 2046 | |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 2047 | @Override |
Mike Lockwood | 4a7b65e | 2010-10-25 16:35:55 -0400 | [diff] [blame] | 2048 | public void handleMessage(Message msg) { |
Mike Lockwood | 98e4869 | 2010-04-07 16:32:51 -0400 | [diff] [blame] | 2049 | int message = msg.what; |
| 2050 | switch (message) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2051 | case SET_REQUEST: |
| 2052 | GpsRequest gpsRequest = (GpsRequest) msg.obj; |
| 2053 | handleSetRequest(gpsRequest.request, gpsRequest.source); |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 2054 | break; |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 2055 | case INJECT_NTP_TIME: |
Yu-Han Yang | a1862b5 | 2018-02-20 17:05:59 -0800 | [diff] [blame] | 2056 | mNtpTimeHelper.retrieveAndInjectNtpTime(); |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 2057 | break; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 2058 | case REQUEST_LOCATION: |
Yu-Han Yang | 53f4d6d | 2019-02-13 21:47:41 -0800 | [diff] [blame] | 2059 | handleRequestLocation(msg.arg1 == 1, (boolean) msg.obj); |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 2060 | break; |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 2061 | case DOWNLOAD_PSDS_DATA: |
| 2062 | handleDownloadPsdsData(); |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 2063 | break; |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 2064 | case DOWNLOAD_PSDS_DATA_FINISHED: |
| 2065 | mDownloadPsdsDataPending = STATE_IDLE; |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 2066 | break; |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 2067 | case UPDATE_LOCATION: |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 2068 | handleUpdateLocation((Location) msg.obj); |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 2069 | break; |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2070 | case INITIALIZE_HANDLER: |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 2071 | handleInitialize(); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2072 | break; |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 2073 | case REPORT_LOCATION: |
| 2074 | handleReportLocation(msg.arg1 == 1, (Location) msg.obj); |
| 2075 | break; |
| 2076 | case REPORT_SV_STATUS: |
| 2077 | handleReportSvStatus((SvStatusInfo) msg.obj); |
| 2078 | break; |
Kweku Adams | b8bb9fb | 2019-08-28 07:45:00 -0700 | [diff] [blame] | 2079 | case UPDATE_LOW_POWER_MODE: |
| 2080 | updateLowPowerMode(); |
| 2081 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2082 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2083 | if (msg.arg2 == 1) { |
| 2084 | // wakelock was taken for this message, release it |
| 2085 | mWakeLock.release(); |
Anil Admal | 4f97c94 | 2018-11-12 10:52:46 -0800 | [diff] [blame] | 2086 | if (DEBUG) { |
| 2087 | Log.d(TAG, "WakeLock released by handleMessage(" + messageIdAsString(message) |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2088 | + ", " + msg.arg1 + ", " + msg.obj + ")"); |
| 2089 | } |
Mike Lockwood | 98e4869 | 2010-04-07 16:32:51 -0400 | [diff] [blame] | 2090 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2091 | } |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2092 | |
| 2093 | /** |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 2094 | * This method is bound to {@link #GnssLocationProvider(Context, LocationProviderManager, |
| 2095 | * Looper)}. |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2096 | * It is in charge of loading properties and registering for events that will be posted to |
| 2097 | * this handler. |
| 2098 | */ |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 2099 | private void handleInitialize() { |
Anil Admal | 0c2b21bd | 2019-05-03 18:29:02 -0700 | [diff] [blame] | 2100 | // class_init_native() already initializes the GNSS service handle during class loading. |
| 2101 | setupNativeGnssService(/* reinitializeGnssServiceHandle = */ false); |
Wyatt Riley | 523a0cf | 2017-10-31 14:36:52 -0700 | [diff] [blame] | 2102 | |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 2103 | if (native_is_gnss_visibility_control_supported()) { |
Anil Admal | 8a246a2 | 2019-05-05 00:34:55 -0700 | [diff] [blame] | 2104 | mGnssVisibilityControl = new GnssVisibilityControl(mContext, mLooper, mNIHandler); |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 2105 | } |
| 2106 | |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2107 | // load default GPS configuration |
| 2108 | // (this configuration might change in the future based on SIM changes) |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 2109 | reloadGpsProperties(); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2110 | |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2111 | // listen for events |
WyattRiley | 6593cf1 | 2018-06-23 10:37:48 -0700 | [diff] [blame] | 2112 | IntentFilter intentFilter = new IntentFilter(); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2113 | intentFilter.addAction(ALARM_WAKEUP); |
| 2114 | intentFilter.addAction(ALARM_TIMEOUT); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2115 | intentFilter.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED); |
Adam Lesinski | 87c17df | 2015-05-27 13:24:13 -0700 | [diff] [blame] | 2116 | intentFilter.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2117 | intentFilter.addAction(Intent.ACTION_SCREEN_OFF); |
| 2118 | intentFilter.addAction(Intent.ACTION_SCREEN_ON); |
Meng Wang | 19b214d | 2018-11-07 12:14:39 -0800 | [diff] [blame] | 2119 | intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED); |
Anil Admal | e1539e8 | 2019-05-09 15:05:04 -0700 | [diff] [blame] | 2120 | intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2121 | mContext.registerReceiver(mBroadcastReceiver, intentFilter, null, this); |
| 2122 | |
Anil Admal | 50ba15e | 2018-11-01 16:42:42 -0700 | [diff] [blame] | 2123 | mNetworkConnectivityHandler.registerNetworkCallbacks(); |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 2124 | |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2125 | // listen for PASSIVE_PROVIDER updates |
| 2126 | LocationManager locManager = |
| 2127 | (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); |
| 2128 | long minTime = 0; |
| 2129 | float minDistance = 0; |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2130 | LocationRequest request = LocationRequest.createFromDeprecatedProvider( |
| 2131 | LocationManager.PASSIVE_PROVIDER, |
| 2132 | minTime, |
| 2133 | minDistance, |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 2134 | false); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2135 | // Don't keep track of this request since it's done on behalf of other clients |
| 2136 | // (which are kept track of separately). |
| 2137 | request.setHideFromAppOps(true); |
| 2138 | locManager.requestLocationUpdates( |
| 2139 | request, |
| 2140 | new NetworkLocationListener(), |
| 2141 | getLooper()); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 2142 | |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 2143 | updateEnabled(); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2144 | } |
| 2145 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2146 | |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 2147 | private abstract class LocationChangeListener implements LocationListener { |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 2148 | private int mNumLocationUpdateRequest; |
Yu-Han Yang | 0756138 | 2018-02-21 13:08:37 -0800 | [diff] [blame] | 2149 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2150 | @Override |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2151 | public void onStatusChanged(String provider, int status, Bundle extras) { |
| 2152 | } |
| 2153 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2154 | @Override |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2155 | public void onProviderEnabled(String provider) { |
| 2156 | } |
| 2157 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2158 | @Override |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2159 | public void onProviderDisabled(String provider) { |
| 2160 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2161 | } |
| 2162 | |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 2163 | private final class NetworkLocationListener extends LocationChangeListener { |
| 2164 | @Override |
| 2165 | public void onLocationChanged(Location location) { |
| 2166 | // this callback happens on mHandler looper |
| 2167 | if (LocationManager.NETWORK_PROVIDER.equals(location.getProvider())) { |
| 2168 | handleUpdateLocation(location); |
| 2169 | } |
| 2170 | } |
| 2171 | } |
| 2172 | |
| 2173 | private final class FusedLocationListener extends LocationChangeListener { |
| 2174 | @Override |
| 2175 | public void onLocationChanged(Location location) { |
| 2176 | if (LocationManager.FUSED_PROVIDER.equals(location.getProvider())) { |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 2177 | injectBestLocation(location); |
| 2178 | } |
| 2179 | } |
| 2180 | } |
| 2181 | |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2182 | /** |
| 2183 | * @return A string representing the given message ID. |
| 2184 | */ |
| 2185 | private String messageIdAsString(int message) { |
| 2186 | switch (message) { |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2187 | case SET_REQUEST: |
| 2188 | return "SET_REQUEST"; |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2189 | case INJECT_NTP_TIME: |
| 2190 | return "INJECT_NTP_TIME"; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 2191 | case REQUEST_LOCATION: |
| 2192 | return "REQUEST_LOCATION"; |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 2193 | case DOWNLOAD_PSDS_DATA: |
| 2194 | return "DOWNLOAD_PSDS_DATA"; |
| 2195 | case DOWNLOAD_PSDS_DATA_FINISHED: |
| 2196 | return "DOWNLOAD_PSDS_DATA_FINISHED"; |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2197 | case UPDATE_LOCATION: |
| 2198 | return "UPDATE_LOCATION"; |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2199 | case INITIALIZE_HANDLER: |
| 2200 | return "INITIALIZE_HANDLER"; |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 2201 | case REPORT_LOCATION: |
| 2202 | return "REPORT_LOCATION"; |
| 2203 | case REPORT_SV_STATUS: |
| 2204 | return "REPORT_SV_STATUS"; |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2205 | default: |
| 2206 | return "<Unknown>"; |
| 2207 | } |
| 2208 | } |
| 2209 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2210 | @Override |
| 2211 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 2212 | StringBuilder s = new StringBuilder(); |
WyattRiley | ba6072f | 2019-04-18 07:37:52 -0700 | [diff] [blame] | 2213 | s.append(" mStarted=").append(mStarted).append(" (changed "); |
| 2214 | TimeUtils.formatDuration(SystemClock.elapsedRealtime() |
| 2215 | - mStartedChangedElapsedRealtime, s); |
| 2216 | s.append(" ago)").append('\n'); |
destradaa | 25e8caf | 2015-08-24 14:14:44 -0700 | [diff] [blame] | 2217 | s.append(" mFixInterval=").append(mFixInterval).append('\n'); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2218 | s.append(" mLowPowerMode=").append(mLowPowerMode).append('\n'); |
Wyatt Riley | 74479bd | 2018-01-17 08:48:27 -0800 | [diff] [blame] | 2219 | s.append(" mGnssMeasurementsProvider.isRegistered()=") |
| 2220 | .append(mGnssMeasurementsProvider.isRegistered()).append('\n'); |
| 2221 | s.append(" mGnssNavigationMessageProvider.isRegistered()=") |
| 2222 | .append(mGnssNavigationMessageProvider.isRegistered()).append('\n'); |
WyattRiley | b244607 | 2019-03-01 07:41:49 -0800 | [diff] [blame] | 2223 | s.append(" mDisableGpsForPowerManager=").append(mDisableGpsForPowerManager).append('\n'); |
Anil Admal | 312fddb | 2019-03-25 12:15:43 -0700 | [diff] [blame] | 2224 | s.append(" mTopHalCapabilities=0x").append(Integer.toHexString(mTopHalCapabilities)); |
destradaa | 25e8caf | 2015-08-24 14:14:44 -0700 | [diff] [blame] | 2225 | s.append(" ( "); |
| 2226 | if (hasCapability(GPS_CAPABILITY_SCHEDULING)) s.append("SCHEDULING "); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2227 | if (hasCapability(GPS_CAPABILITY_MSB)) s.append("MSB "); |
| 2228 | if (hasCapability(GPS_CAPABILITY_MSA)) s.append("MSA "); |
| 2229 | if (hasCapability(GPS_CAPABILITY_SINGLE_SHOT)) s.append("SINGLE_SHOT "); |
| 2230 | if (hasCapability(GPS_CAPABILITY_ON_DEMAND_TIME)) s.append("ON_DEMAND_TIME "); |
destradaa | 25e8caf | 2015-08-24 14:14:44 -0700 | [diff] [blame] | 2231 | if (hasCapability(GPS_CAPABILITY_GEOFENCING)) s.append("GEOFENCING "); |
| 2232 | if (hasCapability(GPS_CAPABILITY_MEASUREMENTS)) s.append("MEASUREMENTS "); |
| 2233 | if (hasCapability(GPS_CAPABILITY_NAV_MESSAGES)) s.append("NAV_MESSAGES "); |
Anil Admal | efd9dc6 | 2019-03-12 17:39:20 -0700 | [diff] [blame] | 2234 | if (hasCapability(GPS_CAPABILITY_LOW_POWER_MODE)) s.append("LOW_POWER_MODE "); |
| 2235 | if (hasCapability(GPS_CAPABILITY_SATELLITE_BLACKLIST)) s.append("SATELLITE_BLACKLIST "); |
Anil Admal | 62c42dc | 2019-04-03 15:39:22 -0700 | [diff] [blame] | 2236 | if (hasCapability(GPS_CAPABILITY_MEASUREMENT_CORRECTIONS)) { |
| 2237 | s.append("MEASUREMENT_CORRECTIONS "); |
| 2238 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2239 | s.append(")\n"); |
Anil Admal | 3ba0fa9 | 2019-04-19 17:43:00 -0700 | [diff] [blame] | 2240 | if (hasCapability(GPS_CAPABILITY_MEASUREMENT_CORRECTIONS)) { |
Anil Admal | 62c42dc | 2019-04-03 15:39:22 -0700 | [diff] [blame] | 2241 | s.append(" SubHal=MEASUREMENT_CORRECTIONS["); |
Anil Admal | efd9dc6 | 2019-03-12 17:39:20 -0700 | [diff] [blame] | 2242 | s.append(mGnssMeasurementCorrectionsProvider.toStringCapabilities()); |
| 2243 | s.append("]\n"); |
| 2244 | } |
Siddharth Ray | bb608c8 | 2017-03-16 11:33:34 -0700 | [diff] [blame] | 2245 | s.append(mGnssMetrics.dumpGnssMetricsAsText()); |
| 2246 | s.append(" native internal state: ").append(native_get_internal_state()); |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2247 | s.append("\n"); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2248 | pw.append(s); |
| 2249 | } |
| 2250 | |
Anil Admal | 0c2b21bd | 2019-05-03 18:29:02 -0700 | [diff] [blame] | 2251 | private void setupNativeGnssService(boolean reinitializeGnssServiceHandle) { |
| 2252 | native_init_once(reinitializeGnssServiceHandle); |
Anil Admal | 7e3953b | 2019-05-04 20:45:22 -0700 | [diff] [blame] | 2253 | |
| 2254 | /* |
| 2255 | * A cycle of native_init() and native_cleanup() is needed so that callbacks are |
| 2256 | * registered after bootup even when location is disabled. |
| 2257 | * This will allow Emergency SUPL to work even when location is disabled before device |
| 2258 | * restart. |
| 2259 | */ |
| 2260 | boolean isInitialized = native_init(); |
| 2261 | if (!isInitialized) { |
| 2262 | Log.w(TAG, "Native initialization failed."); |
| 2263 | } else { |
| 2264 | native_cleanup(); |
| 2265 | } |
| 2266 | } |
| 2267 | |
Mike Lockwood | b16e780 | 2009-08-06 09:26:02 -0400 | [diff] [blame] | 2268 | // preallocated to avoid memory allocation in reportNmea() |
| 2269 | private byte[] mNmeaBuffer = new byte[120]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2270 | |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2271 | static { |
| 2272 | class_init_native(); |
| 2273 | } |
| 2274 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2275 | private static native void class_init_native(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2276 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2277 | private static native boolean native_is_supported(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2278 | |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 2279 | private static native boolean native_is_gnss_visibility_control_supported(); |
| 2280 | |
Anil Admal | 0c2b21bd | 2019-05-03 18:29:02 -0700 | [diff] [blame] | 2281 | private static native void native_init_once(boolean reinitializeGnssServiceHandle); |
Yu-Han Yang | 6d31735 | 2018-03-15 11:53:01 -0700 | [diff] [blame] | 2282 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2283 | private native boolean native_init(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2284 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2285 | private native void native_cleanup(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2286 | |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 2287 | private native boolean native_set_position_mode(int mode, int recurrence, int min_interval, |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2288 | int preferred_accuracy, int preferred_time, boolean lowPowerMode); |
| 2289 | |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 2290 | private native boolean native_start(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2291 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2292 | private native boolean native_stop(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2293 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2294 | private native void native_delete_aiding_data(int flags); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2295 | |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 2296 | private native int native_read_nmea(byte[] buffer, int bufferSize); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2297 | |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 2298 | private native void native_inject_best_location( |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 2299 | int gnssLocationFlags, double latitudeDegrees, double longitudeDegrees, |
| 2300 | double altitudeMeters, float speedMetersPerSec, float bearingDegrees, |
| 2301 | float horizontalAccuracyMeters, float verticalAccuracyMeters, |
| 2302 | float speedAccuracyMetersPerSecond, float bearingAccuracyDegrees, |
Pierre Fite-Georgel | 9e96c57 | 2019-02-25 16:12:53 -0800 | [diff] [blame] | 2303 | long timestamp, int elapsedRealtimeFlags, long elapsedRealtimeNanos, |
Yu-Han Yang | 3cd9a86 | 2019-03-25 17:00:03 -0700 | [diff] [blame] | 2304 | double elapsedRealtimeUncertaintyNanos); |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 2305 | |
Mike Lockwood | d26ce0d | 2009-06-11 12:25:46 -0400 | [diff] [blame] | 2306 | private native void native_inject_location(double latitude, double longitude, float accuracy); |
| 2307 | |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 2308 | // PSDS Support |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2309 | private native void native_inject_time(long time, long timeReference, int uncertainty); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2310 | |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 2311 | private native boolean native_supports_psds(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2312 | |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 2313 | private native void native_inject_psds_data(byte[] data, int length); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2314 | |
Fred Fettinger | 3c8fbdf | 2010-01-04 15:38:13 -0600 | [diff] [blame] | 2315 | // DEBUG Support |
| 2316 | private native String native_get_internal_state(); |
| 2317 | |
| 2318 | // AGPS Support |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2319 | private native void native_agps_ni_message(byte[] msg, int length); |
| 2320 | |
Mike Lockwood | a9e5461 | 2009-06-19 14:54:42 -0400 | [diff] [blame] | 2321 | 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] | 2322 | |
| 2323 | // Network-initiated (NI) Support |
| 2324 | private native void native_send_ni_response(int notificationId, int userResponse); |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 2325 | |
Anil Admal | 50ba15e | 2018-11-01 16:42:42 -0700 | [diff] [blame] | 2326 | // AGPS ril support |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 2327 | private native void native_agps_set_ref_location_cellid(int type, int mcc, int mnc, |
| 2328 | int lac, int cid); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2329 | |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 2330 | private native void native_agps_set_id(int type, String setid); |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 2331 | } |