Hridya Valsaraju | dea91b4 | 2018-07-17 11:14:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | #pragma once |
| 18 | |
| 19 | #include <memory> |
| 20 | #include <string> |
| 21 | #include <unordered_map> |
| 22 | #include <utility> |
| 23 | #include <vector> |
| 24 | |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 25 | #include <android/hardware/boot/1.0/IBootControl.h> |
David Anderson | 220ddb1 | 2019-10-31 18:02:41 -0700 | [diff] [blame] | 26 | #include <android/hardware/boot/1.1/IBootControl.h> |
josephjang | 2906975 | 2020-09-23 16:28:03 +0800 | [diff] [blame] | 27 | #include <android/hardware/fastboot/1.1/IFastboot.h> |
Hridya Valsaraju | 47658ca | 2018-09-28 11:41:22 -0700 | [diff] [blame] | 28 | #include <android/hardware/health/2.0/IHealth.h> |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 29 | |
Hridya Valsaraju | dea91b4 | 2018-07-17 11:14:01 -0700 | [diff] [blame] | 30 | #include "commands.h" |
| 31 | #include "transport.h" |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 32 | #include "variables.h" |
Hridya Valsaraju | dea91b4 | 2018-07-17 11:14:01 -0700 | [diff] [blame] | 33 | |
| 34 | class FastbootDevice { |
| 35 | public: |
| 36 | FastbootDevice(); |
| 37 | ~FastbootDevice(); |
| 38 | |
| 39 | void CloseDevice(); |
| 40 | void ExecuteCommands(); |
| 41 | bool WriteStatus(FastbootResult result, const std::string& message); |
| 42 | bool HandleData(bool read, std::vector<char>* data); |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 43 | std::string GetCurrentSlot(); |
Hridya Valsaraju | dea91b4 | 2018-07-17 11:14:01 -0700 | [diff] [blame] | 44 | |
David Anderson | 0f62663 | 2018-08-31 16:44:25 -0700 | [diff] [blame] | 45 | // Shortcuts for writing status results. |
David Anderson | 856b7ec | 2018-08-08 17:58:56 -0700 | [diff] [blame] | 46 | bool WriteOkay(const std::string& message); |
| 47 | bool WriteFail(const std::string& message); |
David Anderson | 0f62663 | 2018-08-31 16:44:25 -0700 | [diff] [blame] | 48 | bool WriteInfo(const std::string& message); |
David Anderson | 856b7ec | 2018-08-08 17:58:56 -0700 | [diff] [blame] | 49 | |
David Anderson | 12211d1 | 2018-07-24 15:21:20 -0700 | [diff] [blame] | 50 | std::vector<char>& download_data() { return download_data_; } |
Hridya Valsaraju | dea91b4 | 2018-07-17 11:14:01 -0700 | [diff] [blame] | 51 | Transport* get_transport() { return transport_.get(); } |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 52 | android::sp<android::hardware::boot::V1_0::IBootControl> boot_control_hal() { |
| 53 | return boot_control_hal_; |
| 54 | } |
David Anderson | 220ddb1 | 2019-10-31 18:02:41 -0700 | [diff] [blame] | 55 | android::sp<android::hardware::boot::V1_1::IBootControl> boot1_1() { return boot1_1_; } |
josephjang | 2906975 | 2020-09-23 16:28:03 +0800 | [diff] [blame] | 56 | android::sp<android::hardware::fastboot::V1_1::IFastboot> fastboot_hal() { |
Hridya Valsaraju | bf9f8d1 | 2018-09-05 16:57:24 -0700 | [diff] [blame] | 57 | return fastboot_hal_; |
| 58 | } |
Hridya Valsaraju | 47658ca | 2018-09-28 11:41:22 -0700 | [diff] [blame] | 59 | android::sp<android::hardware::health::V2_0::IHealth> health_hal() { return health_hal_; } |
Hridya Valsaraju | dea91b4 | 2018-07-17 11:14:01 -0700 | [diff] [blame] | 60 | |
Hridya Valsaraju | 20bdf89 | 2018-10-10 11:02:19 -0700 | [diff] [blame] | 61 | void set_active_slot(const std::string& active_slot) { active_slot_ = active_slot; } |
| 62 | |
Hridya Valsaraju | dea91b4 | 2018-07-17 11:14:01 -0700 | [diff] [blame] | 63 | private: |
| 64 | const std::unordered_map<std::string, CommandHandler> kCommandMap; |
| 65 | |
| 66 | std::unique_ptr<Transport> transport_; |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 67 | android::sp<android::hardware::boot::V1_0::IBootControl> boot_control_hal_; |
David Anderson | 220ddb1 | 2019-10-31 18:02:41 -0700 | [diff] [blame] | 68 | android::sp<android::hardware::boot::V1_1::IBootControl> boot1_1_; |
Hridya Valsaraju | 47658ca | 2018-09-28 11:41:22 -0700 | [diff] [blame] | 69 | android::sp<android::hardware::health::V2_0::IHealth> health_hal_; |
josephjang | 2906975 | 2020-09-23 16:28:03 +0800 | [diff] [blame] | 70 | android::sp<android::hardware::fastboot::V1_1::IFastboot> fastboot_hal_; |
Hridya Valsaraju | dea91b4 | 2018-07-17 11:14:01 -0700 | [diff] [blame] | 71 | std::vector<char> download_data_; |
Hridya Valsaraju | 20bdf89 | 2018-10-10 11:02:19 -0700 | [diff] [blame] | 72 | std::string active_slot_; |
Hridya Valsaraju | dea91b4 | 2018-07-17 11:14:01 -0700 | [diff] [blame] | 73 | }; |