2019-03-17 14:39:07 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using Android.App;
|
2022-12-19 06:43:12 +00:00
|
|
|
|
using Microsoft.Maui.Devices;
|
2020-10-18 18:07:42 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2022-01-15 13:38:38 +00:00
|
|
|
|
using osu.Framework.Android.Input;
|
2023-06-24 15:05:52 +00:00
|
|
|
|
using osu.Framework.Extensions.ObjectExtensions;
|
2022-01-15 13:38:38 +00:00
|
|
|
|
using osu.Framework.Input.Handlers;
|
|
|
|
|
using osu.Framework.Platform;
|
2019-03-17 14:39:07 +00:00
|
|
|
|
using osu.Game;
|
2022-01-15 13:38:38 +00:00
|
|
|
|
using osu.Game.Overlays.Settings;
|
2019-09-24 09:12:04 +00:00
|
|
|
|
using osu.Game.Updater;
|
2021-04-08 23:34:35 +00:00
|
|
|
|
using osu.Game.Utils;
|
2019-03-17 14:39:07 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Android
|
|
|
|
|
{
|
|
|
|
|
public partial class OsuGameAndroid : OsuGame
|
|
|
|
|
{
|
2020-10-18 18:07:42 +00:00
|
|
|
|
[Cached]
|
|
|
|
|
private readonly OsuGameActivity gameActivity;
|
|
|
|
|
|
|
|
|
|
public OsuGameAndroid(OsuGameActivity activity)
|
|
|
|
|
: base(null)
|
|
|
|
|
{
|
|
|
|
|
gameActivity = activity;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-24 08:45:45 +00:00
|
|
|
|
public override Version AssemblyVersion
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2023-06-24 15:05:52 +00:00
|
|
|
|
var packageInfo = Application.Context.ApplicationContext!.PackageManager!.GetPackageInfo(Application.Context.ApplicationContext.PackageName!, 0).AsNonNull();
|
2019-09-24 08:45:45 +00:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-06-16 11:16:04 +00:00
|
|
|
|
// We store the osu! build number in the "VersionCode" field to better support google play releases.
|
|
|
|
|
// If we were to use the main build number, it would require a new submission each time (similar to TestFlight).
|
|
|
|
|
// In order to do this, we should split it up and pad the numbers to still ensure sequential increase over time.
|
|
|
|
|
//
|
|
|
|
|
// We also need to be aware that older SDK versions store this as a 32bit int.
|
|
|
|
|
//
|
|
|
|
|
// Basic conversion format (as done in Fastfile): 2020.606.0 -> 202006060
|
|
|
|
|
|
|
|
|
|
// https://stackoverflow.com/questions/52977079/android-sdk-28-versioncode-in-packageinfo-has-been-deprecated
|
2023-06-24 15:05:52 +00:00
|
|
|
|
string versionName;
|
2020-06-16 11:16:04 +00:00
|
|
|
|
|
2022-12-19 06:43:12 +00:00
|
|
|
|
if (OperatingSystem.IsAndroidVersionAtLeast(28))
|
2020-06-16 11:16:04 +00:00
|
|
|
|
{
|
|
|
|
|
versionName = packageInfo.LongVersionCode.ToString();
|
2020-06-16 11:20:46 +00:00
|
|
|
|
// ensure we only read the trailing portion of long (the part we are interested in).
|
2020-06-16 11:16:04 +00:00
|
|
|
|
versionName = versionName.Substring(versionName.Length - 9);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
#pragma warning disable CS0618 // Type or member is obsolete
|
|
|
|
|
// this is required else older SDKs will report missing method exception.
|
|
|
|
|
versionName = packageInfo.VersionCode.ToString();
|
|
|
|
|
#pragma warning restore CS0618 // Type or member is obsolete
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// undo play store version garbling (as mentioned above).
|
2019-09-24 08:45:45 +00:00
|
|
|
|
return new Version(int.Parse(versionName.Substring(0, 4)), int.Parse(versionName.Substring(4, 4)), int.Parse(versionName.Substring(8, 1)));
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-24 15:05:52 +00:00
|
|
|
|
return new Version(packageInfo.VersionName.AsNonNull());
|
2019-09-24 08:45:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-24 09:12:04 +00:00
|
|
|
|
|
2020-10-14 11:43:56 +00:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
LoadComponentAsync(new GameplayScreenRotationLocker(), Add);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-15 13:38:38 +00:00
|
|
|
|
public override void SetHost(GameHost host)
|
|
|
|
|
{
|
|
|
|
|
base.SetHost(host);
|
|
|
|
|
host.Window.CursorState |= CursorState.Hidden;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-05 04:34:04 +00:00
|
|
|
|
protected override UpdateManager CreateUpdateManager() => new SimpleUpdateManager();
|
2021-04-09 01:53:42 +00:00
|
|
|
|
|
2021-04-12 14:52:12 +00:00
|
|
|
|
protected override BatteryInfo CreateBatteryInfo() => new AndroidBatteryInfo();
|
2021-04-09 21:55:41 +00:00
|
|
|
|
|
2022-01-15 13:38:38 +00:00
|
|
|
|
public override SettingsSubsection CreateSettingsSubsectionFor(InputHandler handler)
|
|
|
|
|
{
|
|
|
|
|
switch (handler)
|
|
|
|
|
{
|
|
|
|
|
case AndroidMouseHandler mh:
|
|
|
|
|
return new AndroidMouseSettings(mh);
|
|
|
|
|
|
2022-07-01 11:14:11 +00:00
|
|
|
|
case AndroidJoystickHandler jh:
|
|
|
|
|
return new AndroidJoystickSettings(jh);
|
|
|
|
|
|
2022-01-15 13:38:38 +00:00
|
|
|
|
default:
|
|
|
|
|
return base.CreateSettingsSubsectionFor(handler);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-12 14:52:12 +00:00
|
|
|
|
private class AndroidBatteryInfo : BatteryInfo
|
2021-04-08 23:34:35 +00:00
|
|
|
|
{
|
2022-07-30 12:26:19 +00:00
|
|
|
|
public override double? ChargeLevel => Battery.ChargeLevel;
|
2021-04-08 23:34:35 +00:00
|
|
|
|
|
2022-07-30 12:26:19 +00:00
|
|
|
|
public override bool OnBattery => Battery.PowerSource == BatteryPowerSource.Battery;
|
2021-04-08 23:34:35 +00:00
|
|
|
|
}
|
2019-03-17 14:39:07 +00:00
|
|
|
|
}
|
2020-06-16 12:01:10 +00:00
|
|
|
|
}
|