Merge "Avoid crashing when no nanoapp preploaded" into udc-dev
This commit is contained in:
@@ -1207,7 +1207,7 @@ public class ContextHubService extends IContextHubService.Stub {
|
|||||||
pw.println("");
|
pw.println("");
|
||||||
pw.println("=================== NANOAPPS ====================");
|
pw.println("=================== NANOAPPS ====================");
|
||||||
// Dump nanoAppHash
|
// Dump nanoAppHash
|
||||||
mNanoAppStateManager.foreachNanoAppInstanceInfo((info) -> pw.println(info));
|
mNanoAppStateManager.foreachNanoAppInstanceInfo(pw::println);
|
||||||
|
|
||||||
pw.println("");
|
pw.println("");
|
||||||
pw.println("=================== PRELOADED NANOAPPS ====================");
|
pw.println("=================== PRELOADED NANOAPPS ====================");
|
||||||
@@ -1255,16 +1255,17 @@ public class ContextHubService extends IContextHubService.Stub {
|
|||||||
proto.flush();
|
proto.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Dumps preloaded nanoapps to the console */
|
||||||
* Dumps preloaded nanoapps to the console
|
|
||||||
*/
|
|
||||||
private void dumpPreloadedNanoapps(PrintWriter pw) {
|
private void dumpPreloadedNanoapps(PrintWriter pw) {
|
||||||
if (mContextHubWrapper == null) {
|
if (mContextHubWrapper == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
long[] preloadedNanoappIds = mContextHubWrapper.getPreloadedNanoappIds();
|
long[] preloadedNanoappIds = mContextHubWrapper.getPreloadedNanoappIds();
|
||||||
for (long preloadedNanoappId: preloadedNanoappIds) {
|
if (preloadedNanoappIds == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (long preloadedNanoappId : preloadedNanoappIds) {
|
||||||
pw.print("ID: 0x");
|
pw.print("ID: 0x");
|
||||||
pw.println(Long.toHexString(preloadedNanoappId));
|
pw.println(Long.toHexString(preloadedNanoappId));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ import org.mockito.Mock;
|
|||||||
import org.mockito.junit.MockitoJUnit;
|
import org.mockito.junit.MockitoJUnit;
|
||||||
import org.mockito.junit.MockitoRule;
|
import org.mockito.junit.MockitoRule;
|
||||||
|
|
||||||
|
import java.io.FileDescriptor;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -49,7 +52,8 @@ public class ContextHubServiceTest {
|
|||||||
private static final int CONTEXT_HUB_ID = 3;
|
private static final int CONTEXT_HUB_ID = 3;
|
||||||
private static final String CONTEXT_HUB_STRING = "Context Hub Info Test";
|
private static final String CONTEXT_HUB_STRING = "Context Hub Info Test";
|
||||||
|
|
||||||
private Context mContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
private final Context mContext =
|
||||||
|
InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||||
@Mock private IContextHubWrapper mMockContextHubWrapper;
|
@Mock private IContextHubWrapper mMockContextHubWrapper;
|
||||||
@Mock private ContextHubInfo mMockContextHubInfo;
|
@Mock private ContextHubInfo mMockContextHubInfo;
|
||||||
@Rule public final MockitoRule mockito = MockitoJUnit.rule();
|
@Rule public final MockitoRule mockito = MockitoJUnit.rule();
|
||||||
@@ -62,20 +66,29 @@ public class ContextHubServiceTest {
|
|||||||
when(mMockContextHubInfo.toString()).thenReturn(CONTEXT_HUB_STRING);
|
when(mMockContextHubInfo.toString()).thenReturn(CONTEXT_HUB_STRING);
|
||||||
when(mMockContextHubWrapper.getHubs()).thenReturn(hubInfo);
|
when(mMockContextHubWrapper.getHubs()).thenReturn(hubInfo);
|
||||||
|
|
||||||
when(mMockContextHubWrapper.supportsLocationSettingNotifications())
|
when(mMockContextHubWrapper.supportsLocationSettingNotifications()).thenReturn(true);
|
||||||
.thenReturn(true);
|
|
||||||
when(mMockContextHubWrapper.supportsWifiSettingNotifications()).thenReturn(true);
|
when(mMockContextHubWrapper.supportsWifiSettingNotifications()).thenReturn(true);
|
||||||
when(mMockContextHubWrapper.supportsAirplaneModeSettingNotifications())
|
when(mMockContextHubWrapper.supportsAirplaneModeSettingNotifications()).thenReturn(true);
|
||||||
.thenReturn(true);
|
when(mMockContextHubWrapper.supportsMicrophoneSettingNotifications()).thenReturn(true);
|
||||||
when(mMockContextHubWrapper.supportsMicrophoneSettingNotifications())
|
|
||||||
.thenReturn(true);
|
|
||||||
when(mMockContextHubWrapper.supportsBtSettingNotifications()).thenReturn(true);
|
when(mMockContextHubWrapper.supportsBtSettingNotifications()).thenReturn(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO (b/254290317): These existing tests are to setup the testing infra for the ContextHub
|
@Test
|
||||||
// service and verify the constructor correctly registers a context hub.
|
public void testDump_emptyPreloadedNanoappList() {
|
||||||
// We need to augment these tests to cover the full behavior of the
|
when(mMockContextHubWrapper.getPreloadedNanoappIds()).thenReturn(null);
|
||||||
// ContextHub service
|
StringWriter stringWriter = new StringWriter();
|
||||||
|
|
||||||
|
ContextHubService service = new ContextHubService(mContext, mMockContextHubWrapper);
|
||||||
|
service.dump(
|
||||||
|
new FileDescriptor(), new PrintWriter(stringWriter), /* args= */ new String[0]);
|
||||||
|
|
||||||
|
assertThat(stringWriter.toString()).isNotEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO (b/254290317): These existing tests are to setup the testing infra for the ContextHub
|
||||||
|
// service and verify the constructor correctly registers a context hub.
|
||||||
|
// We need to augment these tests to cover the full behavior of the
|
||||||
|
// ContextHub service
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorRegistersContextHub() throws RemoteException {
|
public void testConstructorRegistersContextHub() throws RemoteException {
|
||||||
|
|||||||
Reference in New Issue
Block a user