Skip to content

Commit

Permalink
Try again if adb was unauthorized (fixes #983) or offline (fixes #1317)…
Browse files Browse the repository at this point in the history
… and handle some unlock errors (part of #1479)
  • Loading branch information
NeoTheThird committed Nov 15, 2020
1 parent d5c6741 commit fd4b85e
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 33 deletions.
41 changes: 30 additions & 11 deletions src/devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@ function assembleInstallSteps(steps) {
function restartInstall() {
install(steps);
}
const smartRestart = step.resumable ? runStep : restartInstall;
let reconnections = 0;
function runStep() {
installStep(step)()
.then(() => {
Expand All @@ -518,23 +520,40 @@ function assembleInstallSteps(steps) {
})()
.then(resolve)
.catch(reject);
} else if (error.message.includes("low battery")) {
global.mainEvent.emit("user:low-power");
} else if (
step.type.includes("fastboot") &&
error.message.includes("bootloader is locked")
error.message.includes("bootloader locked") ||
error.message.includes("enable unlocking")
) {
global.mainEvent.emit("user:oem-lock", runStep);
} else if (error.message.includes("low power")) {
global.mainEvent.emit("user:low-power");
} else if (error.message.includes("no device")) {
mainEvent.emit("user:connection-lost", smartRestart);
} else if (
error.message.includes("no device") ||
error.message.includes("device offline") ||
error.message.includes("No such device") ||
error.message.includes("connection lost")
error.message.includes("unauthorized")
) {
mainEvent.emit(
"user:connection-lost",
step.resumable ? runStep : restartInstall
);
if (reconnections < 3) {
adb
.reconnect()
.then(() => {
utils.log.warn(
`automatic reconnection ${++reconnections}`
);
runStep();
})
.catch(error => {
utils.log.warn(
`failed to reconnect automatically: ${error}`
);
mainEvent.emit("user:connection-lost", smartRestart);
});
} else {
utils.log.warn(
"maximum automatic reconnection attempts exceeded"
);
mainEvent.emit("user:connection-lost", smartRestart);
}
} else if (error.message.includes("killed")) {
reject(); // Used for exiting the installer
} else {
Expand Down
14 changes: 8 additions & 6 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ mainEvent.on("restart", () => {
});

// The device's bootloader is locked, prompt the user to unlock it
mainEvent.on("user:oem-lock", callback => {
mainWindow.webContents.send("user:oem-lock");
mainEvent.on("user:oem-lock", (resume, enable = false) => {
mainWindow.webContents.send("user:oem-lock", enable);
ipcMain.once("user:oem-lock:ok", () => {
mainEvent.emit("user:write:working", "particles");
mainEvent.emit("user:write:status", "Unlocking", true);
Expand All @@ -350,11 +350,13 @@ mainEvent.on("user:oem-lock", callback => {
);
deviceTools.fastboot
.oemUnlock()
.then(() => {
callback(true);
})
.then(() => resume())
.catch(err => {
mainEvent.emit("user:error", err);
if (err.message.includes("enable unlocking")) {
mainWindow.webContents.send("user:oem-lock", true);
} else {
mainEvent.emit("user:error", err);
}
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/pug/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ html
// --- Modals ---
// low prio
include modals/select-device
include modals/developer-mode
include modals/oem-lock
include modals/developer-mode
include modals/options
// medium prio
include modals/unlock
Expand Down
27 changes: 16 additions & 11 deletions src/pug/modals/oem-lock.pug
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,28 @@
.modal-header
button.close(type='button', data-dismiss='modal', aria-label='Close')
span(aria-hidden='true') ×
h4#myModalLabel.modal-title Device locked
.modal-body
p
| Your device is oem locked, that means installation of third party operating systems like Ubuntu Touch is disabled.
b
| Removing the OEM-lock might void your device's warranty. If you want to be sure, please ask your manufacturer or vendor if they allow this. UBports is not responsible and won't replace devices in case of warranty loss. You are responsible for your own actions.
p
| Do you want to unlock your device now?
p
| You might see a confirmation dialog on your device next.
h4#oem-lock-label.modal-title Device locked
.modal-body#oem-lock-default
p Your device is oem locked, that means installation of third party operating systems like Ubuntu Touch is disabled.
b Removing the OEM-lock might void your device's warranty. If you want to be sure, please ask your manufacturer or vendor if they allow this. UBports is not responsible and won't replace devices in case of warranty loss. You are responsible for your own actions.
p Do you want to unlock your device now?
p You might see a confirmation dialog on your device next.
.modal-body#oem-lock-enable
p Your device could not be unlocked. Please make sure OEM unlocking is enabled in the devices' #[a(onclick="modals.show('developer-mode-info');") developer options]. After that, you can select the button below to continue the installation.
.modal-footer
button#btn-exit.btn.btn-default(type='button', data-dismiss='modal') Abort
button#btn-unlock.btn.btn-primary(type='button') Unlock
i#unlock-prog.fa.fa-cog.fa-spin.fa-2x.fa-fw.hidden(hidden='hidden')
script.
ipcRenderer.on("user:oem-lock", (event) => {
ipcRenderer.on("user:oem-lock", (event, enable = false) => {
modals.show('oem-lock');
if (enable) {
$("#oem-lock-default").hide();
$("#oem-lock-enable").show();
} else {
$("#oem-lock-default").show();
$("#oem-lock-enable").hide();
}
});

$("#btn-unlock").click(() => {
Expand Down
7 changes: 3 additions & 4 deletions src/pug/views/select-os.pug
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
img(style='height: 350px; margin: auto; display: block;', src='../screens/Screen6.jpg')
.col-xs-6(style='height: 100%')
h4.user-install-header#device-name(style='font-weight: bold;')
p
| #[a#device-page-link about this device] | #[a#device-config view config file]
p
| What operating system do you want to install?
p #[a#device-page-link about this device] | #[a#device-config view config file]
p Please make sure you enabled #[a(onclick="modals.show('developer-mode-info')") developer mode and OEM unlocking].
p What operating system do you want to install?
form.form-horizontal
.form-group
.col-xs-3
Expand Down

0 comments on commit fd4b85e

Please sign in to comment.