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

Commit 3b93880c authored by Fabián Kozynski's avatar Fabián Kozynski Committed by Fabian Kozynski
Browse files

Unbind TileService onNullBinding

Test: atest TileLifecycleManagerTest
Test: manual: adb shell dumpsys activity service
Test: sts test
Bug: 300903792
Change-Id: Ia8126ac65432b124683960e3ebf47301ba6172a1
Merged-In: Ia8126ac65432b124683960e3ebf47301ba6172a1
parent 22454204
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;