Skip to content

Commit

Permalink
Refresh Credential's Auth Keys Daily
Browse files Browse the repository at this point in the history
  • Loading branch information
mitrejcevski committed Oct 18, 2023
1 parent f0fe5ff commit aa60dd8
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -13,5 +14,6 @@ class HolderApp: Application() {
Logger.setLogPrinter(AndroidLogPrinter())
DynamicColors.applyToActivitiesIfAvailable(this)
PreferencesHelper.initialize(this)
PeriodicKeysRefreshWorkRequest(this).schedulePeriodicKeysRefreshing()
}
}
Original file line number Diff line number Diff line change
@@ -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<RefreshKeysWorker>(1, TimeUnit.DAYS)
.build()
workManager.enqueue(workRequest)
}
}
Original file line number Diff line number Diff line change
@@ -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()
}
}
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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" }
Expand Down Expand Up @@ -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"]
Expand Down

0 comments on commit aa60dd8

Please sign in to comment.