Bug 1003020 - Update to the latest battery level when HFP manager initializes, r=shuang

This commit is contained in:
Ben Tian 2014-04-29 19:12:36 +08:00
parent cb4cbe2613
commit 8ca90b6b5b
2 changed files with 10 additions and 2 deletions

View File

@ -406,6 +406,10 @@ BluetoothHfpManager::Init()
}
hal::RegisterBatteryObserver(this);
// Update to the latest battery level
hal::BatteryInformation batteryInfo;
hal::GetCurrentBatteryInformation(&batteryInfo);
Notify(batteryInfo);
mListener = new BluetoothRilListener();
NS_ENSURE_TRUE(mListener->Listen(true), false);
@ -521,7 +525,7 @@ BluetoothHfpManager::Notify(const hal::BatteryInformation& aBatteryInfo)
{
// Range of battery level: [0, 1], double
// Range of CIND::BATTCHG: [0, 5], int
mBattChg = (int) ceil(aBatteryInfo.level() * 5.0);
mBattChg = (int) round(aBatteryInfo.level() * 5.0);
UpdateDeviceCIND();
}

View File

@ -220,7 +220,7 @@ BluetoothHfpManager::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);
int level = round(aBatteryInfo.level() * 5.0);
if (level != sCINDItems[CINDType::BATTCHG].value) {
sCINDItems[CINDType::BATTCHG].value = level;
SendCommand(RESPONSE_CIEV, CINDType::BATTCHG);
@ -425,6 +425,10 @@ BluetoothHfpManager::Init()
}
hal::RegisterBatteryObserver(this);
// Update to the latest battery level
hal::BatteryInformation batteryInfo;
hal::GetCurrentBatteryInformation(&batteryInfo);
Notify(batteryInfo);
#ifdef MOZ_B2G_RIL
mListener = new BluetoothRilListener();