2018-07-17 18:14:01 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
|
2018-07-20 20:35:50 +00:00
|
|
|
#include <android/hardware/boot/1.0/IBootControl.h>
|
2019-11-01 01:02:41 +00:00
|
|
|
#include <android/hardware/boot/1.1/IBootControl.h>
|
2020-09-23 08:28:03 +00:00
|
|
|
#include <android/hardware/fastboot/1.1/IFastboot.h>
|
2018-09-28 18:41:22 +00:00
|
|
|
#include <android/hardware/health/2.0/IHealth.h>
|
2018-07-20 20:35:50 +00:00
|
|
|
|
2018-07-17 18:14:01 +00:00
|
|
|
#include "commands.h"
|
|
|
|
#include "transport.h"
|
2018-07-20 20:35:50 +00:00
|
|
|
#include "variables.h"
|
2018-07-17 18:14:01 +00:00
|
|
|
|
|
|
|
class FastbootDevice {
|
|
|
|
public:
|
|
|
|
FastbootDevice();
|
|
|
|
~FastbootDevice();
|
|
|
|
|
|
|
|
void CloseDevice();
|
|
|
|
void ExecuteCommands();
|
|
|
|
bool WriteStatus(FastbootResult result, const std::string& message);
|
|
|
|
bool HandleData(bool read, std::vector<char>* data);
|
2021-02-17 03:37:21 +00:00
|
|
|
bool HandleData(bool read, char* data, uint64_t size);
|
2018-07-20 20:35:50 +00:00
|
|
|
std::string GetCurrentSlot();
|
2018-07-17 18:14:01 +00:00
|
|
|
|
2018-08-31 23:44:25 +00:00
|
|
|
// Shortcuts for writing status results.
|
2018-08-09 00:58:56 +00:00
|
|
|
bool WriteOkay(const std::string& message);
|
|
|
|
bool WriteFail(const std::string& message);
|
2018-08-31 23:44:25 +00:00
|
|
|
bool WriteInfo(const std::string& message);
|
2018-08-09 00:58:56 +00:00
|
|
|
|
2018-07-24 22:21:20 +00:00
|
|
|
std::vector<char>& download_data() { return download_data_; }
|
2018-07-17 18:14:01 +00:00
|
|
|
Transport* get_transport() { return transport_.get(); }
|
2018-07-20 20:35:50 +00:00
|
|
|
android::sp<android::hardware::boot::V1_0::IBootControl> boot_control_hal() {
|
|
|
|
return boot_control_hal_;
|
|
|
|
}
|
2019-11-01 01:02:41 +00:00
|
|
|
android::sp<android::hardware::boot::V1_1::IBootControl> boot1_1() { return boot1_1_; }
|
2020-09-23 08:28:03 +00:00
|
|
|
android::sp<android::hardware::fastboot::V1_1::IFastboot> fastboot_hal() {
|
2018-09-05 23:57:24 +00:00
|
|
|
return fastboot_hal_;
|
|
|
|
}
|
2018-09-28 18:41:22 +00:00
|
|
|
android::sp<android::hardware::health::V2_0::IHealth> health_hal() { return health_hal_; }
|
2018-07-17 18:14:01 +00:00
|
|
|
|
2018-10-10 18:02:19 +00:00
|
|
|
void set_active_slot(const std::string& active_slot) { active_slot_ = active_slot; }
|
|
|
|
|
2018-07-17 18:14:01 +00:00
|
|
|
private:
|
|
|
|
const std::unordered_map<std::string, CommandHandler> kCommandMap;
|
|
|
|
|
|
|
|
std::unique_ptr<Transport> transport_;
|
2018-07-20 20:35:50 +00:00
|
|
|
android::sp<android::hardware::boot::V1_0::IBootControl> boot_control_hal_;
|
2019-11-01 01:02:41 +00:00
|
|
|
android::sp<android::hardware::boot::V1_1::IBootControl> boot1_1_;
|
2018-09-28 18:41:22 +00:00
|
|
|
android::sp<android::hardware::health::V2_0::IHealth> health_hal_;
|
2020-09-23 08:28:03 +00:00
|
|
|
android::sp<android::hardware::fastboot::V1_1::IFastboot> fastboot_hal_;
|
2018-07-17 18:14:01 +00:00
|
|
|
std::vector<char> download_data_;
|
2018-10-10 18:02:19 +00:00
|
|
|
std::string active_slot_;
|
2018-07-17 18:14:01 +00:00
|
|
|
};
|