Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 40c3beca authored by Yu-Han Yang's avatar Yu-Han Yang Committed by Android (Google) Code Review
Browse files

Merge "Release SUPL connection after timeout" into main

parents 2562d562 608dacd4
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -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 −0
Original line number Diff line number Diff line
@@ -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;
        }