Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -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 | #include "variables.h" |
| 18 | |
| 19 | #include <android-base/file.h> |
| 20 | #include <android-base/logging.h> |
| 21 | #include <android-base/properties.h> |
| 22 | #include <android-base/stringprintf.h> |
| 23 | #include <android-base/strings.h> |
| 24 | #include <ext4_utils/ext4_utils.h> |
| 25 | |
| 26 | #include "fastboot_device.h" |
| 27 | #include "utility.h" |
| 28 | |
| 29 | using ::android::hardware::boot::V1_0::BoolResult; |
| 30 | using ::android::hardware::boot::V1_0::Slot; |
| 31 | |
| 32 | constexpr int kMaxDownloadSizeDefault = 0x20000000; |
| 33 | constexpr char kFastbootProtocolVersion[] = "0.4"; |
| 34 | |
| 35 | std::string GetVersion(FastbootDevice* /* device */, const std::vector<std::string>& /* args */) { |
| 36 | return kFastbootProtocolVersion; |
| 37 | } |
| 38 | |
| 39 | std::string GetBootloaderVersion(FastbootDevice* /* device */, |
| 40 | const std::vector<std::string>& /* args */) { |
| 41 | return android::base::GetProperty("ro.bootloader", ""); |
| 42 | } |
| 43 | |
| 44 | std::string GetBasebandVersion(FastbootDevice* /* device */, |
| 45 | const std::vector<std::string>& /* args */) { |
| 46 | return android::base::GetProperty("ro.build.expect.baseband", ""); |
| 47 | } |
| 48 | |
| 49 | std::string GetProduct(FastbootDevice* /* device */, const std::vector<std::string>& /* args */) { |
| 50 | return android::base::GetProperty("ro.product.device", ""); |
| 51 | } |
| 52 | |
| 53 | std::string GetSerial(FastbootDevice* /* device */, const std::vector<std::string>& /* args */) { |
| 54 | return android::base::GetProperty("ro.serialno", ""); |
| 55 | } |
| 56 | |
| 57 | std::string GetSecure(FastbootDevice* /* device */, const std::vector<std::string>& /* args */) { |
| 58 | return android::base::GetBoolProperty("ro.secure", "") ? "yes" : "no"; |
| 59 | } |
| 60 | |
| 61 | std::string GetCurrentSlot(FastbootDevice* device, const std::vector<std::string>& /* args */) { |
| 62 | std::string suffix = device->GetCurrentSlot(); |
| 63 | return suffix.size() == 2 ? suffix.substr(1) : suffix; |
| 64 | } |
| 65 | |
| 66 | std::string GetSlotCount(FastbootDevice* device, const std::vector<std::string>& /* args */) { |
| 67 | auto boot_control_hal = device->boot_control_hal(); |
| 68 | if (!boot_control_hal) { |
| 69 | return "0"; |
| 70 | } |
| 71 | return std::to_string(boot_control_hal->getNumberSlots()); |
| 72 | } |
| 73 | |
| 74 | std::string GetSlotSuccessful(FastbootDevice* device, const std::vector<std::string>& args) { |
| 75 | if (args.empty()) { |
| 76 | return "no"; |
| 77 | } |
| 78 | Slot slot; |
| 79 | if (!GetSlotNumber(args[0], &slot)) { |
| 80 | return "no"; |
| 81 | } |
| 82 | auto boot_control_hal = device->boot_control_hal(); |
| 83 | if (!boot_control_hal) { |
| 84 | return "no"; |
| 85 | } |
| 86 | return boot_control_hal->isSlotMarkedSuccessful(slot) == BoolResult::TRUE ? "yes" : "no"; |
| 87 | } |
| 88 | |
| 89 | std::string GetSlotUnbootable(FastbootDevice* device, const std::vector<std::string>& args) { |
| 90 | if (args.empty()) { |
| 91 | return "no"; |
| 92 | } |
| 93 | Slot slot; |
| 94 | if (!GetSlotNumber(args[0], &slot)) { |
| 95 | return "no"; |
| 96 | } |
| 97 | auto boot_control_hal = device->boot_control_hal(); |
| 98 | if (!boot_control_hal) { |
| 99 | return "no"; |
| 100 | } |
| 101 | return boot_control_hal->isSlotBootable(slot) == BoolResult::TRUE ? "no" : "yes"; |
| 102 | } |
| 103 | |
| 104 | std::string GetMaxDownloadSize(FastbootDevice* /* device */, |
| 105 | const std::vector<std::string>& /* args */) { |
| 106 | return std::to_string(kMaxDownloadSizeDefault); |
| 107 | } |
| 108 | |
| 109 | std::string GetUnlocked(FastbootDevice* /* device */, const std::vector<std::string>& /* args */) { |
| 110 | return "yes"; |
| 111 | } |
| 112 | |
| 113 | std::string GetHasSlot(FastbootDevice* device, const std::vector<std::string>& args) { |
| 114 | if (args.empty()) { |
| 115 | return "no"; |
| 116 | } |
| 117 | std::string slot_suffix = device->GetCurrentSlot(); |
| 118 | if (slot_suffix.empty()) { |
| 119 | return "no"; |
| 120 | } |
| 121 | return args[0] == "userdata" ? "no" : "yes"; |
| 122 | } |