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