From ef3d45469224e70d605905cd3410036f2aa3e92a Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Mon, 19 Aug 2024 13:50:12 +0100 Subject: [PATCH 01/13] feat: add necessary permission for Android 15 References: https://outsystemsrd.atlassian.net/browse/RMET-3574 --- hooks/androidCopyPreferencesPermissions.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hooks/androidCopyPreferencesPermissions.js b/hooks/androidCopyPreferencesPermissions.js index 9b0b363..092a4a0 100644 --- a/hooks/androidCopyPreferencesPermissions.js +++ b/hooks/androidCopyPreferencesPermissions.js @@ -285,6 +285,14 @@ function addBackgroundJobPermissionsToManifest(configParser, projectRoot, parser addEntryToManifest(manifestXmlDoc, 'android.permission.HIGH_SAMPLING_RATE_SENSORS') addEntryToManifest(manifestXmlDoc, 'android.permission.SCHEDULE_EXACT_ALARM') + // add permissions necessary on Android 15 (API 35) + addEntryToManifest(manifestXmlDoc, 'android.permission.health.READ_HEALTH_DATA_IN_BACKGROUND') + + const permissionsXmlDoc = parser.parseFromString('', 'text/xml'); + const arrayElement = permissionsXmlDoc.getElementsByTagName('array')[0]; + + addEntryToPermissionsXML(permissionsXmlDoc, arrayElement, 'android.permission.health.READ_HEALTH_DATA_IN_BACKGROUND') + // serialize the updated XML document back to string const serializer = new XMLSerializer(); const updatedManifestXmlString = serializer.serializeToString(manifestXmlDoc); From a748b15b53ad27cd7f193e8940d46a99d5558802 Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Mon, 19 Aug 2024 14:10:10 +0100 Subject: [PATCH 02/13] fix: correctly get health_permissions.xml file References: https://outsystemsrd.atlassian.net/browse/RMET-3574 --- hooks/androidCopyPreferencesPermissions.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hooks/androidCopyPreferencesPermissions.js b/hooks/androidCopyPreferencesPermissions.js index 092a4a0..5b93b82 100644 --- a/hooks/androidCopyPreferencesPermissions.js +++ b/hooks/androidCopyPreferencesPermissions.js @@ -276,6 +276,12 @@ function addBackgroundJobPermissionsToManifest(configParser, projectRoot, parser // Parse the XML string const manifestXmlDoc = parser.parseFromString(manifestXmlString, 'text/xml'); + const permissionsXmlFilePath = path.join(projectRoot, 'platforms/android/app/src/main/res/values/health_permissions.xml'); + const permissionsXmlString = fs.readFileSync(permissionsXmlFilePath, 'utf-8'); + + // Parse the XML string + const permissionsXmlDoc = parser.parseFromString(manifestXmlString, 'text/xml'); + // add permissions to XML document addEntryToManifest(manifestXmlDoc, 'android.permission.POST_NOTIFICATIONS') addEntryToManifest(manifestXmlDoc, 'android.permission.ACTIVITY_RECOGNITION') @@ -288,7 +294,6 @@ function addBackgroundJobPermissionsToManifest(configParser, projectRoot, parser // add permissions necessary on Android 15 (API 35) addEntryToManifest(manifestXmlDoc, 'android.permission.health.READ_HEALTH_DATA_IN_BACKGROUND') - const permissionsXmlDoc = parser.parseFromString('', 'text/xml'); const arrayElement = permissionsXmlDoc.getElementsByTagName('array')[0]; addEntryToPermissionsXML(permissionsXmlDoc, arrayElement, 'android.permission.health.READ_HEALTH_DATA_IN_BACKGROUND') From c5989f183b4d65be07504ad243fa6baedcf1b2b1 Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Mon, 19 Aug 2024 14:16:38 +0100 Subject: [PATCH 03/13] fix: use proper health_permissions.xml file References: https://outsystemsrd.atlassian.net/browse/RMET-3574 --- hooks/androidCopyPreferencesPermissions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/androidCopyPreferencesPermissions.js b/hooks/androidCopyPreferencesPermissions.js index 5b93b82..b29ffb4 100644 --- a/hooks/androidCopyPreferencesPermissions.js +++ b/hooks/androidCopyPreferencesPermissions.js @@ -280,7 +280,7 @@ function addBackgroundJobPermissionsToManifest(configParser, projectRoot, parser const permissionsXmlString = fs.readFileSync(permissionsXmlFilePath, 'utf-8'); // Parse the XML string - const permissionsXmlDoc = parser.parseFromString(manifestXmlString, 'text/xml'); + const permissionsXmlDoc = parser.parseFromString(permissionsXmlString, 'text/xml'); // add permissions to XML document addEntryToManifest(manifestXmlDoc, 'android.permission.POST_NOTIFICATIONS') From bb6081e93074c87b0f9d9416229a30298f01c55c Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Mon, 19 Aug 2024 14:25:52 +0100 Subject: [PATCH 04/13] feat: write health_permissions.xml updated file References: https://outsystemsrd.atlassian.net/browse/RMET-3574 --- hooks/androidCopyPreferencesPermissions.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hooks/androidCopyPreferencesPermissions.js b/hooks/androidCopyPreferencesPermissions.js index b29ffb4..856fe19 100644 --- a/hooks/androidCopyPreferencesPermissions.js +++ b/hooks/androidCopyPreferencesPermissions.js @@ -298,12 +298,15 @@ function addBackgroundJobPermissionsToManifest(configParser, projectRoot, parser addEntryToPermissionsXML(permissionsXmlDoc, arrayElement, 'android.permission.health.READ_HEALTH_DATA_IN_BACKGROUND') - // serialize the updated XML document back to string + // serialize the updated XML documents back to strings const serializer = new XMLSerializer(); const updatedManifestXmlString = serializer.serializeToString(manifestXmlDoc); - // write the updated XML string back to the same file + const updatedPermissionsXmlString = serializer.serializeToString(permissionsXmlDoc); + + // write the updated XML strings back to the same files fs.writeFileSync(manifestFilePath, updatedManifestXmlString, 'utf-8'); + fs.writeFileSync(permissionsXmlFilePath, updatedPermissionsXmlString, 'utf-8'); } } From 4c5a30275781c66628e6f94dac679e2eaeb1c188 Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Mon, 19 Aug 2024 14:34:29 +0100 Subject: [PATCH 05/13] refactor: process new health permission first References: https://outsystemsrd.atlassian.net/browse/RMET-3574 --- hooks/androidCopyPreferencesPermissions.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/hooks/androidCopyPreferencesPermissions.js b/hooks/androidCopyPreferencesPermissions.js index 856fe19..e7f8cb8 100644 --- a/hooks/androidCopyPreferencesPermissions.js +++ b/hooks/androidCopyPreferencesPermissions.js @@ -281,6 +281,11 @@ function addBackgroundJobPermissionsToManifest(configParser, projectRoot, parser // Parse the XML string const permissionsXmlDoc = parser.parseFromString(permissionsXmlString, 'text/xml'); + const arrayElement = permissionsXmlDoc.getElementsByTagName('array')[0]; + + // add permissions necessary on Android 15 (API 35) + addEntryToManifest(manifestXmlDoc, 'android.permission.health.READ_HEALTH_DATA_IN_BACKGROUND') + addEntryToPermissionsXML(permissionsXmlDoc, arrayElement, 'android.permission.health.READ_HEALTH_DATA_IN_BACKGROUND') // add permissions to XML document addEntryToManifest(manifestXmlDoc, 'android.permission.POST_NOTIFICATIONS') @@ -291,17 +296,9 @@ function addBackgroundJobPermissionsToManifest(configParser, projectRoot, parser addEntryToManifest(manifestXmlDoc, 'android.permission.HIGH_SAMPLING_RATE_SENSORS') addEntryToManifest(manifestXmlDoc, 'android.permission.SCHEDULE_EXACT_ALARM') - // add permissions necessary on Android 15 (API 35) - addEntryToManifest(manifestXmlDoc, 'android.permission.health.READ_HEALTH_DATA_IN_BACKGROUND') - - const arrayElement = permissionsXmlDoc.getElementsByTagName('array')[0]; - - addEntryToPermissionsXML(permissionsXmlDoc, arrayElement, 'android.permission.health.READ_HEALTH_DATA_IN_BACKGROUND') - // serialize the updated XML documents back to strings const serializer = new XMLSerializer(); const updatedManifestXmlString = serializer.serializeToString(manifestXmlDoc); - const updatedPermissionsXmlString = serializer.serializeToString(permissionsXmlDoc); // write the updated XML strings back to the same files From a1b3f118733febcc20bfe2f6d991f33650a788ac Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Mon, 19 Aug 2024 19:29:04 +0100 Subject: [PATCH 06/13] feat: rest READ_HEALTH_DATA_IN_BACKGROUND permission when setting background job in Android 15 References: https://outsystemsrd.atlassian.net/browse/RMET-3574 --- .../plugins/healthfitness/OSHealthFitness.kt | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/android/com/outsystems/plugins/healthfitness/OSHealthFitness.kt b/src/android/com/outsystems/plugins/healthfitness/OSHealthFitness.kt index 9d787f0..80b55fb 100755 --- a/src/android/com/outsystems/plugins/healthfitness/OSHealthFitness.kt +++ b/src/android/com/outsystems/plugins/healthfitness/OSHealthFitness.kt @@ -306,6 +306,15 @@ class OSHealthFitness : CordovaImplementation() { requestBackgroundJobPermissions() } + private fun requestReadDataBackgroundPermission() { + if (SDK_INT >= 35) { + setAsActivityResultCallback() + healthConnectViewModel.requestReadDataBackgroundPermission(this.getActivity()) + } else { + setBackgroundJobWithParameters(backgroundParameters) + } + } + /** * Sets a background job by calling the setBackgroundJob method of the ViewModel */ @@ -389,6 +398,30 @@ class OSHealthFitness : CordovaImplementation() { override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) { super.onActivityResult(requestCode, resultCode, intent) + + //check if result comes for requesting READ_HEALTH_DATA_IN_BACKGROUND permission + intent?.let { + if (intent.getBooleanExtra(Constants.EXTRA_CONTAINS_READ_DATA_BACKGROUND, false)) { + if (intent.getIntExtra( + Constants.EXTRA_RESULT_PERMISSION_KEY_GLOBAL, + Constants.EXTRA_RESULT_PERMISSION_DENIED + ) == Constants.EXTRA_RESULT_PERMISSION_GRANTED + ) { + setBackgroundJobWithParameters(backgroundParameters) + return + } + sendPluginResult( + null, + Pair( + HealthFitnessError.BACKGROUND_JOB_READ_DATA_PERMISSION_DENIED.code.toString(), + HealthFitnessError.BACKGROUND_JOB_READ_DATA_PERMISSION_DENIED.message + ) + ) + return + } + } + + // if result comes from requesting standard permissions healthConnectViewModel.handleActivityResult(requestCode, resultCode, intent, { sendPluginResult("success", null) @@ -442,7 +475,7 @@ class OSHealthFitness : CordovaImplementation() { return } } - setBackgroundJobWithParameters(backgroundParameters) + requestReadDataBackgroundPermission() } } } From ce27d765ad42935441eec6060f8bc60c9581a50f Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Tue, 20 Aug 2024 11:02:19 +0100 Subject: [PATCH 07/13] chore: update dependency to OSHealthFitnessLib-Android References: https://outsystemsrd.atlassian.net/browse/RMET-3574 --- src/android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/build.gradle b/src/android/build.gradle index a44fb07..402080f 100644 --- a/src/android/build.gradle +++ b/src/android/build.gradle @@ -25,7 +25,7 @@ dependencies{ 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:2.1.1@aar") + implementation("com.github.outsystems:oshealthfitness-android:2.1.2-dev@aar") implementation("com.github.outsystems:osnotificationpermissions-android:0.0.4@aar") // activity From dca5ee3f1a103877a84bc768b7b8bff61c14125a Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Tue, 20 Aug 2024 14:17:46 +0100 Subject: [PATCH 08/13] chore: update dependency to OSHealthFitnessLib-Android References: https://outsystemsrd.atlassian.net/browse/RMET-3574 --- src/android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/build.gradle b/src/android/build.gradle index 402080f..de1e1a7 100644 --- a/src/android/build.gradle +++ b/src/android/build.gradle @@ -25,7 +25,7 @@ dependencies{ 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:2.1.2-dev@aar") + implementation("com.github.outsystems:oshealthfitness-android:2.1.2-dev2@aar") implementation("com.github.outsystems:osnotificationpermissions-android:0.0.4@aar") // activity From 77c138884ce020171f152b5c9c48dee98add2518 Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Tue, 20 Aug 2024 14:58:24 +0100 Subject: [PATCH 09/13] chore: update dependency to OSHealthFitnessLib-Android to version `2.1.2 References: https://outsystemsrd.atlassian.net/browse/RMET-3574 --- src/android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/build.gradle b/src/android/build.gradle index de1e1a7..4a7c453 100644 --- a/src/android/build.gradle +++ b/src/android/build.gradle @@ -25,7 +25,7 @@ dependencies{ 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:2.1.2-dev2@aar") + implementation("com.github.outsystems:oshealthfitness-android:2.1.2@aar") implementation("com.github.outsystems:osnotificationpermissions-android:0.0.4@aar") // activity From c57fead8afdd181bf8b64d41ed5585b016353708 Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Tue, 20 Aug 2024 15:01:25 +0100 Subject: [PATCH 10/13] chore: document function References: https://outsystemsrd.atlassian.net/browse/RMET-3574 --- .../com/outsystems/plugins/healthfitness/OSHealthFitness.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/android/com/outsystems/plugins/healthfitness/OSHealthFitness.kt b/src/android/com/outsystems/plugins/healthfitness/OSHealthFitness.kt index 80b55fb..14377dc 100755 --- a/src/android/com/outsystems/plugins/healthfitness/OSHealthFitness.kt +++ b/src/android/com/outsystems/plugins/healthfitness/OSHealthFitness.kt @@ -306,6 +306,10 @@ class OSHealthFitness : CordovaImplementation() { requestBackgroundJobPermissions() } + /** + * Requests permission to read health data in the background for API 35, + * or calls setBackgroundJobWithParameters otherwise + */ private fun requestReadDataBackgroundPermission() { if (SDK_INT >= 35) { setAsActivityResultCallback() From b7addff54527a59b28a61ab3c9298a3ea277fe3b Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Tue, 20 Aug 2024 15:11:21 +0100 Subject: [PATCH 11/13] chore: update changelog and set plugin version to `2.1.2 References: https://outsystemsrd.atlassian.net/browse/RMET-3574 --- CHANGELOG.md | 4 ++++ package.json | 2 +- plugin.xml | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3baeb09..a3040d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 The changes documented here do not include those from the original repository. +## [2.1.2] + +- Fix: Request `READ_HEALTH_DATA_IN_BACKGROUND` permission for Android 15 when setting a background job (https://outsystemsrd.atlassian.net/browse/RMET-3574). + ## [2.1.1] ### 2024-05-22 diff --git a/package.json b/package.json index 24633c2..cce5d5a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.outsystems.plugins.healthfitness", - "version": "2.1.1", + "version": "2.1.2", "description": "Health & Fitness cordova plugin for OutSystems applications.", "keywords": [ "ecosystem:cordova", diff --git a/plugin.xml b/plugin.xml index fdd9c80..48970f6 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + HealthFitness Health & Fitness cordova plugin for OutSystems applications. OutSystems Inc From e7205b906ade740686b938be42e2e64d42d0f44d Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Wed, 21 Aug 2024 12:38:32 +0100 Subject: [PATCH 12/13] chore: update dependency to OSHealthFitnessLib-Android --- src/android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/build.gradle b/src/android/build.gradle index 4a7c453..909703c 100644 --- a/src/android/build.gradle +++ b/src/android/build.gradle @@ -25,7 +25,7 @@ dependencies{ 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:2.1.2@aar") + implementation("com.github.outsystems:oshealthfitness-android:2.1.2-dev3@aar") implementation("com.github.outsystems:osnotificationpermissions-android:0.0.4@aar") // activity From a2411f090cfe34c2f70e460dd5654d4d33e92bae Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Wed, 21 Aug 2024 13:02:44 +0100 Subject: [PATCH 13/13] Revert "chore: update dependency to OSHealthFitnessLib-Android" This reverts commit e7205b906ade740686b938be42e2e64d42d0f44d. --- src/android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/build.gradle b/src/android/build.gradle index 909703c..4a7c453 100644 --- a/src/android/build.gradle +++ b/src/android/build.gradle @@ -25,7 +25,7 @@ dependencies{ 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:2.1.2-dev3@aar") + implementation("com.github.outsystems:oshealthfitness-android:2.1.2@aar") implementation("com.github.outsystems:osnotificationpermissions-android:0.0.4@aar") // activity