[We're working with Unity Ed. 2022.2.19f1, Win10, MLSDK v1.4.0-dev2 ML Unity v1.11.0.]
We've built an AAR and call it from a Unity method, in which we set up callbacks to request ML2 write permissions:
MLPermissions.RequestPermission(MLPermission.WriteExternalStorage, permissionCallbacks);
At runtime, this permission callback gives permissions as we'd expect, but the app fails to write to storage. Because the AAR is out of Unity's scope, we see no log messages.
Note that our Unity ‘AndroidManifest.xml’ in /Plugins/Android sets both Android and ML permissions as follows. As Unity's manifest overrides others this should be sufficient to allow the AAR methods to write to disk. Is this correct? The permissions block follows:
> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
> <uses-permission android:name="android.permission.CAMERA" />
> <uses-permission android:name="com.magicleap.permission.WRITE_EXTERNAL_STORAGE" />
> <uses-permission android:name="com.magicleap.permission.CAMERA" />
> <uses-permission android:name="com.magicleap.permission.EYE_TRACKING" />
> <uses-permission android:name="com.magicleap.permission.SPATIAL_MAPPING" />
> <uses-permission android:name="com.magicleap.permission.HAND_TRACKING" />
The ‘AndroidManifest.xml’ for the Java code also requests permissions in this way:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
When calling Java methods on their own, the above grants write permission effectively, but when packaged in a library as an AAR our Java methods can’t write to disk.
In Android, permissions are associated with the APK, not with individual pieces of code or libraries. For a Java Android app that calls native C++ code through JNI (Java Native Interface), the permissions are determined by the AndroidManifest.xml file of the Java Android app. The native code runs in the same process and under the same security context as the Java code, so the permissions for the native code are the same as those granted to the Java app.
As above, I believe Unity handles things in the same way -- the manifest for the C# code calling our AAR should determine our permissions.
Why then can't we write to the ML2 from our AAR methods?