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

Commit a7acdb5b authored by Manu Suresh's avatar Manu Suresh Committed by Jackeagle
Browse files

web-installer: do not depend on undefined behavior within Controller.next()

This code does not work the way it was intended to.
isConnected() depends on getDevice() which is not implemented anywhere.
It thus evaluates to `undefined`.
!undefined is `true` and !!undefined is `false`.

Consider following code:
if (this.deviceManager.isConnected() && !this.inInMode(next.mode)) {

When code was working this would evaluate to:
if (undefined && !this.inInMode(next.mode)) {

When we changed isConnected to return boolean with !! trick it evaluated !!undefined which is false.

So the code became
if (false && !this.inInMode(next.mode)) {

It short-circuts and never evaluates right hand side and breaks mode switching.

Remove isConnected() entirely and restore working logic.
parent 34b6a093
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -40,14 +40,12 @@ export class Controller {
    if (next) {
      if (next.mode) {
        //if next step require another mode [adb|fastboot|bootloader]
        if (this.deviceManager.isConnected() && !this.inInMode(next.mode)) {
        if (!this.inInMode(next.mode)) {
          //we need reboot
          await this.deviceManager.reboot(next.mode);
        }
        if (!this.deviceManager.isConnected()) {
        await this.deviceManager.connect(next.mode);
      }
      }
      this.currentIndex++;
      current = this.steps[this.currentIndex];
      this.view.onStepStarted(this.currentIndex, current);
+7 −12
Original line number Diff line number Diff line
@@ -110,16 +110,12 @@ export class DeviceManager {
    }
  }

  isConnected() {
    return this.device.isConnected();
  }
  /**
   * @param mode
   * @returns {boolean}
   *
   */
  isInMode(mode) {
    if (this.isConnected()) {
    switch (mode) {
      case "bootloader":
        return this.device.isBootloader();
@@ -128,7 +124,6 @@ export class DeviceManager {
      case "recovery":
        return this.device.isRecovery();
    }
    }
    return false;
  }

+0 −11
Original line number Diff line number Diff line
@@ -13,17 +13,6 @@ export class ADB extends Device {
    this.webusb = null;
  }

  isConnected() {
    if (!this.device) {
      return false;
    }
    try {
      return !!this.device.getDevice();
    } catch {
      return false;
    }
  }

  isADB() {
    return true;
  }
+0 −4
Original line number Diff line number Diff line
@@ -35,10 +35,6 @@ export class Bootloader extends Device {
    return this.device.runCommand(command);
  }

  isConnected() {
    return this.device.isConnected;
  }

  isBootloader() {
    return true;
  }
+0 −4
Original line number Diff line number Diff line
@@ -7,10 +7,6 @@ export class Device {

  async connect() {}

  isConnected() {
    return false;
  }

  isADB() {
    return false;
  }
Loading