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