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

Commit 065a9a5a authored by Arthur Ishiguro's avatar Arthur Ishiguro
Browse files

Adds additional host info exchanges in Context Hub HAL

Bug: 194287786
Test: Run VTS
Change-Id: I5459e44f752cd04bc1bec3b5e99f398be9f4ce11
parent 8824d6c0
Loading
Loading
Loading
Loading
+46 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
///////////////////////////////////////////////////////////////////////////////
// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE.                          //
///////////////////////////////////////////////////////////////////////////////

// This file is a snapshot of an AIDL file. Do not edit it manually. There are
// two cases:
// 1). this is a frozen version file - do not edit this in any case.
// 2). this is a 'current' file. If you make a backwards compatible change to
//     the interface (from the latest frozen version), the build system will
//     prompt you to update this file with `m <name>-update-api`.
//
// You must not make a backward incompatible change to any AIDL file built
// with the aidl_interface module type with versions property set. The module
// type is used to build AIDL files in a way that they can be used across
// independently updatable components of the system. If a device is shipped
// with such a backward incompatible change, it has a high risk of breaking
// later when a module using the interface is updated, e.g., Mainline modules.

package android.hardware.contexthub;
@VintfStability
parcelable HostEndpointInfo {
  char hostEndpointId;
  android.hardware.contexthub.HostEndpointInfo.Type type;
  @nullable String[] packageName;
  @nullable String[] attributionTag;
  @Backing(type="int") @VintfStability
  enum Type {
    TYPE_FRAMEWORK = 1,
    TYPE_APP = 2,
  }
}
+2 −0
Original line number Diff line number Diff line
@@ -43,4 +43,6 @@ interface IContextHub {
  boolean queryNanoapps(in int contextHubId);
  boolean registerCallback(in int contextHubId, in android.hardware.contexthub.IContextHubCallback cb);
  boolean sendMessageToHub(in int contextHubId, in android.hardware.contexthub.ContextHubMessage message);
  void onHostEndpointConnected(in android.hardware.contexthub.HostEndpointInfo hostEndpointInfo);
  void onHostEndpointDisconnected(char hostEndpointId);
}
+48 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.hardware.contexthub;

/**
 * Stores metadata regarding a host endpoint that may communicate with the Context Hub.
 */
@VintfStability
parcelable HostEndpointInfo {
    /** The ID of the host endpoint asscociated with this host. */
    char hostEndpointId;

    /** The type of endpoint. */
    Type type;

    /** The (optional) package name of the host. */
    @nullable String[] packageName;

    /** The (optional) attribution tag associated with this host. */
    @nullable String[] attributionTag;

    @VintfStability
    @Backing(type="int")
    enum Type {
        /**
           This endpoint is from the Android framework, where packageName and attributionTag may be
           empty.
         */
        TYPE_FRAMEWORK = 1,

        /** This endpoint is an Android app. */
        TYPE_APP = 2,
    }
}
+26 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.hardware.contexthub;

import android.hardware.contexthub.ContextHubInfo;
import android.hardware.contexthub.ContextHubMessage;
import android.hardware.contexthub.HostEndpointInfo;
import android.hardware.contexthub.IContextHubCallback;
import android.hardware.contexthub.NanoappBinary;
import android.hardware.contexthub.Setting;
@@ -151,4 +152,29 @@ interface IContextHub {
     * @return true on success
     */
    boolean sendMessageToHub(in int contextHubId, in ContextHubMessage message);

    /**
     * Invoked when a host endpoint has connected with the ContextHubService.
     *
     * The host associated with this invocation may initiate a communication channel with
     * the Context Hub using sendMessageToHub.
     *
     * @param hostEndpointInfo Metadata associated with this host endpoint.
     */
    void onHostEndpointConnected(in HostEndpointInfo hostEndpointInfo);

    /**
     * Invoked when a host endpoint has disconnected from the framework. This could be as a result
     * of an explicit connection closure, or unexpected restarts.
     *
     * Note that hostEndpointId is the same as the value in HostEndpointInfo. When this function is
     * called, the HAL is expected to clean up any resources attached to the messaging channel
     * associated with this host endpoint ID.
     *
     * @param hostEndPointId The ID of the host that has disconnected.
     *
     * @return Status::ok on success
     *         EX_ILLEGAL_ARGUMENT if hostEndpointId is not associated with a connected host.
     */
    void onHostEndpointDisconnected(char hostEndpointId);
}
+15 −0
Original line number Diff line number Diff line
@@ -111,6 +111,21 @@ namespace contexthub {
    return ndk::ScopedAStatus::ok();
}

::ndk::ScopedAStatus ContextHub::onHostEndpointConnected(const HostEndpointInfo& in_info) {
    mConnectedHostEndpoints.insert(in_info.hostEndpointId);

    return ndk::ScopedAStatus::ok();
}

::ndk::ScopedAStatus ContextHub::onHostEndpointDisconnected(char16_t in_hostEndpointId) {
    if (mConnectedHostEndpoints.count(in_hostEndpointId) > 0) {
        mConnectedHostEndpoints.erase(in_hostEndpointId);
        return ndk::ScopedAStatus::ok();
    } else {
        return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_ILLEGAL_ARGUMENT));
    }
}

}  // namespace contexthub
}  // namespace hardware
}  // namespace android
Loading