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 Report: IllegalStateException in Health Connect SDK #162

Open
Poovit-B opened this issue Sep 27, 2024 · 0 comments
Open

## 🐞 Bug Report: IllegalStateException in Health Connect SDK #162

Poovit-B opened this issue Sep 27, 2024 · 0 comments

Comments

@Poovit-B
Copy link

Describe the bug
While testing for SDK availability, an IllegalStateException occurs when attempting to check or initialize the Health Connect SDK. The app crashes unexpectedly instead of handling the error gracefully.

To Reproduce
Steps to reproduce the behavior:

  1. Attempt to use authHealthConnect function when Health Connect is not installed or needs an update.
  2. Observe the crash with the following error message
    androidx.health.platform.client.impl.ipc.internal.ServiceConnection in connect

Expected behavior
When the Health Connect SDK is unavailable, a popup should appear informing the user to download or update Health Connect. The app should not crash.

Code

export const authHealthConnect = async e => {
  try {
    const status = await getSdkStatus();
    if (
      status === SdkAvailabilityStatus.SDK_UNAVAILABLE ||
      status === SdkAvailabilityStatus.SDK_UNAVAILABLE_PROVIDER_UPDATE_REQUIRED
    ) {
      Alert.alert(
        'Health Connect Not Available',
        'Please check if Health Connect is installed.',
        [
          {
            text: 'Download Health Connect',
            onPress: () =>
              Linking.openURL(
                `market://details?id=${HEALTH_APP_BUNDLE_ID.HEALTH_CONNECT}`,
              ),
          },
          {text: 'OK'},
        ],
      );
      throw {
        success: false,
        sdk_unavilable: true,
        message:
          status === SdkAvailabilityStatus.SDK_UNAVAILABLE
            ? 'SDK is not available'
            : SdkAvailabilityStatus.SDK_UNAVAILABLE_PROVIDER_UPDATE_REQUIRED
            ? 'SDK is not available, provider update required'
            : '',
      };
    }
    await initialize();
    await requestPermission(
      options?.scopes?.map(recordType => {
        return {accessType: 'read', recordType};
      }),
    );
    const permissions = await getGrantedPermissions();
    if (permissions?.length) {
      return {
        success: true,
        permissions,
      };
    }
    throw {
      success: false,
    };
  } catch (error) {
    revokePermissionsHealthConnect()
    return {
      success: false,
      error,
    };
  }
};

Screenshots
image

Environment:

  • Health Connect Version:"^2.1.0"
  • React Native Version: "0.74.3"
  • New architecture enabled: Yes/No
  • Using Expo: No
  • Android API Level: Android 13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant