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

Commit 02d3afb3 authored by Brad Ebinger's avatar Brad Ebinger Committed by Android (Google) Code Review
Browse files

Merge "Allow for call direction updates in Telecom" into rvc-dev

parents 5a0afa15 5eeefc7f
Loading
Loading
Loading
Loading
+22 −1
Original line number Diff line number Diff line
@@ -130,6 +130,7 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
        void onExtrasRemoved(Call c, int source, List<String> keys);
        void onHandleChanged(Call call);
        void onCallerDisplayNameChanged(Call call);
        void onCallDirectionChanged(Call call);
        void onVideoStateChanged(Call call, int previousVideoState, int newVideoState);
        void onTargetPhoneAccountChanged(Call call);
        void onConnectionManagerPhoneAccountChanged(Call call);
@@ -197,6 +198,8 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
        @Override
        public void onCallerDisplayNameChanged(Call call) {}
        @Override
        public void onCallDirectionChanged(Call call) {}
        @Override
        public void onVideoStateChanged(Call call, int previousVideoState, int newVideoState) {}
        @Override
        public void onTargetPhoneAccountChanged(Call call) {}
@@ -258,7 +261,7 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
    /**
     * One of CALL_DIRECTION_INCOMING, CALL_DIRECTION_OUTGOING, or CALL_DIRECTION_UNKNOWN
     */
    private final int mCallDirection;
    private int mCallDirection;

    /**
     * The post-dial digits that were dialed after the network portion of the number
@@ -3631,6 +3634,24 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
        }
    }

    /**
     * Change the call direction. This is useful if it was not previously defined (for example in
     * single caller emulation mode).
     * @param callDirection The new direction of this call.
     */
    // Make sure the callDirection has been mapped to the Call definition correctly!
    public void setCallDirection(int callDirection) {
        if (mCallDirection != callDirection) {
            Log.addEvent(this, LogUtils.Events.CALL_DIRECTION_CHANGED, "callDirection="
                    + callDirection);
            mCallDirection = callDirection;
            for (Listener l : mListeners) {
                // Update InCallService directly, do not notify CallsManager.
                l.onCallDirectionChanged(this);
            }
        }
    }

    /**
     * Sets the video history based on the state and state transitions of the call. Always add the
     * current video state to the video state history during a call transition except for the
+30 −0
Original line number Diff line number Diff line
@@ -1084,6 +1084,7 @@ public class ConnectionServiceWrapper extends ServiceBinder implements
            if (mContext.checkCallingOrSelfPermission(MODIFY_PHONE_STATE)
                    != PackageManager.PERMISSION_GRANTED) {
                Log.w(this, "setConferenceState from caller without permission.");
                Log.endSession();
                return;
            }

@@ -1103,6 +1104,35 @@ public class ConnectionServiceWrapper extends ServiceBinder implements
                Log.endSession();
            }
        }

        @Override
        public void setCallDirection(String callId, int direction, Session.Info sessionInfo) {
            Log.startSession(sessionInfo, "CSW.sCD");

            if (mContext.checkCallingOrSelfPermission(MODIFY_PHONE_STATE)
                    != PackageManager.PERMISSION_GRANTED) {
                Log.w(this, "setCallDirection from caller without permission.");
                Log.endSession();
                return;
            }

            long token = Binder.clearCallingIdentity();
            try {
                synchronized (mLock) {
                    logIncoming("setCallDirection %s %d", callId, direction);
                    Call call = mCallIdMapper.getCall(callId);
                    if (call != null) {
                        call.setCallDirection(Call.getRemappedCallDirection(direction));
                    }
                }
            } catch (Throwable t) {
                Log.e(ConnectionServiceWrapper.this, t, "");
                throw t;
            } finally {
                Binder.restoreCallingIdentity(token);
                Log.endSession();
            }
        }
    }

    private final Adapter mAdapter = new Adapter();
+5 −0
Original line number Diff line number Diff line
@@ -801,6 +801,11 @@ public class InCallController extends CallsManagerListenerBase {
            updateCall(call);
        }

        @Override
        public void onCallDirectionChanged(Call call) {
            updateCall(call);
        }

        @Override
        public void onVideoStateChanged(Call call, int previousVideoState, int newVideoState) {
            updateCall(call);
+1 −0
Original line number Diff line number Diff line
@@ -136,6 +136,7 @@ public class LogUtils {
        public static final String REMOVE_CHILD = "REMOVE_CHILD";
        public static final String SET_PARENT = "SET_PARENT";
        public static final String CONF_STATE_CHANGED = "CONF_STATE_CHANGED";
        public static final String CALL_DIRECTION_CHANGED = "CALL_DIRECTION_CHANGED";
        public static final String MUTE = "MUTE";
        public static final String UNMUTE = "UNMUTE";
        public static final String AUDIO_ROUTE = "AUDIO_ROUTE";
+32 −0
Original line number Diff line number Diff line
@@ -301,4 +301,36 @@ public class CallTest extends TelecomTestCase {
        verify(mMockConnectionService, never()).pullExternalCall(any());
        verify(mMockToast).show();
    }

    @Test
    @SmallTest
    public void testCallDirection() {
        Call call = new Call(
                "1", /* callId */
                mContext,
                mMockCallsManager,
                mLock,
                null /* ConnectionServiceRepository */,
                mMockPhoneNumberUtilsAdapter,
                TEST_ADDRESS,
                null /* GatewayInfo */,
                null /* connectionManagerPhoneAccountHandle */,
                SIM_1_HANDLE,
                Call.CALL_DIRECTION_UNDEFINED,
                false /* shouldAttachToExistingConnection*/,
                true /* isConference */,
                mMockClockProxy,
                mMockToastProxy);
        boolean[] hasCallDirectionChanged = new boolean[1];
        call.addListener(new Call.ListenerBase() {
            @Override
            public void onCallDirectionChanged(Call call) {
                hasCallDirectionChanged[0] = true;
            }
        });
        assertFalse(call.isIncoming());
        call.setCallDirection(Call.CALL_DIRECTION_INCOMING);
        assertTrue(hasCallDirectionChanged[0]);
        assertTrue(call.isIncoming());
    }
}