Skip to content

Commit

Permalink
Fix crash caused by stylus battery delegate
Browse files Browse the repository at this point in the history
Crash occurs if a stylus battery update
comes in before the `battery_update_callback_` is set in
the `BatteryView` constructor.
Adding protective check to make sure we don't use the callback
before it is set.

(cherry picked from commit 45f13e7)

Bug: 1184918
Change-Id: I1a9496986f2ca168648a6400734b26104c0c1377
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2738919
Commit-Queue: Ahmed Mehfooz <amehfooz@chromium.org>
Reviewed-by: Toni Baržić <tbarzic@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#860328}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2739655
Cr-Commit-Position: refs/branch-heads/4430@{#210}
Cr-Branched-From: e5ce7dc-refs/heads/master@{#857950}
  • Loading branch information
amehfooz32 authored and Chromium LUCI CQ committed Mar 7, 2021
1 parent 7ca5df7 commit de97478
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ash/system/palette/stylus_battery_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ void StylusBatteryDelegate::OnAddingBattery(
battery_level_ = battery.level;
battery_charge_status_ = battery.charge_status;
last_update_timestamp_ = battery.last_update_timestamp;
battery_update_callback_.Run();
if (battery_update_callback_)
battery_update_callback_.Run();
}

void StylusBatteryDelegate::OnRemovingBattery(
Expand All @@ -106,7 +107,8 @@ void StylusBatteryDelegate::OnUpdatedBatteryLevel(
battery_level_ = battery.level;
battery_charge_status_ = battery.charge_status;
last_update_timestamp_ = battery.last_update_timestamp;
battery_update_callback_.Run();
if (battery_update_callback_)
battery_update_callback_.Run();
}

} // namespace ash

0 comments on commit de97478

Please sign in to comment.