Skip to content

Commit 2a15ffd

Browse files
authored
Merge pull request #34232 from bdach/android-stream-versioning
Fix android builds losing awareness of their release stream
2 parents 66a4cb5 + 2890a19 commit 2a15ffd

File tree

1 file changed

+12
-38
lines changed

1 file changed

+12
-38
lines changed

osu.Android/OsuGameAndroid.cs

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
// See the LICENCE file in the repository root for full licence text.
33

44
using System;
5+
using System.Linq;
56
using Android.App;
67
using Android.Content.PM;
78
using Microsoft.Maui.Devices;
89
using osu.Framework.Allocation;
10+
using osu.Framework.Development;
911
using osu.Framework.Extensions.ObjectExtensions;
1012
using osu.Framework.Platform;
1113
using osu.Game;
@@ -21,58 +23,30 @@ public partial class OsuGameAndroid : OsuGame
2123
[Cached]
2224
private readonly OsuGameActivity gameActivity;
2325

26+
private readonly PackageInfo packageInfo;
27+
2428
public override Vector2 ScalingContainerTargetDrawSize => new Vector2(1024, 1024 * DrawHeight / DrawWidth);
2529

2630
public OsuGameAndroid(OsuGameActivity activity)
2731
: base(null)
2832
{
2933
gameActivity = activity;
34+
packageInfo = Application.Context.ApplicationContext!.PackageManager!.GetPackageInfo(Application.Context.ApplicationContext.PackageName!, 0).AsNonNull();
3035
}
3136

32-
public override Version AssemblyVersion
37+
public override string Version
3338
{
3439
get
3540
{
36-
var packageInfo = Application.Context.ApplicationContext!.PackageManager!.GetPackageInfo(Application.Context.ApplicationContext.PackageName!, 0).AsNonNull();
37-
38-
try
39-
{
40-
// We store the osu! build number in the "VersionCode" field to better support google play releases.
41-
// If we were to use the main build number, it would require a new submission each time (similar to TestFlight).
42-
// In order to do this, we should split it up and pad the numbers to still ensure sequential increase over time.
43-
//
44-
// We also need to be aware that older SDK versions store this as a 32bit int.
45-
//
46-
// Basic conversion format (as done in Fastfile): 2020.606.0 -> 202006060
47-
48-
// https://stackoverflow.com/questions/52977079/android-sdk-28-versioncode-in-packageinfo-has-been-deprecated
49-
string versionName;
50-
51-
if (OperatingSystem.IsAndroidVersionAtLeast(28))
52-
{
53-
versionName = packageInfo.LongVersionCode.ToString();
54-
// ensure we only read the trailing portion of long (the part we are interested in).
55-
versionName = versionName.Substring(versionName.Length - 9);
56-
}
57-
else
58-
{
59-
#pragma warning disable CS0618 // Type or member is obsolete
60-
// this is required else older SDKs will report missing method exception.
61-
versionName = packageInfo.VersionCode.ToString();
62-
#pragma warning restore CS0618 // Type or member is obsolete
63-
}
64-
65-
// undo play store version garbling (as mentioned above).
66-
return new Version(int.Parse(versionName.Substring(0, 4)), int.Parse(versionName.Substring(4, 4)), int.Parse(versionName.Substring(8, 1)));
67-
}
68-
catch
69-
{
70-
}
71-
72-
return new Version(packageInfo.VersionName.AsNonNull());
41+
if (!IsDeployedBuild)
42+
return @"local " + (DebugUtils.IsDebugBuild ? @"debug" : @"release");
43+
44+
return packageInfo.VersionName.AsNonNull();
7345
}
7446
}
7547

48+
public override Version AssemblyVersion => new Version(packageInfo.VersionName.AsNonNull().Split('-').First());
49+
7650
protected override void LoadComplete()
7751
{
7852
base.LoadComplete();

0 commit comments

Comments
 (0)