blob: 436ea3cd720a55bc256d654561091e8ebd3a3f62 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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 Lockwood00b74272010-03-26 10:41:48 -040017package com.android.server.location;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080018
Mike Lockwood29c84342009-05-06 14:01:15 -040019import android.app.AlarmManager;
Dianne Hackborna06de0f2012-12-11 16:34:47 -080020import android.app.AppOpsManager;
Mike Lockwood29c84342009-05-06 14:01:15 -040021import android.app.PendingIntent;
The Android Open Source Project10592532009-03-18 17:39:46 -070022import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.content.Context;
24import android.content.Intent;
The Android Open Source Project10592532009-03-18 17:39:46 -070025import android.content.IntentFilter;
Kevin Tanga5fe6b22011-06-05 14:25:16 -070026import android.database.Cursor;
destradaa0682809a2013-08-12 18:50:30 -070027import android.hardware.location.GeofenceHardware;
Jaikumar Ganesh8ce470d2013-04-03 12:22:18 -070028import android.hardware.location.GeofenceHardwareImpl;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.location.Criteria;
destradaa0682809a2013-08-12 18:50:30 -070030import android.location.FusedBatchOptions;
Lifu Tang30f95a72016-01-07 23:20:38 -080031import android.location.GnssStatus;
32import android.location.IGnssStatusListener;
33import android.location.IGnssStatusProvider;
Lifu Tang818aa2c2016-02-01 01:52:00 -080034import android.location.GnssMeasurementsEvent;
Lifu Tange8abe8e2016-04-01 10:32:05 -070035import android.location.GnssNavigationMessage;
Jaikumar Ganesh8ce470d2013-04-03 12:22:18 -070036import android.location.IGpsGeofenceHardware;
Mike Lockwood4e50b782009-04-03 08:24:43 -070037import android.location.ILocationManager;
Danke Xie22d1f9f2009-08-18 18:28:45 -040038import android.location.INetInitiatedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import android.location.Location;
Nick Pelly6fa9ad42012-07-16 12:18:23 -070040import android.location.LocationListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import android.location.LocationManager;
42import android.location.LocationProvider;
Stan Chesnutt1d72d8c2013-04-15 19:18:02 -070043import android.location.LocationRequest;
Mike Lockwood58bda982009-04-14 16:25:07 -040044import android.net.ConnectivityManager;
destradaae21252a2015-09-08 12:32:59 -070045import android.net.Network;
46import android.net.NetworkCapabilities;
Mike Lockwood03d24672009-10-08 15:45:03 -040047import android.net.NetworkInfo;
destradaae21252a2015-09-08 12:32:59 -070048import android.net.NetworkRequest;
Kevin Tanga5fe6b22011-06-05 14:25:16 -070049import android.net.Uri;
Kevin Tang40e1baf2012-01-10 14:32:44 -080050import android.os.AsyncTask;
jackqdyulei455e90a2017-02-09 15:29:16 -080051import android.os.PowerSaveState;
Dianne Hackborn91268cf2013-06-13 19:06:50 -070052import android.os.BatteryStats;
Mike Lockwood63aa5a62010-04-14 19:21:31 -040053import android.os.Binder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import android.os.Bundle;
Ecco Park4fa1ab72016-10-24 13:04:52 -070055import android.os.PersistableBundle;
Mike Lockwood62a8fc12010-03-22 14:23:26 -040056import android.os.Handler;
Victoria Lease5cd731a2012-12-19 15:04:21 -080057import android.os.Looper;
Mike Lockwood62a8fc12010-03-22 14:23:26 -040058import android.os.Message;
Mike Lockwood0528b9b2009-05-07 10:12:54 -040059import android.os.PowerManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import android.os.RemoteException;
Mike Lockwood2f82c4e2009-04-17 08:24:10 -040061import android.os.ServiceManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062import android.os.SystemClock;
Colin Cross7c030ed2014-01-28 09:33:53 -080063import android.os.SystemProperties;
Dianne Hackborn5ac72a22012-08-29 18:32:08 -070064import android.os.UserHandle;
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -070065import android.os.WorkSource;
Mike Lockwoodbcab8df2009-06-25 16:39:09 -040066import android.provider.Settings;
Kevin Tanga5fe6b22011-06-05 14:25:16 -070067import android.provider.Telephony.Carriers;
Miguel Torroja1e84da82010-07-27 07:02:24 +020068import android.provider.Telephony.Sms.Intents;
Wink Savillea374c3d2014-11-11 11:48:04 -080069import android.telephony.SubscriptionManager;
Wink Savilled09c4ca2014-11-22 10:08:16 -080070import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener;
Miguel Torroja1e84da82010-07-27 07:02:24 +020071import android.telephony.TelephonyManager;
Ecco Park4fa1ab72016-10-24 13:04:52 -070072import android.telephony.CarrierConfigManager;
Miguel Torroja1e84da82010-07-27 07:02:24 +020073import android.telephony.gsm.GsmCellLocation;
Colin Cross7c030ed2014-01-28 09:33:53 -080074import android.text.TextUtils;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075import android.util.Log;
Jeff Sharkey104344e2011-07-10 14:20:41 -070076import android.util.NtpTrustedTime;
Dianne Hackborna06de0f2012-12-11 16:34:47 -080077
jackqdyulei455e90a2017-02-09 15:29:16 -080078import com.android.internal.app.IAppOpsService;
79import com.android.internal.app.IBatteryStats;
Siddharth Raybb608c82017-03-16 11:33:34 -070080import com.android.internal.location.gnssmetrics.GnssMetrics;
jackqdyulei455e90a2017-02-09 15:29:16 -080081import com.android.internal.location.GpsNetInitiatedHandler;
82import com.android.internal.location.GpsNetInitiatedHandler.GpsNiNotification;
83import com.android.internal.location.ProviderProperties;
84import com.android.internal.location.ProviderRequest;
Siddharth Raybb608c82017-03-16 11:33:34 -070085
jackqdyulei455e90a2017-02-09 15:29:16 -080086import com.android.server.power.BatterySaverPolicy;
87import com.android.server.power.BatterySaverPolicy.ServiceType;
88
89import libcore.io.IoUtils;
90
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091import java.io.File;
Nick Pelly6fa9ad42012-07-16 12:18:23 -070092import java.io.FileDescriptor;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093import java.io.FileInputStream;
94import java.io.IOException;
Nick Pelly6fa9ad42012-07-16 12:18:23 -070095import java.io.PrintWriter;
destradaaea8a8a62014-06-23 18:19:03 -070096import java.net.InetAddress;
97import java.net.UnknownHostException;
Wyatt Rileycf879db2017-01-12 13:57:38 -080098import java.util.ArrayList;
Andreas Gampee6748ce2015-12-11 18:00:38 -080099import java.util.Arrays;
Mike Lockwoodf1218be2010-01-29 09:20:06 -0500100import java.util.Date;
Wyatt Rileycf879db2017-01-12 13:57:38 -0800101import java.util.List;
Danke Xie22d1f9f2009-08-18 18:28:45 -0400102import java.util.Map.Entry;
Jake Hambyb49a73d2011-03-15 20:09:46 -0700103import java.util.Properties;
Hridya Valsaraju2ea29602016-09-13 08:38:09 -0700104import java.util.Map;
105import java.util.HashMap;
Colin Cross7c030ed2014-01-28 09:33:53 -0800106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107/**
gomo4402af62017-01-11 13:20:13 -0800108 * A GNSS implementation of LocationProvider used by LocationManager.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 *
110 * {@hide}
111 */
Lifu Tang30f95a72016-01-07 23:20:38 -0800112public class GnssLocationProvider implements LocationProviderInterface {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113
Lifu Tang30f95a72016-01-07 23:20:38 -0800114 private static final String TAG = "GnssLocationProvider";
Mike Lockwood29c84342009-05-06 14:01:15 -0400115
Brian Muramatsu1715cb32012-08-08 17:32:21 -0700116 private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
117 private static final boolean VERBOSE = Log.isLoggable(TAG, Log.VERBOSE);
Mike Lockwood62a8fc12010-03-22 14:23:26 -0400118
Nick Pelly6fa9ad42012-07-16 12:18:23 -0700119 private static final ProviderProperties PROPERTIES = new ProviderProperties(
120 true, true, false, false, true, true, true,
121 Criteria.POWER_HIGH, Criteria.ACCURACY_FINE);
122
gomo4402af62017-01-11 13:20:13 -0800123 // these need to match GnssPositionMode enum in IGnss.hal
The Android Open Source Project10592532009-03-18 17:39:46 -0700124 private static final int GPS_POSITION_MODE_STANDALONE = 0;
125 private static final int GPS_POSITION_MODE_MS_BASED = 1;
126 private static final int GPS_POSITION_MODE_MS_ASSISTED = 2;
127
gomo4402af62017-01-11 13:20:13 -0800128 // these need to match GnssPositionRecurrence enum in IGnss.hal
Mike Lockwood04598b62010-04-14 17:17:24 -0400129 private static final int GPS_POSITION_RECURRENCE_PERIODIC = 0;
130 private static final int GPS_POSITION_RECURRENCE_SINGLE = 1;
131
gomo4402af62017-01-11 13:20:13 -0800132 // these need to match GnssStatusValue enum in IGnssCallback.hal
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133 private static final int GPS_STATUS_NONE = 0;
134 private static final int GPS_STATUS_SESSION_BEGIN = 1;
135 private static final int GPS_STATUS_SESSION_END = 2;
136 private static final int GPS_STATUS_ENGINE_ON = 3;
137 private static final int GPS_STATUS_ENGINE_OFF = 4;
138
gomo4402af62017-01-11 13:20:13 -0800139 // these need to match AGnssStatusValue enum in IAGnssCallback.hal
Mike Lockwoode3635c92009-05-11 08:38:02 -0400140 /** AGPS status event values. */
141 private static final int GPS_REQUEST_AGPS_DATA_CONN = 1;
142 private static final int GPS_RELEASE_AGPS_DATA_CONN = 2;
143 private static final int GPS_AGPS_DATA_CONNECTED = 3;
144 private static final int GPS_AGPS_DATA_CONN_DONE = 4;
145 private static final int GPS_AGPS_DATA_CONN_FAILED = 5;
Mike Lockwood58bda982009-04-14 16:25:07 -0400146
gomo4402af62017-01-11 13:20:13 -0800147 // these need to match GnssLocationFlags enum in types.hal
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 private static final int LOCATION_INVALID = 0;
149 private static final int LOCATION_HAS_LAT_LONG = 1;
150 private static final int LOCATION_HAS_ALTITUDE = 2;
151 private static final int LOCATION_HAS_SPEED = 4;
152 private static final int LOCATION_HAS_BEARING = 8;
gomo4402af62017-01-11 13:20:13 -0800153 private static final int LOCATION_HAS_HORIZONTAL_ACCURACY = 16;
154 private static final int LOCATION_HAS_VERTICAL_ACCURACY = 32;
155 private static final int LOCATION_HAS_SPEED_ACCURACY = 64;
156 private static final int LOCATION_HAS_BEARING_ACCURACY = 128;
Mike Lockwoode3635c92009-05-11 08:38:02 -0400157
gomo4402af62017-01-11 13:20:13 -0800158
159 // IMPORTANT - the GPS_DELETE_* symbols here must match GnssAidingData enum in IGnss.hal
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160 private static final int GPS_DELETE_EPHEMERIS = 0x0001;
161 private static final int GPS_DELETE_ALMANAC = 0x0002;
162 private static final int GPS_DELETE_POSITION = 0x0004;
163 private static final int GPS_DELETE_TIME = 0x0008;
164 private static final int GPS_DELETE_IONO = 0x0010;
165 private static final int GPS_DELETE_UTC = 0x0020;
166 private static final int GPS_DELETE_HEALTH = 0x0040;
167 private static final int GPS_DELETE_SVDIR = 0x0080;
168 private static final int GPS_DELETE_SVSTEER = 0x0100;
169 private static final int GPS_DELETE_SADATA = 0x0200;
170 private static final int GPS_DELETE_RTI = 0x0400;
171 private static final int GPS_DELETE_CELLDB_INFO = 0x8000;
172 private static final int GPS_DELETE_ALL = 0xFFFF;
173
gomo4402af62017-01-11 13:20:13 -0800174 // The GPS_CAPABILITY_* flags must match Capabilities enum in IGnssCallback.hal
Mike Lockwood04598b62010-04-14 17:17:24 -0400175 private static final int GPS_CAPABILITY_SCHEDULING = 0x0000001;
176 private static final int GPS_CAPABILITY_MSB = 0x0000002;
177 private static final int GPS_CAPABILITY_MSA = 0x0000004;
178 private static final int GPS_CAPABILITY_SINGLE_SHOT = 0x0000008;
Mike Lockwood9b9fb5c2011-06-29 15:09:40 -0400179 private static final int GPS_CAPABILITY_ON_DEMAND_TIME = 0x0000010;
destradaa6568d702014-10-27 12:47:41 -0700180 private static final int GPS_CAPABILITY_GEOFENCING = 0x0000020;
181 private static final int GPS_CAPABILITY_MEASUREMENTS = 0x0000040;
182 private static final int GPS_CAPABILITY_NAV_MESSAGES = 0x0000080;
Mike Lockwood04598b62010-04-14 17:17:24 -0400183
Tsuwei Chen462bcd82014-09-17 12:28:49 -0700184 // The AGPS SUPL mode
185 private static final int AGPS_SUPL_MODE_MSA = 0x02;
186 private static final int AGPS_SUPL_MODE_MSB = 0x01;
187
gomo4402af62017-01-11 13:20:13 -0800188 // these need to match AGnssType enum in IAGnssCallback.hal
Mike Lockwoode3635c92009-05-11 08:38:02 -0400189 private static final int AGPS_TYPE_SUPL = 1;
190 private static final int AGPS_TYPE_C2K = 2;
191
gomo4402af62017-01-11 13:20:13 -0800192 // these must match the ApnIpType enum in IAGnss.hal
destradaa96a14702014-06-05 11:36:30 -0700193 private static final int APN_INVALID = 0;
194 private static final int APN_IPV4 = 1;
195 private static final int APN_IPV6 = 2;
196 private static final int APN_IPV4V6 = 3;
197
Mike Lockwoode3635c92009-05-11 08:38:02 -0400198 // for mAGpsDataConnectionState
199 private static final int AGPS_DATA_CONNECTION_CLOSED = 0;
200 private static final int AGPS_DATA_CONNECTION_OPENING = 1;
201 private static final int AGPS_DATA_CONNECTION_OPEN = 2;
Mike Lockwood58bda982009-04-14 16:25:07 -0400202
Mike Lockwood62a8fc12010-03-22 14:23:26 -0400203 // Handler messages
204 private static final int CHECK_LOCATION = 1;
205 private static final int ENABLE = 2;
Nick Pelly6fa9ad42012-07-16 12:18:23 -0700206 private static final int SET_REQUEST = 3;
Mike Lockwood62a8fc12010-03-22 14:23:26 -0400207 private static final int UPDATE_NETWORK_STATE = 4;
208 private static final int INJECT_NTP_TIME = 5;
209 private static final int DOWNLOAD_XTRA_DATA = 6;
210 private static final int UPDATE_LOCATION = 7;
211 private static final int ADD_LISTENER = 8;
212 private static final int REMOVE_LISTENER = 9;
Kevin Tang40e1baf2012-01-10 14:32:44 -0800213 private static final int INJECT_NTP_TIME_FINISHED = 10;
214 private static final int DOWNLOAD_XTRA_DATA_FINISHED = 11;
destradaafb23c672015-04-16 14:01:27 -0700215 private static final int SUBSCRIPTION_OR_SIM_CHANGED = 12;
216 private static final int INITIALIZE_HANDLER = 13;
destradaae21252a2015-09-08 12:32:59 -0700217 private static final int REQUEST_SUPL_CONNECTION = 14;
218 private static final int RELEASE_SUPL_CONNECTION = 15;
Mike Lockwood62a8fc12010-03-22 14:23:26 -0400219
Miguel Torroja1e84da82010-07-27 07:02:24 +0200220 // Request setid
221 private static final int AGPS_RIL_REQUEST_SETID_IMSI = 1;
222 private static final int AGPS_RIL_REQUEST_SETID_MSISDN = 2;
223
Hridya Valsaraju2ea29602016-09-13 08:38:09 -0700224 //TODO(b/33112647): Create gps_debug.conf with commented career parameters.
225 private static final String DEBUG_PROPERTIES_FILE = "/etc/gps_debug.conf";
Miguel Torroja1e84da82010-07-27 07:02:24 +0200226
227 // ref. location info
228 private static final int AGPS_REF_LOCATION_TYPE_GSM_CELLID = 1;
229 private static final int AGPS_REF_LOCATION_TYPE_UMTS_CELLID = 2;
Miguel Torroja1e84da82010-07-27 07:02:24 +0200230
231 // set id info
232 private static final int AGPS_SETID_TYPE_NONE = 0;
233 private static final int AGPS_SETID_TYPE_IMSI = 1;
234 private static final int AGPS_SETID_TYPE_MSISDN = 2;
235
destradaa0682809a2013-08-12 18:50:30 -0700236 private static final int GPS_GEOFENCE_UNAVAILABLE = 1<<0L;
237 private static final int GPS_GEOFENCE_AVAILABLE = 1<<1L;
238
gomo4402af62017-01-11 13:20:13 -0800239 // GPS Geofence errors. Should match GeofenceStatus enum in IGnssGeofenceCallback.hal.
destradaa0682809a2013-08-12 18:50:30 -0700240 private static final int GPS_GEOFENCE_OPERATION_SUCCESS = 0;
241 private static final int GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES = 100;
242 private static final int GPS_GEOFENCE_ERROR_ID_EXISTS = -101;
243 private static final int GPS_GEOFENCE_ERROR_ID_UNKNOWN = -102;
244 private static final int GPS_GEOFENCE_ERROR_INVALID_TRANSITION = -103;
245 private static final int GPS_GEOFENCE_ERROR_GENERIC = -149;
246
Tsuwei Chen678c13c2014-09-22 17:48:41 -0700247 // TCP/IP constants.
248 // Valid TCP/UDP port range is (0, 65535].
249 private static final int TCP_MIN_PORT = 0;
250 private static final int TCP_MAX_PORT = 0xffff;
251
Nick Pelly6fa9ad42012-07-16 12:18:23 -0700252 /** simpler wrapper for ProviderRequest + Worksource */
253 private static class GpsRequest {
254 public ProviderRequest request;
255 public WorkSource source;
256 public GpsRequest(ProviderRequest request, WorkSource source) {
257 this.request = request;
258 this.source = source;
259 }
260 }
261
262 private Object mLock = new Object();
263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800264 // current status
Mike Lockwood15e3d0f2009-05-01 07:53:28 -0400265 private int mStatus = LocationProvider.TEMPORARILY_UNAVAILABLE;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800266
267 // time for last status update
268 private long mStatusUpdateTime = SystemClock.elapsedRealtime();
Mike Lockwoodd53ba012010-04-15 20:41:26 -0400269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270 // turn off GPS fix icon if we haven't received a fix in 10 seconds
Mike Lockwood04598b62010-04-14 17:17:24 -0400271 private static final long RECENT_FIX_TIMEOUT = 10 * 1000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272
Mike Lockwood0632ca72009-05-14 15:51:03 -0400273 // stop trying if we do not receive a fix within 60 seconds
Mike Lockwood04598b62010-04-14 17:17:24 -0400274 private static final int NO_FIX_TIMEOUT = 60 * 1000;
Mike Lockwood0632ca72009-05-14 15:51:03 -0400275
Nick Pellyb041f232012-05-07 17:12:25 -0700276 // if the fix interval is below this we leave GPS on,
277 // if above then we cycle the GPS driver.
278 // Typical hot TTTF is ~5 seconds, so 10 seconds seems sane.
279 private static final int GPS_POLLING_THRESHOLD_INTERVAL = 10 * 1000;
280
Nick Pelly6fa9ad42012-07-16 12:18:23 -0700281 // how often to request NTP time, in milliseconds
282 // current setting 24 hours
283 private static final long NTP_INTERVAL = 24*60*60*1000;
284 // how long to wait if we have a network error in NTP or XTRA downloading
Wei Liu6f6326b2015-06-24 23:47:50 -0700285 // the initial value of the exponential backoff
Nick Pelly6fa9ad42012-07-16 12:18:23 -0700286 // current setting - 5 minutes
287 private static final long RETRY_INTERVAL = 5*60*1000;
Wei Liu6f6326b2015-06-24 23:47:50 -0700288 // how long to wait if we have a network error in NTP or XTRA downloading
289 // the max value of the exponential backoff
290 // current setting - 4 hours
291 private static final long MAX_RETRY_INTERVAL = 4*60*60*1000;
292
Wei Wangc5706f62017-04-18 11:26:26 -0700293 // Timeout when holding wakelocks for downloading XTRA data.
294 private static final long DOWNLOAD_XTRA_DATA_TIMEOUT_MS = 60 * 1000;
295
Wei Liu6f6326b2015-06-24 23:47:50 -0700296 private BackOff mNtpBackOff = new BackOff(RETRY_INTERVAL, MAX_RETRY_INTERVAL);
297 private BackOff mXtraBackOff = new BackOff(RETRY_INTERVAL, MAX_RETRY_INTERVAL);
Nick Pelly6fa9ad42012-07-16 12:18:23 -0700298
299 // true if we are enabled, protected by this
300 private boolean mEnabled;
301
Kevin Tang40e1baf2012-01-10 14:32:44 -0800302 // states for injecting ntp and downloading xtra data
303 private static final int STATE_PENDING_NETWORK = 0;
304 private static final int STATE_DOWNLOADING = 1;
305 private static final int STATE_IDLE = 2;
306
Mike Lockwood62a8fc12010-03-22 14:23:26 -0400307 // flags to trigger NTP or XTRA data download when network becomes available
308 // initialized to true so we do NTP and XTRA when the network comes up after booting
Kevin Tang40e1baf2012-01-10 14:32:44 -0800309 private int mInjectNtpTimePending = STATE_PENDING_NETWORK;
310 private int mDownloadXtraDataPending = STATE_PENDING_NETWORK;
Mike Lockwood62a8fc12010-03-22 14:23:26 -0400311
destradaa56b47f82015-07-24 10:56:18 -0700312 // set to true if the GPS engine requested on-demand NTP time requests
313 private boolean mOnDemandTimeInjection;
Mike Lockwood9b9fb5c2011-06-29 15:09:40 -0400314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315 // true if GPS is navigating
316 private boolean mNavigating;
Mike Lockwoodcf1d8cb2010-01-20 10:14:54 -0500317
318 // true if GPS engine is on
319 private boolean mEngineOn;
Nick Pelly6fa9ad42012-07-16 12:18:23 -0700320
Mike Lockwood04598b62010-04-14 17:17:24 -0400321 // requested frequency of fixes, in milliseconds
322 private int mFixInterval = 1000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800323
324 // true if we started navigation
325 private boolean mStarted;
326
Stan Chesnutt1d72d8c2013-04-15 19:18:02 -0700327 // true if single shot request is in progress
328 private boolean mSingleShot;
329
Mike Lockwood04598b62010-04-14 17:17:24 -0400330 // capabilities of the GPS engine
331 private int mEngineCapabilities;
332
Mike Lockwood1a1cd3a2010-08-17 07:42:54 -0400333 // true if XTRA is supported
334 private boolean mSupportsXtra;
335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800336 // for calculating time to first fix
337 private long mFixRequestTime = 0;
338 // time to first fix for most recent session
Nick Pelly6fa9ad42012-07-16 12:18:23 -0700339 private int mTimeToFirstFix = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800340 // time we received our last fix
341 private long mLastFixTime;
342
Mike Lockwood04598b62010-04-14 17:17:24 -0400343 private int mPositionMode;
344
David Christied4edf4c2014-08-12 15:22:27 -0700345 // Current request from underlying location clients.
346 private ProviderRequest mProviderRequest = null;
347 // Current list of underlying location clients.
348 private WorkSource mWorkSource = null;
349 // True if gps should be disabled (used to support battery saver mode in settings).
350 private boolean mDisableGps = false;
351
destradaafb23c672015-04-16 14:01:27 -0700352 /**
353 * Properties loaded from PROPERTIES_FILE.
354 * It must be accessed only inside {@link #mHandler}.
355 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356 private Properties mProperties;
destradaafb23c672015-04-16 14:01:27 -0700357
Mike Lockwood734d6032009-07-28 18:30:25 -0700358 private String mSuplServerHost;
Tsuwei Chen678c13c2014-09-22 17:48:41 -0700359 private int mSuplServerPort = TCP_MIN_PORT;
Mike Lockwood734d6032009-07-28 18:30:25 -0700360 private String mC2KServerHost;
361 private int mC2KServerPort;
Tsuwei Chen3324e952014-09-07 01:30:42 -0700362 private boolean mSuplEsEnabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363
Mike Lockwood15e3d0f2009-05-01 07:53:28 -0400364 private final Context mContext;
Jeff Sharkey104344e2011-07-10 14:20:41 -0700365 private final NtpTrustedTime mNtpTime;
Nick Pelly6fa9ad42012-07-16 12:18:23 -0700366 private final ILocationManager mILocationManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800367 private Location mLocation = new Location(LocationManager.GPS_PROVIDER);
368 private Bundle mLocationExtras = new Bundle();
Lifu Tang30f95a72016-01-07 23:20:38 -0800369 private final GnssStatusListenerHelper mListenerHelper;
Lifu Tang818aa2c2016-02-01 01:52:00 -0800370 private final GnssMeasurementsProvider mGnssMeasurementsProvider;
371 private final GnssNavigationMessageProvider mGnssNavigationMessageProvider;
Mike Lockwood62a8fc12010-03-22 14:23:26 -0400372
Victoria Lease5c24fd02012-10-01 11:00:50 -0700373 // Handler for processing events
Mike Lockwood62a8fc12010-03-22 14:23:26 -0400374 private Handler mHandler;
The Android Open Source Project10592532009-03-18 17:39:46 -0700375
destradaae21252a2015-09-08 12:32:59 -0700376 /** It must be accessed only inside {@link #mHandler}. */
Mike Lockwoode3635c92009-05-11 08:38:02 -0400377 private int mAGpsDataConnectionState;
destradaae21252a2015-09-08 12:32:59 -0700378 /** It must be accessed only inside {@link #mHandler}. */
destradaa96a14702014-06-05 11:36:30 -0700379 private InetAddress mAGpsDataConnectionIpAddr;
destradaae21252a2015-09-08 12:32:59 -0700380
Mike Lockwood2f82c4e2009-04-17 08:24:10 -0400381 private final ConnectivityManager mConnMgr;
Nick Pelly6fa9ad42012-07-16 12:18:23 -0700382 private final GpsNetInitiatedHandler mNIHandler;
Mike Lockwood2f82c4e2009-04-17 08:24:10 -0400383
Mike Lockwood0528b9b2009-05-07 10:12:54 -0400384 // Wakelocks
Lifu Tang30f95a72016-01-07 23:20:38 -0800385 private final static String WAKELOCK_KEY = "GnssLocationProvider";
Mike Lockwood0528b9b2009-05-07 10:12:54 -0400386 private final PowerManager.WakeLock mWakeLock;
Wei Wangb71c0492017-05-01 20:24:19 -0700387 private static final String DOWNLOAD_EXTRA_WAKELOCK_KEY = "GnssLocationProviderXtraDownload";
388 private final PowerManager.WakeLock mDownloadXtraWakeLock;
Mike Lockwood0528b9b2009-05-07 10:12:54 -0400389
Mike Lockwood29c84342009-05-06 14:01:15 -0400390 // Alarms
391 private final static String ALARM_WAKEUP = "com.android.internal.location.ALARM_WAKEUP";
Mike Lockwood0632ca72009-05-14 15:51:03 -0400392 private final static String ALARM_TIMEOUT = "com.android.internal.location.ALARM_TIMEOUT";
Tsuwei Chen52617bb2014-08-25 11:49:11 -0700393
394 // SIM/Carrier info.
395 private final static String SIM_STATE_CHANGED = "android.intent.action.SIM_STATE_CHANGED";
396
Ecco Park624ac3c2016-07-18 14:08:05 -0700397 // Persist property for LPP_PROFILE
398 private final static String LPP_PROFILE = "persist.sys.gps.lpp";
399
Ecco Park624ac3c2016-07-18 14:08:05 -0700400
401
David Christied4edf4c2014-08-12 15:22:27 -0700402 private final PowerManager mPowerManager;
Mike Lockwood29c84342009-05-06 14:01:15 -0400403 private final AlarmManager mAlarmManager;
404 private final PendingIntent mWakeupIntent;
Mike Lockwood0632ca72009-05-14 15:51:03 -0400405 private final PendingIntent mTimeoutIntent;
Mike Lockwood29c84342009-05-06 14:01:15 -0400406
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800407 private final IAppOpsService mAppOpsService;
Mike Lockwood2f82c4e2009-04-17 08:24:10 -0400408 private final IBatteryStats mBatteryStats;
The Android Open Source Project10592532009-03-18 17:39:46 -0700409
Nick Pelly6fa9ad42012-07-16 12:18:23 -0700410 // only modified on handler thread
Dianne Hackborn002a54e2013-01-10 17:34:55 -0800411 private WorkSource mClientSource = new WorkSource();
Mike Lockwoodf1218be2010-01-29 09:20:06 -0500412
Jaikumar Ganesh8ce470d2013-04-03 12:22:18 -0700413 private GeofenceHardwareImpl mGeofenceHardwareImpl;
Lifu Tang82f893d2016-01-21 18:15:33 -0800414 private int mYearOfHardware = 0;
415
Wyatt Riley5d5bac82016-11-01 07:05:16 -0700416 // Set lower than the current ITAR limit of 600m/s to allow this to trigger even if GPS HAL
417 // stops output right at 600m/s, depriving this of the information of a device that reaches
418 // greater than 600m/s, and higher than the speed of sound to avoid impacting most use cases.
419 private static final float ITAR_SPEED_LIMIT_METERS_PER_SECOND = 400.0F;
420 private boolean mItarSpeedLimitExceeded = false;
421
Siddharth Raybb608c82017-03-16 11:33:34 -0700422 // GNSS Metrics
423 private GnssMetrics mGnssMetrics;
424
Lifu Tang30f95a72016-01-07 23:20:38 -0800425 private final IGnssStatusProvider mGnssStatusProvider = new IGnssStatusProvider.Stub() {
Nick Pelly6fa9ad42012-07-16 12:18:23 -0700426 @Override
Lifu Tang30f95a72016-01-07 23:20:38 -0800427 public void registerGnssStatusCallback(IGnssStatusListener callback) {
428 mListenerHelper.addListener(callback);
Mike Lockwood15e3d0f2009-05-01 07:53:28 -0400429 }
430
Nick Pelly6fa9ad42012-07-16 12:18:23 -0700431 @Override
Lifu Tang30f95a72016-01-07 23:20:38 -0800432 public void unregisterGnssStatusCallback(IGnssStatusListener callback) {
433 mListenerHelper.removeListener(callback);
destradaaea8a8a62014-06-23 18:19:03 -0700434 }
435 };
Mike Lockwood15e3d0f2009-05-01 07:53:28 -0400436
Lifu Tang30f95a72016-01-07 23:20:38 -0800437 public IGnssStatusProvider getGnssStatusProvider() {
438 return mGnssStatusProvider;
Mike Lockwood15e3d0f2009-05-01 07:53:28 -0400439 }
440
Jaikumar Ganesh8ce470d2013-04-03 12:22:18 -0700441 public IGpsGeofenceHardware getGpsGeofenceProxy() {
442 return mGpsGeofenceBinder;
443 }
444
Lifu Tang818aa2c2016-02-01 01:52:00 -0800445 public GnssMeasurementsProvider getGnssMeasurementsProvider() {
446 return mGnssMeasurementsProvider;
destradaaea8a8a62014-06-23 18:19:03 -0700447 }
448
Lifu Tang818aa2c2016-02-01 01:52:00 -0800449 public GnssNavigationMessageProvider getGnssNavigationMessageProvider() {
450 return mGnssNavigationMessageProvider;
destradaa4b3e3932014-07-21 18:01:47 -0700451 }
452
destradaae21252a2015-09-08 12:32:59 -0700453 /**
454 * Callback used to listen for data connectivity changes.
455 */
456 private final ConnectivityManager.NetworkCallback mNetworkConnectivityCallback =
457 new ConnectivityManager.NetworkCallback() {
458 @Override
459 public void onAvailable(Network network) {
Wyatt Riley0d6e54e22016-10-05 12:03:03 -0700460 if (mInjectNtpTimePending == STATE_PENDING_NETWORK) {
461 requestUtcTime();
462 }
463 if (mDownloadXtraDataPending == STATE_PENDING_NETWORK) {
464 xtraDownloadRequest();
465 }
Wyatt Riley41f6bce2016-12-13 10:45:29 -0800466 // Always on, notify HAL so it can get data it needs
Wyatt Rileybb9c9902016-12-07 07:16:25 -0800467 sendMessage(UPDATE_NETWORK_STATE, 0 /*arg*/, network);
destradaae21252a2015-09-08 12:32:59 -0700468 }
Kevin Tang71ad5fe2017-05-10 19:36:20 -0700469
470 @Override
471 public void onLost(Network network) {
472 sendMessage(UPDATE_NETWORK_STATE, 0 /*arg*/, network);
473 }
destradaae21252a2015-09-08 12:32:59 -0700474 };
475
476 /**
477 * Callback used to listen for availability of a requested SUPL connection.
478 * It is kept as a separate instance from {@link #mNetworkConnectivityCallback} to be able to
479 * manage the registration/un-registration lifetimes separate.
480 */
481 private final ConnectivityManager.NetworkCallback mSuplConnectivityCallback =
482 new ConnectivityManager.NetworkCallback() {
483 @Override
Wyatt Riley41f6bce2016-12-13 10:45:29 -0800484 public void onAvailable(Network network) {
485 // Specific to a change to a SUPL enabled network becoming ready
486 sendMessage(UPDATE_NETWORK_STATE, 0 /*arg*/, network);
487 }
488
489 @Override
destradaae21252a2015-09-08 12:32:59 -0700490 public void onLost(Network network) {
491 releaseSuplConnection(GPS_RELEASE_AGPS_DATA_CONN);
492 }
destradaae21252a2015-09-08 12:32:59 -0700493 };
494
Tsuwei Chen52617bb2014-08-25 11:49:11 -0700495 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
The Android Open Source Project10592532009-03-18 17:39:46 -0700496 @Override public void onReceive(Context context, Intent intent) {
497 String action = intent.getAction();
Tsuwei Chen48d37f92014-09-05 15:15:34 -0700498 if (DEBUG) Log.d(TAG, "receive broadcast intent, action: " + action);
destradaaee9fd342015-08-31 13:31:17 -0700499 if (action == null) {
500 return;
501 }
502
Mike Lockwood29c84342009-05-06 14:01:15 -0400503 if (action.equals(ALARM_WAKEUP)) {
Stan Chesnutt1d72d8c2013-04-15 19:18:02 -0700504 startNavigating(false);
Mike Lockwood0632ca72009-05-14 15:51:03 -0400505 } else if (action.equals(ALARM_TIMEOUT)) {
Mike Lockwood0632ca72009-05-14 15:51:03 -0400506 hibernate();
David Christied4edf4c2014-08-12 15:22:27 -0700507 } else if (PowerManager.ACTION_POWER_SAVE_MODE_CHANGED.equals(action)
Adam Lesinski87c17df2015-05-27 13:24:13 -0700508 || PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED.equals(action)
David Christied4edf4c2014-08-12 15:22:27 -0700509 || Intent.ACTION_SCREEN_OFF.equals(action)
510 || Intent.ACTION_SCREEN_ON.equals(action)) {
511 updateLowPowerMode();
Wink Savillea374c3d2014-11-11 11:48:04 -0800512 } else if (action.equals(SIM_STATE_CHANGED)) {
513 subscriptionOrSimChanged(context);
David Christied4edf4c2014-08-12 15:22:27 -0700514 }
The Android Open Source Project10592532009-03-18 17:39:46 -0700515 }
Mike Lockwood29c84342009-05-06 14:01:15 -0400516 };
The Android Open Source Project10592532009-03-18 17:39:46 -0700517
Wink Savilled09c4ca2014-11-22 10:08:16 -0800518 private final OnSubscriptionsChangedListener mOnSubscriptionsChangedListener =
519 new OnSubscriptionsChangedListener() {
Wink Savillea374c3d2014-11-11 11:48:04 -0800520 @Override
Wink Savilled09c4ca2014-11-22 10:08:16 -0800521 public void onSubscriptionsChanged() {
destradaafb23c672015-04-16 14:01:27 -0700522 sendMessage(SUBSCRIPTION_OR_SIM_CHANGED, 0, null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800523 }
524 };
525
526 private void subscriptionOrSimChanged(Context context) {
Joe Onorato0c484102016-02-01 18:04:24 -0800527 if (DEBUG) Log.d(TAG, "received SIM related action: ");
Wink Savillea374c3d2014-11-11 11:48:04 -0800528 TelephonyManager phone = (TelephonyManager)
529 mContext.getSystemService(Context.TELEPHONY_SERVICE);
Ecco Park4fa1ab72016-10-24 13:04:52 -0700530 CarrierConfigManager configManager = (CarrierConfigManager)
531 mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Wink Savillea374c3d2014-11-11 11:48:04 -0800532 String mccMnc = phone.getSimOperator();
Ecco Park4fa1ab72016-10-24 13:04:52 -0700533 boolean isKeepLppProfile = false;
Wink Savillea374c3d2014-11-11 11:48:04 -0800534 if (!TextUtils.isEmpty(mccMnc)) {
Joe Onorato0c484102016-02-01 18:04:24 -0800535 if (DEBUG) Log.d(TAG, "SIM MCC/MNC is available: " + mccMnc);
Wink Savillea374c3d2014-11-11 11:48:04 -0800536 synchronized (mLock) {
Ecco Park4fa1ab72016-10-24 13:04:52 -0700537 if (configManager != null) {
538 PersistableBundle b = configManager.getConfig();
539 isKeepLppProfile = b.getBoolean(CarrierConfigManager.KEY_PERSIST_LPP_MODE_BOOL);
540 }
541 if (isKeepLppProfile) {
542 // load current properties for the carrier
543 loadPropertiesFromResource(context, mProperties);
544 String lpp_profile = mProperties.getProperty("LPP_PROFILE");
545 // set the persist property LPP_PROFILE for the value
Ecco Park8eec7442017-08-04 16:21:59 -0700546 if (lpp_profile != null) {
547 SystemProperties.set(LPP_PROFILE, lpp_profile);
548 }
Ecco Park624ac3c2016-07-18 14:08:05 -0700549 } else {
Ecco Park4fa1ab72016-10-24 13:04:52 -0700550 // reset the persist property
551 SystemProperties.set(LPP_PROFILE, "");
Ecco Park624ac3c2016-07-18 14:08:05 -0700552 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800553 reloadGpsProperties(context, mProperties);
554 mNIHandler.setSuplEsEnabled(mSuplEsEnabled);
555 }
556 } else {
Joe Onorato0c484102016-02-01 18:04:24 -0800557 if (DEBUG) Log.d(TAG, "SIM MCC/MNC is still not available");
Wink Savillea374c3d2014-11-11 11:48:04 -0800558 }
559 }
560
David Christied4edf4c2014-08-12 15:22:27 -0700561 private void updateLowPowerMode() {
Adam Lesinski87c17df2015-05-27 13:24:13 -0700562 // Disable GPS if we are in device idle mode.
563 boolean disableGps = mPowerManager.isDeviceIdleMode();
jackqdyulei455e90a2017-02-09 15:29:16 -0800564 final PowerSaveState result =
565 mPowerManager.getPowerSaveState(ServiceType.GPS);
566 switch (result.gpsMode) {
567 case BatterySaverPolicy.GPS_MODE_DISABLED_WHEN_SCREEN_OFF:
Adam Lesinski87c17df2015-05-27 13:24:13 -0700568 // If we are in battery saver mode and the screen is off, disable GPS.
jackqdyulei455e90a2017-02-09 15:29:16 -0800569 disableGps |= result.batterySaverEnabled && !mPowerManager.isInteractive();
David Christied4edf4c2014-08-12 15:22:27 -0700570 break;
David Christied4edf4c2014-08-12 15:22:27 -0700571 }
572 if (disableGps != mDisableGps) {
573 mDisableGps = disableGps;
574 updateRequirements();
575 }
576 }
577
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800578 public static boolean isSupported() {
579 return native_is_supported();
580 }
581
Hridya Valsaraju2ea29602016-09-13 08:38:09 -0700582 interface SetCarrierProperty {
583 public boolean set(int value);
584 }
585
Tsuwei Chen52617bb2014-08-25 11:49:11 -0700586 private void reloadGpsProperties(Context context, Properties properties) {
Joe Onorato0c484102016-02-01 18:04:24 -0800587 if (DEBUG) Log.d(TAG, "Reset GPS properties, previous size = " + properties.size());
Tsuwei Chen52617bb2014-08-25 11:49:11 -0700588 loadPropertiesFromResource(context, properties);
Ecco Park624ac3c2016-07-18 14:08:05 -0700589
Ecco Park624ac3c2016-07-18 14:08:05 -0700590 String lpp_prof = SystemProperties.get(LPP_PROFILE);
591 if (!TextUtils.isEmpty(lpp_prof)) {
592 // override default value of this if lpp_prof is not empty
593 properties.setProperty("LPP_PROFILE", lpp_prof);
594 }
Wyatt Riley3e1cd0b2017-04-19 17:57:14 -0700595 /*
596 * Overlay carrier properties from a debug configuration file.
597 */
598 loadPropertiesFromFile(DEBUG_PROPERTIES_FILE, properties);
Tsuwei Chen52617bb2014-08-25 11:49:11 -0700599 // TODO: we should get rid of C2K specific setting.
600 setSuplHostPort(properties.getProperty("SUPL_HOST"),
601 properties.getProperty("SUPL_PORT"));
602 mC2KServerHost = properties.getProperty("C2K_HOST");
603 String portString = properties.getProperty("C2K_PORT");
604 if (mC2KServerHost != null && portString != null) {
605 try {
606 mC2KServerPort = Integer.parseInt(portString);
607 } catch (NumberFormatException e) {
608 Log.e(TAG, "unable to parse C2K_PORT: " + portString);
609 }
610 }
destradaaef752b62015-04-17 13:10:47 -0700611 if (native_is_gnss_configuration_supported()) {
Hridya Valsaraju2ea29602016-09-13 08:38:09 -0700612 Map<String, SetCarrierProperty> map = new HashMap<String, SetCarrierProperty>() {
613 {
614 put("SUPL_VER", (val) -> native_set_supl_version(val));
615 put("SUPL_MODE", (val) -> native_set_supl_mode(val));
616 put("SUPL_ES", (val) -> native_set_supl_es(val));
617 put("LPP_PROFILE", (val) -> native_set_lpp_profile(val));
618 put("A_GLONASS_POS_PROTOCOL_SELECT", (val) -> native_set_gnss_pos_protocol_select(val));
619 put("USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL", (val) -> native_set_emergency_supl_pdn(val));
620 put("GPS_LOCK", (val) -> native_set_gps_lock(val));
621 }
622 };
623
624 for(Entry<String, SetCarrierProperty> entry : map.entrySet()) {
625 String propertyName = entry.getKey();
626 String propertyValueString = properties.getProperty(propertyName);
627 if (propertyValueString != null) {
628 try {
629 int propertyValueInt = Integer.decode(propertyValueString);
630 boolean result = entry.getValue().set(propertyValueInt);
631 if (result == false) {
632 Log.e(TAG, "Unable to set " + propertyName);
633 }
634 } catch (NumberFormatException e) {
635 Log.e(TAG, "unable to parse propertyName: " + propertyValueString);
636 }
637 }
destradaaef752b62015-04-17 13:10:47 -0700638 }
639 } else if (DEBUG) {
640 Log.d(TAG, "Skipped configuration update because GNSS configuration in GPS HAL is not"
641 + " supported");
Tsuwei Chen52617bb2014-08-25 11:49:11 -0700642 }
Tsuwei Chen3324e952014-09-07 01:30:42 -0700643
644 // SUPL_ES configuration.
645 String suplESProperty = mProperties.getProperty("SUPL_ES");
646 if (suplESProperty != null) {
647 try {
648 mSuplEsEnabled = (Integer.parseInt(suplESProperty) == 1);
649 } catch (NumberFormatException e) {
650 Log.e(TAG, "unable to parse SUPL_ES: " + suplESProperty);
651 }
652 }
Tsuwei Chen52617bb2014-08-25 11:49:11 -0700653 }
654
655 private void loadPropertiesFromResource(Context context,
656 Properties properties) {
657 String[] configValues = context.getResources().getStringArray(
658 com.android.internal.R.array.config_gpsParameters);
659 for (String item : configValues) {
Joe Onorato0c484102016-02-01 18:04:24 -0800660 if (DEBUG) Log.d(TAG, "GpsParamsResource: " + item);
Tsuwei Chen7c485bf2014-09-10 15:33:34 -0700661 // We need to support "KEY =", but not "=VALUE".
Tsuwei Chen52617bb2014-08-25 11:49:11 -0700662 String[] split = item.split("=");
663 if (split.length == 2) {
664 properties.setProperty(split[0].trim().toUpperCase(), split[1]);
665 } else {
666 Log.w(TAG, "malformed contents: " + item);
667 }
668 }
669 }
670
671 private boolean loadPropertiesFromFile(String filename,
672 Properties properties) {
Colin Cross7c030ed2014-01-28 09:33:53 -0800673 try {
674 File file = new File(filename);
675 FileInputStream stream = null;
676 try {
677 stream = new FileInputStream(file);
Tsuwei Chen52617bb2014-08-25 11:49:11 -0700678 properties.load(stream);
Colin Cross7c030ed2014-01-28 09:33:53 -0800679 } finally {
680 IoUtils.closeQuietly(stream);
681 }
682
Colin Cross7c030ed2014-01-28 09:33:53 -0800683 } catch (IOException e) {
Wyatt Riley3e1cd0b2017-04-19 17:57:14 -0700684 if (DEBUG) Log.d(TAG, "Could not open GPS configuration file " + filename);
Colin Cross7c030ed2014-01-28 09:33:53 -0800685 return false;
686 }
687 return true;
688 }
689
Lifu Tang30f95a72016-01-07 23:20:38 -0800690 public GnssLocationProvider(Context context, ILocationManager ilocationManager,
Victoria Lease5cd731a2012-12-19 15:04:21 -0800691 Looper looper) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800692 mContext = context;
Jeff Sharkey104344e2011-07-10 14:20:41 -0700693 mNtpTime = NtpTrustedTime.getInstance(context);
Nick Pelly6fa9ad42012-07-16 12:18:23 -0700694 mILocationManager = ilocationManager;
Mike Lockwood63598a02010-02-24 11:52:59 -0500695
696 mLocation.setExtras(mLocationExtras);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800697
Mike Lockwood0528b9b2009-05-07 10:12:54 -0400698 // Create a wake lock
David Christied4edf4c2014-08-12 15:22:27 -0700699 mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
700 mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCK_KEY);
Nick Pelly6fa9ad42012-07-16 12:18:23 -0700701 mWakeLock.setReferenceCounted(true);
Mike Lockwood0528b9b2009-05-07 10:12:54 -0400702
Wei Wangb71c0492017-05-01 20:24:19 -0700703 // Create a separate wake lock for xtra downloader as it may be released due to timeout.
704 mDownloadXtraWakeLock = mPowerManager.newWakeLock(
705 PowerManager.PARTIAL_WAKE_LOCK, DOWNLOAD_EXTRA_WAKELOCK_KEY);
706 mDownloadXtraWakeLock.setReferenceCounted(true);
707
Mike Lockwood29c84342009-05-06 14:01:15 -0400708 mAlarmManager = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);
709 mWakeupIntent = PendingIntent.getBroadcast(mContext, 0, new Intent(ALARM_WAKEUP), 0);
Mike Lockwood0632ca72009-05-14 15:51:03 -0400710 mTimeoutIntent = PendingIntent.getBroadcast(mContext, 0, new Intent(ALARM_TIMEOUT), 0);
Mike Lockwood29c84342009-05-06 14:01:15 -0400711
Mike Lockwood58bda982009-04-14 16:25:07 -0400712 mConnMgr = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
713
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800714 // App ops service to keep track of who is accessing the GPS
715 mAppOpsService = IAppOpsService.Stub.asInterface(ServiceManager.getService(
716 Context.APP_OPS_SERVICE));
717
Mike Lockwood2f82c4e2009-04-17 08:24:10 -0400718 // Battery statistics service to be notified when GPS turns on or off
Dianne Hackborn91268cf2013-06-13 19:06:50 -0700719 mBatteryStats = IBatteryStats.Stub.asInterface(ServiceManager.getService(
720 BatteryStats.SERVICE_NAME));
Mike Lockwood2f82c4e2009-04-17 08:24:10 -0400721
destradaafb23c672015-04-16 14:01:27 -0700722 // Construct internal handler
723 mHandler = new ProviderHandler(looper);
724
725 // Load GPS configuration and register listeners in the background:
726 // some operations, such as opening files and registering broadcast receivers, can take a
727 // relative long time, so the ctor() is kept to create objects needed by this instance,
728 // while IO initialization and registration is delegated to our internal handler
729 // this approach is just fine because events are posted to our handler anyway
Tsuwei Chen52617bb2014-08-25 11:49:11 -0700730 mProperties = new Properties();
destradaafb23c672015-04-16 14:01:27 -0700731 sendMessage(INITIALIZE_HANDLER, 0, null);
Mike Lockwood62a8fc12010-03-22 14:23:26 -0400732
Tsuwei Chen3324e952014-09-07 01:30:42 -0700733 // Create a GPS net-initiated handler.
734 mNIHandler = new GpsNetInitiatedHandler(context,
735 mNetInitiatedListener,
736 mSuplEsEnabled);
737
Lifu Tang30f95a72016-01-07 23:20:38 -0800738 mListenerHelper = new GnssStatusListenerHelper(mHandler) {
destradaa6568d702014-10-27 12:47:41 -0700739 @Override
740 protected boolean isAvailableInPlatform() {
destradaa13a60b02015-01-15 18:36:01 -0800741 return isSupported();
destradaa6568d702014-10-27 12:47:41 -0700742 }
743
744 @Override
745 protected boolean isGpsEnabled() {
746 return isEnabled();
747 }
748 };
749
Lifu Tang818aa2c2016-02-01 01:52:00 -0800750 mGnssMeasurementsProvider = new GnssMeasurementsProvider(mHandler) {
destradaa6568d702014-10-27 12:47:41 -0700751 @Override
752 public boolean isAvailableInPlatform() {
753 return native_is_measurement_supported();
754 }
755
756 @Override
757 protected boolean registerWithService() {
758 return native_start_measurement_collection();
759 }
760
761 @Override
762 protected void unregisterFromService() {
763 native_stop_measurement_collection();
764 }
765
766 @Override
767 protected boolean isGpsEnabled() {
768 return isEnabled();
769 }
770 };
771
Lifu Tang818aa2c2016-02-01 01:52:00 -0800772 mGnssNavigationMessageProvider = new GnssNavigationMessageProvider(mHandler) {
destradaa6568d702014-10-27 12:47:41 -0700773 @Override
774 protected boolean isAvailableInPlatform() {
775 return native_is_navigation_message_supported();
776 }
777
778 @Override
779 protected boolean registerWithService() {
780 return native_start_navigation_message_collection();
781 }
782
783 @Override
784 protected void unregisterFromService() {
785 native_stop_navigation_message_collection();
786 }
787
788 @Override
789 protected boolean isGpsEnabled() {
790 return isEnabled();
791 }
792 };
Siddharth Raybb608c82017-03-16 11:33:34 -0700793 mGnssMetrics = new GnssMetrics();
Siddharth Rayfff3a9d2017-06-21 15:14:44 -0700794
795 /*
796 * A cycle of native_init() and native_cleanup() is needed so that callbacks are registered
797 * after bootup even when location is disabled. This will allow Emergency SUPL to work even
798 * when location is disabled before device restart.
799 * */
800 boolean isInitialized = native_init();
801 if(!isInitialized) {
802 Log.d(TAG, "Failed to initialize at bootup");
803 } else {
804 native_cleanup();
805 }
Mike Lockwood62a8fc12010-03-22 14:23:26 -0400806 }
807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800808 /**
Mike Lockwoodd03ff942010-02-09 08:46:14 -0500809 * Returns the name of this provider.
810 */
Nick Pelly6fa9ad42012-07-16 12:18:23 -0700811 @Override
Mike Lockwoodd03ff942010-02-09 08:46:14 -0500812 public String getName() {
813 return LocationManager.GPS_PROVIDER;
814 }
815
Nick Pelly6fa9ad42012-07-16 12:18:23 -0700816 @Override
817 public ProviderProperties getProperties() {
818 return PROPERTIES;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800819 }
820
destradaae21252a2015-09-08 12:32:59 -0700821 private void handleUpdateNetworkState(Network network) {
822 // retrieve NetworkInfo for this UID
823 NetworkInfo info = mConnMgr.getNetworkInfo(network);
Kevin Tang71ad5fe2017-05-10 19:36:20 -0700824
825 boolean networkAvailable = false;
826 boolean isConnected = false;
827 int type = ConnectivityManager.TYPE_NONE;
828 boolean isRoaming = false;
829 String apnName = null;
830
831 if (info != null) {
832 networkAvailable = info.isAvailable() && TelephonyManager.getDefault().getDataEnabled();
833 isConnected = info.isConnected();
834 type = info.getType();
835 isRoaming = info.isRoaming();
836 apnName = info.getExtraInfo();
destradaae21252a2015-09-08 12:32:59 -0700837 }
Mike Lockwood62a8fc12010-03-22 14:23:26 -0400838
Joe Onoratof5d95cb2010-01-07 21:48:32 -0500839 if (DEBUG) {
destradaae21252a2015-09-08 12:32:59 -0700840 String message = String.format(
841 "UpdateNetworkState, state=%s, connected=%s, info=%s, capabilities=%S",
842 agpsDataConnStateAsString(),
843 isConnected,
844 info,
845 mConnMgr.getNetworkCapabilities(network));
846 Log.d(TAG, message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800847 }
Mike Lockwood03d24672009-10-08 15:45:03 -0400848
destradaae21252a2015-09-08 12:32:59 -0700849 if (native_is_agps_ril_supported()) {
destradaae21252a2015-09-08 12:32:59 -0700850 String defaultApn = getSelectedApn();
851 if (defaultApn == null) {
852 defaultApn = "dummy-apn";
destradaaef752b62015-04-17 13:10:47 -0700853 }
destradaae21252a2015-09-08 12:32:59 -0700854
855 native_update_network_state(
856 isConnected,
Kevin Tang71ad5fe2017-05-10 19:36:20 -0700857 type,
858 isRoaming,
destradaae21252a2015-09-08 12:32:59 -0700859 networkAvailable,
Kevin Tang71ad5fe2017-05-10 19:36:20 -0700860 apnName,
destradaae21252a2015-09-08 12:32:59 -0700861 defaultApn);
862 } else if (DEBUG) {
863 Log.d(TAG, "Skipped network state update because GPS HAL AGPS-RIL is not supported");
Mike Lockwood50130bb2010-10-11 06:22:50 -0400864 }
865
destradaae21252a2015-09-08 12:32:59 -0700866 if (mAGpsDataConnectionState == AGPS_DATA_CONNECTION_OPENING) {
867 if (isConnected) {
Stephen Li83b69712011-01-25 18:47:28 -0800868 if (apnName == null) {
destradaae21252a2015-09-08 12:32:59 -0700869 // assign a dummy value in the case of C2K as otherwise we will have a runtime
870 // exception in the following call to native_agps_data_conn_open
Stephen Li83b69712011-01-25 18:47:28 -0800871 apnName = "dummy-apn";
872 }
destradaae21252a2015-09-08 12:32:59 -0700873 int apnIpType = getApnIpType(apnName);
destradaa96a14702014-06-05 11:36:30 -0700874 setRouting();
875 if (DEBUG) {
876 String message = String.format(
877 "native_agps_data_conn_open: mAgpsApn=%s, mApnIpType=%s",
destradaae21252a2015-09-08 12:32:59 -0700878 apnName,
879 apnIpType);
destradaa96a14702014-06-05 11:36:30 -0700880 Log.d(TAG, message);
Stephen Li8efd74d2011-03-01 20:56:00 -0800881 }
destradaae21252a2015-09-08 12:32:59 -0700882 native_agps_data_conn_open(apnName, apnIpType);
Mike Lockwood03d24672009-10-08 15:45:03 -0400883 mAGpsDataConnectionState = AGPS_DATA_CONNECTION_OPEN;
884 } else {
destradaae21252a2015-09-08 12:32:59 -0700885 handleReleaseSuplConnection(GPS_AGPS_DATA_CONN_FAILED);
Mike Lockwood03d24672009-10-08 15:45:03 -0400886 }
887 }
destradaae21252a2015-09-08 12:32:59 -0700888 }
Mike Lockwood03d24672009-10-08 15:45:03 -0400889
destradaae21252a2015-09-08 12:32:59 -0700890 private void handleRequestSuplConnection(InetAddress address) {
891 if (DEBUG) {
892 String message = String.format(
893 "requestSuplConnection, state=%s, address=%s",
894 agpsDataConnStateAsString(),
895 address);
896 Log.d(TAG, message);
897 }
898
899 if (mAGpsDataConnectionState != AGPS_DATA_CONNECTION_CLOSED) {
900 return;
901 }
902 mAGpsDataConnectionIpAddr = address;
903 mAGpsDataConnectionState = AGPS_DATA_CONNECTION_OPENING;
904
905 NetworkRequest.Builder requestBuilder = new NetworkRequest.Builder();
906 requestBuilder.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);
907 requestBuilder.addCapability(NetworkCapabilities.NET_CAPABILITY_SUPL);
908 NetworkRequest request = requestBuilder.build();
909 mConnMgr.requestNetwork(
910 request,
Etan Cohene9aea9d2017-02-09 18:16:58 -0800911 mSuplConnectivityCallback);
destradaae21252a2015-09-08 12:32:59 -0700912 }
913
914 private void handleReleaseSuplConnection(int agpsDataConnStatus) {
915 if (DEBUG) {
916 String message = String.format(
917 "releaseSuplConnection, state=%s, status=%s",
918 agpsDataConnStateAsString(),
919 agpsDataConnStatusAsString(agpsDataConnStatus));
920 Log.d(TAG, message);
921 }
922
923 if (mAGpsDataConnectionState == AGPS_DATA_CONNECTION_CLOSED) {
924 return;
925 }
926 mAGpsDataConnectionState = AGPS_DATA_CONNECTION_CLOSED;
927
928 mConnMgr.unregisterNetworkCallback(mSuplConnectivityCallback);
929 switch (agpsDataConnStatus) {
930 case GPS_AGPS_DATA_CONN_FAILED:
931 native_agps_data_conn_failed();
932 break;
933 case GPS_RELEASE_AGPS_DATA_CONN:
934 native_agps_data_conn_closed();
935 break;
936 default:
937 Log.e(TAG, "Invalid status to release SUPL connection: " + agpsDataConnStatus);
Mike Lockwood62a8fc12010-03-22 14:23:26 -0400938 }
939 }
940
941 private void handleInjectNtpTime() {
Kevin Tang40e1baf2012-01-10 14:32:44 -0800942 if (mInjectNtpTimePending == STATE_DOWNLOADING) {
943 // already downloading data
Mike Lockwood62a8fc12010-03-22 14:23:26 -0400944 return;
945 }
destradaae21252a2015-09-08 12:32:59 -0700946 if (!isDataNetworkConnected()) {
Kevin Tang40e1baf2012-01-10 14:32:44 -0800947 // try again when network is up
948 mInjectNtpTimePending = STATE_PENDING_NETWORK;
949 return;
Jeff Sharkey104344e2011-07-10 14:20:41 -0700950 }
Kevin Tang40e1baf2012-01-10 14:32:44 -0800951 mInjectNtpTimePending = STATE_DOWNLOADING;
Jeff Sharkey104344e2011-07-10 14:20:41 -0700952
Jeff Brown028872f2012-08-25 13:07:01 -0700953 // hold wake lock while task runs
954 mWakeLock.acquire();
Lifu Tangcbd2a142016-06-22 10:57:55 -0700955 Log.i(TAG, "WakeLock acquired by handleInjectNtpTime()");
Kevin Tang40e1baf2012-01-10 14:32:44 -0800956 AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() {
957 @Override
958 public void run() {
959 long delay;
Mike Lockwood62a8fc12010-03-22 14:23:26 -0400960
Kevin Tang40e1baf2012-01-10 14:32:44 -0800961 // force refresh NTP cache when outdated
destradaa56b47f82015-07-24 10:56:18 -0700962 boolean refreshSuccess = true;
Kevin Tang40e1baf2012-01-10 14:32:44 -0800963 if (mNtpTime.getCacheAge() >= NTP_INTERVAL) {
destradaa56b47f82015-07-24 10:56:18 -0700964 refreshSuccess = mNtpTime.forceRefresh();
Kevin Tang40e1baf2012-01-10 14:32:44 -0800965 }
Mike Lockwood62a8fc12010-03-22 14:23:26 -0400966
Kevin Tang40e1baf2012-01-10 14:32:44 -0800967 // only update when NTP time is fresh
968 if (mNtpTime.getCacheAge() < NTP_INTERVAL) {
969 long time = mNtpTime.getCachedNtpTime();
970 long timeReference = mNtpTime.getCachedNtpTimeReference();
971 long certainty = mNtpTime.getCacheCertainty();
Mike Lockwood62a8fc12010-03-22 14:23:26 -0400972
Joe Onorato0c484102016-02-01 18:04:24 -0800973 if (DEBUG) {
Yipeng Cao276278d2017-05-18 13:27:30 -0700974 long now = System.currentTimeMillis();
Joe Onorato0c484102016-02-01 18:04:24 -0800975 Log.d(TAG, "NTP server returned: "
976 + time + " (" + new Date(time)
977 + ") reference: " + timeReference
978 + " certainty: " + certainty
979 + " system time offset: " + (time - now));
980 }
Kevin Tang40e1baf2012-01-10 14:32:44 -0800981
982 native_inject_time(time, timeReference, (int) certainty);
983 delay = NTP_INTERVAL;
Wei Liu6f6326b2015-06-24 23:47:50 -0700984 mNtpBackOff.reset();
Kevin Tang40e1baf2012-01-10 14:32:44 -0800985 } else {
destradaa56b47f82015-07-24 10:56:18 -0700986 Log.e(TAG, "requestTime failed");
Wei Liu6f6326b2015-06-24 23:47:50 -0700987 delay = mNtpBackOff.nextBackoffMillis();
Kevin Tang40e1baf2012-01-10 14:32:44 -0800988 }
989
Jeff Brown028872f2012-08-25 13:07:01 -0700990 sendMessage(INJECT_NTP_TIME_FINISHED, 0, null);
Kevin Tang40e1baf2012-01-10 14:32:44 -0800991
destradaa56b47f82015-07-24 10:56:18 -0700992 if (DEBUG) {
993 String message = String.format(
994 "onDemandTimeInjection=%s, refreshSuccess=%s, delay=%s",
995 mOnDemandTimeInjection,
996 refreshSuccess,
997 delay);
998 Log.d(TAG, message);
999 }
1000 if (mOnDemandTimeInjection || !refreshSuccess) {
Kevin Tang40e1baf2012-01-10 14:32:44 -08001001 // send delayed message for next NTP injection
1002 // since this is delayed and not urgent we do not hold a wake lock here
Jeff Brown028872f2012-08-25 13:07:01 -07001003 mHandler.sendEmptyMessageDelayed(INJECT_NTP_TIME, delay);
Kevin Tang40e1baf2012-01-10 14:32:44 -08001004 }
Jeff Brown028872f2012-08-25 13:07:01 -07001005
1006 // release wake lock held by task
1007 mWakeLock.release();
Lifu Tangcbd2a142016-06-22 10:57:55 -07001008 Log.i(TAG, "WakeLock released by handleInjectNtpTime()");
Kevin Tang40e1baf2012-01-10 14:32:44 -08001009 }
1010 });
Mike Lockwood62a8fc12010-03-22 14:23:26 -04001011 }
1012
1013 private void handleDownloadXtraData() {
Wyatt Riley0d6e54e22016-10-05 12:03:03 -07001014 if (!mSupportsXtra) {
1015 // native code reports xtra not supported, don't try
1016 Log.d(TAG, "handleDownloadXtraData() called when Xtra not supported");
1017 return;
1018 }
Kevin Tang40e1baf2012-01-10 14:32:44 -08001019 if (mDownloadXtraDataPending == STATE_DOWNLOADING) {
1020 // already downloading data
Mike Lockwood62a8fc12010-03-22 14:23:26 -04001021 return;
1022 }
destradaae21252a2015-09-08 12:32:59 -07001023 if (!isDataNetworkConnected()) {
Kevin Tang40e1baf2012-01-10 14:32:44 -08001024 // try again when network is up
1025 mDownloadXtraDataPending = STATE_PENDING_NETWORK;
1026 return;
Mike Lockwood62a8fc12010-03-22 14:23:26 -04001027 }
Kevin Tang40e1baf2012-01-10 14:32:44 -08001028 mDownloadXtraDataPending = STATE_DOWNLOADING;
1029
Jeff Brown028872f2012-08-25 13:07:01 -07001030 // hold wake lock while task runs
Wei Wangb71c0492017-05-01 20:24:19 -07001031 mDownloadXtraWakeLock.acquire(DOWNLOAD_XTRA_DATA_TIMEOUT_MS);
Lifu Tangcbd2a142016-06-22 10:57:55 -07001032 Log.i(TAG, "WakeLock acquired by handleDownloadXtraData()");
Kevin Tang40e1baf2012-01-10 14:32:44 -08001033 AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() {
1034 @Override
1035 public void run() {
Andreas Gampedfdc6ac2014-10-28 20:42:53 -07001036 GpsXtraDownloader xtraDownloader = new GpsXtraDownloader(mProperties);
Kevin Tang40e1baf2012-01-10 14:32:44 -08001037 byte[] data = xtraDownloader.downloadXtraData();
1038 if (data != null) {
destradaae21252a2015-09-08 12:32:59 -07001039 if (DEBUG) Log.d(TAG, "calling native_inject_xtra_data");
Kevin Tang40e1baf2012-01-10 14:32:44 -08001040 native_inject_xtra_data(data, data.length);
Wei Liu6f6326b2015-06-24 23:47:50 -07001041 mXtraBackOff.reset();
Kevin Tang40e1baf2012-01-10 14:32:44 -08001042 }
1043
Jeff Brown028872f2012-08-25 13:07:01 -07001044 sendMessage(DOWNLOAD_XTRA_DATA_FINISHED, 0, null);
Kevin Tang40e1baf2012-01-10 14:32:44 -08001045
1046 if (data == null) {
1047 // try again later
1048 // since this is delayed and not urgent we do not hold a wake lock here
Wei Liu6f6326b2015-06-24 23:47:50 -07001049 mHandler.sendEmptyMessageDelayed(DOWNLOAD_XTRA_DATA,
1050 mXtraBackOff.nextBackoffMillis());
Kevin Tang40e1baf2012-01-10 14:32:44 -08001051 }
Kevin Tang40e1baf2012-01-10 14:32:44 -08001052
Wei Wangb71c0492017-05-01 20:24:19 -07001053 // Release wake lock held by task, synchronize on mLock in case multiple
1054 // download tasks overrun.
1055 synchronized (mLock) {
1056 if (mDownloadXtraWakeLock.isHeld()) {
Zheng Zhang3cceb252017-08-07 13:51:23 -07001057 // This wakelock may have time-out, if a timeout was specified.
1058 // Catch (and ignore) any timeout exceptions.
1059 try {
1060 mDownloadXtraWakeLock.release();
1061 if (DEBUG) Log.d(TAG, "WakeLock released by handleDownloadXtraData()");
1062 } catch (Exception e) {
1063 Log.i(TAG, "Wakelock timeout & release race exception in "
1064 + "handleDownloadXtraData()", e);
1065 }
Wei Wangb71c0492017-05-01 20:24:19 -07001066 } else {
1067 Log.e(TAG, "WakeLock expired before release in "
1068 + "handleDownloadXtraData()");
1069 }
Wei Wangc5706f62017-04-18 11:26:26 -07001070 }
Jeff Brown028872f2012-08-25 13:07:01 -07001071 }
Kevin Tang40e1baf2012-01-10 14:32:44 -08001072 });
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001073 }
1074
Mike Lockwood62a8fc12010-03-22 14:23:26 -04001075 private void handleUpdateLocation(Location location) {
Mike Lockwoodd26ce0d2009-06-11 12:25:46 -04001076 if (location.hasAccuracy()) {
1077 native_inject_location(location.getLatitude(), location.getLongitude(),
1078 location.getAccuracy());
1079 }
Mike Lockwoodfd6e5f02009-05-21 11:28:20 -04001080 }
1081
1082 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001083 * Enables this provider. When enabled, calls to getStatus()
Mike Lockwood4e50b782009-04-03 08:24:43 -07001084 * must be handled. Hardware may be started up
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001085 * when the provider is enabled.
1086 */
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001087 @Override
Mike Lockwood62a8fc12010-03-22 14:23:26 -04001088 public void enable() {
Laurent Tu7b5aeca2013-01-24 15:10:24 -08001089 synchronized (mLock) {
1090 if (mEnabled) return;
1091 mEnabled = true;
1092 }
1093
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001094 sendMessage(ENABLE, 1, null);
Mike Lockwood62a8fc12010-03-22 14:23:26 -04001095 }
1096
Tsuwei Chen52617bb2014-08-25 11:49:11 -07001097 private void setSuplHostPort(String hostString, String portString) {
1098 if (hostString != null) {
1099 mSuplServerHost = hostString;
1100 }
1101 if (portString != null) {
1102 try {
1103 mSuplServerPort = Integer.parseInt(portString);
1104 } catch (NumberFormatException e) {
1105 Log.e(TAG, "unable to parse SUPL_PORT: " + portString);
1106 }
1107 }
Tsuwei Chen678c13c2014-09-22 17:48:41 -07001108 if (mSuplServerHost != null
1109 && mSuplServerPort > TCP_MIN_PORT
1110 && mSuplServerPort <= TCP_MAX_PORT) {
1111 native_set_agps_server(AGPS_TYPE_SUPL, mSuplServerHost, mSuplServerPort);
1112 }
Tsuwei Chen52617bb2014-08-25 11:49:11 -07001113 }
1114
Tsuwei Chen462bcd82014-09-17 12:28:49 -07001115 /**
1116 * Checks what SUPL mode to use, according to the AGPS mode as well as the
1117 * allowed mode from properties.
1118 *
1119 * @param properties GPS properties
1120 * @param agpsEnabled whether AGPS is enabled by settings value
1121 * @param singleShot whether "singleshot" is needed
1122 * @return SUPL mode (MSA vs MSB vs STANDALONE)
1123 */
1124 private int getSuplMode(Properties properties, boolean agpsEnabled, boolean singleShot) {
1125 if (agpsEnabled) {
1126 String modeString = properties.getProperty("SUPL_MODE");
1127 int suplMode = 0;
1128 if (!TextUtils.isEmpty(modeString)) {
1129 try {
1130 suplMode = Integer.parseInt(modeString);
1131 } catch (NumberFormatException e) {
1132 Log.e(TAG, "unable to parse SUPL_MODE: " + modeString);
1133 return GPS_POSITION_MODE_STANDALONE;
1134 }
1135 }
destradaabfb3bdb2015-04-29 14:42:35 -07001136 // MS-Based is the preferred mode for Assisted-GPS position computation, so we favor
1137 // such mode when it is available
1138 if (hasCapability(GPS_CAPABILITY_MSB) && (suplMode & AGPS_SUPL_MODE_MSB) != 0) {
1139 return GPS_POSITION_MODE_MS_BASED;
1140 }
1141 // for now, just as the legacy code did, we fallback to MS-Assisted if it is available,
1142 // do fallback only for single-shot requests, because it is too expensive to do for
1143 // periodic requests as well
Tsuwei Chen462bcd82014-09-17 12:28:49 -07001144 if (singleShot
1145 && hasCapability(GPS_CAPABILITY_MSA)
1146 && (suplMode & AGPS_SUPL_MODE_MSA) != 0) {
1147 return GPS_POSITION_MODE_MS_ASSISTED;
Tsuwei Chen462bcd82014-09-17 12:28:49 -07001148 }
1149 }
1150 return GPS_POSITION_MODE_STANDALONE;
1151 }
1152
Mike Lockwood62a8fc12010-03-22 14:23:26 -04001153 private void handleEnable() {
1154 if (DEBUG) Log.d(TAG, "handleEnable");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001155
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001156 boolean enabled = native_init();
1157
1158 if (enabled) {
Mike Lockwood1a1cd3a2010-08-17 07:42:54 -04001159 mSupportsXtra = native_supports_xtra();
Tsuwei Chen678c13c2014-09-22 17:48:41 -07001160
1161 // TODO: remove the following native calls if we can make sure they are redundant.
Mike Lockwood734d6032009-07-28 18:30:25 -07001162 if (mSuplServerHost != null) {
1163 native_set_agps_server(AGPS_TYPE_SUPL, mSuplServerHost, mSuplServerPort);
1164 }
1165 if (mC2KServerHost != null) {
1166 native_set_agps_server(AGPS_TYPE_C2K, mC2KServerHost, mC2KServerPort);
1167 }
destradaa13a60b02015-01-15 18:36:01 -08001168
Lifu Tang818aa2c2016-02-01 01:52:00 -08001169 mGnssMeasurementsProvider.onGpsEnabledChanged();
1170 mGnssNavigationMessageProvider.onGpsEnabledChanged();
Wyatt Rileycf879db2017-01-12 13:57:38 -08001171 enableBatching();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001172 } else {
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001173 synchronized (mLock) {
1174 mEnabled = false;
1175 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001176 Log.w(TAG, "Failed to enable location provider");
1177 }
1178 }
1179
1180 /**
1181 * Disables this provider. When disabled, calls to getStatus()
Mike Lockwood4e50b782009-04-03 08:24:43 -07001182 * need not be handled. Hardware may be shut
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001183 * down while the provider is disabled.
1184 */
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001185 @Override
Mike Lockwood62a8fc12010-03-22 14:23:26 -04001186 public void disable() {
Laurent Tu7b5aeca2013-01-24 15:10:24 -08001187 synchronized (mLock) {
1188 if (!mEnabled) return;
1189 mEnabled = false;
1190 }
1191
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001192 sendMessage(ENABLE, 0, null);
Mike Lockwood62a8fc12010-03-22 14:23:26 -04001193 }
1194
1195 private void handleDisable() {
Mike Lockwood89096312010-03-24 10:14:55 -04001196 if (DEBUG) Log.d(TAG, "handleDisable");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001197
David Christie3bc26142013-12-19 14:53:44 -08001198 updateClientUids(new WorkSource());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001199 stopNavigating();
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001200 mAlarmManager.cancel(mWakeupIntent);
1201 mAlarmManager.cancel(mTimeoutIntent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001202
Wyatt Rileycf879db2017-01-12 13:57:38 -08001203 disableBatching();
Mike Lockwoodcf1d8cb2010-01-20 10:14:54 -05001204 // do this before releasing wakelock
1205 native_cleanup();
destradaa13a60b02015-01-15 18:36:01 -08001206
Lifu Tang818aa2c2016-02-01 01:52:00 -08001207 mGnssMeasurementsProvider.onGpsEnabledChanged();
1208 mGnssNavigationMessageProvider.onGpsEnabledChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001209 }
1210
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001211 @Override
Mike Lockwoodd03ff942010-02-09 08:46:14 -05001212 public boolean isEnabled() {
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001213 synchronized (mLock) {
1214 return mEnabled;
1215 }
Mike Lockwoodd03ff942010-02-09 08:46:14 -05001216 }
1217
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001218 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001219 public int getStatus(Bundle extras) {
Wyatt Rileyc9f25dd2017-05-05 13:45:23 -07001220 setLocationExtras(extras);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001221 return mStatus;
1222 }
1223
Wyatt Rileyc9f25dd2017-05-05 13:45:23 -07001224 private void updateStatus(int status, int svCount, int meanCn0, int maxCn0) {
1225 if (status != mStatus || svCount != mSvCount || meanCn0 != mMeanCn0 || maxCn0 != mMaxCn0 ) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001226 mStatus = status;
1227 mSvCount = svCount;
Wyatt Rileyc9f25dd2017-05-05 13:45:23 -07001228 mMeanCn0 = meanCn0;
1229 mMaxCn0 = maxCn0;
1230 setLocationExtras(mLocationExtras);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001231 mStatusUpdateTime = SystemClock.elapsedRealtime();
1232 }
1233 }
1234
Wyatt Rileyc9f25dd2017-05-05 13:45:23 -07001235 private void setLocationExtras(Bundle extras) {
1236 if (extras != null) {
1237 extras.putInt("satellites", mSvCount);
1238 extras.putInt("meanCn0", mMeanCn0);
1239 extras.putInt("maxCn0", mMaxCn0);
1240 }
1241 }
1242
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001243 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001244 public long getStatusUpdateTime() {
1245 return mStatusUpdateTime;
1246 }
1247
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001248 @Override
1249 public void setRequest(ProviderRequest request, WorkSource source) {
1250 sendMessage(SET_REQUEST, 0, new GpsRequest(request, source));
Mike Lockwood62a8fc12010-03-22 14:23:26 -04001251 }
1252
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001253 private void handleSetRequest(ProviderRequest request, WorkSource source) {
David Christied4edf4c2014-08-12 15:22:27 -07001254 mProviderRequest = request;
1255 mWorkSource = source;
1256 updateRequirements();
1257 }
1258
1259 // Called when the requirements for GPS may have changed
1260 private void updateRequirements() {
1261 if (mProviderRequest == null || mWorkSource == null) {
1262 return;
1263 }
1264
Stan Chesnutt1d72d8c2013-04-15 19:18:02 -07001265 boolean singleShot = false;
1266
1267 // see if the request is for a single update
David Christied4edf4c2014-08-12 15:22:27 -07001268 if (mProviderRequest.locationRequests != null
1269 && mProviderRequest.locationRequests.size() > 0) {
Stan Chesnutt1d72d8c2013-04-15 19:18:02 -07001270 // if any request has zero or more than one updates
1271 // requested, then this is not single-shot mode
1272 singleShot = true;
1273
David Christied4edf4c2014-08-12 15:22:27 -07001274 for (LocationRequest lr : mProviderRequest.locationRequests) {
Stan Chesnutt1d72d8c2013-04-15 19:18:02 -07001275 if (lr.getNumUpdates() != 1) {
1276 singleShot = false;
1277 }
1278 }
1279 }
1280
David Christied4edf4c2014-08-12 15:22:27 -07001281 if (DEBUG) Log.d(TAG, "setRequest " + mProviderRequest);
Dante Russo260d6672016-06-20 11:11:59 -07001282 if (mProviderRequest.reportLocation && !mDisableGps && isEnabled()) {
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001283 // update client uids
David Christied4edf4c2014-08-12 15:22:27 -07001284 updateClientUids(mWorkSource);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001285
David Christied4edf4c2014-08-12 15:22:27 -07001286 mFixInterval = (int) mProviderRequest.interval;
Mike Lockwood03ca2162010-04-01 08:10:09 -07001287
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001288 // check for overflow
David Christied4edf4c2014-08-12 15:22:27 -07001289 if (mFixInterval != mProviderRequest.interval) {
1290 Log.w(TAG, "interval overflow: " + mProviderRequest.interval);
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001291 mFixInterval = Integer.MAX_VALUE;
1292 }
Mike Lockwood03ca2162010-04-01 08:10:09 -07001293
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001294 // apply request to GPS engine
Mike Lockwood04598b62010-04-14 17:17:24 -04001295 if (mStarted && hasCapability(GPS_CAPABILITY_SCHEDULING)) {
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001296 // change period
Mike Lockwood04598b62010-04-14 17:17:24 -04001297 if (!native_set_position_mode(mPositionMode, GPS_POSITION_RECURRENCE_PERIODIC,
1298 mFixInterval, 0, 0)) {
1299 Log.e(TAG, "set_position_mode failed in setMinTime()");
1300 }
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001301 } else if (!mStarted) {
1302 // start GPS
Stan Chesnutt1d72d8c2013-04-15 19:18:02 -07001303 startNavigating(singleShot);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001304 }
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001305 } else {
Dianne Hackborn002a54e2013-01-10 17:34:55 -08001306 updateClientUids(new WorkSource());
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001307
1308 stopNavigating();
1309 mAlarmManager.cancel(mWakeupIntent);
1310 mAlarmManager.cancel(mTimeoutIntent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001311 }
1312 }
1313
Dianne Hackborn002a54e2013-01-10 17:34:55 -08001314 private void updateClientUids(WorkSource source) {
1315 // Update work source.
1316 WorkSource[] changes = mClientSource.setReturningDiffs(source);
Victoria Leaseea78b852013-01-15 10:39:28 -08001317 if (changes == null) {
1318 return;
1319 }
Dianne Hackborn002a54e2013-01-10 17:34:55 -08001320 WorkSource newWork = changes[0];
1321 WorkSource goneWork = changes[1];
1322
1323 // Update sources that were not previously tracked.
1324 if (newWork != null) {
1325 int lastuid = -1;
1326 for (int i=0; i<newWork.size(); i++) {
Dianne Hackborn2e418422009-06-22 20:00:17 -07001327 try {
Dianne Hackborn002a54e2013-01-10 17:34:55 -08001328 int uid = newWork.get(i);
Dianne Hackborne98f5db2013-07-17 17:23:25 -07001329 mAppOpsService.startOperation(AppOpsManager.getToken(mAppOpsService),
1330 AppOpsManager.OP_GPS, uid, newWork.getName(i));
Dianne Hackborn002a54e2013-01-10 17:34:55 -08001331 if (uid != lastuid) {
1332 lastuid = uid;
1333 mBatteryStats.noteStartGps(uid);
1334 }
Dianne Hackborn2e418422009-06-22 20:00:17 -07001335 } catch (RemoteException e) {
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001336 Log.w(TAG, "RemoteException", e);
1337 }
1338 }
1339 }
1340
Dianne Hackborn002a54e2013-01-10 17:34:55 -08001341 // Update sources that are no longer tracked.
1342 if (goneWork != null) {
1343 int lastuid = -1;
1344 for (int i=0; i<goneWork.size(); i++) {
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001345 try {
Dianne Hackborn002a54e2013-01-10 17:34:55 -08001346 int uid = goneWork.get(i);
Dianne Hackborne98f5db2013-07-17 17:23:25 -07001347 mAppOpsService.finishOperation(AppOpsManager.getToken(mAppOpsService),
1348 AppOpsManager.OP_GPS, uid, goneWork.getName(i));
Dianne Hackborn002a54e2013-01-10 17:34:55 -08001349 if (uid != lastuid) {
1350 lastuid = uid;
1351 mBatteryStats.noteStopGps(uid);
1352 }
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001353 } catch (RemoteException e) {
1354 Log.w(TAG, "RemoteException", e);
Dianne Hackborn2e418422009-06-22 20:00:17 -07001355 }
Mike Lockwood2f82c4e2009-04-17 08:24:10 -04001356 }
1357 }
1358 }
1359
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001360 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001361 public boolean sendExtraCommand(String command, Bundle extras) {
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001362
Mike Lockwood63aa5a62010-04-14 19:21:31 -04001363 long identity = Binder.clearCallingIdentity();
1364 boolean result = false;
1365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001366 if ("delete_aiding_data".equals(command)) {
Mike Lockwood63aa5a62010-04-14 19:21:31 -04001367 result = deleteAidingData(extras);
1368 } else if ("force_time_injection".equals(command)) {
destradaae21252a2015-09-08 12:32:59 -07001369 requestUtcTime();
Mike Lockwood63aa5a62010-04-14 19:21:31 -04001370 result = true;
1371 } else if ("force_xtra_injection".equals(command)) {
Mike Lockwood1a1cd3a2010-08-17 07:42:54 -04001372 if (mSupportsXtra) {
Mike Lockwood93bc44d2009-05-20 16:58:22 -04001373 xtraDownloadRequest();
Mike Lockwood63aa5a62010-04-14 19:21:31 -04001374 result = true;
Mike Lockwood93bc44d2009-05-20 16:58:22 -04001375 }
Mike Lockwood63aa5a62010-04-14 19:21:31 -04001376 } else {
1377 Log.w(TAG, "sendExtraCommand: unknown command " + command);
Mike Lockwood93bc44d2009-05-20 16:58:22 -04001378 }
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001379
Mike Lockwood63aa5a62010-04-14 19:21:31 -04001380 Binder.restoreCallingIdentity(identity);
1381 return result;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001382 }
1383
Jaikumar Ganesh8ce470d2013-04-03 12:22:18 -07001384 private IGpsGeofenceHardware mGpsGeofenceBinder = new IGpsGeofenceHardware.Stub() {
1385 public boolean isHardwareGeofenceSupported() {
1386 return native_is_geofence_supported();
1387 }
1388
1389 public boolean addCircularHardwareGeofence(int geofenceId, double latitude,
1390 double longitude, double radius, int lastTransition, int monitorTransitions,
1391 int notificationResponsiveness, int unknownTimer) {
1392 return native_add_geofence(geofenceId, latitude, longitude, radius,
1393 lastTransition, monitorTransitions, notificationResponsiveness, unknownTimer);
1394 }
1395
1396 public boolean removeHardwareGeofence(int geofenceId) {
1397 return native_remove_geofence(geofenceId);
1398 }
1399
1400 public boolean pauseHardwareGeofence(int geofenceId) {
1401 return native_pause_geofence(geofenceId);
1402 }
1403
1404 public boolean resumeHardwareGeofence(int geofenceId, int monitorTransition) {
1405 return native_resume_geofence(geofenceId, monitorTransition);
1406 }
1407 };
1408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001409 private boolean deleteAidingData(Bundle extras) {
1410 int flags;
1411
1412 if (extras == null) {
1413 flags = GPS_DELETE_ALL;
1414 } else {
1415 flags = 0;
1416 if (extras.getBoolean("ephemeris")) flags |= GPS_DELETE_EPHEMERIS;
1417 if (extras.getBoolean("almanac")) flags |= GPS_DELETE_ALMANAC;
1418 if (extras.getBoolean("position")) flags |= GPS_DELETE_POSITION;
1419 if (extras.getBoolean("time")) flags |= GPS_DELETE_TIME;
1420 if (extras.getBoolean("iono")) flags |= GPS_DELETE_IONO;
1421 if (extras.getBoolean("utc")) flags |= GPS_DELETE_UTC;
1422 if (extras.getBoolean("health")) flags |= GPS_DELETE_HEALTH;
1423 if (extras.getBoolean("svdir")) flags |= GPS_DELETE_SVDIR;
1424 if (extras.getBoolean("svsteer")) flags |= GPS_DELETE_SVSTEER;
1425 if (extras.getBoolean("sadata")) flags |= GPS_DELETE_SADATA;
1426 if (extras.getBoolean("rti")) flags |= GPS_DELETE_RTI;
1427 if (extras.getBoolean("celldb-info")) flags |= GPS_DELETE_CELLDB_INFO;
1428 if (extras.getBoolean("all")) flags |= GPS_DELETE_ALL;
1429 }
1430
1431 if (flags != 0) {
1432 native_delete_aiding_data(flags);
1433 return true;
1434 }
1435
1436 return false;
1437 }
1438
Stan Chesnutt1d72d8c2013-04-15 19:18:02 -07001439 private void startNavigating(boolean singleShot) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001440 if (!mStarted) {
Stan Chesnutt1d72d8c2013-04-15 19:18:02 -07001441 if (DEBUG) Log.d(TAG, "startNavigating, singleShot is " + singleShot);
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001442 mTimeToFirstFix = 0;
1443 mLastFixTime = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001444 mStarted = true;
Stan Chesnutt1d72d8c2013-04-15 19:18:02 -07001445 mSingleShot = singleShot;
Mike Lockwood03ca2162010-04-01 08:10:09 -07001446 mPositionMode = GPS_POSITION_MODE_STANDALONE;
Wyatt Riley5d5bac82016-11-01 07:05:16 -07001447 // Notify about suppressed output, if speed limit was previously exceeded.
1448 // Elsewhere, we check again with every speed output reported.
1449 if (mItarSpeedLimitExceeded) {
1450 Log.i(TAG, "startNavigating with ITAR limit in place. Output limited " +
1451 "until slow enough speed reported.");
1452 }
Mike Lockwood03ca2162010-04-01 08:10:09 -07001453
Tsuwei Chen462bcd82014-09-17 12:28:49 -07001454 boolean agpsEnabled =
1455 (Settings.Global.getInt(mContext.getContentResolver(),
1456 Settings.Global.ASSISTED_GPS_ENABLED, 1) != 0);
1457 mPositionMode = getSuplMode(mProperties, agpsEnabled, singleShot);
Mike Lockwoodbcab8df2009-06-25 16:39:09 -04001458
Stan Chesnutt1d72d8c2013-04-15 19:18:02 -07001459 if (DEBUG) {
1460 String mode;
1461
1462 switch(mPositionMode) {
1463 case GPS_POSITION_MODE_STANDALONE:
1464 mode = "standalone";
1465 break;
1466 case GPS_POSITION_MODE_MS_ASSISTED:
1467 mode = "MS_ASSISTED";
1468 break;
1469 case GPS_POSITION_MODE_MS_BASED:
1470 mode = "MS_BASED";
1471 break;
1472 default:
1473 mode = "unknown";
1474 break;
1475 }
1476 Log.d(TAG, "setting position_mode to " + mode);
1477 }
1478
Mike Lockwood04598b62010-04-14 17:17:24 -04001479 int interval = (hasCapability(GPS_CAPABILITY_SCHEDULING) ? mFixInterval : 1000);
1480 if (!native_set_position_mode(mPositionMode, GPS_POSITION_RECURRENCE_PERIODIC,
1481 interval, 0, 0)) {
1482 mStarted = false;
1483 Log.e(TAG, "set_position_mode failed in startNavigating()");
1484 return;
1485 }
1486 if (!native_start()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001487 mStarted = false;
1488 Log.e(TAG, "native_start failed in startNavigating()");
Mike Lockwood0632ca72009-05-14 15:51:03 -04001489 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001490 }
1491
1492 // reset SV count to zero
Wyatt Rileyc9f25dd2017-05-05 13:45:23 -07001493 updateStatus(LocationProvider.TEMPORARILY_UNAVAILABLE, 0, 0, 0);
Yipeng Cao282b5942017-05-17 20:31:39 -07001494 mFixRequestTime = SystemClock.elapsedRealtime();
Mike Lockwood04598b62010-04-14 17:17:24 -04001495 if (!hasCapability(GPS_CAPABILITY_SCHEDULING)) {
1496 // set timer to give up if we do not receive a fix within NO_FIX_TIMEOUT
1497 // and our fix interval is not short
1498 if (mFixInterval >= NO_FIX_TIMEOUT) {
1499 mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
1500 SystemClock.elapsedRealtime() + NO_FIX_TIMEOUT, mTimeoutIntent);
1501 }
Mike Lockwood0632ca72009-05-14 15:51:03 -04001502 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001503 }
1504 }
1505
Mike Lockwood62a8fc12010-03-22 14:23:26 -04001506 private void stopNavigating() {
Mike Lockwood29c84342009-05-06 14:01:15 -04001507 if (DEBUG) Log.d(TAG, "stopNavigating");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001508 if (mStarted) {
1509 mStarted = false;
Stan Chesnutt1d72d8c2013-04-15 19:18:02 -07001510 mSingleShot = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001511 native_stop();
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001512 mTimeToFirstFix = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001513 mLastFixTime = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001514
1515 // reset SV count to zero
Wyatt Rileyc9f25dd2017-05-05 13:45:23 -07001516 updateStatus(LocationProvider.TEMPORARILY_UNAVAILABLE, 0, 0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001517 }
1518 }
1519
Mike Lockwood0632ca72009-05-14 15:51:03 -04001520 private void hibernate() {
1521 // stop GPS until our next fix interval arrives
1522 stopNavigating();
Mike Lockwood0632ca72009-05-14 15:51:03 -04001523 mAlarmManager.cancel(mTimeoutIntent);
1524 mAlarmManager.cancel(mWakeupIntent);
1525 long now = SystemClock.elapsedRealtime();
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001526 mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, now + mFixInterval, mWakeupIntent);
Mike Lockwood04598b62010-04-14 17:17:24 -04001527 }
1528
1529 private boolean hasCapability(int capability) {
1530 return ((mEngineCapabilities & capability) != 0);
Mike Lockwood0632ca72009-05-14 15:51:03 -04001531 }
1532
Jaikumar Ganesh8ce470d2013-04-03 12:22:18 -07001533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001534 /**
1535 * called from native code to update our position.
1536 */
Wyatt Riley5d229832017-02-10 17:06:00 -08001537 private void reportLocation(boolean hasLatLong, Location location) {
1538 if (location.hasSpeed()) {
1539 mItarSpeedLimitExceeded = location.getSpeed() > ITAR_SPEED_LIMIT_METERS_PER_SECOND;
Wyatt Riley5d5bac82016-11-01 07:05:16 -07001540 }
1541
1542 if (mItarSpeedLimitExceeded) {
1543 Log.i(TAG, "Hal reported a speed in excess of ITAR limit." +
1544 " GPS/GNSS Navigation output blocked.");
Siddharth Raybb608c82017-03-16 11:33:34 -07001545 mGnssMetrics.logReceivedLocationStatus(false);
Wyatt Riley5d5bac82016-11-01 07:05:16 -07001546 return; // No output of location allowed
1547 }
1548
Wyatt Riley5d229832017-02-10 17:06:00 -08001549 if (VERBOSE) Log.v(TAG, "reportLocation " + location.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001551 synchronized (mLocation) {
Wyatt Riley5d229832017-02-10 17:06:00 -08001552 mLocation = location;
1553 // It would be nice to push the elapsed real-time timestamp
1554 // further down the stack, but this is still useful
1555 mLocation.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
Sean Barbeauced2b2c2011-12-19 04:43:07 -05001556 mLocation.setExtras(mLocationExtras);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001557
Mike Lockwood15e3d0f2009-05-01 07:53:28 -04001558 try {
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001559 mILocationManager.reportLocation(mLocation, false);
Mike Lockwood15e3d0f2009-05-01 07:53:28 -04001560 } catch (RemoteException e) {
1561 Log.e(TAG, "RemoteException calling reportLocation");
1562 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001563 }
1564
Siddharth Raybb608c82017-03-16 11:33:34 -07001565 mGnssMetrics.logReceivedLocationStatus(hasLatLong);
1566 if (hasLatLong) {
1567 if (location.hasAccuracy()) {
1568 mGnssMetrics.logPositionAccuracyMeters(location.getAccuracy());
1569 }
1570 if (mTimeToFirstFix > 0) {
Yipeng Cao282b5942017-05-17 20:31:39 -07001571 int timeBetweenFixes = (int) (SystemClock.elapsedRealtime() - mLastFixTime);
Siddharth Raybb608c82017-03-16 11:33:34 -07001572 mGnssMetrics.logMissedReports(mFixInterval, timeBetweenFixes);
1573 }
1574 }
1575
Yipeng Cao282b5942017-05-17 20:31:39 -07001576 mLastFixTime = SystemClock.elapsedRealtime();
Hakan Gustavssonfa94ff02010-02-23 09:12:38 +01001577 // report time to first fix
Wyatt Riley5d229832017-02-10 17:06:00 -08001578 if (mTimeToFirstFix == 0 && hasLatLong) {
Nick Pelly6fa9ad42012-07-16 12:18:23 -07001579 mTimeToFirstFix = (int)(mLastFixTime - mFixRequestTime);
1580 if (DEBUG) Log.d(TAG, "TTFF: " + mTimeToFirstFix);
Siddharth Raybb608c82017-03-16 11:33:34 -07001581 mGnssMetrics.logTimeToFirstFixMilliSecs(mTimeToFirstFix);
Hakan Gustavssonfa94ff02010-02-23 09:12:38 +01001582
1583 // notify status listeners
destradaaea8a8a62014-06-23 18:19:03 -07001584 mListenerHelper.onFirstFix(mTimeToFirstFix);
Hakan Gustavssonfa94ff02010-02-23 09:12:38 +01001585 }
1586
Stan Chesnutt1d72d8c2013-04-15 19:18:02 -07001587 if (mSingleShot) {
1588 stopNavigating();
1589 }
1590
Mike Lockwood15e3d0f2009-05-01 07:53:28 -04001591 if (mStarted && mStatus != LocationProvider.AVAILABLE) {
Mike Lockwoodd53ba012010-04-15 20:41:26 -04001592 // we want to time out if we do not receive a fix
Mike Lockwoodb7be5442010-02-24 14:34:50 -05001593 // within the time out and we are requesting infrequent fixes
Mike Lockwood04598b62010-04-14 17:17:24 -04001594 if (!hasCapability(GPS_CAPABILITY_SCHEDULING) && mFixInterval < NO_FIX_TIMEOUT) {
Mike Lockwoodb7be5442010-02-24 14:34:50 -05001595 mAlarmManager.cancel(mTimeoutIntent);
1596 }
1597
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001598 // send an intent to notify that the GPS is receiving fixes.
Mike Lockwood00b74272010-03-26 10:41:48 -04001599 Intent intent = new Intent(LocationManager.GPS_FIX_CHANGE_ACTION);
1600 intent.putExtra(LocationManager.EXTRA_GPS_ENABLED, true);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001601 mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
Wyatt Rileyc9f25dd2017-05-05 13:45:23 -07001602 updateStatus(LocationProvider.AVAILABLE, mSvCount, mMeanCn0, mMaxCn0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001603 }
Mike Lockwood29c84342009-05-06 14:01:15 -04001604
Nick Pellyb041f232012-05-07 17:12:25 -07001605 if (!hasCapability(GPS_CAPABILITY_SCHEDULING) && mStarted &&
1606 mFixInterval > GPS_POLLING_THRESHOLD_INTERVAL) {
Mike Lockwoodd53ba012010-04-15 20:41:26 -04001607 if (DEBUG) Log.d(TAG, "got fix, hibernating");
Mike Lockwood0632ca72009-05-14 15:51:03 -04001608 hibernate();
Mike Lockwood29c84342009-05-06 14:01:15 -04001609 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001610 }
1611
1612 /**
1613 * called from native code to update our status
1614 */
1615 private void reportStatus(int status) {
Mike Lockwoodb8d90332010-10-18 17:59:48 -04001616 if (DEBUG) Log.v(TAG, "reportStatus status: " + status);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001617
destradaaea8a8a62014-06-23 18:19:03 -07001618 boolean wasNavigating = mNavigating;
1619 switch (status) {
1620 case GPS_STATUS_SESSION_BEGIN:
1621 mNavigating = true;
1622 mEngineOn = true;
1623 break;
1624 case GPS_STATUS_SESSION_END:
1625 mNavigating = false;
1626 break;
1627 case GPS_STATUS_ENGINE_ON:
1628 mEngineOn = true;
1629 break;
1630 case GPS_STATUS_ENGINE_OFF:
1631 mEngineOn = false;
1632 mNavigating = false;
1633 break;
1634 }
Mike Lockwooddbd6fd82009-12-07 18:43:36 -05001635
destradaaea8a8a62014-06-23 18:19:03 -07001636 if (wasNavigating != mNavigating) {
destradaa13a60b02015-01-15 18:36:01 -08001637 mListenerHelper.onStatusChanged(mNavigating);
Mike Lockwoodcf1d8cb2010-01-20 10:14:54 -05001638
destradaaea8a8a62014-06-23 18:19:03 -07001639 // send an intent to notify that the GPS has been enabled or disabled
1640 Intent intent = new Intent(LocationManager.GPS_ENABLED_CHANGE_ACTION);
1641 intent.putExtra(LocationManager.EXTRA_GPS_ENABLED, mNavigating);
1642 mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001643 }
1644 }
1645
1646 /**
1647 * called from native code to update SV info
1648 */
1649 private void reportSvStatus() {
gomo4402af62017-01-11 13:20:13 -08001650 int svCount = native_read_sv_status(mSvidWithFlags,
1651 mCn0s,
1652 mSvElevations,
1653 mSvAzimuths,
1654 mSvCarrierFreqs);
destradaaea8a8a62014-06-23 18:19:03 -07001655 mListenerHelper.onSvStatusChanged(
1656 svCount,
Lifu Tang120480f2016-02-07 18:08:19 -08001657 mSvidWithFlags,
Lifu Tang76a620f2016-02-26 19:53:01 -08001658 mCn0s,
destradaaea8a8a62014-06-23 18:19:03 -07001659 mSvElevations,
gomo4402af62017-01-11 13:20:13 -08001660 mSvAzimuths,
1661 mSvCarrierFreqs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001662
Siddharth Ray168f12a2017-07-10 11:55:10 -07001663 // Log CN0 as part of GNSS metrics
1664 mGnssMetrics.logCn0(mCn0s, svCount);
1665
Mike Lockwood29c84342009-05-06 14:01:15 -04001666 if (VERBOSE) {
Lifu Tang30f95a72016-01-07 23:20:38 -08001667 Log.v(TAG, "SV count: " + svCount);
1668 }
Wyatt Rileyc9f25dd2017-05-05 13:45:23 -07001669 // Calculate number of satellites used in fix.
Lifu Tang30f95a72016-01-07 23:20:38 -08001670 int usedInFixCount = 0;
Wyatt Rileyc9f25dd2017-05-05 13:45:23 -07001671 int maxCn0 = 0;
1672 int meanCn0 = 0;
Lifu Tang30f95a72016-01-07 23:20:38 -08001673 for (int i = 0; i < svCount; i++) {
Lifu Tang120480f2016-02-07 18:08:19 -08001674 if ((mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_USED_IN_FIX) != 0) {
Lifu Tang30f95a72016-01-07 23:20:38 -08001675 ++usedInFixCount;
Wyatt Rileyc9f25dd2017-05-05 13:45:23 -07001676 if (mCn0s[i] > maxCn0) {
1677 maxCn0 = (int)mCn0s[i];
1678 }
1679 meanCn0 += mCn0s[i];
Lifu Tang30f95a72016-01-07 23:20:38 -08001680 }
1681 if (VERBOSE) {
Lifu Tang120480f2016-02-07 18:08:19 -08001682 Log.v(TAG, "svid: " + (mSvidWithFlags[i] >> GnssStatus.SVID_SHIFT_WIDTH) +
Wyatt Rileyc9f25dd2017-05-05 13:45:23 -07001683 " cn0: " + mCn0s[i] +
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001684 " elev: " + mSvElevations[i] +
1685 " azimuth: " + mSvAzimuths[i] +
gomo4402af62017-01-11 13:20:13 -08001686 " carrier frequency: " + mSvCarrierFreqs[i] +
Lifu Tang120480f2016-02-07 18:08:19 -08001687 ((mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_HAS_EPHEMERIS_DATA) == 0
Lifu Tang30f95a72016-01-07 23:20:38 -08001688 ? " " : " E") +
Lifu Tang120480f2016-02-07 18:08:19 -08001689 ((mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_HAS_ALMANAC_DATA) == 0
Lifu Tang30f95a72016-01-07 23:20:38 -08001690 ? " " : " A") +
Lifu Tang120480f2016-02-07 18:08:19 -08001691 ((mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_USED_IN_FIX) == 0
gomo4402af62017-01-11 13:20:13 -08001692 ? "" : "U") +
1693 ((mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_HAS_CARRIER_FREQUENCY) == 0
1694 ? "" : "F"));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001695 }
1696 }
Wyatt Rileyc9f25dd2017-05-05 13:45:23 -07001697 if (usedInFixCount > 0) {
1698 meanCn0 /= usedInFixCount;
1699 }
1700 // return number of sats used in fix instead of total reported
1701 updateStatus(mStatus, usedInFixCount, meanCn0, maxCn0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001702
Mike Lockwood15e3d0f2009-05-01 07:53:28 -04001703 if (mNavigating && mStatus == LocationProvider.AVAILABLE && mLastFixTime > 0 &&
Yipeng Cao282b5942017-05-17 20:31:39 -07001704 SystemClock.elapsedRealtime() - mLastFixTime > RECENT_FIX_TIMEOUT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001705 // send an intent to notify that the GPS is no longer receiving fixes.
Mike Lockwood00b74272010-03-26 10:41:48 -04001706 Intent intent = new Intent(LocationManager.GPS_FIX_CHANGE_ACTION);
1707 intent.putExtra(LocationManager.EXTRA_GPS_ENABLED, false);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001708 mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
Wyatt Rileyc9f25dd2017-05-05 13:45:23 -07001709 updateStatus(LocationProvider.TEMPORARILY_UNAVAILABLE, mSvCount, mMeanCn0, mMaxCn0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001710 }
1711 }
Mike Lockwood58bda982009-04-14 16:25:07 -04001712
1713 /**
Mike Lockwoode3635c92009-05-11 08:38:02 -04001714 * called from native code to update AGPS status
Mike Lockwood58bda982009-04-14 16:25:07 -04001715 */
destradaa96a14702014-06-05 11:36:30 -07001716 private void reportAGpsStatus(int type, int status, byte[] ipaddr) {
Mike Lockwood58bda982009-04-14 16:25:07 -04001717 switch (status) {
Mike Lockwoode3635c92009-05-11 08:38:02 -04001718 case GPS_REQUEST_AGPS_DATA_CONN:
Mike Lockwoodb6e5fa82010-10-09 20:10:46 -04001719 if (DEBUG) Log.d(TAG, "GPS_REQUEST_AGPS_DATA_CONN");
Andreas Gampee6748ce2015-12-11 18:00:38 -08001720 Log.v(TAG, "Received SUPL IP addr[]: " + Arrays.toString(ipaddr));
destradaae21252a2015-09-08 12:32:59 -07001721 InetAddress connectionIpAddress = null;
destradaa96a14702014-06-05 11:36:30 -07001722 if (ipaddr != null) {
1723 try {
destradaae21252a2015-09-08 12:32:59 -07001724 connectionIpAddress = InetAddress.getByAddress(ipaddr);
1725 if (DEBUG) Log.d(TAG, "IP address converted to: " + connectionIpAddress);
destradaa96a14702014-06-05 11:36:30 -07001726 } catch (UnknownHostException e) {
1727 Log.e(TAG, "Bad IP Address: " + ipaddr, e);
destradaa96a14702014-06-05 11:36:30 -07001728 }
1729 }
destradaae21252a2015-09-08 12:32:59 -07001730 sendMessage(REQUEST_SUPL_CONNECTION, 0 /*arg*/, connectionIpAddress);
Mike Lockwood58bda982009-04-14 16:25:07 -04001731 break;
Mike Lockwoode3635c92009-05-11 08:38:02 -04001732 case GPS_RELEASE_AGPS_DATA_CONN:
Mike Lockwoodb6e5fa82010-10-09 20:10:46 -04001733 if (DEBUG) Log.d(TAG, "GPS_RELEASE_AGPS_DATA_CONN");
destradaae21252a2015-09-08 12:32:59 -07001734 releaseSuplConnection(GPS_RELEASE_AGPS_DATA_CONN);
Mike Lockwood58bda982009-04-14 16:25:07 -04001735 break;
Mike Lockwoode3635c92009-05-11 08:38:02 -04001736 case GPS_AGPS_DATA_CONNECTED:
Mike Lockwoodb6e5fa82010-10-09 20:10:46 -04001737 if (DEBUG) Log.d(TAG, "GPS_AGPS_DATA_CONNECTED");
Mike Lockwood58bda982009-04-14 16:25:07 -04001738 break;
Mike Lockwoode3635c92009-05-11 08:38:02 -04001739 case GPS_AGPS_DATA_CONN_DONE:
Mike Lockwoodb6e5fa82010-10-09 20:10:46 -04001740 if (DEBUG) Log.d(TAG, "GPS_AGPS_DATA_CONN_DONE");
Mike Lockwood58bda982009-04-14 16:25:07 -04001741 break;
Mike Lockwoode3635c92009-05-11 08:38:02 -04001742 case GPS_AGPS_DATA_CONN_FAILED:
Mike Lockwoodb6e5fa82010-10-09 20:10:46 -04001743 if (DEBUG) Log.d(TAG, "GPS_AGPS_DATA_CONN_FAILED");
Mike Lockwood58bda982009-04-14 16:25:07 -04001744 break;
destradaa931a37f2014-08-12 16:36:59 -07001745 default:
Joe Onorato0c484102016-02-01 18:04:24 -08001746 if (DEBUG) Log.d(TAG, "Received Unknown AGPS status: " + status);
Mike Lockwood58bda982009-04-14 16:25:07 -04001747 }
1748 }
1749
destradaae21252a2015-09-08 12:32:59 -07001750 private void releaseSuplConnection(int connStatus) {
1751 sendMessage(RELEASE_SUPL_CONNECTION, connStatus, null /*obj*/);
1752 }
1753
Mike Lockwoodb16e7802009-08-06 09:26:02 -04001754 /**
1755 * called from native code to report NMEA data received
1756 */
Mike Lockwoodf602d362010-06-20 14:28:16 -07001757 private void reportNmea(long timestamp) {
Wyatt Riley5d5bac82016-11-01 07:05:16 -07001758 if (!mItarSpeedLimitExceeded) {
1759 int length = native_read_nmea(mNmeaBuffer, mNmeaBuffer.length);
1760 String nmea = new String(mNmeaBuffer, 0 /* offset */, length);
1761 mListenerHelper.onNmeaReceived(timestamp, nmea);
1762 }
destradaaea8a8a62014-06-23 18:19:03 -07001763 }
Mike Lockwoodb16e7802009-08-06 09:26:02 -04001764
destradaaea8a8a62014-06-23 18:19:03 -07001765 /**
Wyatt Rileyaa420d52017-07-03 15:14:42 -07001766 * called from native code - GNSS measurements callback
destradaaea8a8a62014-06-23 18:19:03 -07001767 */
Lifu Tang818aa2c2016-02-01 01:52:00 -08001768 private void reportMeasurementData(GnssMeasurementsEvent event) {
Wyatt Riley5d5bac82016-11-01 07:05:16 -07001769 if (!mItarSpeedLimitExceeded) {
Wyatt Rileyaa420d52017-07-03 15:14:42 -07001770 // send to handler to allow native to return quickly
1771 mHandler.post(new Runnable() {
1772 @Override
1773 public void run() {
1774 mGnssMeasurementsProvider.onMeasurementsAvailable(event);
1775 }
1776 });
Wyatt Riley5d5bac82016-11-01 07:05:16 -07001777 }
Mike Lockwoodb16e7802009-08-06 09:26:02 -04001778 }
1779
Mike Lockwood62a8fc12010-03-22 14:23:26 -04001780 /**
Wyatt Rileyaa420d52017-07-03 15:14:42 -07001781 * called from native code - GNSS navigation message callback
destradaa4b3e3932014-07-21 18:01:47 -07001782 */
Lifu Tange8abe8e2016-04-01 10:32:05 -07001783 private void reportNavigationMessage(GnssNavigationMessage event) {
Wyatt Riley5d5bac82016-11-01 07:05:16 -07001784 if (!mItarSpeedLimitExceeded) {
Wyatt Rileyaa420d52017-07-03 15:14:42 -07001785 // send to handler to allow native to return quickly
1786 mHandler.post(new Runnable() {
1787 @Override
1788 public void run() {
1789 mGnssNavigationMessageProvider.onNavigationMessageAvailable(event);
1790 }
1791 });
Wyatt Riley5d5bac82016-11-01 07:05:16 -07001792 }
destradaa4b3e3932014-07-21 18:01:47 -07001793 }
1794
1795 /**
Mike Lockwood04598b62010-04-14 17:17:24 -04001796 * called from native code to inform us what the GPS engine capabilities are
1797 */
1798 private void setEngineCapabilities(int capabilities) {
1799 mEngineCapabilities = capabilities;
Mike Lockwood9b9fb5c2011-06-29 15:09:40 -04001800
destradaa56b47f82015-07-24 10:56:18 -07001801 if (hasCapability(GPS_CAPABILITY_ON_DEMAND_TIME)) {
1802 mOnDemandTimeInjection = true;
Mike Lockwood9b9fb5c2011-06-29 15:09:40 -04001803 requestUtcTime();
1804 }
destradaa6568d702014-10-27 12:47:41 -07001805
Lifu Tang818aa2c2016-02-01 01:52:00 -08001806 mGnssMeasurementsProvider.onCapabilitiesUpdated(
destradaa6568d702014-10-27 12:47:41 -07001807 (capabilities & GPS_CAPABILITY_MEASUREMENTS) == GPS_CAPABILITY_MEASUREMENTS);
Lifu Tang818aa2c2016-02-01 01:52:00 -08001808 mGnssNavigationMessageProvider.onCapabilitiesUpdated(
destradaa6568d702014-10-27 12:47:41 -07001809 (capabilities & GPS_CAPABILITY_NAV_MESSAGES) == GPS_CAPABILITY_NAV_MESSAGES);
Mike Lockwood04598b62010-04-14 17:17:24 -04001810 }
1811
1812 /**
Lifu Tang82f893d2016-01-21 18:15:33 -08001813 * Called from native code to inform us the hardware information.
1814 */
Lifu Tang9363b942016-02-16 18:07:00 -08001815 private void setGnssYearOfHardware(int yearOfHardware) {
1816 if (DEBUG) Log.d(TAG, "setGnssYearOfHardware called with " + yearOfHardware);
Lifu Tang82f893d2016-01-21 18:15:33 -08001817 mYearOfHardware = yearOfHardware;
1818 }
1819
Lifu Tang9363b942016-02-16 18:07:00 -08001820 public interface GnssSystemInfoProvider {
Lifu Tang82f893d2016-01-21 18:15:33 -08001821 /**
1822 * Returns the year of GPS hardware.
1823 */
Lifu Tang9363b942016-02-16 18:07:00 -08001824 int getGnssYearOfHardware();
Lifu Tang82f893d2016-01-21 18:15:33 -08001825 }
1826
1827 /**
1828 * @hide
1829 */
Lifu Tang9363b942016-02-16 18:07:00 -08001830 public GnssSystemInfoProvider getGnssSystemInfoProvider() {
1831 return new GnssSystemInfoProvider() {
Lifu Tang82f893d2016-01-21 18:15:33 -08001832 @Override
Lifu Tang9363b942016-02-16 18:07:00 -08001833 public int getGnssYearOfHardware() {
Lifu Tang82f893d2016-01-21 18:15:33 -08001834 return mYearOfHardware;
1835 }
1836 };
1837 }
1838
Wyatt Rileycf879db2017-01-12 13:57:38 -08001839 public interface GnssBatchingProvider {
1840 /**
1841 * Returns the GNSS batching size
1842 */
1843 int getSize();
1844 /**
1845 * Starts the hardware batching operation
1846 */
1847 boolean start(long periodNanos, boolean wakeOnFifoFull);
1848 /**
1849 * Forces a flush of existing locations from the hardware batching
1850 */
1851 void flush();
1852 /**
1853 * Stops the batching operation
1854 */
1855 boolean stop();
1856 }
1857
1858 /**
1859 * @hide
1860 */
1861 public GnssBatchingProvider getGnssBatchingProvider() {
1862 return new GnssBatchingProvider() {
1863 @Override
1864 public int getSize() {
1865 return native_get_batch_size();
1866 }
1867 @Override
1868 public boolean start(long periodNanos, boolean wakeOnFifoFull) {
1869 if (periodNanos <= 0) {
1870 Log.e(TAG, "Invalid periodNanos " + periodNanos +
1871 "in batching request, not started");
1872 return false;
1873 }
1874 return native_start_batch(periodNanos, wakeOnFifoFull);
1875 }
1876 @Override
1877 public void flush() {
1878 native_flush_batch();
1879 }
1880 @Override
1881 public boolean stop() {
1882 return native_stop_batch();
1883 }
1884 };
1885 }
1886
Siddharth Raybb608c82017-03-16 11:33:34 -07001887 public interface GnssMetricsProvider {
1888 /**
1889 * Returns GNSS metrics as proto string
1890 */
1891 String getGnssMetricsAsProtoString();
1892 }
1893
1894 /**
1895 * @hide
1896 */
1897 public GnssMetricsProvider getGnssMetricsProvider() {
1898 return new GnssMetricsProvider() {
1899 @Override
1900 public String getGnssMetricsAsProtoString() {
1901 return mGnssMetrics.dumpGnssMetricsAsProtoString();
1902 }
1903 };
1904 }
1905
Wyatt Rileycf879db2017-01-12 13:57:38 -08001906 /**
1907 * Initialize Batching if enabled
1908 */
1909 private void enableBatching() {
1910 if (!native_init_batching()) {
1911 Log.e(TAG, "Failed to initialize GNSS batching");
1912 };
1913 }
1914
1915 /**
1916 * Disable batching
1917 */
1918 private void disableBatching() {
1919 native_stop_batch();
1920 native_cleanup_batching();
1921 }
1922
1923 /**
1924 * called from native code - GNSS location batch callback
1925 */
1926 private void reportLocationBatch(Location[] locationArray) {
1927 List<Location> locations = new ArrayList<>(Arrays.asList(locationArray));
1928 if(DEBUG) { Log.d(TAG, "Location batch of size " + locationArray.length + "reported"); }
1929 try {
1930 mILocationManager.reportLocationBatch(locations);
1931 } catch (RemoteException e) {
1932 Log.e(TAG, "RemoteException calling reportLocationBatch");
1933 }
1934 }
1935
Lifu Tang82f893d2016-01-21 18:15:33 -08001936 /**
Mike Lockwood62a8fc12010-03-22 14:23:26 -04001937 * called from native code to request XTRA data
1938 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001939 private void xtraDownloadRequest() {
Joe Onoratof5d95cb2010-01-07 21:48:32 -05001940 if (DEBUG) Log.d(TAG, "xtraDownloadRequest");
Mike Lockwood98e48692010-04-07 16:32:51 -04001941 sendMessage(DOWNLOAD_XTRA_DATA, 0, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001942 }
1943
Jaikumar Ganesh8ce470d2013-04-03 12:22:18 -07001944 /**
destradaa0682809a2013-08-12 18:50:30 -07001945 * Converts the GPS HAL status to the internal Geofence Hardware status.
1946 */
1947 private int getGeofenceStatus(int status) {
1948 switch(status) {
1949 case GPS_GEOFENCE_OPERATION_SUCCESS:
1950 return GeofenceHardware.GEOFENCE_SUCCESS;
1951 case GPS_GEOFENCE_ERROR_GENERIC:
1952 return GeofenceHardware.GEOFENCE_FAILURE;
1953 case GPS_GEOFENCE_ERROR_ID_EXISTS:
1954 return GeofenceHardware.GEOFENCE_ERROR_ID_EXISTS;
1955 case GPS_GEOFENCE_ERROR_INVALID_TRANSITION:
1956 return GeofenceHardware.GEOFENCE_ERROR_INVALID_TRANSITION;
1957 case GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES:
1958 return GeofenceHardware.GEOFENCE_ERROR_TOO_MANY_GEOFENCES;
1959 case GPS_GEOFENCE_ERROR_ID_UNKNOWN:
1960 return GeofenceHardware.GEOFENCE_ERROR_ID_UNKNOWN;
1961 default:
1962 return -1;
1963 }
1964 }
1965
1966 /**
Jaikumar Ganesh8ce470d2013-04-03 12:22:18 -07001967 * Called from native to report GPS Geofence transition
1968 * All geofence callbacks are called on the same thread
1969 */
Wyatt Riley5d229832017-02-10 17:06:00 -08001970 private void reportGeofenceTransition(int geofenceId, Location location, int transition,
1971 long transitionTimestamp) {
Jaikumar Ganesh8ce470d2013-04-03 12:22:18 -07001972 if (mGeofenceHardwareImpl == null) {
1973 mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext);
1974 }
Wyatt Riley5d229832017-02-10 17:06:00 -08001975
destradaa0682809a2013-08-12 18:50:30 -07001976 mGeofenceHardwareImpl.reportGeofenceTransition(
1977 geofenceId,
1978 location,
1979 transition,
1980 transitionTimestamp,
1981 GeofenceHardware.MONITORING_TYPE_GPS_HARDWARE,
1982 FusedBatchOptions.SourceTechnologies.GNSS);
Jaikumar Ganesh8ce470d2013-04-03 12:22:18 -07001983 }
1984
1985 /**
1986 * called from native code to report GPS status change.
1987 */
Wyatt Riley5d229832017-02-10 17:06:00 -08001988 private void reportGeofenceStatus(int status, Location location) {
Jaikumar Ganesh8ce470d2013-04-03 12:22:18 -07001989 if (mGeofenceHardwareImpl == null) {
1990 mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext);
1991 }
destradaa0682809a2013-08-12 18:50:30 -07001992 int monitorStatus = GeofenceHardware.MONITOR_CURRENTLY_UNAVAILABLE;
1993 if(status == GPS_GEOFENCE_AVAILABLE) {
1994 monitorStatus = GeofenceHardware.MONITOR_CURRENTLY_AVAILABLE;
1995 }
1996 mGeofenceHardwareImpl.reportGeofenceMonitorStatus(
1997 GeofenceHardware.MONITORING_TYPE_GPS_HARDWARE,
1998 monitorStatus,
1999 location,
2000 FusedBatchOptions.SourceTechnologies.GNSS);
Jaikumar Ganesh8ce470d2013-04-03 12:22:18 -07002001 }
2002
2003 /**
2004 * called from native code - Geofence Add callback
2005 */
2006 private void reportGeofenceAddStatus(int geofenceId, int status) {
2007 if (mGeofenceHardwareImpl == null) {
2008 mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext);
2009 }
destradaa0682809a2013-08-12 18:50:30 -07002010 mGeofenceHardwareImpl.reportGeofenceAddStatus(geofenceId, getGeofenceStatus(status));
Jaikumar Ganesh8ce470d2013-04-03 12:22:18 -07002011 }
2012
2013 /**
2014 * called from native code - Geofence Remove callback
2015 */
2016 private void reportGeofenceRemoveStatus(int geofenceId, int status) {
2017 if (mGeofenceHardwareImpl == null) {
2018 mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext);
2019 }
destradaa0682809a2013-08-12 18:50:30 -07002020 mGeofenceHardwareImpl.reportGeofenceRemoveStatus(geofenceId, getGeofenceStatus(status));
Jaikumar Ganesh8ce470d2013-04-03 12:22:18 -07002021 }
2022
2023 /**
2024 * called from native code - Geofence Pause callback
2025 */
2026 private void reportGeofencePauseStatus(int geofenceId, int status) {
2027 if (mGeofenceHardwareImpl == null) {
2028 mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext);
2029 }
destradaa0682809a2013-08-12 18:50:30 -07002030 mGeofenceHardwareImpl.reportGeofencePauseStatus(geofenceId, getGeofenceStatus(status));
Jaikumar Ganesh8ce470d2013-04-03 12:22:18 -07002031 }
2032
2033 /**
2034 * called from native code - Geofence Resume callback
2035 */
2036 private void reportGeofenceResumeStatus(int geofenceId, int status) {
2037 if (mGeofenceHardwareImpl == null) {
2038 mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext);
2039 }
destradaa0682809a2013-08-12 18:50:30 -07002040 mGeofenceHardwareImpl.reportGeofenceResumeStatus(geofenceId, getGeofenceStatus(status));
Jaikumar Ganesh8ce470d2013-04-03 12:22:18 -07002041 }
2042
Danke Xie22d1f9f2009-08-18 18:28:45 -04002043 //=============================================================
2044 // NI Client support
Miguel Torroja1e84da82010-07-27 07:02:24 +02002045 //=============================================================
Danke Xie22d1f9f2009-08-18 18:28:45 -04002046 private final INetInitiatedListener mNetInitiatedListener = new INetInitiatedListener.Stub() {
destradaaef752b62015-04-17 13:10:47 -07002047 // Sends a response for an NI request to HAL.
Nick Pelly6fa9ad42012-07-16 12:18:23 -07002048 @Override
Miguel Torroja1e84da82010-07-27 07:02:24 +02002049 public boolean sendNiResponse(int notificationId, int userResponse)
2050 {
2051 // TODO Add Permission check
Danke Xie22d1f9f2009-08-18 18:28:45 -04002052
Miguel Torroja1e84da82010-07-27 07:02:24 +02002053 if (DEBUG) Log.d(TAG, "sendNiResponse, notifId: " + notificationId +
2054 ", response: " + userResponse);
2055 native_send_ni_response(notificationId, userResponse);
2056 return true;
2057 }
Danke Xie22d1f9f2009-08-18 18:28:45 -04002058 };
Nick Pelly6fa9ad42012-07-16 12:18:23 -07002059
Danke Xie22d1f9f2009-08-18 18:28:45 -04002060 public INetInitiatedListener getNetInitiatedListener() {
2061 return mNetInitiatedListener;
2062 }
2063
2064 // Called by JNI function to report an NI request.
Miguel Torroja1e84da82010-07-27 07:02:24 +02002065 public void reportNiNotification(
2066 int notificationId,
2067 int niType,
2068 int notifyFlags,
2069 int timeout,
2070 int defaultResponse,
2071 String requestorId,
2072 String text,
2073 int requestorIdEncoding,
Hridya Valsaraju2ea29602016-09-13 08:38:09 -07002074 int textEncoding
Danke Xie22d1f9f2009-08-18 18:28:45 -04002075 )
Miguel Torroja1e84da82010-07-27 07:02:24 +02002076 {
2077 Log.i(TAG, "reportNiNotification: entered");
2078 Log.i(TAG, "notificationId: " + notificationId +
2079 ", niType: " + niType +
2080 ", notifyFlags: " + notifyFlags +
2081 ", timeout: " + timeout +
2082 ", defaultResponse: " + defaultResponse);
2083
2084 Log.i(TAG, "requestorId: " + requestorId +
2085 ", text: " + text +
2086 ", requestorIdEncoding: " + requestorIdEncoding +
2087 ", textEncoding: " + textEncoding);
2088
2089 GpsNiNotification notification = new GpsNiNotification();
2090
2091 notification.notificationId = notificationId;
2092 notification.niType = niType;
2093 notification.needNotify = (notifyFlags & GpsNetInitiatedHandler.GPS_NI_NEED_NOTIFY) != 0;
2094 notification.needVerify = (notifyFlags & GpsNetInitiatedHandler.GPS_NI_NEED_VERIFY) != 0;
2095 notification.privacyOverride = (notifyFlags & GpsNetInitiatedHandler.GPS_NI_PRIVACY_OVERRIDE) != 0;
2096 notification.timeout = timeout;
2097 notification.defaultResponse = defaultResponse;
2098 notification.requestorId = requestorId;
2099 notification.text = text;
2100 notification.requestorIdEncoding = requestorIdEncoding;
2101 notification.textEncoding = textEncoding;
2102
Miguel Torroja1e84da82010-07-27 07:02:24 +02002103 mNIHandler.handleNiNotification(notification);
2104 }
2105
2106 /**
2107 * Called from native code to request set id info.
2108 * We should be careful about receiving null string from the TelephonyManager,
2109 * because sending null String to JNI function would cause a crash.
2110 */
2111
2112 private void requestSetID(int flags) {
2113 TelephonyManager phone = (TelephonyManager)
2114 mContext.getSystemService(Context.TELEPHONY_SERVICE);
destradaaef752b62015-04-17 13:10:47 -07002115 int type = AGPS_SETID_TYPE_NONE;
Miguel Torroja1e84da82010-07-27 07:02:24 +02002116 String data = "";
2117
2118 if ((flags & AGPS_RIL_REQUEST_SETID_IMSI) == AGPS_RIL_REQUEST_SETID_IMSI) {
2119 String data_temp = phone.getSubscriberId();
2120 if (data_temp == null) {
2121 // This means the framework does not have the SIM card ready.
2122 } else {
2123 // This means the framework has the SIM card.
2124 data = data_temp;
2125 type = AGPS_SETID_TYPE_IMSI;
2126 }
2127 }
2128 else if ((flags & AGPS_RIL_REQUEST_SETID_MSISDN) == AGPS_RIL_REQUEST_SETID_MSISDN) {
2129 String data_temp = phone.getLine1Number();
2130 if (data_temp == null) {
2131 // This means the framework does not have the SIM card ready.
2132 } else {
2133 // This means the framework has the SIM card.
2134 data = data_temp;
2135 type = AGPS_SETID_TYPE_MSISDN;
2136 }
2137 }
2138 native_agps_set_id(type, data);
2139 }
2140
2141 /**
Mike Lockwood9b9fb5c2011-06-29 15:09:40 -04002142 * Called from native code to request utc time info
2143 */
Mike Lockwood9b9fb5c2011-06-29 15:09:40 -04002144 private void requestUtcTime() {
destradaae21252a2015-09-08 12:32:59 -07002145 if (DEBUG) Log.d(TAG, "utcTimeRequest");
Mike Lockwood9b9fb5c2011-06-29 15:09:40 -04002146 sendMessage(INJECT_NTP_TIME, 0, null);
2147 }
2148
2149 /**
Miguel Torroja1e84da82010-07-27 07:02:24 +02002150 * Called from native code to request reference location info
2151 */
2152
Hridya Valsaraju2ea29602016-09-13 08:38:09 -07002153 private void requestRefLocation() {
Miguel Torroja1e84da82010-07-27 07:02:24 +02002154 TelephonyManager phone = (TelephonyManager)
2155 mContext.getSystemService(Context.TELEPHONY_SERVICE);
Victoria Leased50d0c32012-10-29 13:16:17 -07002156 final int phoneType = phone.getPhoneType();
2157 if (phoneType == TelephonyManager.PHONE_TYPE_GSM) {
Miguel Torroja1e84da82010-07-27 07:02:24 +02002158 GsmCellLocation gsm_cell = (GsmCellLocation) phone.getCellLocation();
Victoria Leased50d0c32012-10-29 13:16:17 -07002159 if ((gsm_cell != null) && (phone.getNetworkOperator() != null)
2160 && (phone.getNetworkOperator().length() > 3)) {
Miguel Torroja1e84da82010-07-27 07:02:24 +02002161 int type;
2162 int mcc = Integer.parseInt(phone.getNetworkOperator().substring(0,3));
2163 int mnc = Integer.parseInt(phone.getNetworkOperator().substring(3));
Mike Lockwoodedc0f3872010-10-22 09:16:17 -04002164 int networkType = phone.getNetworkType();
2165 if (networkType == TelephonyManager.NETWORK_TYPE_UMTS
2166 || networkType == TelephonyManager.NETWORK_TYPE_HSDPA
2167 || networkType == TelephonyManager.NETWORK_TYPE_HSUPA
Arun Ravindran58d46122012-07-30 17:50:21 +03002168 || networkType == TelephonyManager.NETWORK_TYPE_HSPA
2169 || networkType == TelephonyManager.NETWORK_TYPE_HSPAP) {
Miguel Torroja1e84da82010-07-27 07:02:24 +02002170 type = AGPS_REF_LOCATION_TYPE_UMTS_CELLID;
Mike Lockwoodedc0f3872010-10-22 09:16:17 -04002171 } else {
Miguel Torroja1e84da82010-07-27 07:02:24 +02002172 type = AGPS_REF_LOCATION_TYPE_GSM_CELLID;
Mike Lockwoodedc0f3872010-10-22 09:16:17 -04002173 }
Miguel Torroja1e84da82010-07-27 07:02:24 +02002174 native_agps_set_ref_location_cellid(type, mcc, mnc,
2175 gsm_cell.getLac(), gsm_cell.getCid());
Mike Lockwoodedc0f3872010-10-22 09:16:17 -04002176 } else {
Miguel Torroja1e84da82010-07-27 07:02:24 +02002177 Log.e(TAG,"Error getting cell location info.");
Mike Lockwoodedc0f3872010-10-22 09:16:17 -04002178 }
Victoria Leased50d0c32012-10-29 13:16:17 -07002179 } else if (phoneType == TelephonyManager.PHONE_TYPE_CDMA) {
2180 Log.e(TAG, "CDMA not supported.");
Mike Lockwoodedc0f3872010-10-22 09:16:17 -04002181 }
Miguel Torroja1e84da82010-07-27 07:02:24 +02002182 }
Danke Xie22d1f9f2009-08-18 18:28:45 -04002183
Mike Lockwood98e48692010-04-07 16:32:51 -04002184 private void sendMessage(int message, int arg, Object obj) {
Nick Pelly6fa9ad42012-07-16 12:18:23 -07002185 // hold a wake lock until this message is delivered
Jeff Brown028872f2012-08-25 13:07:01 -07002186 // note that this assumes the message will not be removed from the queue before
2187 // it is handled (otherwise the wake lock would be leaked).
Nick Pelly6fa9ad42012-07-16 12:18:23 -07002188 mWakeLock.acquire();
Wyatt Rileycf879db2017-01-12 13:57:38 -08002189 if (Log.isLoggable(TAG, Log.INFO)) {
2190 Log.i(TAG, "WakeLock acquired by sendMessage(" + messageIdAsString(message) + ", " + arg
2191 + ", " + obj + ")");
2192 }
Nick Pelly6fa9ad42012-07-16 12:18:23 -07002193 mHandler.obtainMessage(message, arg, 1, obj).sendToTarget();
Mike Lockwood98e48692010-04-07 16:32:51 -04002194 }
2195
Mike Lockwood62a8fc12010-03-22 14:23:26 -04002196 private final class ProviderHandler extends Handler {
Victoria Lease5cd731a2012-12-19 15:04:21 -08002197 public ProviderHandler(Looper looper) {
2198 super(looper, null, true /*async*/);
Jeff Brown028872f2012-08-25 13:07:01 -07002199 }
2200
Mike Lockwood62a8fc12010-03-22 14:23:26 -04002201 @Override
Mike Lockwood4a7b65e2010-10-25 16:35:55 -04002202 public void handleMessage(Message msg) {
Mike Lockwood98e48692010-04-07 16:32:51 -04002203 int message = msg.what;
2204 switch (message) {
Mike Lockwood62a8fc12010-03-22 14:23:26 -04002205 case ENABLE:
2206 if (msg.arg1 == 1) {
2207 handleEnable();
2208 } else {
2209 handleDisable();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002210 }
Mike Lockwood62a8fc12010-03-22 14:23:26 -04002211 break;
Nick Pelly6fa9ad42012-07-16 12:18:23 -07002212 case SET_REQUEST:
2213 GpsRequest gpsRequest = (GpsRequest) msg.obj;
2214 handleSetRequest(gpsRequest.request, gpsRequest.source);
Mike Lockwood03ca2162010-04-01 08:10:09 -07002215 break;
Mike Lockwood62a8fc12010-03-22 14:23:26 -04002216 case UPDATE_NETWORK_STATE:
destradaae21252a2015-09-08 12:32:59 -07002217 handleUpdateNetworkState((Network) msg.obj);
2218 break;
2219 case REQUEST_SUPL_CONNECTION:
2220 handleRequestSuplConnection((InetAddress) msg.obj);
2221 break;
2222 case RELEASE_SUPL_CONNECTION:
2223 handleReleaseSuplConnection(msg.arg1);
Mike Lockwood62a8fc12010-03-22 14:23:26 -04002224 break;
2225 case INJECT_NTP_TIME:
2226 handleInjectNtpTime();
2227 break;
2228 case DOWNLOAD_XTRA_DATA:
Wyatt Riley0d6e54e22016-10-05 12:03:03 -07002229 handleDownloadXtraData();
Mike Lockwood62a8fc12010-03-22 14:23:26 -04002230 break;
Kevin Tang40e1baf2012-01-10 14:32:44 -08002231 case INJECT_NTP_TIME_FINISHED:
2232 mInjectNtpTimePending = STATE_IDLE;
2233 break;
2234 case DOWNLOAD_XTRA_DATA_FINISHED:
2235 mDownloadXtraDataPending = STATE_IDLE;
2236 break;
Mike Lockwood62a8fc12010-03-22 14:23:26 -04002237 case UPDATE_LOCATION:
destradaae21252a2015-09-08 12:32:59 -07002238 handleUpdateLocation((Location) msg.obj);
Mike Lockwood62a8fc12010-03-22 14:23:26 -04002239 break;
destradaafb23c672015-04-16 14:01:27 -07002240 case SUBSCRIPTION_OR_SIM_CHANGED:
2241 subscriptionOrSimChanged(mContext);
2242 break;
2243 case INITIALIZE_HANDLER:
destradaae21252a2015-09-08 12:32:59 -07002244 handleInitialize();
destradaafb23c672015-04-16 14:01:27 -07002245 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002246 }
Nick Pelly6fa9ad42012-07-16 12:18:23 -07002247 if (msg.arg2 == 1) {
2248 // wakelock was taken for this message, release it
2249 mWakeLock.release();
Wyatt Rileycf879db2017-01-12 13:57:38 -08002250 if (Log.isLoggable(TAG, Log.INFO)) {
2251 Log.i(TAG, "WakeLock released by handleMessage(" + messageIdAsString(message)
2252 + ", " + msg.arg1 + ", " + msg.obj + ")");
2253 }
Mike Lockwood98e48692010-04-07 16:32:51 -04002254 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002255 }
destradaafb23c672015-04-16 14:01:27 -07002256
2257 /**
Lifu Tang30f95a72016-01-07 23:20:38 -08002258 * This method is bound to {@link #GnssLocationProvider(Context, ILocationManager, Looper)}.
destradaafb23c672015-04-16 14:01:27 -07002259 * It is in charge of loading properties and registering for events that will be posted to
2260 * this handler.
2261 */
destradaae21252a2015-09-08 12:32:59 -07002262 private void handleInitialize() {
destradaafb23c672015-04-16 14:01:27 -07002263 // load default GPS configuration
2264 // (this configuration might change in the future based on SIM changes)
2265 reloadGpsProperties(mContext, mProperties);
2266
2267 // TODO: When this object "finishes" we should unregister by invoking
2268 // SubscriptionManager.getInstance(mContext).unregister(mOnSubscriptionsChangedListener);
2269 // This is not strictly necessary because it will be unregistered if the
2270 // notification fails but it is good form.
2271
2272 // Register for SubscriptionInfo list changes which is guaranteed
2273 // to invoke onSubscriptionsChanged the first time.
2274 SubscriptionManager.from(mContext)
2275 .addOnSubscriptionsChangedListener(mOnSubscriptionsChangedListener);
2276
2277 // listen for events
destradaaef752b62015-04-17 13:10:47 -07002278 IntentFilter intentFilter;
2279 if (native_is_agps_ril_supported()) {
2280 intentFilter = new IntentFilter();
2281 intentFilter.addAction(Intents.DATA_SMS_RECEIVED_ACTION);
2282 intentFilter.addDataScheme("sms");
2283 intentFilter.addDataAuthority("localhost", "7275");
2284 mContext.registerReceiver(mBroadcastReceiver, intentFilter, null, this);
destradaafb23c672015-04-16 14:01:27 -07002285
destradaaef752b62015-04-17 13:10:47 -07002286 intentFilter = new IntentFilter();
2287 intentFilter.addAction(Intents.WAP_PUSH_RECEIVED_ACTION);
2288 try {
2289 intentFilter.addDataType("application/vnd.omaloc-supl-init");
2290 } catch (IntentFilter.MalformedMimeTypeException e) {
2291 Log.w(TAG, "Malformed SUPL init mime type");
2292 }
2293 mContext.registerReceiver(mBroadcastReceiver, intentFilter, null, this);
2294 } else if (DEBUG) {
2295 Log.d(TAG, "Skipped registration for SMS/WAP-PUSH messages because AGPS Ril in GPS"
2296 + " HAL is not supported");
destradaafb23c672015-04-16 14:01:27 -07002297 }
destradaafb23c672015-04-16 14:01:27 -07002298
2299 intentFilter = new IntentFilter();
2300 intentFilter.addAction(ALARM_WAKEUP);
2301 intentFilter.addAction(ALARM_TIMEOUT);
destradaafb23c672015-04-16 14:01:27 -07002302 intentFilter.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED);
Adam Lesinski87c17df2015-05-27 13:24:13 -07002303 intentFilter.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED);
destradaafb23c672015-04-16 14:01:27 -07002304 intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
2305 intentFilter.addAction(Intent.ACTION_SCREEN_ON);
2306 intentFilter.addAction(SIM_STATE_CHANGED);
2307 mContext.registerReceiver(mBroadcastReceiver, intentFilter, null, this);
2308
destradaae21252a2015-09-08 12:32:59 -07002309 // register for connectivity change events, this is equivalent to the deprecated way of
2310 // registering for CONNECTIVITY_ACTION broadcasts
2311 NetworkRequest.Builder networkRequestBuilder = new NetworkRequest.Builder();
2312 networkRequestBuilder.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);
2313 networkRequestBuilder.addTransportType(NetworkCapabilities.TRANSPORT_WIFI);
2314 NetworkRequest networkRequest = networkRequestBuilder.build();
2315 mConnMgr.registerNetworkCallback(networkRequest, mNetworkConnectivityCallback);
2316
destradaafb23c672015-04-16 14:01:27 -07002317 // listen for PASSIVE_PROVIDER updates
2318 LocationManager locManager =
2319 (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
2320 long minTime = 0;
2321 float minDistance = 0;
2322 boolean oneShot = false;
2323 LocationRequest request = LocationRequest.createFromDeprecatedProvider(
2324 LocationManager.PASSIVE_PROVIDER,
2325 minTime,
2326 minDistance,
2327 oneShot);
2328 // Don't keep track of this request since it's done on behalf of other clients
2329 // (which are kept track of separately).
2330 request.setHideFromAppOps(true);
2331 locManager.requestLocationUpdates(
2332 request,
2333 new NetworkLocationListener(),
2334 getLooper());
2335 }
2336 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002337
Nick Pelly6fa9ad42012-07-16 12:18:23 -07002338 private final class NetworkLocationListener implements LocationListener {
2339 @Override
2340 public void onLocationChanged(Location location) {
2341 // this callback happens on mHandler looper
2342 if (LocationManager.NETWORK_PROVIDER.equals(location.getProvider())) {
2343 handleUpdateLocation(location);
2344 }
2345 }
2346 @Override
2347 public void onStatusChanged(String provider, int status, Bundle extras) { }
2348 @Override
2349 public void onProviderEnabled(String provider) { }
2350 @Override
2351 public void onProviderDisabled(String provider) { }
2352 }
2353
Kevin Tanga5fe6b22011-06-05 14:25:16 -07002354 private String getSelectedApn() {
2355 Uri uri = Uri.parse("content://telephony/carriers/preferapn");
destradaa96a14702014-06-05 11:36:30 -07002356 Cursor cursor = null;
2357 try {
2358 cursor = mContext.getContentResolver().query(
2359 uri,
2360 new String[] { "apn" },
2361 null /* selection */,
2362 null /* selectionArgs */,
2363 Carriers.DEFAULT_SORT_ORDER);
2364 if (cursor != null && cursor.moveToFirst()) {
2365 return cursor.getString(0);
2366 } else {
2367 Log.e(TAG, "No APN found to select.");
2368 }
2369 } catch (Exception e) {
destradaaea8a8a62014-06-23 18:19:03 -07002370 Log.e(TAG, "Error encountered on selecting the APN.", e);
destradaa96a14702014-06-05 11:36:30 -07002371 } finally {
2372 if (cursor != null) {
Kevin Tanga5fe6b22011-06-05 14:25:16 -07002373 cursor.close();
2374 }
2375 }
destradaa96a14702014-06-05 11:36:30 -07002376
2377 return null;
2378 }
2379
2380 private int getApnIpType(String apn) {
destradaae21252a2015-09-08 12:32:59 -07002381 ensureInHandlerThread();
destradaa96a14702014-06-05 11:36:30 -07002382 if (apn == null) {
2383 return APN_INVALID;
2384 }
2385
destradaa96a14702014-06-05 11:36:30 -07002386 String selection = String.format("current = 1 and apn = '%s' and carrier_enabled = 1", apn);
2387 Cursor cursor = null;
2388 try {
2389 cursor = mContext.getContentResolver().query(
2390 Carriers.CONTENT_URI,
2391 new String[] { Carriers.PROTOCOL },
2392 selection,
2393 null,
2394 Carriers.DEFAULT_SORT_ORDER);
2395
2396 if (null != cursor && cursor.moveToFirst()) {
2397 return translateToApnIpType(cursor.getString(0), apn);
2398 } else {
2399 Log.e(TAG, "No entry found in query for APN: " + apn);
2400 }
2401 } catch (Exception e) {
2402 Log.e(TAG, "Error encountered on APN query for: " + apn, e);
2403 } finally {
2404 if (cursor != null) {
2405 cursor.close();
2406 }
2407 }
2408
2409 return APN_INVALID;
2410 }
2411
2412 private int translateToApnIpType(String ipProtocol, String apn) {
2413 if ("IP".equals(ipProtocol)) {
2414 return APN_IPV4;
2415 }
2416 if ("IPV6".equals(ipProtocol)) {
2417 return APN_IPV6;
2418 }
2419 if ("IPV4V6".equals(ipProtocol)) {
2420 return APN_IPV4V6;
2421 }
2422
2423 // we hit the default case so the ipProtocol is not recognized
2424 String message = String.format("Unknown IP Protocol: %s, for APN: %s", ipProtocol, apn);
2425 Log.e(TAG, message);
2426 return APN_INVALID;
2427 }
2428
2429 private void setRouting() {
2430 if (mAGpsDataConnectionIpAddr == null) {
2431 return;
2432 }
2433
destradaae21252a2015-09-08 12:32:59 -07002434 // TODO: replace the use of this deprecated API
destradaa96a14702014-06-05 11:36:30 -07002435 boolean result = mConnMgr.requestRouteToHostAddress(
2436 ConnectivityManager.TYPE_MOBILE_SUPL,
2437 mAGpsDataConnectionIpAddr);
2438
2439 if (!result) {
2440 Log.e(TAG, "Error requesting route to host: " + mAGpsDataConnectionIpAddr);
2441 } else if (DEBUG) {
2442 Log.d(TAG, "Successfully requested route to host: " + mAGpsDataConnectionIpAddr);
2443 }
Kevin Tanga5fe6b22011-06-05 14:25:16 -07002444 }
2445
destradaae21252a2015-09-08 12:32:59 -07002446 /**
2447 * @return {@code true} if there is a data network available for outgoing connections,
2448 * {@code false} otherwise.
2449 */
2450 private boolean isDataNetworkConnected() {
2451 NetworkInfo activeNetworkInfo = mConnMgr.getActiveNetworkInfo();
2452 return activeNetworkInfo != null && activeNetworkInfo.isConnected();
2453 }
2454
2455 /**
2456 * Ensures the calling function is running in the thread associated with {@link #mHandler}.
2457 */
2458 private void ensureInHandlerThread() {
2459 if (mHandler != null && Looper.myLooper() == mHandler.getLooper()) {
2460 return;
2461 }
2462 throw new RuntimeException("This method must run on the Handler thread.");
2463 }
2464
2465 /**
2466 * @return A string representing the current state stored in {@link #mAGpsDataConnectionState}.
2467 */
2468 private String agpsDataConnStateAsString() {
2469 switch(mAGpsDataConnectionState) {
2470 case AGPS_DATA_CONNECTION_CLOSED:
2471 return "CLOSED";
2472 case AGPS_DATA_CONNECTION_OPEN:
2473 return "OPEN";
2474 case AGPS_DATA_CONNECTION_OPENING:
2475 return "OPENING";
2476 default:
2477 return "<Unknown>";
2478 }
2479 }
2480
2481 /**
2482 * @return A string representing the given GPS_AGPS_DATA status.
2483 */
2484 private String agpsDataConnStatusAsString(int agpsDataConnStatus) {
2485 switch (agpsDataConnStatus) {
2486 case GPS_AGPS_DATA_CONNECTED:
2487 return "CONNECTED";
2488 case GPS_AGPS_DATA_CONN_DONE:
2489 return "DONE";
2490 case GPS_AGPS_DATA_CONN_FAILED:
2491 return "FAILED";
2492 case GPS_RELEASE_AGPS_DATA_CONN:
2493 return "RELEASE";
2494 case GPS_REQUEST_AGPS_DATA_CONN:
2495 return "REQUEST";
2496 default:
2497 return "<Unknown>";
2498 }
2499 }
2500
Wyatt Rileycf879db2017-01-12 13:57:38 -08002501 /**
2502 * @return A string representing the given message ID.
2503 */
2504 private String messageIdAsString(int message) {
2505 switch (message) {
2506 case ENABLE:
2507 return "ENABLE";
2508 case SET_REQUEST:
2509 return "SET_REQUEST";
2510 case UPDATE_NETWORK_STATE:
2511 return "UPDATE_NETWORK_STATE";
2512 case REQUEST_SUPL_CONNECTION:
2513 return "REQUEST_SUPL_CONNECTION";
2514 case RELEASE_SUPL_CONNECTION:
2515 return "RELEASE_SUPL_CONNECTION";
2516 case INJECT_NTP_TIME:
2517 return "INJECT_NTP_TIME";
2518 case DOWNLOAD_XTRA_DATA:
2519 return "DOWNLOAD_XTRA_DATA";
2520 case INJECT_NTP_TIME_FINISHED:
2521 return "INJECT_NTP_TIME_FINISHED";
2522 case DOWNLOAD_XTRA_DATA_FINISHED:
2523 return "DOWNLOAD_XTRA_DATA_FINISHED";
2524 case UPDATE_LOCATION:
2525 return "UPDATE_LOCATION";
2526 case SUBSCRIPTION_OR_SIM_CHANGED:
2527 return "SUBSCRIPTION_OR_SIM_CHANGED";
2528 case INITIALIZE_HANDLER:
2529 return "INITIALIZE_HANDLER";
2530 default:
2531 return "<Unknown>";
2532 }
2533 }
2534
Siddharth Raybb608c82017-03-16 11:33:34 -07002535
2536
Nick Pelly6fa9ad42012-07-16 12:18:23 -07002537 @Override
2538 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
2539 StringBuilder s = new StringBuilder();
Wyatt Riley77ca4f82017-06-30 18:13:44 -07002540 s.append(" mStarted=").append(mStarted).append('\n');
destradaa25e8caf2015-08-24 14:14:44 -07002541 s.append(" mFixInterval=").append(mFixInterval).append('\n');
2542 s.append(" mDisableGps (battery saver mode)=").append(mDisableGps).append('\n');
2543 s.append(" mEngineCapabilities=0x").append(Integer.toHexString(mEngineCapabilities));
2544 s.append(" ( ");
2545 if (hasCapability(GPS_CAPABILITY_SCHEDULING)) s.append("SCHEDULING ");
Nick Pelly6fa9ad42012-07-16 12:18:23 -07002546 if (hasCapability(GPS_CAPABILITY_MSB)) s.append("MSB ");
2547 if (hasCapability(GPS_CAPABILITY_MSA)) s.append("MSA ");
2548 if (hasCapability(GPS_CAPABILITY_SINGLE_SHOT)) s.append("SINGLE_SHOT ");
2549 if (hasCapability(GPS_CAPABILITY_ON_DEMAND_TIME)) s.append("ON_DEMAND_TIME ");
destradaa25e8caf2015-08-24 14:14:44 -07002550 if (hasCapability(GPS_CAPABILITY_GEOFENCING)) s.append("GEOFENCING ");
2551 if (hasCapability(GPS_CAPABILITY_MEASUREMENTS)) s.append("MEASUREMENTS ");
2552 if (hasCapability(GPS_CAPABILITY_NAV_MESSAGES)) s.append("NAV_MESSAGES ");
Nick Pelly6fa9ad42012-07-16 12:18:23 -07002553 s.append(")\n");
Siddharth Raybb608c82017-03-16 11:33:34 -07002554 s.append(mGnssMetrics.dumpGnssMetricsAsText());
2555 s.append(" native internal state: ").append(native_get_internal_state());
Wyatt Rileycf879db2017-01-12 13:57:38 -08002556 s.append("\n");
Nick Pelly6fa9ad42012-07-16 12:18:23 -07002557 pw.append(s);
2558 }
2559
Wei Liu6f6326b2015-06-24 23:47:50 -07002560 /**
2561 * A simple implementation of exponential backoff.
2562 */
2563 private static final class BackOff {
2564 private static final int MULTIPLIER = 2;
2565 private final long mInitIntervalMillis;
2566 private final long mMaxIntervalMillis;
2567 private long mCurrentIntervalMillis;
2568
2569 public BackOff(long initIntervalMillis, long maxIntervalMillis) {
2570 mInitIntervalMillis = initIntervalMillis;
2571 mMaxIntervalMillis = maxIntervalMillis;
2572
2573 mCurrentIntervalMillis = mInitIntervalMillis / MULTIPLIER;
2574 }
2575
2576 public long nextBackoffMillis() {
2577 if (mCurrentIntervalMillis > mMaxIntervalMillis) {
2578 return mMaxIntervalMillis;
2579 }
2580
2581 mCurrentIntervalMillis *= MULTIPLIER;
2582 return mCurrentIntervalMillis;
2583 }
2584
2585 public void reset() {
2586 mCurrentIntervalMillis = mInitIntervalMillis / MULTIPLIER;
2587 }
2588 }
2589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002590 // for GPS SV statistics
Lifu Tang120480f2016-02-07 18:08:19 -08002591 private static final int MAX_SVS = 64;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002592
2593 // preallocated arrays, to avoid memory allocation in reportStatus()
Lifu Tang120480f2016-02-07 18:08:19 -08002594 private int mSvidWithFlags[] = new int[MAX_SVS];
Lifu Tang76a620f2016-02-26 19:53:01 -08002595 private float mCn0s[] = new float[MAX_SVS];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002596 private float mSvElevations[] = new float[MAX_SVS];
2597 private float mSvAzimuths[] = new float[MAX_SVS];
gomo4402af62017-01-11 13:20:13 -08002598 private float mSvCarrierFreqs[] = new float[MAX_SVS];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002599 private int mSvCount;
Wyatt Rileyc9f25dd2017-05-05 13:45:23 -07002600 private int mMeanCn0;
2601 private int mMaxCn0;
Mike Lockwoodb16e7802009-08-06 09:26:02 -04002602 // preallocated to avoid memory allocation in reportNmea()
2603 private byte[] mNmeaBuffer = new byte[120];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002604
gomo4402af62017-01-11 13:20:13 -08002605 static { class_init_native(); }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002606 private static native void class_init_native();
2607 private static native boolean native_is_supported();
destradaaef752b62015-04-17 13:10:47 -07002608 private static native boolean native_is_agps_ril_supported();
2609 private static native boolean native_is_gnss_configuration_supported();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002610
2611 private native boolean native_init();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002612 private native void native_cleanup();
Mike Lockwood04598b62010-04-14 17:17:24 -04002613 private native boolean native_set_position_mode(int mode, int recurrence, int min_interval,
2614 int preferred_accuracy, int preferred_time);
2615 private native boolean native_start();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002616 private native boolean native_stop();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002617 private native void native_delete_aiding_data(int flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002618 // returns number of SVs
2619 // mask[0] is ephemeris mask and mask[1] is almanac mask
Lifu Tang76a620f2016-02-26 19:53:01 -08002620 private native int native_read_sv_status(int[] prnWithFlags, float[] cn0s, float[] elevations,
gomo4402af62017-01-11 13:20:13 -08002621 float[] azimuths, float[] carrierFrequencies);
Mike Lockwoodf602d362010-06-20 14:28:16 -07002622 private native int native_read_nmea(byte[] buffer, int bufferSize);
Mike Lockwoodd26ce0d2009-06-11 12:25:46 -04002623 private native void native_inject_location(double latitude, double longitude, float accuracy);
2624
Fred Fettinger3c8fbdf2010-01-04 15:38:13 -06002625 // XTRA Support
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002626 private native void native_inject_time(long time, long timeReference, int uncertainty);
2627 private native boolean native_supports_xtra();
2628 private native void native_inject_xtra_data(byte[] data, int length);
The Android Open Source Project10592532009-03-18 17:39:46 -07002629
Fred Fettinger3c8fbdf2010-01-04 15:38:13 -06002630 // DEBUG Support
2631 private native String native_get_internal_state();
2632
2633 // AGPS Support
destradaa96a14702014-06-05 11:36:30 -07002634 private native void native_agps_data_conn_open(String apn, int apnIpType);
Mike Lockwoode3635c92009-05-11 08:38:02 -04002635 private native void native_agps_data_conn_closed();
2636 private native void native_agps_data_conn_failed();
Miguel Torroja1e84da82010-07-27 07:02:24 +02002637 private native void native_agps_ni_message(byte [] msg, int length);
Mike Lockwooda9e54612009-06-19 14:54:42 -04002638 private native void native_set_agps_server(int type, String hostname, int port);
Danke Xie22d1f9f2009-08-18 18:28:45 -04002639
2640 // Network-initiated (NI) Support
2641 private native void native_send_ni_response(int notificationId, int userResponse);
Miguel Torroja1e84da82010-07-27 07:02:24 +02002642
2643 // AGPS ril suport
2644 private native void native_agps_set_ref_location_cellid(int type, int mcc, int mnc,
2645 int lac, int cid);
2646 private native void native_agps_set_id(int type, String setid);
Mike Lockwood50130bb2010-10-11 06:22:50 -04002647
2648 private native void native_update_network_state(boolean connected, int type,
Kevin Tanga5fe6b22011-06-05 14:25:16 -07002649 boolean roaming, boolean available, String extraInfo, String defaultAPN);
Jaikumar Ganesh8ce470d2013-04-03 12:22:18 -07002650
2651 // Hardware Geofence support.
2652 private static native boolean native_is_geofence_supported();
2653 private static native boolean native_add_geofence(int geofenceId, double latitude,
2654 double longitude, double radius, int lastTransition,int monitorTransitions,
2655 int notificationResponsivenes, int unknownTimer);
2656 private static native boolean native_remove_geofence(int geofenceId);
2657 private static native boolean native_resume_geofence(int geofenceId, int transitions);
2658 private static native boolean native_pause_geofence(int geofenceId);
destradaaea8a8a62014-06-23 18:19:03 -07002659
2660 // Gps Hal measurements support.
2661 private static native boolean native_is_measurement_supported();
destradaa4b3e3932014-07-21 18:01:47 -07002662 private native boolean native_start_measurement_collection();
2663 private native boolean native_stop_measurement_collection();
2664
2665 // Gps Navigation message support.
2666 private static native boolean native_is_navigation_message_supported();
2667 private native boolean native_start_navigation_message_collection();
2668 private native boolean native_stop_navigation_message_collection();
Tsuwei Chen52617bb2014-08-25 11:49:11 -07002669
2670 // GNSS Configuration
Hridya Valsaraju2ea29602016-09-13 08:38:09 -07002671 private static native boolean native_set_supl_version(int version);
2672 private static native boolean native_set_supl_mode(int mode);
2673 private static native boolean native_set_supl_es(int es);
2674 private static native boolean native_set_lpp_profile(int lppProfile);
2675 private static native boolean native_set_gnss_pos_protocol_select(int gnssPosProtocolSelect);
2676 private static native boolean native_set_gps_lock(int gpsLock);
2677 private static native boolean native_set_emergency_supl_pdn(int emergencySuplPdn);
2678
Wyatt Rileycf879db2017-01-12 13:57:38 -08002679 // GNSS Batching
2680 private static native int native_get_batch_size();
2681 private static native boolean native_start_batch(long periodNanos, boolean wakeOnFifoFull);
2682 private static native void native_flush_batch();
2683 private static native boolean native_stop_batch();
2684 private static native boolean native_init_batching();
2685 private static native void native_cleanup_batching();
2686
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002687}