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-3191 H&F Plugin - Use sensors for background jobs (Activity Recognition Transition API) #111

Merged
merged 24 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8cf934b
feat: include necessary permissions for API 28 and below
alexgerardojacinto Mar 1, 2024
73e8033
feat: declare SCHEDULE_EXACT_ALARM permission in manifest
alexgerardojacinto Mar 12, 2024
1725910
feat: request SCHEDULE_EXACT_ALARM permission when setting background…
alexgerardojacinto Mar 12, 2024
08887b7
feat: handle SCHEDULE_EXACT_ALARM permission not being given when set…
alexgerardojacinto Mar 12, 2024
859735b
feat: ask for SCHEDULE_EXACT_ALARM permission before other ones
alexgerardojacinto Mar 13, 2024
5130e60
feat: get foreground notification info from strings.xml file
alexgerardojacinto Mar 13, 2024
8ad9830
feat: replace workManager with alarmManager
alexgerardojacinto Mar 14, 2024
d5dc3de
feat: pass context parameter to AdvancedQuery, as it is needed
alexgerardojacinto Mar 14, 2024
d25c270
chore: update dependency to H&F Android library
alexgerardojacinto Mar 14, 2024
6cbf5d9
chore: update dependency to H&F Android lib
alexgerardojacinto Mar 14, 2024
a0e2036
chore: add explanatory comment
alexgerardojacinto Mar 14, 2024
bb2980a
chore: update changelog
alexgerardojacinto Mar 14, 2024
3455dc8
Merge branch 'feat/RMET-3190/background-alarms' into feat/RMET-3191/b…
alexgerardojacinto Mar 15, 2024
18a2d30
feat: only request SCHEDULE_EXACT_ALARM permission if variable requir…
alexgerardojacinto Mar 15, 2024
009c1fc
fix: properly check if SCHEDULE_EXACT_ALARM permission is necessary
alexgerardojacinto Mar 15, 2024
b7d4e5b
refactor: remove unnecessary semicolon
alexgerardojacinto Mar 18, 2024
5910ab0
feat: use ActivityTransitionHelper from Android library
alexgerardojacinto Mar 18, 2024
a3e2518
chore: update dependency to H&F Android library
alexgerardojacinto Mar 18, 2024
1ba44f5
feat: include play-services-services-location dependency through Gralde
alexgerardojacinto Mar 18, 2024
f8c4aa5
chore: remove unnecessary gradle dependency
alexgerardojacinto Mar 18, 2024
0e0addf
Merge branch 'development' into feat/RMET-3191/background-activity
alexgerardojacinto Mar 18, 2024
ab3724c
chore: update changelog
alexgerardojacinto Mar 18, 2024
bce588d
chore: update dependency to H&F Android lib
alexgerardojacinto Mar 19, 2024
63f8427
chore: update dependency to H&F Android library
alexgerardojacinto Mar 19, 2024
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-03-18
- Implemented the usage of the Activity Transition Recognition API for background jobs (https://outsystemsrd.atlassian.net/browse/RMET-3191).

## 2024-03-14
- Implemented the usage of exact alarms for background jobs (https://outsystemsrd.atlassian.net/browse/RMET-3190).

Expand Down
1 change: 1 addition & 0 deletions hooks/androidCopyPreferencesPermissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ function addBackgroundJobPermissionsToManifest(configParser, projectRoot, parser
// add permissions to XML document
addEntryToManifest(manifestXmlDoc, 'android.permission.POST_NOTIFICATIONS')
addEntryToManifest(manifestXmlDoc, 'android.permission.ACTIVITY_RECOGNITION')
addEntryToManifest(manifestXmlDoc, 'com.google.android.gms.permission.ACTIVITY_RECOGNITION') // necessary for API 28 and below
addEntryToManifest(manifestXmlDoc, 'android.permission.FOREGROUND_SERVICE')
addEntryToManifest(manifestXmlDoc, 'android.permission.FOREGROUND_SERVICE_HEALTH')
addEntryToManifest(manifestXmlDoc, 'android.permission.HIGH_SAMPLING_RATE_SENSORS')
Expand Down
6 changes: 2 additions & 4 deletions src/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ allprojects {
dependencies{
implementation("com.google.android.gms:play-services-fitness:20.0.0")
implementation("com.google.android.gms:play-services-auth:19.2.0")
implementation("com.google.android.gms:play-services-location:19.0.1")
implementation("com.google.code.gson:gson:2.8.8")

implementation 'com.google.code.findbugs:jsr305:1.3.9'

implementation("com.github.outsystems:oscore-android:1.2.0@aar")
implementation("com.github.outsystems:oscordova-android:2.0.1@aar")
implementation("com.github.outsystems:oshealthfitness-android:1.2.0.22@aar")
implementation("com.github.outsystems:oshealthfitness-android:1.2.0.23@aar")
implementation("com.github.outsystems:osnotificationpermissions-android:0.0.4@aar")

// activity
Expand All @@ -37,9 +38,6 @@ dependencies{
// health connect sdk
implementation "androidx.health.connect:connect-client:1.1.0-alpha07"

// work manager
implementation "androidx.work:work-runtime-ktx:2.9.0"

// compose
implementation 'androidx.activity:activity-compose:1.8.2'
implementation 'androidx.compose.material3:material3:1.2.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class OSHealthFitness : CordovaImplementation() {
private lateinit var healthConnectDataManager: HealthConnectDataManager
private lateinit var healthConnectHelper: HealthConnectHelper
private lateinit var alarmManagerHelper: AlarmManagerHelper
private lateinit var activityTransitionHelper: ActivityTransitionHelper
private lateinit var backgroundParameters: BackgroundJobParameters

private lateinit var alarmManager: AlarmManager
Expand All @@ -57,8 +58,9 @@ class OSHealthFitness : CordovaImplementation() {
healthConnectRepository = HealthConnectRepository(healthConnectDataManager)
healthConnectHelper = HealthConnectHelper()
alarmManagerHelper = AlarmManagerHelper()
activityTransitionHelper = ActivityTransitionHelper()
healthConnectViewModel =
HealthConnectViewModel(healthConnectRepository, healthConnectHelper, alarmManagerHelper)
HealthConnectViewModel(healthConnectRepository, healthConnectHelper, alarmManagerHelper, activityTransitionHelper)
alarmManager = getContext().getSystemService(Context.ALARM_SERVICE) as AlarmManager

// get foreground notification title and description from resources (strings.xml)
Expand Down Expand Up @@ -279,12 +281,12 @@ class OSHealthFitness : CordovaImplementation() {
backgroundParameters = gson.fromJson(args.getString(0), BackgroundJobParameters::class.java)

//request permission for exact alarms if necessary
if (SDK_INT >= 31 && !alarmManager.canScheduleExactAlarms()) {
if (!Constants.ACTIVITY_VARIABLES.contains(backgroundParameters.variable) && SDK_INT >= 31 && !alarmManager.canScheduleExactAlarms()) {
requestingExactAlarmPermission = true
// we only need to request this permission if exact alarms need to be used
// when there's another way to schedule background jobs to run, we can avoid this for some variables (e.g. steps)
// we intended to use the Activity Recognition API, but it currently has a bug already reported to Google
getContext().startActivity(Intent(ACTION_REQUEST_SCHEDULE_EXACT_ALARM));
// when the variable is an activity variable (e.g. steps),
// we use the Activity Recognition Transition API instead of exact alarms.
getContext().startActivity(Intent(ACTION_REQUEST_SCHEDULE_EXACT_ALARM))
} else { // we can move on to other permissions if we don't need to request exact alarm permissions
requestBackgroundJobPermissions()
}
Expand Down
Loading