Merge "Handle onNullBinding" into sc-qpr1-dev am: b785d6d94e am: 9904b1ef82

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15854017

Change-Id: I6bd0975884d8bc69ff1028ca9472f86029c5b08a
This commit is contained in:
Julia Reynolds
2021-09-23 05:34:20 +00:00
committed by Automerger Merge Worker
2 changed files with 9 additions and 9 deletions

View File

@@ -1536,7 +1536,7 @@ abstract public class ManagedServices {
@Override @Override
public void onNullBinding(ComponentName name) { public void onNullBinding(ComponentName name) {
Slog.v(TAG, "onNullBinding() called with: name = [" + name + "]"); Slog.v(TAG, "onNullBinding() called with: name = [" + name + "]");
mServicesBound.remove(servicesBindingTag); mContext.unbindService(this);
} }
}; };
if (!mContext.bindServiceAsUser(intent, if (!mContext.bindServiceAsUser(intent,

View File

@@ -65,6 +65,7 @@ import com.google.android.collect.Lists;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
@@ -1320,16 +1321,15 @@ public class ManagedServicesTest extends UiServiceTestCase {
APPROVAL_BY_COMPONENT); APPROVAL_BY_COMPONENT);
ComponentName cn = ComponentName.unflattenFromString("a/a"); ComponentName cn = ComponentName.unflattenFromString("a/a");
service.registerSystemService(cn, 0); ArgumentCaptor<ServiceConnection> captor = ArgumentCaptor.forClass(ServiceConnection.class);
when(context.bindServiceAsUser(any(), any(), anyInt(), any())).thenAnswer(invocation -> { when(context.bindServiceAsUser(any(), captor.capture(), anyInt(), any()))
Object[] args = invocation.getArguments(); .thenAnswer(invocation -> {
ServiceConnection sc = (ServiceConnection) args[1]; captor.getValue().onNullBinding(cn);
sc.onNullBinding(cn); return true;
return true; });
});
service.registerSystemService(cn, 0); service.registerSystemService(cn, 0);
assertFalse(service.isBound(cn, 0)); verify(context).unbindService(captor.getValue());
} }
@Test @Test