From d8dfcae3265c915deaecd2cde9041b8e9d902545 Mon Sep 17 00:00:00 2001 From: "K. Shankari" Date: Sun, 12 Mar 2023 11:44:47 -0700 Subject: [PATCH 1/8] Update instructions for android 12 And change the existing instructions to only apply to android 11 --- www/i18n/en.json | 3 ++- www/js/appstatus/permissioncheck.js | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/www/i18n/en.json b/www/i18n/en.json index 08732d04d..137d46454 100644 --- a/www/i18n/en.json +++ b/www/i18n/en.json @@ -347,7 +347,8 @@ "android-lt-6": "Enabled during app installation.", "android-6-9": "Please select 'allow'", "android-10": "Please select 'Allow all the time'", - "android-gte-11": "On the app settings page, choose the 'Location' permission and set it to 'Allow all the time'", + "android-11": "On the app settings page, choose the 'Location' permission and set it to 'Allow all the time'", + "android-gte-12": "On the app settings page, choose the 'Location' permission and set it to 'Allow all the time' and 'Precise'", "ios-lt-13": "Please select 'Always allow'", "ios-gte-13": "On the app settings page, please select 'Always' and 'Precise' and return here to continue" } diff --git a/www/js/appstatus/permissioncheck.js b/www/js/appstatus/permissioncheck.js index dfe136343..293144693 100644 --- a/www/js/appstatus/permissioncheck.js +++ b/www/js/appstatus/permissioncheck.js @@ -171,13 +171,15 @@ controller("PermissionCheckControl", function($scope, $element, $attrs, if (version < 9) { androidSettingsDescTag = "intro.appstatus.locsettings.description.android-lt-9"; } - var androidPermDescTag = "intro.appstatus.locperms.description.android-gte-11"; + var androidPermDescTag = "intro.appstatus.locperms.description.android-gte-12"; if($scope.osver < 6) { androidPermDescTag = 'intro.appstatus.locperms.description.android-lt-6'; } else if ($scope.osver < 10) { androidPermDescTag = "intro.appstatus.locperms.description.android-6-9"; } else if ($scope.osver < 11) { androidPermDescTag= "intro.appstatus.locperms.description.android-10"; + } else if ($scope.osver < 12) { + androidPermDescTag= "intro.appstatus.locperms.description.android-11"; } console.log("description tags are "+androidSettingsDescTag+" "+androidPermDescTag); // location settings From d83c667cf5619c02d59cac1fe2f84617ea269674 Mon Sep 17 00:00:00 2001 From: "K. Shankari" Date: Mon, 13 Mar 2023 18:47:29 -0700 Subject: [PATCH 2/8] Bump up the SDK versions + switch to android12 versions of plugins Bump up the minSDK to API 23 (Marshmallow, Android 6) - I am not sure why this was API 22; we are certainly not testing on that version Bump the targetSDK to API 32, android 12 (required for Google Play) Switch the push and local notification plugins to ones that support the new trampoline functionality https://developer.android.com/about/versions/12/behavior-changes-12#notification-trampolines The push plugin is a "dev" version but seems to have all android fixes It also bumps up the iOS version so that we can avoid the "non-public selectors" error https://github.com/havesource/cordova-plugin-push/issues/106 https://github.com/e-mission/e-mission-docs/issues/838#issuecomment-1465467430 The push plugin had kotlin build errors that were fixed by adding the gradle preferences https://github.com/havesource/cordova-plugin-push/issues/218#issuecomment-1453983584 The local notification is a new fork maintained by a new author which requires us to add the new `AndroidLaunchMode` preference. The new plugins already have the compile -> implementation fix So removing the hook added in 6de1f4cd26ce79f1326f8a3c0f861c1385c67466 Testing done: - builds - generated a local notification by turning off location permissions - clicking on the notification opened the status screen --- config.cordovabuild.xml | 8 +-- .../android_change_compile_implementation.js | 54 ------------------- package.cordovabuild.json | 18 ++++--- 3 files changed, 16 insertions(+), 64 deletions(-) delete mode 100755 hooks/before_build/android/android_change_compile_implementation.js diff --git a/config.cordovabuild.xml b/config.cordovabuild.xml index 18e08aa21..1bfecc184 100644 --- a/config.cordovabuild.xml +++ b/config.cordovabuild.xml @@ -45,12 +45,14 @@ - - + + + + + - diff --git a/hooks/before_build/android/android_change_compile_implementation.js b/hooks/before_build/android/android_change_compile_implementation.js deleted file mode 100755 index b77d16175..000000000 --- a/hooks/before_build/android/android_change_compile_implementation.js +++ /dev/null @@ -1,54 +0,0 @@ -/* - * A hook to change provider in order to match with the application name. - */ - -var fs = require('fs'); -var path = require('path'); -var et = require('elementtree'); - -const PROVIDER = "edu.berkeley.eecs.emission.provider"; -const ACCOUNT_TYPE = "eecs.berkeley.edu"; -const LOG_NAME = "Changing Providers: "; - -var changeCompileToImplementation = function (file) { - if (fs.existsSync(file)) { - fs.readFile(file, 'utf8', function (err, data) { - var result = data.replace("compile", "implementation"); - fs.writeFile(file, result, 'utf8', function (err) { - if (err) throw new Error(LOG_NAME + 'Unable to write into ' + file + ': ' + err); - console.log(LOG_NAME + "" + file + " updated...") - }); - }); - } else { - console.error("Could not find file "+file+" skipping compile -> implementation change"); - } -} - -module.exports = function (context) { - // If Android platform is not installed, don't even execute - if (!context.opts.platforms.includes('android')) return; - - var config_xml = path.join(context.opts.projectRoot, 'config.xml'); - var data = fs.readFileSync(config_xml).toString(); - // If no data then no config.xml - if (data) { - var etree = et.parse(data); - console.log(LOG_NAME + "Retrieving application name...") - var applicationName = etree._root.attrib.id; - console.info(LOG_NAME + "Your application is " + applicationName); - const splitParts = applicationName.split(".") - var lastApplicationPart = splitParts[splitParts.length - 1]; - - var platformRoot = path.join(context.opts.projectRoot, 'platforms/android/') - - console.log(LOG_NAME + "Updating barcode scanner gradle..."); - var gradleFile = path.join(platformRoot, 'phonegap-plugin-barcodescanner/'+lastApplicationPart+'-barcodescanner.gradle'); - changeCompileToImplementation(gradleFile); - - console.log(LOG_NAME + "Updating badge gradle..."); - var gradleFile = path.join(platformRoot, 'cordova-plugin-badge/'+lastApplicationPart+'-badge.gradle'); - changeCompileToImplementation(gradleFile); - } else { - throw new Error(LOG_NAME + "Could not retrieve application name."); - } -} diff --git a/package.cordovabuild.json b/package.cordovabuild.json index ea6ebb691..cc62df422 100644 --- a/package.cordovabuild.json +++ b/package.cordovabuild.json @@ -20,8 +20,8 @@ "plugins": { "@havesource/cordova-plugin-push": { "ANDROIDX_CORE_VERSION": "1.6.+", - "FCM_VERSION": "18.+", - "IOS_FIREBASE_MESSAGING_VERSION": "~> 6.32.2" + "FCM_VERSION": "23.+", + "IOS_FIREBASE_MESSAGING_VERSION": "~> 8.1.1" }, "cordova-plugin-ionic-keyboard": {}, "cordova-plugin-app-version": {}, @@ -39,7 +39,11 @@ "PHOTO_LIBRARY_USAGE_DESCRIPTION": "This app requires photo library access to share photos on social media." }, "cordova-plugin-inappbrowser": {}, - "cordova-plugin-local-notification": {}, + "cordova-plugin-local-notification-12": { + "ANDROID_SUPPORT_V4_VERSION": "26.+", + "ANDROIDX_VERSION": "1.2.0", + "ANDROIDX_APPCOMPAT_VERSION": "1.3.1" + }, "cordova-plugin-advanced-http": {}, "cordova-plugin-ionic-webview": { "ANDROID_SUPPORT_ANNOTATIONS_VERSION": "27.+" @@ -47,8 +51,8 @@ "cordova-plugin-em-opcodeauth": {}, "cordova-plugin-em-server-communication": {}, "cordova-plugin-em-datacollection": { - "LOCATION_VERSION": "18.0.0", - "ANDROIDX_CORE_VERSION": "1.7.0", + "LOCATION_VERSION": "21.0.1", + "ANDROIDX_CORE_VERSION": "1.8.0", "ANDROIDX_WORK_VERSION": "2.7.1" }, "cordova-plugin-em-serversync": {}, @@ -79,11 +83,11 @@ "cordova-plugin-inappbrowser": "5.0.0", "cordova-plugin-ionic-keyboard": "2.2.0", "cordova-plugin-ionic-webview": "5.0.0", - "cordova-plugin-local-notification": "https://github.com/levanax/cordova-plugin-local-notifications.git#0362bc731a3f2241acadcc6a0cc63776806e851c", + "cordova-plugin-local-notification-12": "0.1.4", "cordova-plugin-x-socialsharing": "6.0.4", "fs-extra": "^9.0.1", "klaw-sync": "^6.0.0", "phonegap-plugin-barcodescanner": "git+https://github.com/phonegap/phonegap-plugin-barcodescanner#v8.1.0", - "@havesource/cordova-plugin-push": "3.0.1" + "@havesource/cordova-plugin-push": "git+https://github.com/havesource/cordova-plugin-push.git#4.0.0-dev.0" } } From a8ca751e3e9487a7f1815de1c3522fb8ec7648f3 Mon Sep 17 00:00:00 2001 From: "K. Shankari" Date: Mon, 13 Mar 2023 19:21:33 -0700 Subject: [PATCH 3/8] Upgrade the QR code scanner to an android12 compatible one as well To avoid reintroducing the hook after the following failure ``` * Where: See https://docs.gradle.org/7.4.2/userguide/command_line_interface.html#sec:command_line_warnings Script '/Users/runner/work/e-mission-phone/e-mission-phone/platforms/android/phonegap-plugin-barcodescanner/emission-barcodescanner.gradle' line: 9 * What went wrong: A problem occurred evaluating script. > Could not find method compile() for arguments [{name=barcodescanner-release-2.1.5, ext=aar}] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. ``` --- package.cordovabuild.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.cordovabuild.json b/package.cordovabuild.json index cc62df422..213dcf806 100644 --- a/package.cordovabuild.json +++ b/package.cordovabuild.json @@ -60,7 +60,7 @@ "cordova-plugin-em-unifiedlogger": {}, "cordova-plugin-em-usercache": {}, "cordova-plugin-androidx-adapter": {}, - "phonegap-plugin-barcodescanner": {} + "cordova-plugin-barcode-qrscanner": {} } }, "dependencies": { @@ -87,7 +87,7 @@ "cordova-plugin-x-socialsharing": "6.0.4", "fs-extra": "^9.0.1", "klaw-sync": "^6.0.0", - "phonegap-plugin-barcodescanner": "git+https://github.com/phonegap/phonegap-plugin-barcodescanner#v8.1.0", + "cordova-plugin-barcode-qrscanner": "^3.0.12", "@havesource/cordova-plugin-push": "git+https://github.com/havesource/cordova-plugin-push.git#4.0.0-dev.0" } } From 7901a28ba01b8fd5de0935dc3470b0c88f48fc05 Mon Sep 17 00:00:00 2001 From: "K. Shankari" Date: Mon, 13 Mar 2023 19:41:49 -0700 Subject: [PATCH 4/8] Bump up the number of expected plugins to 24 The new QR code scanning plugin that we added in a8ca751e3e9487a7f1815de1c3522fb8ec7648f3 had a dependency on `cordova-plugin-add-swift-support` --- setup/setup_shared_native.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/setup_shared_native.sh b/setup/setup_shared_native.sh index 382289001..22f7ca72a 100644 --- a/setup/setup_shared_native.sh +++ b/setup/setup_shared_native.sh @@ -26,7 +26,7 @@ sed -i -e "s|/usr/bin/env node|/usr/bin/env node --unhandled-rejections=strict|" npx cordova prepare -EXPECTED_COUNT=23 +EXPECTED_COUNT=24 INSTALLED_COUNT=`npx cordova plugin list | wc -l` echo "Found $INSTALLED_COUNT plugins, expected $EXPECTED_COUNT" if [ $INSTALLED_COUNT -lt $EXPECTED_COUNT ]; From 46af183bc31ae4649bbf095f6fc7bea5b6b4b43a Mon Sep 17 00:00:00 2001 From: "K. Shankari" Date: Thu, 16 Mar 2023 20:26:10 -0700 Subject: [PATCH 5/8] Add support to turn off background optimizations for the app This is a companion commit to https://github.com/e-mission/e-mission-data-collection/pull/202/commits/60f6fa4b4e1f47c0d082f9179635de8a7b7c01a8 from https://github.com/e-mission/e-mission-data-collection/pull/202 This allows us to start foreground services from the background Which allows us to keep our original model and kick the can down the road e-mission/e-mission-docs#838 (comment) I have explored options to do it the right way, but am concerned about testing overhead given our short time frame. This change: - adds interface functions to check and fix battery optimizations - implements the check with the powermanager call - implements the fix by launching the optimization window Testing done: - Turn off the data optimizations - Kill the app (including the foreground service) using adb https://github.com/e-mission/e-mission-docs/issues/838#issuecomment-1471157824 - Send the initialize transition using adb - Foreground service is restarted https://github.com/e-mission/e-mission-docs/issues/838#issuecomment-1471220105 --- www/i18n/en.json | 10 +++++++++- www/js/appstatus/permissioncheck.js | 24 ++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/www/i18n/en.json b/www/i18n/en.json index 137d46454..c2a793e0c 100644 --- a/www/i18n/en.json +++ b/www/i18n/en.json @@ -379,7 +379,15 @@ "unusedapprestrict": { "name": "Unused apps disabled", "description": { - "android-disable": "On the app settings page, go to 'Permissions' and ensure that the app permissions will not be automatically reset.", + "android-disable-lt-12": "On the app settings page, go to 'Permissions' and ensure that the app permissions will not be automatically reset.", + "android-disable-gte-12": "On the app settings page, turn off 'Remove permissions and free up space.'", + "ios": "Please allow." + } + }, + "ignorebatteryopt": { + "name": "Ignore battery optimizations", + "description": { + "android-disable": "On the optimization page, go to all apps, search for this app and turn off optimizations.", "ios": "Please allow." } } diff --git a/www/js/appstatus/permissioncheck.js b/www/js/appstatus/permissioncheck.js index 293144693..f39b4af82 100644 --- a/www/js/appstatus/permissioncheck.js +++ b/www/js/appstatus/permissioncheck.js @@ -329,13 +329,33 @@ controller("PermissionCheckControl", function($scope, $element, $attrs, return checkOrFix(unusedAppsUnrestrictedCheck, $window.cordova.plugins.BEMDataCollection.isUnusedAppUnrestricted, $scope.recomputeBackgroundRestrictionStatus, showError=false); }; + let fixBatteryOpt = function() { + console.log("fix and refresh battery optimization permissions"); + return checkOrFix(ignoreBatteryOptCheck, $window.cordova.plugins.BEMDataCollection.fixIgnoreBatteryOptimizations, + $scope.recomputeBackgroundRestrictionStatus, showError=true); + }; + let checkBatteryOpt = function() { + console.log("fix and refresh battery optimization permissions"); + return checkOrFix(ignoreBatteryOptCheck, $window.cordova.plugins.BEMDataCollection.isIgnoreBatteryOptimizations, + $scope.recomputeBackgroundRestrictionStatus, showError=false); + }; + var androidUnusedDescTag = "intro.appstatus.unusedapprestrict.description.android-disable-gte-12"; + if ($scope.osver < 12) { + androidUnusedDescTag= "intro.appstatus.unusedapprestrict.description.android-disable-lt-12"; + } let unusedAppsUnrestrictedCheck = { name: $translate.instant("intro.appstatus.unusedapprestrict.name"), - desc: $translate.instant("intro.appstatus.unusedapprestrict.description.android-disable"), + desc: $translate.instant(androidUnusedDescTag), fix: fixPerms, refresh: checkPerms } - $scope.backgroundRestrictionChecks = [unusedAppsUnrestrictedCheck]; + let ignoreBatteryOptCheck = { + name: $translate.instant("intro.appstatus.ignorebatteryopt.name"), + desc: $translate.instant("intro.appstatus.ignorebatteryopt.description.android-disable"), + fix: fixBatteryOpt, + refresh: checkBatteryOpt + } + $scope.backgroundRestrictionChecks = [unusedAppsUnrestrictedCheck, ignoreBatteryOptCheck]; refreshChecks($scope.backgroundRestrictionChecks, $scope.recomputeBackgroundRestrictionStatus); } From 763fa2b0c11527b06550397c1da667a58b00722a Mon Sep 17 00:00:00 2001 From: "K. Shankari" Date: Thu, 16 Mar 2023 20:26:40 -0700 Subject: [PATCH 6/8] Add a couple of rootable system images to the list The `google_apis_playstore` images are signed and cannot be rooted If we want to send broadcast messages using adb for testing, we need root support https://github.com/e-mission/e-mission-docs/issues/838#issuecomment-1471220105 Add a couple of rootable system images as well so we can test appropriately --- setup/android_sdk_packages | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup/android_sdk_packages b/setup/android_sdk_packages index e6237520c..5d3f6737b 100644 --- a/setup/android_sdk_packages +++ b/setup/android_sdk_packages @@ -20,5 +20,7 @@ system-images;android-28;google_apis_playstore;x86_64 system-images;android-29;google_apis_playstore;x86_64 system-images;android-30;google_apis_playstore;x86_64 system-images;android-31;google_apis_playstore;x86_64 +system-images;android-32;google_apis;x86_64 system-images;android-32;google_apis_playstore;x86_64 +system-images;android-33;google_apis;x86_64 system-images;android-33;google_apis_playstore;x86_64 From 994c1c8086f7f51819214d0ac85e445e293a1ac9 Mon Sep 17 00:00:00 2001 From: "K. Shankari" Date: Thu, 16 Mar 2023 20:34:01 -0700 Subject: [PATCH 7/8] Bump up the version numbers Since this is going to be a testable version --- config.cordovabuild.xml | 2 +- package.cordovabuild.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config.cordovabuild.xml b/config.cordovabuild.xml index 1bfecc184..212485757 100644 --- a/config.cordovabuild.xml +++ b/config.cordovabuild.xml @@ -1,5 +1,5 @@ - + emission A commute pattern tracker and carbon footprint estimator. diff --git a/package.cordovabuild.json b/package.cordovabuild.json index 213dcf806..95fd6f5ff 100644 --- a/package.cordovabuild.json +++ b/package.cordovabuild.json @@ -1,6 +1,6 @@ { "name": "edu.berkeley.eecs.emission", - "version": "3.2.6", + "version": "3.2.7", "displayName": "emission", "license": "BSD-3-Clause", "repository": { From 2cf8cef4c38e45083b1581bf228396626fe1aab1 Mon Sep 17 00:00:00 2001 From: "K. Shankari" Date: Thu, 16 Mar 2023 22:02:12 -0700 Subject: [PATCH 8/8] Bump up the versions of our plugins - data collection: https://github.com/e-mission/e-mission-data-collection/releases/tag/v1.7.6 - unified logger: https://github.com/e-mission/cordova-unified-logger/releases/tag/v1.3.6 - server sync: https://github.com/e-mission/cordova-server-sync/releases/tag/v1.3.1 --- package.cordovabuild.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.cordovabuild.json b/package.cordovabuild.json index 95fd6f5ff..16ae81301 100644 --- a/package.cordovabuild.json +++ b/package.cordovabuild.json @@ -71,12 +71,12 @@ "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.7.5", + "cordova-plugin-em-datacollection": "git+https://github.com/e-mission/e-mission-data-collection.git#v1.7.6", "cordova-plugin-em-opcodeauth": "git+https://github.com/e-mission/cordova-jwt-auth.git#v1.7.0", "cordova-plugin-em-server-communication": "git+https://github.com/e-mission/cordova-server-communication.git#v1.2.5", - "cordova-plugin-em-serversync": "git+https://github.com/e-mission/cordova-server-sync.git#v1.3.0", + "cordova-plugin-em-serversync": "git+https://github.com/e-mission/cordova-server-sync.git#v1.3.1", "cordova-plugin-em-settings": "git+https://github.com/e-mission/cordova-connection-settings.git#v1.2.3", - "cordova-plugin-em-unifiedlogger": "git+https://github.com/e-mission/cordova-unified-logger.git#v1.3.5", + "cordova-plugin-em-unifiedlogger": "git+https://github.com/e-mission/cordova-unified-logger.git#v1.3.6", "cordova-plugin-em-usercache": "git+https://github.com/e-mission/cordova-usercache.git#v1.1.5", "cordova-plugin-email-composer": "git+https://github.com/katzer/cordova-plugin-email-composer.git#0.10.1", "cordova-plugin-file": "7.0.0",