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

RMET-3145:::Show app's privacy policy dialog #105

Merged
merged 4 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ The changes documented here do not include those from the original repository.

## [Unreleased]

## 2024-02-26
- Implemented `Show app's privacy policy dialog` (https://outsystemsrd.atlassian.net/browse/RMET-3145).

## 2024-02-23
- Re-implement `DeleteBackgroundJob` feature (https://outsystemsrd.atlassian.net/browse/RMET-3068).

Expand Down
45 changes: 45 additions & 0 deletions hooks/androidCopyPrivacyUrlEnv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"use strict";

const fs = require('fs');
const path = require('path');
const { ConfigParser } = require('cordova-common');
const et = require('elementtree');
const { fileExists } = require('./utils');
let fileNamePrivacyPolicy = "HealthConnect_PrivacyPolicy.txt";

module.exports = async function (context) {
const projectRoot = context.opts.cordova.project ? context.opts.cordova.project.root : context.opts.projectRoot;
const platformPath = path.join(projectRoot, `platforms/android/app/src/main/assets/www/${fileNamePrivacyPolicy}`);

if (fileExists(platformPath)) {
const configXML = path.join(projectRoot, 'config.xml');
const configParser = new ConfigParser(configXML);

setPrivacyPolicyUrl(configParser, projectRoot);
} else {
throw new Error("Privacy Policy file not found in the resources folder.");
}
};

function setPrivacyPolicyUrl(configParser, projectRoot) {
const hostname = configParser.getPreference('hostname', 'android');
const applicationNameUrl = configParser.getPreference('DefaultApplicationURL', 'android');

if (hostname && applicationNameUrl) {
const url = `https://${hostname}/${applicationNameUrl}/${fileNamePrivacyPolicy}`;
const stringsPath = path.join(projectRoot, 'platforms/android/app/src/main/res/values/strings.xml');
const stringsFile = fs.readFileSync(stringsPath).toString();
const etreeStrings = et.parse(stringsFile);

let privacyPolicyUrl = etreeStrings.find('./string[@name="privacy_policy_url"]');
if (!privacyPolicyUrl) {
console.error('Privacy policy URL string not found in strings.xml');
return;
}
privacyPolicyUrl.text = url;
const resultXmlStrings = etreeStrings.write({method: 'xml'});
fs.writeFileSync(stringsPath, resultXmlStrings);
} else {
throw new Error("Error getting the environment variables.");
}
}
11 changes: 11 additions & 0 deletions hooks/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"use strict"

var fs = require("fs");

function fileExists(filePath) {
return fs.existsSync(filePath);
}

module.exports = {
fileExists
};
6 changes: 6 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
</js-module>
<platform name="android">

<hook type="after_prepare" src="hooks/androidCopyPrivacyUrlEnv.js"/>

<config-file parent="/*" target="res/xml/config.xml">
<feature name="OSHealthFitness">
<param name="android-package" value="com.outsystems.plugins.healthfitness.OSHealthFitness"/>
Expand All @@ -18,6 +20,10 @@
<preference name="AndroidXEnabled" value="true"/>
</config-file>

<config-file parent="/*" target="res/values/strings.xml">
<string name="privacy_policy_url">PRIVACY_POLICY_URL</string>
</config-file>

<config-file parent="/*" target="AndroidManifest.xml">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
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:1.2.0@aar")
implementation("com.github.outsystems:oshealthfitness-android:1.2.0.13@aar")
implementation("com.github.outsystems:oshealthfitness-android:1.2.0.18@aar")
implementation("com.github.outsystems:osnotificationpermissions-android:0.0.4@aar")

def roomVersion = "2.4.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class OSHealthFitness : CordovaImplementation() {
gson.fromJson(args.getString(2), HealthFitnessGroupPermission::class.java),
gson.fromJson(args.getString(3), HealthFitnessGroupPermission::class.java),
gson.fromJson(args.getString(4), HealthFitnessGroupPermission::class.java),
privacyPolicyUrl = getActivity().resources.getString(getActivity().resources.getIdentifier("privacy_policy_url", "string", getActivity().packageName)),
{
setAsActivityResultCallback()
},
Expand Down
Loading