Drjacky / ImagePicker

📸Image Picker for Android, Pick images from Gallery or Capture a new image with Camera🖼
https://github.com/Drjacky/ImagePicker
Apache License 2.0
233 stars 57 forks source link

Crashes on some Android 10 devices #28

Closed petruscurtu closed 3 years ago

petruscurtu commented 3 years ago

Hello,

I am using your library in a production application and have received some bug reports in my crashalytics dashboard. It seems to affect certain devices running Android 10. I have tested locally with emulators and devices running Android 10 but could not reproduce the issue.

Firebase logs

Caused by android.graphics.ImageDecoder$DecodeException: Input was incomplete.
       at android.graphics.ImageDecoder.onPartialImage(ImageDecoder.java:1967)
       at android.graphics.ImageDecoder.nDecodeBitmap(ImageDecoder.java)
       at android.graphics.ImageDecoder.decodeBitmapInternal(ImageDecoder.java:1697)
       at android.graphics.ImageDecoder.decodeBitmapImpl(ImageDecoder.java:1854)
       at android.graphics.ImageDecoder.decodeBitmap(ImageDecoder.java:1945)
       at com.github.drjacky.imagepicker.provider.CropProvider.getBitmap(CropProvider.kt:173)
       at com.github.drjacky.imagepicker.provider.CropProvider.cropImage(CropProvider.kt:123)
       at com.github.drjacky.imagepicker.provider.CropProvider.startIntent(CropProvider.kt:105)
       at com.github.drjacky.imagepicker.ImagePickerActivity.setImage(ImagePickerActivity.kt:162)
       at com.github.drjacky.imagepicker.provider.CameraProvider.handleResult(CameraProvider.kt:156)
       at com.github.drjacky.imagepicker.ImagePickerActivity$cameraLauncher$1.onActivityResult(ImagePickerActivity.kt:54)
       at com.github.drjacky.imagepicker.ImagePickerActivity$cameraLauncher$1.onActivityResult(ImagePickerActivity.kt:25)
       at androidx.activity.result.ActivityResultRegistry.doDispatch(ActivityResultRegistry.java:377)
       at androidx.activity.result.ActivityResultRegistry.dispatchResult(ActivityResultRegistry.java:336)
       at androidx.activity.ComponentActivity.onActivityResult(ComponentActivity.java:624)
       at androidx.fragment.app.FragmentActivity.onActivityResult(FragmentActivity.java:164)
       at android.app.Activity.dispatchActivityResult(Activity.java:8292)
       at android.app.ActivityThread.deliverResults(ActivityThread.java:5223)
       at android.app.ActivityThread.handleSendResult(ActivityThread.java:5271)
       at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
       at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2216)
       at android.os.Handler.dispatchMessage(Handler.java:107)
       at android.os.Looper.loop(Looper.java:237)
       at android.app.ActivityThread.main(ActivityThread.java:7948)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)

and

Caused by android.graphics.ImageDecoder$DecodeException: Failed to create image decoder with message 'unimplemented'Input contained an error.
       at android.graphics.ImageDecoder.nCreate(ImageDecoder.java)
       at android.graphics.ImageDecoder.createFromAssetFileDescriptor(ImageDecoder.java:351)
       at android.graphics.ImageDecoder.access$400(ImageDecoder.java:173)
       at android.graphics.ImageDecoder$ContentResolverSource.createImageDecoder(ImageDecoder.java:289)
       at android.graphics.ImageDecoder.decodeBitmapImpl(ImageDecoder.java:1847)
       at android.graphics.ImageDecoder.decodeBitmap(ImageDecoder.java:1945)
       at com.github.drjacky.imagepicker.provider.CropProvider.getBitmap(CropProvider.kt:173)
       at com.github.drjacky.imagepicker.provider.CropProvider.cropImage(CropProvider.kt:123)
       at com.github.drjacky.imagepicker.provider.CropProvider.startIntent(CropProvider.kt:105)
       at com.github.drjacky.imagepicker.ImagePickerActivity.setImage(ImagePickerActivity.kt:162)
       at com.github.drjacky.imagepicker.provider.CameraProvider.handleResult(CameraProvider.kt:156)
       at com.github.drjacky.imagepicker.ImagePickerActivity$cameraLauncher$1.onActivityResult(ImagePickerActivity.kt:54)
       at com.github.drjacky.imagepicker.ImagePickerActivity$cameraLauncher$1.onActivityResult(ImagePickerActivity.kt:25)
       at androidx.activity.result.ActivityResultRegistry$1.onStateChanged(ActivityResultRegistry.java:148)
       at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:354)
       at androidx.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.java:265)
       at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:307)
       at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:148)
       at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:134)
       at androidx.lifecycle.ReportFragment.dispatch(ReportFragment.java:68)
       at androidx.lifecycle.ReportFragment$LifecycleCallbacks.onActivityPostStarted(ReportFragment.java:187)
       at android.app.Activity.dispatchActivityPostStarted(Activity.java:1274)
       at android.app.Activity.performStart(Activity.java:8026)
       at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3677)
       at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
       at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
       at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2267)
       at android.os.Handler.dispatchMessage(Handler.java:107)
       at android.os.Looper.loop(Looper.java:237)
       at android.app.ActivityThread.main(ActivityThread.java:8167)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)

Smartphone (please complete the following information): All the logs are from devices running Android 10. Affected models seems to include:

Code

Intent intent = ImagePicker.Companion.with(this)
          .cameraOnly()
          .crop()
          .createIntent();

The problem seems to arise in the crop functionality before the activity result callback function is called. The problems have originated in apps which used version 2.1.7 of the library. I upgraded the library to the latest version (2.1.12) but I am not sure this will fix the issues. Any help regarding the issue would be much appreciated.

Drjacky commented 3 years ago

Could you create a bug ticket on android? I'm using the ImageDecoder (for API above P) and BitmapFactory from android.graphics.* package.

Drjacky commented 3 years ago

I could reproduce the issue by choosing a corrupted image. It has been fixed on v2.1.14. Now, if the image has an issue (or there is an issue on the crop step), it cancels the process and does not crash the app.