Bug 1542286 - Show the application version instead of the Gecko version for Fenix runtimes r=daisuke
authorJulian Descottes <jdescottes@mozilla.com>
Tue, 07 May 2019 12:04:36 +0000
changeset 534803 27b582600447f02b895c1f6b920e129a06d21b95
parent 534802 49d2d968ce1d11ec30728ec86b3a1e5298c2b5a6
child 534804 1d326e6840189ef74100cdf109eec8107ae6c689
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdaisuke
bugs1542286
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1542286 - Show the application version instead of the Gecko version for Fenix runtimes r=daisuke Depends on D29377 Differential Revision: https://phabricator.services.mozilla.com/D29462
devtools/client/aboutdebugging-new/src/actions/runtimes.js
devtools/client/aboutdebugging-new/src/modules/usb-runtimes.js
devtools/client/aboutdebugging-new/src/types/runtime.js
devtools/shared/adb/adb-runtime.js
devtools/shared/adb/adb.js
--- a/devtools/client/aboutdebugging-new/src/actions/runtimes.js
+++ b/devtools/client/aboutdebugging-new/src/actions/runtimes.js
@@ -143,28 +143,33 @@ function connectRuntime(id) {
       // Fenix specific workarounds are needed until we can get proper server side APIs
       // to detect Fenix and get the proper application names and versions.
       // See https://github.com/mozilla-mobile/fenix/issues/2016.
 
       // For Fenix runtimes, the ADB runtime name is more accurate than the one returned
       // by the Device actor.
       const runtimeName = runtime.isFenix ? runtime.name : deviceDescription.name;
 
+      // For Fenix runtimes, the version we should display is the application version
+      // retrieved from ADB, and not the Gecko version returned by the Device actor.
+      const version = runtime.isFenix ?
+        runtime.extra.adbPackageVersion : deviceDescription.version;
+
       const runtimeDetails = {
         clientWrapper,
         compatibilityReport,
         connectionPromptEnabled,
         extensionDebugEnabled,
         info: {
           deviceName: deviceDescription.deviceName,
           icon,
           name: runtimeName,
           os: deviceDescription.os,
           type: runtime.type,
-          version: deviceDescription.version,
+          version,
         },
         isMultiE10s: deviceDescription.isMultiE10s,
         serviceWorkersAvailable,
       };
 
       const deviceFront = await clientWrapper.getFront("device");
       if (deviceFront) {
         deviceFront.on("multi-e10s-updated", onMultiE10sUpdated);
@@ -381,16 +386,17 @@ function updateUSBRuntimes(adbRuntimes) 
     const socketPath = adbRuntime.socketPath;
     const deviceId = adbRuntime.deviceId;
     const connectionParameters = socketPath ? { deviceId, socketPath } : null;
     return {
       id: adbRuntime.id,
       extra: {
         connectionParameters,
         deviceName: adbRuntime.deviceName,
+        adbPackageVersion: adbRuntime.versionName,
       },
       isConnecting: false,
       isConnectionFailed: false,
       isConnectionNotResponding: false,
       isConnectionTimeout: false,
       isFenix: adbRuntime.isFenix,
       isUnavailable: adbRuntime.isUnavailable,
       isUnplugged: adbRuntime.isUnplugged,
--- a/devtools/client/aboutdebugging-new/src/modules/usb-runtimes.js
+++ b/devtools/client/aboutdebugging-new/src/modules/usb-runtimes.js
@@ -14,16 +14,17 @@ class UsbRuntime {
     this.id = adbRuntime.id;
     this.deviceId = adbRuntime.deviceId;
     this.deviceName = adbRuntime.deviceName;
     this.shortName = adbRuntime.shortName;
     this.socketPath = adbRuntime.socketPath;
     this.isFenix = adbRuntime.isFenix;
     this.isUnavailable = false;
     this.isUnplugged = false;
+    this.versionName = adbRuntime.versionName;
   }
 }
 
 /**
  * Used when a device was detected, meaning USB debugging is enabled on the device, but no
  * runtime/browser is available for connection.
  */
 class UnavailableUsbRuntime {
@@ -31,16 +32,17 @@ class UnavailableUsbRuntime {
     this.id = adbDevice.id + "|unavailable";
     this.deviceId = adbDevice.id;
     this.deviceName = adbDevice.name;
     this.shortName = "Unavailable runtime";
     this.socketPath = null;
     this.isFenix = false;
     this.isUnavailable = true;
     this.isUnplugged = false;
+    this.versionName = null;
   }
 }
 
 /**
  * Used to represent USB devices that were previously connected but are now missing
  * (presumably after being unplugged/disconnected from the computer).
  */
 class UnpluggedUsbRuntime {
@@ -48,16 +50,17 @@ class UnpluggedUsbRuntime {
     this.id = deviceId + "|unplugged";
     this.deviceId = deviceId;
     this.deviceName = deviceName;
     this.shortName = "Unplugged runtime";
     this.socketPath = null;
     this.isFenix = false;
     this.isUnavailable = true;
     this.isUnplugged = true;
+    this.versionName = null;
   }
 }
 
 /**
  * Map used to keep track of discovered usb devices. Will be used to create the unplugged
  * usb runtimes.
  */
 const devices = new Map();
--- a/devtools/client/aboutdebugging-new/src/types/runtime.js
+++ b/devtools/client/aboutdebugging-new/src/types/runtime.js
@@ -100,16 +100,20 @@ const runtimeExtra = {
   connectionParameters: PropTypes.oneOfType([
     PropTypes.shape(networkRuntimeConnectionParameter),
     PropTypes.shape(usbRuntimeConnectionParameter),
   ]),
 
   // device name
   // unavailable on this-firefox and network-location runtimes
   deviceName: PropTypes.string,
+
+  // version of the application coming from ADB, only available via USB. Useful for Fenix
+  // runtimes, because the version can't be retrieved from Service.appInfo.
+  adbPackageVersion: PropTypes.string,
 };
 
 const runtime = {
   // unique id for the runtime
   id: PropTypes.string.isRequired,
 
   // object containing non standard properties that depend on the runtime type,
   // unavailable on this-firefox runtime
--- a/devtools/shared/adb/adb-runtime.js
+++ b/devtools/shared/adb/adb-runtime.js
@@ -1,41 +1,56 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 const { RuntimeTypes } = require("devtools/client/webide/modules/runtime-types");
 const { prepareTCPConnection } = require("devtools/shared/adb/commands/index");
+const { shell } = require("devtools/shared/adb/commands/index");
 
 class AdbRuntime {
   constructor(adbDevice, socketPath) {
     this.type = RuntimeTypes.USB;
 
     this._adbDevice = adbDevice;
     this._socketPath = socketPath;
   }
 
+  async init() {
+    const packageName = this._packageName();
+    const query = `dumpsys package ${packageName} | grep versionName`;
+    const versionNameString = await shell(this._adbDevice.id, query);
+    const matches = versionNameString.match(/versionName=([\d.]+)/);
+    if (matches && matches[1]) {
+      this._versionName = matches[1];
+    }
+  }
+
   get id() {
     return this._adbDevice.id + "|" + this._socketPath;
   }
 
   get isFenix() {
     return this._packageName().includes("org.mozilla.fenix");
   }
 
   get deviceId() {
     return this._adbDevice.id;
   }
 
   get deviceName() {
     return this._adbDevice.name;
   }
 
+  get versionName() {
+    return this._versionName;
+  }
+
   get shortName() {
     const packageName = this._packageName();
 
     switch (packageName) {
       case "org.mozilla.firefox":
         return "Firefox";
       case "org.mozilla.firefox_beta":
         return "Firefox Beta";
--- a/devtools/shared/adb/adb.js
+++ b/devtools/shared/adb/adb.js
@@ -129,13 +129,19 @@ class Adb extends EventEmitter {
   }
 
   _onNoDevicesDetected() {
     this.updateRuntimes();
   }
 
   async _getDeviceRuntimes(device) {
     const socketPaths = [...await device.getRuntimeSocketPaths()];
-    return socketPaths.map(socketPath => new AdbRuntime(device, socketPath));
+    const runtimes = [];
+    for (const socketPath of socketPaths) {
+      const runtime = new AdbRuntime(device, socketPath);
+      await runtime.init();
+      runtimes.push(runtime);
+    }
+    return runtimes;
   }
 }
 
 exports.adb = new Adb();