diff options
| author | Danny Lin <danny@kdrag0n.dev> | 2021-01-27 17:08:59 -0800 |
|---|---|---|
| committer | Daniel Micay <danielmicay@gmail.com> | 2021-01-27 20:24:49 -0500 |
| commit | cc976583a66322750321a84216b15b844339e8fa (patch) | |
| tree | 2a4b5b4592e6c630a732904d61b0515a0477ad61 /static/js | |
| parent | e5a7ae8ec0ab3c09f5a32daee52348b09ddc5f5b (diff) | |
web-install: Handle bootloader lock/unlock errors
Diffstat (limited to 'static/js')
| -rw-r--r-- | static/js/web-install.js | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/static/js/web-install.js b/static/js/web-install.js index 1395971a..507776f3 100644 --- a/static/js/web-install.js +++ b/static/js/web-install.js @@ -105,8 +105,24 @@ async function ensureConnected(setProgress) { async function unlockBootloader(setProgress) { await ensureConnected(setProgress); + // Trying to unlock when the bootloader is already unlocked results in a FAIL, + // so don't try to do it. + if (await device.getVariable("unlocked") === "yes") { + return "Bootloader is already unlocked."; + } + setProgress("Unlocking bootloader..."); - await device.runCommand("flashing unlock"); + try { + await device.runCommand("flashing unlock"); + } catch (error) { + // FAIL = user rejected unlock + if (error instanceof fastboot.FastbootError && error.status === "FAIL") { + throw new Error("Bootloader was not unlocked, please try again!"); + } else { + throw error; + } + } + return "Bootloader unlocked."; } @@ -160,7 +176,20 @@ async function lockBootloader(setProgress) { await ensureConnected(setProgress); setProgress("Locking bootloader..."); - await device.runCommand("flashing lock"); + try { + await device.runCommand("flashing lock"); + } catch (error) { + // FAIL = user rejected lock + if (error instanceof fastboot.FastbootError && error.status === "FAIL") { + throw new Error("Bootloader was not locked, please try again!"); + } else { + throw error; + } + } + + // We can't explicitly validate the bootloader lock state because it reboots + // to recovery after locking. Assume that the device would've replied with + // FAIL if if it wasn't locked. return "Bootloader locked."; } |
