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

Commit 40f4564a authored by Pranav Madapurmath's avatar Pranav Madapurmath Committed by Automerger Merge Worker
Browse files

Call Redirection: unbind service when onBind returns null am: c3580d96 am:...

Call Redirection: unbind service when onBind returns null am: c3580d96 am: 97392ff5 am: feb31d54 am: 1e9d666b

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/services/Telecomm/+/22183547



Change-Id: I801553195967efd2a26f4addce13750431cd2f9a
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 0e0ae89a 1e9d666b
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -151,6 +151,19 @@ public class CallRedirectionProcessor implements CallRedirectionCallback {
                    Log.endSession();
                }
            }

            @Override
            public void onNullBinding(ComponentName componentName) {
                // Make sure we unbind the service if onBind returns null
                Log.startSession("CRSC.oNB");
                try {
                    synchronized (mTelecomLock) {
                        finishCallRedirection();
                    }
                } finally {
                    Log.endSession();
                }
            }
        }

        private class CallRedirectionAdapter extends ICallRedirectionAdapter.Stub {
+24 −0
Original line number Diff line number Diff line
@@ -352,4 +352,28 @@ public class CallRedirectionProcessorTest extends TelecomTestCase {
        assertEquals(REDIRECTED_GATEWAY_NUMBER_WITH_POST_DIAL,
                gatewayInfoArgumentCaptor.getValue().getGatewayAddress());
    }

    @Test
    public void testUnbindOnNullBind() throws Exception {
        startProcessWithNoGateWayInfo();
        // To make sure tests are not flaky, clean all the previous handler messages
        waitForHandlerAction(mProcessor.getHandler(), HANDLER_TIMEOUT_DELAY);
        enableUserDefinedCallRedirectionService();
        disableCarrierCallRedirectionService();

        mProcessor.performCallRedirection();

        // Capture the binder
        ArgumentCaptor<ServiceConnection> serviceConnectionCaptor = ArgumentCaptor.forClass(
                ServiceConnection.class);
        // Verify binding occurred
        verify(mContext, times(1)).bindServiceAsUser(any(Intent.class),
                serviceConnectionCaptor.capture(), anyInt(), eq(UserHandle.CURRENT));
        // Simulate null return from onBind
        serviceConnectionCaptor.getValue().onNullBinding(USER_DEFINED_SERVICE_TEST_COMPONENT_NAME);

        // Verify service was unbound
        verify(mContext, times(1)).
                unbindService(any(ServiceConnection.class));
    }
}