Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve android tools handling #1540

Merged
merged 3 commits into from
Nov 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"jquery-i18next": "^1.2.0",
"popper.js": "^1.16.0",
"progressive-downloader": "^1.0.5",
"promise-android-tools": "^4.0.0",
"promise-android-tools": "^4.0.2",
"ps-tree": "^1.2.0",
"sudo-prompt": "^9.2.1",
"system-image-node-module": "^1.1.1",
Expand Down
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 @@ -337,8 +337,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 @@ -348,11 +348,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
2 changes: 1 addition & 1 deletion src/pug/modals/options.pug
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#options-modal.modal.fade(tabindex='-1', role='dialog')
#options-modal.modal.fade(tabindex='-1', data-keyboard='false', data-backdrop='static', role='dialog')
.modal-dialog(role='document')
.modal-content
.modal-header
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