Bug 1426936 - When reading the battery capacity on Mac do not assume that a battery is always present; r=dhylands
authorGabriele Svelto <gsvelto@mozilla.com>
Mon, 05 Mar 2018 23:35:36 +0100
changeset 407345 1f522b139917c38f2b4eb88c8ea00247219579d4
parent 407344 142b4e5c97592d877598b64bd5db3e8199d354d6
child 407346 d1a36af94ccd8800d7538a9f9510c39dbcc090f5
push id100640
push usergsvelto@mozilla.com
push dateFri, 09 Mar 2018 10:43:32 +0000
treeherdermozilla-inbound@1f522b139917 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdhylands
bugs1426936
milestone60.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 1426936 - When reading the battery capacity on Mac do not assume that a battery is always present; r=dhylands MozReview-Commit-ID: ArLSxMUE66e
hal/cocoa/CocoaBattery.cpp
--- a/hal/cocoa/CocoaBattery.cpp
+++ b/hal/cocoa/CocoaBattery.cpp
@@ -249,19 +249,23 @@ MacPowerInformationService::HandleChange
   // Usually there's only 1 available, depending on current power source.
   for (CFIndex i = 0; i < ::CFArrayGetCount(list); ++i) {
     CFTypeRef source = ::CFArrayGetValueAtIndex(list, i);
     CFDictionaryRef currPowerSourceDesc = ::IOPSGetPowerSourceDescription(data, source);
     if (!currPowerSourceDesc) {
       continue;
     }
 
-    // Get a battery level estimate. This key is required.
+    // Get a battery level estimate. This key is required but does not always
+    // exist.
     int currentCapacity = 0;
     const void* cfRef = ::CFDictionaryGetValue(currPowerSourceDesc, CFSTR(kIOPSCurrentCapacityKey));
+    if (!cfRef) {
+      continue;
+    }
     ::CFNumberGetValue((CFNumberRef)cfRef, kCFNumberSInt32Type, &currentCapacity);
 
     // This key is also required.
     int maxCapacity = 0;
     cfRef = ::CFDictionaryGetValue(currPowerSourceDesc, CFSTR(kIOPSMaxCapacityKey));
     ::CFNumberGetValue((CFNumberRef)cfRef, kCFNumberSInt32Type, &maxCapacity);
 
     if (maxCapacity > 0) {