GoogleVR's PermissionsDemo - permissions always denied

Hello there,

Has anyone managed to get a permission granted through Google VR’s gvr-permissions-support library?

A demo that is shipped with Google VR plugin that shows how the gvr-permissions-support library can be used to offer the ability to grant runtime permissions. While I was able to run the demo, I was not fortunate enough to be granted a permission.

Specifically, when I click the “Request Permission” button on the demo scene, I get the following exception:

04-22 15:02:53.476 3034-3034/? E/ActivityThread: Activity com.google.gvr.permissionsupport.TransitionVRActivity has leaked ServiceConnection com.google.vr.ndk.base.DaydreamApi$1@3ed206d that was originally bound here
                                                 android.app.ServiceConnectionLeaked: Activity com.google.gvr.permissionsupport.TransitionVRActivity has leaked ServiceConnection com.google.vr.ndk.base.DaydreamApi$1@3ed206d that was originally bound here
                                                     at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:1336)
                                                     at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:1231)
                                                     at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1450)
                                                     at android.app.ContextImpl.bindService(ContextImpl.java:1422)
                                                     at android.content.ContextWrapper.bindService(ContextWrapper.java:636)
                                                     at com.google.vr.ndk.base.DaydreamApi.init(DaydreamApi.java:838)
                                                     at com.google.vr.ndk.base.DaydreamApi.create(DaydreamApi.java:141)
                                                     at com.google.gvr.permissionsupport.TransitionVRActivity.onCreate(TransitionVRActivity.java:74)
                                                     at android.app.Activity.performCreate(Activity.java:6682)
                                                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2619)
                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727)
                                                     at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478)
                                                     at android.os.Handler.dispatchMessage(Handler.java:102)
                                                     at android.os.Looper.loop(Looper.java:154)
                                                     at android.app.ActivityThread.main(ActivityThread.java:6121)
                                                     at java.lang.reflect.Method.invoke(Native Method)
                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)

@majedzayer, I managed to get permissions to work for my application. I’m not sure what’s wrong in the demo, but what was happening with me is I didn’t have an XML file named AndroidManifest.xml directly in my Assets/Plugins/Android folder. The only files that were there as a part of the Unity GVR SDK were two manifests named AndroidManifest - Cardboard.xml and AndroidManifest - Daydream.xml. Neither of these files get recognized when Unity goes to compile a manifest because it explicitly looks for a file with the name AndroidManifest.xml. Any manifests that are in subfolders of the above directory do not get merged if there isn’t a manifest in Assets/Plugins/Android.

So, my solution was to copy the AndroidManifest - Daydream.xml, change the file’s name to remove the -Daydream part, change the package tag from the default one to the tag of my project, and add the permissions I needed. After doing that, the script I had made based off of the PermissionsFlowManager.cs that is a part of that demo worked, and it asked me for the permissions I requested. Below is what my manifest actually looks like. I hope this helps!

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          android:versionCode="1"
          android:versionName="1.0"
          package="com.MacGyver.DaydreamSMS"
          android:installLocation="preferExternal">

  <uses-permission android:name="android.permission.READ_SMS" />
  <uses-permission android:name="android.permission.READ_CONTACTS" />

  <supports-screens
          android:anyDensity="true"
          android:largeScreens="true"
          android:normalScreens="true"
          android:smallScreens="true"
          android:xlargeScreens="true" />

  <application
          android:icon="@drawable/app_icon"
          android:label="@string/app_name"
          android:debuggable="false"
          android:isGame="true"
          android:banner="@drawable/app_banner"
          android:theme="@style/VrActivityTheme">

    <activity
            android:label="@string/app_name"
            android:name="com.unity3d.player.UnityPlayerActivity"
            android:screenOrientation="landscape"
            android:launchMode="singleTask"
            android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale"
            android:enableVrMode="@string/gvr_vr_mode_component"
            android:resizeableActivity="false">

      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>

      <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    </activity>
  </application>
</manifest>

@majedzayer, I’ve noticed the same lack of functionality in the PermissionsDemo scene. I tried two things, neither of which have worked:

  1. I tried implementing the RequestPermissions() method from the PermissionsFlowManager.cs script in the demo in my own app to no success. I didn’t get an error, but I got what I’ve seen other people get which is a black fragment screen that displays a button saying “return to vr”. In my understanding, switching to that fragment should prompt the Android OS to ask the user for the permissions it finds in the AndroidManifest.xml, because of the internal calls that it is making.
  2. The next thing is I tried adding a permissionsHandler method that I had inside of the plugin I’m trying to make work in my VR scene. I thought that if I called the permissions handler of my “native” android app while I was waiting on that fragment, it might kick those permissions off. Again, no luck.

Please, let me know if you did find a solution to this problem, and I will let you know if I find anything else too.

public void RequestPermissions()
    {
        var plugin = new AndroidJavaClass("com.example.lfswe.smsfetch.MainActivity");
        GvrPermissionsRequester permissionRequester = GvrPermissionsRequester.Instance;
        if (permissionRequester == null)
        {
            return;
        }
        if (!permissionRequester.IsPermissionGranted(permissionNames[0]) || !permissionRequester.IsPermissionGranted(permissionNames[1]))
        {
            permissionRequester.RequestPermissions(permissionNames,
                (GvrPermissionsRequester.PermissionStatus[] permissionResults) =>
                {
                    permissionList.Clear();
                    permissionList.AddRange(permissionResults);
                });
            plugin.Call("handlePermissions", permissionNames, 24);
        }
    }

unity add this in manifest in temporary file

Temp StagingArea AndroidManifest.xml

meta-data android:name=“unityplayer.SkipPermissionsDialog” android:value=“true”

this block the permission
i wait to fix developers because override not working for my