Skip to content

Commit 02ae6e1

Browse files
Android app enhancements for state management and status on UI (#3819)
Add missing statuses and fix state handling, improve display of status on UI with training progress. ### Description Add missing statuses and improves state handling, improve display of status on UI with training progress. ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Quick tests passed locally by running `./runtest.sh`. - [ ] In-line docstrings updated. - [ ] Documentation updated. --------- Co-authored-by: Chester Chen <[email protected]>
1 parent 22e204a commit 02ae6e1

File tree

5 files changed

+657
-27
lines changed

5 files changed

+657
-27
lines changed

nvflare/edge/device/android/app/src/main/java/com/nvidia/nvflare/app/controllers/FlareRunnerController.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.content.Context
44
import android.util.Log
55
import com.nvidia.nvflare.app.data.AndroidDataSource
66
import com.nvidia.nvflare.app.data.DatasetError
7+
import com.nvidia.nvflare.sdk.models.TrainingProgress
78
import com.nvidia.nvflare.sdk.training.TrainingStatus
89
import com.nvidia.nvflare.sdk.core.AndroidFlareRunner
910
import com.nvidia.nvflare.sdk.core.Connection
@@ -18,6 +19,8 @@ import kotlinx.coroutines.Dispatchers
1819
import kotlinx.coroutines.Job
1920
import kotlinx.coroutines.launch
2021
import kotlinx.coroutines.withContext
22+
import android.os.Handler
23+
import android.os.Looper
2124

2225

2326
sealed class TrainingError : Exception() {
@@ -91,6 +94,7 @@ class FlareRunnerController(
9194

9295
fun startTraining(
9396
onStatusUpdate: (TrainingStatus) -> Unit,
97+
onProgressUpdate: (TrainingProgress) -> Unit,
9498
onError: (Exception) -> Unit,
9599
onSuccess: () -> Unit
96100
) {
@@ -104,6 +108,7 @@ class FlareRunnerController(
104108

105109
status = TrainingStatus.TRAINING
106110
onStatusUpdate(status)
111+
onProgressUpdate(TrainingProgress.idle())
107112

108113
// Create connection on main thread to avoid background thread issues
109114
val connection = createConnection()
@@ -178,7 +183,7 @@ class FlareRunnerController(
178183
currentDataset = dataset
179184
Log.d(TAG, "FlareRunnerController: Stored dataset reference: $dataset")
180185

181-
// Create FlareRunner with dataset
186+
// Create FlareRunner with dataset and progress callback
182187
val runner = AndroidFlareRunner(
183188
context = context,
184189
connection = connection,
@@ -193,7 +198,13 @@ class FlareRunnerController(
193198
"app_version" to context.packageManager.getPackageInfo(context.packageName, 0).versionName
194199
),
195200
userInfo = emptyMap(),
196-
jobTimeout = TWENTY_FOUR_HOURS_IN_SECONDS
201+
jobTimeout = TWENTY_FOUR_HOURS_IN_SECONDS,
202+
onProgressUpdate = { progress ->
203+
// Pass TrainingProgress directly to UI on main thread
204+
Handler(Looper.getMainLooper()).post {
205+
onProgressUpdate(progress)
206+
}
207+
}
197208
)
198209

199210
flareRunner = runner

0 commit comments

Comments
 (0)