1 //
2 // Copyright (C) 2023 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 #pragma once
17 
18 #include <string>
19 
20 #include "android-base/unique_fd.h"
21 
22 class Transport;
23 
24 namespace fastboot {
25 
26 enum RetCode : int {
27     SUCCESS = 0,
28     BAD_ARG,
29     IO_ERROR,
30     BAD_DEV_RESP,
31     DEVICE_FAIL,
32     TIMEOUT,
33 };
34 
35 class IFastBootDriver {
36   public:
37     RetCode virtual FlashPartition(const std::string& partition, android::base::borrowed_fd fd,
38                                    uint32_t sz) = 0;
39     RetCode virtual DeletePartition(const std::string& partition) = 0;
40     RetCode virtual WaitForDisconnect() = 0;
41     RetCode virtual Reboot(std::string* response = nullptr,
42                            std::vector<std::string>* info = nullptr) = 0;
43 
44     RetCode virtual RebootTo(std::string target, std::string* response = nullptr,
45                              std::vector<std::string>* info = nullptr) = 0;
46     RetCode virtual GetVar(const std::string& key, std::string* val,
47                            std::vector<std::string>* info = nullptr) = 0;
48     RetCode virtual FetchToFd(const std::string& partition, android::base::borrowed_fd fd,
49                               int64_t offset = -1, int64_t size = -1,
50                               std::string* response = nullptr,
51                               std::vector<std::string>* info = nullptr) = 0;
52     RetCode virtual Download(const std::string& name, android::base::borrowed_fd fd, size_t size,
53                              std::string* response = nullptr,
54                              std::vector<std::string>* info = nullptr) = 0;
55     RetCode virtual RawCommand(const std::string& cmd, const std::string& message,
56                                std::string* response = nullptr,
57                                std::vector<std::string>* info = nullptr, int* dsize = nullptr) = 0;
58     RetCode virtual ResizePartition(const std::string& partition, const std::string& size) = 0;
59     RetCode virtual Erase(const std::string& partition, std::string* response = nullptr,
60                           std::vector<std::string>* info = nullptr) = 0;
61     virtual ~IFastBootDriver() = default;
62 };
63 }  // namespace fastboot