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

Issue/12126 fix image upload issues #12127

Merged
merged 3 commits into from
Jul 24, 2024

Conversation

hichamboushaba
Copy link
Member

@hichamboushaba hichamboushaba commented Jul 24, 2024

Closes: #12126

Description

This PR fixes two issues regarding media upload:

  1. Fixes an issue where the lack fo the permission to read external storage broke media upload from local files on devices with Android 9 and lower.
    The issue happens because we don't fetch media when the Uri is in the media store content:://media, then later when we try to read it directly in FluxC, it causes an issue.
    This wasn't happening on devices running on Android 10 and above, as we still had to copy the file to internal storage later on, so accidentally the issue wasn't caught when we removed the permissions.
    The fix I applied here is to remove the check, and proceed to fetch the external media in all cases: meaning the external file will be copied to app's internal cache before the upload, this will align the behavior for all platforms, and it was already happening for newer Android versions.

  2. Fixes an issue with Camera flow, the issue was also caused by the lack of the external storage permissions, mainly the WRITE_EXTERNAL_STORAGE one, and I believe this was caused by a misinterpretation of the documentation, the library requires the permission WRITE_EXTERNAL_STORAGE for devices running on API lower than 29, where the documentation states (in a non-clear way TBH) that this permission is needed only for devices with API lower than 19.
    This fix comes from the MediaPicker library PR.

Steps to reproduce

Preparation
  1. Use trunk or the release/19.6 branch
  2. Apply the following patch (the patch is needed because we still have the needed permissions on debug builds, so the issue is not reproducible on them without this change)
Index: WooCommerce/src/debug/AndroidManifest.xml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/WooCommerce/src/debug/AndroidManifest.xml b/WooCommerce/src/debug/AndroidManifest.xml
--- a/WooCommerce/src/debug/AndroidManifest.xml	(revision 4c39a709bfd15241392554ecc9e17cf1e21d268c)
+++ b/WooCommerce/src/debug/AndroidManifest.xml	(date 1721823754943)
@@ -8,10 +8,10 @@
     <uses-permission android:name="android.permission.WAKE_LOCK" />
 
     <!-- Allows for storing and retrieving screenshots -->
-    <uses-permission
-        android:name="android.permission.WRITE_EXTERNAL_STORAGE"
-        android:maxSdkVersion="28" />
-    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
+<!--    <uses-permission-->
+<!--        android:name="android.permission.WRITE_EXTERNAL_STORAGE"-->
+<!--        android:maxSdkVersion="28" />-->
+<!--    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />-->
 
     <!-- Allows changing locales -->
     <uses-permission
Local files
  1. Use a device with Android 9 or 8
  2. Open the app
  3. Add a file to a new or existing product from the device
  4. Notice the upload failure.
Camera
  1. Use a device with Android 9 or 8
  2. Open the app
  3. Add a file to a new or existing product from the camera
  4. Notice the camera complaints about the lack of the storage permission

Testing information

  1. Switch to this branch.
  2. Confirm the two above cases are now working without issues.
  3. Test on a newer device too and confirm there is no regression.
  • I have considered if this change warrants release notes and have added them to RELEASE-NOTES.txt if necessary. Use the "[Internal]" label for non-user-facing changes.

@hichamboushaba hichamboushaba added type: bug A confirmed bug. feature: product details Related to adding or editing products, includes product settings. status: do not merge Dependent on another PR, ready for review but not ready for merge. labels Jul 24, 2024
@dangermattic
Copy link
Collaborator

dangermattic commented Jul 24, 2024

1 Warning
⚠️ This PR is assigned to the milestone 19.6 ❄️. The due date for this milestone has already passed.
Please assign it to a milestone with a later deadline or check whether the release for this milestone has already been finished.
1 Message
📖 This PR contains changes to RELEASE-NOTES.txt.
Note that these changes won't affect the final version of the release notes as this version is in code freeze.
Please, get in touch with a release manager if you want to update the final release notes.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Jul 24, 2024

📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
App Name WooCommerce-Wear Android
Platform⌚️ Wear OS
FlavorJalapeno
Build TypeDebug
Commitd5c3154
Direct Downloadwoocommerce-wear-prototype-build-pr12127-d5c3154.apk

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Jul 24, 2024

📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.

App Name WooCommerce Android
Platform📱 Mobile
FlavorJalapeno
Build TypeDebug
Commitd5c3154
Direct Downloadwoocommerce-prototype-build-pr12127-d5c3154.apk

Comment on lines 11 to 14
<!-- <uses-permission-->
<!-- android:name="android.permission.WRITE_EXTERNAL_STORAGE"-->
<!-- android:maxSdkVersion="28" />-->
<!-- <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />-->
Copy link
Member Author

@hichamboushaba hichamboushaba Jul 24, 2024

Choose a reason for hiding this comment

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

I removed these permissions temporarily, I'll make sure to revert this commit before merging.

My goal is to make testing the PR changes easier for Paolo without having to build the app locally, because since the alpha builds from PRs use debug variant, they would have the needed permissions, and then the issue won't be reproducible on them.

@hichamboushaba
Copy link
Member Author

@pmusolino can you please test the changes of this PR using the build from above and confirm if it fixes the issues you encountered on your device.

@JorgeMucientes JorgeMucientes self-assigned this Jul 24, 2024
@pmusolino pmusolino self-requested a review July 24, 2024 14:50
Copy link
Member

@pmusolino pmusolino left a comment

Choose a reason for hiding this comment

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

It works as expected! Thanks, Hicham

Copy link
Contributor

@JorgeMucientes JorgeMucientes left a comment

Choose a reason for hiding this comment

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

Excellent job at finding the culprit of the issue @hichamboushaba . This was a tricky one.

As talked in private I was not able to reproduce the bug due to the emulators with Androdi 8 and 9 not showing the photo picker. But since Paolo tested that the bug is fixed for him I think that should be enough. Also checked there are no regressions with the changes

:shipit:

This is needed to fix a bug where media upload fails on devices running on versions lower than Android 10
@hichamboushaba hichamboushaba force-pushed the issue/12126-fix-image-upload-issues branch from c8d0f45 to d5c3154 Compare July 24, 2024 16:07
@hichamboushaba hichamboushaba removed the status: do not merge Dependent on another PR, ready for review but not ready for merge. label Jul 24, 2024
@wpmobilebot
Copy link
Collaborator

Found 1 violations:

The PR caused the following dependency changes:

expand

-+--- org.wordpress:mediapicker:0.3.0
-|    +--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.8.21 -> 1.9.22 (*)
-|    +--- com.google.android.material:material:1.6.1 -> 1.9.0 (*)
-|    +--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4 -> 1.8.1 (*)
-|    +--- androidx.navigation:navigation-fragment-ktx:2.5.3 -> 2.7.7 (*)
-|    +--- androidx.core:core-ktx:1.12.0 (*)
-|    +--- androidx.appcompat:appcompat:1.4.2 -> 1.6.1 (*)
-|    +--- androidx.constraintlayout:constraintlayout:2.1.4 (*)
-|    +--- androidx.swiperefreshlayout:swiperefreshlayout:1.1.0 (*)
-|    +--- androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2 (*)
-|    +--- androidx.datastore:datastore-preferences:1.0.0 (*)
-|    +--- com.github.bumptech.glide:glide:4.13.2 -> 4.16.0 (*)
-|    +--- com.google.dagger:hilt-android:2.45 -> 2.50 (*)
-|    +--- com.google.dagger:hilt-android-compiler:2.45
-|    |    +--- com.google.dagger:dagger:2.45 -> 2.50 (*)
-|    |    +--- com.google.dagger:dagger-compiler:2.45
-|    |    |    +--- com.google.dagger:dagger:2.45 -> 2.50 (*)
-|    |    |    +--- com.google.dagger:dagger-producers:2.45
-|    |    |    |    +--- com.google.dagger:dagger:2.45 -> 2.50 (*)
-|    |    |    |    +--- com.google.guava:failureaccess:1.0.1 -> 1.0.2
-|    |    |    |    +--- com.google.guava:guava:31.0.1-jre -> 33.1.0-android (*)
-|    |    |    |    +--- javax.inject:javax.inject:1
-|    |    |    |    \--- org.checkerframework:checker-compat-qual:2.5.5
-|    |    |    +--- com.google.dagger:dagger-spi:2.45
-|    |    |    |    +--- com.google.dagger:dagger:2.45 -> 2.50 (*)
-|    |    |    |    +--- com.google.dagger:dagger-producers:2.45 (*)
-|    |    |    |    +--- com.google.code.findbugs:jsr305:3.0.2
-|    |    |    |    +--- com.google.devtools.ksp:symbol-processing-api:1.7.0-1.0.6
-|    |    |    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.7.0 -> 1.9.22 (*)
-|    |    |    |    +--- com.google.guava:failureaccess:1.0.1 -> 1.0.2
-|    |    |    |    +--- com.google.guava:guava:31.0.1-jre -> 33.1.0-android (*)
-|    |    |    |    +--- com.squareup:javapoet:1.13.0
-|    |    |    |    +--- com.squareup:kotlinpoet:1.11.0
-|    |    |    |    |    +--- org.jetbrains.kotlin:kotlin-reflect:1.6.10
-|    |    |    |    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.6.10 -> 1.9.22 (*)
-|    |    |    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10 -> 1.9.10 (*)
-|    |    |    |    +--- javax.inject:javax.inject:1
-|    |    |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.7.0 -> 1.9.22 (*)
-|    |    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.0 -> 1.9.10 (*)
-|    |    |    +--- com.google.code.findbugs:jsr305:3.0.2
-|    |    |    +--- com.google.devtools.ksp:symbol-processing-api:1.7.0-1.0.6 (*)
-|    |    |    +--- com.google.googlejavaformat:google-java-format:1.5
-|    |    |    |    +--- com.google.guava:guava:22.0 -> 33.1.0-android (*)
-|    |    |    |    \--- com.google.errorprone:javac-shaded:9-dev-r4023-3
-|    |    |    +--- com.google.guava:failureaccess:1.0.1 -> 1.0.2
-|    |    |    +--- com.google.guava:guava:31.0.1-jre -> 33.1.0-android (*)
-|    |    |    +--- com.squareup:javapoet:1.13.0
-|    |    |    +--- javax.inject:javax.inject:1
-|    |    |    +--- net.ltgt.gradle.incap:incap:0.2
-|    |    |    +--- org.checkerframework:checker-compat-qual:2.5.5
-|    |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.7.0 -> 1.9.22 (*)
-|    |    |    \--- org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.5.0
-|    |    |         \--- org.jetbrains.kotlin:kotlin-stdlib:1.7.0 -> 1.9.22 (*)
-|    |    +--- com.google.dagger:dagger-spi:2.45 (*)
-|    |    +--- com.google.code.findbugs:jsr305:3.0.2
-|    |    +--- com.google.guava:failureaccess:1.0.1 -> 1.0.2
-|    |    +--- com.google.guava:guava:31.0.1-jre -> 33.1.0-android (*)
-|    |    +--- com.squareup:javapoet:1.13.0
-|    |    +--- javax.annotation:javax.annotation-api:1.3.2
-|    |    +--- javax.inject:javax.inject:1
-|    |    +--- net.ltgt.gradle.incap:incap:0.2
-|    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.7.0 -> 1.9.22 (*)
-|    |    \--- org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.5.0 (*)
-|    +--- com.github.chrisbanes:PhotoView:2.3.0 (*)
-|    +--- org.wordpress.mediapicker:domain:0.3.0
-|    |    +--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.8.21 -> 1.9.22 (*)
-|    |    +--- androidx.core:core-ktx:1.12.0 (*)
-|    |    +--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4 -> 1.8.1 (*)
-|    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.21 -> 1.9.10 (*)
-|    +--- androidx.databinding:viewbinding:8.1.0 (*)
-|    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.21 -> 1.9.10 (*)
++--- org.wordpress:mediapicker:0.3.1 FAILED
-+--- org.wordpress.mediapicker:source-camera:0.3.0
-|    +--- org.wordpress.mediapicker:domain:0.3.0 (*)
-|    +--- androidx.core:core-ktx:1.12.0 (*)
-|    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.21 -> 1.9.10 (*)
++--- org.wordpress.mediapicker:source-camera:0.3.1 FAILED
-\--- org.wordpress.mediapicker:source-wordpress:0.3.0
-     +--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.8.21 -> 1.9.22 (*)
-     +--- org.wordpress.mediapicker:domain:0.3.0 (*)
-     +--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4 -> 1.8.1 (*)
-     +--- com.google.dagger:hilt-android:2.45 -> 2.50 (*)
-     +--- com.google.dagger:hilt-android-compiler:2.45 (*)
-     \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.21 -> 1.9.10 (*)
+\--- org.wordpress.mediapicker:source-wordpress:0.3.1 FAILED

Please review and act accordingly

@hichamboushaba hichamboushaba merged commit db2d626 into release/19.6 Jul 24, 2024
14 of 16 checks passed
@hichamboushaba hichamboushaba deleted the issue/12126-fix-image-upload-issues branch July 24, 2024 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: product details Related to adding or editing products, includes product settings. type: bug A confirmed bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Image upload is broken for devices running on Android 9 and lower
5 participants