Loading packages/SystemUI/src/com/android/systemui/controls/controller/ControlsProviderLifecycleManager.kt +5 −1 Original line number Diff line number Diff line Loading @@ -97,7 +97,11 @@ class ControlsProviderLifecycleManager( } bindTryCount++ try { context.bindServiceAsUser(intent, serviceConnection, BIND_FLAGS, user) val bound = context .bindServiceAsUser(intent, serviceConnection, BIND_FLAGS, user) if (!bound) { context.unbindService(serviceConnection) } } catch (e: SecurityException) { Log.e(TAG, "Failed to bind to service", e) } Loading packages/SystemUI/src/com/android/systemui/qs/external/TileLifecycleManager.java +3 −0 Original line number Diff line number Diff line Loading @@ -204,6 +204,9 @@ public class TileLifecycleManager extends BroadcastReceiver implements | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS | Context.BIND_WAIVE_PRIORITY, mUser); if (!mIsBound) { mContext.unbindService(this); } } catch (SecurityException e) { Log.e(TAG, "Failed to bind to service", e); mIsBound = false; Loading packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsProviderLifecycleManagerTest.kt +21 −0 Original line number Diff line number Diff line Loading @@ -210,4 +210,25 @@ class ControlsProviderLifecycleManagerTest : SysuiTestCase() { eq(actionCallbackService)) assertEquals(action, wrapperCaptor.getValue().getWrappedAction()) } @Test fun testFalseBindCallsUnbind() { val falseContext = mock(Context::class.java) `when`(falseContext.bindServiceAsUser(any(), any(), anyInt(), any())).thenReturn(false) val manager = ControlsProviderLifecycleManager( falseContext, executor, actionCallbackService, UserHandle.of(0), componentName ) manager.bindService() executor.runAllReady() val captor = ArgumentCaptor.forClass( ServiceConnection::class.java ) verify(falseContext).bindServiceAsUser(any(), captor.capture(), anyInt(), any()) verify(falseContext).unbindService(captor.value) } } packages/SystemUI/tests/src/com/android/systemui/qs/external/TileLifecycleManagerTest.java +26 −5 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import static org.junit.Assert.assertNotEquals; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; Loading @@ -34,6 +35,7 @@ import android.content.Context; import android.content.ContextWrapper; import android.content.Intent; import android.content.IntentFilter; import android.content.ServiceConnection; import android.content.pm.PackageInfo; import android.content.pm.ServiceInfo; import android.net.Uri; Loading @@ -56,7 +58,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; import org.mockito.ArgumentCaptor; @SmallTest @RunWith(AndroidJUnit4.class) Loading @@ -64,10 +66,10 @@ public class TileLifecycleManagerTest extends SysuiTestCase { private static final int TEST_FAIL_TIMEOUT = 5000; private final PackageManagerAdapter mMockPackageManagerAdapter = Mockito.mock(PackageManagerAdapter.class); mock(PackageManagerAdapter.class); private final BroadcastDispatcher mMockBroadcastDispatcher = Mockito.mock(BroadcastDispatcher.class); private final IQSTileService.Stub mMockTileService = Mockito.mock(IQSTileService.Stub.class); mock(BroadcastDispatcher.class); private final IQSTileService.Stub mMockTileService = mock(IQSTileService.Stub.class); private ComponentName mTileServiceComponentName; private Intent mTileServiceIntent; private UserHandle mUser; Loading Loading @@ -95,7 +97,7 @@ public class TileLifecycleManagerTest extends SysuiTestCase { mThread.start(); mHandler = Handler.createAsync(mThread.getLooper()); mStateManager = new TileLifecycleManager(mHandler, mWrappedContext, Mockito.mock(IQSService.class), mock(IQSService.class), mMockPackageManagerAdapter, mMockBroadcastDispatcher, mTileServiceIntent, Loading Loading @@ -269,6 +271,25 @@ public class TileLifecycleManagerTest extends SysuiTestCase { assertTrue(mStateManager.isToggleableTile()); } @Test public void testFalseBindCallsUnbind() { Context falseContext = mock(Context.class); when(falseContext.bindServiceAsUser(any(), any(), anyInt(), any())).thenReturn(false); TileLifecycleManager manager = new TileLifecycleManager(mHandler, falseContext, mock(IQSService.class), mMockPackageManagerAdapter, mMockBroadcastDispatcher, mTileServiceIntent, mUser); manager.setBindService(true); ArgumentCaptor<ServiceConnection> captor = ArgumentCaptor.forClass(ServiceConnection.class); verify(falseContext).bindServiceAsUser(any(), captor.capture(), anyInt(), any()); verify(falseContext).unbindService(captor.getValue()); } private static class TestContextWrapper extends ContextWrapper { private IntentFilter mLastIntentFilter; private int mLastFlag; Loading Loading
packages/SystemUI/src/com/android/systemui/controls/controller/ControlsProviderLifecycleManager.kt +5 −1 Original line number Diff line number Diff line Loading @@ -97,7 +97,11 @@ class ControlsProviderLifecycleManager( } bindTryCount++ try { context.bindServiceAsUser(intent, serviceConnection, BIND_FLAGS, user) val bound = context .bindServiceAsUser(intent, serviceConnection, BIND_FLAGS, user) if (!bound) { context.unbindService(serviceConnection) } } catch (e: SecurityException) { Log.e(TAG, "Failed to bind to service", e) } Loading
packages/SystemUI/src/com/android/systemui/qs/external/TileLifecycleManager.java +3 −0 Original line number Diff line number Diff line Loading @@ -204,6 +204,9 @@ public class TileLifecycleManager extends BroadcastReceiver implements | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS | Context.BIND_WAIVE_PRIORITY, mUser); if (!mIsBound) { mContext.unbindService(this); } } catch (SecurityException e) { Log.e(TAG, "Failed to bind to service", e); mIsBound = false; Loading
packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsProviderLifecycleManagerTest.kt +21 −0 Original line number Diff line number Diff line Loading @@ -210,4 +210,25 @@ class ControlsProviderLifecycleManagerTest : SysuiTestCase() { eq(actionCallbackService)) assertEquals(action, wrapperCaptor.getValue().getWrappedAction()) } @Test fun testFalseBindCallsUnbind() { val falseContext = mock(Context::class.java) `when`(falseContext.bindServiceAsUser(any(), any(), anyInt(), any())).thenReturn(false) val manager = ControlsProviderLifecycleManager( falseContext, executor, actionCallbackService, UserHandle.of(0), componentName ) manager.bindService() executor.runAllReady() val captor = ArgumentCaptor.forClass( ServiceConnection::class.java ) verify(falseContext).bindServiceAsUser(any(), captor.capture(), anyInt(), any()) verify(falseContext).unbindService(captor.value) } }
packages/SystemUI/tests/src/com/android/systemui/qs/external/TileLifecycleManagerTest.java +26 −5 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import static org.junit.Assert.assertNotEquals; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; Loading @@ -34,6 +35,7 @@ import android.content.Context; import android.content.ContextWrapper; import android.content.Intent; import android.content.IntentFilter; import android.content.ServiceConnection; import android.content.pm.PackageInfo; import android.content.pm.ServiceInfo; import android.net.Uri; Loading @@ -56,7 +58,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; import org.mockito.ArgumentCaptor; @SmallTest @RunWith(AndroidJUnit4.class) Loading @@ -64,10 +66,10 @@ public class TileLifecycleManagerTest extends SysuiTestCase { private static final int TEST_FAIL_TIMEOUT = 5000; private final PackageManagerAdapter mMockPackageManagerAdapter = Mockito.mock(PackageManagerAdapter.class); mock(PackageManagerAdapter.class); private final BroadcastDispatcher mMockBroadcastDispatcher = Mockito.mock(BroadcastDispatcher.class); private final IQSTileService.Stub mMockTileService = Mockito.mock(IQSTileService.Stub.class); mock(BroadcastDispatcher.class); private final IQSTileService.Stub mMockTileService = mock(IQSTileService.Stub.class); private ComponentName mTileServiceComponentName; private Intent mTileServiceIntent; private UserHandle mUser; Loading Loading @@ -95,7 +97,7 @@ public class TileLifecycleManagerTest extends SysuiTestCase { mThread.start(); mHandler = Handler.createAsync(mThread.getLooper()); mStateManager = new TileLifecycleManager(mHandler, mWrappedContext, Mockito.mock(IQSService.class), mock(IQSService.class), mMockPackageManagerAdapter, mMockBroadcastDispatcher, mTileServiceIntent, Loading Loading @@ -269,6 +271,25 @@ public class TileLifecycleManagerTest extends SysuiTestCase { assertTrue(mStateManager.isToggleableTile()); } @Test public void testFalseBindCallsUnbind() { Context falseContext = mock(Context.class); when(falseContext.bindServiceAsUser(any(), any(), anyInt(), any())).thenReturn(false); TileLifecycleManager manager = new TileLifecycleManager(mHandler, falseContext, mock(IQSService.class), mMockPackageManagerAdapter, mMockBroadcastDispatcher, mTileServiceIntent, mUser); manager.setBindService(true); ArgumentCaptor<ServiceConnection> captor = ArgumentCaptor.forClass(ServiceConnection.class); verify(falseContext).bindServiceAsUser(any(), captor.capture(), anyInt(), any()); verify(falseContext).unbindService(captor.getValue()); } private static class TestContextWrapper extends ContextWrapper { private IntentFilter mLastIntentFilter; private int mLastFlag; Loading