MCPcopy Create free account
hub / github.com/BabylonJS/BabylonNative / CheckCameraPermissionAsync

Function CheckCameraPermissionAsync

Dependencies/xr/Source/ARCore/XR.cpp:276–316  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

274 }
275
276 arcana::task<void, std::exception_ptr> CheckCameraPermissionAsync()
277 {
278 auto task = arcana::task_from_result<std::exception_ptr>();
279
280 // Check if permissions are already granted.
281 if (!GetAppContext().checkSelfPermission(ManifestPermission::CAMERA()))
282 {
283 // Register for the permission callback request.
284 arcana::task_completion_source<void, std::exception_ptr> permissionTcs;
285 auto permissionTicket
286 {
287 AddRequestPermissionsResultCallback(
288 [permissionTcs](int32_t requestCode, const std::vector<std::string>& /*permissionList*/, const std::vector<int32_t>& results) mutable
289 {
290 // Check if this is our permission request ID.
291 if (requestCode == PERMISSION_REQUEST_ID)
292 {
293 // If the permission is found and granted complete the task.
294 if (results[0] == 0 /* PackageManager.PERMISSION_GRANTED */)
295 {
296 permissionTcs.complete();
297 return;
298 }
299
300 // Permission was denied. Complete the task with an error.
301 std::ostringstream message;
302 message << "Camera permission not acquired successfully";
303 permissionTcs.complete(arcana::make_unexpected(make_exception_ptr(std::runtime_error{message.str()})));
304 }
305 })
306 };
307
308 // Kick off the permission check request, and set the task for our caller to wait on.
309 GetCurrentActivity().requestPermissions(ManifestPermission::CAMERA(), PERMISSION_REQUEST_ID);
310 task = permissionTcs.as_task().then(arcana::inline_scheduler, arcana::cancellation::none(), [ticket = std::move(permissionTicket)](){
311 return;
312 });
313 }
314
315 return task;
316 }
317 }
318
319 struct System::Session::Impl

Callers 1

CreateAsyncMethod · 0.85

Calls 5

GetAppContextFunction · 0.85
GetCurrentActivityFunction · 0.85
checkSelfPermissionMethod · 0.80
requestPermissionsMethod · 0.80

Tested by

no test coverage detected