From db2f33f9215acfe0b9d1d20c3dc8957d5d04e532 Mon Sep 17 00:00:00 2001 From: Jared Hirsch Date: Wed, 15 Aug 2018 14:55:19 -0700 Subject: [PATCH] Replace Telemetry pref check with Telemetry API check --- addon/bootstrap.js | 6 +----- addon/webextension/background/analytics.js | 10 +++------- addon/webextension/manifest.json.template | 1 + 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/addon/bootstrap.js b/addon/bootstrap.js index b2519e6819..8da03116d8 100644 --- a/addon/bootstrap.js +++ b/addon/bootstrap.js @@ -1,6 +1,5 @@ /* globals ADDON_DISABLE Services CustomizableUI LegacyExtensionsUtils AppConstants PageActions */ const ADDON_ID = "screenshots@mozilla.org"; -const TELEMETRY_ENABLED_PREF = "datareporting.healthreport.uploadEnabled"; const PREF_BRANCH = "extensions.screenshots."; const USER_DISABLE_PREF = "extensions.screenshots.disabled"; const UPLOAD_DISABLED_PREF = "extensions.screenshots.upload-disabled"; @@ -178,10 +177,7 @@ function handleMessage(msg, sender, sendReply) { return; } - if (msg.funcName === "isTelemetryEnabled") { - const telemetryEnabled = getBoolPref(TELEMETRY_ENABLED_PREF); - sendReply({type: "success", value: telemetryEnabled}); - } else if (msg.funcName === "isUploadDisabled") { + if (msg.funcName === "isUploadDisabled") { const isESR = AppConstants.MOZ_UPDATE_CHANNEL === "esr"; const uploadDisabled = getBoolPref(UPLOAD_DISABLED_PREF); sendReply({type: "success", value: uploadDisabled || isESR}); diff --git a/addon/webextension/background/analytics.js b/addon/webextension/background/analytics.js index a9157d728a..3dcf14392d 100644 --- a/addon/webextension/background/analytics.js +++ b/addon/webextension/background/analytics.js @@ -1,4 +1,4 @@ -/* globals main, auth, catcher, deviceInfo, communication, log */ +/* globals main, auth, browser, catcher, deviceInfo, communication, log */ "use strict"; @@ -129,13 +129,9 @@ this.analytics = (function() { }; exports.refreshTelemetryPref = function() { - return communication.sendToBootstrap("isTelemetryEnabled").then((result) => { + return browser.telemetry.canUpload().then((result) => { telemetryPrefKnown = true; - if (result === communication.NO_BOOTSTRAP) { - telemetryEnabled = true; - } else { - telemetryEnabled = result; - } + telemetryEnabled = result; }, (error) => { // If there's an error reading the pref, we should assume that we shouldn't send data telemetryPrefKnown = true; diff --git a/addon/webextension/manifest.json.template b/addon/webextension/manifest.json.template index 9d91405931..bacdb751e1 100644 --- a/addon/webextension/manifest.json.template +++ b/addon/webextension/manifest.json.template @@ -70,6 +70,7 @@ "clipboardWrite", "contextMenus", "mozillaAddons", + "telemetry", "", "http://localhost:10080/", "resource://pdf.js/",