1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "host/commands/cvd/server.h" 18 19 #include <build/version.h> 20 #include <cvd_server.pb.h> 21 #include <fruit/fruit.h> 22 23 #include "common/libs/utils/result.h" 24 #include "host/commands/cvd/common_utils.h" 25 #include "host/commands/cvd/server_command/components.h" 26 #include "host/commands/cvd/server_constants.h" 27 #include "host/commands/cvd/types.h" 28 #include "host/libs/config/host_tools_version.h" 29 30 namespace cuttlefish { 31 namespace { 32 33 class CvdVersionHandler : public CvdServerHandler { 34 public: 35 INJECT(CvdVersionHandler()) = default; 36 CanHandle(const RequestWithStdio & request) const37 Result<bool> CanHandle(const RequestWithStdio& request) const override { 38 return request.Message().contents_case() == 39 cvd::Request::ContentsCase::kVersionRequest; 40 } 41 Handle(const RequestWithStdio & request)42 Result<cvd::Response> Handle(const RequestWithStdio& request) override { 43 CF_EXPECT(CanHandle(request)); 44 cvd::Response response; 45 auto& version = *response.mutable_version_response()->mutable_version(); 46 version.set_major(cvd::kVersionMajor); 47 version.set_minor(cvd::kVersionMinor); 48 version.set_build(android::build::GetBuildNumber()); 49 version.set_crc32(FileCrc(kServerExecPath)); 50 response.mutable_status()->set_code(cvd::Status::OK); 51 return response; 52 } 53 Interrupt()54 Result<void> Interrupt() override { return CF_ERR("Can't interrupt"); } 55 CmdList() const56 cvd_common::Args CmdList() const override { return {"version"}; } 57 }; 58 59 } // namespace 60 cvdVersionComponent()61fruit::Component<> cvdVersionComponent() { 62 return fruit::createComponent() 63 .addMultibinding<CvdServerHandler, CvdVersionHandler>(); 64 } 65 66 } // namespace cuttlefish 67