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

Commit 99bafb0d authored by Derek Jedral's avatar Derek Jedral Committed by Android (Google) Code Review
Browse files

Merge "Debounce multiple rapid suggestion requests" into main

parents 1c4a065b 50a832ae
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
public class LocalMediaManager implements BluetoothCallback {
    private static final String TAG = "LocalMediaManager";
    private static final int MAX_DISCONNECTED_DEVICE_NUM = 5;
    private static final int MIN_DURATION_BETWEEN_SUGGESTION_REQUESTS_MILLIS = 5000;

    @Retention(RetentionPolicy.SOURCE)
    @IntDef({MediaDeviceState.STATE_CONNECTED,
@@ -112,6 +113,8 @@ public class LocalMediaManager implements BluetoothCallback {
    @VisibleForTesting
    BluetoothAdapter mBluetoothAdapter;

    private long mLastSuggestionRequestTime = 0L;

    /**
     * Register to start receiving callbacks for MediaDevice events.
     */
@@ -246,7 +249,19 @@ public class LocalMediaManager implements BluetoothCallback {

    /** Requests a suggestion from other routers. */
    public void requestDeviceSuggestion() {
        // Debounce multiple requests in a short duration
        long currentRequestTime = System.currentTimeMillis();
        if (currentRequestTime - mLastSuggestionRequestTime
                > MIN_DURATION_BETWEEN_SUGGESTION_REQUESTS_MILLIS) {
            Log.d(TAG, "requesting device suggestion");
            mLastSuggestionRequestTime = currentRequestTime;
            mInfoMediaManager.requestDeviceSuggestion();
        } else {
            Log.d(
                    TAG,
                    "requestDeviceSuggestion() ignored due to difference between requests: "
                            + (currentRequestTime - mLastSuggestionRequestTime));
        }
    }

    @Nullable