Merge "Handle emergency SUPL on active SIM" into tm-d1-dev

This commit is contained in:
TreeHugger Robot
2022-07-22 18:33:15 +00:00
committed by Android (Google) Code Review
4 changed files with 104 additions and 18 deletions

View File

@@ -142,6 +142,14 @@ public class GpsNetInitiatedHandler {
public int textEncoding; public int textEncoding;
} }
/** Callbacks for Emergency call events. */
public interface EmergencyCallCallback {
/** Callback invoked when an emergency call starts */
void onEmergencyCallStart(int subId);
/** Callback invoked when an emergency call ends */
void onEmergencyCallEnd();
}
private class EmergencyCallListener extends TelephonyCallback implements private class EmergencyCallListener extends TelephonyCallback implements
TelephonyCallback.OutgoingEmergencyCallListener, TelephonyCallback.OutgoingEmergencyCallListener,
TelephonyCallback.CallStateListener { TelephonyCallback.CallStateListener {
@@ -152,6 +160,7 @@ public class GpsNetInitiatedHandler {
int subscriptionId) { int subscriptionId) {
mIsInEmergencyCall = true; mIsInEmergencyCall = true;
if (DEBUG) Log.d(TAG, "onOutgoingEmergencyCall(): inEmergency = " + getInEmergency()); if (DEBUG) Log.d(TAG, "onOutgoingEmergencyCall(): inEmergency = " + getInEmergency());
mEmergencyCallCallback.onEmergencyCallStart(subscriptionId);
} }
@Override @Override
@@ -163,6 +172,7 @@ public class GpsNetInitiatedHandler {
if (mIsInEmergencyCall) { if (mIsInEmergencyCall) {
mCallEndElapsedRealtimeMillis = SystemClock.elapsedRealtime(); mCallEndElapsedRealtimeMillis = SystemClock.elapsedRealtime();
mIsInEmergencyCall = false; mIsInEmergencyCall = false;
mEmergencyCallCallback.onEmergencyCallEnd();
} }
} }
} }
@@ -180,8 +190,11 @@ public class GpsNetInitiatedHandler {
*/ */
private Notification.Builder mNiNotificationBuilder; private Notification.Builder mNiNotificationBuilder;
private final EmergencyCallCallback mEmergencyCallCallback;
public GpsNetInitiatedHandler(Context context, public GpsNetInitiatedHandler(Context context,
INetInitiatedListener netInitiatedListener, INetInitiatedListener netInitiatedListener,
EmergencyCallCallback emergencyCallCallback,
boolean isSuplEsEnabled) { boolean isSuplEsEnabled) {
mContext = context; mContext = context;
@@ -190,6 +203,7 @@ public class GpsNetInitiatedHandler {
} else { } else {
mNetInitiatedListener = netInitiatedListener; mNetInitiatedListener = netInitiatedListener;
} }
mEmergencyCallCallback = emergencyCallCallback;
setSuplEsEnabled(isSuplEsEnabled); setSuplEsEnabled(isSuplEsEnabled);
mLocationManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE); mLocationManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);

View File

@@ -21,6 +21,7 @@ import android.os.PersistableBundle;
import android.os.SystemProperties; import android.os.SystemProperties;
import android.telephony.CarrierConfigManager; import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
@@ -73,6 +74,8 @@ public class GnssConfiguration {
static final String CONFIG_NFW_PROXY_APPS = "NFW_PROXY_APPS"; static final String CONFIG_NFW_PROXY_APPS = "NFW_PROXY_APPS";
private static final String CONFIG_ENABLE_PSDS_PERIODIC_DOWNLOAD = private static final String CONFIG_ENABLE_PSDS_PERIODIC_DOWNLOAD =
"ENABLE_PSDS_PERIODIC_DOWNLOAD"; "ENABLE_PSDS_PERIODIC_DOWNLOAD";
private static final String CONFIG_ENABLE_ACTIVE_SIM_EMERGENCY_SUPL =
"ENABLE_ACTIVE_SIM_EMERGENCY_SUPL";
static final String CONFIG_LONGTERM_PSDS_SERVER_1 = "LONGTERM_PSDS_SERVER_1"; static final String CONFIG_LONGTERM_PSDS_SERVER_1 = "LONGTERM_PSDS_SERVER_1";
static final String CONFIG_LONGTERM_PSDS_SERVER_2 = "LONGTERM_PSDS_SERVER_2"; static final String CONFIG_LONGTERM_PSDS_SERVER_2 = "LONGTERM_PSDS_SERVER_2";
static final String CONFIG_LONGTERM_PSDS_SERVER_3 = "LONGTERM_PSDS_SERVER_3"; static final String CONFIG_LONGTERM_PSDS_SERVER_3 = "LONGTERM_PSDS_SERVER_3";
@@ -206,6 +209,14 @@ public class GnssConfiguration {
return getBooleanConfig(CONFIG_ENABLE_PSDS_PERIODIC_DOWNLOAD, false); return getBooleanConfig(CONFIG_ENABLE_PSDS_PERIODIC_DOWNLOAD, false);
} }
/**
* Returns true if during an emergency call, the GnssConfiguration of the activeSubId will be
* injected for the emergency SUPL flow; Returns false otherwise. Default false if not set.
*/
boolean isActiveSimEmergencySuplEnabled() {
return getBooleanConfig(CONFIG_ENABLE_ACTIVE_SIM_EMERGENCY_SUPL, false);
}
/** /**
* Returns true if a long-term PSDS server is configured. * Returns true if a long-term PSDS server is configured.
*/ */
@@ -232,16 +243,31 @@ public class GnssConfiguration {
/** /**
* Loads the GNSS properties from carrier config file followed by the properties from * Loads the GNSS properties from carrier config file followed by the properties from
* gps debug config file. * gps debug config file, and injects the GNSS properties into the HAL.
*/ */
void reloadGpsProperties() { void reloadGpsProperties() {
if (DEBUG) Log.d(TAG, "Reset GPS properties, previous size = " + mProperties.size()); reloadGpsProperties(/* inEmergency= */ false, /* activeSubId= */ -1);
loadPropertiesFromCarrierConfig(); }
String lpp_prof = SystemProperties.get(LPP_PROFILE); /**
if (!TextUtils.isEmpty(lpp_prof)) { * Loads the GNSS properties from carrier config file followed by the properties from
// override default value of this if lpp_prof is not empty * gps debug config file, and injects the GNSS properties into the HAL.
mProperties.setProperty(CONFIG_LPP_PROFILE, lpp_prof); */
void reloadGpsProperties(boolean inEmergency, int activeSubId) {
if (DEBUG) {
Log.d(TAG,
"Reset GPS properties, previous size = " + mProperties.size() + ", inEmergency:"
+ inEmergency + ", activeSubId=" + activeSubId);
}
loadPropertiesFromCarrierConfig(inEmergency, activeSubId);
if (isSimAbsent(mContext)) {
// Use the default SIM's LPP profile when SIM is absent.
String lpp_prof = SystemProperties.get(LPP_PROFILE);
if (!TextUtils.isEmpty(lpp_prof)) {
// override default value of this if lpp_prof is not empty
mProperties.setProperty(CONFIG_LPP_PROFILE, lpp_prof);
}
} }
/* /*
@@ -322,16 +348,19 @@ public class GnssConfiguration {
/** /**
* Loads GNSS properties from carrier config file. * Loads GNSS properties from carrier config file.
*/ */
void loadPropertiesFromCarrierConfig() { void loadPropertiesFromCarrierConfig(boolean inEmergency, int activeSubId) {
CarrierConfigManager configManager = (CarrierConfigManager) CarrierConfigManager configManager = (CarrierConfigManager)
mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE); mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE);
if (configManager == null) { if (configManager == null) {
return; return;
} }
int ddSubId = SubscriptionManager.getDefaultDataSubscriptionId(); int subId = SubscriptionManager.getDefaultDataSubscriptionId();
PersistableBundle configs = SubscriptionManager.isValidSubscriptionId(ddSubId) if (inEmergency && activeSubId >= 0) {
? configManager.getConfigForSubId(ddSubId) : configManager.getConfig(); subId = activeSubId;
}
PersistableBundle configs = SubscriptionManager.isValidSubscriptionId(subId)
? configManager.getConfigForSubId(subId) : configManager.getConfig();
if (configs == null) { if (configs == null) {
if (DEBUG) Log.d(TAG, "SIM not ready, use default carrier config."); if (DEBUG) Log.d(TAG, "SIM not ready, use default carrier config.");
configs = CarrierConfigManager.getDefaultConfig(); configs = CarrierConfigManager.getDefaultConfig();
@@ -422,6 +451,12 @@ public class GnssConfiguration {
return gnssConfiguartionIfaceVersion.mMajor < 2; return gnssConfiguartionIfaceVersion.mMajor < 2;
} }
private static boolean isSimAbsent(Context context) {
TelephonyManager phone = (TelephonyManager) context.getSystemService(
Context.TELEPHONY_SERVICE);
return phone.getSimState() == TelephonyManager.SIM_STATE_ABSENT;
}
private static native HalInterfaceVersion native_get_gnss_configuration_version(); private static native HalInterfaceVersion native_get_gnss_configuration_version();
private static native boolean native_set_supl_version(int version); private static native boolean native_set_supl_version(int version);

View File

@@ -126,6 +126,7 @@ import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
/** /**
* A GNSS implementation of LocationProvider used by LocationManager. * A GNSS implementation of LocationProvider used by LocationManager.
@@ -359,8 +360,9 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
} }
} }
if (isKeepLppProfile) { if (isKeepLppProfile) {
// load current properties for the carrier // load current properties for the carrier of ddSubId
mGnssConfiguration.loadPropertiesFromCarrierConfig(); mGnssConfiguration.loadPropertiesFromCarrierConfig(/* inEmergency= */ false,
/* activeSubId= */ -1);
String lpp_profile = mGnssConfiguration.getLppProfile(); String lpp_profile = mGnssConfiguration.getLppProfile();
// set the persist property LPP_PROFILE for the value // set the persist property LPP_PROFILE for the value
if (lpp_profile != null) { if (lpp_profile != null) {
@@ -431,13 +433,38 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
// this approach is just fine because events are posted to our handler anyway // this approach is just fine because events are posted to our handler anyway
mGnssConfiguration = mGnssNative.getConfiguration(); mGnssConfiguration = mGnssNative.getConfiguration();
// Create a GPS net-initiated handler (also needed by handleInitialize) // Create a GPS net-initiated handler (also needed by handleInitialize)
GpsNetInitiatedHandler.EmergencyCallCallback emergencyCallCallback =
new GpsNetInitiatedHandler.EmergencyCallCallback() {
@Override
public void onEmergencyCallStart(int subId) {
if (!mGnssConfiguration.isActiveSimEmergencySuplEnabled()) {
return;
}
mHandler.post(() -> mGnssConfiguration.reloadGpsProperties(
mNIHandler.getInEmergency(), subId));
}
@Override
public void onEmergencyCallEnd() {
if (!mGnssConfiguration.isActiveSimEmergencySuplEnabled()) {
return;
}
mHandler.postDelayed(() -> mGnssConfiguration.reloadGpsProperties(
/* inEmergency= */ false,
SubscriptionManager.getDefaultDataSubscriptionId()),
TimeUnit.SECONDS.toMillis(mGnssConfiguration.getEsExtensionSec()));
}
};
mNIHandler = new GpsNetInitiatedHandler(context, mNIHandler = new GpsNetInitiatedHandler(context,
mNetInitiatedListener, mNetInitiatedListener,
emergencyCallCallback,
mSuplEsEnabled); mSuplEsEnabled);
// Trigger PSDS data download when the network comes up after booting. // Trigger PSDS data download when the network comes up after booting.
mPendingDownloadPsdsTypes.add(GnssPsdsDownloader.LONG_TERM_PSDS_SERVER_INDEX); mPendingDownloadPsdsTypes.add(GnssPsdsDownloader.LONG_TERM_PSDS_SERVER_INDEX);
mNetworkConnectivityHandler = new GnssNetworkConnectivityHandler(context, mNetworkConnectivityHandler = new GnssNetworkConnectivityHandler(context,
GnssLocationProvider.this::onNetworkAvailable, mHandler.getLooper(), mNIHandler); GnssLocationProvider.this::onNetworkAvailable,
mHandler.getLooper(), mNIHandler);
mNtpTimeHelper = new NtpTimeHelper(mContext, mHandler.getLooper(), this); mNtpTimeHelper = new NtpTimeHelper(mContext, mHandler.getLooper(), this);
mGnssSatelliteBlocklistHelper = mGnssSatelliteBlocklistHelper =
@@ -1694,9 +1721,12 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
int type = AGPS_SETID_TYPE_NONE; int type = AGPS_SETID_TYPE_NONE;
String setId = null; String setId = null;
int ddSubId = SubscriptionManager.getDefaultDataSubscriptionId(); int subId = SubscriptionManager.getDefaultDataSubscriptionId();
if (SubscriptionManager.isValidSubscriptionId(ddSubId)) { if (mNIHandler.getInEmergency() && mNetworkConnectivityHandler.getActiveSubId() >= 0) {
phone = phone.createForSubscriptionId(ddSubId); subId = mNetworkConnectivityHandler.getActiveSubId();
}
if (SubscriptionManager.isValidSubscriptionId(subId)) {
phone = phone.createForSubscriptionId(subId);
} }
if ((flags & AGPS_REQUEST_SETID_IMSI) == AGPS_REQUEST_SETID_IMSI) { if ((flags & AGPS_REQUEST_SETID_IMSI) == AGPS_REQUEST_SETID_IMSI) {
setId = phone.getSubscriberId(); setId = phone.getSubscriberId();

View File

@@ -190,7 +190,7 @@ class GnssNetworkConnectivityHandler {
mContext = context; mContext = context;
mGnssNetworkListener = gnssNetworkListener; mGnssNetworkListener = gnssNetworkListener;
SubscriptionManager subManager = mContext.getSystemService(SubscriptionManager.class); SubscriptionManager subManager = mContext.getSystemService(SubscriptionManager.class);
if (subManager != null) { if (subManager != null) {
subManager.addOnSubscriptionsChangedListener(mOnSubscriptionsChangeListener); subManager.addOnSubscriptionsChangedListener(mOnSubscriptionsChangeListener);
} }
@@ -310,6 +310,13 @@ class GnssNetworkConnectivityHandler {
return activeNetworkInfo != null && activeNetworkInfo.isConnected(); return activeNetworkInfo != null && activeNetworkInfo.isConnected();
} }
/**
* Returns the active Sub ID for emergency SUPL connection.
*/
int getActiveSubId() {
return mActiveSubId;
}
/** /**
* Called from native code to update AGPS connection status, or to request or release a SUPL * Called from native code to update AGPS connection status, or to request or release a SUPL
* connection. * connection.