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 | |
David Anderson | 12211d1 | 2018-07-24 15:21:20 -0700 | [diff] [blame] | 19 | #include <inttypes.h> |
| 20 | |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 21 | #include <android-base/file.h> |
| 22 | #include <android-base/logging.h> |
| 23 | #include <android-base/properties.h> |
| 24 | #include <android-base/stringprintf.h> |
| 25 | #include <android-base/strings.h> |
| 26 | #include <ext4_utils/ext4_utils.h> |
Hridya Valsaraju | 47658ca | 2018-09-28 11:41:22 -0700 | [diff] [blame^] | 27 | #include <healthhalutils/HealthHalUtils.h> |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 28 | |
| 29 | #include "fastboot_device.h" |
David Anderson | 12211d1 | 2018-07-24 15:21:20 -0700 | [diff] [blame] | 30 | #include "flashing.h" |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 31 | #include "utility.h" |
| 32 | |
| 33 | using ::android::hardware::boot::V1_0::BoolResult; |
| 34 | using ::android::hardware::boot::V1_0::Slot; |
Hridya Valsaraju | bf9f8d1 | 2018-09-05 16:57:24 -0700 | [diff] [blame] | 35 | using ::android::hardware::fastboot::V1_0::FileSystemType; |
| 36 | using ::android::hardware::fastboot::V1_0::Result; |
| 37 | using ::android::hardware::fastboot::V1_0::Status; |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 38 | |
| 39 | constexpr int kMaxDownloadSizeDefault = 0x20000000; |
| 40 | constexpr char kFastbootProtocolVersion[] = "0.4"; |
| 41 | |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 42 | bool GetVersion(FastbootDevice* /* device */, const std::vector<std::string>& /* args */, |
| 43 | std::string* message) { |
| 44 | *message = kFastbootProtocolVersion; |
| 45 | return true; |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 46 | } |
| 47 | |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 48 | bool GetBootloaderVersion(FastbootDevice* /* device */, const std::vector<std::string>& /* args */, |
| 49 | std::string* message) { |
| 50 | *message = android::base::GetProperty("ro.bootloader", ""); |
| 51 | return true; |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 52 | } |
| 53 | |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 54 | bool GetBasebandVersion(FastbootDevice* /* device */, const std::vector<std::string>& /* args */, |
| 55 | std::string* message) { |
| 56 | *message = android::base::GetProperty("ro.build.expect.baseband", ""); |
| 57 | return true; |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 58 | } |
| 59 | |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 60 | bool GetProduct(FastbootDevice* /* device */, const std::vector<std::string>& /* args */, |
| 61 | std::string* message) { |
| 62 | *message = android::base::GetProperty("ro.product.device", ""); |
| 63 | return true; |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 64 | } |
| 65 | |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 66 | bool GetSerial(FastbootDevice* /* device */, const std::vector<std::string>& /* args */, |
| 67 | std::string* message) { |
| 68 | *message = android::base::GetProperty("ro.serialno", ""); |
| 69 | return true; |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 70 | } |
| 71 | |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 72 | bool GetSecure(FastbootDevice* /* device */, const std::vector<std::string>& /* args */, |
| 73 | std::string* message) { |
| 74 | *message = android::base::GetBoolProperty("ro.secure", "") ? "yes" : "no"; |
| 75 | return true; |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Hridya Valsaraju | 4af8090 | 2018-09-26 13:08:16 -0700 | [diff] [blame] | 78 | bool GetVariant(FastbootDevice* device, const std::vector<std::string>& /* args */, |
| 79 | std::string* message) { |
| 80 | auto fastboot_hal = device->fastboot_hal(); |
| 81 | if (!fastboot_hal) { |
| 82 | *message = "Fastboot HAL not found"; |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | Result ret; |
| 87 | auto ret_val = fastboot_hal->getVariant([&](std::string device_variant, Result result) { |
| 88 | *message = device_variant; |
| 89 | ret = result; |
| 90 | }); |
| 91 | if (!ret_val.isOk() || ret.status != Status::SUCCESS) { |
| 92 | *message = "Unable to get device variant"; |
| 93 | return false; |
| 94 | } |
| 95 | |
| 96 | return true; |
| 97 | } |
| 98 | |
Hridya Valsaraju | 7c9bbe9 | 2018-09-27 10:41:01 -0700 | [diff] [blame] | 99 | bool GetOffModeChargeState(FastbootDevice* device, const std::vector<std::string>& /* args */, |
| 100 | std::string* message) { |
| 101 | auto fastboot_hal = device->fastboot_hal(); |
| 102 | if (!fastboot_hal) { |
| 103 | *message = "Fastboot HAL not found"; |
| 104 | return false; |
| 105 | } |
| 106 | |
| 107 | Result ret; |
| 108 | auto ret_val = |
| 109 | fastboot_hal->getOffModeChargeState([&](bool off_mode_charging_state, Result result) { |
| 110 | *message = off_mode_charging_state ? "1" : "0"; |
| 111 | ret = result; |
| 112 | }); |
| 113 | if (!ret_val.isOk() || (ret.status != Status::SUCCESS)) { |
| 114 | *message = "Unable to get off mode charge state"; |
| 115 | return false; |
| 116 | } |
| 117 | |
| 118 | return true; |
| 119 | } |
| 120 | |
Hridya Valsaraju | 47658ca | 2018-09-28 11:41:22 -0700 | [diff] [blame^] | 121 | bool GetBatteryVoltage(FastbootDevice* device, const std::vector<std::string>& /* args */, |
| 122 | std::string* message) { |
| 123 | using android::hardware::health::V2_0::HealthInfo; |
| 124 | using android::hardware::health::V2_0::Result; |
| 125 | |
| 126 | auto health_hal = device->health_hal(); |
| 127 | if (!health_hal) { |
| 128 | *message = "Health HAL not found"; |
| 129 | return false; |
| 130 | } |
| 131 | |
| 132 | Result ret; |
| 133 | auto ret_val = health_hal->getHealthInfo([&](Result result, HealthInfo info) { |
| 134 | *message = std::to_string(info.legacy.batteryVoltage); |
| 135 | ret = result; |
| 136 | }); |
| 137 | if (!ret_val.isOk() || (ret != Result::SUCCESS)) { |
| 138 | *message = "Unable to get battery voltage"; |
| 139 | return false; |
| 140 | } |
| 141 | |
| 142 | return true; |
| 143 | } |
| 144 | |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 145 | bool GetCurrentSlot(FastbootDevice* device, const std::vector<std::string>& /* args */, |
| 146 | std::string* message) { |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 147 | std::string suffix = device->GetCurrentSlot(); |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 148 | *message = suffix.size() == 2 ? suffix.substr(1) : suffix; |
| 149 | return true; |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 150 | } |
| 151 | |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 152 | bool GetSlotCount(FastbootDevice* device, const std::vector<std::string>& /* args */, |
| 153 | std::string* message) { |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 154 | auto boot_control_hal = device->boot_control_hal(); |
| 155 | if (!boot_control_hal) { |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 156 | *message = "0"; |
| 157 | } else { |
| 158 | *message = std::to_string(boot_control_hal->getNumberSlots()); |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 159 | } |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 160 | return true; |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 161 | } |
| 162 | |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 163 | bool GetSlotSuccessful(FastbootDevice* device, const std::vector<std::string>& args, |
| 164 | std::string* message) { |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 165 | if (args.empty()) { |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 166 | *message = "Missing argument"; |
| 167 | return false; |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 168 | } |
| 169 | Slot slot; |
| 170 | if (!GetSlotNumber(args[0], &slot)) { |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 171 | *message = "Invalid slot"; |
| 172 | return false; |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 173 | } |
| 174 | auto boot_control_hal = device->boot_control_hal(); |
| 175 | if (!boot_control_hal) { |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 176 | *message = "Device has no slots"; |
| 177 | return false; |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 178 | } |
David Anderson | 856b7ec | 2018-08-08 17:58:56 -0700 | [diff] [blame] | 179 | if (boot_control_hal->isSlotMarkedSuccessful(slot) != BoolResult::TRUE) { |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 180 | *message = "no"; |
| 181 | } else { |
| 182 | *message = "yes"; |
David Anderson | 856b7ec | 2018-08-08 17:58:56 -0700 | [diff] [blame] | 183 | } |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 184 | return true; |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 185 | } |
| 186 | |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 187 | bool GetSlotUnbootable(FastbootDevice* device, const std::vector<std::string>& args, |
| 188 | std::string* message) { |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 189 | if (args.empty()) { |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 190 | *message = "Missing argument"; |
| 191 | return false; |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 192 | } |
| 193 | Slot slot; |
| 194 | if (!GetSlotNumber(args[0], &slot)) { |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 195 | *message = "Invalid slot"; |
| 196 | return false; |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 197 | } |
| 198 | auto boot_control_hal = device->boot_control_hal(); |
| 199 | if (!boot_control_hal) { |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 200 | *message = "Device has no slots"; |
| 201 | return false; |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 202 | } |
David Anderson | 856b7ec | 2018-08-08 17:58:56 -0700 | [diff] [blame] | 203 | if (boot_control_hal->isSlotBootable(slot) != BoolResult::TRUE) { |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 204 | *message = "yes"; |
| 205 | } else { |
| 206 | *message = "no"; |
David Anderson | 856b7ec | 2018-08-08 17:58:56 -0700 | [diff] [blame] | 207 | } |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 208 | return true; |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 209 | } |
| 210 | |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 211 | bool GetMaxDownloadSize(FastbootDevice* /* device */, const std::vector<std::string>& /* args */, |
| 212 | std::string* message) { |
David Anderson | 28b81cd | 2018-09-04 16:51:29 -0700 | [diff] [blame] | 213 | *message = android::base::StringPrintf("0x%X", kMaxDownloadSizeDefault); |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 214 | return true; |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 215 | } |
| 216 | |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 217 | bool GetUnlocked(FastbootDevice* /* device */, const std::vector<std::string>& /* args */, |
| 218 | std::string* message) { |
Hridya Valsaraju | dca328d | 2018-09-24 16:01:35 -0700 | [diff] [blame] | 219 | *message = GetDeviceLockStatus() ? "no" : "yes"; |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 220 | return true; |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 221 | } |
| 222 | |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 223 | bool GetHasSlot(FastbootDevice* device, const std::vector<std::string>& args, |
| 224 | std::string* message) { |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 225 | if (args.empty()) { |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 226 | *message = "Missing argument"; |
| 227 | return false; |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 228 | } |
| 229 | std::string slot_suffix = device->GetCurrentSlot(); |
| 230 | if (slot_suffix.empty()) { |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 231 | *message = "no"; |
| 232 | return true; |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 233 | } |
David Anderson | 79ab0e3 | 2018-08-14 16:21:50 -0700 | [diff] [blame] | 234 | std::string partition_name = args[0] + slot_suffix; |
| 235 | if (FindPhysicalPartition(partition_name) || |
| 236 | LogicalPartitionExists(partition_name, slot_suffix)) { |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 237 | *message = "yes"; |
| 238 | } else { |
| 239 | *message = "no"; |
David Anderson | 79ab0e3 | 2018-08-14 16:21:50 -0700 | [diff] [blame] | 240 | } |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 241 | return true; |
Hridya Valsaraju | 31d2c26 | 2018-07-20 13:35:50 -0700 | [diff] [blame] | 242 | } |
David Anderson | 12211d1 | 2018-07-24 15:21:20 -0700 | [diff] [blame] | 243 | |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 244 | bool GetPartitionSize(FastbootDevice* device, const std::vector<std::string>& args, |
| 245 | std::string* message) { |
David Anderson | 12211d1 | 2018-07-24 15:21:20 -0700 | [diff] [blame] | 246 | if (args.size() < 1) { |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 247 | *message = "Missing argument"; |
| 248 | return false; |
David Anderson | 12211d1 | 2018-07-24 15:21:20 -0700 | [diff] [blame] | 249 | } |
David Anderson | 88ef0b1 | 2018-08-09 10:40:00 -0700 | [diff] [blame] | 250 | // Zero-length partitions cannot be created through device-mapper, so we |
| 251 | // special case them here. |
| 252 | bool is_zero_length; |
| 253 | if (LogicalPartitionExists(args[0], device->GetCurrentSlot(), &is_zero_length) && |
| 254 | is_zero_length) { |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 255 | *message = "0"; |
| 256 | return true; |
David Anderson | 88ef0b1 | 2018-08-09 10:40:00 -0700 | [diff] [blame] | 257 | } |
| 258 | // Otherwise, open the partition as normal. |
David Anderson | 12211d1 | 2018-07-24 15:21:20 -0700 | [diff] [blame] | 259 | PartitionHandle handle; |
| 260 | if (!OpenPartition(device, args[0], &handle)) { |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 261 | *message = "Could not open partition"; |
| 262 | return false; |
David Anderson | 12211d1 | 2018-07-24 15:21:20 -0700 | [diff] [blame] | 263 | } |
| 264 | uint64_t size = get_block_device_size(handle.fd()); |
David Anderson | 4758967 | 2018-09-04 16:22:41 -0700 | [diff] [blame] | 265 | *message = android::base::StringPrintf("0x%" PRIX64, size); |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 266 | return true; |
David Anderson | 12211d1 | 2018-07-24 15:21:20 -0700 | [diff] [blame] | 267 | } |
David Anderson | 0d4277d | 2018-07-31 13:27:37 -0700 | [diff] [blame] | 268 | |
Hridya Valsaraju | bf9f8d1 | 2018-09-05 16:57:24 -0700 | [diff] [blame] | 269 | bool GetPartitionType(FastbootDevice* device, const std::vector<std::string>& args, |
| 270 | std::string* message) { |
| 271 | if (args.size() < 1) { |
| 272 | *message = "Missing argument"; |
| 273 | return false; |
| 274 | } |
| 275 | std::string partition_name = args[0]; |
| 276 | auto fastboot_hal = device->fastboot_hal(); |
| 277 | if (!fastboot_hal) { |
| 278 | *message = "Fastboot HAL not found"; |
| 279 | return false; |
| 280 | } |
| 281 | |
| 282 | FileSystemType type; |
| 283 | Result ret; |
| 284 | auto ret_val = |
| 285 | fastboot_hal->getPartitionType(args[0], [&](FileSystemType fs_type, Result result) { |
| 286 | type = fs_type; |
| 287 | ret = result; |
| 288 | }); |
| 289 | if (!ret_val.isOk() || (ret.status != Status::SUCCESS)) { |
| 290 | *message = "Unable to retrieve partition type"; |
| 291 | } else { |
| 292 | switch (type) { |
| 293 | case FileSystemType::RAW: |
| 294 | *message = "raw"; |
| 295 | return true; |
| 296 | case FileSystemType::EXT4: |
| 297 | *message = "ext4"; |
| 298 | return true; |
| 299 | case FileSystemType::F2FS: |
| 300 | *message = "f2fs"; |
| 301 | return true; |
| 302 | default: |
| 303 | *message = "Unknown file system type"; |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | return false; |
| 308 | } |
| 309 | |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 310 | bool GetPartitionIsLogical(FastbootDevice* device, const std::vector<std::string>& args, |
| 311 | std::string* message) { |
David Anderson | 0d4277d | 2018-07-31 13:27:37 -0700 | [diff] [blame] | 312 | if (args.size() < 1) { |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 313 | *message = "Missing argument"; |
| 314 | return false; |
David Anderson | 0d4277d | 2018-07-31 13:27:37 -0700 | [diff] [blame] | 315 | } |
| 316 | // Note: if a partition name is in both the GPT and the super partition, we |
| 317 | // return "true", to be consistent with prefering to flash logical partitions |
| 318 | // over physical ones. |
| 319 | std::string partition_name = args[0]; |
| 320 | if (LogicalPartitionExists(partition_name, device->GetCurrentSlot())) { |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 321 | *message = "yes"; |
| 322 | return true; |
David Anderson | 0d4277d | 2018-07-31 13:27:37 -0700 | [diff] [blame] | 323 | } |
| 324 | if (FindPhysicalPartition(partition_name)) { |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 325 | *message = "no"; |
| 326 | return true; |
David Anderson | 0d4277d | 2018-07-31 13:27:37 -0700 | [diff] [blame] | 327 | } |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 328 | *message = "Partition not found"; |
| 329 | return false; |
David Anderson | 0d4277d | 2018-07-31 13:27:37 -0700 | [diff] [blame] | 330 | } |
David Anderson | d9ba061 | 2018-08-02 11:05:00 -0700 | [diff] [blame] | 331 | |
David Anderson | 1fb3fd7 | 2018-08-31 14:40:22 -0700 | [diff] [blame] | 332 | bool GetIsUserspace(FastbootDevice* /* device */, const std::vector<std::string>& /* args */, |
| 333 | std::string* message) { |
| 334 | *message = "yes"; |
| 335 | return true; |
David Anderson | d9ba061 | 2018-08-02 11:05:00 -0700 | [diff] [blame] | 336 | } |
David Anderson | 0f62663 | 2018-08-31 16:44:25 -0700 | [diff] [blame] | 337 | |
| 338 | std::vector<std::vector<std::string>> GetAllPartitionArgsWithSlot(FastbootDevice* device) { |
| 339 | std::vector<std::vector<std::string>> args; |
| 340 | auto partitions = ListPartitions(device); |
| 341 | for (const auto& partition : partitions) { |
| 342 | args.emplace_back(std::initializer_list<std::string>{partition}); |
| 343 | } |
| 344 | return args; |
| 345 | } |
| 346 | |
| 347 | std::vector<std::vector<std::string>> GetAllPartitionArgsNoSlot(FastbootDevice* device) { |
| 348 | auto partitions = ListPartitions(device); |
| 349 | |
| 350 | std::string slot_suffix = device->GetCurrentSlot(); |
| 351 | if (!slot_suffix.empty()) { |
| 352 | auto names = std::move(partitions); |
| 353 | for (const auto& name : names) { |
| 354 | std::string slotless_name = name; |
| 355 | if (android::base::EndsWith(name, "_a") || android::base::EndsWith(name, "_b")) { |
| 356 | slotless_name = name.substr(0, name.rfind("_")); |
| 357 | } |
| 358 | if (std::find(partitions.begin(), partitions.end(), slotless_name) == |
| 359 | partitions.end()) { |
| 360 | partitions.emplace_back(slotless_name); |
| 361 | } |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | std::vector<std::vector<std::string>> args; |
| 366 | for (const auto& partition : partitions) { |
| 367 | args.emplace_back(std::initializer_list<std::string>{partition}); |
| 368 | } |
| 369 | return args; |
| 370 | } |
David Anderson | c091c17 | 2018-09-04 18:11:03 -0700 | [diff] [blame] | 371 | |
| 372 | bool GetHardwareRevision(FastbootDevice* /* device */, const std::vector<std::string>& /* args */, |
| 373 | std::string* message) { |
| 374 | *message = android::base::GetProperty("ro.revision", ""); |
| 375 | return true; |
| 376 | } |