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

Commit e2974560 authored by Yu Shan's avatar Yu Shan
Browse files

Implement the GrpcWakeupClient.

Implement a remoteaccess HAL implementation that talks with
the wake up client using grpc.

Test: local build.
Bug: 241483300
Change-Id: I02a51f41427fa2854930d2076ca3a49791488fd9
parent 562c0f80
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -32,6 +32,11 @@ cc_binary {
        "libbinder_ndk",
        "liblog",
        "libutils",
        "libgrpc++",
        "libprotobuf-cpp-full",
    ],
    cflags: [
        "-Wno-unused-parameter",
    ],
}

@@ -45,10 +50,17 @@ cc_library {
    ],
    whole_static_libs: [
        "android.hardware.automotive.remoteaccess-V1-ndk",
        "wakeup_client_protos",
    ],
    shared_libs: [
        "libbase",
        "libbinder_ndk",
        "liblog",
        "libutils",
        "libgrpc++",
        "libprotobuf-cpp-full",
    ],
    cflags: [
        "-Wno-unused-parameter",
    ],
}
+13 −1
Original line number Diff line number Diff line
@@ -19,8 +19,10 @@
#include <aidl/android/hardware/automotive/remoteaccess/ApState.h>
#include <aidl/android/hardware/automotive/remoteaccess/BnRemoteAccess.h>
#include <aidl/android/hardware/automotive/remoteaccess/IRemoteTaskCallback.h>
#include <wakeup_client.grpc.pb.h>

#include <string>
#include <thread>

namespace android {
namespace hardware {
@@ -30,9 +32,11 @@ namespace remoteaccess {
class RemoteAccessService
    : public aidl::android::hardware::automotive::remoteaccess::BnRemoteAccess {
  public:
    RemoteAccessService(WakeupClient::StubInterface* grpcStub);

    ndk::ScopedAStatus getDeviceId(std::string* deviceId) override;

    ndk::ScopedAStatus getWakeupServiceName(std::string* wakeupServerName) override;
    ndk::ScopedAStatus getWakeupServiceName(std::string* wakeupServiceName) override;

    ndk::ScopedAStatus setRemoteTaskCallback(
            const std::shared_ptr<
@@ -43,6 +47,14 @@ class RemoteAccessService

    ndk::ScopedAStatus notifyApStateChange(
            const aidl::android::hardware::automotive::remoteaccess::ApState& newState) override;

  private:
    WakeupClient::StubInterface* mGrpcStub;
    std::shared_ptr<aidl::android::hardware::automotive::remoteaccess::IRemoteTaskCallback>
            mRemoteTaskCallback;
    std::thread mThread;

    void taskLoop();
};

}  // namespace remoteaccess
+2 −1
Original line number Diff line number Diff line
@@ -25,8 +25,9 @@
int main(int /* argc */, char* /* argv */[]) {
    ALOGI("Registering RemoteAccessService as service...");

    // TODO(b/241483300): Create GrpcClientStub here.
    auto service = ndk::SharedRefBase::make<
            android::hardware::automotive::remoteaccess::RemoteAccessService>();
            android::hardware::automotive::remoteaccess::RemoteAccessService>(nullptr);

    binder_exception_t err = AServiceManager_addService(
            service->asBinder().get(), "android.hardware.automotive.remote.IRemoteAccess/default");
+31 −3
Original line number Diff line number Diff line
@@ -16,30 +16,58 @@

#include "RemoteAccessService.h"

#include <android/binder_status.h>
#include <grpc++/grpc++.h>
#include <utils/Log.h>
#include <chrono>
#include <thread>

namespace android {
namespace hardware {
namespace automotive {
namespace remoteaccess {

namespace {

using ::aidl::android::hardware::automotive::remoteaccess::ApState;
using ::aidl::android::hardware::automotive::remoteaccess::IRemoteTaskCallback;
using ::grpc::ClientContext;
using ::grpc::ClientReader;
using ::grpc::Status;
using ::grpc::StatusCode;
using ::ndk::ScopedAStatus;

ScopedAStatus RemoteAccessService::getDeviceId([[maybe_unused]] std::string* deviceId) {
const std::string WAKEUP_SERVICE_NAME = "com.google.vehicle.wakeup";

}  // namespace

RemoteAccessService::RemoteAccessService(WakeupClient::StubInterface* grpcStub)
    : mGrpcStub(grpcStub) {
    // mThread = std::thread([this]() { taskLoop(); });
}

void RemoteAccessService::taskLoop() {
    // TODO(b/241483300): handle remote tasks.
}

ScopedAStatus RemoteAccessService::getDeviceId(std::string* deviceId) {
    // TODO(b/241483300): Call VHAL to get VIN.
    return ScopedAStatus::ok();
}

ScopedAStatus RemoteAccessService::getWakeupServiceName(
        [[maybe_unused]] std::string* wakeupServiceName) {
ScopedAStatus RemoteAccessService::getWakeupServiceName(std::string* wakeupServiceName) {
    *wakeupServiceName = WAKEUP_SERVICE_NAME;
    return ScopedAStatus::ok();
}

ScopedAStatus RemoteAccessService::setRemoteTaskCallback(
        [[maybe_unused]] const std::shared_ptr<IRemoteTaskCallback>& callback) {
    mRemoteTaskCallback = callback;
    return ScopedAStatus::ok();
}

ScopedAStatus RemoteAccessService::clearRemoteTaskCallback() {
    mRemoteTaskCallback.reset();
    return ScopedAStatus::ok();
}

+4 −0
Original line number Diff line number Diff line
@@ -24,7 +24,9 @@ genrule {
    ],
    out: [
        "wakeup_client.pb.h",
        "wakeup_client.grpc.pb.h",
    ],
    vendor: true,
}

genrule {
@@ -39,7 +41,9 @@ genrule {
    ],
    out: [
        "wakeup_client.pb.cc",
        "wakeup_client.grpc.pb.cc",
    ],
    vendor: true,
}

cc_library_static {
Loading