Skip to content

Commit

Permalink
Merge pull request godotengine#87080 from m4gr3d/disable_automatic_pe…
Browse files Browse the repository at this point in the history
…rmissions_request

Disable automatic permissions request
  • Loading branch information
akien-mga committed Jan 11, 2024
2 parents 99f3e40 + df4f9e8 commit 12ee58d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ open class GodotEditor : GodotActivity() {
private val commandLineParams = ArrayList<String>()

override fun onCreate(savedInstanceState: Bundle?) {
// We exclude certain permissions from the set we request at startup, as they'll be
// requested on demand based on use-cases.
PermissionsUtil.requestManifestPermissions(this, setOf(Manifest.permission.RECORD_AUDIO))

val params = intent.getStringArrayExtra(EXTRA_COMMAND_LINE_PARAMS)
Log.d(TAG, "Received parameters ${params.contentToString()}")
updateCommandLineParams(params)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

package org.godotengine.godot

import android.Manifest
import android.app.Activity
import android.content.Intent
import android.content.pm.PackageManager
Expand Down Expand Up @@ -65,10 +64,6 @@ abstract class GodotActivity : FragmentActivity(), GodotHost {
private set

override fun onCreate(savedInstanceState: Bundle?) {
// We exclude certain permissions from the set we request at startup, as they'll be
// requested on demand based on use-cases.
PermissionsUtil.requestManifestPermissions(this, setOf(Manifest.permission.RECORD_AUDIO))

super.onCreate(savedInstanceState)
setContentView(R.layout.godot_app_layout)

Expand Down Expand Up @@ -156,7 +151,8 @@ abstract class GodotActivity : FragmentActivity(), GodotHost {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
godotFragment?.onRequestPermissionsResult(requestCode, permissions, grantResults)

if (requestCode == PermissionsUtil.REQUEST_ALL_PERMISSION_REQ_CODE) {
// Logging the result of permission requests
if (requestCode == PermissionsUtil.REQUEST_ALL_PERMISSION_REQ_CODE || requestCode == PermissionsUtil.REQUEST_SINGLE_PERMISSION_REQ_CODE) {
Log.d(TAG, "Received permissions request result..")
for (i in permissions.indices) {
val permissionGranted = grantResults[i] == PackageManager.PERMISSION_GRANTED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
public final class PermissionsUtil {
private static final String TAG = PermissionsUtil.class.getSimpleName();

static final int REQUEST_RECORD_AUDIO_PERMISSION = 1;
static final int REQUEST_CAMERA_PERMISSION = 2;
static final int REQUEST_VIBRATE_PERMISSION = 3;
public static final int REQUEST_RECORD_AUDIO_PERMISSION = 1;
public static final int REQUEST_CAMERA_PERMISSION = 2;
public static final int REQUEST_VIBRATE_PERMISSION = 3;
public static final int REQUEST_ALL_PERMISSION_REQ_CODE = 1001;
public static final int REQUEST_SINGLE_PERMISSION_REQ_CODE = 1002;
public static final int REQUEST_MANAGE_EXTERNAL_STORAGE_REQ_CODE = 2002;
Expand All @@ -70,7 +70,7 @@ private PermissionsUtil() {
* Request a dangerous permission. name must be specified in <a href="https://github.com/aosp-mirror/platform_frameworks_base/blob/master/core/res/AndroidManifest.xml">this</a>
* @param permissionName the name of the requested permission.
* @param activity the caller activity for this method.
* @return true/false. "true" if permission was granted otherwise returns "false".
* @return true/false. "true" if permission is already granted, "false" if a permission request was dispatched.
*/
public static boolean requestPermission(String permissionName, Activity activity) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
Expand Down Expand Up @@ -124,7 +124,7 @@ public static boolean requestPermission(String permissionName, Activity activity
/**
* Request dangerous permissions which are defined in the Android manifest file from the user.
* @param activity the caller activity for this method.
* @return true/false. "true" if all permissions were granted otherwise returns "false".
* @return true/false. "true" if all permissions were already granted, returns "false" if permissions requests were dispatched.
*/
public static boolean requestManifestPermissions(Activity activity) {
return requestManifestPermissions(activity, null);
Expand All @@ -134,7 +134,7 @@ public static boolean requestManifestPermissions(Activity activity) {
* Request dangerous permissions which are defined in the Android manifest file from the user.
* @param activity the caller activity for this method.
* @param excludes Set of permissions to exclude from the request
* @return true/false. "true" if all permissions were granted otherwise returns "false".
* @return true/false. "true" if all permissions were already granted, returns "false" if permissions requests were dispatched.
*/
public static boolean requestManifestPermissions(Activity activity, @Nullable Set<String> excludes) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
Expand Down Expand Up @@ -235,7 +235,7 @@ public static String[] getGrantedPermissions(Context context) {
/**
* Check if the given permission is in the AndroidManifest.xml file.
* @param context the caller context for this method.
* @param permission the permession to look for in the manifest file.
* @param permission the permission to look for in the manifest file.
* @return "true" if the permission is in the manifest file of the activity, "false" otherwise.
*/
public static boolean hasManifestPermission(Context context, String permission) {
Expand Down

0 comments on commit 12ee58d

Please sign in to comment.