Skip to content

Commit

Permalink
Update the Godot lib dependency to 4.3.beta
Browse files Browse the repository at this point in the history
  • Loading branch information
m4gr3d committed Jun 24, 2024
1 parent 10cf401 commit 1e681e9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 77 deletions.
3 changes: 2 additions & 1 deletion config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ ext {
]

libraries = [
godotAndroidLib: "org.godotengine:godot:4.2.1.stable",
// TODO: Update to the 4.3 stable version when it's out.
godotAndroidLib: "org.godotengine:godot:4.3.0.beta-SNAPSHOT",
]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ class GodotOpenXRMeta(godot: Godot?) : GodotPlugin(godot) {
companion object {
private val TAG = GodotOpenXRMeta::class.java.simpleName

const val BODY_TRACKING_PERMISSION = "com.oculus.permission.BODY_TRACKING"
const val EYE_TRACKING_PERMISSION = "com.oculus.permission.EYE_TRACKING"
const val FACE_TRACKING_PERMISSION = "com.oculus.permission.FACE_TRACKING"
const val SCENE_PERMISSION = "com.oculus.permission.USE_SCENE"
private const val BODY_TRACKING_PERMISSION = "com.oculus.permission.BODY_TRACKING"
private const val EYE_TRACKING_PERMISSION = "com.oculus.permission.EYE_TRACKING"
private const val FACE_TRACKING_PERMISSION = "com.oculus.permission.FACE_TRACKING"
private const val SCENE_PERMISSION = "com.oculus.permission.USE_SCENE"

init {
try {
Expand All @@ -66,77 +66,6 @@ class GodotOpenXRMeta(godot: Godot?) : GodotPlugin(godot) {
}
}

/**
* Returns the information of the desired permission.
* @param context the caller context for this method.
* @param permission the name of the permission.
* @return permission info object
* @throws PackageManager.NameNotFoundException the exception is thrown when a given package, application, or component name cannot be found.
*
* TODO: remove this when Godot 4.3 is out with the new `PermissionsUtil.requestPermissions(...)` api
*/
@Throws(PackageManager.NameNotFoundException::class)
private fun getPermissionInfo(context: Context, permission: String): PermissionInfo {
val packageManager = context.packageManager
return packageManager.getPermissionInfo(permission, 0)
}

/**
* Request a list of dangerous permissions. The requested permissions must be included in the app's AndroidManifest
* @param permissions list of the permissions to request.
* @param activity the caller activity for this method.
* @return true/false. "true" if permissions are already granted, "false" if a permissions request was dispatched.
*
* TODO: remove this when Godot 4.3 is out with the new `PermissionsUtil.requestPermissions(...)` api
*/
private fun requestPermissions(activity: Activity?, permissions: List<String>): Boolean {
if (activity == null) {
return false
}
if (permissions.isEmpty()) {
return true
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
// Not necessary, asked on install already
return true
}

val requestedPermissions: MutableSet<String> = HashSet()
for (permission in permissions) {
try {
if (permission == Manifest.permission.MANAGE_EXTERNAL_STORAGE) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && !Environment.isExternalStorageManager()) {
Log.d(TAG, "Requesting permission $permission")
try {
val intent = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
intent.setData(Uri.parse(String.format("package:%s", activity.packageName)))
activity.startActivityForResult(intent, PermissionsUtil.REQUEST_MANAGE_EXTERNAL_STORAGE_REQ_CODE)
} catch (ignored: Exception) {
val intent = Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION)
activity.startActivityForResult(intent, PermissionsUtil.REQUEST_MANAGE_EXTERNAL_STORAGE_REQ_CODE)
}
}
} else {
val permissionInfo = getPermissionInfo(activity, permission)
val protectionLevel = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) permissionInfo.protection else permissionInfo.protectionLevel
if (protectionLevel == PermissionInfo.PROTECTION_DANGEROUS && activity.checkSelfPermission(permission) !== PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "Requesting permission $permission")
requestedPermissions.add(permission)
}
}
} catch (e: PackageManager.NameNotFoundException) {
// Skip this permission and continue.
Log.w(TAG, "Unable to identify permission $permission", e)
}
}
if (requestedPermissions.isEmpty()) {
// If list is empty, all of dangerous permissions were granted.
return true
}
activity.requestPermissions(requestedPermissions.toTypedArray<String>(), PermissionsUtil.REQUEST_ALL_PERMISSION_REQ_CODE)
return true
}

/**
* Dispatch the necessary requests for all plugin's permissions in the app's manifest.
*/
Expand All @@ -161,7 +90,7 @@ class GodotOpenXRMeta(godot: Godot?) : GodotPlugin(godot) {
}

if (permissionsToRequest.isNotEmpty()) {
requestPermissions(activity, permissionsToRequest)
PermissionsUtil.requestPermissions(activity, permissionsToRequest)
}
}
}
Expand Down

0 comments on commit 1e681e9

Please sign in to comment.