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

Commit c9cf5440 authored by Hall Liu's avatar Hall Liu
Browse files

Add lock to NewOutgoingCallBroadcastIntentReceiver

Synchronize on main Telecom lock when processing the returning ordered
broadcast.

Change-Id: Ic63efc9fb6d2e17bf1ca40c118594531054db985
Fixes: 29424036
parent fc130b27
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -2035,6 +2035,10 @@ public class CallsManager extends Call.ListenerBase
        }
    }

    public TelecomSystem.SyncRoot getLock() {
        return mLock;
    }

    private void reloadMissedCallsOfUser(UserHandle userHandle) {
        mMissedCallNotifier.reloadFromDatabase(
                mLock, this, mContactsAsyncHelper, mCallerInfoAsyncQueryFactory, userHandle);
+55 −56
Original line number Diff line number Diff line
@@ -55,9 +55,6 @@ import com.android.internal.annotations.VisibleForTesting;
 */
@VisibleForTesting
public class NewOutgoingCallIntentBroadcaster {
    private static final String EXTRA_ACTUAL_NUMBER_TO_DIAL =
            "android.telecom.extra.ACTUAL_NUMBER_TO_DIAL";

    /**
     * Legacy string constants used to retrieve gateway provider extras from intents. These still
     * need to be copied from the source call intent to the destination intent in order to
@@ -67,14 +64,13 @@ public class NewOutgoingCallIntentBroadcaster {
    public static final String EXTRA_GATEWAY_PROVIDER_PACKAGE =
            "com.android.phone.extra.GATEWAY_PROVIDER_PACKAGE";
    public static final String EXTRA_GATEWAY_URI = "com.android.phone.extra.GATEWAY_URI";
    public static final String EXTRA_GATEWAY_ORIGINAL_URI =
            "com.android.phone.extra.GATEWAY_ORIGINAL_URI";

    private final CallsManager mCallsManager;
    private final Call mCall;
    private final Intent mIntent;
    private final Context mContext;
    private final PhoneNumberUtilsAdapter mPhoneNumberUtilsAdapter;
    private final TelecomSystem.SyncRoot mLock;

    /*
     * Whether or not the outgoing call intent originated from the default phone application. If
@@ -92,6 +88,7 @@ public class NewOutgoingCallIntentBroadcaster {
        mIntent = intent;
        mPhoneNumberUtilsAdapter = phoneNumberUtilsAdapter;
        mIsDefaultOrSystemPhoneApp = isDefaultPhoneApp;
        mLock = mCallsManager.getLock();
    }

    /**
@@ -105,10 +102,11 @@ public class NewOutgoingCallIntentBroadcaster {
            try {
                Log.startSession("NOCBIR.oR");
                Trace.beginSection("onReceiveNewOutgoingCallBroadcast");
                synchronized (mLock) {
                    Log.v(this, "onReceive: %s", intent);

                // Once the NEW_OUTGOING_CALL broadcast is finished, the resultData is used as the
                // actual number to call. (If null, no call will be placed.)
                    // Once the NEW_OUTGOING_CALL broadcast is finished, the resultData is
                    // used as the actual number to call. (If null, no call will be placed.)
                    String resultNumber = getResultData();
                    Log.i(this, "Received new-outgoing-call-broadcast for %s with data %s", mCall,
                            Log.pii(resultNumber));
@@ -133,8 +131,8 @@ public class NewOutgoingCallIntentBroadcaster {

                    // If this call is already disconnected then we have nothing more to do.
                    if (mCall.isDisconnected()) {
                    Log.w(this,
                        "Call has already been disconnected, ignore the broadcast Call %s", mCall);
                        Log.w(this, "Call has already been disconnected," +
                                        " ignore the broadcast Call %s", mCall);
                        return;
                    }

@@ -146,10 +144,11 @@ public class NewOutgoingCallIntentBroadcaster {
                    Uri originalUri = mIntent.getData();

                    if (originalUri.getSchemeSpecificPart().equals(resultNumber)) {
                    Log.v(this, "Call number unmodified after new outgoing call intent broadcast.");
                        Log.v(this, "Call number unmodified after" +
                                " new outgoing call intent broadcast.");
                    } else {
                    Log.v(this, "Retrieved modified handle after outgoing call intent broadcast: "
                                    + "Original: %s, Modified: %s",
                        Log.v(this, "Retrieved modified handle after outgoing call intent" +
                                " broadcast: Original: %s, Modified: %s",
                                Log.pii(originalUri),
                                Log.pii(resultHandleUri));
                    }
@@ -157,11 +156,11 @@ public class NewOutgoingCallIntentBroadcaster {
                    GatewayInfo gatewayInfo = getGateWayInfoFromIntent(intent, resultHandleUri);
                    mCall.setNewOutgoingCallIntentBroadcastIsDone();
                    mCallsManager.placeOutgoingCall(mCall, resultHandleUri, gatewayInfo,
                        mIntent.getBooleanExtra(TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE,
                                false),
                            mIntent.getBooleanExtra(
                                    TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, false),
                            mIntent.getIntExtra(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE,
                                    VideoProfile.STATE_AUDIO_ONLY));

                }
            } finally {
                Trace.endSection();
                Log.endSession();
+2 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import com.android.server.telecom.CallsManager;
import com.android.server.telecom.NewOutgoingCallIntentBroadcaster;
import com.android.server.telecom.PhoneNumberUtilsAdapter;
import com.android.server.telecom.PhoneNumberUtilsAdapterImpl;
import com.android.server.telecom.TelecomSystem;

import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
@@ -77,6 +78,7 @@ public class NewOutgoingCallIntentBroadcasterTest extends TelecomTestCase {
        mContext = mComponentContextFixture.getTestDouble().getApplicationContext();
        mPhoneNumberUtilsAdapterSpy = spy(new PhoneNumberUtilsAdapterImpl());
        when(mCall.getInitiatingUser()).thenReturn(UserHandle.CURRENT);
        when(mCallsManager.getLock()).thenReturn(new TelecomSystem.SyncRoot() { });
    }

    @SmallTest