frameworks/base
Révision | 79f540388df8207c31a3aed9333bd68b08e32db9 (tree) |
---|---|
l'heure | 2019-06-06 21:52:19 |
Auteur | WyattRiley <wyattriley@goog...> |
Commiter | Kevin F. Haggerty |
Adding SUPL NI Emergency Extension Time
Configurable by carrier config.xml resource
Bug: 118839234
Bug: 115361555
Bug: 112159033
Test: On device, see b/115361555#comment14
Change-Id: I52e61656cca8b6fa6468d32d2e69bf60f4c83c61
(cherry picked from commit a725dd6650846090f70ed9811f1a94f036ab3f29)
@@ -16,6 +16,9 @@ | ||
16 | 16 | |
17 | 17 | package com.android.internal.location; |
18 | 18 | |
19 | +import java.io.UnsupportedEncodingException; | |
20 | +import java.util.concurrent.TimeUnit; | |
21 | + | |
19 | 22 | import android.app.Notification; |
20 | 23 | import android.app.NotificationManager; |
21 | 24 | import android.app.PendingIntent; |
@@ -23,20 +26,21 @@ import android.content.BroadcastReceiver; | ||
23 | 26 | import android.content.Context; |
24 | 27 | import android.content.Intent; |
25 | 28 | import android.content.IntentFilter; |
26 | -import android.location.INetInitiatedListener; | |
27 | 29 | import android.location.LocationManager; |
30 | +import android.location.INetInitiatedListener; | |
31 | +import android.os.SystemClock; | |
32 | +import android.telephony.TelephonyManager; | |
33 | +import android.telephony.PhoneNumberUtils; | |
34 | +import android.telephony.PhoneStateListener; | |
28 | 35 | import android.os.Bundle; |
29 | 36 | import android.os.RemoteException; |
30 | -import android.os.SystemProperties; | |
31 | 37 | import android.os.UserHandle; |
32 | -import android.telephony.PhoneNumberUtils; | |
33 | -import android.telephony.PhoneStateListener; | |
34 | -import android.telephony.TelephonyManager; | |
38 | +import android.os.SystemProperties; | |
35 | 39 | import android.util.Log; |
40 | + | |
36 | 41 | import com.android.internal.R; |
37 | 42 | import com.android.internal.telephony.GsmAlphabet; |
38 | 43 | import com.android.internal.telephony.TelephonyProperties; |
39 | -import java.io.UnsupportedEncodingException; | |
40 | 44 | |
41 | 45 | /** |
42 | 46 | * A GPS Network-initiated Handler class used by LocationManager. |
@@ -47,8 +51,7 @@ public class GpsNetInitiatedHandler { | ||
47 | 51 | |
48 | 52 | private static final String TAG = "GpsNetInitiatedHandler"; |
49 | 53 | |
50 | - private static final boolean DEBUG = true; | |
51 | - private static final boolean VERBOSE = false; | |
54 | + private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); | |
52 | 55 | |
53 | 56 | // NI verify activity for bringing up UI (not used yet) |
54 | 57 | public static final String ACTION_NI_VERIFY = "android.intent.action.NETWORK_INITIATED_VERIFY"; |
@@ -91,6 +94,9 @@ public class GpsNetInitiatedHandler { | ||
91 | 94 | public static final int GPS_ENC_SUPL_UCS2 = 3; |
92 | 95 | public static final int GPS_ENC_UNKNOWN = -1; |
93 | 96 | |
97 | + // Limit on SUPL NI emergency mode time extension after emergency sessions ends | |
98 | + private static final int MAX_EMERGENCY_MODE_EXTENSION_SECONDS = 300; // 5 minute maximum | |
99 | + | |
94 | 100 | private final Context mContext; |
95 | 101 | private final TelephonyManager mTelephonyManager; |
96 | 102 | private final PhoneStateListener mPhoneStateListener; |
@@ -106,7 +112,7 @@ public class GpsNetInitiatedHandler { | ||
106 | 112 | private volatile boolean mIsSuplEsEnabled; |
107 | 113 | |
108 | 114 | // Set to true if the phone is having emergency call. |
109 | - private volatile boolean mIsInEmergency; | |
115 | + private volatile boolean mIsInEmergencyCall; | |
110 | 116 | |
111 | 117 | // If Location function is enabled. |
112 | 118 | private volatile boolean mIsLocationEnabled = false; |
@@ -116,6 +122,10 @@ public class GpsNetInitiatedHandler { | ||
116 | 122 | // Set to true if string from HAL is encoded as Hex, e.g., "3F0039" |
117 | 123 | static private boolean mIsHexInput = true; |
118 | 124 | |
125 | + // End time of emergency call, and extension, if set | |
126 | + private volatile long mCallEndElapsedRealtimeMillis = 0; | |
127 | + private volatile long mEmergencyExtensionMillis = 0; | |
128 | + | |
119 | 129 | public static class GpsNiNotification |
120 | 130 | { |
121 | 131 | public int notificationId; |
@@ -146,16 +156,12 @@ public class GpsNetInitiatedHandler { | ||
146 | 156 | if (action.equals(Intent.ACTION_NEW_OUTGOING_CALL)) { |
147 | 157 | String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); |
148 | 158 | /* |
149 | - Emergency Mode is when during emergency call or in emergency call back mode. | |
150 | - For checking if it is during emergency call: | |
151 | - mIsInEmergency records if the phone is in emergency call or not. It will | |
159 | + Tracks the emergency call: | |
160 | + mIsInEmergencyCall records if the phone is in emergency call or not. It will | |
152 | 161 | be set to true when the phone is having emergency call, and then will |
153 | 162 | be set to false by mPhoneStateListener when the emergency call ends. |
154 | - For checking if it is in emergency call back mode: | |
155 | - Emergency call back mode will be checked by reading system properties | |
156 | - when necessary: SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE) | |
157 | 163 | */ |
158 | - setInEmergency(PhoneNumberUtils.isEmergencyNumber(phoneNumber)); | |
164 | + mIsInEmergencyCall = PhoneNumberUtils.isEmergencyNumber(phoneNumber); | |
159 | 165 | if (DEBUG) Log.v(TAG, "ACTION_NEW_OUTGOING_CALL - " + getInEmergency()); |
160 | 166 | } else if (action.equals(LocationManager.MODE_CHANGED_ACTION)) { |
161 | 167 | updateLocationMode(); |
@@ -195,7 +201,10 @@ public class GpsNetInitiatedHandler { | ||
195 | 201 | if (DEBUG) Log.d(TAG, "onCallStateChanged(): state is "+ state); |
196 | 202 | // listening for emergency call ends |
197 | 203 | if (state == TelephonyManager.CALL_STATE_IDLE) { |
198 | - setInEmergency(false); | |
204 | + if (mIsInEmergencyCall) { | |
205 | + mCallEndElapsedRealtimeMillis = SystemClock.elapsedRealtime(); | |
206 | + mIsInEmergencyCall = false; | |
207 | + } | |
199 | 208 | } |
200 | 209 | } |
201 | 210 | }; |
@@ -229,23 +238,37 @@ public class GpsNetInitiatedHandler { | ||
229 | 238 | return mIsLocationEnabled; |
230 | 239 | } |
231 | 240 | |
232 | - // Note: Currently, there are two mechanisms involved to determine if a | |
233 | - // phone is in emergency mode: | |
234 | - // 1. If the user is making an emergency call, this is provided by activly | |
235 | - // monitoring the outgoing phone number; | |
236 | - // 2. If the device is in a emergency callback state, this is provided by | |
237 | - // system properties. | |
238 | - // If either one of above exists, the phone is considered in an emergency | |
239 | - // mode. Because of this complexity, we need to be careful about how to set | |
240 | - // and clear the emergency state. | |
241 | - public void setInEmergency(boolean isInEmergency) { | |
242 | - mIsInEmergency = isInEmergency; | |
243 | - } | |
244 | - | |
241 | + /** | |
242 | + * Determines whether device is in user-initiated emergency session based on the following | |
243 | + * 1. If the user is making an emergency call, this is provided by actively | |
244 | + * monitoring the outgoing phone number; | |
245 | + * 2. If the user has recently ended an emergency call, and the device is in a configured time | |
246 | + * window after the end of that call. | |
247 | + * 3. If the device is in a emergency callback state, this is provided by querying | |
248 | + * TelephonyManager. | |
249 | + * @return true if is considered in user initiated emergency mode for NI purposes | |
250 | + */ | |
245 | 251 | public boolean getInEmergency() { |
252 | + boolean isInEmergencyExtension = | |
253 | + (mCallEndElapsedRealtimeMillis > 0) | |
254 | + && ((SystemClock.elapsedRealtime() - mCallEndElapsedRealtimeMillis) | |
255 | + < mEmergencyExtensionMillis); | |
246 | 256 | boolean isInEmergencyCallback = Boolean.parseBoolean( |
247 | 257 | SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE)); |
248 | - return mIsInEmergency || isInEmergencyCallback; | |
258 | + return mIsInEmergencyCall || isInEmergencyCallback || isInEmergencyExtension; | |
259 | + } | |
260 | + | |
261 | + public void setEmergencyExtensionSeconds(int emergencyExtensionSeconds) { | |
262 | + if (emergencyExtensionSeconds > MAX_EMERGENCY_MODE_EXTENSION_SECONDS) { | |
263 | + Log.w(TAG, "emergencyExtensionSeconds " + emergencyExtensionSeconds | |
264 | + + " too high, reset to " + MAX_EMERGENCY_MODE_EXTENSION_SECONDS); | |
265 | + emergencyExtensionSeconds = MAX_EMERGENCY_MODE_EXTENSION_SECONDS; | |
266 | + } else if (emergencyExtensionSeconds < 0) { | |
267 | + Log.w(TAG, "emergencyExtensionSeconds " + emergencyExtensionSeconds | |
268 | + + " is negative, reset to zero."); | |
269 | + emergencyExtensionSeconds = 0; | |
270 | + } | |
271 | + mEmergencyExtensionMillis = TimeUnit.SECONDS.toMillis(emergencyExtensionSeconds); | |
249 | 272 | } |
250 | 273 | |
251 | 274 |
@@ -675,6 +675,17 @@ public class GnssLocationProvider implements LocationProviderInterface { | ||
675 | 675 | Log.e(TAG, "unable to parse SUPL_ES: " + suplESProperty); |
676 | 676 | } |
677 | 677 | } |
678 | + | |
679 | + String emergencyExtensionSecondsString | |
680 | + = properties.getProperty("ES_EXTENSION_SEC", "0"); | |
681 | + try { | |
682 | + int emergencyExtensionSeconds = | |
683 | + Integer.parseInt(emergencyExtensionSecondsString); | |
684 | + mNIHandler.setEmergencyExtensionSeconds(emergencyExtensionSeconds); | |
685 | + } catch (NumberFormatException e) { | |
686 | + Log.e(TAG, "unable to parse ES_EXTENSION_SEC: " | |
687 | + + emergencyExtensionSecondsString); | |
688 | + } | |
678 | 689 | } |
679 | 690 | |
680 | 691 | private void loadPropertiesFromResource(Context context, |