Develop
Develop
Select your platform

Spatial Data Permission

Overview

We have introduced a new spatial data runtime permission that allows users to control which app can access their spatial data. The permission applies to apps running on Quest 2, Quest Pro, and Quest 3. See Requesting runtime permissions for more information.
An app that wants to use Scene API needs to request spatial data permission during the app’s runtime. The request will display a one-time permission explainer dialog, followed by a permission consent confirmation dialog. Only when the permission is granted by the users can the apps query all spatial data on the user’s device.
An illustration of the permission flow UX.

Devices

Accessing spatial data through the new permission flow is effective on Quest 2, Quest Pro, and Quest 3.
There is no need to request scene runtime permission when developing apps via Link. Apps running from Link will continue accessing spatial data when querying for anchors on the device.

Declare the permission

In your app’s AndroidManifest.xml, declare the following permission:
<uses-permission android:name="com.oculus.permission.USE_SCENE" />

When to request permission

As per the Android permission guidelines, it is recommended to request the permission only when using the functionality, and to provide a fallback if the user decides not to grant the permission.
If the app is compiled with the current versions of the SDK, there is no requirement to request the permission in the app. The system will automatically show a permission dialog when the app is launched.

How to request permission

Request the permission in Java in a NativeActivity:
package com.oculus.test.permissionTestApp;

import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends android.app.NativeActivity {
  private static final String PERMISSION_USE_SCENE = "com.oculus.permission.USE_SCENE";
  private static final int REQUEST_CODE_PERMISSION_USE_SCENE = 1;

static {
  System.loadLibrary("openxr_loader");
  System.loadLibrary("permissionTestApp");
}


@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  requestScenePermissionIfNeeded();
}

private void requestScenePermissionIfNeeded() {
if (checkSelfPermission(PERMISSION_USE_SCENE) !=      PackageManager.PERMISSION_GRANTED) {
  requestPermissions(new String[] {PERMISSION_USE_SCENE}, REQUEST_CODE_PERMISSION_USE_SCENE);
}
}
}
Request the permission in C++ via JNI:
static bool checkAndMaybeRequestPermission(JNIEnv* env, jobject activityObject) {
  jstring strPermission = env->NewStringUTF("com.oculus.permission.USE_SCENE");
  jobject objPermission = env->NewLocalRef(strPermission);

  // Check if we already have the permission
  jclass clsActivity = env->FindClass("android/app/Activity");

  jmethodID methodCheckSelfPermission = env->GetMethodID(clsActivity, "checkSelfPermission", "(Ljava/lang/String;)I");

  jint intPermissionResult = env->CallIntMethod(activityObject, methodCheckSelfPermission, objPermission);

  jclass clsPackageManager = env->FindClass("android/content/pm/PackageManager");

  jfieldID fidPermissionGranted = env->GetStaticFieldID(clsPackageManager, "PERMISSION_GRANTED", "I");

  jint intPermissionGranted = env->GetStaticIntField(clsPackageManager, fidPermissionGranted);
  if (intPermissionResult == intPermissionGranted) {
    return true;
  }

  // Request the permission
  jmethodID methodRequestPermissions = env->GetMethodID(clsActivity, "requestPermissions", "([Ljava/lang/String;I)V");

  jclass clsString = env->FindClass("java/lang/String");
  jobjectArray objArrayPermissionStrings = env->NewObjectArray(1, clsString, objPermission);

  jint requestCode = 0;
  env->CallVoidMethod(activityObject, methodRequestPermissions, objArrayPermissionStrings, requestCode);
  return true;
}
If users do not grant spatial data permission, the function XrQuerySpacesFB will not return XrSpace. This behavior will occur regardless of what filter is applied. Specifically, XrQuerySpacesFB will not return a XrSpace that contains the following XrSpaceComponentTypeFB. This will be true even if a scene has been captured on the user’s device:
  • XR_SPACE_COMPONENT_TYPE_BOUNDED_2D_FB
  • XR_SPACE_COMPONENT_TYPE_BOUNDED_3D_FB
  • XR_SPACE_COMPONENT_TYPE_SEMANTIC_LABELS_FB
  • XR_SPACE_COMPONENT_TYPE_ROOM_LAYOUT_FB
  • XR_SPACE_COMPONENT_TYPE_SPACE_CONTAINER_FB
  • XR_SPACE_COMPONENT_TYPE_TRIANGLE_MESH_METAX1
Did you find this page helpful?