From df3bb9a3c67ece83c9eed75a083084c2a47d23b8 Mon Sep 17 00:00:00 2001 From: sim Date: Sat, 25 Feb 2023 18:47:24 +0100 Subject: [PATCH] Fix RACE to deleteDevice --- .../distributor/nextpush/activities/MainActivity.kt | 7 ++++--- .../java/org/unifiedpush/distributor/nextpush/api/Api.kt | 3 ++- .../distributor/nextpush/distributor/Distributor.kt | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/unifiedpush/distributor/nextpush/activities/MainActivity.kt b/app/src/main/java/org/unifiedpush/distributor/nextpush/activities/MainActivity.kt index c9a1940..e134584 100644 --- a/app/src/main/java/org/unifiedpush/distributor/nextpush/activities/MainActivity.kt +++ b/app/src/main/java/org/unifiedpush/distributor/nextpush/activities/MainActivity.kt @@ -178,9 +178,10 @@ class MainActivity : AppCompatActivity() { .edit() .remove("PREF_CURRENT_ACCOUNT_STRING") .apply() - deleteDevice(this) - StartService.stopService() - FailureHandler.clearFails() + deleteDevice(this) { + StartService.stopService() + FailureHandler.clearFails() + } showStart() finish() startActivity(intent) diff --git a/app/src/main/java/org/unifiedpush/distributor/nextpush/api/Api.kt b/app/src/main/java/org/unifiedpush/distributor/nextpush/api/Api.kt index d02e65a..7f4f78a 100644 --- a/app/src/main/java/org/unifiedpush/distributor/nextpush/api/Api.kt +++ b/app/src/main/java/org/unifiedpush/distributor/nextpush/api/Api.kt @@ -106,7 +106,7 @@ object Api { Log.d(TAG, "cSync done.") } - fun Context.apiDeleteDevice() { + fun Context.apiDeleteDevice(block: () -> Unit = {}) { val deviceId = getDeviceId(this) ?: return withApiProvider { apiProvider -> @@ -132,6 +132,7 @@ object Api { override fun onComplete() { removeUrl(this@apiDeleteDevice) + block() } }) removeDeviceId(this) diff --git a/app/src/main/java/org/unifiedpush/distributor/nextpush/distributor/Distributor.kt b/app/src/main/java/org/unifiedpush/distributor/nextpush/distributor/Distributor.kt index 165baad..30ffe93 100644 --- a/app/src/main/java/org/unifiedpush/distributor/nextpush/distributor/Distributor.kt +++ b/app/src/main/java/org/unifiedpush/distributor/nextpush/distributor/Distributor.kt @@ -108,13 +108,13 @@ object Distributor { return TOKEN_NOK } - fun deleteDevice(context: Context) { + fun deleteDevice(context: Context, block: () -> Unit = {}) { val db = getDb(context) db.listTokens().forEach { sendUnregistered(context, it) db.unregisterApp(it) } - context.apiDeleteDevice() + context.apiDeleteDevice(block) } fun createApp(context: Context, appName: String, connectorToken: String, block: () -> Unit) {