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 <fruit/fruit.h> 21 22 #include "cvd_server.pb.h" 23 24 #include "common/libs/utils/result.h" 25 #include "host/commands/cvd/server_constants.h" 26 #include "host/libs/config/host_tools_version.h" 27 28 namespace cuttlefish { 29 namespace { 30 31 class CvdVersionHandler : public CvdServerHandler { 32 public: 33 INJECT(CvdVersionHandler()) = default; 34 CanHandle(const RequestWithStdio & request) const35 Result<bool> CanHandle(const RequestWithStdio& request) const override { 36 return request.Message().contents_case() == 37 cvd::Request::ContentsCase::kVersionRequest; 38 } 39 Handle(const RequestWithStdio & request)40 Result<cvd::Response> Handle(const RequestWithStdio& request) override { 41 CF_EXPECT(CanHandle(request)); 42 cvd::Response response; 43 auto& version = *response.mutable_version_response()->mutable_version(); 44 version.set_major(cvd::kVersionMajor); 45 version.set_minor(cvd::kVersionMinor); 46 version.set_build(android::build::GetBuildNumber()); 47 version.set_crc32(FileCrc("/proc/self/exe")); 48 response.mutable_status()->set_code(cvd::Status::OK); 49 return response; 50 } 51 Interrupt()52 Result<void> Interrupt() override { return CF_ERR("Can't interrupt"); } 53 }; 54 55 } // namespace 56 cvdVersionComponent()57fruit::Component<> cvdVersionComponent() { 58 return fruit::createComponent() 59 .addMultibinding<CvdServerHandler, CvdVersionHandler>(); 60 } 61 62 } // namespace cuttlefish 63