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

Commit b16d4d73 authored by Fabian Kozynski's avatar Fabian Kozynski Committed by Automerger Merge Worker
Browse files

Merge "Unbind TileService onNullBinding" into tm-dev am: 53eeb6ec

parents 06a01901 53eeb6ec
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -242,6 +242,11 @@ public class TileLifecycleManager extends BroadcastReceiver implements
        handlePendingMessages();
    }

    @Override
    public void onNullBinding(ComponentName name) {
        setBindService(false);
    }

    @Override
    public void onServiceDisconnected(ComponentName name) {
        if (DEBUG) Log.d(TAG, "onServiceDisconnected " + name);
+21 −0
Original line number Diff line number Diff line
@@ -290,6 +290,27 @@ public class TileLifecycleManagerTest extends SysuiTestCase {
        verify(falseContext).unbindService(captor.getValue());
    }

    @Test
    public void testNullBindingCallsUnbind() {
        Context mockContext = mock(Context.class);
        // Binding has to succeed
        when(mockContext.bindServiceAsUser(any(), any(), anyInt(), any())).thenReturn(true);
        TileLifecycleManager manager = new TileLifecycleManager(mHandler, mockContext,
                mock(IQSService.class),
                mMockPackageManagerAdapter,
                mMockBroadcastDispatcher,
                mTileServiceIntent,
                mUser);

        manager.setBindService(true);

        ArgumentCaptor<ServiceConnection> captor = ArgumentCaptor.forClass(ServiceConnection.class);
        verify(mockContext).bindServiceAsUser(any(), captor.capture(), anyInt(), any());

        captor.getValue().onNullBinding(mTileServiceComponentName);
        verify(mockContext).unbindService(captor.getValue());
    }

    private static class TestContextWrapper extends ContextWrapper {
        private IntentFilter mLastIntentFilter;
        private int mLastFlag;