コード例 #1
0
void BatteryManager::UpdateFromBatteryInfo(
    const hal::BatteryInformation& aBatteryInfo) {
  mLevel = aBatteryInfo.level();

  // Round to the nearest ten percent for non-chrome.
  nsIDocument* doc = GetOwner() ? GetOwner()->GetDoc() : nullptr;

  mCharging = aBatteryInfo.charging();
  mRemainingTime = aBatteryInfo.remainingTime();

  if (!nsContentUtils::IsChromeDoc(doc)) {
    mLevel = lround(mLevel * 10.0) / 10.0;
    if (mLevel == 1.0) {
      mRemainingTime =
          mCharging ? kDefaultRemainingTime : kUnknownRemainingTime;
    } else if (mRemainingTime != kUnknownRemainingTime) {
      // Round the remaining time to a multiple of 15 minutes and never zero
      const double MINUTES_15 = 15.0 * 60.0;
      mRemainingTime =
          fmax(lround(mRemainingTime / MINUTES_15) * MINUTES_15, MINUTES_15);
    }
  }

  // Add some guards to make sure the values are coherent.
  if (mLevel == 1.0 && mCharging == true &&
      mRemainingTime != kDefaultRemainingTime) {
    mRemainingTime = kDefaultRemainingTime;
    NS_ERROR(
        "Battery API: When charging and level at 1.0, remaining time "
        "should be 0. Please fix your backend!");
  }
}
コード例 #2
0
void
BatteryManager::UpdateFromBatteryInfo(const hal::BatteryInformation& aBatteryInfo)
{
  mLevel = aBatteryInfo.level();

  // Round to the nearest ten percent for non-chrome and non-certified apps
  nsIDocument* doc = GetOwner()->GetDoc();
  uint16_t status = nsIPrincipal::APP_STATUS_NOT_INSTALLED;
  if (doc) {
    doc->NodePrincipal()->GetAppStatus(&status);
  }

  if (!nsContentUtils::IsChromeDoc(doc) &&
      status != nsIPrincipal::APP_STATUS_CERTIFIED)
  {
    mLevel = lround(mLevel * 10.0) / 10.0;
  }

  mCharging = aBatteryInfo.charging();
  mRemainingTime = aBatteryInfo.remainingTime();

  // Add some guards to make sure the values are coherent.
  if (mLevel == 1.0 && mCharging == true &&
      mRemainingTime != kDefaultRemainingTime) {
    mRemainingTime = kDefaultRemainingTime;
    NS_ERROR("Battery API: When charging and level at 1.0, remaining time "
             "should be 0. Please fix your backend!");
  }
}
コード例 #3
0
void
BatteryManager::UpdateFromBatteryInfo(const hal::BatteryInformation& aBatteryInfo)
{
  mLevel = aBatteryInfo.level();
  mCharging = aBatteryInfo.charging();
  mRemainingTime = aBatteryInfo.remainingTime();

  // Add some guards to make sure the values are coherent.
  if (mLevel == 1.0 && mCharging == true &&
      mRemainingTime != kDefaultRemainingTime) {
    mRemainingTime = kDefaultRemainingTime;
    NS_ERROR("Battery API: When charging and level at 1.0, remaining time "
             "should be 0. Please fix your backend!");
  }
}
コード例 #4
0
ファイル: WindowsBattery.cpp プロジェクト: jianglu/v8monkey
static void
UpdateHandler(nsITimer* aTimer, void* aClosure) {
  NS_ASSERTION(!IsVistaOrLater(),
               "We shouldn't call this function for Vista or later version!");

  static hal::BatteryInformation sLastInfo;
  hal::BatteryInformation currentInfo;

  hal_impl::GetCurrentBatteryInformation(&currentInfo);
  if (sLastInfo.level() != currentInfo.level() ||
      sLastInfo.charging() != currentInfo.charging() ||
      sLastInfo.remainingTime() != currentInfo.remainingTime()) {
    hal::NotifyBatteryChange(currentInfo);
    sLastInfo = currentInfo;
  }
}
コード例 #5
0
ファイル: BluetoothHfpManager.cpp プロジェクト: atilag/Gecko
void
BluetoothHfpManager::Notify(const hal::BatteryInformation& aBatteryInfo)
{
  // Range of battery level: [0, 1], double
  // Range of CIND::BATTCHG: [0, 5], int
  mBattChg = (int) round(aBatteryInfo.level() * 5.0);
  UpdateDeviceCIND();
}
コード例 #6
0
 void Notify(const hal::BatteryInformation& aBatteryInfo)
 {
   // Range of battery level: [0, 1], double
   // Range of CIND::BATTCHG: [0, 5], int
   int level = ceil(aBatteryInfo.level() * 5.0);
   if (level != sCINDItems[CINDType::BATTCHG].value) {
     sCINDItems[CINDType::BATTCHG].value = level;
     gBluetoothHfpManager->SendCommand("+CIEV: ", CINDType::BATTCHG);
   }
 }