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

Commit 0d53dda2 authored by Hunsuk Choi's avatar Hunsuk Choi
Browse files

Update unit test of DomainSelectionController

Bug: 319995092
Test: atest DomainSelectionControllerTest
Change-Id: Ide8248ae5e90c4e6bd6e4d5c8f7a9778e9fa5769
parent 9e935a83
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -101,6 +101,7 @@ public class DomainSelectionController {

    private ExponentialBackoff mBackoff;
    private boolean mBackoffStarted = false;
    private boolean mUnbind = false;

    // Retry the bind to the DomainSelectionService that has died after mBindRetry timeout.
    private Runnable mRestartBindingRunnable = new Runnable() {
@@ -470,12 +471,14 @@ public class DomainSelectionController {
     */
    public boolean bind(@NonNull ComponentName componentName) {
        mComponentName = componentName;
        mUnbind = false;
        return bind();
    }

    private boolean bind() {
        logd("bind isBindingOrBound=" + mIsBound);
        synchronized (mLock) {
            if (mUnbind) return false;
            if (!mIsBound) {
                mIsBound = true;
                Intent serviceIntent = new Intent(DomainSelectionService.SERVICE_INTERFACE)
@@ -512,6 +515,7 @@ public class DomainSelectionController {
     */
    public void unbind() {
        synchronized (mLock) {
            mUnbind = true;
            stopBackoffTimer();
            mIsBound = false;
            setServiceController(null);
@@ -548,7 +552,8 @@ public class DomainSelectionController {
    }

    private void notifyBindFailure() {
        logi("notifyBindFailure " + mBackoffStarted);
        logi("notifyBindFailure started=" + mBackoffStarted + ", unbind=" + mUnbind);
        if (mUnbind) return;
        if (mBackoffStarted) {
            mBackoff.notifyFailed();
        } else {
+18 −0
Original line number Diff line number Diff line
@@ -246,6 +246,24 @@ public class DomainSelectionControllerTest extends TelephonyTest {
        verify(mMockContext, times(1)).bindService(any(), any(), anyInt());
    }

    /**
     * Ensure that calling unbind stops automatic rebind from occurring.
     */
    @SmallTest
    @Test
    public void testUnbindCauseAutoBindCancelAfterBinderDied() throws RemoteException {
        ServiceConnection conn = bindAndConnectService();

        conn.onBindingDied(null /*null*/);
        mTestController.unbind();

        long delay = mTestController.getBindDelay();
        waitForHandlerActionDelayed(mHandler, delay, 2 * delay);

        // Unbind should stop the autobind from occurring.
        verify(mMockContext, times(1)).bindService(any(), any(), anyInt());
    }

    private void bindAndNullServiceError() {
        ServiceConnection connection = bindService(mTestComponentName);
        connection.onNullBinding(mTestComponentName);