Loading services/core/java/com/android/server/location/contexthub/ContextHubService.java +6 −5 Original line number Diff line number Diff line Loading @@ -1207,7 +1207,7 @@ public class ContextHubService extends IContextHubService.Stub { pw.println(""); pw.println("=================== NANOAPPS ===================="); // Dump nanoAppHash mNanoAppStateManager.foreachNanoAppInstanceInfo((info) -> pw.println(info)); mNanoAppStateManager.foreachNanoAppInstanceInfo(pw::println); pw.println(""); pw.println("=================== PRELOADED NANOAPPS ===================="); Loading Loading @@ -1255,15 +1255,16 @@ public class ContextHubService extends IContextHubService.Stub { proto.flush(); } /** * Dumps preloaded nanoapps to the console */ /** Dumps preloaded nanoapps to the console */ private void dumpPreloadedNanoapps(PrintWriter pw) { if (mContextHubWrapper == null) { return; } long[] preloadedNanoappIds = mContextHubWrapper.getPreloadedNanoappIds(); if (preloadedNanoappIds == null) { return; } for (long preloadedNanoappId : preloadedNanoappIds) { pw.print("ID: 0x"); pw.println(Long.toHexString(preloadedNanoappId)); Loading services/tests/servicestests/src/com/android/server/location/contexthub/ContextHubServiceTest.java +24 −11 Original line number Diff line number Diff line Loading @@ -40,6 +40,9 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import java.io.FileDescriptor; import java.io.PrintWriter; import java.io.StringWriter; import java.util.Arrays; import java.util.List; Loading @@ -49,7 +52,8 @@ public class ContextHubServiceTest { private static final int CONTEXT_HUB_ID = 3; 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 ContextHubInfo mMockContextHubInfo; @Rule public final MockitoRule mockito = MockitoJUnit.rule(); Loading @@ -62,16 +66,25 @@ public class ContextHubServiceTest { when(mMockContextHubInfo.toString()).thenReturn(CONTEXT_HUB_STRING); when(mMockContextHubWrapper.getHubs()).thenReturn(hubInfo); when(mMockContextHubWrapper.supportsLocationSettingNotifications()) .thenReturn(true); when(mMockContextHubWrapper.supportsLocationSettingNotifications()).thenReturn(true); when(mMockContextHubWrapper.supportsWifiSettingNotifications()).thenReturn(true); when(mMockContextHubWrapper.supportsAirplaneModeSettingNotifications()) .thenReturn(true); when(mMockContextHubWrapper.supportsMicrophoneSettingNotifications()) .thenReturn(true); when(mMockContextHubWrapper.supportsAirplaneModeSettingNotifications()).thenReturn(true); when(mMockContextHubWrapper.supportsMicrophoneSettingNotifications()).thenReturn(true); when(mMockContextHubWrapper.supportsBtSettingNotifications()).thenReturn(true); } @Test public void testDump_emptyPreloadedNanoappList() { when(mMockContextHubWrapper.getPreloadedNanoappIds()).thenReturn(null); 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 Loading Loading
services/core/java/com/android/server/location/contexthub/ContextHubService.java +6 −5 Original line number Diff line number Diff line Loading @@ -1207,7 +1207,7 @@ public class ContextHubService extends IContextHubService.Stub { pw.println(""); pw.println("=================== NANOAPPS ===================="); // Dump nanoAppHash mNanoAppStateManager.foreachNanoAppInstanceInfo((info) -> pw.println(info)); mNanoAppStateManager.foreachNanoAppInstanceInfo(pw::println); pw.println(""); pw.println("=================== PRELOADED NANOAPPS ===================="); Loading Loading @@ -1255,15 +1255,16 @@ public class ContextHubService extends IContextHubService.Stub { proto.flush(); } /** * Dumps preloaded nanoapps to the console */ /** Dumps preloaded nanoapps to the console */ private void dumpPreloadedNanoapps(PrintWriter pw) { if (mContextHubWrapper == null) { return; } long[] preloadedNanoappIds = mContextHubWrapper.getPreloadedNanoappIds(); if (preloadedNanoappIds == null) { return; } for (long preloadedNanoappId : preloadedNanoappIds) { pw.print("ID: 0x"); pw.println(Long.toHexString(preloadedNanoappId)); Loading
services/tests/servicestests/src/com/android/server/location/contexthub/ContextHubServiceTest.java +24 −11 Original line number Diff line number Diff line Loading @@ -40,6 +40,9 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import java.io.FileDescriptor; import java.io.PrintWriter; import java.io.StringWriter; import java.util.Arrays; import java.util.List; Loading @@ -49,7 +52,8 @@ public class ContextHubServiceTest { private static final int CONTEXT_HUB_ID = 3; 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 ContextHubInfo mMockContextHubInfo; @Rule public final MockitoRule mockito = MockitoJUnit.rule(); Loading @@ -62,16 +66,25 @@ public class ContextHubServiceTest { when(mMockContextHubInfo.toString()).thenReturn(CONTEXT_HUB_STRING); when(mMockContextHubWrapper.getHubs()).thenReturn(hubInfo); when(mMockContextHubWrapper.supportsLocationSettingNotifications()) .thenReturn(true); when(mMockContextHubWrapper.supportsLocationSettingNotifications()).thenReturn(true); when(mMockContextHubWrapper.supportsWifiSettingNotifications()).thenReturn(true); when(mMockContextHubWrapper.supportsAirplaneModeSettingNotifications()) .thenReturn(true); when(mMockContextHubWrapper.supportsMicrophoneSettingNotifications()) .thenReturn(true); when(mMockContextHubWrapper.supportsAirplaneModeSettingNotifications()).thenReturn(true); when(mMockContextHubWrapper.supportsMicrophoneSettingNotifications()).thenReturn(true); when(mMockContextHubWrapper.supportsBtSettingNotifications()).thenReturn(true); } @Test public void testDump_emptyPreloadedNanoappList() { when(mMockContextHubWrapper.getPreloadedNanoappIds()).thenReturn(null); 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 Loading