dropbox / dropshots

Easy on-device screenshot testing for Android.
Apache License 2.0
260 stars 17 forks source link

ErrnoException: open failed: EACCES (Permission denied) #74

Open saket opened 2 weeks ago

saket commented 2 weeks ago

Dropshots fails to read images every now and then with this error:

java.io.FileNotFoundException: /storage/emulated/0/Download/screenshots/me.saket.telephoto.subsamplingimage.test/various_image_orientations_in_exif_metadata[RotatedBy180,Center,Fill]_zoomed.png: open failed: EACCES (Permission denied)
at libcore.io.IoBridge.open(IoBridge.java:575)
at java.io.FileOutputStream.<init>(FileOutputStream.java:236)
at java.io.FileOutputStream.<init>(FileOutputStream.java:186)
at com.dropbox.dropshots.Dropshots.writeImage(Dropshots.kt:196)
at com.dropbox.dropshots.Dropshots.writeThen(Dropshots.kt:176)
at com.dropbox.dropshots.Dropshots.assertSnapshot(Dropshots.kt:153)
at com.dropbox.dropshots.Dropshots.assertSnapshot(Dropshots.kt:94)
at com.dropbox.dropshots.Dropshots.assertSnapshot$default(Dropshots.kt:90)
…
Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
at libcore.io.Linux.open(Native Method)
at libcore.io.ForwardingOs.open(ForwardingOs.java:567)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:273)
at libcore.io.ForwardingOs.open(ForwardingOs.java:567)
at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7725)
at libcore.io.IoBridge.open(IoBridge.java:561)
... 24 more

I used to workaround this by manually granting WRITE_EXTERNAL_STORAGE permission in my tests, but do you know why is this even needed?

// Shouldn't be needed on > API 29, but dropshots is occasionally unable to write to external storage without this.
val uiAutomation = InstrumentationRegistry.getInstrumentation().uiAutomation
uiAutomation.grantRuntimePermission(packageName, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
rharter commented 2 weeks ago

Hmm, I've seen this from time to time as well, but I'm not sure where it's coming from, the emulator or the emulators bridge to the host system. I'm working on some updates for managed devices that I think should fix this as well, if you don't mind using your workaround until those land.

saket commented 2 weeks ago

Sounds good! I'll also cross-post this to google's issuetracker in case they might have any ideas.

saket commented 2 weeks ago

Done: https://issuetracker.google.com/issues/378650093