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

Improved external storage permission handling #157 #163

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Anshu-Bijarnia
Copy link

This pull request provides a good solution for the external storage handling based on different android versions. Closing -> Improve external storage handling for external intent Image Capture #157

Copy link

google-cla bot commented Mar 29, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@temcguir temcguir requested a review from davidjiagoogle April 1, 2024 17:30
@Anshu-Bijarnia
Copy link
Author

@davidjiagoogle can you guide me regarding what i should do to make these tests pass ?

@@ -25,10 +24,17 @@
android:required="false" />

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi Anshu, you removed writing permission and replaced it with reading permissions. Won't this cause a problem with image capturing and recording where we save an image or video file onto disk?

Copy link
Collaborator

Choose a reason for hiding this comment

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

More on this: Image capture is tested in ImageCaptureDeviceTest, where the WRITE_EXTERNAL_STORAGE permission is specified again in the test. I believe if you change AppTestUtil.APP_REQUIRED_PERMISSIONS to reflect your changes here, the test will fail, as the app wouldn't be able to save onto storage without WRITE permission

@davidjiagoogle
Copy link
Collaborator

@Anshu-Bijarnia Have you tried running the tests locally with a connected device or emulator?

@Anshu-Bijarnia
Copy link
Author

@Anshu-Bijarnia Have you tried running the tests locally with a connected device or emulator?

I will try fixing the errors and test the application locally.

@Anshu-Bijarnia
Copy link
Author

@Anshu-Bijarnia Have you tried running the tests locally with a connected device or emulator?

Can you help me with this, even adding the write permission. The ImageCaptureDeviceTest fails. Write permission is only required till SDK - 28, correct? Higher than that the device already has access to scoped storage by default. Guide me on where i am going wrong.

@davidjiagoogle
Copy link
Collaborator

@Anshu-Bijarnia

I can't be sure the exact problem you had after adding these permissions to AppTestUtil.APP_REQUIRED_PERMISSION the PR is not updated with them, but I'm guessing you ran into this error:
"Permission: android.permission.[one of the permissions] cannot be granted!
junit.framework.AssertionFailedError: Failed to grant permissions"

This could be because you are trying to grant a permission passed a build version on which it can be granted. For example, if you try to grant "READ_EXTERNAL_STORAGE" on 32 and above, this error would show.

Did you version gate the permissions like you did in JcaApp when adding them to AppTestUtil?

Could you update the PR with the latest change and let's see what the errors are?

Comment on lines +35 to +39
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<!-- To handle the reselection within the app on devices running Android 14
or higher if your app targets Android 14 (API level 34) or higher. -->
<uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED" />
Copy link
Collaborator

Choose a reason for hiding this comment

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

these 3 permissions should be added in AppTestUtil with the same version-checking logics they as in JcaApp

Copy link
Author

Choose a reason for hiding this comment

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

I will do that and make a PR

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