-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Send a warning notification if device is unplugged and at low battery #12330
Conversation
- Uses Xamarin.Essentials in osu.Game.PlayerLoader to check battery level - Encapsulated battery checking in the public BatteryManager class so battery level and plugged in status can be accessed and edited in TestPlayerLoader - When checking battery level, catch NotImplementedException thrown by Xamarin.Essentials.Battery on non-mobile platforms - Added visual unit tests for battery notification To mock battery status and level, we had to define a batteryManager object in TestPlayerLoader and add a new function ResetPlayerWithBattery() Co-Authored-By: Marlina José <marlina@umich.edu>
Importing a platform-specific package and using it in the main One common way to do it would be to make an abstract For test case, you would make a dummy battery status class and cache from the test scene. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above.
Thanks for the review. I added an abstract OsuGameDesktop.cs internal class OsuGameDesktop : OsuGame
{
// ...
[Cached]
protected readonly PowerStatus PowerStatus = new DesktopPowerStatus();
// ...
[Cached]
private class DesktopPowerStatus : PowerStatus
{
public override double ChargeLevel => 1;
public override bool IsCharging => true;
}
} PlayerLoader.cs namespace osu.Game.Screens.Play
{
public class PlayerLoader : ScreenWithBeatmapBackground
{
[Resolved]
private PowerStatus PowerStatus { get; set; }
// ...
}
} How should I should be registering The commit: Cublibre@3289f9a |
Honestly why don't we just keep this simple and make it a global notification rather than only on entering gameplay? In addition, does your operating system not tell you this already?? iOS will show battery warnings at a system level, so I don't believe we even want this implemented for the iOS platform. Is it not a thing on android? |
It most certainly is a thing on any platform, although on android it might depend on the manufacturer. But isn't the idea here that the in game notification would appear before the OS one and be less intrusive. If the OS shows the notification it would unexpectedly pause gameplay. |
Fair, but that should be documented if so, along with the cutoffs for the operating systems showing the notifications themselves. |
@Cublibre the code you have looks quite correct. what is the issue you're running into with DI? One thing I've noticed is that it will likely crash on non-mobile platforms because the cached |
- Removed the Xamarin.Essentials package from osu.Game and added it to osu.iOS and osu.Android only. - iOS and Android implementations use Xamarin.Essentials.Battery, while the Desktop implementation only returns 100% battery for now. - Added a BatteryCutoff property to PowerStatus so it can be different for each platform (default 20%, 25% on iOS)
I added a |
sorry about the style fixes... I'm using JetBrains Rider from now on.
Right now, we are trying to cache the PowerStatus dependency in OsuGameBase and initialize it within each platform (Android, iOS), but we are running into an issue as seen in the CI logs related to a Null value within an argument. We are initializing the PowerStatus within OsuTestBrowser, but is there somewhere else we should be doing this? |
This is the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor code quality notes. Haven't tested this yet.
…tatus class in test scene
Thanks. How do I cherry-pick those commits? They don't exist on any branch so |
Oh whoops forgot about that, they're from this branch you can checkout here: https://github.com/ppy/osu/compare/master..frenzibyte:low-battery |
I've pushed the changes. |
Missing this commit frenzibyte@bb7c40b? |
My bad, I didn't realize cherry-pick doesn't include the first commit in a given range. Thanks for pointing that out! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
As an aside, if you wish to further contribute here, I would recommend reading the contributing guidelines if you haven't already, as I see you've PR'd this off the master
branch, instead of a separate branch.
@@ -16,6 +16,7 @@ protected override void InitialiseDefaults() | |||
{ | |||
SetDefault(Static.LoginOverlayDisplayed, false); | |||
SetDefault(Static.MutedAudioNotificationShownOnce, false); | |||
SetDefault(Static.LowBatteryNotificationShownOnce, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing to note is that if the app is never closed, this will not be reset, meaning potentially it will not be displaying when the user may want it to. I'm not sure if that's an issue which should be solved in this PR, or whether it's a SessionStatics
issue (one could argue the other features using this class suffer from the same flaw, and should be reset when the app goes inactive or after a certain period of time).
Leaning towards the latter.
Related to #12239
Description
Imported
Xamarin.Essentials.Battery
toosu.Game
to detect battery information on all platforms. If the device's battery level is below some value (currently 20%) and not plugged in, sends a notification similar to the muted notification (only once per game session, upon loading a beatmap). Doesn't detect battery information on desktop versions because .NET standard is unsupported by Xamarin.Essentials.Type of change
How Has This Been Tested?
TestScenePlayerLoader.cs:TestLowBatteryNotification
with different battery configurationsCo-Authored-By: Marlina José marlina@umich.edu