ManageXR / mxr-unity-sdk

8 stars 0 forks source link

Calling Init on non-mdm controlled headset throws DirectoryNotFoundException #39

Closed tenebris93 closed 1 year ago

tenebris93 commented 1 year ago

Device Info:

Notes: I just updated the local version of MXR SDK to version 1.0.4. Now all of a sudden when we install our app onto a non-mdm controlled headset we are getting a DirectoryNotFoundException error that is triggering one of the services we use for error tracking. Is there a way to determine if the MDM app is installed?

[MXRAndroidSystem]: System.IO.DirectoryNotFoundException: Could not find a part of the path "/storage/emulated/0/MightyImmersion/runtimeSettingsSummary.json".
  at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x00000] in <00000000000000000000000000000000>:0 
  at System.IO.StreamReader..ctor (System.String path, System.Text.Encoding encoding, System.Boolean detectEncodingFromByteOrderMarks, System.Int32 bufferSize, System.Boolean checkHost) [0x00000] in <00000000000000000000000000000000>:0 
  at System.IO.File.ReadAllText (System.String path) [0x00000] in <00000000000000000000000000000000>:0 
  at MXR.SDK.MXRAndroidSystem.DeserializeFromFile[T] (System.String subPath, System.String& contents, T& value) [0x00000] in <00000000000000000000000000000000>:0 
  at MXR.SDK.MXRAndroidSystem.InitializeRuntimeSettingsSummary () [0x00000] in <00000000000000000000000000000000>:0 
  at MXR.SDK.MXRAndroidSystem..ctor () [0x00000] in <00000000000000000000000000000000>:0 
  at MXR.SDK.MXRManager.Init (MXR.SDK.IMXRSystem system) [0x00000] in <00000000000000000000000000000000>:0 
  at Immertec.Medoptic.Utilities.Tools.GetSerialNumber () [0x00000] in <00000000000000000000000000000000>:0 
  at Immertec.Medoptic.FiniteStateMachines.MainBaseMenuState.EnterState[T] (T fsm) [0x00000] in <00000000000000000000000000000000>:0 
adrenak commented 1 year ago

Hi @tenebris93 this is because the SDK now uses the local json files for initializing the state such as DeviceStatus and RuntimeSettingsSummary as it's faster during bootup. The SDK doesn't offer anything in its API that tells you if the headset has MDM enabled. We'll add that soon.

In the meantime if you want to know if the headset is MDM controlled, you could do so by checking if com.mightyimmersion.mightyplatform.adminapp.prod is installed using the Android Package Manager API. That's the package name for the admin app on Oculus headsets.

adrenak commented 1 year ago

@tenebris93 we have an API for this now inside MXRAndroidSystem

You can use new MXRAndroidSystem().IsAdminAppInstalled when running on Android headsets.

Note that constructing MXRAndroidSystem will fail in the editor as required native android objects cannot be constructed, so use Application.platform == RuntimePlatform.Android or #if !UNITY_EDITOR to avoid console errors while developing.