Skip to content

Commit

Permalink
Use int flags instead of Bundle extras in IUBus API (#7)
Browse files Browse the repository at this point in the history
Co-authored-by: Mikhail Petrov <[email protected]>
  • Loading branch information
mishap4 and Mikhail Petrov authored Feb 14, 2024
1 parent a222816 commit c45f630
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 32 deletions.
11 changes: 0 additions & 11 deletions CONTRIBUTORS.adoc

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface IUBus {
ParcelableUStatus registerClient(in String packageName, in ParcelableUEntity entity, in IBinder clientToken, in int flags, in IUListener listener);
ParcelableUStatus unregisterClient(in IBinder clientToken);
ParcelableUStatus send(in ParcelableUMessage message, in IBinder clientToken);
@nullable ParcelableUMessage[] pull(in ParcelableUUri uri, int count, in @nullable Bundle extras, IBinder clientToken);
ParcelableUStatus enableDispatching(in ParcelableUUri uri, in @nullable Bundle extras, IBinder clientToken);
ParcelableUStatus disableDispatching(in ParcelableUUri uri, in @nullable Bundle extras, IBinder clientToken);
@nullable ParcelableUMessage[] pull(in ParcelableUUri uri, int count, in int flags, IBinder clientToken);
ParcelableUStatus enableDispatching(in ParcelableUUri uri, in int flags, IBinder clientToken);
ParcelableUStatus disableDispatching(in ParcelableUUri uri, in int flags, IBinder clientToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
public final class UBusManager {
public static final String ACTION_BIND_UBUS = "uprotocol.action.BIND_UBUS";

public static final int FLAG_BLOCK_AUTO_FETCH = 0x00000001;

private static final int REBIND_BACKOFF_EXPONENT_MAX = 5;
private static final int REBIND_BACKOFF_BASE = 2;

Expand Down Expand Up @@ -432,7 +434,7 @@ long calculateRebindDelaySeconds() {
public @NonNull UStatus enableDispatching(@NonNull UUri uri) {
UStatus status;
try {
status = getServiceOrThrow().enableDispatching(new ParcelableUUri(uri), null, mClientToken).getWrapped();
status = getServiceOrThrow().enableDispatching(new ParcelableUUri(uri), 0, mClientToken).getWrapped();
} catch (Exception e) {
status = toStatus(e);
}
Expand All @@ -445,7 +447,7 @@ long calculateRebindDelaySeconds() {
public @NonNull UStatus disableDispatching(@NonNull UUri uri) {
UStatus status;
try {
status = getServiceOrThrow().disableDispatching(new ParcelableUUri(uri), null, mClientToken).getWrapped();
status = getServiceOrThrow().disableDispatching(new ParcelableUUri(uri), 0, mClientToken).getWrapped();
} catch (Exception e) {
status = toStatus(e);
}
Expand All @@ -462,7 +464,7 @@ public void disableDispatchingQuietly(@NonNull UUri uri) {
public @Nullable UMessage getLastMessage(@NonNull UUri topic) {
try {
final ParcelableUMessage[] bundle = getServiceOrThrow()
.pull(new ParcelableUUri(topic), 1, null, mClientToken);
.pull(new ParcelableUUri(topic), 1, 0, mClientToken);
return (bundle != null && bundle.length > 0) ? bundle[0].getWrapped() : null;
} catch (Exception e) {
Log.e(mTag, status("getLastMessage", toStatus(e), Key.URI, stringify(topic)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ private void prepareService() throws RemoteException {
doReturn(mServiceBinder).when(mService).asBinder();
doReturn(new ParcelableUStatus(STATUS_OK)).when(mService).registerClient(any(), any(), any(), anyInt(), any());
doReturn(new ParcelableUStatus(STATUS_OK)).when(mService).unregisterClient(any());
doReturn(new ParcelableUStatus(STATUS_OK)).when(mService).enableDispatching(any(), any(), any());
doReturn(new ParcelableUStatus(STATUS_OK)).when(mService).disableDispatching(any(), any(), any());
doReturn(new ParcelableUStatus(STATUS_OK)).when(mService).enableDispatching(any(), anyInt(), any());
doReturn(new ParcelableUStatus(STATUS_OK)).when(mService).disableDispatching(any(), anyInt(), any());
doReturn(new ParcelableUStatus(STATUS_OK)).when(mService).send(any(), any());
doReturn(new ParcelableUMessage[] { new ParcelableUMessage(MESSAGE) })
.when(mService).pull(any(), anyInt(), any(), any());
.when(mService).pull(any(), anyInt(), anyInt(), any());
prepareService(true, connection -> {
mServiceConnection = connection;
mServiceConnection.onServiceConnected(SERVICE, mServiceBinder);
Expand Down Expand Up @@ -415,71 +415,71 @@ public void testCalculateRebindDelaySeconds() {
public void testEnableDispatching() throws RemoteException {
testConnect();
assertStatus(UCode.OK, mManager.enableDispatching(RESOURCE_URI));
verify(mService, times(1)).enableDispatching(eq(new ParcelableUUri(RESOURCE_URI)), any(), any());
verify(mService, times(1)).enableDispatching(eq(new ParcelableUUri(RESOURCE_URI)), anyInt(), any());
}

@Test
public void testEnableDispatchingDisconnected() throws RemoteException {
assertStatus(UCode.UNAVAILABLE, mManager.enableDispatching(RESOURCE_URI));
verify(mService, never()).enableDispatching(any(), any(), any());
verify(mService, never()).enableDispatching(any(), anyInt(), any());
}

@Test
public void testDisableDispatching() throws RemoteException {
testConnect();
assertStatus(UCode.OK, mManager.disableDispatching(RESOURCE_URI));
verify(mService, times(1)).disableDispatching(eq(new ParcelableUUri(RESOURCE_URI)), any(), any());
verify(mService, times(1)).disableDispatching(eq(new ParcelableUUri(RESOURCE_URI)), anyInt(), any());
}

@Test
public void testDisableDispatchingDisconnected() throws RemoteException {
assertStatus(UCode.UNAVAILABLE, mManager.disableDispatching(RESOURCE_URI));
verify(mService, never()).disableDispatching(any(), any(), any());
verify(mService, never()).disableDispatching(any(), anyInt(), any());
}

@Test
public void testDisableDispatchingDisconnectedDebug() throws RemoteException {
mManager.setLoggable(Log.DEBUG);
assertStatus(UCode.UNAVAILABLE, mManager.disableDispatching(RESOURCE_URI));
verify(mService, never()).disableDispatching(any(), any(), any());
verify(mService, never()).disableDispatching(any(), anyInt(), any());
}

@Test
public void testDisableDispatchingQuietly() throws RemoteException {
testConnect();
mManager.disableDispatchingQuietly(RESOURCE_URI);
verify(mService, times(1)).disableDispatching(eq(new ParcelableUUri(RESOURCE_URI)), any(), any());
verify(mService, times(1)).disableDispatching(eq(new ParcelableUUri(RESOURCE_URI)), anyInt(), any());
}

@Test
public void testGetLastMessage() throws RemoteException {
testConnect();
assertEquals(MESSAGE, mManager.getLastMessage(RESOURCE_URI));
verify(mService, times(1)).pull(eq(new ParcelableUUri(RESOURCE_URI)), eq(1), any(), any());
verify(mService, times(1)).pull(eq(new ParcelableUUri(RESOURCE_URI)), eq(1), anyInt(), any());
}

@Test
public void testGetLastMessageNotAvailable() throws RemoteException {
testConnect();
doReturn(new ParcelableUMessage[0]).when(mService).pull(any(), anyInt(), any(), any());
doReturn(new ParcelableUMessage[0]).when(mService).pull(any(), anyInt(), anyInt(), any());
assertNull(mManager.getLastMessage(RESOURCE_URI));
doReturn(null).when(mService).pull(any(), anyInt(), any(), any());
doReturn(null).when(mService).pull(any(), anyInt(), anyInt(), any());
assertNull(mManager.getLastMessage(RESOURCE_URI));
verify(mService, times(2)).pull(eq(new ParcelableUUri(RESOURCE_URI)), eq(1), any(), any());
verify(mService, times(2)).pull(eq(new ParcelableUUri(RESOURCE_URI)), eq(1), anyInt(), any());
}

@Test
@SuppressWarnings("DataFlowIssue")
public void testGetLastMessageInvalidArgument() throws RemoteException {
testConnect();
doThrow(new NullPointerException()).when(mService).pull(any(), anyInt(), any(), any());
doThrow(new NullPointerException()).when(mService).pull(any(), anyInt(), anyInt(), any());
assertNull(mManager.getLastMessage(null));
}

@Test
public void testGetLastMessageDisconnected() throws RemoteException {
assertNull(mManager.getLastMessage(RESOURCE_URI));
verify(mService, never()).pull(any(), anyInt(), any(), any());
verify(mService, never()).pull(any(), anyInt(), anyInt(), any());
}

@Test
Expand Down

0 comments on commit c45f630

Please sign in to comment.