async startFirefoxAPK()

in src/util/adb.js [240:304]


  async startFirefoxAPK(deviceId, apk, apkComponent, deviceProfileDir) {
    const { adbClient } = this;

    log.debug(`Starting ${apk} on ${deviceId}`);

    // Fenix does ignore the -profile parameter, on the contrary Fennec
    // would run using the given path as the profile to be used during
    // this execution.
    const extras = [
      {
        key: 'args',
        value: `-profile ${deviceProfileDir}`,
      },
    ];

    if (!apkComponent) {
      apkComponent = '.App';
      if (defaultApkComponents[apk]) {
        apkComponent = defaultApkComponents[apk];
      }
    } else if (!apkComponent.includes('.')) {
      apkComponent = `.${apkComponent}`;
    }

    // If `apk` is a browser package or the `apk` has a browser package prefix:
    // prepend the package identifier before `apkComponent`.
    if (apkComponent.startsWith('.')) {
      for (const browser of packageIdentifiers) {
        if (apk === browser || apk.startsWith(`${browser}.`)) {
          apkComponent = browser + apkComponent;
          break;
        }
      }
    }

    // If `apkComponent` starts with a '.', then adb will expand the following
    // to: `${apk}/${apk}.${apkComponent}`
    let component = `${apk}`;
    if (apkComponent) {
      component += `/${apkComponent}`;
    }

    await wrapADBCall(async () => {
      try {
        // TODO: once Fenix (release) uses Android 13, we can get rid of this
        // call and only use the second call in the `catch` block.
        await adbClient.getDevice(deviceId).startActivity({
          wait: true,
          action: 'android.activity.MAIN',
          component,
          extras,
        });
      } catch {
        // Android 13+ requires a different action/category but we still need
        // to support older Fenix builds.
        await adbClient.getDevice(deviceId).startActivity({
          wait: true,
          action: 'android.intent.action.MAIN',
          category: 'android.intent.category.LAUNCHER',
          component,
          extras,
        });
      }
    });
  }