Ocean
Permission.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_PLATFORM_ANDROID_PERMISSION_H
9 #define META_OCEAN_PLATFORM_ANDROID_PERMISSION_H
10 
12 
13 namespace Ocean
14 {
15 
16 namespace Platform
17 {
18 
19 namespace Android
20 {
21 
22 /**
23  * This class implements functions for Android application permissions.
24  * @ingroup platformandroid
25  */
26 class OCEAN_PLATFORM_ANDROID_EXPORT Permission
27 {
28  public:
29 
30  /**
31  * Returns whether the Android app has a specific permission.
32  * @param javaVM The Java virtual machine, must be valid
33  * @param activity The Android main activity, must be valid
34  * @param permission The permission to be checked, must be valid
35  * @param translate If true, translates short permission name to Android-internal full permission name, note: must be `false` for Oculus permissions, e.g., `com.oculus.permission.USE_SCENE`
36  * @param state True, if the app has the specified permission; False, if the app does not have the specified permission
37  * @return True, if succeeded
38  */
39  static bool hasPermission(JavaVM* javaVM, jobject activity, const std::string& permission, bool& state, const bool translate = true);
40 
41  /**
42  * Requests several permissions for the Android app.
43  * @param javaVM The Java virtual machine, must be valid
44  * @param activity The Android main activity, must be valid
45  * @param permissions The permissions to be requested, at least one
46  * @param translate If true, translates short permission name to Android-internal full permission name, note: must be `false` for Oculus permissions, e.g., `com.oculus.permission.USE_SCENE`
47  * @return True, if the request was invoked successfully, does not check whether the permission was granted
48  */
49  static bool requestPermissions(JavaVM* javaVM, jobject activity, const std::vector<std::string>& permissions, const bool translate = true);
50 
51  /**
52  * Determines Android's internal permission name for a readable permission.
53  * @param jniEnv The Java environment, attached with the current thread, must be valid
54  * @param permission The readable permission
55  * @return Android's internal permission
56  */
57  static std::string translatePermission(JNIEnv* jniEnv, const std::string& permission);
58 };
59 
60 }
61 
62 }
63 
64 }
65 
66 #endif // META_OCEAN_PLATFORM_ANDROID_PERMISSION_H
This class implements functions for Android application permissions.
Definition: Permission.h:27
static std::string translatePermission(JNIEnv *jniEnv, const std::string &permission)
Determines Android's internal permission name for a readable permission.
static bool hasPermission(JavaVM *javaVM, jobject activity, const std::string &permission, bool &state, const bool translate=true)
Returns whether the Android app has a specific permission.
static bool requestPermissions(JavaVM *javaVM, jobject activity, const std::vector< std::string > &permissions, const bool translate=true)
Requests several permissions for the Android app.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15