Loading packages/SystemUI/src/com/android/systemui/util/service/ObservableServiceConnection.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -158,11 +158,11 @@ public class ObservableServiceConnection<T> implements ServiceConnection { try { try { bindResult = mContext.bindServiceAsUser(mServiceIntent, this, mFlags, bindResult = mContext.bindServiceAsUser(mServiceIntent, this, mFlags, mUserTracker.getUserHandle()); mUserTracker.getUserHandle()); mBoundCalled = true; } catch (SecurityException e) { } catch (SecurityException e) { Log.d(TAG, "Could not bind to service", e); Log.d(TAG, "Could not bind to service", e); mContext.unbindService(this); mContext.unbindService(this); } } mBoundCalled = true; if (DEBUG) { if (DEBUG) { Log.d(TAG, "bind. bound:" + bindResult); Log.d(TAG, "bind. bound:" + bindResult); } } Loading packages/SystemUI/tests/src/com/android/systemui/util/service/ObservableServiceConnectionTest.java +21 −0 Original line number Original line Diff line number Diff line Loading @@ -200,4 +200,25 @@ public class ObservableServiceConnectionTest extends SysuiTestCase { assertThat(connection.bind()).isFalse(); assertThat(connection.bind()).isFalse(); verify(mContext).unbindService(connection); verify(mContext).unbindService(connection); } } @Test public void testUnbindDoesNotCallUnbindServiceWhenBindThrowsError() { ObservableServiceConnection<Foo> connection = new ObservableServiceConnection<>(mContext, mIntent, mUserTracker, mExecutor, mTransformer); connection.addCallback(mCallback); when(mContext.bindServiceAsUser(eq(mIntent), eq(connection), anyInt(), eq(UserHandle.of(MAIN_USER_ID)))) .thenThrow(new SecurityException()); // Verify that bind returns false and we properly unbind. assertThat(connection.bind()).isFalse(); verify(mContext).unbindService(connection); clearInvocations(mContext); // Ensure unbind after the failed bind has no effect. connection.unbind(); verify(mContext, never()).unbindService(eq(connection)); } } } Loading
packages/SystemUI/src/com/android/systemui/util/service/ObservableServiceConnection.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -158,11 +158,11 @@ public class ObservableServiceConnection<T> implements ServiceConnection { try { try { bindResult = mContext.bindServiceAsUser(mServiceIntent, this, mFlags, bindResult = mContext.bindServiceAsUser(mServiceIntent, this, mFlags, mUserTracker.getUserHandle()); mUserTracker.getUserHandle()); mBoundCalled = true; } catch (SecurityException e) { } catch (SecurityException e) { Log.d(TAG, "Could not bind to service", e); Log.d(TAG, "Could not bind to service", e); mContext.unbindService(this); mContext.unbindService(this); } } mBoundCalled = true; if (DEBUG) { if (DEBUG) { Log.d(TAG, "bind. bound:" + bindResult); Log.d(TAG, "bind. bound:" + bindResult); } } Loading
packages/SystemUI/tests/src/com/android/systemui/util/service/ObservableServiceConnectionTest.java +21 −0 Original line number Original line Diff line number Diff line Loading @@ -200,4 +200,25 @@ public class ObservableServiceConnectionTest extends SysuiTestCase { assertThat(connection.bind()).isFalse(); assertThat(connection.bind()).isFalse(); verify(mContext).unbindService(connection); verify(mContext).unbindService(connection); } } @Test public void testUnbindDoesNotCallUnbindServiceWhenBindThrowsError() { ObservableServiceConnection<Foo> connection = new ObservableServiceConnection<>(mContext, mIntent, mUserTracker, mExecutor, mTransformer); connection.addCallback(mCallback); when(mContext.bindServiceAsUser(eq(mIntent), eq(connection), anyInt(), eq(UserHandle.of(MAIN_USER_ID)))) .thenThrow(new SecurityException()); // Verify that bind returns false and we properly unbind. assertThat(connection.bind()).isFalse(); verify(mContext).unbindService(connection); clearInvocations(mContext); // Ensure unbind after the failed bind has no effect. connection.unbind(); verify(mContext, never()).unbindService(eq(connection)); } } }