• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
25 #include <android/hardware/boot/1.0/IBootControl.h>
26 #include <android/hardware/boot/1.1/IBootControl.h>
27 #include <android/hardware/fastboot/1.1/IFastboot.h>
28 #include <android/hardware/health/2.0/IHealth.h>
29 
30 #include "commands.h"
31 #include "transport.h"
32 #include "variables.h"
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);
43     bool HandleData(bool read, char* data, uint64_t size);
44     std::string GetCurrentSlot();
45 
46     // Shortcuts for writing status results.
47     bool WriteOkay(const std::string& message);
48     bool WriteFail(const std::string& message);
49     bool WriteInfo(const std::string& message);
50 
download_data()51     std::vector<char>& download_data() { return download_data_; }
get_transport()52     Transport* get_transport() { return transport_.get(); }
boot_control_hal()53     android::sp<android::hardware::boot::V1_0::IBootControl> boot_control_hal() {
54         return boot_control_hal_;
55     }
boot1_1()56     android::sp<android::hardware::boot::V1_1::IBootControl> boot1_1() { return boot1_1_; }
fastboot_hal()57     android::sp<android::hardware::fastboot::V1_1::IFastboot> fastboot_hal() {
58         return fastboot_hal_;
59     }
health_hal()60     android::sp<android::hardware::health::V2_0::IHealth> health_hal() { return health_hal_; }
61 
set_active_slot(const std::string & active_slot)62     void set_active_slot(const std::string& active_slot) { active_slot_ = active_slot; }
63 
64   private:
65     const std::unordered_map<std::string, CommandHandler> kCommandMap;
66 
67     std::unique_ptr<Transport> transport_;
68     android::sp<android::hardware::boot::V1_0::IBootControl> boot_control_hal_;
69     android::sp<android::hardware::boot::V1_1::IBootControl> boot1_1_;
70     android::sp<android::hardware::health::V2_0::IHealth> health_hal_;
71     android::sp<android::hardware::fastboot::V1_1::IFastboot> fastboot_hal_;
72     std::vector<char> download_data_;
73     std::string active_slot_;
74 };
75