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

Commit 6f26d200 authored by Grace Jia's avatar Grace Jia
Browse files

Avoid array usage in handleConnectionServiceDeath.

When we trying to create a new array by using an array size returned
from a java Collection, we may get weird NegativeArraySizeException.
Instead of create a pending response array, directly use an iterator for
the loop to mark connection as failed.

Bug: b/298029420
Test: atest CreateConnectionProcessorTest
Change-Id: I6ba6b7d7ba12469b1fad3b21531ca8d8f6f7a785
parent 23a939e3
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ import com.android.internal.telecom.RemoteServiceCallback;
import com.android.internal.util.Preconditions;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -2492,12 +2493,11 @@ public class ConnectionServiceWrapper extends ServiceBinder implements
     */
    private void handleConnectionServiceDeath() {
        if (!mPendingResponses.isEmpty()) {
            CreateConnectionResponse[] responses = mPendingResponses.values().toArray(
                    new CreateConnectionResponse[mPendingResponses.values().size()]);
            Collection<CreateConnectionResponse> responses = mPendingResponses.values();
            mPendingResponses.clear();
            for (int i = 0; i < responses.length; i++) {
                responses[i].handleCreateConnectionFailure(
                        new DisconnectCause(DisconnectCause.ERROR, "CS_DEATH"));
            for (CreateConnectionResponse response : responses) {
                response.handleCreateConnectionFailure(new DisconnectCause(DisconnectCause.ERROR,
                        "CS_DEATH"));
            }
        }
        mCallIdMapper.clear();