Skip to content

Commit

Permalink
Merge pull request #268 from MORE-Platform/191-data-upload-issue-when…
Browse files Browse the repository at this point in the history
…-network-connection-is-off-for-long-issue-on-ios-app

Fixes multiple issues and improved memory management
  • Loading branch information
janoliver20 authored Jul 26, 2024
2 parents 8bf1678 + 3390536 commit 9fda138
Show file tree
Hide file tree
Showing 85 changed files with 349 additions and 264 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/Users/jancortiel/Documents/More/LBI/more-multiplatform-app/.kotlin/metadata/kotlinTransformedCInteropMetadataLibraries/org.jetbrains.kotlinx-atomicfu-0.23.1-nativeMain-cinterop/org.jetbrains.kotlinx_atomicfu-cinterop-interop-wFq7cg.klib
/Users/jancortiel/Documents/More/LBI/more-multiplatform-app/.kotlin/metadata/kotlinTransformedCInteropMetadataLibraries/io.realm.kotlin-cinterop-1.13.0-nativeDarwin-cinterop/io.realm.kotlin_cinterop-cinterop-realm_wrapper-nt9oMQ.klib
/Users/jancortiel/Documents/More/LBI/more-multiplatform-app/.kotlin/metadata/kotlinTransformedCInteropMetadataLibraries/io.ktor-ktor-utils-2.3.12-iosMain-cinterop/io.ktor_ktor-utils-cinterop-threadUtils-TE4abA.klib
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/Users/jancortiel/Documents/More/LBI/more-multiplatform-app/.kotlin/metadata/kotlinTransformedCInteropMetadataLibraries/org.jetbrains.kotlinx-atomicfu-0.23.1-nativeMain-cinterop/org.jetbrains.kotlinx_atomicfu-cinterop-interop-wFq7cg.klib
/Users/jancortiel/Documents/More/LBI/more-multiplatform-app/.kotlin/metadata/kotlinTransformedCInteropMetadataLibraries/io.realm.kotlin-cinterop-1.13.0-nativeDarwin-cinterop/io.realm.kotlin_cinterop-cinterop-realm_wrapper-nt9oMQ.klib
/Users/jancortiel/Documents/More/LBI/more-multiplatform-app/.kotlin/metadata/kotlinTransformedCInteropMetadataLibraries/io.ktor-ktor-utils-2.3.12-iosMain-cinterop/io.ktor_ktor-utils-cinterop-threadUtils-TE4abA.klib
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/Users/jancortiel/Documents/More/LBI/more-multiplatform-app/.kotlin/metadata/kotlinTransformedCInteropMetadataLibraries/org.jetbrains.kotlinx-atomicfu-0.23.1-nativeMain-cinterop/org.jetbrains.kotlinx_atomicfu-cinterop-interop-wFq7cg.klib
/Users/jancortiel/Documents/More/LBI/more-multiplatform-app/.kotlin/metadata/kotlinTransformedCInteropMetadataLibraries/io.realm.kotlin-cinterop-1.13.0-nativeDarwin-cinterop/io.realm.kotlin_cinterop-cinterop-realm_wrapper-nt9oMQ.klib
/Users/jancortiel/Documents/More/LBI/more-multiplatform-app/.kotlin/metadata/kotlinTransformedCInteropMetadataLibraries/io.ktor-ktor-utils-2.3.12-iosMain-cinterop/io.ktor_ktor-utils-cinterop-threadUtils-TE4abA.klib
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/Users/jancortiel/Documents/More/LBI/more-multiplatform-app/.kotlin/metadata/kotlinTransformedCInteropMetadataLibraries/org.jetbrains.kotlinx-atomicfu-0.23.1-nativeMain-cinterop/org.jetbrains.kotlinx_atomicfu-cinterop-interop-wFq7cg.klib
/Users/jancortiel/Documents/More/LBI/more-multiplatform-app/.kotlin/metadata/kotlinTransformedCInteropMetadataLibraries/io.realm.kotlin-cinterop-1.13.0-nativeDarwin-cinterop/io.realm.kotlin_cinterop-cinterop-realm_wrapper-nt9oMQ.klib
/Users/jancortiel/Documents/More/LBI/more-multiplatform-app/.kotlin/metadata/kotlinTransformedCInteropMetadataLibraries/io.ktor-ktor-utils-2.3.12-iosMain-cinterop/io.ktor_ktor-utils-cinterop-threadUtils-TE4abA.klib
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/Users/jancortiel/Documents/More/LBI/more-multiplatform-app/.kotlin/metadata/kotlinTransformedCInteropMetadataLibraries/org.jetbrains.kotlinx-atomicfu-0.23.1-nativeMain-cinterop/org.jetbrains.kotlinx_atomicfu-cinterop-interop-wFq7cg.klib
/Users/jancortiel/Documents/More/LBI/more-multiplatform-app/.kotlin/metadata/kotlinTransformedCInteropMetadataLibraries/io.realm.kotlin-cinterop-1.13.0-nativeDarwin-cinterop/io.realm.kotlin_cinterop-cinterop-realm_wrapper-nt9oMQ.klib
/Users/jancortiel/Documents/More/LBI/more-multiplatform-app/.kotlin/metadata/kotlinTransformedCInteropMetadataLibraries/io.ktor-ktor-utils-2.3.12-iosMain-cinterop/io.ktor_ktor-utils-cinterop-threadUtils-TE4abA.klib
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/Users/jancortiel/Documents/More/LBI/more-multiplatform-app/.kotlin/metadata/kotlinTransformedCInteropMetadataLibraries/org.jetbrains.kotlinx-atomicfu-0.23.1-nativeMain-cinterop/org.jetbrains.kotlinx_atomicfu-cinterop-interop-wFq7cg.klib
/Users/jancortiel/Documents/More/LBI/more-multiplatform-app/.kotlin/metadata/kotlinTransformedCInteropMetadataLibraries/io.realm.kotlin-cinterop-1.13.0-nativeDarwin-cinterop/io.realm.kotlin_cinterop-cinterop-realm_wrapper-nt9oMQ.klib
/Users/jancortiel/Documents/More/LBI/more-multiplatform-app/.kotlin/metadata/kotlinTransformedCInteropMetadataLibraries/io.ktor-ktor-utils-2.3.12-iosMain-cinterop/io.ktor_ktor-utils-cinterop-threadUtils-TE4abA.klib
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
12 changes: 6 additions & 6 deletions androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId = "ac.at.lbg.dhp.more"
minSdk = 29
targetSdk = 34
versionCode = 10
versionName = "4.0.12"
versionCode = 12
versionName = "4.0.14"
}
buildFeatures {
compose = true
Expand Down Expand Up @@ -50,7 +50,7 @@ android {
val composeVersion = "1.6.8"
val workVersion = "2.9.0"
val navVersion = "2.7.7"
val polarSDKVersion = "5.5.0"
val polarSDKVersion = "5.6.0"

dependencies {
implementation(project(":shared"))
Expand All @@ -61,8 +61,8 @@ dependencies {
implementation("androidx.compose.material:material:$composeVersion")
implementation("androidx.compose.material:material-icons-core:$composeVersion")
implementation("androidx.compose.material:material-icons-extended:$composeVersion")
implementation("androidx.fragment:fragment:1.8.1")
implementation("androidx.activity:activity-compose:1.9.0")
implementation("androidx.fragment:fragment:1.8.2")
implementation("androidx.activity:activity-compose:1.9.1")
implementation("io.realm.kotlin:library-base:1.13.0")
implementation("androidx.navigation:navigation-compose:$navVersion")
implementation("androidx.work:work-runtime-ktx:$workVersion")
Expand All @@ -80,5 +80,5 @@ dependencies {
implementation("com.google.firebase:firebase-inappmessaging-display-ktx")
implementation("com.google.code.gson:gson:2.10.1")
implementation("com.github.acsbendi:Android-Request-Inspector-WebView:1.0.3")
implementation("androidx.lifecycle:lifecycle-process:2.8.3")
implementation("androidx.lifecycle:lifecycle-process:2.8.4")
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package io.redlink.more.app.android.observations.HR


import com.polar.androidcommunications.api.ble.model.DisInfo
import com.polar.sdk.api.PolarBleApi
import com.polar.sdk.api.PolarBleApiCallback
import com.polar.sdk.api.model.PolarDeviceInfo
Expand Down Expand Up @@ -45,35 +46,60 @@ class PolarObserverCallback : PolarBleApiCallback() {

override fun deviceConnected(polarDeviceInfo: PolarDeviceInfo) {
super.deviceConnected(polarDeviceInfo)
Napier.d("CONNECTED: ${polarDeviceInfo.deviceId}", tag = "PolarObserverCallback::deviceConnected")
Napier.d(
"CONNECTED: ${polarDeviceInfo.deviceId}",
tag = "PolarObserverCallback::deviceConnected"
)
connectionListener?.onDeviceConnected(polarDeviceInfo)
}

override fun deviceConnecting(polarDeviceInfo: PolarDeviceInfo) {
super.deviceConnecting(polarDeviceInfo)
Napier.d("CONNECTING: ${polarDeviceInfo.deviceId}", tag = "PolarObserverCallback::deviceConnecting")
Napier.d(
"CONNECTING: ${polarDeviceInfo.deviceId}",
tag = "PolarObserverCallback::deviceConnecting"
)
connectionListener?.onDeviceConnecting(polarDeviceInfo)
}

override fun deviceDisconnected(polarDeviceInfo: PolarDeviceInfo) {
super.deviceDisconnected(polarDeviceInfo)
Napier.i("Device disconnected: ${polarDeviceInfo.name}", tag = "PolarObserverCallback::deviceDisconnected")
Napier.i(
"Device disconnected: ${polarDeviceInfo.name}",
tag = "PolarObserverCallback::deviceDisconnected"
)
connectionListener?.onDeviceDisconnected(polarDeviceInfo)
}

override fun bleSdkFeatureReady(identifier: String, feature: PolarBleApi.PolarBleSdkFeature) {
super.bleSdkFeatureReady(identifier, feature)
Napier.i("SDK Feature ready: ${feature.name}, identifier: $identifier", tag = "PolarObserverCallback::bleSdkFeatureReady")
Napier.i(
"SDK Feature ready: ${feature.name}, identifier: $identifier",
tag = "PolarObserverCallback::bleSdkFeatureReady"
)
connectionListener?.onPolarFeatureReady(feature)
}

override fun disInformationReceived(identifier: String, uuid: UUID, value: String) {
super.disInformationReceived(identifier, uuid, value)
Napier.i("Disinformation: $identifier, UUID: $uuid, Value: $value", tag = "PolarObserverCallback::disInformationReceived")
Napier.i(
"Disinformation: $identifier, UUID: $uuid, Value: $value",
tag = "PolarObserverCallback::disInformationReceived"
)
}

override fun disInformationReceived(identifier: String, disInfo: DisInfo) {
Napier.i(
"Disinformation: $identifier, DisInfo: $disInfo",
tag = "PolarObserverCallback::disInformationReceived"
)
}

override fun batteryLevelReceived(identifier: String, level: Int) {
super.batteryLevelReceived(identifier, level)
Napier.i( "Battery Level Received: $level", tag = "PolarObserverCallback::batteryLevelReceived")
Napier.i(
"Battery Level Received: $level",
tag = "PolarObserverCallback::batteryLevelReceived"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class PolarConnector(context: Context) : BluetoothConnector, PolarConnectorListe
override fun onPolarFeatureReady(feature: PolarBleApi.PolarBleSdkFeature) {
if (feature == PolarBleApi.PolarBleSdkFeature.FEATURE_HR) {
Napier.i(tag = "PolarConnector::onPolarFeatureReady") { "HR ready!" }
PolarHeartRateObservation.setHRFeature(false)
PolarHeartRateObservation.setHRFeature(true)
}
}

Expand Down
2 changes: 1 addition & 1 deletion androidApp/src/main/res/values-de/bluetooth-strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<string name="more_ble_context_description">Manche Aufgaben benötigen Bluetooth Geräte um abgeschlossen zu werden. Stelle sicher, dass folgende Geräte verbunden sind</string>
<string name="more_ble_context_description_part2">Sie können sich jederzeit mit Geräten verbinden in: Info > Geräte</string>
<string name="more_ble_skip">Setup überspringen</string>
<string name="more_ble_disabled">Bluetooth ist deaktiviert. Bitte aktivieren zum verbinden!</string>
<string name="more_ble_disabled">Bluetooth oder GPS deaktiviert! Bitte aktivieren Sie beides für die Nutzung!</string>
<string name="more_connect_device_info">Verbinde ein Gerät, indem du es aus der Liste auswählst, nachdem du dieses mit deinem Smartphone gekoppelt hast.</string>
<string name="more_connect_no_device_found_info">Bitte verbinde das geforderte Gerät mit deinem Smartphone, um es mit der App zu verbinden.</string>
</resources>
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
buildscript {
dependencies {
classpath("com.google.gms:google-services:4.4.1")
classpath("com.google.firebase:firebase-crashlytics-gradle:2.9.9")
classpath("com.google.gms:google-services:4.4.2")
classpath("com.google.firebase:firebase-crashlytics-gradle:3.0.2")
}
repositories {
google() // Google's Maven repository
Expand All @@ -13,7 +13,7 @@ plugins {
//trick: for the same plugin versions in all sub-modules
id("com.android.application").version("8.2.2").apply(false)
id("com.android.library").version("8.2.2").apply(false)
kotlin("android").version("1.9.22").apply(false)
kotlin("android").version("1.9.23").apply(false)
kotlin("multiplatform").version("1.9.23").apply(false)
kotlin("plugin.serialization").version("1.9.23").apply(false)
}
Expand Down
4 changes: 2 additions & 2 deletions iosApp/iosApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1798,7 +1798,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 4.0.12;
MARKETING_VERSION = 4.0.14;
OTHER_LDFLAGS = (
"$(inherited)",
"-framework",
Expand Down Expand Up @@ -1838,7 +1838,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 4.0.12;
MARKETING_VERSION = 4.0.14;
OTHER_LDFLAGS = (
"$(inherited)",
"-framework",
Expand Down
10 changes: 1 addition & 9 deletions iosApp/iosApp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class AppDelegate: NSObject, UIApplicationDelegate {
fcmService.register()
AppDelegate.registerForNotifications()

registerBackgroundTasks()
DataUploadBackgroundTask.setupBackgroundTasks()

AppDelegate.shared.deeplinkManager.addAvailableDeepLinks(deepLinks: Set(NavigationScreen.allCases.map { $0.values.navigationLink }))

Expand All @@ -78,14 +78,6 @@ class AppDelegate: NSObject, UIApplicationDelegate {
print("App did fail to register for remote notifications: \(error)")
}

private func registerBackgroundTasks() {
BGTaskScheduler.shared.register(forTaskWithIdentifier: DataUploadBackgroundTask.taskID, using: nil) { task in
if let task = task as? BGProcessingTask {
DataUploadBackgroundTask().handleProcessingTask(task: task)
}
}
}

func cancelBackgroundTasks() {
BGTaskScheduler.shared.cancel(taskRequestWithIdentifier: DataUploadBackgroundTask.taskID)
}
Expand Down
50 changes: 26 additions & 24 deletions iosApp/iosApp/BackgroundTasks/DataUploadBackgroundTask.swift
Original file line number Diff line number Diff line change
@@ -1,39 +1,28 @@
//
// DataUploadBackgroundTask.swift
// iosApp
//
// Created by Jan Cortiel on 23.03.23.
// Copyright © 2023 Ludwig Boltzmann Institute for
// Digital Health and Prevention - A research institute
// of the Ludwig Boltzmann Gesellschaft,
// Oesterreichische Vereinigung zur Foerderung
// der wissenschaftlichen Forschung
// Licensed under the Apache 2.0 license with Commons Clause
// (see https://www.apache.org/licenses/LICENSE-2.0 and
// https://commonsclause.com/).
//

import BackgroundTasks
import Foundation

class DataUploadBackgroundTask {
static let taskID = "io.redlink.more.app.multiplatform.data-upload"
static func schedule() {

static func schedule(earliestBeginDate: Date? = nil) {
let request = BGProcessingTaskRequest(identifier: taskID)
request.earliestBeginDate = Calendar.current.date(byAdding: .minute, value: 15, to: Date())
if let earliestDate = earliestBeginDate {
request.earliestBeginDate = earliestDate
} else {
request.earliestBeginDate = Calendar.current.date(byAdding: .minute, value: 15, to: Date())
}
request.requiresNetworkConnectivity = true
request.requiresExternalPower = false

do {
try BGTaskScheduler.shared.submit(request)
print("DataUploadBackgroundTask::schedule - Background Task scheduled")
} catch {
print("DataUploadBackgroundTask:schedule - Error requesting for a background task")
print("DataUploadBackgroundTask::schedule - Error requesting a background task: \(error.localizedDescription)")
}
}

private let dataCollector = ObservationDataCollector()

private func collectRecordedData(completion: @escaping () -> Void) {
print("DataUploadBackgroundTask::collectRecordedData - \(Date()): Collecting recorded data...")
dataCollector.collectData { dataCollected in
Expand All @@ -45,15 +34,17 @@ class DataUploadBackgroundTask {
completion()
}
}

private func close() {
print("DataUploadBackgroundTask::close - Cleaning up resources")
}
}

extension DataUploadBackgroundTask: BackgroundTaskHandler {
@MainActor
func handleProcessingTask(task: BGProcessingTask) {
print("DataUploadBackgroundTask::handleProcessingTask - Starting Background Processing Task")

task.expirationHandler = {
print("\(Date()): Task will soon expire! Cleaning up...")
self.close()
Expand All @@ -63,24 +54,35 @@ extension DataUploadBackgroundTask: BackgroundTaskHandler {
task.setTaskCompleted(success: false)
}
}

collectRecordedData { [weak self] in
guard let strongSelf = self else {
DataUploadBackgroundTask.schedule()
task.setTaskCompleted(success: false)
return
}

strongSelf.close()
DataUploadBackgroundTask.schedule()
DispatchQueue.main.async {
task.setTaskCompleted(success: true)
}
}

}

func handleRefreshTask(task: BGAppRefreshTask) {
print("DataUploadBackgroundTask::handleRefreshTask - Handling Refresh Task")
task.setTaskCompleted(success: true)
}


static func setupBackgroundTasks() {
BGTaskScheduler.shared.register(forTaskWithIdentifier: DataUploadBackgroundTask.taskID, using: nil) { task in
if let processingTask = task as? BGProcessingTask {
let backgroundTaskHandler = DataUploadBackgroundTask()
Task {
await backgroundTaskHandler.handleProcessingTask(task: processingTask)
}
}
}
}
}
4 changes: 2 additions & 2 deletions iosApp/iosApp/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>4.0.12</string>
<string>4.0.14</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
Expand All @@ -36,7 +36,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>4.0.12</string>
<string>4.0.14</string>
<key>FirebaseAppDelegateProxyEnabled</key>
<false/>
<key>ITSAppUsesNonExemptEncryption</key>
Expand Down
Loading

0 comments on commit 9fda138

Please sign in to comment.