diff --git a/CHANGELOG.md b/CHANGELOG.md index ebddeaa6..b56c9b17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ The changes documented here do not include those from the original repository. ## [Unreleased] +## 2024-03-18 +- Implemented the usage of the Activity Transition Recognition API for background jobs (https://outsystemsrd.atlassian.net/browse/RMET-3191). + ## 2024-03-14 - Implemented the usage of exact alarms for background jobs (https://outsystemsrd.atlassian.net/browse/RMET-3190). diff --git a/hooks/androidCopyPreferencesPermissions.js b/hooks/androidCopyPreferencesPermissions.js index 2fecef2b..c272ee9b 100644 --- a/hooks/androidCopyPreferencesPermissions.js +++ b/hooks/androidCopyPreferencesPermissions.js @@ -272,6 +272,7 @@ function addBackgroundJobPermissionsToManifest(configParser, projectRoot, parser // add permissions to XML document addEntryToManifest(manifestXmlDoc, 'android.permission.POST_NOTIFICATIONS') addEntryToManifest(manifestXmlDoc, 'android.permission.ACTIVITY_RECOGNITION') + addEntryToManifest(manifestXmlDoc, 'com.google.android.gms.permission.ACTIVITY_RECOGNITION') // necessary for API 28 and below addEntryToManifest(manifestXmlDoc, 'android.permission.FOREGROUND_SERVICE') addEntryToManifest(manifestXmlDoc, 'android.permission.FOREGROUND_SERVICE_HEALTH') addEntryToManifest(manifestXmlDoc, 'android.permission.HIGH_SAMPLING_RATE_SENSORS') diff --git a/src/android/build.gradle b/src/android/build.gradle index a8b5e498..4edc5a37 100644 --- a/src/android/build.gradle +++ b/src/android/build.gradle @@ -19,13 +19,14 @@ allprojects { dependencies{ implementation("com.google.android.gms:play-services-fitness:20.0.0") implementation("com.google.android.gms:play-services-auth:19.2.0") + implementation("com.google.android.gms:play-services-location:19.0.1") implementation("com.google.code.gson:gson:2.8.8") implementation 'com.google.code.findbugs:jsr305:1.3.9' implementation("com.github.outsystems:oscore-android:1.2.0@aar") implementation("com.github.outsystems:oscordova-android:2.0.1@aar") - implementation("com.github.outsystems:oshealthfitness-android:1.2.0.22@aar") + implementation("com.github.outsystems:oshealthfitness-android:1.2.0.25@aar") implementation("com.github.outsystems:osnotificationpermissions-android:0.0.4@aar") // activity @@ -37,9 +38,6 @@ dependencies{ // health connect sdk implementation "androidx.health.connect:connect-client:1.1.0-alpha07" - // work manager - implementation "androidx.work:work-runtime-ktx:2.9.0" - // compose implementation 'androidx.activity:activity-compose:1.8.2' implementation 'androidx.compose.material3:material3:1.2.0' diff --git a/src/android/com/outsystems/plugins/healthfitness/OSHealthFitness.kt b/src/android/com/outsystems/plugins/healthfitness/OSHealthFitness.kt index 149400c0..7ba0031f 100755 --- a/src/android/com/outsystems/plugins/healthfitness/OSHealthFitness.kt +++ b/src/android/com/outsystems/plugins/healthfitness/OSHealthFitness.kt @@ -33,6 +33,7 @@ class OSHealthFitness : CordovaImplementation() { private lateinit var healthConnectDataManager: HealthConnectDataManager private lateinit var healthConnectHelper: HealthConnectHelper private lateinit var alarmManagerHelper: AlarmManagerHelper + private lateinit var activityTransitionHelper: ActivityTransitionHelper private lateinit var backgroundParameters: BackgroundJobParameters private lateinit var alarmManager: AlarmManager @@ -57,8 +58,9 @@ class OSHealthFitness : CordovaImplementation() { healthConnectRepository = HealthConnectRepository(healthConnectDataManager) healthConnectHelper = HealthConnectHelper() alarmManagerHelper = AlarmManagerHelper() + activityTransitionHelper = ActivityTransitionHelper() healthConnectViewModel = - HealthConnectViewModel(healthConnectRepository, healthConnectHelper, alarmManagerHelper) + HealthConnectViewModel(healthConnectRepository, healthConnectHelper, alarmManagerHelper, activityTransitionHelper) alarmManager = getContext().getSystemService(Context.ALARM_SERVICE) as AlarmManager // get foreground notification title and description from resources (strings.xml) @@ -279,12 +281,12 @@ class OSHealthFitness : CordovaImplementation() { backgroundParameters = gson.fromJson(args.getString(0), BackgroundJobParameters::class.java) //request permission for exact alarms if necessary - if (SDK_INT >= 31 && !alarmManager.canScheduleExactAlarms()) { + if (!Constants.ACTIVITY_VARIABLES.contains(backgroundParameters.variable) && SDK_INT >= 31 && !alarmManager.canScheduleExactAlarms()) { requestingExactAlarmPermission = true // we only need to request this permission if exact alarms need to be used - // when there's another way to schedule background jobs to run, we can avoid this for some variables (e.g. steps) - // we intended to use the Activity Recognition API, but it currently has a bug already reported to Google - getContext().startActivity(Intent(ACTION_REQUEST_SCHEDULE_EXACT_ALARM)); + // when the variable is an activity variable (e.g. steps), + // we use the Activity Recognition Transition API instead of exact alarms. + getContext().startActivity(Intent(ACTION_REQUEST_SCHEDULE_EXACT_ALARM)) } else { // we can move on to other permissions if we don't need to request exact alarm permissions requestBackgroundJobPermissions() }