From b81804a835681e51a7fda8fb17cb4a1afabf8375 Mon Sep 17 00:00:00 2001 From: "K. Shankari" Date: Fri, 6 Sep 2024 15:04:21 -0700 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=90=9B=20Re-enable=20"Download=20JSON?= =?UTF-8?q?=20dump"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After the giant refactor, both "email log" and "download JSON dump" were broken. We fixed "email log" in https://github.com/e-mission/e-mission-phone/pull/1160 but didn't fix "Download JSON dump then, because of lack of time. This fixes the "Download JSON dump" as well by making it similar to implementation in "email log". It was already fairly similar, but for some reason, was reading the data before sharing the file ``` const reader = new FileReader(); reader.onloadend = () => { const readResult = this.result as string; logDebug(`Successfull file read with ${readResult.length} characters`); ``` and "this" doesn't exist, resulting in an undefined error. Since the shareObj takes in a file name anyway, I just made this similar to the emailLog changes by passing in the filename directly. Also, similar ot the "Email Log", added a `.txt` extension so that the file can be sent on iOS. Testing done: - Before this change: clicking on "Download JSON dump" did not do anything - After this change: clicking on "Download JSON dump" launched the share menu I haven't actually tried sharing yet because gmail is not configured on the emulator. --- www/js/services/controlHelper.ts | 79 ++++++++++++++------------------ 1 file changed, 35 insertions(+), 44 deletions(-) diff --git a/www/js/services/controlHelper.ts b/www/js/services/controlHelper.ts index da2e60ed7..9334ee318 100644 --- a/www/js/services/controlHelper.ts +++ b/www/js/services/controlHelper.ts @@ -39,48 +39,38 @@ export function getMyDataHelpers(fileName: string, startTimeString: string, endT function localShareData() { return new Promise((resolve, reject) => { window['resolveLocalFileSystemURL'](window['cordova'].file.cacheDirectory, (fs) => { - fs.filesystem.root.getFile(fileName, null, (fileEntry) => { - logDebug(`fileEntry ${fileEntry.nativeURL} is file? ${fileEntry.isFile.toString()}`); - fileEntry.file( - (file) => { - const reader = new FileReader(); - - reader.onloadend = () => { - const readResult = this.result as string; - logDebug(`Successfull file read with ${readResult.length} characters`); - const dataArray = JSON.parse(readResult); - logDebug(`Successfully read resultList of size ${dataArray.length}`); - let attachFile = fileEntry.nativeURL; - const shareObj = { - files: [attachFile], - message: i18next.t( - 'shareFile-service.send-data.body-data-consists-of-list-of-entries', - ), - subject: i18next.t('shareFile-service.send-data.subject-data-dump-from-to', { - start: startTimeString, - end: endTimeString, - }), - }; - window['plugins'].socialsharing.shareWithOptions( - shareObj, - (result) => { - logDebug(`Share Completed? ${result.completed}`); // On Android, most likely returns false - logDebug(`Shared to app: ${result.app}`); - resolve(); - }, - (msg) => { - logDebug(`Sharing failed with message ${msg}`); - }, - ); - }; - reader.readAsText(file); - }, - (error) => { - displayError(error, 'Error while downloading JSON dump'); - reject(error); - }, - ); - }); + fs.filesystem.root.getFile( + fileName, + null, + (fileEntry) => { + logDebug(`fileEntry ${fileEntry.nativeURL} is file? ${fileEntry.isFile.toString()}`); + const shareObj = { + files: [fileEntry.nativeURL], + message: i18next.t( + 'shareFile-service.send-data.body-data-consists-of-list-of-entries', + ), + subject: i18next.t('shareFile-service.send-data.subject-data-dump-from-to', { + start: startTimeString, + end: endTimeString, + }), + }; + window['plugins'].socialsharing.shareWithOptions( + shareObj, + (result) => { + logDebug(`Share Completed? ${result.completed}`); // On Android, most likely returns false + logDebug(`Shared to app: ${result.app}`); + resolve(); + }, + (error) => { + displayError(error, `Sharing failed with message`); + }, + ); + }, + (error) => { + displayError(error, 'Error while downloading JSON dump'); + reject(error); + }, + ); }); }); } @@ -117,7 +107,7 @@ export function getMyDataHelpers(fileName: string, startTimeString: string, endT * getMyData fetches timeline data for a given day, and then gives the user a prompt to share the data * @param timeStamp initial timestamp of the timeline to be fetched. */ -export function getMyData(timeStamp: Date) { +export async function getMyData(timeStamp: Date) { // We are only retrieving data for a single day to avoid // running out of memory on the phone const endTime = DateTime.fromJSDate(timeStamp); @@ -125,7 +115,8 @@ export function getMyData(timeStamp: Date) { const startTimeString = startTime.toFormat("yyyy'-'MM'-'dd"); const endTimeString = endTime.toFormat("yyyy'-'MM'-'dd"); - const dumpFile = startTimeString + '.' + endTimeString + '.timeline'; + // let's rename this to .txt so that we can email it on iPhones + const dumpFile = startTimeString + '.' + endTimeString + '.timeline.txt'; alert(`Going to retrieve data to ${dumpFile}`); const getDataMethods = getMyDataHelpers(dumpFile, startTimeString, endTimeString); From 1de8f78a5507890f39bfac979c05844d3a5a82d8 Mon Sep 17 00:00:00 2001 From: "K. Shankari" Date: Fri, 6 Sep 2024 17:47:18 -0700 Subject: [PATCH 2/3] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20=20Fix=20the=20"spurio?= =?UTF-8?q?us=20fleet=20trips"=20by=20updating=20the=20plugin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this fix, we checked for fleet status only in the EXITED_GEOFENCE case. This meant that the VISIT transitions started trip tracking, which led to spurious trips. Fixed by adding a fleet check to this case as well. Related PR: https://github.com/e-mission/e-mission-data-collection/pull/234 Related release: https://github.com/e-mission/e-mission-data-collection/releases/tag/v1.9.0 --- package.cordovabuild.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.cordovabuild.json b/package.cordovabuild.json index d6f0ba462..6f44bb60d 100644 --- a/package.cordovabuild.json +++ b/package.cordovabuild.json @@ -120,7 +120,7 @@ "cordova-plugin-app-version": "0.1.14", "cordova-plugin-customurlscheme": "5.0.2", "cordova-plugin-device": "2.1.0", - "cordova-plugin-em-datacollection": "git+https://github.com/e-mission/e-mission-data-collection.git#v1.8.9", + "cordova-plugin-em-datacollection": "git+https://github.com/e-mission/e-mission-data-collection.git#v1.9.0", "cordova-plugin-em-opcodeauth": "git+https://github.com/e-mission/cordova-jwt-auth.git#v1.7.2", "cordova-plugin-em-server-communication": "git+https://github.com/e-mission/cordova-server-communication.git#v1.2.7", "cordova-plugin-em-serversync": "git+https://github.com/e-mission/cordova-server-sync.git#v1.3.3", From 3b6ecd5fda65ac8cae2bf9127a0789cc7fadb3c2 Mon Sep 17 00:00:00 2001 From: "K. Shankari" Date: Fri, 6 Sep 2024 18:19:04 -0700 Subject: [PATCH 3/3] =?UTF-8?q?Revert=20"=F0=9F=94=A5=20Remove=20the=20man?= =?UTF-8?q?ual=20gradle=20installation"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 399e9e7a4f83ed7d67fbf2e249179fa073cfec68. I _thought_ this wasn't needed because cordova configures `build.gradle` so that the correct version of gradle is downloaded and installed on the first run. However, when I tried to rebuild on a fresh installation, I got the following error ``` Using Android SDK: /Users/kshankar/Library/Android/sdk Could not find an installed version of Gradle either in Android Studio, or on your system to install the gradle wrapper. Please include gradle in your path, or install Android Studio ``` It looks like although cordova installs gradle, the system needs to have a version of gradle installed as well to bootstrap the gradle wrapper. This error doesn't show up in the CI/CD pipeline because the CI environment has gradle installed. @catarial did you encounter this during your setup as well?! Or maybe it has not been an issue so far because you are focused on the iOS build. --- setup/activate_native.sh | 3 +++ setup/export_shared_dep_versions.sh | 1 + setup/setup_android_native.sh | 15 +++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/setup/activate_native.sh b/setup/activate_native.sh index 21e8f7566..c1014c987 100644 --- a/setup/activate_native.sh +++ b/setup/activate_native.sh @@ -10,6 +10,9 @@ then echo "ANDROID_HOME and ANDROID_SDK_ROOT not set, android SDK not found" fi +echo "Activating sdkman, and by default, gradle" +source ~/.sdkman/bin/sdkman-init.sh + echo "Ensuring that we use the most recent version of the command line tools" export PATH=$ANDROID_SDK_ROOT/cmdline-tools/latest/bin:$ANDROID_SDK_ROOT/emulator:$PATH diff --git a/setup/export_shared_dep_versions.sh b/setup/export_shared_dep_versions.sh index 49d062a8b..acc974c1d 100644 --- a/setup/export_shared_dep_versions.sh +++ b/setup/export_shared_dep_versions.sh @@ -6,6 +6,7 @@ export NODE_VERSION=20.9.0 # Looks like brew supports only major and minor, not patch version export RUBY_VERSION=3.0 export COCOAPODS_VERSION=1.15.2 +export GRADLE_VERSION=8.10 export OSX_EXP_VERSION=12 export NVM_DIR="$HOME/.nvm" diff --git a/setup/setup_android_native.sh b/setup/setup_android_native.sh index 3dfd5279e..95dc9222e 100644 --- a/setup/setup_android_native.sh +++ b/setup/setup_android_native.sh @@ -27,4 +27,19 @@ else echo "ANDROID_HOME = $ANDROID_HOME; ANDROID_SDK_ROOT=$ANDROID_SDK_ROOT" fi +echo "Setting up sdkman" +curl -s "https://get.sdkman.io" | bash +source ~/.sdkman/bin/sdkman-init.sh + +CURR_GRADLE_VER=`sdk current gradle | cut -d " " -f 4 | xargs` + +echo "CURR_GRADLE_VER = '$CURR_GRADLE_VER', expected $GRADLE_VERSION" + +if [[ $CURR_GRADLE_VER == $GRADLE_VERSION ]]; then + echo "Already have gradle version $GRADLE_VERSION" +else + echo "Setting up gradle using SDKMan" + sdk install gradle $GRADLE_VERSION +fi + source setup/setup_shared_native.sh