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