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

Commit 724467e2 authored by wilsonshih's avatar wilsonshih
Browse files

Schedules the removal of pending requests...

...when the remote service unbinds. This prevents requests from queuing
up indefinitely and consuming significant memory.

Bug: 441398542
Flag: EXEMPT bugfix
Test: NA
Change-Id: Id8fe4dd1d734fcc409be93444f825c606fd0e630
parent c89bedf7
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -43,7 +43,8 @@ public abstract class AbstractMultiplePendingRequestsRemoteService<S

    private final int mInitialCapacity;

    protected @NonNull List<BasePendingRequest<S, I>> mPendingRequests;
    protected final @NonNull List<BasePendingRequest<S, I>> mPendingRequests;
    private static final long PENDING_REQUEST_TIMEOUT_MS = 5000;

    public AbstractMultiplePendingRequestsRemoteService(@NonNull Context context,
            @NonNull String serviceInterface, @NonNull ComponentName componentName, int userId,
@@ -114,6 +115,18 @@ public abstract class AbstractMultiplePendingRequestsRemoteService<S
                Slog.v(mTag,
                        "queued " + mPendingRequests.size() + " requests; last=" + pendingRequest);
            }
            final Runnable handleTimeout = () -> {
                synchronized (mPendingRequests) {
                    if (mPendingRequests.remove(pendingRequest)) {
                        if (mVerbose) {
                            Slog.v(mTag, "pendingRequest timeout, remove");
                        }
                        pendingRequest.onFailed();
                        pendingRequest.finish();
                    }
                }
            };
            mHandler.postDelayed(handleTimeout, PENDING_REQUEST_TIMEOUT_MS);
        }
    }
}