Skip to content

Commit

Permalink
Merge pull request #145 from OutSystems/development
Browse files Browse the repository at this point in the history
RMET-3574 - Prepare to release version `2.1.2`
  • Loading branch information
alexgerardojacinto authored Aug 21, 2024
2 parents ab94cca + 3195653 commit e98f02f
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions hooks/androidCopyPreferencesPermissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,17 @@ 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(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')
addEntryToManifest(manifestXmlDoc, 'android.permission.ACTIVITY_RECOGNITION')
Expand All @@ -285,12 +296,14 @@ function addBackgroundJobPermissionsToManifest(configParser, projectRoot, parser
addEntryToManifest(manifestXmlDoc, 'android.permission.HIGH_SAMPLING_RATE_SENSORS')
addEntryToManifest(manifestXmlDoc, 'android.permission.SCHEDULE_EXACT_ALARM')

// 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);
const updatedPermissionsXmlString = serializer.serializeToString(permissionsXmlDoc);

// write the updated XML string back to the same file
// write the updated XML strings back to the same files
fs.writeFileSync(manifestFilePath, updatedManifestXmlString, 'utf-8');
fs.writeFileSync(permissionsXmlFilePath, updatedPermissionsXmlString, 'utf-8');
}

}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<plugin id="com.outsystems.plugins.healthfitness" version="2.1.1" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<plugin id="com.outsystems.plugins.healthfitness" version="2.1.2" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>HealthFitness</name>
<description>Health &amp; Fitness cordova plugin for OutSystems applications.</description>
<author>OutSystems Inc</author>
Expand Down
2 changes: 1 addition & 1 deletion src/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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@aar")
implementation("com.github.outsystems:osnotificationpermissions-android:0.0.4@aar")

// activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,19 @@ 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()
healthConnectViewModel.requestReadDataBackgroundPermission(this.getActivity())
} else {
setBackgroundJobWithParameters(backgroundParameters)
}
}

/**
* Sets a background job by calling the setBackgroundJob method of the ViewModel
*/
Expand Down Expand Up @@ -389,6 +402,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)
Expand Down Expand Up @@ -442,7 +479,7 @@ class OSHealthFitness : CordovaImplementation() {
return
}
}
setBackgroundJobWithParameters(backgroundParameters)
requestReadDataBackgroundPermission()
}
}
}
Expand Down

0 comments on commit e98f02f

Please sign in to comment.