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; |
Wei Wang | c5706f6 | 2017-04-18 11:26:26 -0700 | [diff] [blame] | 304 | |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 305 | private final ExponentialBackOff mPsdsBackOff = new ExponentialBackOff(RETRY_INTERVAL, |
Yu-Han Yang | a1862b5 | 2018-02-20 17:05:59 -0800 | [diff] [blame] | 306 | MAX_RETRY_INTERVAL); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 307 | |
Sasha Kuznetsov | b9f26b4 | 2019-10-03 17:30:46 -0700 | [diff] [blame] | 308 | private static boolean sIsInitialized = false; |
| 309 | private static boolean sStaticTestOverride = false; |
| 310 | |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 311 | // True if we are enabled |
| 312 | @GuardedBy("mLock") |
| 313 | private boolean mGpsEnabled; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 314 | |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 315 | private boolean mShutdown; |
| 316 | |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 317 | // states for injecting ntp and downloading psds data |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 318 | private static final int STATE_PENDING_NETWORK = 0; |
| 319 | private static final int STATE_DOWNLOADING = 1; |
| 320 | private static final int STATE_IDLE = 2; |
| 321 | |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 322 | // flags to trigger NTP or PSDS data download when network becomes available |
| 323 | // initialized to true so we do NTP and PSDS when the network comes up after booting |
| 324 | private int mDownloadPsdsDataPending = STATE_PENDING_NETWORK; |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 325 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 326 | // true if GPS is navigating |
| 327 | private boolean mNavigating; |
Mike Lockwood | cf1d8cb | 2010-01-20 10:14:54 -0500 | [diff] [blame] | 328 | |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 329 | // requested frequency of fixes, in milliseconds |
| 330 | private int mFixInterval = 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 331 | |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 332 | // true if low power mode for the GNSS chipset is part of the latest request. |
| 333 | private boolean mLowPowerMode = false; |
| 334 | |
WyattRiley | ba6072f | 2019-04-18 07:37:52 -0700 | [diff] [blame] | 335 | // 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] | 336 | private boolean mStarted; |
| 337 | |
WyattRiley | ba6072f | 2019-04-18 07:37:52 -0700 | [diff] [blame] | 338 | // for logging of latest change, and warning of ongoing location after a stop |
| 339 | private long mStartedChangedElapsedRealtime; |
| 340 | |
| 341 | // threshold for delay in GNSS engine turning off before warning & error |
| 342 | private static final long LOCATION_OFF_DELAY_THRESHOLD_WARN_MILLIS = 2 * 1000; |
| 343 | private static final long LOCATION_OFF_DELAY_THRESHOLD_ERROR_MILLIS = 15 * 1000; |
| 344 | |
Anil Admal | 312fddb | 2019-03-25 12:15:43 -0700 | [diff] [blame] | 345 | // capabilities reported through the top level IGnssCallback.hal |
| 346 | private volatile int mTopHalCapabilities; |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 347 | |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 348 | // true if PSDS is supported |
| 349 | private boolean mSupportsPsds; |
Mike Lockwood | 1a1cd3a | 2010-08-17 07:42:54 -0400 | [diff] [blame] | 350 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 351 | // for calculating time to first fix |
| 352 | private long mFixRequestTime = 0; |
| 353 | // time to first fix for most recent session |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 354 | private int mTimeToFirstFix = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 355 | // time we received our last fix |
| 356 | private long mLastFixTime; |
| 357 | |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 358 | private int mPositionMode; |
Yu-Han Yang | c8b9ff7 | 2018-04-17 00:47:24 -0700 | [diff] [blame] | 359 | private GnssPositionMode mLastPositionMode; |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 360 | |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 361 | // Current request from underlying location clients. |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 362 | private ProviderRequest mProviderRequest; |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 363 | // The WorkSource associated with the most recent client request (i.e, most recent call to |
| 364 | // setRequest). |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 365 | private WorkSource mWorkSource = null; |
WyattRiley | b244607 | 2019-03-01 07:41:49 -0800 | [diff] [blame] | 366 | // True if gps should be disabled because of PowerManager controls |
| 367 | private boolean mDisableGpsForPowerManager = false; |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 368 | |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 369 | /** |
Kweku Adams | 810c77d | 2019-08-28 07:45:00 -0700 | [diff] [blame] | 370 | * True if the device idle controller has determined that the device is stationary. This is only |
| 371 | * updated when the device enters idle mode. |
| 372 | */ |
| 373 | private volatile boolean mIsDeviceStationary = false; |
| 374 | |
| 375 | /** |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 376 | * Properties loaded from PROPERTIES_FILE. |
| 377 | * It must be accessed only inside {@link #mHandler}. |
| 378 | */ |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 379 | private GnssConfiguration mGnssConfiguration; |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 380 | |
Mike Lockwood | 734d603 | 2009-07-28 18:30:25 -0700 | [diff] [blame] | 381 | private String mSuplServerHost; |
Tsuwei Chen | 678c13c | 2014-09-22 17:48:41 -0700 | [diff] [blame] | 382 | private int mSuplServerPort = TCP_MIN_PORT; |
Mike Lockwood | 734d603 | 2009-07-28 18:30:25 -0700 | [diff] [blame] | 383 | private String mC2KServerHost; |
| 384 | private int mC2KServerPort; |
Tsuwei Chen | 3324e95 | 2014-09-07 01:30:42 -0700 | [diff] [blame] | 385 | private boolean mSuplEsEnabled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 386 | |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 387 | private final Looper mLooper; |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 388 | private final LocationExtras mLocationExtras = new LocationExtras(); |
Anil Admal | 75b9fd6 | 2018-11-28 11:22:50 -0800 | [diff] [blame] | 389 | private final GnssStatusListenerHelper mGnssStatusListenerHelper; |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 390 | private final GnssMeasurementsProvider mGnssMeasurementsProvider; |
Anil Admal | efd9dc6 | 2019-03-12 17:39:20 -0700 | [diff] [blame] | 391 | private final GnssMeasurementCorrectionsProvider mGnssMeasurementCorrectionsProvider; |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 392 | private final GnssNavigationMessageProvider mGnssNavigationMessageProvider; |
Yu-Han Yang | 0756138 | 2018-02-21 13:08:37 -0800 | [diff] [blame] | 393 | private final LocationChangeListener mNetworkLocationListener = new NetworkLocationListener(); |
| 394 | private final LocationChangeListener mFusedLocationListener = new FusedLocationListener(); |
Yu-Han Yang | a1862b5 | 2018-02-20 17:05:59 -0800 | [diff] [blame] | 395 | private final NtpTimeHelper mNtpTimeHelper; |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 396 | private final GnssBatchingProvider mGnssBatchingProvider; |
Yu-Han Yang | 890ca8b | 2018-04-16 22:11:31 -0700 | [diff] [blame] | 397 | private final GnssGeofenceProvider mGnssGeofenceProvider; |
Anil Admal | 312fddb | 2019-03-25 12:15:43 -0700 | [diff] [blame] | 398 | private final GnssCapabilitiesProvider mGnssCapabilitiesProvider; |
| 399 | |
Anil Admal | 316f948 | 2019-02-12 18:57:18 -0800 | [diff] [blame] | 400 | // Available only on GNSS HAL 2.0 implementations and later. |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 401 | private GnssVisibilityControl mGnssVisibilityControl; |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 402 | |
Victoria Lease | 5c24fd0 | 2012-10-01 11:00:50 -0700 | [diff] [blame] | 403 | // Handler for processing events |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 404 | private Handler mHandler; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 405 | |
Anil Admal | 50ba15e | 2018-11-01 16:42:42 -0700 | [diff] [blame] | 406 | private final GnssNetworkConnectivityHandler mNetworkConnectivityHandler; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 407 | private final GpsNetInitiatedHandler mNIHandler; |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 408 | |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 409 | // Wakelocks |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 410 | private final static String WAKELOCK_KEY = "GnssLocationProvider"; |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 411 | private final PowerManager.WakeLock mWakeLock; |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 412 | private static final String DOWNLOAD_EXTRA_WAKELOCK_KEY = "GnssLocationProviderPsdsDownload"; |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 413 | @GuardedBy("mLock") |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 414 | private final PowerManager.WakeLock mDownloadPsdsWakeLock; |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 415 | |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 416 | // Alarms |
| 417 | private final static String ALARM_WAKEUP = "com.android.internal.location.ALARM_WAKEUP"; |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 418 | private final static String ALARM_TIMEOUT = "com.android.internal.location.ALARM_TIMEOUT"; |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 419 | |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 420 | private final PowerManager mPowerManager; |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 421 | private final AlarmManager mAlarmManager; |
| 422 | private final PendingIntent mWakeupIntent; |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 423 | private final PendingIntent mTimeoutIntent; |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 424 | |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 425 | private final AppOpsManager mAppOps; |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 426 | private final IBatteryStats mBatteryStats; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 427 | |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 428 | // Current list of underlying location clients. |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 429 | // only modified on handler thread |
Dianne Hackborn | 002a54e | 2013-01-10 17:34:55 -0800 | [diff] [blame] | 430 | private WorkSource mClientSource = new WorkSource(); |
Mike Lockwood | f1218be | 2010-01-29 09:20:06 -0500 | [diff] [blame] | 431 | |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 432 | private GeofenceHardwareImpl mGeofenceHardwareImpl; |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 433 | |
| 434 | // Volatile for simple inter-thread sync on these values. |
| 435 | private volatile int mHardwareYear = 0; |
Wyatt Riley | 49097c0 | 2018-03-15 09:14:43 -0700 | [diff] [blame] | 436 | private volatile String mHardwareModelName; |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 437 | |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 438 | // Set lower than the current ITAR limit of 600m/s to allow this to trigger even if GPS HAL |
| 439 | // stops output right at 600m/s, depriving this of the information of a device that reaches |
| 440 | // greater than 600m/s, and higher than the speed of sound to avoid impacting most use cases. |
| 441 | private static final float ITAR_SPEED_LIMIT_METERS_PER_SECOND = 400.0F; |
Wyatt Riley | 042c48f | 2017-10-06 14:59:25 -0700 | [diff] [blame] | 442 | |
Wyatt Riley | 042c48f | 2017-10-06 14:59:25 -0700 | [diff] [blame] | 443 | private volatile boolean mItarSpeedLimitExceeded = false; |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 444 | |
Siddharth Ray | bb608c8 | 2017-03-16 11:33:34 -0700 | [diff] [blame] | 445 | // GNSS Metrics |
| 446 | private GnssMetrics mGnssMetrics; |
| 447 | |
Anil Admal | 75b9fd6 | 2018-11-28 11:22:50 -0800 | [diff] [blame] | 448 | public GnssStatusListenerHelper getGnssStatusProvider() { |
| 449 | return mGnssStatusListenerHelper; |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 450 | } |
| 451 | |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 452 | public IGpsGeofenceHardware getGpsGeofenceProxy() { |
Yu-Han Yang | 890ca8b | 2018-04-16 22:11:31 -0700 | [diff] [blame] | 453 | return mGnssGeofenceProvider; |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 456 | public GnssMeasurementsProvider getGnssMeasurementsProvider() { |
| 457 | return mGnssMeasurementsProvider; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 458 | } |
| 459 | |
Anil Admal | efd9dc6 | 2019-03-12 17:39:20 -0700 | [diff] [blame] | 460 | public GnssMeasurementCorrectionsProvider getGnssMeasurementCorrectionsProvider() { |
| 461 | return mGnssMeasurementCorrectionsProvider; |
| 462 | } |
| 463 | |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 464 | public GnssNavigationMessageProvider getGnssNavigationMessageProvider() { |
| 465 | return mGnssNavigationMessageProvider; |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 466 | } |
Kweku Adams | 810c77d | 2019-08-28 07:45:00 -0700 | [diff] [blame] | 467 | |
| 468 | private final DeviceIdleInternal.StationaryListener mDeviceIdleStationaryListener = |
| 469 | isStationary -> { |
| 470 | mIsDeviceStationary = isStationary; |
| 471 | // Call updateLowPowerMode on handler thread so it's always called from the same |
| 472 | // thread. |
| 473 | mHandler.sendEmptyMessage(UPDATE_LOW_POWER_MODE); |
| 474 | }; |
| 475 | |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 476 | private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 477 | @Override |
| 478 | public void onReceive(Context context, Intent intent) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 479 | String action = intent.getAction(); |
Tsuwei Chen | 48d37f9 | 2014-09-05 15:15:34 -0700 | [diff] [blame] | 480 | if (DEBUG) Log.d(TAG, "receive broadcast intent, action: " + action); |
destradaa | ee9fd34 | 2015-08-31 13:31:17 -0700 | [diff] [blame] | 481 | if (action == null) { |
| 482 | return; |
| 483 | } |
| 484 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 485 | switch (action) { |
| 486 | case ALARM_WAKEUP: |
Yu-Han Yang | 6a5f0b7 | 2019-01-24 18:34:28 -0800 | [diff] [blame] | 487 | startNavigating(); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 488 | break; |
| 489 | case ALARM_TIMEOUT: |
| 490 | hibernate(); |
| 491 | break; |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 492 | case PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED: |
Kweku Adams | 810c77d | 2019-08-28 07:45:00 -0700 | [diff] [blame] | 493 | DeviceIdleInternal deviceIdleService = LocalServices.getService( |
| 494 | DeviceIdleInternal.class); |
| 495 | if (mPowerManager.isDeviceIdleMode()) { |
| 496 | deviceIdleService.registerStationaryListener(mDeviceIdleStationaryListener); |
| 497 | } else { |
| 498 | deviceIdleService.unregisterStationaryListener( |
| 499 | mDeviceIdleStationaryListener); |
| 500 | } |
| 501 | // Intentional fall-through. |
| 502 | case PowerManager.ACTION_POWER_SAVE_MODE_CHANGED: |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 503 | case Intent.ACTION_SCREEN_OFF: |
| 504 | case Intent.ACTION_SCREEN_ON: |
Kweku Adams | 810c77d | 2019-08-28 07:45:00 -0700 | [diff] [blame] | 505 | // Call updateLowPowerMode on handler thread so it's always called from the |
| 506 | // same thread. |
| 507 | mHandler.sendEmptyMessage(UPDATE_LOW_POWER_MODE); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 508 | break; |
Meng Wang | 19b214d | 2018-11-07 12:14:39 -0800 | [diff] [blame] | 509 | case CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED: |
Anil Admal | e1539e8 | 2019-05-09 15:05:04 -0700 | [diff] [blame] | 510 | case TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED: |
Soonil Nagarkar | fc9c7f8 | 2019-07-16 12:07:57 -0700 | [diff] [blame] | 511 | subscriptionOrCarrierConfigChanged(); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 512 | break; |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 513 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 514 | } |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 515 | }; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 516 | |
Yu-Han Yang | 66c7ea9 | 2018-03-11 17:17:15 -0700 | [diff] [blame] | 517 | /** |
| 518 | * Implements {@link GnssSatelliteBlacklistCallback#onUpdateSatelliteBlacklist}. |
| 519 | */ |
| 520 | @Override |
| 521 | public void onUpdateSatelliteBlacklist(int[] constellations, int[] svids) { |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 522 | mHandler.post(() -> mGnssConfiguration.setSatelliteBlacklist(constellations, svids)); |
Yu-Han Yang | 284234e | 2019-03-28 19:35:57 -0700 | [diff] [blame] | 523 | mGnssMetrics.resetConstellationTypes(); |
Yu-Han Yang | 66c7ea9 | 2018-03-11 17:17:15 -0700 | [diff] [blame] | 524 | } |
| 525 | |
Soonil Nagarkar | fc9c7f8 | 2019-07-16 12:07:57 -0700 | [diff] [blame] | 526 | private void subscriptionOrCarrierConfigChanged() { |
Joe Onorato | 0c48410 | 2016-02-01 18:04:24 -0800 | [diff] [blame] | 527 | if (DEBUG) Log.d(TAG, "received SIM related action: "); |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 528 | TelephonyManager phone = (TelephonyManager) |
| 529 | mContext.getSystemService(Context.TELEPHONY_SERVICE); |
Ecco Park | 4fa1ab7 | 2016-10-24 13:04:52 -0700 | [diff] [blame] | 530 | CarrierConfigManager configManager = (CarrierConfigManager) |
| 531 | mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Anil Admal | e1539e8 | 2019-05-09 15:05:04 -0700 | [diff] [blame] | 532 | int ddSubId = SubscriptionManager.getDefaultDataSubscriptionId(); |
| 533 | String mccMnc = SubscriptionManager.isValidSubscriptionId(ddSubId) |
| 534 | ? phone.getSimOperator(ddSubId) : phone.getSimOperator(); |
Ecco Park | 4fa1ab7 | 2016-10-24 13:04:52 -0700 | [diff] [blame] | 535 | boolean isKeepLppProfile = false; |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 536 | if (!TextUtils.isEmpty(mccMnc)) { |
Joe Onorato | 0c48410 | 2016-02-01 18:04:24 -0800 | [diff] [blame] | 537 | if (DEBUG) Log.d(TAG, "SIM MCC/MNC is available: " + mccMnc); |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 538 | if (configManager != null) { |
Anil Admal | e1539e8 | 2019-05-09 15:05:04 -0700 | [diff] [blame] | 539 | PersistableBundle b = SubscriptionManager.isValidSubscriptionId(ddSubId) |
| 540 | ? configManager.getConfigForSubId(ddSubId) : null; |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 541 | if (b != null) { |
| 542 | isKeepLppProfile = |
| 543 | b.getBoolean(CarrierConfigManager.Gps.KEY_PERSIST_LPP_MODE_BOOL); |
Ecco Park | 4fa1ab7 | 2016-10-24 13:04:52 -0700 | [diff] [blame] | 544 | } |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 545 | } |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 546 | if (isKeepLppProfile) { |
| 547 | // load current properties for the carrier |
| 548 | mGnssConfiguration.loadPropertiesFromCarrierConfig(); |
| 549 | String lpp_profile = mGnssConfiguration.getLppProfile(); |
| 550 | // set the persist property LPP_PROFILE for the value |
| 551 | if (lpp_profile != null) { |
| 552 | SystemProperties.set(GnssConfiguration.LPP_PROFILE, lpp_profile); |
| 553 | } |
| 554 | } else { |
| 555 | // reset the persist property |
| 556 | SystemProperties.set(GnssConfiguration.LPP_PROFILE, ""); |
| 557 | } |
| 558 | reloadGpsProperties(); |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 559 | } else { |
Joe Onorato | 0c48410 | 2016-02-01 18:04:24 -0800 | [diff] [blame] | 560 | if (DEBUG) Log.d(TAG, "SIM MCC/MNC is still not available"); |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 561 | } |
| 562 | } |
| 563 | |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 564 | private void updateLowPowerMode() { |
Kweku Adams | 810c77d | 2019-08-28 07:45:00 -0700 | [diff] [blame] | 565 | // Disable GPS if we are in device idle mode and the device is stationary. |
| 566 | boolean disableGpsForPowerManager = mPowerManager.isDeviceIdleMode() && mIsDeviceStationary; |
| 567 | final PowerSaveState result = mPowerManager.getPowerSaveState(ServiceType.LOCATION); |
Kweku Adams | 731a103 | 2019-02-04 14:05:41 -0800 | [diff] [blame] | 568 | switch (result.locationMode) { |
Makoto Onuki | 57f0f55 | 2017-12-11 12:22:18 -0800 | [diff] [blame] | 569 | case PowerManager.LOCATION_MODE_GPS_DISABLED_WHEN_SCREEN_OFF: |
Kweku Adams | 5e0052b | 2019-02-22 15:17:52 -0800 | [diff] [blame] | 570 | case PowerManager.LOCATION_MODE_ALL_DISABLED_WHEN_SCREEN_OFF: |
Adam Lesinski | 87c17df | 2015-05-27 13:24:13 -0700 | [diff] [blame] | 571 | // If we are in battery saver mode and the screen is off, disable GPS. |
WyattRiley | b244607 | 2019-03-01 07:41:49 -0800 | [diff] [blame] | 572 | disableGpsForPowerManager |= |
| 573 | result.batterySaverEnabled && !mPowerManager.isInteractive(); |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 574 | break; |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 575 | } |
WyattRiley | b244607 | 2019-03-01 07:41:49 -0800 | [diff] [blame] | 576 | if (disableGpsForPowerManager != mDisableGpsForPowerManager) { |
| 577 | mDisableGpsForPowerManager = disableGpsForPowerManager; |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 578 | updateEnabled(); |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 579 | updateRequirements(); |
| 580 | } |
| 581 | } |
| 582 | |
Sasha Kuznetsov | b9f26b4 | 2019-10-03 17:30:46 -0700 | [diff] [blame] | 583 | @VisibleForTesting |
| 584 | public static void setIsSupportedForTest(boolean override) { |
| 585 | sStaticTestOverride = override; |
| 586 | } |
| 587 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 588 | public static boolean isSupported() { |
Sasha Kuznetsov | b9f26b4 | 2019-10-03 17:30:46 -0700 | [diff] [blame] | 589 | if (sStaticTestOverride) { |
| 590 | return true; |
| 591 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 592 | return native_is_supported(); |
| 593 | } |
| 594 | |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 595 | private void reloadGpsProperties() { |
| 596 | mGnssConfiguration.reloadGpsProperties(); |
| 597 | setSuplHostPort(); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 598 | // TODO: we should get rid of C2K specific setting. |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 599 | mC2KServerHost = mGnssConfiguration.getC2KHost(); |
| 600 | mC2KServerPort = mGnssConfiguration.getC2KPort(TCP_MIN_PORT); |
| 601 | mNIHandler.setEmergencyExtensionSeconds(mGnssConfiguration.getEsExtensionSec()); |
| 602 | mSuplEsEnabled = mGnssConfiguration.getSuplEs(0) == 1; |
Anil Admal | e1539e8 | 2019-05-09 15:05:04 -0700 | [diff] [blame] | 603 | mNIHandler.setSuplEsEnabled(mSuplEsEnabled); |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 604 | if (mGnssVisibilityControl != null) { |
Anil Admal | e1539e8 | 2019-05-09 15:05:04 -0700 | [diff] [blame] | 605 | mGnssVisibilityControl.onConfigurationUpdated(mGnssConfiguration); |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 606 | } |
Colin Cross | 7c030ed | 2014-01-28 09:33:53 -0800 | [diff] [blame] | 607 | } |
| 608 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 609 | public GnssLocationProvider(Context context, LocationProviderManager locationProviderManager, |
Victoria Lease | 5cd731a | 2012-12-19 15:04:21 -0800 | [diff] [blame] | 610 | Looper looper) { |
Soonil Nagarkar | 0d77ea6 | 2019-01-31 14:36:56 -0800 | [diff] [blame] | 611 | super(context, locationProviderManager); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 612 | |
Sasha Kuznetsov | b9f26b4 | 2019-10-03 17:30:46 -0700 | [diff] [blame] | 613 | synchronized (mLock) { |
| 614 | if (!sIsInitialized) { |
| 615 | class_init_native(); |
| 616 | } |
| 617 | sIsInitialized = true; |
| 618 | } |
| 619 | |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 620 | mLooper = looper; |
Mike Lockwood | 63598a0 | 2010-02-24 11:52:59 -0500 | [diff] [blame] | 621 | |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 622 | // Create a wake lock |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 623 | mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); |
| 624 | mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCK_KEY); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 625 | mWakeLock.setReferenceCounted(true); |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 626 | |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 627 | // Create a separate wake lock for psds downloader as it may be released due to timeout. |
| 628 | mDownloadPsdsWakeLock = mPowerManager.newWakeLock( |
Wei Wang | b71c049 | 2017-05-01 20:24:19 -0700 | [diff] [blame] | 629 | PowerManager.PARTIAL_WAKE_LOCK, DOWNLOAD_EXTRA_WAKELOCK_KEY); |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 630 | mDownloadPsdsWakeLock.setReferenceCounted(true); |
Wei Wang | b71c049 | 2017-05-01 20:24:19 -0700 | [diff] [blame] | 631 | |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 632 | mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 633 | mWakeupIntent = PendingIntent.getBroadcast(mContext, 0, new Intent(ALARM_WAKEUP), 0); |
Mike Lockwood | 0632ca7 | 2009-05-14 15:51:03 -0400 | [diff] [blame] | 634 | mTimeoutIntent = PendingIntent.getBroadcast(mContext, 0, new Intent(ALARM_TIMEOUT), 0); |
Mike Lockwood | 29c8434 | 2009-05-06 14:01:15 -0400 | [diff] [blame] | 635 | |
Anil Admal | 312fddb | 2019-03-25 12:15:43 -0700 | [diff] [blame] | 636 | mNetworkConnectivityHandler = new GnssNetworkConnectivityHandler(context, |
| 637 | GnssLocationProvider.this::onNetworkAvailable, looper); |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 638 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 639 | // App ops service to keep track of who is accessing the GPS |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 640 | mAppOps = mContext.getSystemService(AppOpsManager.class); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 641 | |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 642 | // Battery statistics service to be notified when GPS turns on or off |
Dianne Hackborn | 91268cf | 2013-06-13 19:06:50 -0700 | [diff] [blame] | 643 | mBatteryStats = IBatteryStats.Stub.asInterface(ServiceManager.getService( |
| 644 | BatteryStats.SERVICE_NAME)); |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 645 | |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 646 | // Construct internal handler |
| 647 | mHandler = new ProviderHandler(looper); |
| 648 | |
| 649 | // Load GPS configuration and register listeners in the background: |
| 650 | // some operations, such as opening files and registering broadcast receivers, can take a |
| 651 | // relative long time, so the ctor() is kept to create objects needed by this instance, |
| 652 | // while IO initialization and registration is delegated to our internal handler |
| 653 | // 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] | 654 | mGnssConfiguration = new GnssConfiguration(mContext); |
Anil Admal | 312fddb | 2019-03-25 12:15:43 -0700 | [diff] [blame] | 655 | mGnssCapabilitiesProvider = new GnssCapabilitiesProvider(); |
WyattRiley | d130931 | 2019-02-28 12:11:45 -0800 | [diff] [blame] | 656 | // Create a GPS net-initiated handler (also needed by handleInitialize) |
Tsuwei Chen | 3324e95 | 2014-09-07 01:30:42 -0700 | [diff] [blame] | 657 | mNIHandler = new GpsNetInitiatedHandler(context, |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 658 | mNetInitiatedListener, |
| 659 | mSuplEsEnabled); |
WyattRiley | d130931 | 2019-02-28 12:11:45 -0800 | [diff] [blame] | 660 | sendMessage(INITIALIZE_HANDLER, 0, null); |
Tsuwei Chen | 3324e95 | 2014-09-07 01:30:42 -0700 | [diff] [blame] | 661 | |
Anil Admal | 75b9fd6 | 2018-11-28 11:22:50 -0800 | [diff] [blame] | 662 | mGnssStatusListenerHelper = new GnssStatusListenerHelper(mContext, mHandler) { |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 663 | @Override |
| 664 | protected boolean isAvailableInPlatform() { |
destradaa | 13a60b0 | 2015-01-15 18:36:01 -0800 | [diff] [blame] | 665 | return isSupported(); |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | @Override |
| 669 | protected boolean isGpsEnabled() { |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 670 | return GnssLocationProvider.this.isGpsEnabled(); |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 671 | } |
| 672 | }; |
| 673 | |
Yu-Han Yang | 8de2150 | 2018-04-23 01:40:25 -0700 | [diff] [blame] | 674 | mGnssMeasurementsProvider = new GnssMeasurementsProvider(mContext, mHandler) { |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 675 | @Override |
| 676 | protected boolean isGpsEnabled() { |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 677 | return GnssLocationProvider.this.isGpsEnabled(); |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 678 | } |
| 679 | }; |
| 680 | |
Anil Admal | efd9dc6 | 2019-03-12 17:39:20 -0700 | [diff] [blame] | 681 | mGnssMeasurementCorrectionsProvider = new GnssMeasurementCorrectionsProvider(mHandler); |
| 682 | |
Anil Admal | 75b9fd6 | 2018-11-28 11:22:50 -0800 | [diff] [blame] | 683 | mGnssNavigationMessageProvider = new GnssNavigationMessageProvider(mContext, mHandler) { |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 684 | @Override |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 685 | protected boolean isGpsEnabled() { |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 686 | return GnssLocationProvider.this.isGpsEnabled(); |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 687 | } |
| 688 | }; |
Yu-Han Yang | a1862b5 | 2018-02-20 17:05:59 -0800 | [diff] [blame] | 689 | |
Anil Admal | 50ba15e | 2018-11-01 16:42:42 -0700 | [diff] [blame] | 690 | mGnssMetrics = new GnssMetrics(mBatteryStats); |
Yu-Han Yang | 66c7ea9 | 2018-03-11 17:17:15 -0700 | [diff] [blame] | 691 | mNtpTimeHelper = new NtpTimeHelper(mContext, looper, this); |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 692 | GnssSatelliteBlacklistHelper gnssSatelliteBlacklistHelper = |
| 693 | new GnssSatelliteBlacklistHelper(mContext, |
| 694 | looper, this); |
| 695 | mHandler.post(gnssSatelliteBlacklistHelper::updateSatelliteBlacklist); |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 696 | mGnssBatchingProvider = new GnssBatchingProvider(); |
Yu-Han Yang | 6dc9f05 | 2018-12-04 17:11:24 -0800 | [diff] [blame] | 697 | mGnssGeofenceProvider = new GnssGeofenceProvider(); |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 698 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 699 | mContext.registerReceiverAsUser(new BroadcastReceiver() { |
| 700 | @Override |
| 701 | public void onReceive(Context context, Intent intent) { |
| 702 | if (getSendingUserId() == UserHandle.USER_ALL) { |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 703 | mShutdown = true; |
| 704 | updateEnabled(); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 705 | } |
| 706 | } |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 707 | }, UserHandle.ALL, new IntentFilter(Intent.ACTION_SHUTDOWN), null, mHandler); |
| 708 | |
| 709 | mContext.getContentResolver().registerContentObserver( |
| 710 | Settings.Secure.getUriFor(Settings.Secure.LOCATION_MODE), |
| 711 | true, |
| 712 | new ContentObserver(mHandler) { |
| 713 | @Override |
| 714 | public void onChange(boolean selfChange) { |
| 715 | updateEnabled(); |
| 716 | } |
| 717 | }, UserHandle.USER_ALL); |
Mike Lockwood | d03ff94 | 2010-02-09 08:46:14 -0500 | [diff] [blame] | 718 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 719 | setProperties(PROPERTIES); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 720 | setEnabled(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 721 | } |
| 722 | |
Yu-Han Yang | a1862b5 | 2018-02-20 17:05:59 -0800 | [diff] [blame] | 723 | /** |
| 724 | * Implements {@link InjectNtpTimeCallback#injectTime} |
| 725 | */ |
| 726 | @Override |
| 727 | public void injectTime(long time, long timeReference, int uncertainty) { |
| 728 | native_inject_time(time, timeReference, uncertainty); |
| 729 | } |
| 730 | |
Anil Admal | 50ba15e | 2018-11-01 16:42:42 -0700 | [diff] [blame] | 731 | /** |
| 732 | * Implements {@link GnssNetworkConnectivityHandler.GnssNetworkListener#onNetworkAvailable()} |
| 733 | */ |
| 734 | private void onNetworkAvailable() { |
| 735 | mNtpTimeHelper.onNetworkAvailable(); |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 736 | if (mDownloadPsdsDataPending == STATE_PENDING_NETWORK) { |
| 737 | if (mSupportsPsds) { |
Anil Admal | 316f948 | 2019-02-12 18:57:18 -0800 | [diff] [blame] | 738 | // Download only if supported, (prevents an unnecessary on-boot download) |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 739 | psdsDownloadRequest(); |
destradaa | ef752b6 | 2015-04-17 13:10:47 -0700 | [diff] [blame] | 740 | } |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 741 | } |
| 742 | } |
Yu-Han Yang | 8de2150 | 2018-04-23 01:40:25 -0700 | [diff] [blame] | 743 | |
Yu-Han Yang | 53f4d6d | 2019-02-13 21:47:41 -0800 | [diff] [blame] | 744 | private void handleRequestLocation(boolean independentFromGnss, boolean isUserEmergency) { |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 745 | if (isRequestLocationRateLimited()) { |
| 746 | if (DEBUG) { |
| 747 | Log.d(TAG, "RequestLocation is denied due to too frequent requests."); |
| 748 | } |
| 749 | return; |
| 750 | } |
Yu-Han Yang | 74041ff | 2018-04-06 15:57:31 -0700 | [diff] [blame] | 751 | ContentResolver resolver = mContext.getContentResolver(); |
| 752 | long durationMillis = Settings.Global.getLong( |
| 753 | resolver, |
| 754 | Settings.Global.GNSS_HAL_LOCATION_REQUEST_DURATION_MILLIS, |
| 755 | LOCATION_UPDATE_DURATION_MILLIS); |
| 756 | if (durationMillis == 0) { |
| 757 | Log.i(TAG, "GNSS HAL location request is disabled by Settings."); |
| 758 | return; |
| 759 | } |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 760 | |
| 761 | LocationManager locationManager = (LocationManager) mContext.getSystemService( |
| 762 | Context.LOCATION_SERVICE); |
Yu-Han Yang | 0756138 | 2018-02-21 13:08:37 -0800 | [diff] [blame] | 763 | String provider; |
| 764 | LocationChangeListener locationListener; |
Anil Admal | b1c6c0d | 2019-06-20 12:00:16 -0700 | [diff] [blame] | 765 | LocationRequest locationRequest = new LocationRequest() |
| 766 | .setInterval(LOCATION_UPDATE_MIN_TIME_INTERVAL_MILLIS) |
| 767 | .setFastestInterval(LOCATION_UPDATE_MIN_TIME_INTERVAL_MILLIS); |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 768 | |
| 769 | if (independentFromGnss) { |
| 770 | // For fast GNSS TTFF |
Yu-Han Yang | 0756138 | 2018-02-21 13:08:37 -0800 | [diff] [blame] | 771 | provider = LocationManager.NETWORK_PROVIDER; |
| 772 | locationListener = mNetworkLocationListener; |
Anil Admal | b1c6c0d | 2019-06-20 12:00:16 -0700 | [diff] [blame] | 773 | locationRequest.setQuality(LocationRequest.POWER_LOW); |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 774 | } else { |
| 775 | // For Device-Based Hybrid (E911) |
Yu-Han Yang | 0756138 | 2018-02-21 13:08:37 -0800 | [diff] [blame] | 776 | provider = LocationManager.FUSED_PROVIDER; |
| 777 | locationListener = mFusedLocationListener; |
Anil Admal | b1c6c0d | 2019-06-20 12:00:16 -0700 | [diff] [blame] | 778 | locationRequest.setQuality(LocationRequest.ACCURACY_FINE); |
| 779 | } |
| 780 | |
| 781 | locationRequest.setProvider(provider); |
| 782 | |
| 783 | // Ignore location settings if in emergency mode. |
| 784 | if (isUserEmergency && mNIHandler.getInEmergency()) { |
| 785 | locationRequest.setLocationSettingsIgnored(true); |
| 786 | durationMillis *= EMERGENCY_LOCATION_UPDATE_DURATION_MULTIPLIER; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 787 | } |
Yu-Han Yang | 0756138 | 2018-02-21 13:08:37 -0800 | [diff] [blame] | 788 | |
| 789 | Log.i(TAG, |
Yu-Han Yang | 74041ff | 2018-04-06 15:57:31 -0700 | [diff] [blame] | 790 | String.format( |
| 791 | "GNSS HAL Requesting location updates from %s provider for %d millis.", |
| 792 | provider, durationMillis)); |
Yu-Han Yang | 53f4d6d | 2019-02-13 21:47:41 -0800 | [diff] [blame] | 793 | |
Yu-Han Yang | e684dda | 2018-05-24 10:29:39 -0700 | [diff] [blame] | 794 | try { |
Yu-Han Yang | 53f4d6d | 2019-02-13 21:47:41 -0800 | [diff] [blame] | 795 | locationManager.requestLocationUpdates(locationRequest, |
Yu-Han Yang | e684dda | 2018-05-24 10:29:39 -0700 | [diff] [blame] | 796 | locationListener, mHandler.getLooper()); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 797 | locationListener.mNumLocationUpdateRequest++; |
Yu-Han Yang | e684dda | 2018-05-24 10:29:39 -0700 | [diff] [blame] | 798 | mHandler.postDelayed(() -> { |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 799 | if (--locationListener.mNumLocationUpdateRequest == 0) { |
Yu-Han Yang | e684dda | 2018-05-24 10:29:39 -0700 | [diff] [blame] | 800 | Log.i(TAG, |
| 801 | String.format("Removing location updates from %s provider.", provider)); |
| 802 | locationManager.removeUpdates(locationListener); |
| 803 | } |
| 804 | }, durationMillis); |
| 805 | } catch (IllegalArgumentException e) { |
| 806 | Log.w(TAG, "Unable to request location.", e); |
| 807 | } |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | private void injectBestLocation(Location location) { |
Anil Admal | b1c6c0d | 2019-06-20 12:00:16 -0700 | [diff] [blame] | 811 | if (DEBUG) { |
| 812 | Log.d(TAG, "injectBestLocation: " + location); |
| 813 | } |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 814 | int gnssLocationFlags = LOCATION_HAS_LAT_LONG | |
| 815 | (location.hasAltitude() ? LOCATION_HAS_ALTITUDE : 0) | |
| 816 | (location.hasSpeed() ? LOCATION_HAS_SPEED : 0) | |
| 817 | (location.hasBearing() ? LOCATION_HAS_BEARING : 0) | |
| 818 | (location.hasAccuracy() ? LOCATION_HAS_HORIZONTAL_ACCURACY : 0) | |
| 819 | (location.hasVerticalAccuracy() ? LOCATION_HAS_VERTICAL_ACCURACY : 0) | |
| 820 | (location.hasSpeedAccuracy() ? LOCATION_HAS_SPEED_ACCURACY : 0) | |
| 821 | (location.hasBearingAccuracy() ? LOCATION_HAS_BEARING_ACCURACY : 0); |
| 822 | |
| 823 | double latitudeDegrees = location.getLatitude(); |
| 824 | double longitudeDegrees = location.getLongitude(); |
| 825 | double altitudeMeters = location.getAltitude(); |
| 826 | float speedMetersPerSec = location.getSpeed(); |
| 827 | float bearingDegrees = location.getBearing(); |
| 828 | float horizontalAccuracyMeters = location.getAccuracy(); |
| 829 | float verticalAccuracyMeters = location.getVerticalAccuracyMeters(); |
| 830 | float speedAccuracyMetersPerSecond = location.getSpeedAccuracyMetersPerSecond(); |
| 831 | float bearingAccuracyDegrees = location.getBearingAccuracyDegrees(); |
| 832 | long timestamp = location.getTime(); |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 833 | |
Pierre Fite-Georgel | 9e96c57 | 2019-02-25 16:12:53 -0800 | [diff] [blame] | 834 | int elapsedRealtimeFlags = ELAPSED_REALTIME_HAS_TIMESTAMP_NS |
| 835 | | (location.hasElapsedRealtimeUncertaintyNanos() |
| 836 | ? ELAPSED_REALTIME_HAS_TIME_UNCERTAINTY_NS : 0); |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 837 | long elapsedRealtimeNanos = location.getElapsedRealtimeNanos(); |
Yu-Han Yang | 3cd9a86 | 2019-03-25 17:00:03 -0700 | [diff] [blame] | 838 | double elapsedRealtimeUncertaintyNanos = location.getElapsedRealtimeUncertaintyNanos(); |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 839 | |
| 840 | native_inject_best_location( |
| 841 | gnssLocationFlags, latitudeDegrees, longitudeDegrees, |
| 842 | altitudeMeters, speedMetersPerSec, bearingDegrees, |
| 843 | horizontalAccuracyMeters, verticalAccuracyMeters, |
| 844 | speedAccuracyMetersPerSecond, bearingAccuracyDegrees, timestamp, |
Pierre Fite-Georgel | 9e96c57 | 2019-02-25 16:12:53 -0800 | [diff] [blame] | 845 | elapsedRealtimeFlags, elapsedRealtimeNanos, elapsedRealtimeUncertaintyNanos); |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 846 | } |
| 847 | |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 848 | /** Returns true if the location request is too frequent. */ |
| 849 | private boolean isRequestLocationRateLimited() { |
Anil Admal | 316f948 | 2019-02-12 18:57:18 -0800 | [diff] [blame] | 850 | // TODO: implement exponential backoff. |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 851 | return false; |
| 852 | } |
| 853 | |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 854 | private void handleDownloadPsdsData() { |
| 855 | if (!mSupportsPsds) { |
| 856 | // native code reports psds not supported, don't try |
| 857 | Log.d(TAG, "handleDownloadPsdsData() called when PSDS not supported"); |
Wyatt Riley | 0d6e54e2 | 2016-10-05 12:03:03 -0700 | [diff] [blame] | 858 | return; |
| 859 | } |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 860 | if (mDownloadPsdsDataPending == STATE_DOWNLOADING) { |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 861 | // already downloading data |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 862 | return; |
| 863 | } |
Anil Admal | 50ba15e | 2018-11-01 16:42:42 -0700 | [diff] [blame] | 864 | if (!mNetworkConnectivityHandler.isDataNetworkConnected()) { |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 865 | // try again when network is up |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 866 | mDownloadPsdsDataPending = STATE_PENDING_NETWORK; |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 867 | return; |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 868 | } |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 869 | mDownloadPsdsDataPending = STATE_DOWNLOADING; |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 870 | |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 871 | synchronized (mLock) { |
| 872 | // hold wake lock while task runs |
| 873 | mDownloadPsdsWakeLock.acquire(DOWNLOAD_PSDS_DATA_TIMEOUT_MS); |
| 874 | } |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 875 | Log.i(TAG, "WakeLock acquired by handleDownloadPsdsData()"); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 876 | AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> { |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 877 | GpsPsdsDownloader psdsDownloader = new GpsPsdsDownloader( |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 878 | mGnssConfiguration.getProperties()); |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 879 | byte[] data = psdsDownloader.downloadPsdsData(); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 880 | if (data != null) { |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 881 | if (DEBUG) Log.d(TAG, "calling native_inject_psds_data"); |
| 882 | native_inject_psds_data(data, data.length); |
| 883 | mPsdsBackOff.reset(); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 884 | } |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 885 | |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 886 | sendMessage(DOWNLOAD_PSDS_DATA_FINISHED, 0, null); |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 887 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 888 | if (data == null) { |
| 889 | // try again later |
| 890 | // 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] | 891 | mHandler.sendEmptyMessageDelayed(DOWNLOAD_PSDS_DATA, |
| 892 | mPsdsBackOff.nextBackoffMillis()); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 893 | } |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 894 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 895 | // Release wake lock held by task, synchronize on mLock in case multiple |
| 896 | // download tasks overrun. |
| 897 | synchronized (mLock) { |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 898 | if (mDownloadPsdsWakeLock.isHeld()) { |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 899 | // This wakelock may have time-out, if a timeout was specified. |
| 900 | // Catch (and ignore) any timeout exceptions. |
| 901 | try { |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 902 | mDownloadPsdsWakeLock.release(); |
| 903 | if (DEBUG) Log.d(TAG, "WakeLock released by handleDownloadPsdsData()"); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 904 | } catch (Exception e) { |
| 905 | Log.i(TAG, "Wakelock timeout & release race exception in " |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 906 | + "handleDownloadPsdsData()", e); |
Wei Wang | b71c049 | 2017-05-01 20:24:19 -0700 | [diff] [blame] | 907 | } |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 908 | } else { |
| 909 | Log.e(TAG, "WakeLock expired before release in " |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 910 | + "handleDownloadPsdsData()"); |
Wei Wang | c5706f6 | 2017-04-18 11:26:26 -0700 | [diff] [blame] | 911 | } |
Jeff Brown | 028872f | 2012-08-25 13:07:01 -0700 | [diff] [blame] | 912 | } |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 913 | }); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 914 | } |
| 915 | |
Anil Admal | 2ac7046 | 2019-06-28 19:17:41 -0700 | [diff] [blame] | 916 | private void injectLocation(Location location) { |
Mike Lockwood | d26ce0d | 2009-06-11 12:25:46 -0400 | [diff] [blame] | 917 | if (location.hasAccuracy()) { |
Anil Admal | b1c6c0d | 2019-06-20 12:00:16 -0700 | [diff] [blame] | 918 | if (DEBUG) { |
| 919 | Log.d(TAG, "injectLocation: " + location); |
| 920 | } |
Mike Lockwood | d26ce0d | 2009-06-11 12:25:46 -0400 | [diff] [blame] | 921 | native_inject_location(location.getLatitude(), location.getLongitude(), |
| 922 | location.getAccuracy()); |
| 923 | } |
Mike Lockwood | fd6e5f0 | 2009-05-21 11:28:20 -0400 | [diff] [blame] | 924 | } |
| 925 | |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 926 | private void setSuplHostPort() { |
| 927 | mSuplServerHost = mGnssConfiguration.getSuplHost(); |
| 928 | mSuplServerPort = mGnssConfiguration.getSuplPort(TCP_MIN_PORT); |
Tsuwei Chen | 678c13c | 2014-09-22 17:48:41 -0700 | [diff] [blame] | 929 | if (mSuplServerHost != null |
| 930 | && mSuplServerPort > TCP_MIN_PORT |
| 931 | && mSuplServerPort <= TCP_MAX_PORT) { |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 932 | native_set_agps_server(GnssNetworkConnectivityHandler.AGPS_TYPE_SUPL, |
| 933 | mSuplServerHost, mSuplServerPort); |
Tsuwei Chen | 678c13c | 2014-09-22 17:48:41 -0700 | [diff] [blame] | 934 | } |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 935 | } |
| 936 | |
Tsuwei Chen | 462bcd8 | 2014-09-17 12:28:49 -0700 | [diff] [blame] | 937 | /** |
| 938 | * Checks what SUPL mode to use, according to the AGPS mode as well as the |
| 939 | * allowed mode from properties. |
| 940 | * |
Tsuwei Chen | 462bcd8 | 2014-09-17 12:28:49 -0700 | [diff] [blame] | 941 | * @param agpsEnabled whether AGPS is enabled by settings value |
Tsuwei Chen | 462bcd8 | 2014-09-17 12:28:49 -0700 | [diff] [blame] | 942 | * @return SUPL mode (MSA vs MSB vs STANDALONE) |
| 943 | */ |
Yu-Han Yang | 6a5f0b7 | 2019-01-24 18:34:28 -0800 | [diff] [blame] | 944 | private int getSuplMode(boolean agpsEnabled) { |
Tsuwei Chen | 462bcd8 | 2014-09-17 12:28:49 -0700 | [diff] [blame] | 945 | if (agpsEnabled) { |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 946 | int suplMode = mGnssConfiguration.getSuplMode(0); |
| 947 | if (suplMode == 0) { |
| 948 | return GPS_POSITION_MODE_STANDALONE; |
Tsuwei Chen | 462bcd8 | 2014-09-17 12:28:49 -0700 | [diff] [blame] | 949 | } |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 950 | |
destradaa | bfb3bdb | 2015-04-29 14:42:35 -0700 | [diff] [blame] | 951 | // MS-Based is the preferred mode for Assisted-GPS position computation, so we favor |
| 952 | // such mode when it is available |
| 953 | if (hasCapability(GPS_CAPABILITY_MSB) && (suplMode & AGPS_SUPL_MODE_MSB) != 0) { |
| 954 | return GPS_POSITION_MODE_MS_BASED; |
| 955 | } |
Tsuwei Chen | 462bcd8 | 2014-09-17 12:28:49 -0700 | [diff] [blame] | 956 | } |
| 957 | return GPS_POSITION_MODE_STANDALONE; |
| 958 | } |
| 959 | |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 960 | private void setGpsEnabled(boolean enabled) { |
| 961 | synchronized (mLock) { |
| 962 | mGpsEnabled = enabled; |
| 963 | } |
| 964 | } |
| 965 | |
| 966 | private void handleEnable() { |
| 967 | if (DEBUG) Log.d(TAG, "handleEnable"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 968 | |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 969 | boolean inited = native_init(); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 970 | |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 971 | if (inited) { |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 972 | setGpsEnabled(true); |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 973 | mSupportsPsds = native_supports_psds(); |
Tsuwei Chen | 678c13c | 2014-09-22 17:48:41 -0700 | [diff] [blame] | 974 | |
| 975 | // 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] | 976 | if (mSuplServerHost != null) { |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 977 | native_set_agps_server(GnssNetworkConnectivityHandler.AGPS_TYPE_SUPL, |
| 978 | mSuplServerHost, mSuplServerPort); |
Mike Lockwood | 734d603 | 2009-07-28 18:30:25 -0700 | [diff] [blame] | 979 | } |
| 980 | if (mC2KServerHost != null) { |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 981 | native_set_agps_server(GnssNetworkConnectivityHandler.AGPS_TYPE_C2K, |
| 982 | mC2KServerHost, mC2KServerPort); |
Mike Lockwood | 734d603 | 2009-07-28 18:30:25 -0700 | [diff] [blame] | 983 | } |
destradaa | 13a60b0 | 2015-01-15 18:36:01 -0800 | [diff] [blame] | 984 | |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 985 | mGnssMeasurementsProvider.onGpsEnabledChanged(); |
| 986 | mGnssNavigationMessageProvider.onGpsEnabledChanged(); |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 987 | mGnssBatchingProvider.enable(); |
Anil Admal | 138cdc3 | 2019-04-16 10:07:43 -0700 | [diff] [blame] | 988 | if (mGnssVisibilityControl != null) { |
Anil Admal | 8b83dc1 | 2019-06-12 13:55:42 -0700 | [diff] [blame] | 989 | mGnssVisibilityControl.onGpsEnabledChanged(/* isEnabled= */ true); |
Anil Admal | 138cdc3 | 2019-04-16 10:07:43 -0700 | [diff] [blame] | 990 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 991 | } else { |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 992 | setGpsEnabled(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 993 | Log.w(TAG, "Failed to enable location provider"); |
| 994 | } |
| 995 | } |
| 996 | |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 997 | private void handleDisable() { |
| 998 | if (DEBUG) Log.d(TAG, "handleDisable"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 999 | |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 1000 | setGpsEnabled(false); |
David Christie | 3bc2614 | 2013-12-19 14:53:44 -0800 | [diff] [blame] | 1001 | updateClientUids(new WorkSource()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1002 | stopNavigating(); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1003 | mAlarmManager.cancel(mWakeupIntent); |
| 1004 | mAlarmManager.cancel(mTimeoutIntent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1005 | |
Anil Admal | 138cdc3 | 2019-04-16 10:07:43 -0700 | [diff] [blame] | 1006 | if (mGnssVisibilityControl != null) { |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 1007 | mGnssVisibilityControl.onGpsEnabledChanged(/* isEnabled= */ false); |
Anil Admal | 138cdc3 | 2019-04-16 10:07:43 -0700 | [diff] [blame] | 1008 | } |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 1009 | mGnssBatchingProvider.disable(); |
Mike Lockwood | cf1d8cb | 2010-01-20 10:14:54 -0500 | [diff] [blame] | 1010 | // do this before releasing wakelock |
| 1011 | native_cleanup(); |
destradaa | 13a60b0 | 2015-01-15 18:36:01 -0800 | [diff] [blame] | 1012 | |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 1013 | mGnssMeasurementsProvider.onGpsEnabledChanged(); |
| 1014 | mGnssNavigationMessageProvider.onGpsEnabledChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1015 | } |
| 1016 | |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 1017 | private void updateEnabled() { |
Tyler Trephan | 037ef9d | 2019-05-17 13:41:18 -0700 | [diff] [blame] | 1018 | // Generally follow location setting for current user |
| 1019 | boolean enabled = mContext.getSystemService(LocationManager.class) |
| 1020 | .isLocationEnabledForUser(UserHandle.CURRENT); |
WyattRiley | b244607 | 2019-03-01 07:41:49 -0800 | [diff] [blame] | 1021 | |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 1022 | // ... but disable if PowerManager overrides |
| 1023 | enabled &= !mDisableGpsForPowerManager; |
WyattRiley | b244607 | 2019-03-01 07:41:49 -0800 | [diff] [blame] | 1024 | |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 1025 | // .. but enable anyway, if there's an active settings-ignored request (e.g. ELS) |
| 1026 | enabled |= (mProviderRequest != null && mProviderRequest.reportLocation |
| 1027 | && mProviderRequest.locationSettingsIgnored); |
WyattRiley | b244607 | 2019-03-01 07:41:49 -0800 | [diff] [blame] | 1028 | |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 1029 | // ... and, finally, disable anyway, if device is being shut down |
| 1030 | enabled &= !mShutdown; |
WyattRiley | b244607 | 2019-03-01 07:41:49 -0800 | [diff] [blame] | 1031 | |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 1032 | if (enabled == isGpsEnabled()) { |
| 1033 | return; |
| 1034 | } |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 1035 | |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 1036 | if (enabled) { |
| 1037 | handleEnable(); |
| 1038 | } else { |
| 1039 | handleDisable(); |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 1040 | } |
| 1041 | } |
| 1042 | |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 1043 | private boolean isGpsEnabled() { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1044 | synchronized (mLock) { |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 1045 | return mGpsEnabled; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1046 | } |
Mike Lockwood | d03ff94 | 2010-02-09 08:46:14 -0500 | [diff] [blame] | 1047 | } |
| 1048 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1049 | @Override |
Soonil Nagarkar | d334f7b | 2019-07-08 16:16:19 -0700 | [diff] [blame] | 1050 | public void onSetRequest(ProviderRequest request, WorkSource source) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1051 | sendMessage(SET_REQUEST, 0, new GpsRequest(request, source)); |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 1052 | } |
| 1053 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1054 | private void handleSetRequest(ProviderRequest request, WorkSource source) { |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 1055 | mProviderRequest = request; |
| 1056 | mWorkSource = source; |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 1057 | updateEnabled(); |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 1058 | updateRequirements(); |
| 1059 | } |
| 1060 | |
| 1061 | // Called when the requirements for GPS may have changed |
| 1062 | private void updateRequirements() { |
| 1063 | if (mProviderRequest == null || mWorkSource == null) { |
| 1064 | return; |
| 1065 | } |
| 1066 | |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 1067 | if (DEBUG) Log.d(TAG, "setRequest " + mProviderRequest); |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 1068 | if (mProviderRequest.reportLocation && isGpsEnabled()) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1069 | // update client uids |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 1070 | updateClientUids(mWorkSource); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1071 | |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 1072 | mFixInterval = (int) mProviderRequest.interval; |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1073 | mLowPowerMode = mProviderRequest.lowPowerMode; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1074 | // check for overflow |
David Christie | d4edf4c | 2014-08-12 15:22:27 -0700 | [diff] [blame] | 1075 | if (mFixInterval != mProviderRequest.interval) { |
| 1076 | Log.w(TAG, "interval overflow: " + mProviderRequest.interval); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1077 | mFixInterval = Integer.MAX_VALUE; |
| 1078 | } |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 1079 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1080 | // apply request to GPS engine |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 1081 | if (mStarted && hasCapability(GPS_CAPABILITY_SCHEDULING)) { |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1082 | // change period and/or lowPowerMode |
Yu-Han Yang | c8b9ff7 | 2018-04-17 00:47:24 -0700 | [diff] [blame] | 1083 | if (!setPositionMode(mPositionMode, GPS_POSITION_RECURRENCE_PERIODIC, |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1084 | mFixInterval, 0, 0, mLowPowerMode)) { |
| 1085 | Log.e(TAG, "set_position_mode failed in updateRequirements"); |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 1086 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1087 | } else if (!mStarted) { |
| 1088 | // start GPS |
Yu-Han Yang | 6a5f0b7 | 2019-01-24 18:34:28 -0800 | [diff] [blame] | 1089 | startNavigating(); |
gomo | 300b240 | 2017-12-13 19:04:12 -0800 | [diff] [blame] | 1090 | } else { |
| 1091 | // GNSS Engine is already ON, but no GPS_CAPABILITY_SCHEDULING |
| 1092 | mAlarmManager.cancel(mTimeoutIntent); |
| 1093 | if (mFixInterval >= NO_FIX_TIMEOUT) { |
| 1094 | // set timer to give up if we do not receive a fix within NO_FIX_TIMEOUT |
| 1095 | // and our fix interval is not short |
| 1096 | mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1097 | SystemClock.elapsedRealtime() + NO_FIX_TIMEOUT, mTimeoutIntent); |
| 1098 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1099 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1100 | } else { |
Dianne Hackborn | 002a54e | 2013-01-10 17:34:55 -0800 | [diff] [blame] | 1101 | updateClientUids(new WorkSource()); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1102 | |
| 1103 | stopNavigating(); |
| 1104 | mAlarmManager.cancel(mWakeupIntent); |
| 1105 | mAlarmManager.cancel(mTimeoutIntent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1106 | } |
| 1107 | } |
| 1108 | |
Yu-Han Yang | c8b9ff7 | 2018-04-17 00:47:24 -0700 | [diff] [blame] | 1109 | private boolean setPositionMode(int mode, int recurrence, int minInterval, |
| 1110 | int preferredAccuracy, int preferredTime, boolean lowPowerMode) { |
| 1111 | GnssPositionMode positionMode = new GnssPositionMode(mode, recurrence, minInterval, |
| 1112 | preferredAccuracy, preferredTime, lowPowerMode); |
| 1113 | if (mLastPositionMode != null && mLastPositionMode.equals(positionMode)) { |
| 1114 | return true; |
| 1115 | } |
| 1116 | |
| 1117 | boolean result = native_set_position_mode(mode, recurrence, minInterval, |
| 1118 | preferredAccuracy, preferredTime, lowPowerMode); |
| 1119 | if (result) { |
| 1120 | mLastPositionMode = positionMode; |
| 1121 | } else { |
| 1122 | mLastPositionMode = null; |
| 1123 | } |
| 1124 | return result; |
| 1125 | } |
| 1126 | |
Dianne Hackborn | 002a54e | 2013-01-10 17:34:55 -0800 | [diff] [blame] | 1127 | private void updateClientUids(WorkSource source) { |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 1128 | if (source.equals(mClientSource)) { |
Victoria Lease | ea78b85 | 2013-01-15 10:39:28 -0800 | [diff] [blame] | 1129 | return; |
| 1130 | } |
Dianne Hackborn | 002a54e | 2013-01-10 17:34:55 -0800 | [diff] [blame] | 1131 | |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 1132 | // (1) Inform BatteryStats that the list of IDs we're tracking changed. |
| 1133 | try { |
| 1134 | mBatteryStats.noteGpsChanged(mClientSource, source); |
| 1135 | } catch (RemoteException e) { |
| 1136 | Log.w(TAG, "RemoteException", e); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1137 | } |
| 1138 | |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 1139 | // (2) Inform AppOps service about the list of changes to UIDs. |
| 1140 | |
| 1141 | List<WorkChain>[] diffs = WorkSource.diffChains(mClientSource, source); |
| 1142 | if (diffs != null) { |
| 1143 | List<WorkChain> newChains = diffs[0]; |
| 1144 | List<WorkChain> goneChains = diffs[1]; |
| 1145 | |
| 1146 | if (newChains != null) { |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1147 | for (WorkChain newChain : newChains) { |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 1148 | mAppOps.startOpNoThrow(AppOpsManager.OP_GPS, newChain.getAttributionUid(), |
| 1149 | newChain.getAttributionTag()); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 1150 | } |
| 1151 | } |
| 1152 | |
| 1153 | if (goneChains != null) { |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1154 | for (WorkChain goneChain : goneChains) { |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 1155 | mAppOps.finishOp(AppOpsManager.OP_GPS, goneChain.getAttributionUid(), |
| 1156 | goneChain.getAttributionTag()); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | mClientSource.transferWorkChains(source); |
| 1161 | } |
| 1162 | |
| 1163 | // Update the flat UIDs and names list and inform app-ops of all changes. |
| 1164 | WorkSource[] changes = mClientSource.setReturningDiffs(source); |
| 1165 | if (changes != null) { |
| 1166 | WorkSource newWork = changes[0]; |
| 1167 | WorkSource goneWork = changes[1]; |
| 1168 | |
| 1169 | // Update sources that were not previously tracked. |
| 1170 | if (newWork != null) { |
| 1171 | for (int i = 0; i < newWork.size(); i++) { |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 1172 | mAppOps.startOpNoThrow(AppOpsManager.OP_GPS, |
| 1173 | newWork.get(i), newWork.getName(i)); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 1174 | } |
| 1175 | } |
| 1176 | |
| 1177 | // Update sources that are no longer tracked. |
| 1178 | if (goneWork != null) { |
| 1179 | for (int i = 0; i < goneWork.size(); i++) { |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 1180 | mAppOps.finishOp(AppOpsManager.OP_GPS, goneWork.get(i), goneWork.getName(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. |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1482 | int usedInFixCount = 0; |
Wyatt Riley | c9f25dd | 2017-05-05 13:45:23 -0700 | [diff] [blame] | 1483 | int maxCn0 = 0; |
| 1484 | int meanCn0 = 0; |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1485 | for (int i = 0; i < info.mSvCount; i++) { |
| 1486 | if ((info.mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_USED_IN_FIX) != 0) { |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1487 | ++usedInFixCount; |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1488 | if (info.mCn0s[i] > maxCn0) { |
| 1489 | maxCn0 = (int) info.mCn0s[i]; |
Wyatt Riley | c9f25dd | 2017-05-05 13:45:23 -0700 | [diff] [blame] | 1490 | } |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1491 | meanCn0 += info.mCn0s[i]; |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1492 | } |
| 1493 | if (VERBOSE) { |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1494 | Log.v(TAG, "svid: " + (info.mSvidWithFlags[i] >> GnssStatus.SVID_SHIFT_WIDTH) + |
| 1495 | " cn0: " + info.mCn0s[i] + |
| 1496 | " elev: " + info.mSvElevations[i] + |
| 1497 | " azimuth: " + info.mSvAzimuths[i] + |
| 1498 | " carrier frequency: " + info.mSvCarrierFreqs[i] + |
| 1499 | ((info.mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_HAS_EPHEMERIS_DATA) == 0 |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1500 | ? " " : " E") + |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1501 | ((info.mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_HAS_ALMANAC_DATA) == 0 |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1502 | ? " " : " A") + |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1503 | ((info.mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_USED_IN_FIX) == 0 |
gomo | 4402af6 | 2017-01-11 13:20:13 -0800 | [diff] [blame] | 1504 | ? "" : "U") + |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1505 | ((info.mSvidWithFlags[i] & |
| 1506 | GnssStatus.GNSS_SV_FLAGS_HAS_CARRIER_FREQUENCY) == 0 |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1507 | ? "" : "F")); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1508 | } |
Yu-Han Yang | 284234e | 2019-03-28 19:35:57 -0700 | [diff] [blame] | 1509 | |
| 1510 | if ((info.mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_USED_IN_FIX) != 0) { |
| 1511 | int constellationType = |
| 1512 | (info.mSvidWithFlags[i] >> GnssStatus.CONSTELLATION_TYPE_SHIFT_WIDTH) |
| 1513 | & GnssStatus.CONSTELLATION_TYPE_MASK; |
| 1514 | mGnssMetrics.logConstellationType(constellationType); |
| 1515 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1516 | } |
Wyatt Riley | c9f25dd | 2017-05-05 13:45:23 -0700 | [diff] [blame] | 1517 | if (usedInFixCount > 0) { |
| 1518 | meanCn0 /= usedInFixCount; |
| 1519 | } |
| 1520 | // return number of sats used in fix instead of total reported |
Wyatt Riley | c706741 | 2018-02-07 15:50:35 -0800 | [diff] [blame] | 1521 | mLocationExtras.set(usedInFixCount, meanCn0, maxCn0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1522 | |
Blake Kragten | bb61360 | 2019-08-28 16:21:35 -0700 | [diff] [blame] | 1523 | mGnssMetrics.logSvStatus(info.mSvCount, info.mSvidWithFlags, info.mSvCarrierFreqs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1524 | } |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 1525 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1526 | @NativeEntryPoint |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 1527 | private void reportAGpsStatus(int agpsType, int agpsStatus, byte[] suplIpAddr) { |
| 1528 | mNetworkConnectivityHandler.onReportAGpsStatus(agpsType, agpsStatus, suplIpAddr); |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 1529 | } |
| 1530 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1531 | @NativeEntryPoint |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 1532 | private void reportNmea(long timestamp) { |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1533 | if (!mItarSpeedLimitExceeded) { |
| 1534 | int length = native_read_nmea(mNmeaBuffer, mNmeaBuffer.length); |
| 1535 | String nmea = new String(mNmeaBuffer, 0 /* offset */, length); |
Anil Admal | 75b9fd6 | 2018-11-28 11:22:50 -0800 | [diff] [blame] | 1536 | mGnssStatusListenerHelper.onNmeaReceived(timestamp, nmea); |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1537 | } |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1538 | } |
Mike Lockwood | b16e780 | 2009-08-06 09:26:02 -0400 | [diff] [blame] | 1539 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1540 | @NativeEntryPoint |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 1541 | private void reportMeasurementData(GnssMeasurementsEvent event) { |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1542 | if (!mItarSpeedLimitExceeded) { |
Wyatt Riley | aa420d5 | 2017-07-03 15:14:42 -0700 | [diff] [blame] | 1543 | // send to handler to allow native to return quickly |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1544 | mHandler.post(() -> mGnssMeasurementsProvider.onMeasurementsAvailable(event)); |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1545 | } |
Mike Lockwood | b16e780 | 2009-08-06 09:26:02 -0400 | [diff] [blame] | 1546 | } |
| 1547 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1548 | @NativeEntryPoint |
Lifu Tang | e8abe8e | 2016-04-01 10:32:05 -0700 | [diff] [blame] | 1549 | private void reportNavigationMessage(GnssNavigationMessage event) { |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1550 | if (!mItarSpeedLimitExceeded) { |
Wyatt Riley | aa420d5 | 2017-07-03 15:14:42 -0700 | [diff] [blame] | 1551 | // send to handler to allow native to return quickly |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1552 | mHandler.post(() -> mGnssNavigationMessageProvider.onNavigationMessageAvailable(event)); |
Wyatt Riley | 5d5bac8 | 2016-11-01 07:05:16 -0700 | [diff] [blame] | 1553 | } |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1554 | } |
| 1555 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1556 | @NativeEntryPoint |
Anil Admal | 62c42dc | 2019-04-03 15:39:22 -0700 | [diff] [blame] | 1557 | private void setTopHalCapabilities(int topHalCapabilities) { |
Anil Admal | efd9dc6 | 2019-03-12 17:39:20 -0700 | [diff] [blame] | 1558 | mHandler.post(() -> { |
Anil Admal | 312fddb | 2019-03-25 12:15:43 -0700 | [diff] [blame] | 1559 | mTopHalCapabilities = topHalCapabilities; |
Mike Lockwood | 9b9fb5c | 2011-06-29 15:09:40 -0400 | [diff] [blame] | 1560 | |
Anil Admal | efd9dc6 | 2019-03-12 17:39:20 -0700 | [diff] [blame] | 1561 | if (hasCapability(GPS_CAPABILITY_ON_DEMAND_TIME)) { |
| 1562 | mNtpTimeHelper.enablePeriodicTimeInjection(); |
| 1563 | requestUtcTime(); |
| 1564 | } |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1565 | |
Anil Admal | 62c42dc | 2019-04-03 15:39:22 -0700 | [diff] [blame] | 1566 | mGnssMeasurementsProvider.onCapabilitiesUpdated( |
| 1567 | hasCapability(GPS_CAPABILITY_MEASUREMENTS)); |
| 1568 | mGnssNavigationMessageProvider.onCapabilitiesUpdated( |
| 1569 | hasCapability(GPS_CAPABILITY_NAV_MESSAGES)); |
Anil Admal | efd9dc6 | 2019-03-12 17:39:20 -0700 | [diff] [blame] | 1570 | restartRequests(); |
Anil Admal | 312fddb | 2019-03-25 12:15:43 -0700 | [diff] [blame] | 1571 | |
Anil Admal | 62c42dc | 2019-04-03 15:39:22 -0700 | [diff] [blame] | 1572 | mGnssCapabilitiesProvider.setTopHalCapabilities(mTopHalCapabilities); |
Anil Admal | efd9dc6 | 2019-03-12 17:39:20 -0700 | [diff] [blame] | 1573 | }); |
| 1574 | } |
| 1575 | |
| 1576 | @NativeEntryPoint |
Anil Admal | 312fddb | 2019-03-25 12:15:43 -0700 | [diff] [blame] | 1577 | private void setSubHalMeasurementCorrectionsCapabilities(int subHalCapabilities) { |
| 1578 | mHandler.post(() -> { |
| 1579 | if (!mGnssMeasurementCorrectionsProvider.onCapabilitiesUpdated(subHalCapabilities)) { |
| 1580 | return; |
| 1581 | } |
| 1582 | |
| 1583 | mGnssCapabilitiesProvider.setSubHalMeasurementCorrectionsCapabilities( |
| 1584 | subHalCapabilities); |
| 1585 | }); |
Yu-Han Yang | 5205762 | 2018-04-25 00:51:22 -0700 | [diff] [blame] | 1586 | } |
| 1587 | |
| 1588 | private void restartRequests() { |
| 1589 | Log.i(TAG, "restartRequests"); |
| 1590 | |
| 1591 | restartLocationRequest(); |
| 1592 | mGnssMeasurementsProvider.resumeIfStarted(); |
| 1593 | mGnssNavigationMessageProvider.resumeIfStarted(); |
| 1594 | mGnssBatchingProvider.resumeIfStarted(); |
| 1595 | mGnssGeofenceProvider.resumeIfStarted(); |
| 1596 | } |
| 1597 | |
| 1598 | private void restartLocationRequest() { |
| 1599 | if (DEBUG) Log.d(TAG, "restartLocationRequest"); |
WyattRiley | ba6072f | 2019-04-18 07:37:52 -0700 | [diff] [blame] | 1600 | setStarted(false); |
Yu-Han Yang | 5205762 | 2018-04-25 00:51:22 -0700 | [diff] [blame] | 1601 | updateRequirements(); |
| 1602 | } |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1603 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1604 | @NativeEntryPoint |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1605 | private void setGnssYearOfHardware(final int yearOfHardware) { |
| 1606 | // mHardwareYear is simply set here, to be read elsewhere, and is volatile for safe sync |
| 1607 | if (DEBUG) Log.d(TAG, "setGnssYearOfHardware called with " + yearOfHardware); |
| 1608 | mHardwareYear = yearOfHardware; |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 1609 | } |
| 1610 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1611 | @NativeEntryPoint |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1612 | private void setGnssHardwareModelName(final String modelName) { |
| 1613 | // mHardwareModelName is simply set here, to be read elsewhere, and volatile for safe sync |
| 1614 | if (DEBUG) Log.d(TAG, "setGnssModelName called with " + modelName); |
| 1615 | mHardwareModelName = modelName; |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 1616 | } |
| 1617 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1618 | @NativeEntryPoint |
Yu-Han Yang | 5205762 | 2018-04-25 00:51:22 -0700 | [diff] [blame] | 1619 | private void reportGnssServiceDied() { |
| 1620 | if (DEBUG) Log.d(TAG, "reportGnssServiceDied"); |
| 1621 | mHandler.post(() -> { |
Anil Admal | 0c2b21bd | 2019-05-03 18:29:02 -0700 | [diff] [blame] | 1622 | setupNativeGnssService(/* reinitializeGnssServiceHandle = */ true); |
Anil Admal | 204406f | 2019-07-23 12:00:23 -0700 | [diff] [blame] | 1623 | // resend configuration into the restarted HAL service. |
| 1624 | reloadGpsProperties(); |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 1625 | if (isGpsEnabled()) { |
| 1626 | setGpsEnabled(false); |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 1627 | updateEnabled(); |
Yu-Han Yang | 5205762 | 2018-04-25 00:51:22 -0700 | [diff] [blame] | 1628 | } |
| 1629 | }); |
| 1630 | } |
| 1631 | |
Lifu Tang | 9363b94 | 2016-02-16 18:07:00 -0800 | [diff] [blame] | 1632 | public interface GnssSystemInfoProvider { |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 1633 | /** |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1634 | * Returns the year of underlying GPS hardware. |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 1635 | */ |
Lifu Tang | 9363b94 | 2016-02-16 18:07:00 -0800 | [diff] [blame] | 1636 | int getGnssYearOfHardware(); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1637 | |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1638 | /** |
| 1639 | * Returns the model name of underlying GPS hardware. |
| 1640 | */ |
| 1641 | String getGnssHardwareModelName(); |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 1642 | } |
| 1643 | |
| 1644 | /** |
| 1645 | * @hide |
| 1646 | */ |
Lifu Tang | 9363b94 | 2016-02-16 18:07:00 -0800 | [diff] [blame] | 1647 | public GnssSystemInfoProvider getGnssSystemInfoProvider() { |
| 1648 | return new GnssSystemInfoProvider() { |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 1649 | @Override |
Lifu Tang | 9363b94 | 2016-02-16 18:07:00 -0800 | [diff] [blame] | 1650 | public int getGnssYearOfHardware() { |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1651 | return mHardwareYear; |
| 1652 | } |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1653 | |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1654 | @Override |
| 1655 | public String getGnssHardwareModelName() { |
| 1656 | return mHardwareModelName; |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 1657 | } |
| 1658 | }; |
| 1659 | } |
| 1660 | |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1661 | /** |
| 1662 | * @hide |
| 1663 | */ |
| 1664 | public GnssBatchingProvider getGnssBatchingProvider() { |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 1665 | return mGnssBatchingProvider; |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1666 | } |
| 1667 | |
Siddharth Ray | bb608c8 | 2017-03-16 11:33:34 -0700 | [diff] [blame] | 1668 | public interface GnssMetricsProvider { |
| 1669 | /** |
| 1670 | * Returns GNSS metrics as proto string |
| 1671 | */ |
| 1672 | String getGnssMetricsAsProtoString(); |
| 1673 | } |
| 1674 | |
| 1675 | /** |
| 1676 | * @hide |
| 1677 | */ |
| 1678 | public GnssMetricsProvider getGnssMetricsProvider() { |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1679 | return () -> mGnssMetrics.dumpGnssMetricsAsProtoString(); |
Siddharth Ray | bb608c8 | 2017-03-16 11:33:34 -0700 | [diff] [blame] | 1680 | } |
| 1681 | |
Anil Admal | 312fddb | 2019-03-25 12:15:43 -0700 | [diff] [blame] | 1682 | /** |
| 1683 | * @hide |
| 1684 | */ |
| 1685 | public GnssCapabilitiesProvider getGnssCapabilitiesProvider() { |
| 1686 | return mGnssCapabilitiesProvider; |
| 1687 | } |
| 1688 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1689 | @NativeEntryPoint |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1690 | private void reportLocationBatch(Location[] locationArray) { |
| 1691 | List<Location> locations = new ArrayList<>(Arrays.asList(locationArray)); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1692 | if (DEBUG) { |
| 1693 | Log.d(TAG, "Location batch of size " + locationArray.length + " reported"); |
| 1694 | } |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1695 | reportLocation(locations); |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1696 | } |
| 1697 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1698 | @NativeEntryPoint |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 1699 | private void psdsDownloadRequest() { |
| 1700 | if (DEBUG) Log.d(TAG, "psdsDownloadRequest"); |
| 1701 | sendMessage(DOWNLOAD_PSDS_DATA, 0, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1702 | } |
| 1703 | |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1704 | /** |
destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 1705 | * Converts the GPS HAL status to the internal Geofence Hardware status. |
| 1706 | */ |
Yu-Han Yang | 6dc9f05 | 2018-12-04 17:11:24 -0800 | [diff] [blame] | 1707 | private static int getGeofenceStatus(int status) { |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1708 | switch (status) { |
destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 1709 | case GPS_GEOFENCE_OPERATION_SUCCESS: |
| 1710 | return GeofenceHardware.GEOFENCE_SUCCESS; |
| 1711 | case GPS_GEOFENCE_ERROR_GENERIC: |
| 1712 | return GeofenceHardware.GEOFENCE_FAILURE; |
| 1713 | case GPS_GEOFENCE_ERROR_ID_EXISTS: |
| 1714 | return GeofenceHardware.GEOFENCE_ERROR_ID_EXISTS; |
| 1715 | case GPS_GEOFENCE_ERROR_INVALID_TRANSITION: |
| 1716 | return GeofenceHardware.GEOFENCE_ERROR_INVALID_TRANSITION; |
| 1717 | case GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES: |
| 1718 | return GeofenceHardware.GEOFENCE_ERROR_TOO_MANY_GEOFENCES; |
| 1719 | case GPS_GEOFENCE_ERROR_ID_UNKNOWN: |
| 1720 | return GeofenceHardware.GEOFENCE_ERROR_ID_UNKNOWN; |
| 1721 | default: |
| 1722 | return -1; |
| 1723 | } |
| 1724 | } |
| 1725 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1726 | @NativeEntryPoint |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 1727 | private void reportGeofenceTransition(int geofenceId, Location location, int transition, |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1728 | long transitionTimestamp) { |
Yu-Han Yang | 6dc9f05 | 2018-12-04 17:11:24 -0800 | [diff] [blame] | 1729 | mHandler.post(() -> { |
| 1730 | if (mGeofenceHardwareImpl == null) { |
| 1731 | mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext); |
| 1732 | } |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 1733 | |
Yu-Han Yang | 6dc9f05 | 2018-12-04 17:11:24 -0800 | [diff] [blame] | 1734 | mGeofenceHardwareImpl.reportGeofenceTransition( |
| 1735 | geofenceId, |
| 1736 | location, |
| 1737 | transition, |
| 1738 | transitionTimestamp, |
| 1739 | GeofenceHardware.MONITORING_TYPE_GPS_HARDWARE, |
| 1740 | FusedBatchOptions.SourceTechnologies.GNSS); |
| 1741 | }); |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1742 | } |
| 1743 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1744 | @NativeEntryPoint |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 1745 | private void reportGeofenceStatus(int status, Location location) { |
Yu-Han Yang | 6dc9f05 | 2018-12-04 17:11:24 -0800 | [diff] [blame] | 1746 | mHandler.post(() -> { |
| 1747 | if (mGeofenceHardwareImpl == null) { |
| 1748 | mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext); |
| 1749 | } |
| 1750 | int monitorStatus = GeofenceHardware.MONITOR_CURRENTLY_UNAVAILABLE; |
| 1751 | if (status == GPS_GEOFENCE_AVAILABLE) { |
| 1752 | monitorStatus = GeofenceHardware.MONITOR_CURRENTLY_AVAILABLE; |
| 1753 | } |
| 1754 | mGeofenceHardwareImpl.reportGeofenceMonitorStatus( |
| 1755 | GeofenceHardware.MONITORING_TYPE_GPS_HARDWARE, |
| 1756 | monitorStatus, |
| 1757 | location, |
| 1758 | FusedBatchOptions.SourceTechnologies.GNSS); |
| 1759 | }); |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1760 | } |
| 1761 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1762 | @NativeEntryPoint |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1763 | private void reportGeofenceAddStatus(int geofenceId, int status) { |
Yu-Han Yang | 6dc9f05 | 2018-12-04 17:11:24 -0800 | [diff] [blame] | 1764 | mHandler.post(() -> { |
| 1765 | if (mGeofenceHardwareImpl == null) { |
| 1766 | mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext); |
| 1767 | } |
| 1768 | mGeofenceHardwareImpl.reportGeofenceAddStatus(geofenceId, getGeofenceStatus(status)); |
| 1769 | }); |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1770 | } |
| 1771 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1772 | @NativeEntryPoint |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1773 | private void reportGeofenceRemoveStatus(int geofenceId, int status) { |
Yu-Han Yang | 6dc9f05 | 2018-12-04 17:11:24 -0800 | [diff] [blame] | 1774 | mHandler.post(() -> { |
| 1775 | if (mGeofenceHardwareImpl == null) { |
| 1776 | mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext); |
| 1777 | } |
| 1778 | mGeofenceHardwareImpl.reportGeofenceRemoveStatus(geofenceId, getGeofenceStatus(status)); |
| 1779 | }); |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1780 | } |
| 1781 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1782 | @NativeEntryPoint |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1783 | private void reportGeofencePauseStatus(int geofenceId, int status) { |
Yu-Han Yang | 6dc9f05 | 2018-12-04 17:11:24 -0800 | [diff] [blame] | 1784 | mHandler.post(() -> { |
| 1785 | if (mGeofenceHardwareImpl == null) { |
| 1786 | mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext); |
| 1787 | } |
| 1788 | mGeofenceHardwareImpl.reportGeofencePauseStatus(geofenceId, getGeofenceStatus(status)); |
| 1789 | }); |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1790 | } |
| 1791 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1792 | @NativeEntryPoint |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1793 | private void reportGeofenceResumeStatus(int geofenceId, int status) { |
Yu-Han Yang | 6dc9f05 | 2018-12-04 17:11:24 -0800 | [diff] [blame] | 1794 | mHandler.post(() -> { |
| 1795 | if (mGeofenceHardwareImpl == null) { |
| 1796 | mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext); |
| 1797 | } |
| 1798 | mGeofenceHardwareImpl.reportGeofenceResumeStatus(geofenceId, getGeofenceStatus(status)); |
| 1799 | }); |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 1800 | } |
| 1801 | |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 1802 | //============================================================= |
| 1803 | // NI Client support |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1804 | //============================================================= |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 1805 | private final INetInitiatedListener mNetInitiatedListener = new INetInitiatedListener.Stub() { |
destradaa | ef752b6 | 2015-04-17 13:10:47 -0700 | [diff] [blame] | 1806 | // Sends a response for an NI request to HAL. |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1807 | @Override |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1808 | public boolean sendNiResponse(int notificationId, int userResponse) { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1809 | // TODO Add Permission check |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 1810 | |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1811 | if (DEBUG) { |
| 1812 | Log.d(TAG, "sendNiResponse, notifId: " + notificationId + |
| 1813 | ", response: " + userResponse); |
| 1814 | } |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1815 | native_send_ni_response(notificationId, userResponse); |
Yu-Han Yang | 8a1b51d | 2018-12-26 22:18:31 -0800 | [diff] [blame] | 1816 | |
| 1817 | StatsLog.write(StatsLog.GNSS_NI_EVENT_REPORTED, |
| 1818 | StatsLog.GNSS_NI_EVENT_REPORTED__EVENT_TYPE__NI_RESPONSE, |
| 1819 | notificationId, |
| 1820 | /* niType= */ 0, |
| 1821 | /* needNotify= */ false, |
| 1822 | /* needVerify= */ false, |
| 1823 | /* privacyOverride= */ false, |
| 1824 | /* timeout= */ 0, |
| 1825 | /* defaultResponse= */ 0, |
| 1826 | /* requestorId= */ null, |
| 1827 | /* text= */ null, |
| 1828 | /* requestorIdEncoding= */ 0, |
| 1829 | /* textEncoding= */ 0, |
| 1830 | mSuplEsEnabled, |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 1831 | isGpsEnabled(), |
Yu-Han Yang | 8a1b51d | 2018-12-26 22:18:31 -0800 | [diff] [blame] | 1832 | userResponse); |
| 1833 | |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1834 | return true; |
| 1835 | } |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 1836 | }; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1837 | |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 1838 | public INetInitiatedListener getNetInitiatedListener() { |
| 1839 | return mNetInitiatedListener; |
| 1840 | } |
| 1841 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1842 | /** Reports a NI notification. */ |
| 1843 | @NativeEntryPoint |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1844 | public void reportNiNotification( |
| 1845 | int notificationId, |
| 1846 | int niType, |
| 1847 | int notifyFlags, |
| 1848 | int timeout, |
| 1849 | int defaultResponse, |
| 1850 | String requestorId, |
| 1851 | String text, |
| 1852 | int requestorIdEncoding, |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1853 | int textEncoding |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1854 | ) { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1855 | Log.i(TAG, "reportNiNotification: entered"); |
| 1856 | Log.i(TAG, "notificationId: " + notificationId + |
| 1857 | ", niType: " + niType + |
| 1858 | ", notifyFlags: " + notifyFlags + |
| 1859 | ", timeout: " + timeout + |
| 1860 | ", defaultResponse: " + defaultResponse); |
| 1861 | |
| 1862 | Log.i(TAG, "requestorId: " + requestorId + |
| 1863 | ", text: " + text + |
| 1864 | ", requestorIdEncoding: " + requestorIdEncoding + |
| 1865 | ", textEncoding: " + textEncoding); |
| 1866 | |
| 1867 | GpsNiNotification notification = new GpsNiNotification(); |
| 1868 | |
| 1869 | notification.notificationId = notificationId; |
| 1870 | notification.niType = niType; |
| 1871 | notification.needNotify = (notifyFlags & GpsNetInitiatedHandler.GPS_NI_NEED_NOTIFY) != 0; |
| 1872 | notification.needVerify = (notifyFlags & GpsNetInitiatedHandler.GPS_NI_NEED_VERIFY) != 0; |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1873 | notification.privacyOverride = |
| 1874 | (notifyFlags & GpsNetInitiatedHandler.GPS_NI_PRIVACY_OVERRIDE) != 0; |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1875 | notification.timeout = timeout; |
| 1876 | notification.defaultResponse = defaultResponse; |
| 1877 | notification.requestorId = requestorId; |
| 1878 | notification.text = text; |
| 1879 | notification.requestorIdEncoding = requestorIdEncoding; |
| 1880 | notification.textEncoding = textEncoding; |
| 1881 | |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1882 | mNIHandler.handleNiNotification(notification); |
Yu-Han Yang | 8a1b51d | 2018-12-26 22:18:31 -0800 | [diff] [blame] | 1883 | StatsLog.write(StatsLog.GNSS_NI_EVENT_REPORTED, |
| 1884 | StatsLog.GNSS_NI_EVENT_REPORTED__EVENT_TYPE__NI_REQUEST, |
| 1885 | notification.notificationId, |
| 1886 | notification.niType, |
| 1887 | notification.needNotify, |
| 1888 | notification.needVerify, |
| 1889 | notification.privacyOverride, |
| 1890 | notification.timeout, |
| 1891 | notification.defaultResponse, |
| 1892 | notification.requestorId, |
| 1893 | notification.text, |
| 1894 | notification.requestorIdEncoding, |
| 1895 | notification.textEncoding, |
| 1896 | mSuplEsEnabled, |
Yu-Han Yang | 76f9995 | 2019-05-04 17:45:44 -0700 | [diff] [blame] | 1897 | isGpsEnabled(), |
Yu-Han Yang | 8a1b51d | 2018-12-26 22:18:31 -0800 | [diff] [blame] | 1898 | /* userResponse= */ 0); |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1899 | } |
| 1900 | |
| 1901 | /** |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1902 | * We should be careful about receiving null string from the TelephonyManager, |
| 1903 | * because sending null String to JNI function would cause a crash. |
| 1904 | */ |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1905 | @NativeEntryPoint |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1906 | private void requestSetID(int flags) { |
| 1907 | TelephonyManager phone = (TelephonyManager) |
| 1908 | mContext.getSystemService(Context.TELEPHONY_SERVICE); |
destradaa | ef752b6 | 2015-04-17 13:10:47 -0700 | [diff] [blame] | 1909 | int type = AGPS_SETID_TYPE_NONE; |
Anil Admal | e1539e8 | 2019-05-09 15:05:04 -0700 | [diff] [blame] | 1910 | String setId = null; |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1911 | |
Anil Admal | e1539e8 | 2019-05-09 15:05:04 -0700 | [diff] [blame] | 1912 | int ddSubId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1913 | if ((flags & AGPS_RIL_REQUEST_SETID_IMSI) == AGPS_RIL_REQUEST_SETID_IMSI) { |
Anil Admal | e1539e8 | 2019-05-09 15:05:04 -0700 | [diff] [blame] | 1914 | if (SubscriptionManager.isValidSubscriptionId(ddSubId)) { |
| 1915 | setId = phone.getSubscriberId(ddSubId); |
| 1916 | } |
| 1917 | if (setId == null) { |
| 1918 | setId = phone.getSubscriberId(); |
| 1919 | } |
| 1920 | if (setId != null) { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1921 | // This means the framework has the SIM card. |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1922 | type = AGPS_SETID_TYPE_IMSI; |
| 1923 | } |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1924 | } 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] | 1925 | if (SubscriptionManager.isValidSubscriptionId(ddSubId)) { |
| 1926 | setId = phone.getLine1Number(ddSubId); |
| 1927 | } |
| 1928 | if (setId == null) { |
| 1929 | setId = phone.getLine1Number(); |
| 1930 | } |
| 1931 | if (setId != null) { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1932 | // This means the framework has the SIM card. |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1933 | type = AGPS_SETID_TYPE_MSISDN; |
| 1934 | } |
| 1935 | } |
Anil Admal | e1539e8 | 2019-05-09 15:05:04 -0700 | [diff] [blame] | 1936 | |
| 1937 | native_agps_set_id(type, (setId == null) ? "" : setId); |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1938 | } |
| 1939 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1940 | @NativeEntryPoint |
Yu-Han Yang | 53f4d6d | 2019-02-13 21:47:41 -0800 | [diff] [blame] | 1941 | private void requestLocation(boolean independentFromGnss, boolean isUserEmergency) { |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 1942 | if (DEBUG) { |
Yu-Han Yang | 53f4d6d | 2019-02-13 21:47:41 -0800 | [diff] [blame] | 1943 | Log.d(TAG, "requestLocation. independentFromGnss: " + independentFromGnss |
| 1944 | + ", isUserEmergency: " |
| 1945 | + isUserEmergency); |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 1946 | } |
Yu-Han Yang | 53f4d6d | 2019-02-13 21:47:41 -0800 | [diff] [blame] | 1947 | sendMessage(REQUEST_LOCATION, independentFromGnss ? 1 : 0, isUserEmergency); |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 1948 | } |
| 1949 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1950 | @NativeEntryPoint |
Mike Lockwood | 9b9fb5c | 2011-06-29 15:09:40 -0400 | [diff] [blame] | 1951 | private void requestUtcTime() { |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 1952 | if (DEBUG) Log.d(TAG, "utcTimeRequest"); |
Mike Lockwood | 9b9fb5c | 2011-06-29 15:09:40 -0400 | [diff] [blame] | 1953 | sendMessage(INJECT_NTP_TIME, 0, null); |
| 1954 | } |
| 1955 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1956 | @NativeEntryPoint |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1957 | private void requestRefLocation() { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1958 | TelephonyManager phone = (TelephonyManager) |
| 1959 | mContext.getSystemService(Context.TELEPHONY_SERVICE); |
Victoria Lease | d50d0c3 | 2012-10-29 13:16:17 -0700 | [diff] [blame] | 1960 | final int phoneType = phone.getPhoneType(); |
| 1961 | if (phoneType == TelephonyManager.PHONE_TYPE_GSM) { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1962 | GsmCellLocation gsm_cell = (GsmCellLocation) phone.getCellLocation(); |
Victoria Lease | d50d0c3 | 2012-10-29 13:16:17 -0700 | [diff] [blame] | 1963 | if ((gsm_cell != null) && (phone.getNetworkOperator() != null) |
| 1964 | && (phone.getNetworkOperator().length() > 3)) { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1965 | int type; |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1966 | int mcc = Integer.parseInt(phone.getNetworkOperator().substring(0, 3)); |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1967 | int mnc = Integer.parseInt(phone.getNetworkOperator().substring(3)); |
Mike Lockwood | edc0f387 | 2010-10-22 09:16:17 -0400 | [diff] [blame] | 1968 | int networkType = phone.getNetworkType(); |
| 1969 | if (networkType == TelephonyManager.NETWORK_TYPE_UMTS |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1970 | || networkType == TelephonyManager.NETWORK_TYPE_HSDPA |
| 1971 | || networkType == TelephonyManager.NETWORK_TYPE_HSUPA |
| 1972 | || networkType == TelephonyManager.NETWORK_TYPE_HSPA |
| 1973 | || networkType == TelephonyManager.NETWORK_TYPE_HSPAP) { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1974 | type = AGPS_REF_LOCATION_TYPE_UMTS_CELLID; |
Mike Lockwood | edc0f387 | 2010-10-22 09:16:17 -0400 | [diff] [blame] | 1975 | } else { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1976 | type = AGPS_REF_LOCATION_TYPE_GSM_CELLID; |
Mike Lockwood | edc0f387 | 2010-10-22 09:16:17 -0400 | [diff] [blame] | 1977 | } |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1978 | native_agps_set_ref_location_cellid(type, mcc, mnc, |
| 1979 | gsm_cell.getLac(), gsm_cell.getCid()); |
Mike Lockwood | edc0f387 | 2010-10-22 09:16:17 -0400 | [diff] [blame] | 1980 | } else { |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1981 | Log.e(TAG, "Error getting cell location info."); |
Mike Lockwood | edc0f387 | 2010-10-22 09:16:17 -0400 | [diff] [blame] | 1982 | } |
Victoria Lease | d50d0c3 | 2012-10-29 13:16:17 -0700 | [diff] [blame] | 1983 | } else if (phoneType == TelephonyManager.PHONE_TYPE_CDMA) { |
| 1984 | Log.e(TAG, "CDMA not supported."); |
Mike Lockwood | edc0f387 | 2010-10-22 09:16:17 -0400 | [diff] [blame] | 1985 | } |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 1986 | } |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 1987 | |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 1988 | // Implements method nfwNotifyCb() in IGnssVisibilityControlCallback.hal. |
| 1989 | @NativeEntryPoint |
| 1990 | private void reportNfwNotification(String proxyAppPackageName, byte protocolStack, |
| 1991 | String otherProtocolStackName, byte requestor, String requestorId, byte responseType, |
| 1992 | boolean inEmergencyMode, boolean isCachedLocation) { |
| 1993 | if (mGnssVisibilityControl == null) { |
| 1994 | Log.e(TAG, "reportNfwNotification: mGnssVisibilityControl is not initialized."); |
| 1995 | return; |
| 1996 | } |
| 1997 | |
| 1998 | mGnssVisibilityControl.reportNfwNotification(proxyAppPackageName, protocolStack, |
| 1999 | otherProtocolStackName, requestor, requestorId, responseType, inEmergencyMode, |
| 2000 | isCachedLocation); |
| 2001 | } |
| 2002 | |
| 2003 | // Implements method isInEmergencySession() in IGnssVisibilityControlCallback.hal. |
| 2004 | @NativeEntryPoint |
| 2005 | boolean isInEmergencySession() { |
| 2006 | return mNIHandler.getInEmergency(); |
| 2007 | } |
| 2008 | |
Mike Lockwood | 98e4869 | 2010-04-07 16:32:51 -0400 | [diff] [blame] | 2009 | private void sendMessage(int message, int arg, Object obj) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2010 | // hold a wake lock until this message is delivered |
Jeff Brown | 028872f | 2012-08-25 13:07:01 -0700 | [diff] [blame] | 2011 | // note that this assumes the message will not be removed from the queue before |
| 2012 | // it is handled (otherwise the wake lock would be leaked). |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2013 | mWakeLock.acquire(); |
Anil Admal | 4f97c94 | 2018-11-12 10:52:46 -0800 | [diff] [blame] | 2014 | if (DEBUG) { |
| 2015 | Log.d(TAG, "WakeLock acquired by sendMessage(" + messageIdAsString(message) + ", " + arg |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2016 | + ", " + obj + ")"); |
| 2017 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2018 | mHandler.obtainMessage(message, arg, 1, obj).sendToTarget(); |
Mike Lockwood | 98e4869 | 2010-04-07 16:32:51 -0400 | [diff] [blame] | 2019 | } |
| 2020 | |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 2021 | private final class ProviderHandler extends Handler { |
Victoria Lease | 5cd731a | 2012-12-19 15:04:21 -0800 | [diff] [blame] | 2022 | public ProviderHandler(Looper looper) { |
| 2023 | super(looper, null, true /*async*/); |
Jeff Brown | 028872f | 2012-08-25 13:07:01 -0700 | [diff] [blame] | 2024 | } |
| 2025 | |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 2026 | @Override |
Mike Lockwood | 4a7b65e | 2010-10-25 16:35:55 -0400 | [diff] [blame] | 2027 | public void handleMessage(Message msg) { |
Mike Lockwood | 98e4869 | 2010-04-07 16:32:51 -0400 | [diff] [blame] | 2028 | int message = msg.what; |
| 2029 | switch (message) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2030 | case SET_REQUEST: |
| 2031 | GpsRequest gpsRequest = (GpsRequest) msg.obj; |
| 2032 | handleSetRequest(gpsRequest.request, gpsRequest.source); |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 2033 | break; |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 2034 | case INJECT_NTP_TIME: |
Yu-Han Yang | a1862b5 | 2018-02-20 17:05:59 -0800 | [diff] [blame] | 2035 | mNtpTimeHelper.retrieveAndInjectNtpTime(); |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 2036 | break; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 2037 | case REQUEST_LOCATION: |
Yu-Han Yang | 53f4d6d | 2019-02-13 21:47:41 -0800 | [diff] [blame] | 2038 | handleRequestLocation(msg.arg1 == 1, (boolean) msg.obj); |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 2039 | break; |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 2040 | case DOWNLOAD_PSDS_DATA: |
| 2041 | handleDownloadPsdsData(); |
Mike Lockwood | 62a8fc1 | 2010-03-22 14:23:26 -0400 | [diff] [blame] | 2042 | break; |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 2043 | case DOWNLOAD_PSDS_DATA_FINISHED: |
| 2044 | mDownloadPsdsDataPending = STATE_IDLE; |
Kevin Tang | 40e1baf | 2012-01-10 14:32:44 -0800 | [diff] [blame] | 2045 | break; |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2046 | case INITIALIZE_HANDLER: |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 2047 | handleInitialize(); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2048 | break; |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 2049 | case REPORT_LOCATION: |
| 2050 | handleReportLocation(msg.arg1 == 1, (Location) msg.obj); |
| 2051 | break; |
| 2052 | case REPORT_SV_STATUS: |
| 2053 | handleReportSvStatus((SvStatusInfo) msg.obj); |
| 2054 | break; |
Kweku Adams | 810c77d | 2019-08-28 07:45:00 -0700 | [diff] [blame] | 2055 | case UPDATE_LOW_POWER_MODE: |
| 2056 | updateLowPowerMode(); |
| 2057 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2058 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2059 | if (msg.arg2 == 1) { |
| 2060 | // wakelock was taken for this message, release it |
| 2061 | mWakeLock.release(); |
Anil Admal | 4f97c94 | 2018-11-12 10:52:46 -0800 | [diff] [blame] | 2062 | if (DEBUG) { |
| 2063 | Log.d(TAG, "WakeLock released by handleMessage(" + messageIdAsString(message) |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2064 | + ", " + msg.arg1 + ", " + msg.obj + ")"); |
| 2065 | } |
Mike Lockwood | 98e4869 | 2010-04-07 16:32:51 -0400 | [diff] [blame] | 2066 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2067 | } |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2068 | |
| 2069 | /** |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 2070 | * This method is bound to {@link #GnssLocationProvider(Context, LocationProviderManager, |
| 2071 | * Looper)}. |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2072 | * It is in charge of loading properties and registering for events that will be posted to |
| 2073 | * this handler. |
| 2074 | */ |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 2075 | private void handleInitialize() { |
Anil Admal | 0c2b21bd | 2019-05-03 18:29:02 -0700 | [diff] [blame] | 2076 | // class_init_native() already initializes the GNSS service handle during class loading. |
| 2077 | setupNativeGnssService(/* reinitializeGnssServiceHandle = */ false); |
Wyatt Riley | 523a0cf | 2017-10-31 14:36:52 -0700 | [diff] [blame] | 2078 | |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 2079 | if (native_is_gnss_visibility_control_supported()) { |
Anil Admal | 8a246a2 | 2019-05-05 00:34:55 -0700 | [diff] [blame] | 2080 | mGnssVisibilityControl = new GnssVisibilityControl(mContext, mLooper, mNIHandler); |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 2081 | } |
| 2082 | |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2083 | // load default GPS configuration |
| 2084 | // (this configuration might change in the future based on SIM changes) |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 2085 | reloadGpsProperties(); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2086 | |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2087 | // listen for events |
WyattRiley | 6593cf1 | 2018-06-23 10:37:48 -0700 | [diff] [blame] | 2088 | IntentFilter intentFilter = new IntentFilter(); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2089 | intentFilter.addAction(ALARM_WAKEUP); |
| 2090 | intentFilter.addAction(ALARM_TIMEOUT); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2091 | intentFilter.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED); |
Adam Lesinski | 87c17df | 2015-05-27 13:24:13 -0700 | [diff] [blame] | 2092 | intentFilter.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2093 | intentFilter.addAction(Intent.ACTION_SCREEN_OFF); |
| 2094 | intentFilter.addAction(Intent.ACTION_SCREEN_ON); |
Meng Wang | 19b214d | 2018-11-07 12:14:39 -0800 | [diff] [blame] | 2095 | intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED); |
Anil Admal | e1539e8 | 2019-05-09 15:05:04 -0700 | [diff] [blame] | 2096 | intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2097 | mContext.registerReceiver(mBroadcastReceiver, intentFilter, null, this); |
| 2098 | |
Anil Admal | 50ba15e | 2018-11-01 16:42:42 -0700 | [diff] [blame] | 2099 | mNetworkConnectivityHandler.registerNetworkCallbacks(); |
destradaa | e21252a | 2015-09-08 12:32:59 -0700 | [diff] [blame] | 2100 | |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2101 | // listen for PASSIVE_PROVIDER updates |
| 2102 | LocationManager locManager = |
| 2103 | (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); |
| 2104 | long minTime = 0; |
| 2105 | float minDistance = 0; |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2106 | LocationRequest request = LocationRequest.createFromDeprecatedProvider( |
| 2107 | LocationManager.PASSIVE_PROVIDER, |
| 2108 | minTime, |
| 2109 | minDistance, |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 2110 | false); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2111 | // Don't keep track of this request since it's done on behalf of other clients |
| 2112 | // (which are kept track of separately). |
| 2113 | request.setHideFromAppOps(true); |
| 2114 | locManager.requestLocationUpdates( |
| 2115 | request, |
| 2116 | new NetworkLocationListener(), |
| 2117 | getLooper()); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 2118 | |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 2119 | updateEnabled(); |
destradaa | fb23c67 | 2015-04-16 14:01:27 -0700 | [diff] [blame] | 2120 | } |
| 2121 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2122 | |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 2123 | private abstract class LocationChangeListener implements LocationListener { |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 2124 | private int mNumLocationUpdateRequest; |
Yu-Han Yang | 0756138 | 2018-02-21 13:08:37 -0800 | [diff] [blame] | 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 onStatusChanged(String provider, int status, Bundle extras) { |
| 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 onProviderEnabled(String provider) { |
| 2132 | } |
| 2133 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2134 | @Override |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2135 | public void onProviderDisabled(String provider) { |
| 2136 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2137 | } |
| 2138 | |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 2139 | private final class NetworkLocationListener extends LocationChangeListener { |
| 2140 | @Override |
| 2141 | public void onLocationChanged(Location location) { |
| 2142 | // this callback happens on mHandler looper |
| 2143 | if (LocationManager.NETWORK_PROVIDER.equals(location.getProvider())) { |
Anil Admal | 2ac7046 | 2019-06-28 19:17:41 -0700 | [diff] [blame] | 2144 | injectLocation(location); |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 2145 | } |
| 2146 | } |
| 2147 | } |
| 2148 | |
| 2149 | private final class FusedLocationListener extends LocationChangeListener { |
| 2150 | @Override |
| 2151 | public void onLocationChanged(Location location) { |
| 2152 | if (LocationManager.FUSED_PROVIDER.equals(location.getProvider())) { |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 2153 | injectBestLocation(location); |
| 2154 | } |
| 2155 | } |
| 2156 | } |
| 2157 | |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2158 | /** |
| 2159 | * @return A string representing the given message ID. |
| 2160 | */ |
| 2161 | private String messageIdAsString(int message) { |
| 2162 | switch (message) { |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2163 | case SET_REQUEST: |
| 2164 | return "SET_REQUEST"; |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2165 | case INJECT_NTP_TIME: |
| 2166 | return "INJECT_NTP_TIME"; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 2167 | case REQUEST_LOCATION: |
| 2168 | return "REQUEST_LOCATION"; |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 2169 | case DOWNLOAD_PSDS_DATA: |
| 2170 | return "DOWNLOAD_PSDS_DATA"; |
| 2171 | case DOWNLOAD_PSDS_DATA_FINISHED: |
| 2172 | return "DOWNLOAD_PSDS_DATA_FINISHED"; |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2173 | case INITIALIZE_HANDLER: |
| 2174 | return "INITIALIZE_HANDLER"; |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 2175 | case REPORT_LOCATION: |
| 2176 | return "REPORT_LOCATION"; |
| 2177 | case REPORT_SV_STATUS: |
| 2178 | return "REPORT_SV_STATUS"; |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2179 | default: |
| 2180 | return "<Unknown>"; |
| 2181 | } |
| 2182 | } |
| 2183 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2184 | @Override |
| 2185 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 2186 | StringBuilder s = new StringBuilder(); |
Soonil Nagarkar | 1c57255 | 2019-07-10 13:31:47 -0700 | [diff] [blame] | 2187 | s.append("mStarted=").append(mStarted).append(" (changed "); |
WyattRiley | ba6072f | 2019-04-18 07:37:52 -0700 | [diff] [blame] | 2188 | TimeUtils.formatDuration(SystemClock.elapsedRealtime() |
| 2189 | - mStartedChangedElapsedRealtime, s); |
| 2190 | s.append(" ago)").append('\n'); |
Soonil Nagarkar | 1c57255 | 2019-07-10 13:31:47 -0700 | [diff] [blame] | 2191 | s.append("mFixInterval=").append(mFixInterval).append('\n'); |
| 2192 | s.append("mLowPowerMode=").append(mLowPowerMode).append('\n'); |
| 2193 | s.append("mGnssMeasurementsProvider.isRegistered()=") |
Wyatt Riley | 74479bd | 2018-01-17 08:48:27 -0800 | [diff] [blame] | 2194 | .append(mGnssMeasurementsProvider.isRegistered()).append('\n'); |
Soonil Nagarkar | 1c57255 | 2019-07-10 13:31:47 -0700 | [diff] [blame] | 2195 | s.append("mGnssNavigationMessageProvider.isRegistered()=") |
Wyatt Riley | 74479bd | 2018-01-17 08:48:27 -0800 | [diff] [blame] | 2196 | .append(mGnssNavigationMessageProvider.isRegistered()).append('\n'); |
Soonil Nagarkar | 1c57255 | 2019-07-10 13:31:47 -0700 | [diff] [blame] | 2197 | s.append("mDisableGpsForPowerManager=").append(mDisableGpsForPowerManager).append('\n'); |
| 2198 | s.append("mTopHalCapabilities=0x").append(Integer.toHexString(mTopHalCapabilities)); |
destradaa | 25e8caf | 2015-08-24 14:14:44 -0700 | [diff] [blame] | 2199 | s.append(" ( "); |
| 2200 | if (hasCapability(GPS_CAPABILITY_SCHEDULING)) s.append("SCHEDULING "); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2201 | if (hasCapability(GPS_CAPABILITY_MSB)) s.append("MSB "); |
| 2202 | if (hasCapability(GPS_CAPABILITY_MSA)) s.append("MSA "); |
| 2203 | if (hasCapability(GPS_CAPABILITY_SINGLE_SHOT)) s.append("SINGLE_SHOT "); |
| 2204 | if (hasCapability(GPS_CAPABILITY_ON_DEMAND_TIME)) s.append("ON_DEMAND_TIME "); |
destradaa | 25e8caf | 2015-08-24 14:14:44 -0700 | [diff] [blame] | 2205 | if (hasCapability(GPS_CAPABILITY_GEOFENCING)) s.append("GEOFENCING "); |
| 2206 | if (hasCapability(GPS_CAPABILITY_MEASUREMENTS)) s.append("MEASUREMENTS "); |
| 2207 | if (hasCapability(GPS_CAPABILITY_NAV_MESSAGES)) s.append("NAV_MESSAGES "); |
Anil Admal | efd9dc6 | 2019-03-12 17:39:20 -0700 | [diff] [blame] | 2208 | if (hasCapability(GPS_CAPABILITY_LOW_POWER_MODE)) s.append("LOW_POWER_MODE "); |
| 2209 | if (hasCapability(GPS_CAPABILITY_SATELLITE_BLACKLIST)) s.append("SATELLITE_BLACKLIST "); |
Anil Admal | 62c42dc | 2019-04-03 15:39:22 -0700 | [diff] [blame] | 2210 | if (hasCapability(GPS_CAPABILITY_MEASUREMENT_CORRECTIONS)) { |
| 2211 | s.append("MEASUREMENT_CORRECTIONS "); |
| 2212 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2213 | s.append(")\n"); |
Anil Admal | 3ba0fa9 | 2019-04-19 17:43:00 -0700 | [diff] [blame] | 2214 | if (hasCapability(GPS_CAPABILITY_MEASUREMENT_CORRECTIONS)) { |
Soonil Nagarkar | 1c57255 | 2019-07-10 13:31:47 -0700 | [diff] [blame] | 2215 | s.append("SubHal=MEASUREMENT_CORRECTIONS["); |
Anil Admal | efd9dc6 | 2019-03-12 17:39:20 -0700 | [diff] [blame] | 2216 | s.append(mGnssMeasurementCorrectionsProvider.toStringCapabilities()); |
| 2217 | s.append("]\n"); |
| 2218 | } |
Siddharth Ray | bb608c8 | 2017-03-16 11:33:34 -0700 | [diff] [blame] | 2219 | s.append(mGnssMetrics.dumpGnssMetricsAsText()); |
Soonil Nagarkar | 1c57255 | 2019-07-10 13:31:47 -0700 | [diff] [blame] | 2220 | s.append("native internal state: \n"); |
| 2221 | s.append(" ").append(native_get_internal_state()); |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2222 | s.append("\n"); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2223 | pw.append(s); |
| 2224 | } |
| 2225 | |
Anil Admal | 0c2b21bd | 2019-05-03 18:29:02 -0700 | [diff] [blame] | 2226 | private void setupNativeGnssService(boolean reinitializeGnssServiceHandle) { |
| 2227 | native_init_once(reinitializeGnssServiceHandle); |
Anil Admal | 7e3953b | 2019-05-04 20:45:22 -0700 | [diff] [blame] | 2228 | |
| 2229 | /* |
| 2230 | * A cycle of native_init() and native_cleanup() is needed so that callbacks are |
| 2231 | * registered after bootup even when location is disabled. |
| 2232 | * This will allow Emergency SUPL to work even when location is disabled before device |
| 2233 | * restart. |
| 2234 | */ |
| 2235 | boolean isInitialized = native_init(); |
| 2236 | if (!isInitialized) { |
| 2237 | Log.w(TAG, "Native initialization failed."); |
| 2238 | } else { |
| 2239 | native_cleanup(); |
| 2240 | } |
| 2241 | } |
| 2242 | |
Mike Lockwood | b16e780 | 2009-08-06 09:26:02 -0400 | [diff] [blame] | 2243 | // preallocated to avoid memory allocation in reportNmea() |
| 2244 | private byte[] mNmeaBuffer = new byte[120]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2245 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2246 | private static native void class_init_native(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2247 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2248 | private static native boolean native_is_supported(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2249 | |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 2250 | private static native boolean native_is_gnss_visibility_control_supported(); |
| 2251 | |
Anil Admal | 0c2b21bd | 2019-05-03 18:29:02 -0700 | [diff] [blame] | 2252 | private static native void native_init_once(boolean reinitializeGnssServiceHandle); |
Yu-Han Yang | 6d31735 | 2018-03-15 11:53:01 -0700 | [diff] [blame] | 2253 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2254 | private native boolean native_init(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2255 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2256 | private native void native_cleanup(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2257 | |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 2258 | 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] | 2259 | int preferred_accuracy, int preferred_time, boolean lowPowerMode); |
| 2260 | |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 2261 | private native boolean native_start(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2262 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2263 | private native boolean native_stop(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2264 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2265 | private native void native_delete_aiding_data(int flags); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2266 | |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 2267 | private native int native_read_nmea(byte[] buffer, int bufferSize); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2268 | |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 2269 | private native void native_inject_best_location( |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 2270 | int gnssLocationFlags, double latitudeDegrees, double longitudeDegrees, |
| 2271 | double altitudeMeters, float speedMetersPerSec, float bearingDegrees, |
| 2272 | float horizontalAccuracyMeters, float verticalAccuracyMeters, |
| 2273 | float speedAccuracyMetersPerSecond, float bearingAccuracyDegrees, |
Pierre Fite-Georgel | 9e96c57 | 2019-02-25 16:12:53 -0800 | [diff] [blame] | 2274 | long timestamp, int elapsedRealtimeFlags, long elapsedRealtimeNanos, |
Yu-Han Yang | 3cd9a86 | 2019-03-25 17:00:03 -0700 | [diff] [blame] | 2275 | double elapsedRealtimeUncertaintyNanos); |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 2276 | |
Mike Lockwood | d26ce0d | 2009-06-11 12:25:46 -0400 | [diff] [blame] | 2277 | private native void native_inject_location(double latitude, double longitude, float accuracy); |
| 2278 | |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 2279 | // PSDS Support |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2280 | private native void native_inject_time(long time, long timeReference, int uncertainty); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2281 | |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 2282 | private native boolean native_supports_psds(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2283 | |
Kevin Tang | 8c6ac67 | 2019-03-22 12:31:01 -0700 | [diff] [blame] | 2284 | 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] | 2285 | |
Fred Fettinger | 3c8fbdf | 2010-01-04 15:38:13 -0600 | [diff] [blame] | 2286 | // DEBUG Support |
| 2287 | private native String native_get_internal_state(); |
| 2288 | |
| 2289 | // AGPS Support |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2290 | private native void native_agps_ni_message(byte[] msg, int length); |
| 2291 | |
Mike Lockwood | a9e5461 | 2009-06-19 14:54:42 -0400 | [diff] [blame] | 2292 | 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] | 2293 | |
| 2294 | // Network-initiated (NI) Support |
| 2295 | private native void native_send_ni_response(int notificationId, int userResponse); |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 2296 | |
Anil Admal | 50ba15e | 2018-11-01 16:42:42 -0700 | [diff] [blame] | 2297 | // AGPS ril support |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 2298 | private native void native_agps_set_ref_location_cellid(int type, int mcc, int mnc, |
| 2299 | int lac, int cid); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2300 | |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 2301 | private native void native_agps_set_id(int type, String setid); |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 2302 | } |