Skip to content
Snippets Groups Projects
Commit 608dacd4 authored by Yu-Han Yang's avatar Yu-Han Yang
Browse files

Release SUPL connection after timeout

Bug: 315024652
Test: on device
Change-Id: I0ef6b3e0c9eb6de4ea018c0b88e7527455ed0540
parent a338097c
No related branches found
No related tags found
No related merge requests found
......@@ -20,3 +20,10 @@ flag {
description: "Flag for GnssMeasurementRequest WorkSource API"
bug: "295235160"
}
flag {
name: "release_supl_connection_on_timeout"
namespace: "location"
description: "Flag for releasing SUPL connection on timeout"
bug: "315024652"
}
......@@ -19,6 +19,7 @@ package com.android.server.location.gnss;
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED;
import android.content.Context;
import android.location.flags.Flags;
import android.net.ConnectivityManager;
import android.net.LinkAddress;
import android.net.LinkProperties;
......@@ -48,6 +49,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
* Handles network connection requests and network state change updates for AGPS data download.
......@@ -91,6 +93,10 @@ class GnssNetworkConnectivityHandler {
// network with SUPL connectivity or report an error.
private static final int SUPL_NETWORK_REQUEST_TIMEOUT_MILLIS = 20 * 1000;
// If the chipset does not request to release a SUPL connection before the specified timeout in
// milliseconds, the connection will be automatically released.
private static final long SUPL_CONNECTION_TIMEOUT_MILLIS = TimeUnit.MINUTES.toMillis(1);
private static final int HASH_MAP_INITIAL_CAPACITY_TO_TRACK_CONNECTED_NETWORKS = 5;
// Keeps track of networks and their state as notified by the network request callbacks.
......@@ -121,6 +127,8 @@ class GnssNetworkConnectivityHandler {
private static final long WAKELOCK_TIMEOUT_MILLIS = 60 * 1000;
private final PowerManager.WakeLock mWakeLock;
private final Object mSuplConnectionReleaseOnTimeoutToken = new Object();
/**
* Network attributes needed when updating HAL about network connectivity status changes.
*/
......@@ -609,6 +617,13 @@ class GnssNetworkConnectivityHandler {
mSuplConnectivityCallback,
mHandler,
SUPL_NETWORK_REQUEST_TIMEOUT_MILLIS);
if (Flags.releaseSuplConnectionOnTimeout()) {
// Schedule to release the SUPL connection after timeout
mHandler.removeCallbacksAndMessages(mSuplConnectionReleaseOnTimeoutToken);
mHandler.postDelayed(() -> handleReleaseSuplConnection(GPS_RELEASE_AGPS_DATA_CONN),
mSuplConnectionReleaseOnTimeoutToken,
SUPL_CONNECTION_TIMEOUT_MILLIS);
}
} catch (RuntimeException e) {
Log.e(TAG, "Failed to request network.", e);
mSuplConnectivityCallback = null;
......@@ -639,6 +654,10 @@ class GnssNetworkConnectivityHandler {
Log.d(TAG, message);
}
if (Flags.releaseSuplConnectionOnTimeout()) {
// Remove pending task to avoid releasing an incorrect connection
mHandler.removeCallbacksAndMessages(mSuplConnectionReleaseOnTimeoutToken);
}
if (mAGpsDataConnectionState == AGPS_DATA_CONNECTION_CLOSED) {
return;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment