Bug 1703307 - Include `app.update.background.enabled` in Telemetry Environment r=chutten,nalexander
authorKirk Steuber <ksteuber@mozilla.com>
Thu, 22 Apr 2021 18:35:16 +0000
changeset 577138 eb40719c0827ea6c5a06bcf497bedc2a7df9d7be
parent 577137 b35ee13d7aa5321bdf84a47d0215ca6570589ef7
child 577139 4a2b343c670f80a8e61fa1a98ba2f573745a933e
push id141776
push userksteuber@mozilla.com
push dateThu, 22 Apr 2021 19:09:02 +0000
treeherderautoland@eb40719c0827 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschutten, nalexander
bugs1703307
milestone90.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 1703307 - Include `app.update.background.enabled` in Telemetry Environment r=chutten,nalexander Differential Revision: https://phabricator.services.mozilla.com/D112076
toolkit/components/telemetry/app/TelemetryEnvironment.jsm
toolkit/components/telemetry/docs/data/environment.rst
toolkit/components/telemetry/tests/unit/TelemetryEnvironmentTesting.jsm
--- a/toolkit/components/telemetry/app/TelemetryEnvironment.jsm
+++ b/toolkit/components/telemetry/app/TelemetryEnvironment.jsm
@@ -353,17 +353,21 @@ const COMPOSITOR_PROCESS_ABORTED_TOPIC =
 const DISTRIBUTION_CUSTOMIZATION_COMPLETE_TOPIC =
   "distribution-customization-complete";
 const GFX_FEATURES_READY_TOPIC = "gfx-features-ready";
 const SEARCH_ENGINE_MODIFIED_TOPIC = "browser-search-engine-modified";
 const SEARCH_SERVICE_TOPIC = "browser-search-service";
 const SESSIONSTORE_WINDOWS_RESTORED_TOPIC = "sessionstore-windows-restored";
 const PREF_CHANGED_TOPIC = "nsPref:changed";
 const BLOCKLIST_LOADED_TOPIC = "plugin-blocklist-loaded";
-const AUTO_UPDATE_PREF_CHANGE_TOPIC = "auto-update-config-change";
+const AUTO_UPDATE_PREF_CHANGE_TOPIC =
+  UpdateUtils.PER_INSTALLATION_PREFS["app.update.auto"].observerTopic;
+const BACKGROUND_UPDATE_PREF_CHANGE_TOPIC =
+  UpdateUtils.PER_INSTALLATION_PREFS["app.update.background.enabled"]
+    .observerTopic;
 const SERVICES_INFO_CHANGE_TOPIC = "sync-ui-state:update";
 
 /**
  * Enforces the parameter to a boolean value.
  * @param aValue The input value.
  * @return {Boolean|Object} If aValue is a boolean or a number, returns its truthfulness
  *         value. Otherwise, return null.
  */
@@ -941,17 +945,17 @@ function EnvironmentCache() {
   this._addonBuilder = new EnvironmentAddonBuilder(this);
   p.push(this._addonBuilder.init());
 
   this._currentEnvironment.profile = {};
   p.push(this._updateProfile());
   if (AppConstants.MOZ_BUILD_APP == "browser") {
     p.push(this._loadAttributionAsync());
   }
-  p.push(this._loadAutoUpdateAsync());
+  p.push(this._loadAsyncUpdateSettings());
   p.push(this._loadIntlData());
 
   for (const [
     id,
     { branch, options },
   ] of gActiveExperimentStartupBuffer.entries()) {
     this.setExperimentActive(id, branch, options);
   }
@@ -1280,16 +1284,17 @@ EnvironmentCache.prototype = {
     Services.obs.addObserver(this, SESSIONSTORE_WINDOWS_RESTORED_TOPIC);
     Services.obs.addObserver(this, COMPOSITOR_CREATED_TOPIC);
     Services.obs.addObserver(this, COMPOSITOR_PROCESS_ABORTED_TOPIC);
     Services.obs.addObserver(this, DISTRIBUTION_CUSTOMIZATION_COMPLETE_TOPIC);
     Services.obs.addObserver(this, GFX_FEATURES_READY_TOPIC);
     Services.obs.addObserver(this, SEARCH_ENGINE_MODIFIED_TOPIC);
     Services.obs.addObserver(this, SEARCH_SERVICE_TOPIC);
     Services.obs.addObserver(this, AUTO_UPDATE_PREF_CHANGE_TOPIC);
+    Services.obs.addObserver(this, BACKGROUND_UPDATE_PREF_CHANGE_TOPIC);
     Services.obs.addObserver(this, SERVICES_INFO_CHANGE_TOPIC);
   },
 
   _removeObservers() {
     Services.obs.removeObserver(this, SESSIONSTORE_WINDOWS_RESTORED_TOPIC);
     Services.obs.removeObserver(this, COMPOSITOR_CREATED_TOPIC);
     Services.obs.removeObserver(this, COMPOSITOR_PROCESS_ABORTED_TOPIC);
     try {
@@ -1297,16 +1302,17 @@ EnvironmentCache.prototype = {
         this,
         DISTRIBUTION_CUSTOMIZATION_COMPLETE_TOPIC
       );
     } catch (ex) {}
     Services.obs.removeObserver(this, GFX_FEATURES_READY_TOPIC);
     Services.obs.removeObserver(this, SEARCH_ENGINE_MODIFIED_TOPIC);
     Services.obs.removeObserver(this, SEARCH_SERVICE_TOPIC);
     Services.obs.removeObserver(this, AUTO_UPDATE_PREF_CHANGE_TOPIC);
+    Services.obs.removeObserver(this, BACKGROUND_UPDATE_PREF_CHANGE_TOPIC);
     Services.obs.removeObserver(this, SERVICES_INFO_CHANGE_TOPIC);
   },
 
   observe(aSubject, aTopic, aData) {
     this._log.trace("observe - aTopic: " + aTopic + ", aData: " + aData);
     switch (aTopic) {
       case SEARCH_ENGINE_MODIFIED_TOPIC:
         if (
@@ -1365,16 +1371,19 @@ EnvironmentCache.prototype = {
         let options = this._watchedPrefs.get(aData);
         if (options && !options.requiresRestart) {
           this._onPrefChanged(aData);
         }
         break;
       case AUTO_UPDATE_PREF_CHANGE_TOPIC:
         this._currentEnvironment.settings.update.autoDownload = aData == "true";
         break;
+      case BACKGROUND_UPDATE_PREF_CHANGE_TOPIC:
+        this._currentEnvironment.settings.update.background = aData == "true";
+        break;
       case SERVICES_INFO_CHANGE_TOPIC:
         this._updateServicesInfo();
         break;
     }
   },
 
   /**
    * Update the default search engine value.
@@ -1576,17 +1585,17 @@ EnvironmentCache.prototype = {
     } catch (e) {}
 
     this._currentEnvironment.settings.addonCompatibilityCheckEnabled =
       AddonManager.checkCompatibility;
 
     this._updateAttribution();
     this._updateDefaultBrowser();
     await this._updateSearchEngine();
-    this._updateAutoDownload();
+    this._loadAsyncUpdateSettingsFromCache();
   },
 
   _getSandboxData() {
     let effectiveContentProcessLevel = null;
     try {
       let sandboxSettings = Cc[
         "@mozilla.org/sandbox/sandbox-settings;1"
       ].getService(Ci.mozISandboxSettings);
@@ -1661,36 +1670,43 @@ EnvironmentCache.prototype = {
         data[key],
         MAX_ATTRIBUTION_STRING_LENGTH
       );
     }
     this._currentEnvironment.settings.attribution = attributionData;
   },
 
   /**
-   * Load the auto update pref and adds it to the environment
+   * Load the per-installation update settings, cache them, and add them to the
+   * environment.
    */
-  async _loadAutoUpdateAsync() {
+  async _loadAsyncUpdateSettings() {
     if (AppConstants.MOZ_UPDATER) {
       this._updateAutoDownloadCache = await UpdateUtils.getAppUpdateAutoEnabled();
+      this._updateBackgroundCache = await UpdateUtils.readUpdateConfigSetting(
+        "app.update.background.enabled"
+      );
     } else {
       this._updateAutoDownloadCache = false;
+      this._updateBackgroundCache = false;
     }
-    this._updateAutoDownload();
+    this._loadAsyncUpdateSettingsFromCache();
   },
 
   /**
-   * Update the environment with the cached value for whether updates can auto-
-   * download.
+   * Update the environment with the cached values for per-installation update
+   * settings.
    */
-  _updateAutoDownload() {
-    if (this._updateAutoDownloadCache === undefined) {
-      return;
+  _loadAsyncUpdateSettingsFromCache() {
+    if (this._updateAutoDownloadCache !== undefined) {
+      this._currentEnvironment.settings.update.autoDownload = this._updateAutoDownloadCache;
     }
-    this._currentEnvironment.settings.update.autoDownload = this._updateAutoDownloadCache;
+    if (this._updateBackgroundCache !== undefined) {
+      this._currentEnvironment.settings.update.background = this._updateBackgroundCache;
+    }
   },
 
   /**
    * Get i18n data about the system.
    * @return A promise of completion.
    */
   async _loadIntlData() {
     // Wait for the startup topic.
--- a/toolkit/components/telemetry/docs/data/environment.rst
+++ b/toolkit/components/telemetry/docs/data/environment.rst
@@ -62,16 +62,17 @@ Structure:
           systemLocales: [ <string>, ... ], // The locales for the OS.
           regionalPrefsLocales: [ <string>, ... ], // The regional preferences for the OS.
           acceptLanguages: [ <string>, ... ], // The languages for the Accept-Languages header.
         },
         update: {
           channel: <string>, // e.g. "release", null on failure
           enabled: <bool>, // true on failure
           autoDownload: <bool>, // true on failure
+          background: <bool>, // Indicates whether updates may be installed when Firefox is not running.
         },
         userPrefs: {
           // Only prefs which are changed are listed in this block
           "pref.name.value": value // some prefs send the value
           "pref.name.url": "<user-set>" // For some privacy-sensitive prefs
             // only the fact that the value has been changed is recorded
         },
         attribution: { // optional, only present if the installation has attribution data
--- a/toolkit/components/telemetry/tests/unit/TelemetryEnvironmentTesting.jsm
+++ b/toolkit/components/telemetry/tests/unit/TelemetryEnvironmentTesting.jsm
@@ -292,16 +292,17 @@ var TelemetryEnvironmentTesting = {
       Assert.ok(this.checkNullOrBool(data.settings.isDefaultBrowser));
     }
 
     // Check "channel" separately, as it can either be null or string.
     let update = data.settings.update;
     Assert.ok(this.checkNullOrString(update.channel));
     Assert.equal(typeof update.enabled, "boolean");
     Assert.equal(typeof update.autoDownload, "boolean");
+    Assert.equal(typeof update.background, "boolean");
 
     // Check "defaultSearchEngine" separately, as it can either be undefined or string.
     if ("defaultSearchEngine" in data.settings) {
       this.checkString(data.settings.defaultSearchEngine);
       Assert.equal(typeof data.settings.defaultSearchEngineData, "object");
     }
 
     if ("defaultPrivateSearchEngineData" in data.settings) {