blob: 091aadfd3f60c38fc74dd12546d3949d989027de [file] [log] [blame]
Hridya Valsarajudea91b42018-07-17 11:14:01 -07001/*
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 Valsaraju31d2c262018-07-20 13:35:50 -070025#include <android/hardware/boot/1.0/IBootControl.h>
Hridya Valsarajubf9f8d12018-09-05 16:57:24 -070026#include <android/hardware/fastboot/1.0/IFastboot.h>
Hridya Valsaraju47658ca2018-09-28 11:41:22 -070027#include <android/hardware/health/2.0/IHealth.h>
Hridya Valsaraju31d2c262018-07-20 13:35:50 -070028
Hridya Valsarajudea91b42018-07-17 11:14:01 -070029#include "commands.h"
30#include "transport.h"
Hridya Valsaraju31d2c262018-07-20 13:35:50 -070031#include "variables.h"
Hridya Valsarajudea91b42018-07-17 11:14:01 -070032
33class FastbootDevice {
34 public:
35 FastbootDevice();
36 ~FastbootDevice();
37
38 void CloseDevice();
39 void ExecuteCommands();
40 bool WriteStatus(FastbootResult result, const std::string& message);
41 bool HandleData(bool read, std::vector<char>* data);
Hridya Valsaraju31d2c262018-07-20 13:35:50 -070042 std::string GetCurrentSlot();
Hridya Valsarajudea91b42018-07-17 11:14:01 -070043
David Anderson0f626632018-08-31 16:44:25 -070044 // Shortcuts for writing status results.
David Anderson856b7ec2018-08-08 17:58:56 -070045 bool WriteOkay(const std::string& message);
46 bool WriteFail(const std::string& message);
David Anderson0f626632018-08-31 16:44:25 -070047 bool WriteInfo(const std::string& message);
David Anderson856b7ec2018-08-08 17:58:56 -070048
David Anderson12211d12018-07-24 15:21:20 -070049 std::vector<char>& download_data() { return download_data_; }
Hridya Valsarajudea91b42018-07-17 11:14:01 -070050 Transport* get_transport() { return transport_.get(); }
Hridya Valsaraju31d2c262018-07-20 13:35:50 -070051 android::sp<android::hardware::boot::V1_0::IBootControl> boot_control_hal() {
52 return boot_control_hal_;
53 }
Hridya Valsarajubf9f8d12018-09-05 16:57:24 -070054 android::sp<android::hardware::fastboot::V1_0::IFastboot> fastboot_hal() {
55 return fastboot_hal_;
56 }
Hridya Valsaraju47658ca2018-09-28 11:41:22 -070057 android::sp<android::hardware::health::V2_0::IHealth> health_hal() { return health_hal_; }
Hridya Valsarajudea91b42018-07-17 11:14:01 -070058
Hridya Valsaraju20bdf892018-10-10 11:02:19 -070059 void set_active_slot(const std::string& active_slot) { active_slot_ = active_slot; }
60
Hridya Valsarajudea91b42018-07-17 11:14:01 -070061 private:
62 const std::unordered_map<std::string, CommandHandler> kCommandMap;
63
64 std::unique_ptr<Transport> transport_;
Hridya Valsaraju31d2c262018-07-20 13:35:50 -070065 android::sp<android::hardware::boot::V1_0::IBootControl> boot_control_hal_;
Hridya Valsaraju47658ca2018-09-28 11:41:22 -070066 android::sp<android::hardware::health::V2_0::IHealth> health_hal_;
Hridya Valsarajubf9f8d12018-09-05 16:57:24 -070067 android::sp<android::hardware::fastboot::V1_0::IFastboot> fastboot_hal_;
Hridya Valsarajudea91b42018-07-17 11:14:01 -070068 std::vector<char> download_data_;
Hridya Valsaraju20bdf892018-10-10 11:02:19 -070069 std::string active_slot_;
Hridya Valsarajudea91b42018-07-17 11:14:01 -070070};