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: fixes incorrectly mapping from granted permissions to record types #153

Merged
merged 5 commits into from
Sep 10, 2024

Conversation

matinzd
Copy link
Owner

@matinzd matinzd commented Sep 10, 2024

Rebase of #142

Summary

How we infer Record types from permission names after calling PermissionController.getGrantedPermissions doesn't work for all permissions - not all record names overlap with snake cased version of the permission names. For example, the code block:

val perm1 = HealthPermission.getReadPermission(MenstruationFlowRecord::class)
      val perm2 = HealthPermission.getReadPermission(MenstruationPeriodRecord::class)
      val perm3 = HealthPermission.getReadPermission(ExerciseSessionRecord::class)
      listOf(perm1, perm2, perm3).forEach {
        Log.d("PermissionUtils", it)
      }

will output:

2024-08-31 14:00:59.844 21940-22030 PermissionUtils         com.healthconnectexample             D  android.permission.health.READ_MENSTRUATION
2024-08-31 14:00:59.844 21940-22030 PermissionUtils         com.healthconnectexample             D  android.permission.health.READ_MENSTRUATION
2024-08-31 14:00:59.844 21940-22030 PermissionUtils         com.healthconnectexample             D  android.permission.health.READ_EXERCISE

The only way to extract the exact set of React RecordTypes an app has permissions for would be to run through the record classes supported by the library and run its read/write permission against the list of granted permissions returned by the PermissionController which is what this PR aims to do.

Testing

Manually tested the example app and the granted permissions worked as usual.

Related Issues

Should fix #63 as the record name for sleep is SleepSession (ref) while the permission name is READ_/WRITE_SLEEP (ref).

@matinzd matinzd linked an issue Sep 10, 2024 that may be closed by this pull request
@matinzd matinzd merged commit c7851a7 into main Sep 10, 2024
3 checks passed
@matinzd matinzd deleted the fix/permission-typing branch September 10, 2024 21:12
matinzd added a commit that referenced this pull request Sep 10, 2024
…es (#153)

* fix: fixes incorrect mapping between permission names to records

* style: reformatted file and remove unused import

* fix: fixes granted permissions loop order and adds a permission class

* chore: remove obsolete custom exception

* chore: update example

---------

Co-authored-by: Ugur Akin <[email protected]>
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