Skip to content

Commit 040f21c

Browse files
authored
CU-868brkjk3: Gate DeviceData code based on admin app version (#137)
NativeUtils.java now has a getInstalledAdminAppVersionName() method to retrieve the version name of the admin app MXRAndroidUtils changes: * MinAdminAppVersionSupportingDeviceData defines 1.7.74 as the minimum admin app version supporting DeviceData * IsDeviceDataSupported returns if the admin app supports DeviceData features. * GetAdminAppVersionName() that returns the version name as a string * GetAdminAppVersion() that returns the version as a Version object MXRManager now waits for DeviceData for its initialization only if the installed admin app supports DeviceData features. MXRAndroidSystem initializes DeviceData (including initializing from the last cached json) only if admin app supports DeviceData. Note: There's no version check on MXRAndroidSystem.cs#187. This allows DeviceData to start coming in during homescreen runtime the admin app updates to a version that supports DeviceData.
2 parents 9c9aa75 + f71d0ec commit 040f21c

File tree

4 files changed

+89
-7
lines changed

4 files changed

+89
-7
lines changed

Assets/MXR.SDK/Plugins/Android/NativeUtils.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,27 @@ public int getInstalledAdminAppVersionCode() {
250250
}
251251
}
252252

253+
public String getInstalledAdminAppVersionName() {
254+
try {
255+
PackageManager pm = mContext.getPackageManager();
256+
List<PackageInfo> packages = pm.getInstalledPackages(0);
257+
258+
String adminAppPackageName = getInstalledAdminAppPackageName();
259+
if (adminAppPackageName == null) return null;
260+
261+
for (PackageInfo packageInfo : packages) {
262+
if (!packageInfo.packageName.equals(adminAppPackageName)) continue;
263+
264+
return packageInfo.versionName;
265+
}
266+
267+
return null;
268+
} catch (Exception e) {
269+
Log.e("NativeUtils", e.toString());
270+
return null;
271+
}
272+
}
273+
253274
public String getSystemProperty(String key) {
254275
String result = "";
255276
try {

Assets/MXR.SDK/Runtime/Android/MXRAndroidSystem.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ public MXRAndroidSystem() {
9898
messenger.OnBoundStatusToAdminAppChanged += x =>
9999
OnAvailabilityChange?.Invoke(x);
100100

101-
InitializeDeviceData();
101+
if(MXRAndroidUtils.IsDeviceDataSupported)
102+
InitializeDeviceData();
102103
InitializeRuntimeSettingsSummary();
103104
InitializeDeviceStatus();
104105
RefreshWifiConnectionStatus();

Assets/MXR.SDK/Runtime/Android/Utils/MXRAndroidUtils.Apps.cs

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
namespace MXR.SDK {
66
public static partial class MXRAndroidUtils {
7+
/// <summary>
8+
/// The minimum Admin App version that supports the <see cref="DeviceData"/> features
9+
/// </summary>
10+
public static Version MinAdminAppVersionSupportingDeviceData => new Version(1, 7, 74);
11+
712
/// <summary>
813
/// Gets the class name using the package name of an app
914
/// </summary>
@@ -92,16 +97,67 @@ public static void LaunchAppWithPackageAndClassNames(string packageName, string
9297
public static void LaunchIntentAction(string intentAction) =>
9398
NativeUtils.SafeCall<bool>("launchIntentAction", intentAction);
9499

100+
/// <summary>
101+
/// The package name of the Admin App installed on an Android device
102+
/// </summary>
103+
/// <returns>Returns null if unsuccessful</returns>
104+
public static string GetAdminAppPackageName() {
105+
if(NativeUtils != null)
106+
return NativeUtils.SafeCall<string>("getInstalledAdminAppPackageName");
107+
return null;
108+
}
95109

96-
public static string GetAdminAppPackageName() =>
97-
NativeUtils.SafeCall<string>("getInstalledAdminAppPackageName");
98-
110+
/// <summary>
111+
/// The version code of the Admin App installed on an Android device
112+
/// </summary>
113+
/// <returns>Returns -1 if unsuccessful</returns>
99114
public static int GetAdminAppVersionCode() {
100115
if (NativeUtils != null)
101116
return NativeUtils.SafeCall<int>("getInstalledAdminAppVersionCode");
102117
return -1;
103118
}
104119

120+
/// <summary>
121+
/// The version name string of the Admin App installed on an Android device
122+
/// </summary>
123+
/// <returns>Returns null if unsuccessful</returns>
124+
public static string GetAdminAppVersionName() {
125+
if (NativeUtils != null)
126+
return NativeUtils.SafeCall<string>("getInstalledAdminAppVersionName");
127+
return null;
128+
}
129+
130+
/// <summary>
131+
/// The <see cref="Version"/> of the Admin App installed on an Android device
132+
/// </summary>
133+
/// <returns>Returns null if the version name of the installed Admin App could not be retrieved
134+
/// or if the retrieved value is invalid.
135+
/// </returns>
136+
public static Version GetAdminAppVersion() {
137+
var versionName = GetAdminAppVersionName();
138+
if (versionName == null)
139+
return null;
140+
141+
// The version name may have a hyphen, e.g. "1.0.0-test"
142+
var versionString = versionName.Split('-')[0];
143+
if (Version.TryParse(versionString, out var version))
144+
return version;
145+
return null;
146+
}
147+
148+
/// <summary>
149+
/// Whether the Admin App installed on an Android device supports the <see cref="DeviceData"/> features
150+
/// </summary>
151+
/// <returns>Returns false if the version of the installed Admin App could not be retrieved</returns>
152+
public static bool IsDeviceDataSupported {
153+
get {
154+
var version = GetAdminAppVersion();
155+
if (version == null)
156+
return false;
157+
return version >= MinAdminAppVersionSupportingDeviceData;
158+
}
159+
}
160+
105161
/// <summary>
106162
/// Returns a system property using the android.os.SystemProperties.get method
107163
/// </summary>

Assets/MXR.SDK/Runtime/MXRManager.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ async public static Task<IMXRSystem> InitAsync(IMXRSystem system = null) {
7171
Debug.unityLogger.Log("Waiting to connect to Admin App");
7272
await Task.Delay(100);
7373
}
74-
74+
7575
// Next we wait for the DeviceData, DeviceStatus and RuntimeSettingsSummary to become non null.
76-
if (System.DeviceData == null)
76+
if (!MXRAndroidUtils.IsDeviceDataSupported)
77+
Debug.unityLogger.Log(LogType.Log, TAG, $"{MXRAndroidUtils.GetAdminAppVersionName()} does not support DeviceData");
78+
else if (System.DeviceData == null)
7779
Debug.unityLogger.Log(LogType.Log, TAG, "Waiting for MXRManager.System.DeviceData to be initialized.");
7880

7981
if (System.DeviceStatus == null)
@@ -83,7 +85,9 @@ async public static Task<IMXRSystem> InitAsync(IMXRSystem system = null) {
8385
Debug.unityLogger.Log(LogType.Log, TAG, "Waiting for MXRManager.System.RuntimeSettingsSummary to be initialized.");
8486

8587
bool hadToWait = false;
86-
while (System.DeviceData == null || System.DeviceStatus == null || System.RuntimeSettingsSummary == null) {
88+
while ((MXRAndroidUtils.IsDeviceDataSupported && System.DeviceData == null)
89+
|| System.DeviceStatus == null
90+
|| System.RuntimeSettingsSummary == null) {
8791
hadToWait = true;
8892
await Task.Delay(100);
8993
}

0 commit comments

Comments
 (0)