Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d1e62316 authored by Hridya Valsaraju's avatar Hridya Valsaraju
Browse files

Allow erase, set_active and download commands only on unlocked devices.

Bug: 117276890
Bug: 117277405
Bug: 117278071
Test: make

Change-Id: Ic5e3a3ce9e2199578c2788b3b14aac7a8860a270
parent d7f2c560
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -129,6 +129,11 @@ bool EraseHandler(FastbootDevice* device, const std::vector<std::string>& args)
    if (args.size() < 2) {
        return device->WriteStatus(FastbootResult::FAIL, "Invalid arguments");
    }

    if (GetDeviceLockStatus()) {
        return device->WriteStatus(FastbootResult::FAIL, "Erase is not allowed on locked devices");
    }

    PartitionHandle handle;
    if (!OpenPartition(device, args[1], &handle)) {
        return device->WriteStatus(FastbootResult::FAIL, "Partition doesn't exist");
@@ -161,6 +166,12 @@ bool DownloadHandler(FastbootDevice* device, const std::vector<std::string>& arg
    if (args.size() < 2) {
        return device->WriteStatus(FastbootResult::FAIL, "size argument unspecified");
    }

    if (GetDeviceLockStatus()) {
        return device->WriteStatus(FastbootResult::FAIL,
                                   "Download is not allowed on locked devices");
    }

    // arg[0] is the command name, arg[1] contains size of data to be downloaded
    unsigned int size;
    if (!android::base::ParseUint("0x" + args[1], &size, UINT_MAX)) {
@@ -201,6 +212,11 @@ bool SetActiveHandler(FastbootDevice* device, const std::vector<std::string>& ar
        return device->WriteStatus(FastbootResult::FAIL, "Missing slot argument");
    }

    if (GetDeviceLockStatus()) {
        return device->WriteStatus(FastbootResult::FAIL,
                                   "set_active command is not allowed on locked devices");
    }

    // Slot suffix needs to be between 'a' and 'z'.
    Slot slot;
    if (!GetSlotNumber(args[1], &slot)) {