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

Fix crash when user wants to use the camera #1400

Merged
merged 18 commits into from
Sep 21, 2023
Merged

Conversation

bmarty
Copy link
Member

@bmarty bmarty commented Sep 21, 2023

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

Camera permission is not required when using the external app, except when the Android Manifest contains the CAMERA permission. And this permission has been added when we integrated Element Call.

This PR ensures that the CAMERA permission is provided when user want to:

  • take a photo or record a video to send as attachement
  • take a photo to set a room avatar when creating a room
  • take a photo to set a room avatar when editing a room
  • take a photo to set the user profile

Also contains some cleanup on the codebase, and some new localazy strings.

At some point we will need to revisit how we manage the permissions, since this is also done for the location permission, in the dedicated module.

Motivation and context

Fixes #1395

Screenshots / GIFs

Tests

  • Test the use case in the description

Tested devices

  • Physical
  • Emulator
  • OS version(s):

Checklist

@bmarty bmarty requested a review from a team as a code owner September 21, 2023 11:02
@bmarty bmarty requested review from julioromano and removed request for a team September 21, 2023 11:02
@ElementBot
Copy link
Collaborator

ElementBot commented Sep 21, 2023

Warnings
⚠️

features/createroom/impl/src/main/kotlin/io/element/android/features/createroom/impl/configureroom/ConfigureRoomView.kt#L35 - Using a material import while also using the material3 library

⚠️

features/createroom/impl/src/main/kotlin/io/element/android/features/createroom/impl/configureroom/ConfigureRoomView.kt#L36 - Using a material import while also using the material3 library

⚠️

features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/user/editprofile/EditUserProfileView.kt#L30 - Using a material import while also using the material3 library

⚠️

features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/user/editprofile/EditUserProfileView.kt#L31 - Using a material import while also using the material3 library

⚠️

features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/edit/RoomDetailsEditView.kt#L34 - Using a material import while also using the material3 library

⚠️

features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/edit/RoomDetailsEditView.kt#L35 - Using a material import while also using the material3 library

⚠️

libraries/permissions/api/src/main/kotlin/io/element/android/libraries/permissions/api/PermissionsViewStateProvider.kt#L25 - Field requires API level 33 (current min is 23): android.Manifest.permission#POST_NOTIFICATIONS

⚠️

libraries/permissions/api/src/main/kotlin/io/element/android/libraries/permissions/api/PermissionsViewStateProvider.kt#L34 - Field requires API level 33 (current min is 23): android.Manifest.permission#POST_NOTIFICATIONS

Generated by 🚫 dangerJS against 56a57de

@github-actions
Copy link
Contributor

github-actions bot commented Sep 21, 2023

📱 Scan the QR code below to install the build (arm64 only) for this PR.
QR code
If you can't scan the QR code you can install the build via this link: https://i.diawi.com/gQYxqA

@bmarty bmarty changed the title Fix crash when user wants to photo Fix crash when user wants to use the camera Sep 21, 2023
ConfigureRoomView(
state = state,
modifier = modifier,
onBackPressed = this::navigateUp,
onRoomCreated = this::onRoomCreated,
onOpenSystemSettings = { context.openAppSettingsPage() }
Copy link

@julioromano julioromano Sep 21, 2023

Choose a reason for hiding this comment

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

Maybe this can be moved into PermissionsPresenter itself so each client of PermissionsPresenter doesn't have to manually add it?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, a bit simpler: dd5d67d

@codecov
Copy link

codecov bot commented Sep 21, 2023

Codecov Report

Patch coverage: 74.35% and project coverage change: +0.03% 🎉

Comparison is base (7b9d2f9) 57.97% compared to head (1b5aa7a) 58.01%.
Report is 8 commits behind head on develop.

❗ Current head 1b5aa7a differs from pull request most recent head 5a8f2c5. Consider uploading reports for the commit 5a8f2c5 to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1400      +/-   ##
===========================================
+ Coverage    57.97%   58.01%   +0.03%     
===========================================
  Files         1126     1128       +2     
  Lines        29794    29853      +59     
  Branches      6052     6060       +8     
===========================================
+ Hits         17274    17318      +44     
- Misses        9931     9936       +5     
- Partials      2589     2599      +10     
Files Changed Coverage Δ
.../permissions/impl/action/AndroidLocationActions.kt 0.00% <0.00%> (ø)
...createroom/impl/configureroom/ConfigureRoomView.kt 56.39% <25.00%> (+0.66%) ⬆️
...aries/permissions/test/FakePermissionsPresenter.kt 45.45% <33.33%> (-4.55%) ⬇️
...ences/impl/user/editprofile/EditUserProfileView.kt 52.43% <50.00%> (+1.18%) ⬆️
...tures/roomdetails/impl/edit/RoomDetailsEditView.kt 70.09% <50.00%> (+0.56%) ⬆️
...droid/libraries/permissions/api/PermissionsView.kt 43.47% <60.00%> (-9.30%) ⬇️
...s/impl/messagecomposer/MessageComposerPresenter.kt 86.28% <65.38%> (-4.34%) ⬇️
...es/permissions/impl/DefaultPermissionsPresenter.kt 89.58% <75.00%> (-1.12%) ⬇️
...eroom/impl/configureroom/ConfigureRoomPresenter.kt 83.33% <90.90%> (-2.16%) ⬇️
.../impl/user/editprofile/EditUserProfilePresenter.kt 81.08% <90.90%> (+1.39%) ⬆️
... and 12 more

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@julioromano julioromano left a comment

Choose a reason for hiding this comment

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

LGTM, just some suggestions for the future.

) : Presenter<ConfigureRoomState> {

private val cameraPermissionPresenter: PermissionsPresenter = permissionsPresenterFactory.create(android.Manifest.permission.CAMERA)
private var pendingPermissionRequest = false

Choose a reason for hiding this comment

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

Maybe this should be a remember { mutableStateOf() } ?

Moreover, perhaps this could also be hoisted to PermissionsPresenter to simplify the client side impementation.

@@ -182,6 +185,10 @@ class ConfigureRoomPresenterTests {
// From camera
val uriFromCamera = Uri.parse(AN_URI_FROM_CAMERA)
fakePickerProvider.givenResult(uriFromCamera)
assertThat(newState.cameraPermissionState.permissionGranted).isFalse()

Choose a reason for hiding this comment

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

Shouldn't we also test that when permission is not granted we catually call into the PermissionsPresenter to request it?

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, there is a missing test. I will ad it.

@@ -65,7 +65,7 @@ class NotificationsOptInPresenter @AssistedInject constructor(
if (notificationsPermissionsState.permissionGranted) {
callback.onNotificationsOptInFinished()
} else {
notificationsPermissionsState.eventSink(PermissionsEvents.OpenSystemDialog)
notificationsPermissionsState.eventSink(PermissionsEvents.AskPermissionToUser)

Choose a reason for hiding this comment

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

In similar android contexts this is usually called "RequestPermissions".

@bmarty
Copy link
Member Author

bmarty commented Sep 21, 2023

@julioromano should be fine now, the CI should turn green.

@bmarty bmarty merged commit 0255ec6 into develop Sep 21, 2023
@bmarty bmarty deleted the feature/bma/fixCrashPhoto branch September 21, 2023 14:31
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

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.

[Crash] Crash when trying to take a picture
3 participants