Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Avoid possible crash using essentials Battery #18386

Merged
merged 7 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Essentials/src/Battery/Battery.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void StopBatteryListeners()
{
System.Diagnostics.Debug.WriteLine("Battery receiver already unregistered. Disposing of it.");
}
batteryReceiver.Dispose();
batteryReceiver?.Dispose();
jsuarezruiz marked this conversation as resolved.
Show resolved Hide resolved
batteryReceiver = null;
}

Expand Down
10 changes: 10 additions & 0 deletions src/Essentials/test/DeviceTests/Tests/Battery_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,15 @@ public void App_Is_Not_Lower_Power_mode()
{
Assert.Equal(EnergySaverStatus.Off, Battery.EnergySaverStatus);
}

[Fact]
public void No_Unsubscribe_Crash()
{
// TODO: the test runner app (UI version) should do this, until then...
if (!HardwareSupport.HasBattery)
return;

Battery.BatteryInfoChanged -= (sender, args) => { };
}
}
}