Complete VHAL GRPC Interfaces

Add missing operations from IVehicleHardware.h

Bug: 266001013
Test: `atest GRPCVehicleHardwareUnitTest GRPCVehicleProxyServerUnitTest`

Change-Id: Ida3533dedce49c49c4762b2f9a43997317f5d2c4
This commit is contained in:
Hao Chen 2023-04-11 15:27:44 -07:00
parent 32d467066a
commit a810fb2583
9 changed files with 127 additions and 18 deletions

View file

@ -152,21 +152,49 @@ void GRPCVehicleHardware::registerOnPropertySetErrorEvent(
mOnSetErr = std::move(callback);
}
DumpResult GRPCVehicleHardware::dump(const std::vector<std::string>& /* options */) {
// TODO(chenhaosjtuacm): To be implemented.
return {};
DumpResult GRPCVehicleHardware::dump(const std::vector<std::string>& options) {
::grpc::ClientContext context;
proto::DumpOptions protoDumpOptions;
proto::DumpResult protoDumpResult;
for (const auto& option : options) {
protoDumpOptions.add_options(option);
}
auto grpc_status = mGrpcStub->Dump(&context, protoDumpOptions, &protoDumpResult);
if (!grpc_status.ok()) {
LOG(ERROR) << __func__ << ": GRPC Dump Failed: " << grpc_status.error_message();
return {};
}
return {
.callerShouldDumpState = protoDumpResult.caller_should_dump_state(),
.buffer = protoDumpResult.buffer(),
};
}
aidlvhal::StatusCode GRPCVehicleHardware::checkHealth() {
// TODO(chenhaosjtuacm): To be implemented.
return aidlvhal::StatusCode::OK;
::grpc::ClientContext context;
proto::VehicleHalCallStatus protoStatus;
auto grpc_status = mGrpcStub->CheckHealth(&context, ::google::protobuf::Empty(), &protoStatus);
if (!grpc_status.ok()) {
LOG(ERROR) << __func__ << ": GRPC CheckHealth 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 */) {
// TODO(chenhaosjtuacm): To be implemented.
return aidlvhal::StatusCode::OK;
aidlvhal::StatusCode GRPCVehicleHardware::updateSampleRate(int32_t propId, int32_t areaId,
float sampleRate) {
::grpc::ClientContext context;
proto::UpdateSampleRateRequest request;
proto::VehicleHalCallStatus protoStatus;
request.set_prop(propId);
request.set_area_id(areaId);
request.set_sample_rate(sampleRate);
auto grpc_status = mGrpcStub->UpdateSampleRate(&context, request, &protoStatus);
if (!grpc_status.ok()) {
LOG(ERROR) << __func__ << ": GRPC UpdateSampleRate Failed: " << grpc_status.error_message();
return aidlvhal::StatusCode::INTERNAL_ERROR;
}
return static_cast<aidlvhal::StatusCode>(protoStatus.status_code());
}
bool GRPCVehicleHardware::waitForConnected(std::chrono::milliseconds waitTime) {

View file

@ -155,6 +155,33 @@ GrpcVehicleProxyServer::GrpcVehicleProxyServer(std::string serverAddr,
return ::grpc::Status::OK;
}
::grpc::Status GrpcVehicleProxyServer::UpdateSampleRate(
::grpc::ServerContext* context, const proto::UpdateSampleRateRequest* request,
proto::VehicleHalCallStatus* status) {
const auto status_code = mHardware->updateSampleRate(request->prop(), request->area_id(),
request->sample_rate());
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) {
status->set_status_code(static_cast<proto::StatusCode>(mHardware->checkHealth()));
return ::grpc::Status::OK;
}
::grpc::Status GrpcVehicleProxyServer::Dump(::grpc::ServerContext* context,
const proto::DumpOptions* options,
proto::DumpResult* result) {
std::vector<std::string> dumpOptionStrings(options->options().begin(),
options->options().end());
auto dumpResult = mHardware->dump(dumpOptionStrings);
result->set_caller_should_dump_state(dumpResult.callerShouldDumpState);
result->set_buffer(dumpResult.buffer);
return ::grpc::Status::OK;
}
::grpc::Status GrpcVehicleProxyServer::StartPropertyValuesStream(
::grpc::ServerContext* context, const ::google::protobuf::Empty* request,
::grpc::ServerWriter<proto::VehiclePropValues>* stream) {

View file

@ -53,6 +53,16 @@ class GrpcVehicleProxyServer : public proto::VehicleServer::Service {
const proto::VehiclePropValueRequests* requests,
proto::GetValueResults* results) override;
::grpc::Status UpdateSampleRate(::grpc::ServerContext* context,
const proto::UpdateSampleRateRequest* request,
proto::VehicleHalCallStatus* status) override;
::grpc::Status CheckHealth(::grpc::ServerContext* context, const ::google::protobuf::Empty*,
proto::VehicleHalCallStatus* status) override;
::grpc::Status Dump(::grpc::ServerContext* context, const proto::DumpOptions* options,
proto::DumpResult* result) override;
::grpc::Status StartPropertyValuesStream(
::grpc::ServerContext* context, const ::google::protobuf::Empty* request,
::grpc::ServerWriter<proto::VehiclePropValues>* stream) override;

View file

@ -18,20 +18,14 @@ syntax = "proto3";
package android.hardware.automotive.vehicle.proto;
import "android/hardware/automotive/vehicle/DumpOptions.proto";
import "android/hardware/automotive/vehicle/DumpResult.proto";
import "android/hardware/automotive/vehicle/StatusCode.proto";
import "android/hardware/automotive/vehicle/VehiclePropConfig.proto";
import "android/hardware/automotive/vehicle/VehiclePropValue.proto";
import "android/hardware/automotive/vehicle/VehiclePropValueRequest.proto";
import "google/protobuf/empty.proto";
message VehicleHalCallStatus {
StatusCode status_code = 1;
}
message VehiclePropValues {
repeated VehiclePropValue values = 1;
}
service VehicleServer {
rpc GetAllPropertyConfig(google.protobuf.Empty) returns (stream VehiclePropConfig) {}
@ -39,5 +33,11 @@ service VehicleServer {
rpc GetValues(VehiclePropValueRequests) returns (GetValueResults) {}
rpc UpdateSampleRate(UpdateSampleRateRequest) returns (VehicleHalCallStatus) {}
rpc CheckHealth(google.protobuf.Empty) returns (VehicleHalCallStatus) {}
rpc Dump(DumpOptions) returns (DumpResult) {}
rpc StartPropertyValuesStream(google.protobuf.Empty) returns (stream VehiclePropValues) {}
}

View file

@ -40,6 +40,7 @@ genrule {
":VehicleHalProtoFiles",
],
out: [
"android/hardware/automotive/vehicle/DumpOptions.pb.h",
"android/hardware/automotive/vehicle/DumpResult.pb.h",
"android/hardware/automotive/vehicle/StatusCode.pb.h",
"android/hardware/automotive/vehicle/VehicleAreaConfig.pb.h",
@ -63,6 +64,7 @@ genrule {
":VehicleHalProtoFiles",
],
out: [
"android/hardware/automotive/vehicle/DumpOptions.pb.cc",
"android/hardware/automotive/vehicle/DumpResult.pb.cc",
"android/hardware/automotive/vehicle/StatusCode.pb.cc",
"android/hardware/automotive/vehicle/VehicleAreaConfig.pb.cc",

View file

@ -0,0 +1,23 @@
/*
* Copyright (C) 2023 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.
*/
syntax = "proto3";
package android.hardware.automotive.vehicle.proto;
message DumpOptions {
repeated string options = 1;
}

View file

@ -39,3 +39,7 @@ enum StatusCode {
/* Something unexpected has happened in Vehicle HAL */
INTERNAL_ERROR = 5;
};
message VehicleHalCallStatus {
StatusCode status_code = 1;
}

View file

@ -52,3 +52,7 @@ message VehiclePropValue {
/* This is used for properties of type VehiclePropertyType#STRING */
string string_value = 9;
};
message VehiclePropValues {
repeated VehiclePropValue values = 1;
}

View file

@ -26,6 +26,17 @@ message VehiclePropValueRequest {
VehiclePropValue value = 2;
};
message UpdateSampleRateRequest {
/* Property identifier */
int32 prop = 1;
/* Area type(s) for non-global property it must be one of the value from
* VehicleArea* enums or 0 for global properties. */
int32 area_id = 2;
float sample_rate = 3;
};
message SetValueResult {
int64 request_id = 1;
StatusCode status = 2;