Skip to content

Commit

Permalink
Make device-protection enable with file work completely offline
Browse files Browse the repository at this point in the history
  • Loading branch information
monkbroc committed Jun 28, 2024
1 parent d6d0b53 commit df4af0e
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/cmd/device-protection.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ module.exports = class DeviceProtectionCommands extends CLICommandBase {
*/
async enableProtection({ file } = {}) {
let addToOutput = [];
let protectedBinary = file;
try {
await this.ui.showBusySpinnerUntilResolved('Enabling device protection', this._withDevice(false, async () => {
const deviceStr = await this._getDeviceString();
Expand All @@ -162,8 +161,10 @@ module.exports = class DeviceProtectionCommands extends CLICommandBase {
return;
}

if (!protectedBinary) {
// bypass checking the product when the bootloader is provided to allow for enabling device protection offline
let protectedBinary = file;
// bypass checking the product and clearing development mode when the bootloader is provided to allow for enabling device protection offline
const onlineMode = !file;
if (onlineMode) {
const deviceProtectionActiveInProduct = await this._isDeviceProtectionActiveInProduct();
if (!deviceProtectionActiveInProduct) {
addToOutput.push(`${deviceStr} is not in a product that supports device protection.${os.EOL}`);
Expand All @@ -177,12 +178,14 @@ module.exports = class DeviceProtectionCommands extends CLICommandBase {
await this._flashBootloader(protectedBinary);
addToOutput.push(`${deviceStr} is now a Protected Device.${os.EOL}`);

const success = await this._markAsDevelopmentDevice(false);
addToOutput.push(success ?
// TODO: Improve these lines
`Device removed from development mode to maintain current settings.${os.EOL}` :
`Failed to remove device from development mode. Device protection may be disabled on next cloud connection.${os.EOL}`
);
if (onlineMode) {
const success = await this._markAsDevelopmentDevice(false);
addToOutput.push(success ?
// TODO: Improve these lines
`Device removed from development mode to maintain current settings.${os.EOL}` :
`Failed to remove device from development mode. Device protection may be disabled on next cloud connection.${os.EOL}`
);
}
}));
} catch (error) {
throw new Error(`Failed to enable device protection: ${error.message}${os.EOL}`);
Expand Down

0 comments on commit df4af0e

Please sign in to comment.