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

fix(GH-706): (android) Allow permissions requests #968

Merged
merged 1 commit into from
Oct 27, 2023

Conversation

joanbat
Copy link
Contributor

@joanbat joanbat commented Jul 25, 2022

Platforms affected

Android

Motivation and Context

Android in-app-browser does not allow in-browser camera/webcamera usage (permission denied)
With this change, camera usage will be allowed as long as the app has permissions.
Issue GH-706: #706

Description

Allows permissions requests from ChromeWebView

Testing

IAB would show permissions denied error in website https://webcam-test.com/
After the changes it successfuly works (requires app's camera permission to be enabled)

Checklist

  • I've run the tests to see all new and existing tests pass
  • I added automated test coverage as appropriate for this change
  • Commit is prefixed with (platform) if this change only applies to one platform (e.g. (android))
  • If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct keyword to close issues using keywords)
  • I've updated the documentation if necessary

Copy link

@asfackahamed asfackahamed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your solution is working fine for microphone access 👍

Copy link

@rushabhmshah99 rushabhmshah99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spent numerous hours trying to find a solution for this. I can confirm the above change makes it work! Would vote to get it merged asap

@ittlsa
Copy link

ittlsa commented Oct 26, 2022

plase confirm this fix.

@breautek
Copy link
Contributor

Does this change assumes that you have the proper permissions declared in the AndroidManifest.xml? Usually you cannot request permissions unless if the app declares that it uses the permission in the manifest.

@joanbat
Copy link
Contributor Author

joanbat commented Oct 26, 2022

Yes, the permissions must be declared in AndroidManifest.xml, additionally, permissions must be granted as with this change there is no OS permission popup if permissions have not been allowed.

@breautek
Copy link
Contributor

additionally, permissions must be granted as with this change there is no OS permission popup if permissions have not been allowed.

Ok, so to be clear we have the following use cases:

Declared In Manifest means the <uses-permission> entry for the permission in question was present in AndroidManifest.
Permission Granted Previously means that the permission was granted by some means outside of the WebView. Either via another action that triggered the OS permission prompt, or the user used the OS App Permission settings to enable permission manually.
Permission OK'ed in IAB means that the permission was granted and the in-app-browser webview was able to utilise the feature.

Case 1

Declared In Manifest Permission Granted Previously Permission OK'ed in IAB
✔️ ✔️ ✔️

Because the AndroidManifest contains the permission declaration, and the user has somehow previously granted permission (which has yet to be revoked), the IAB was able to receive the permission and utilise the related features.

Case 2

Declared In Manifest Permission Granted Previously Permission OK'ed in IAB

Because the AndroidManifest does not contain the permission declaration, the user would have never been able to have the permission granted previously, and naturally neither would the IAB browser.

Case 3

Declared In Manifest Permission Granted Previously Permission OK'ed in IAB
✔️

The AndroidManifest does contain the permission declaration, but the user has yet to trigger a OS permission prompt somehow and does not have the permission currently granted. IAB is unable to trigger a permission prompt, so it will also fail to receive the grant.

Do these case results correctly represent the behaviour as the PR stands now?

@joanbat
Copy link
Contributor Author

joanbat commented Oct 26, 2022

Exactly.

@breautek
Copy link
Contributor

breautek commented Oct 26, 2022

Awseome.. ok

Personally I feel like this doesn't go far enough to allow permission requests, but I understand it is still an improvement over what the plugin is doing now. Since this can be further improved later, I've written a snippet that I think we could probably include at the end of the README file that provides some notes regarding permissions.

### Permissions

Some webview features may require additional permissions. The in-app browser does not have the ability to grant additional permissions. However, on Android if the permissions have already been granted, the related featureset will become available. On iOS, permission-locked features may still be unavailable regardless of permission grants.

Also, I'm not certain if the iOS claim is accurate. I know this PR doesn't touch iOS, but we should double check iOS behaviour if possible. Unfortunately I'm not in the position to check this myself as I do not have access to a Mac. If we are unable to check the behaviour, then it might be better to scratch the On iOS, permission-locked features may still be unavailable regardless of permission grants. line. You can include the snippet if you like. Don't hesitate to rephrase or make edits if you feel like it's necessary. I'm definitely not convinced that my own wording is the best.

Outside of that, I think the PR is good but I'll request further input from a couple of other members who have worked more closely with the IAB than I have.

Note, I added the close keyword to close #706 but it seems the issue applies to both Android & iOS, so I reverted my edit as this PR only addresses the Android platform.

@breautek breautek changed the title GH-706 android: Allow permissions requests fix(GH-706): (android) Allow permissions requests Oct 26, 2022
@joanbat
Copy link
Contributor Author

joanbat commented Oct 26, 2022

Also, I'm not certain if the iOS claim is accurate. I know this PR doesn't touch iOS, but we should double check iOS behaviour if possible. Unfortunately I'm not in the position to check this myself as I do not have access to a Mac.

I only tested video, but during my tests I could use webcam and mic access on devices with iOS version 14.3 or higher - That's then WebRTC was introduced in WKWebKit, which is what IAB on iOS uses, as far as I am aware.

With the issue being reported prior to iOS 14.3 release (dec 14th 2020), and that I was able to use permission sensitive features from iOS's IAB during my tests, I would highly suspect it was entirely due to not supporting WebRTC on iOS, rather than having permissions passthrough issues.

@breautek
Copy link
Contributor

Also, I'm not certain if the iOS claim is accurate. I know this PR doesn't touch iOS, but we should double check iOS behaviour if possible. Unfortunately I'm not in the position to check this myself as I do not have access to a Mac.

I only tested video, but during my tests I could use webcam and mic access on devices with iOS version 14.3 or higher - That's then WebRTC was introduced in WKWebKit, which is what IAB on iOS uses, as far as I am aware.

With the issue being reported prior to iOS 14.3 release (dec 14th 2020), and that I was able to use permission sensitive features from iOS's IAB during my tests, I would highly suspect it was entirely due to not supporting WebRTC on iOS, rather than having permissions passthrough issues.

Ok, so we can probably scratch the iOS claim in my snippet.

### Permissions

Some webview features may require additional permissions. The in-app browser does not have the ability to grant additional permissions. However, on Android if the permissions have already been granted, the related features will become available.

@NiklasMerz
Copy link
Member

After setting the permissions I got the camera working on Android with this PR. I think it should be good to go with the small note in README.

I tested it on iOS, too and at least for my only real iOS device (iPad with iOS 16.1 beta) the camera does not work in the IAB.

@Parag-Tharani
Copy link

@NiklasMerz could you please approve above PR

@kulkarni005
Copy link

Please Merge this to master

@Meng991003
Copy link

I have tried with the above solution, adding the permission in AndroidManifest.xml and granted the access. But I still not be able to open the camera when using IAB. The website is using the input tag <input type="file" id="myFile" name="filename" accept="image/*> to get the input.

@jooles
Copy link

jooles commented Jun 27, 2023

Any news on this? We need camera access for file type=input :)
Thanks for reviewing, too, @NiklasMerz !

@RemcovandenBerg
Copy link

RemcovandenBerg commented Sep 19, 2023

@NiklasMerz any reason the review and merge is being delayed? People are waiting on this. thx! @breautek Niklas seems inactive lately. Any change you could review or add someone (like me for example) to merge this?

@StefaniToto
Copy link

The fix is working. Thank you

@NiklasMerz
Copy link
Member

@breautek If you think this fine feel free to merge. I could create a new release if we think it's a good time to do that.

@breautek breautek merged commit d735e13 into apache:master Oct 27, 2023
pesi-hgc pushed a commit to pesi-hgc/cordova-plugin-inappbrowser-transparent that referenced this pull request Nov 3, 2023
Co-authored-by: joanb-moncasoft <55381916+joanb-moncasoft@users.noreply.github.com>
@alexandrampolta
Copy link

Solution worked for me , for camera access
Step 1 :
cordova plugin add cordova-plugin-android-permissions

With in your index.js

var permissions = cordova.plugins.permissions;
permissions.requestPermission(permissions.CAMERA, success, error);
function error() {
console.warn('Camera permission is not turned on');
}
function success( status ) {
console.log(status);
}

Step 2 :
cordova plugin remove cordova-plugin-inappbrowser

step 3 :
cordova plugin add https://github.com/apache/cordova-plugin-inappbrowser.git (it's same library but looks like it's updated)

step 4:
cordova build android --packageType=apk
Build your app normally

@vasanthnataraj
Copy link

vasanthnataraj commented Sep 8, 2024

@alexandrampolta camera access works but microphone access is still not working in inappbrowser. Did you try it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.