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

[Health 10.2.0] Health connect permissions don't match what is asked #984

Closed
louisdeveseleer opened this issue Jun 18, 2024 · 3 comments · Fixed by #1117
Closed

[Health 10.2.0] Health connect permissions don't match what is asked #984

louisdeveseleer opened this issue Jun 18, 2024 · 3 comments · Fixed by #1117
Assignees
Labels
bugfix a bug fix

Comments

@louisdeveseleer
Copy link

louisdeveseleer commented Jun 18, 2024

Device / Emulator and OS

  • Device: Pixel 7
  • OS: Android 14

Describe the bug

The permissions appearing in Health connect do not match the list of permissions passed to the plugin method requestAuthorization.

Dart:

  final types = [
    HealthDataType.WEIGHT,
    HealthDataType.HEIGHT,
    HealthDataType.WORKOUT,
    HealthDataType.ACTIVE_ENERGY_BURNED,
  ];
  final permissions = [
    HealthDataAccess.WRITE,
    HealthDataAccess.WRITE,
    HealthDataAccess.WRITE,
    HealthDataAccess.WRITE,
  ];
  await health.requestAuthorization(types, permissions: permissions);

Android Manifest:

    <uses-permission android:name="android.permission.health.WRITE_HEIGHT"/>
    <uses-permission android:name="android.permission.health.WRITE_WEIGHT"/>
    <uses-permission android:name="android.permission.health.WRITE_EXERCISE"/>
    <uses-permission android:name="android.permission.health.WRITE_ACTIVE_CALORIES_BURNED"/>

Health connect screen:
Screenshot_20240618-105608

The "write" permissions in health connect do not include the ones that were requested, and the "read" permissions include all of them, although none was requested.

As a consequence:

  • the necessary permissions are not enabled, which leads to failed writes to health connect.
  • the method hasPermissions always returns false.

To Reproduce

Ask for Write-only permissions.

Expected behavior

For Health connect to list the exact permissions requested, no more, no less.

Actual behavior

The permissions requested do not appear, and others that were not requested do appear.

Flutter doctor

[✓] Flutter (Channel stable, 3.22.2, on macOS 14.5 23F79 darwin-arm64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.1)
[✓] VS Code (version 1.90.1)
[✓] Connected device (4 available)
[✓] Network resources

• No issues found!
@louisdeveseleer louisdeveseleer added the bugfix a bug fix label Jun 18, 2024
@louisdeveseleer
Copy link
Author

After further investigation, I was able to narrow down the precise issues:

  • On the device Pixel 7 (Android 14, sdk 34), there are extra permissions asked (which lead to hasPermission returning false), but we can still write data as needed.
  • On an older device (Nokia 6.1, Android 10, sdk 29), the Health plugin version 10.2.0 fails to write any data. After many attempts to make things work, I had to revert to Health version 9.0.1 to be able to restore the data writes.

@harryandroiddev
Copy link

harryandroiddev commented Aug 28, 2024

This is because you are using workout , which under the hood request for total calories burned and distance .

This is the plugin native code for android


   // Workout also needs distance and total energy burned too
            if (typeKey == WORKOUT) {
                if (access == 0) {
                    permList.addAll(
                        listOf(
                            HealthPermission.getReadPermission(
                                DistanceRecord::class
                            ),
                            HealthPermission.getReadPermission(
                                TotalCaloriesBurnedRecord::class
                            ),
                        ),
                    )
                } else {
                    permList.addAll(
                        listOf(
                            HealthPermission.getReadPermission(
                                DistanceRecord::class
                            ),
                            HealthPermission.getReadPermission(
                                TotalCaloriesBurnedRecord::class
                            ),
                            HealthPermission.getWritePermission(
                                DistanceRecord::class
                            ),
                            HealthPermission.getWritePermission(
                                TotalCaloriesBurnedRecord::class
                            ),
                        ),
                    )
                }
            }

@louisdeveseleer
Copy link
Author

@harryandroiddev Thanks for sharing your insight!
Do you know why "Distance" is automatically added for Workout, considering that many workout types don't involve any distance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix a bug fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants