Skip to content

Commit

Permalink
Add support to turn off background optimizations for the app
Browse files Browse the repository at this point in the history
This is a companion commit to
e-mission/e-mission-data-collection@60f6fa4
from
e-mission/e-mission-data-collection#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
e-mission/e-mission-docs#838 (comment)

- Send the initialize transition using adb
    - Foreground service is restarted
e-mission/e-mission-docs#838 (comment)
  • Loading branch information
shankari committed Mar 17, 2023
1 parent 7901a28 commit 46af183
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
10 changes: 9 additions & 1 deletion www/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}
Expand Down
24 changes: 22 additions & 2 deletions www/js/appstatus/permissioncheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 46af183

Please sign in to comment.