Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move request for microphone permission to onCreate #25

Merged
merged 1 commit into from
Jan 25, 2024

Conversation

gyroninja
Copy link
Contributor

@gyroninja gyroninja commented Jan 24, 2024

This request can cause issues if the user denies the microphone permission.
Calling requestPermissions causes GrantPermissionsActivity to be launched.
Citra's MainActivity will pause. GrantPermissionsActivity will immediately
finish as the user has already denied the permission. Citra's MainActivity then
gets resumed and then tries to request the permission again forming a loop.

@gyroninja
Copy link
Contributor Author

Citra already handles falling back to no mic if the permission is not granted.

if (!Core::System::GetInstance().HasMicPermission()) {

@gyroninja
Copy link
Contributor Author

This change does delay the initial microphone permission request to when a game is launched.

@gyroninja
Copy link
Contributor Author

gyroninja commented Jan 24, 2024

This code was added in the Added VR megacommit so it isn't clear if this workaround some other issue.

I double checked that we have the microphone permission when it is determining which input device to use, so I am not sure the purpose of this.

@amwatson
Copy link
Owner

Ah! I forgot about this. That's because the runtime permissions dialog can launch in either the 2D window or as its own immersive window on top of XR depending on the current scene, and checking on game launch (2D -> immersive) can cause it to appear in the wrong container.

The check should probably be in onCreate of MainActivity instead of onResume(), unless there was a specific reason I avoided that.

Regarding your comment about the loop: in theory, the permissions dialog should cause MainActivity to lose focus, but not pause. Is that not the case?

@gyroninja
Copy link
Contributor Author

gyroninja commented Jan 24, 2024

Do you mean that originally the permission request would sometimes be shown on the 2d app and sometimes on the 3d app? I didn't heavily stress test this scenario myself, but that seems plausible.

in theory, the permissions dialog should cause MainActivity to lose focus, but not pause. Is that not the case?

It is not the case.

This method may start an activity allowing the user to choose which permissions to grant and which to reject. Hence, you should be prepared that your activity may be paused and resumed. Further, granting some permissions may require a restart of you application. In such a case, the system will recreate the activity stack before delivering the result to your onRequestPermissionsResult.

https://developer.android.com/reference/androidx/core/app/ActivityCompat#requestPermissions(android.app.Activity,%20java.lang.String[],%20int)

@amwatson
Copy link
Owner

amwatson commented Jan 25, 2024

Do you mean that originally the permission request would sometimes be shown on the 2d app and sometimes on the 3d app?

More specifically: when requested while the immersive activity is launching, it will try (and fail) to show the correct permissions dialog over the activity.

@amwatson
Copy link
Owner

amwatson commented Jan 25, 2024

@gyroninja note: in the original project, audio was being requested here.

Now I remember: the reason I moved the permission request originally is because the native code requests the mic permission on the launch of the application -- which triggers the issue I mentioned. Moving it to the launch of MainActivity makes this a non-issue.

You should be able to request the permission in onCreate() instead of onResume() if you want. I think that should resolve both issues.

This request can cause issues if the user denies the microphone permission.
Calling requestPermissions causes GrantPermissionsActivity to be launched.
Citra's MainActivity will pause. GrantPermissionsActivity will immediately
finish as the user has already denied the permission. Citra's MainActivity then
gets resumed and then tries to request the permission again forming a loop.
@gyroninja gyroninja changed the title Remove microphone permission nag Move request for microphone permission to onCreate Jan 25, 2024
@gyroninja
Copy link
Contributor Author

Moving it to onCreate worked fine.

@amwatson amwatson merged commit 92d698a into amwatson:master Jan 25, 2024
@gyroninja gyroninja deleted the remove-mic-nag branch January 25, 2024 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants