Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fdbbd468 authored by Arthur Ishiguro's avatar Arthur Ishiguro
Browse files

Implements getContextHubs

Bug: 67734082
Test: Run test app that uses this API, verify app can find the
appropriate hub.
Change-Id: I7cd588419bc5b30cf2e8d95ee21f0b6a5592540f
parent ab7113d4
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -258,9 +258,9 @@ public final class ContextHubManager {
    }

    /**
     * Returns the list of context hubs in the system.
     * Returns the list of ContextHubInfo objects describing the available Context Hubs.
     *
     * @return the list of context hub informations
     * @return the list of ContextHubInfo objects
     *
     * @see ContextHubInfo
     *
@@ -268,7 +268,11 @@ public final class ContextHubManager {
     */
    @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
    public List<ContextHubInfo> getContextHubs() {
        throw new UnsupportedOperationException("TODO: Implement this");
        try {
            return mService.getContextHubs();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
+3 −0
Original line number Diff line number Diff line
@@ -60,6 +60,9 @@ interface IContextHubService {
    // Creates a client to send and receive messages
    IContextHubClient createClient(in IContextHubClientCallback client, int contextHubId);

    // Returns a list of ContextHub objects of available hubs
    List<ContextHubInfo> getContextHubs();

    // Loads a nanoapp at the specified hub (new API)
    void loadNanoAppOnHub(
            int contextHubId, in IContextHubTransactionCallback transactionCallback,
+14 −0
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ public class ContextHubService extends IContextHubService.Stub {
    private final Context mContext;

    private final Map<Integer, ContextHubInfo> mContextHubIdToInfoMap;
    private final List<ContextHubInfo> mContextHubInfoList;
    private final RemoteCallbackList<IContextHubCallback> mCallbacksList =
            new RemoteCallbackList<>();

@@ -143,6 +144,7 @@ public class ContextHubService extends IContextHubService.Stub {
            mClientManager = null;
            mDefaultClientMap = Collections.emptyMap();
            mContextHubIdToInfoMap = Collections.emptyMap();
            mContextHubInfoList = Collections.emptyList();
            return;
        }

@@ -159,6 +161,7 @@ public class ContextHubService extends IContextHubService.Stub {
        }
        mContextHubIdToInfoMap = Collections.unmodifiableMap(
                ContextHubServiceUtil.createContextHubInfoMap(hubList));
        mContextHubInfoList = new ArrayList<>(mContextHubIdToInfoMap.values());

        HashMap<Integer, IContextHubClient> defaultClientMap = new HashMap<>();
        for (int contextHubId : mContextHubIdToInfoMap.keySet()) {
@@ -270,6 +273,17 @@ public class ContextHubService extends IContextHubService.Stub {
        return mContextHubIdToInfoMap.get(contextHubHandle);
    }

    /**
     * Returns a List of ContextHubInfo object describing the available hubs.
     *
     * @return the List of ContextHubInfo objects
     */
    @Override
    public List<ContextHubInfo> getContextHubs() throws RemoteException {
        checkPermissions();
        return mContextHubInfoList;
    }

    /**
     * Creates an internal load transaction callback to be used for old API clients
     *