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

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

Implement Unsubscribe in vhal proxy.

Implement the unsubscribe function in IVehicleHardware. This will
stop the server from generating property update events for the
specified [propId, areaId].

Test: atest GRPCVehicleHardwareUnitTest GRPCVehicleProxyServerUnitTest
Flag: EXEMPT hal change
Bug: 328316981
Change-Id: I35f4860eead0c8ec9b192657fe51cc0ff4319383
parent 1c670114
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -206,6 +206,25 @@ aidlvhal::StatusCode GRPCVehicleHardware::subscribe(aidlvhal::SubscribeOptions o
    return static_cast<aidlvhal::StatusCode>(protoStatus.status_code());
}

aidlvhal::StatusCode GRPCVehicleHardware::unsubscribe(int32_t propId, int32_t areaId) {
    proto::UnsubscribeRequest request;
    ::grpc::ClientContext context;
    proto::VehicleHalCallStatus protoStatus;
    request.set_prop_id(propId);
    request.set_area_id(areaId);
    auto grpc_status = mGrpcStub->Unsubscribe(&context, request, &protoStatus);
    if (!grpc_status.ok()) {
        if (grpc_status.error_code() == ::grpc::StatusCode::UNIMPLEMENTED) {
            // This is a legacy sever. Ignore unsubscribe request.
            LOG(INFO) << __func__ << ": GRPC Unsubscribe is not supported by the server";
            return aidlvhal::StatusCode::OK;
        }
        LOG(ERROR) << __func__ << ": GRPC Unsubscribe Failed: " << grpc_status.error_message();
        return aidlvhal::StatusCode::INTERNAL_ERROR;
    }
    return static_cast<aidlvhal::StatusCode>(protoStatus.status_code());
}

aidlvhal::StatusCode GRPCVehicleHardware::updateSampleRate(int32_t propId, int32_t areaId,
                                                           float sampleRate) {
    ::grpc::ClientContext context;
+2 −0
Original line number Diff line number Diff line
@@ -85,6 +85,8 @@ class GRPCVehicleHardware : public IVehicleHardware {

    aidlvhal::StatusCode subscribe(aidlvhal::SubscribeOptions options) override;

    aidlvhal::StatusCode unsubscribe(int32_t propId, int32_t areaId) override;

    bool waitForConnected(std::chrono::milliseconds waitTime);

  protected:
+10 −0
Original line number Diff line number Diff line
@@ -175,6 +175,16 @@ GrpcVehicleProxyServer::GrpcVehicleProxyServer(std::string serverAddr,
    return ::grpc::Status::OK;
}

::grpc::Status GrpcVehicleProxyServer::Unsubscribe(::grpc::ServerContext* context,
                                                   const proto::UnsubscribeRequest* request,
                                                   proto::VehicleHalCallStatus* status) {
    int32_t propId = request->prop_id();
    int32_t areaId = request->area_id();
    const auto status_code = mHardware->unsubscribe(propId, areaId);
    status->set_status_code(static_cast<proto::StatusCode>(status_code));
    return ::grpc::Status::OK;
}

::grpc::Status GrpcVehicleProxyServer::CheckHealth(::grpc::ServerContext* context,
                                                   const ::google::protobuf::Empty*,
                                                   proto::VehicleHalCallStatus* status) {
+4 −0
Original line number Diff line number Diff line
@@ -60,6 +60,10 @@ class GrpcVehicleProxyServer : public proto::VehicleServer::Service {
    ::grpc::Status Subscribe(::grpc::ServerContext* context, const proto::SubscribeRequest* request,
                             proto::VehicleHalCallStatus* status) override;

    ::grpc::Status Unsubscribe(::grpc::ServerContext* context,
                               const proto::UnsubscribeRequest* request,
                               proto::VehicleHalCallStatus* status) override;

    ::grpc::Status CheckHealth(::grpc::ServerContext* context, const ::google::protobuf::Empty*,
                               proto::VehicleHalCallStatus* status) override;

+3 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import "android/hardware/automotive/vehicle/DumpOptions.proto";
import "android/hardware/automotive/vehicle/DumpResult.proto";
import "android/hardware/automotive/vehicle/SubscribeRequest.proto";
import "android/hardware/automotive/vehicle/StatusCode.proto";
import "android/hardware/automotive/vehicle/UnsubscribeRequest.proto";
import "android/hardware/automotive/vehicle/VehiclePropConfig.proto";
import "android/hardware/automotive/vehicle/VehiclePropValue.proto";
import "android/hardware/automotive/vehicle/VehiclePropValueRequest.proto";
@@ -43,4 +44,6 @@ service VehicleServer {
    rpc StartPropertyValuesStream(google.protobuf.Empty) returns (stream VehiclePropValues) {}

    rpc Subscribe(SubscribeRequest) returns (VehicleHalCallStatus) {}

    rpc Unsubscribe(UnsubscribeRequest) returns (VehicleHalCallStatus) {}
}
Loading