From 61c49ed18f07be6f02c4835436335e2a1a28c94b Mon Sep 17 00:00:00 2001 From: Matthew Sedam Date: Mon, 6 Mar 2023 18:36:35 +0000 Subject: [PATCH] Pass the context hub ID to getPreloadedNanoappIds in the Context Hub service Bug: 271846335 Test: m, flash, boot # normal Test: logs # normal Test: Dump context hub service and AIDL HAL # normal Test: atest VtsAidlHalContextHubTargetTest Test: atest com.android.server.location.contexthub.ContextHubServiceTest Change-Id: Ia3e5c052059c46b7baa26dda19d12d2e8b6f8c6e --- .../contexthub/ContextHubService.java | 22 ++++++++++++------- .../contexthub/IContextHubWrapper.java | 12 +++++----- .../contexthub/ContextHubServiceTest.java | 5 +++-- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/services/core/java/com/android/server/location/contexthub/ContextHubService.java b/services/core/java/com/android/server/location/contexthub/ContextHubService.java index 94f12dd7ff011..653b71828c5bb 100644 --- a/services/core/java/com/android/server/location/contexthub/ContextHubService.java +++ b/services/core/java/com/android/server/location/contexthub/ContextHubService.java @@ -1148,7 +1148,7 @@ public class ContextHubService extends IContextHubService.Stub { super.getPreloadedNanoAppIds_enforcePermission(); Objects.requireNonNull(hubInfo, "hubInfo cannot be null"); - long[] nanoappIds = mContextHubWrapper.getPreloadedNanoappIds(); + long[] nanoappIds = mContextHubWrapper.getPreloadedNanoappIds(hubInfo.getId()); if (nanoappIds == null) { return new long[0]; } @@ -1261,13 +1261,19 @@ public class ContextHubService extends IContextHubService.Stub { return; } - long[] preloadedNanoappIds = mContextHubWrapper.getPreloadedNanoappIds(); - if (preloadedNanoappIds == null) { - return; - } - for (long preloadedNanoappId : preloadedNanoappIds) { - pw.print("ID: 0x"); - pw.println(Long.toHexString(preloadedNanoappId)); + for (int contextHubId: mContextHubIdToInfoMap.keySet()) { + long[] preloadedNanoappIds = mContextHubWrapper.getPreloadedNanoappIds(contextHubId); + if (preloadedNanoappIds == null) { + return; + } + + pw.print("Context Hub (id="); + pw.print(contextHubId); + pw.println("):"); + for (long preloadedNanoappId : preloadedNanoappIds) { + pw.print(" ID: 0x"); + pw.println(Long.toHexString(preloadedNanoappId)); + } } } diff --git a/services/core/java/com/android/server/location/contexthub/IContextHubWrapper.java b/services/core/java/com/android/server/location/contexthub/IContextHubWrapper.java index 1e32ad613eba0..eb1a0e27090f7 100644 --- a/services/core/java/com/android/server/location/contexthub/IContextHubWrapper.java +++ b/services/core/java/com/android/server/location/contexthub/IContextHubWrapper.java @@ -363,9 +363,11 @@ public abstract class IContextHubWrapper { * Provides the list of preloaded nanoapp IDs on the system. The output of this API must * not change. * - * @return The list of preloaded nanoapp IDs + * @param contextHubId The context Hub ID. + * + * @return The list of preloaded nanoapp IDs. */ - public abstract long[] getPreloadedNanoappIds(); + public abstract long[] getPreloadedNanoappIds(int contextHubId); /** * Registers a callback with the Context Hub. @@ -714,14 +716,14 @@ public abstract class IContextHubWrapper { } } - public long[] getPreloadedNanoappIds() { + public long[] getPreloadedNanoappIds(int contextHubId) { android.hardware.contexthub.IContextHub hub = getHub(); if (hub == null) { return null; } try { - return hub.getPreloadedNanoappIds(); + return hub.getPreloadedNanoappIds(contextHubId); } catch (RemoteException e) { Log.e(TAG, "Exception while getting preloaded nanoapp IDs: " + e.getMessage()); return null; @@ -924,7 +926,7 @@ public abstract class IContextHubWrapper { mHub.queryApps(contextHubId)); } - public long[] getPreloadedNanoappIds() { + public long[] getPreloadedNanoappIds(int contextHubId) { return new long[0]; } diff --git a/services/tests/servicestests/src/com/android/server/location/contexthub/ContextHubServiceTest.java b/services/tests/servicestests/src/com/android/server/location/contexthub/ContextHubServiceTest.java index c0a994ba340ac..685e8d6a3bc5c 100644 --- a/services/tests/servicestests/src/com/android/server/location/contexthub/ContextHubServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/location/contexthub/ContextHubServiceTest.java @@ -18,7 +18,8 @@ package com.android.server.location.contexthub; import static com.google.common.truth.Truth.assertThat; -import static org.mockito.Matchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -75,7 +76,7 @@ public class ContextHubServiceTest { @Test public void testDump_emptyPreloadedNanoappList() { - when(mMockContextHubWrapper.getPreloadedNanoappIds()).thenReturn(null); + when(mMockContextHubWrapper.getPreloadedNanoappIds(anyInt())).thenReturn(null); StringWriter stringWriter = new StringWriter(); ContextHubService service = new ContextHubService(mContext, mMockContextHubWrapper);