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

[BUG] - Crash when camera permission is present in manifest #417

Closed
PhilippNowak96 opened this issue Jul 28, 2022 · 5 comments · Fixed by #424
Closed

[BUG] - Crash when camera permission is present in manifest #417

PhilippNowak96 opened this issue Jul 28, 2022 · 5 comments · Fixed by #424

Comments

@PhilippNowak96
Copy link
Contributor

  • Lib Version: 4.3.1

Describe the bug

When having <uses-permission android:name="android.permission.CAMERA" /> in AndroidManifest and select Camera as the source, the app crashes due to missing camera permission.

I saw that the permission stuff got removed in 4.0.0 in favor of using ActivityResultContracts (which is awesome actually) but we need that permission for another feature in our app. As soon as you remove the permission from the manifest, selecting camera as source doesn't crash anymore.

Stacktrace
java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE flg=0x3 cmp=com.android.camera2/com.android.camera.CaptureActivity clip={text/uri-list hasLabel(0) {U(content)}} (has extras) } from ProcessRecord{5163a5b 17423:de.nowdev.imagecropperbug/u0a253} (pid=17423, uid=10253) with revoked permission android.permission.CAMERA
        at android.os.Parcel.createExceptionOrNull(Parcel.java:3011)
        at android.os.Parcel.createException(Parcel.java:2995)
        at android.os.Parcel.readException(Parcel.java:2978)
        at android.os.Parcel.readException(Parcel.java:2920)
        at android.app.IActivityTaskManager$Stub$Proxy.startActivity(IActivityTaskManager.java:2043)
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1801)
        at android.app.Activity.startActivityForResult(Activity.java:5470)
        at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:705)
        at androidx.core.app.ActivityCompat$Api16Impl.startActivityForResult(ActivityCompat.java:766)
        at androidx.core.app.ActivityCompat.startActivityForResult(ActivityCompat.java:241)
        at androidx.activity.ComponentActivity$2.onLaunch(ComponentActivity.java:237)
        at androidx.activity.result.ActivityResultRegistry$2.launch(ActivityResultRegistry.java:175)
        at androidx.activity.result.ActivityResultLauncher.launch(ActivityResultLauncher.java:47)
        at com.canhub.cropper.CropImageActivity.openCamera(CropImageActivity.kt:133)
        at com.canhub.cropper.CropImageActivity.openSource(CropImageActivity.kt:125)
        at com.canhub.cropper.CropImageActivity.access$openSource(CropImageActivity.kt:24)
        at com.canhub.cropper.CropImageActivity$onCreate$1.invoke(CropImageActivity.kt:68)
        at com.canhub.cropper.CropImageActivity$onCreate$1.invoke(CropImageActivity.kt:68)
        at com.canhub.cropper.CropImageActivity.showImageSourceDialog$lambda-10(CropImageActivity.kt:159)
        at com.canhub.cropper.CropImageActivity.$r8$lambda$8d0SyBfqZBq2EMFA6nOVWjQNv2s(Unknown Source:0)
        at com.canhub.cropper.CropImageActivity$$ExternalSyntheticLambda0.onClick(Unknown Source:2)
        at androidx.appcompat.app.AlertController$AlertParams$3.onItemClick(AlertController.java:1068)
        at android.widget.AdapterView.performItemClick(AdapterView.java:330)
        at android.widget.AbsListView.performItemClick(AbsListView.java:1197)
        at android.widget.AbsListView$PerformClick.run(AbsListView.java:3210)
        at android.widget.AbsListView$3.run(AbsListView.java:4176)
        at android.os.Handler.handleCallback(Handler.java:942)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7898)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
     Caused by: android.os.RemoteException: Remote stack trace:
        at com.android.server.wm.ActivityTaskSupervisor.checkStartAnyActivityPermission(ActivityTaskSupervisor.java:1108)
        at com.android.server.wm.ActivityStarter.executeRequest(ActivityStarter.java:1013)
        at com.android.server.wm.ActivityStarter.execute(ActivityStarter.java:702)
        at com.android.server.wm.ActivityTaskManagerService.startActivityAsUser(ActivityTaskManagerService.java:1240)
        at com.android.server.wm.ActivityTaskManagerService.startActivityAsUser(ActivityTaskManagerService.java:1203)

To Reproduce
Steps to reproduce the behavior:

  1. Add <uses-permission android:name="android.permission.CAMERA" /> to AndroidManifest
  2. Launch Image Cropper via CropImageContract(): cropImage.launch(options {})
  3. Select Camera as source
  4. See crash

Expected behavior
Library still uses the new way via ActivityResultContract and just ignores the presence of the camera permission

Smartphone (please complete the following information):

  • simply test on Emulator or any device (API >= 23 because of permission I guess)

Additional context
If you need a sample project, just ping me again. I can provide one.

@Canato
Copy link
Member

Canato commented Jul 28, 2022

Not sure how to solve, open for suggestions and/or a PR

@PhilippNowak96
Copy link
Contributor Author

PhilippNowak96 commented Jul 29, 2022

Found out that this behaviour is actually described in the docs too: https://developer.android.com/reference/android/provider/MediaStore#ACTION_IMAGE_CAPTURE 😟

For now we use the workaround to request the camera permission on our side in advance. Not sure if we could do something in the library to at least prevent crashes in this situation.

But I think it would be worth to note that circumstance in the readme. What do you think?

@Canato
Copy link
Member

Canato commented Jul 29, 2022

@PhilippNowak96 We can add on the FAQ documentation, could you please drop the PR?

Would avoid README since is not this library specific

@Canato Canato removed the pinned label Jul 29, 2022
@stale
Copy link

stale bot commented Aug 12, 2022

Let's keep this mess organised! This issue has been automatically marked as stale because it has not had recent activity. =( It will be closed if no further activity occurs. Thank you for your contributions.

@PhilippNowak96
Copy link
Contributor Author

Sorry for the late answer, was quite busy. I opened a PR with the change in the FAQs :)

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