diff --git a/appholder/src/main/java/com/android/identity/wallet/HolderApp.kt b/appholder/src/main/java/com/android/identity/wallet/HolderApp.kt index 570872356..44ba212e9 100644 --- a/appholder/src/main/java/com/android/identity/wallet/HolderApp.kt +++ b/appholder/src/main/java/com/android/identity/wallet/HolderApp.kt @@ -3,6 +3,7 @@ package com.android.identity.wallet import android.app.Application import com.android.identity.android.util.AndroidLogPrinter import com.android.identity.util.Logger +import com.android.identity.wallet.util.PeriodicKeysRefreshWorkRequest import com.android.identity.wallet.util.PreferencesHelper import com.google.android.material.color.DynamicColors @@ -13,5 +14,6 @@ class HolderApp: Application() { Logger.setLogPrinter(AndroidLogPrinter()) DynamicColors.applyToActivitiesIfAvailable(this) PreferencesHelper.initialize(this) + PeriodicKeysRefreshWorkRequest(this).schedulePeriodicKeysRefreshing() } } \ No newline at end of file diff --git a/appholder/src/main/java/com/android/identity/wallet/util/PeriodicKeysRefreshWorkRequest.kt b/appholder/src/main/java/com/android/identity/wallet/util/PeriodicKeysRefreshWorkRequest.kt new file mode 100644 index 000000000..69e2c04b8 --- /dev/null +++ b/appholder/src/main/java/com/android/identity/wallet/util/PeriodicKeysRefreshWorkRequest.kt @@ -0,0 +1,17 @@ +package com.android.identity.wallet.util + +import android.content.Context +import androidx.work.PeriodicWorkRequestBuilder +import androidx.work.WorkManager +import java.util.concurrent.TimeUnit + +class PeriodicKeysRefreshWorkRequest(context: Context) { + + private val workManager = WorkManager.getInstance(context) + + fun schedulePeriodicKeysRefreshing() { + val workRequest = PeriodicWorkRequestBuilder(1, TimeUnit.DAYS) + .build() + workManager.enqueue(workRequest) + } +} \ No newline at end of file diff --git a/appholder/src/main/java/com/android/identity/wallet/util/RefreshKeysWorker.kt b/appholder/src/main/java/com/android/identity/wallet/util/RefreshKeysWorker.kt new file mode 100644 index 000000000..b1b601ac0 --- /dev/null +++ b/appholder/src/main/java/com/android/identity/wallet/util/RefreshKeysWorker.kt @@ -0,0 +1,23 @@ +package com.android.identity.wallet.util + +import android.content.Context +import androidx.work.Worker +import androidx.work.WorkerParameters +import com.android.identity.wallet.document.DocumentManager + +class RefreshKeysWorker( + context: Context, + params: WorkerParameters +) : Worker(context, params) { + + private val documentManager = DocumentManager.getInstance(context) + private val provisioningUtil = ProvisioningUtil.getInstance(context) + + override fun doWork(): Result { + documentManager.getDocuments().forEach { documentInformation -> + val credential = documentManager.getCredentialByName(documentInformation.docName) + credential?.let { provisioningUtil.refreshAuthKeys(it, documentInformation) } + } + return Result.success() + } +} \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2b4182123..c0ffaa946 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -26,6 +26,7 @@ sonar-gradle-plugin = "3.4.0.2513" jacoco = "0.47.0" navigation = "2.6.0" + work-version = "2.8.1" navigation_plugin = "2.5.3" code_scanner = "2.1.0" junit-android-test = "1.1.5" @@ -41,6 +42,7 @@ androidx-fragment-ktx = { module = "androidx.fragment:fragment-ktx", version.ref = "fragment" } androidx-legacy-v4 = { module = "androidx.legacy:legacy-support-v4", version.ref = "legacy-support-v4" } androidx-preference-ktx = { module = "androidx.preference:preference-ktx", version.ref = "androidx-preference" } + androidx-work = { module = "androidx.work:work-runtime-ktx", version.ref = "work-version"} androidx-lifecycle-extensions = { module = "androidx.lifecycle:lifecycle-extensions", version.ref = "lifecycle" } androidx-lifecycle-livedata = { module = "androidx.lifecycle:lifecycle-livedata-ktx", version.ref = "lifecycle-ktx" } @@ -83,7 +85,7 @@ truth = { module = "com.google.truth:truth", version.ref = "truth" } [bundles] - androidx-core = ["androidx-core-ktx", "androidx-appcompat", "androidx-material", "androidx-contraint-layout", "androidx-fragment-ktx", "androidx-legacy-v4", "androidx-preference-ktx"] + androidx-core = ["androidx-core-ktx", "androidx-appcompat", "androidx-material", "androidx-contraint-layout", "androidx-fragment-ktx", "androidx-legacy-v4", "androidx-preference-ktx", "androidx-work"] androidx-lifecycle = ["androidx-lifecycle-extensions", "androidx-lifecycle-livedata", "androidx-lifecycle-viewmodel"] androidx-navigation = ["androidx-navigation-ktx", "androidx-navigation-ui-ktx"] compose = ["compose-ui", "compose-foundation", "compose-material", "compose-ui-tooling", "compose-preview", "compose-icons"]