Loading Android.bp +1 −1 Original line number Diff line number Diff line Loading @@ -205,7 +205,7 @@ java_library { "android.hardware.contexthub-V1.0-java", "android.hardware.contexthub-V1.1-java", "android.hardware.contexthub-V1.2-java", "android.hardware.contexthub-V1-java", "android.hardware.contexthub-V2-java", "android.hardware.gnss-V1.0-java", "android.hardware.gnss-V2.1-java", "android.hardware.health-V1.0-java-constants", Loading core/java/android/hardware/location/IContextHubService.aidl +4 −0 Original line number Diff line number Diff line Loading @@ -109,4 +109,8 @@ interface IContextHubService { // Queries for a list of nanoapps @EnforcePermission("ACCESS_CONTEXT_HUB") void queryNanoApps(int contextHubId, in IContextHubTransactionCallback transactionCallback); // Queries for a list of preloaded nanoapps @EnforcePermission("ACCESS_CONTEXT_HUB") long[] getPreloadedNanoAppIds(in ContextHubInfo hubInfo); } services/core/java/com/android/server/location/contexthub/ContextHubService.java +44 −3 Original line number Diff line number Diff line Loading @@ -73,6 +73,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ScheduledThreadPoolExecutor; Loading Loading @@ -147,7 +148,6 @@ public class ContextHubService extends IContextHubService.Stub { private final ScheduledThreadPoolExecutor mDailyMetricTimer = new ScheduledThreadPoolExecutor(1); // The period of the recurring time private static final int PERIOD_METRIC_QUERY_DAYS = 1; Loading Loading @@ -363,11 +363,13 @@ public class ContextHubService extends IContextHubService.Stub { */ private void initDefaultClientMap() { HashMap<Integer, IContextHubClient> defaultClientMap = new HashMap<>(); for (int contextHubId : mContextHubIdToInfoMap.keySet()) { for (Map.Entry<Integer, ContextHubInfo> entry: mContextHubIdToInfoMap.entrySet()) { int contextHubId = entry.getKey(); ContextHubInfo contextHubInfo = entry.getValue(); mLastRestartTimestampMap.put(contextHubId, new AtomicLong(SystemClock.elapsedRealtimeNanos())); ContextHubInfo contextHubInfo = mContextHubIdToInfoMap.get(contextHubId); IContextHubClient client = mClientManager.registerClient( contextHubInfo, createDefaultClientCallback(contextHubId), /* attributionTag= */ null, mTransactionManager, mContext.getPackageName()); Loading Loading @@ -1133,6 +1135,26 @@ public class ContextHubService extends IContextHubService.Stub { mTransactionManager.addTransaction(transaction); } @android.annotation.EnforcePermission(android.Manifest.permission.ACCESS_CONTEXT_HUB) /** * Queries for a list of preloaded nanoapp IDs from the specified Context Hub. * * @param hubInfo The Context Hub to query a list of nanoapps from. * @return The list of 64-bit IDs of the preloaded nanoapps. * @throws NullPointerException if hubInfo is null */ @Override public long[] getPreloadedNanoAppIds(ContextHubInfo hubInfo) throws RemoteException { super.getPreloadedNanoAppIds_enforcePermission(); Objects.requireNonNull(hubInfo, "hubInfo cannot be null"); long[] nanoappIds = mContextHubWrapper.getPreloadedNanoappIds(); if (nanoappIds == null) { return new long[0]; } return nanoappIds; } @Override protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return; Loading @@ -1159,6 +1181,10 @@ public class ContextHubService extends IContextHubService.Stub { // Dump nanoAppHash mNanoAppStateManager.foreachNanoAppInstanceInfo((info) -> pw.println(info)); pw.println(""); pw.println("=================== PRELOADED NANOAPPS ===================="); dumpPreloadedNanoapps(pw); pw.println(""); pw.println("=================== CLIENTS ===================="); pw.println(mClientManager); Loading Loading @@ -1201,6 +1227,21 @@ public class ContextHubService extends IContextHubService.Stub { proto.flush(); } /** * Dumps preloaded nanoapps to the console */ private void dumpPreloadedNanoapps(PrintWriter pw) { if (mContextHubWrapper == null) { return; } long[] preloadedNanoappIds = mContextHubWrapper.getPreloadedNanoappIds(); for (long preloadedNanoappId: preloadedNanoappIds) { pw.print("ID: 0x"); pw.println(Long.toHexString(preloadedNanoappId)); } } private void checkPermissions() { ContextHubServiceUtil.checkPermissions(mContext); } Loading services/core/java/com/android/server/location/contexthub/IContextHubWrapper.java +26 −0 Original line number Diff line number Diff line Loading @@ -358,6 +358,14 @@ public abstract class IContextHubWrapper { @ContextHubTransaction.Result public abstract int queryNanoapps(int contextHubId) throws RemoteException; /** * 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 */ public abstract long[] getPreloadedNanoappIds(); /** * Registers a callback with the Context Hub. * Loading Loading @@ -683,6 +691,20 @@ public abstract class IContextHubWrapper { } } public long[] getPreloadedNanoappIds() { android.hardware.contexthub.IContextHub hub = getHub(); if (hub == null) { return null; } try { return hub.getPreloadedNanoappIds(); } catch (RemoteException e) { Log.e(TAG, "Exception while getting preloaded nanoapp IDs: " + e.getMessage()); return null; } } public void registerExistingCallback(int contextHubId) { android.hardware.contexthub.IContextHub hub = getHub(); if (hub == null) { Loading Loading @@ -863,6 +885,10 @@ public abstract class IContextHubWrapper { mHub.queryApps(contextHubId)); } public long[] getPreloadedNanoappIds() { return new long[0]; } public void registerCallback(int contextHubId, ICallback callback) throws RemoteException { mHidlCallbackMap.put(contextHubId, new ContextHubWrapperHidlCallback(contextHubId, callback)); Loading Loading
Android.bp +1 −1 Original line number Diff line number Diff line Loading @@ -205,7 +205,7 @@ java_library { "android.hardware.contexthub-V1.0-java", "android.hardware.contexthub-V1.1-java", "android.hardware.contexthub-V1.2-java", "android.hardware.contexthub-V1-java", "android.hardware.contexthub-V2-java", "android.hardware.gnss-V1.0-java", "android.hardware.gnss-V2.1-java", "android.hardware.health-V1.0-java-constants", Loading
core/java/android/hardware/location/IContextHubService.aidl +4 −0 Original line number Diff line number Diff line Loading @@ -109,4 +109,8 @@ interface IContextHubService { // Queries for a list of nanoapps @EnforcePermission("ACCESS_CONTEXT_HUB") void queryNanoApps(int contextHubId, in IContextHubTransactionCallback transactionCallback); // Queries for a list of preloaded nanoapps @EnforcePermission("ACCESS_CONTEXT_HUB") long[] getPreloadedNanoAppIds(in ContextHubInfo hubInfo); }
services/core/java/com/android/server/location/contexthub/ContextHubService.java +44 −3 Original line number Diff line number Diff line Loading @@ -73,6 +73,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ScheduledThreadPoolExecutor; Loading Loading @@ -147,7 +148,6 @@ public class ContextHubService extends IContextHubService.Stub { private final ScheduledThreadPoolExecutor mDailyMetricTimer = new ScheduledThreadPoolExecutor(1); // The period of the recurring time private static final int PERIOD_METRIC_QUERY_DAYS = 1; Loading Loading @@ -363,11 +363,13 @@ public class ContextHubService extends IContextHubService.Stub { */ private void initDefaultClientMap() { HashMap<Integer, IContextHubClient> defaultClientMap = new HashMap<>(); for (int contextHubId : mContextHubIdToInfoMap.keySet()) { for (Map.Entry<Integer, ContextHubInfo> entry: mContextHubIdToInfoMap.entrySet()) { int contextHubId = entry.getKey(); ContextHubInfo contextHubInfo = entry.getValue(); mLastRestartTimestampMap.put(contextHubId, new AtomicLong(SystemClock.elapsedRealtimeNanos())); ContextHubInfo contextHubInfo = mContextHubIdToInfoMap.get(contextHubId); IContextHubClient client = mClientManager.registerClient( contextHubInfo, createDefaultClientCallback(contextHubId), /* attributionTag= */ null, mTransactionManager, mContext.getPackageName()); Loading Loading @@ -1133,6 +1135,26 @@ public class ContextHubService extends IContextHubService.Stub { mTransactionManager.addTransaction(transaction); } @android.annotation.EnforcePermission(android.Manifest.permission.ACCESS_CONTEXT_HUB) /** * Queries for a list of preloaded nanoapp IDs from the specified Context Hub. * * @param hubInfo The Context Hub to query a list of nanoapps from. * @return The list of 64-bit IDs of the preloaded nanoapps. * @throws NullPointerException if hubInfo is null */ @Override public long[] getPreloadedNanoAppIds(ContextHubInfo hubInfo) throws RemoteException { super.getPreloadedNanoAppIds_enforcePermission(); Objects.requireNonNull(hubInfo, "hubInfo cannot be null"); long[] nanoappIds = mContextHubWrapper.getPreloadedNanoappIds(); if (nanoappIds == null) { return new long[0]; } return nanoappIds; } @Override protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return; Loading @@ -1159,6 +1181,10 @@ public class ContextHubService extends IContextHubService.Stub { // Dump nanoAppHash mNanoAppStateManager.foreachNanoAppInstanceInfo((info) -> pw.println(info)); pw.println(""); pw.println("=================== PRELOADED NANOAPPS ===================="); dumpPreloadedNanoapps(pw); pw.println(""); pw.println("=================== CLIENTS ===================="); pw.println(mClientManager); Loading Loading @@ -1201,6 +1227,21 @@ public class ContextHubService extends IContextHubService.Stub { proto.flush(); } /** * Dumps preloaded nanoapps to the console */ private void dumpPreloadedNanoapps(PrintWriter pw) { if (mContextHubWrapper == null) { return; } long[] preloadedNanoappIds = mContextHubWrapper.getPreloadedNanoappIds(); for (long preloadedNanoappId: preloadedNanoappIds) { pw.print("ID: 0x"); pw.println(Long.toHexString(preloadedNanoappId)); } } private void checkPermissions() { ContextHubServiceUtil.checkPermissions(mContext); } Loading
services/core/java/com/android/server/location/contexthub/IContextHubWrapper.java +26 −0 Original line number Diff line number Diff line Loading @@ -358,6 +358,14 @@ public abstract class IContextHubWrapper { @ContextHubTransaction.Result public abstract int queryNanoapps(int contextHubId) throws RemoteException; /** * 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 */ public abstract long[] getPreloadedNanoappIds(); /** * Registers a callback with the Context Hub. * Loading Loading @@ -683,6 +691,20 @@ public abstract class IContextHubWrapper { } } public long[] getPreloadedNanoappIds() { android.hardware.contexthub.IContextHub hub = getHub(); if (hub == null) { return null; } try { return hub.getPreloadedNanoappIds(); } catch (RemoteException e) { Log.e(TAG, "Exception while getting preloaded nanoapp IDs: " + e.getMessage()); return null; } } public void registerExistingCallback(int contextHubId) { android.hardware.contexthub.IContextHub hub = getHub(); if (hub == null) { Loading Loading @@ -863,6 +885,10 @@ public abstract class IContextHubWrapper { mHub.queryApps(contextHubId)); } public long[] getPreloadedNanoappIds() { return new long[0]; } public void registerCallback(int contextHubId, ICallback callback) throws RemoteException { mHidlCallbackMap.put(contextHubId, new ContextHubWrapperHidlCallback(contextHubId, callback)); Loading