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

Commit 5698c0ee authored by Yifei Zhang's avatar Yifei Zhang
Browse files

contexthub: throw when mHubInfoRegistry is null

- Behavior change to getHubs/findEndpoints/findEndpointsWithService
- Throw instead of returning empty list.

Bug: 386842901
Test: build
Flag: EXEMPT, bug fix
Change-Id: I9df8b6080d6bb59fc50662b5b71d9d16fca78b7e
parent e8a48423
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -697,6 +697,7 @@ public final class ContextHubManager {
     *
     * @param endpointId Statically generated ID for an endpoint.
     * @return A list of {@link HubDiscoveryInfo} objects that represents the result of discovery.
     * @throws UnsupportedOperationException If the operation is not supported.
     */
    @FlaggedApi(Flags.FLAG_OFFLOAD_API)
    @RequiresPermission(android.Manifest.permission.ACCESS_CONTEXT_HUB)
@@ -733,6 +734,7 @@ public final class ContextHubManager {
     *     cannot be null or empty.
     * @return A list of {@link HubDiscoveryInfo} objects that represents the result of discovery.
     * @throws IllegalArgumentException if the serviceDescriptor is empty/null.
     * @throws UnsupportedOperationException If the operation is not supported.
     */
    @FlaggedApi(Flags.FLAG_OFFLOAD_API)
    @RequiresPermission(android.Manifest.permission.ACCESS_CONTEXT_HUB)
+10 −9
Original line number Diff line number Diff line
@@ -768,9 +768,7 @@ public class ContextHubService extends IContextHubService.Stub {
    @Override
    public List<HubInfo> getHubs() throws RemoteException {
        super.getHubs_enforcePermission();
        if (mHubInfoRegistry == null) {
            return Collections.emptyList();
        }
        checkHubDiscoveryPreconditions();
        return mHubInfoRegistry.getHubs();
    }

@@ -778,9 +776,7 @@ public class ContextHubService extends IContextHubService.Stub {
    @Override
    public List<HubEndpointInfo> findEndpoints(long endpointId) {
        super.findEndpoints_enforcePermission();
        if (mHubInfoRegistry == null) {
            return Collections.emptyList();
        }
        checkEndpointDiscoveryPreconditions();
        return mHubInfoRegistry.findEndpoints(endpointId);
    }

@@ -788,9 +784,7 @@ public class ContextHubService extends IContextHubService.Stub {
    @Override
    public List<HubEndpointInfo> findEndpointsWithService(String serviceDescriptor) {
        super.findEndpointsWithService_enforcePermission();
        if (mHubInfoRegistry == null) {
            return Collections.emptyList();
        }
        checkEndpointDiscoveryPreconditions();
        return mHubInfoRegistry.findEndpointsWithService(serviceDescriptor);
    }

@@ -844,6 +838,13 @@ public class ContextHubService extends IContextHubService.Stub {
        }
    }

    private void checkHubDiscoveryPreconditions() {
        if (mHubInfoRegistry == null) {
            Log.e(TAG, "Hub registry failed to initialize");
            throw new UnsupportedOperationException("Hub discovery is not supported");
        }
    }

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