From b5e7bbe5b8e1d120d3f13f6d15b7be16d4f2e132 Mon Sep 17 00:00:00 2001 From: WyattRiley Date: Tue, 19 Feb 2019 13:19:13 -0800 Subject: [PATCH] DO NOT MERGE - SUPL ES Extension - Safer Init and Not After Boot Safe order of pointer setting and background thread start Verifying mCallEndElapsedRealtimeMillis is not the initial value Bug: 112159033 Bug: 115361555 Bug: 125124724 Test: Verified not-after-boot with test code b/115361555#comment14 Test: Reproed NPE on Nexus 5x with test thread sleep and verify fix Change-Id: I596f913bc79873274c2743132c93ef2381d9f3c7 --- .../internal/location/GpsNetInitiatedHandler.java | 9 +++++---- .../android/server/location/GnssLocationProvider.java | 5 ++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/location/java/com/android/internal/location/GpsNetInitiatedHandler.java b/location/java/com/android/internal/location/GpsNetInitiatedHandler.java index 1f9155d9c4aeb..aa73bc6e015cb 100644 --- a/location/java/com/android/internal/location/GpsNetInitiatedHandler.java +++ b/location/java/com/android/internal/location/GpsNetInitiatedHandler.java @@ -123,8 +123,8 @@ public class GpsNetInitiatedHandler { static private boolean mIsHexInput = true; // End time of emergency call, and extension, if set - private long mCallEndElapsedRealtimeMillis = 0; - private long mEmergencyExtensionMillis = 0; + private volatile long mCallEndElapsedRealtimeMillis = 0; + private volatile long mEmergencyExtensionMillis = 0; public static class GpsNiNotification { @@ -250,8 +250,9 @@ public class GpsNetInitiatedHandler { */ public boolean getInEmergency() { boolean isInEmergencyExtension = - (SystemClock.elapsedRealtime() - mCallEndElapsedRealtimeMillis) < - mEmergencyExtensionMillis; + (mCallEndElapsedRealtimeMillis > 0) + && ((SystemClock.elapsedRealtime() - mCallEndElapsedRealtimeMillis) + < mEmergencyExtensionMillis); boolean isInEmergencyCallback = Boolean.parseBoolean( SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE)); return mIsInEmergencyCall || isInEmergencyCallback || isInEmergencyExtension; diff --git a/services/core/java/com/android/server/location/GnssLocationProvider.java b/services/core/java/com/android/server/location/GnssLocationProvider.java index 64cabd9643176..93e041b1bab79 100644 --- a/services/core/java/com/android/server/location/GnssLocationProvider.java +++ b/services/core/java/com/android/server/location/GnssLocationProvider.java @@ -705,12 +705,11 @@ public class GnssLocationProvider implements LocationProviderInterface { // while IO initialization and registration is delegated to our internal handler // this approach is just fine because events are posted to our handler anyway mProperties = new Properties(); - sendMessage(INITIALIZE_HANDLER, 0, null); - - // Create a GPS net-initiated handler. + // Create a GPS net-initiated handler (also needed by handleInitialize) mNIHandler = new GpsNetInitiatedHandler(context, mNetInitiatedListener, mSuplEsEnabled); + sendMessage(INITIALIZE_HANDLER, 0, null); mListenerHelper = new GnssStatusListenerHelper(mHandler) { @Override