Bug 1409468 - Add a property appleModelId to telemetry's environment data to collect model IDs for Apple desktop devices. r=mstange, r=francois, a=ritu
authorStephen A Pohl <spohl.mozilla.bugs@gmail.com>
Wed, 18 Oct 2017 14:52:06 -0400
changeset 432650 13789fec0a4be336215d1567972160e63217396e
parent 432649 cba3cbf27533a3e888858074449f9427d1ef2403
child 432651 428c84cbc00a0b2fe10f10886c83aeb3d1baa044
push id8020
push userryanvm@gmail.com
push dateFri, 20 Oct 2017 21:59:23 +0000
treeherdermozilla-beta@add4a60517c0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange, francois, ritu
bugs1409468
milestone57.0
Bug 1409468 - Add a property appleModelId to telemetry's environment data to collect model IDs for Apple desktop devices. r=mstange, r=francois, a=ritu
toolkit/components/telemetry/TelemetryEnvironment.jsm
toolkit/components/telemetry/docs/data/environment.rst
xpcom/base/nsSystemInfo.cpp
--- a/toolkit/components/telemetry/TelemetryEnvironment.jsm
+++ b/toolkit/components/telemetry/TelemetryEnvironment.jsm
@@ -1642,16 +1642,17 @@ EnvironmentCache.prototype = {
 
     let data = {
       memoryMB,
       virtualMaxMB: virtualMB,
       cpu: this._getCpuData(),
       os: this._getOSData(),
       hdd: this._getHDDData(),
       gfx: this._getGFXData(),
+      appleModelId: getSysinfoProperty("appleModelId", null),
     };
 
     if (AppConstants.platform === "win") {
       data.isWow64 = getSysinfoProperty("isWow64", null);
     } else if (AppConstants.platform == "android") {
       data.device = this._getDeviceData();
     }
 
--- a/toolkit/components/telemetry/docs/data/environment.rst
+++ b/toolkit/components/telemetry/docs/data/environment.rst
@@ -198,16 +198,17 @@ Structure:
               gpuProcess: { // Out-of-process compositing ("GPU process") feature
                 status: <string>, // "Available" means currently in use
               },
               advancedLayers: { // Advanced Layers compositing. Only present if D3D11 enabled.
                 status: <string>,    // See the status codes above.
               },
             },
           },
+        appleModelId: <string>, // Mac only or null on failure
       },
       addons: {
         activeAddons: { // the currently enabled add-ons
           <addon id>: {
             blocklisted: <bool>,
             description: <string>, // null if not available
             name: <string>,
             userDisabled: <bool>,
--- a/xpcom/base/nsSystemInfo.cpp
+++ b/xpcom/base/nsSystemInfo.cpp
@@ -232,16 +232,36 @@ nsresult GetCountryCode(nsAString& aCoun
   // numChars includes null terminator
   aCountryCode.Truncate(numChars - 1);
   return NS_OK;
 }
 
 } // namespace
 #endif // defined(XP_WIN)
 
+#ifdef XP_MACOSX
+static nsresult GetAppleModelId(nsAutoCString& aModelId)
+{
+  size_t numChars = 0;
+  size_t result = sysctlbyname("hw.model", nullptr, &numChars, nullptr, 0);
+  if (result != 0 || !numChars) {
+    return NS_ERROR_FAILURE;
+  }
+  aModelId.SetLength(numChars);
+  result = sysctlbyname("hw.model", aModelId.BeginWriting(), &numChars, nullptr,
+                        0);
+  if (result != 0) {
+    return NS_ERROR_FAILURE;
+  }
+  // numChars includes null terminator
+  aModelId.Truncate(numChars - 1);
+  return NS_OK;
+}
+#endif
+
 using namespace mozilla;
 
 nsSystemInfo::nsSystemInfo()
 {
 }
 
 nsSystemInfo::~nsSystemInfo()
 {
@@ -675,16 +695,22 @@ nsSystemInfo::Init()
 #endif
 
 #if defined(XP_MACOSX)
   nsAutoString countryCode;
   if (NS_SUCCEEDED(GetSelectedCityInfo(countryCode))) {
     rv = SetPropertyAsAString(NS_LITERAL_STRING("countryCode"), countryCode);
     NS_ENSURE_SUCCESS(rv, rv);
   }
+
+  nsAutoCString modelId;
+  if (NS_SUCCEEDED(GetAppleModelId(modelId))) {
+    rv = SetPropertyAsACString(NS_LITERAL_STRING("appleModelId"), modelId);
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
 #endif
 
 #if defined(MOZ_WIDGET_GTK)
   // This must be done here because NSPR can only separate OS's when compiled, not libraries.
   // 64 bytes is going to be well enough for "GTK " followed by 3 integers
   // separated with dots.
   char gtkver[64];
   ssize_t gtkver_len = 0;