Skip to content

Commit

Permalink
RMET-3406 ::: Android ::: Add More Verifications for Privacy Policy F…
Browse files Browse the repository at this point in the history
…ile (#139)

* fix: Compare file with extension

Include the file extension on the `policyFileExists` method.
Remove some redundant code.

References: https://outsystemsrd.atlassian.net/browse/RMET-3406

* fix: ODC caveat

Since ODC adds some text between the file name and extension, add some log to validate that the file starts with the file name and ends with the 'txt' format.

References: https://outsystemsrd.atlassian.net/browse/RMET-3406

* chore: Add CHANGELOG

References: https://outsystemsrd.atlassian.net/browse/RMET-3406
  • Loading branch information
OS-ricardomoreirasilva authored May 20, 2024
1 parent d0939dc commit c876ff5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The changes documented here do not include those from the original repository.

## [2.1.0]

- Fix: Add format verification for Android's Privacy Policy file (https://outsystemsrd.atlassian.net/browse/RMET-3406).
- Feat: Implemented support for `OxygenSaturation` variable when using requestPermissions, advancedQuery, getHealthData, and background jobs (https://outsystemsrd.atlassian.net/browse/RMET-3363).

## [2.0.1]
Expand Down
19 changes: 12 additions & 7 deletions hooks/androidCopyPrivacyUrlEnv.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ const path = require('path');
const { ConfigParser } = require('cordova-common');
const et = require('elementtree');
const { fileExists } = require('./utils');

let fileNamePrivacyPolicy = "HealthConnect_PrivacyPolicy.txt";
let mainFolder = "platforms/android/app/src/main/";

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}`);
const directoryPath = path.join(projectRoot, mainFolder);
const platformPath = path.join(directoryPath, `assets/www/${fileNamePrivacyPolicy}`);

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

Expand All @@ -27,7 +30,7 @@ function setPrivacyPolicyUrl(configParser, projectRoot) {

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

Expand All @@ -43,12 +46,14 @@ function setPrivacyPolicyUrl(configParser, projectRoot) {
}
}

function policyFileExists() {
const directoryPath = 'platforms/android/app/src/main/assets/www';
const searchString = 'HealthConnect_PrivacyPolicy';
function policyFileExists(platformPath) {
const directoryPath = path.join(platformPath, 'assets/www');
// splits the file in name & format.
const searchStrings = fileNamePrivacyPolicy.split('.');

try {
const files = fs.readdirSync(directoryPath);
const matchingFiles = files.filter(fileName => fileName.includes(searchString));
const matchingFiles = files.filter(fileName => fileName.startsWith(searchStrings[0]) && fileName.endsWith(searchStrings[1]));

// return true if there are matching files, false otherwise
return matchingFiles.length > 0;
Expand Down

0 comments on commit c876ff5

Please sign in to comment.