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

Commit 39eda27e authored by Fabian Kozynski's avatar Fabian Kozynski Committed by Android (Google) Code Review
Browse files

Merge "Unbind TileService onNullBinding" into main

parents ec75adac b9807f01
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -278,6 +278,11 @@ public class TileLifecycleManager extends BroadcastReceiver implements
        handlePendingMessages();
    }

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

    @Override
    public void onServiceDisconnected(ComponentName name) {
        if (DEBUG) Log.d(TAG, "onServiceDisconnected " + name);
+25 −0
Original line number Diff line number Diff line
@@ -403,6 +403,31 @@ public class TileLifecycleManagerTest extends SysuiTestCase {
        verify(falseContext).bindServiceAsUser(any(), any(), eq(flags), any());
    }

    @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,
                mActivityManager,
                mExecutor);

        manager.executeSetBindService(true);
        mExecutor.runAllReady();

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

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

    private void mockChangeEnabled(long changeId, boolean enabled) {
        doReturn(enabled).when(() -> CompatChanges.isChangeEnabled(eq(changeId), anyString(),
                any(UserHandle.class)));