Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
Revert "use SharedPreferences to save verify results"
Browse files Browse the repository at this point in the history
This reverts commit 0dd837f.
  • Loading branch information
thestinger committed May 1, 2023
1 parent 95b5ca3 commit 515ab1e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ class DomainVerificationReceiverV1 : BaseDomainVerificationReceiver() {
}
}

//clear sp before enqueue unique work since policy is REPLACE
val deContext = context.createDeviceProtectedStorageContext()
val editor = deContext?.getSharedPreferences(packageName, Context.MODE_PRIVATE)?.edit()
editor?.clear()?.apply()
WorkManager.getInstance(context)
.beginUniqueWork(
"$PACKAGE_WORK_PREFIX_V1$packageName",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ class CollectV1Worker(appContext: Context, params: WorkerParameters) :
Data.Builder()
.putInt(VERIFICATION_ID_KEY, verificationId)
.apply {
putString(PACKAGE_NAME_KEY, packageName)
if (DEBUG) {
putString(PACKAGE_NAME_KEY, packageName)
}
}
.build()
)
Expand All @@ -50,29 +52,14 @@ class CollectV1Worker(appContext: Context, params: WorkerParameters) :

override suspend fun doWork() = coroutineScope {
if (!AndroidUtils.isReceiverV1Enabled(appContext)) {
//clear sp and commit here
val inputData = params.inputData
val packageName = inputData.getString(PACKAGE_NAME_KEY)
val deContext = appContext.createDeviceProtectedStorageContext()
val sp = deContext?.getSharedPreferences(packageName, Context.MODE_PRIVATE)
val editor = sp?.edit()
editor?.clear()?.commit()
//delete sp file
val retOfDel = deContext?.deleteSharedPreferences(packageName)
if (DEBUG) {
Log.d(TAG, "delete sp for $packageName return $retOfDel")
}
return@coroutineScope Result.success()
}

val inputData = params.inputData
val verificationId = inputData.getInt(VERIFICATION_ID_KEY, -1)
val successfulHosts = mutableListOf<String>()
val failedHosts = mutableListOf<String>()
val packageName = inputData.getString(PACKAGE_NAME_KEY)
val deContext = appContext.createDeviceProtectedStorageContext()
val sp = deContext?.getSharedPreferences(packageName, Context.MODE_PRIVATE)
sp?.all?.entries?.forEach { (key, _) ->
inputData.keyValueMap.entries.forEach { (key, _) ->
when {
key.startsWith(SingleV1RequestWorker.HOST_SUCCESS_PREFIX) ->
successfulHosts += key.removePrefix(SingleV1RequestWorker.HOST_SUCCESS_PREFIX)
Expand All @@ -82,6 +69,7 @@ class CollectV1Worker(appContext: Context, params: WorkerParameters) :
}

if (DEBUG) {
val packageName = inputData.getString(PACKAGE_NAME_KEY)
Log.d(
TAG, "Domain verification v1 request for $packageName: " +
"success = $successfulHosts, failed = $failedHosts"
Expand All @@ -96,15 +84,6 @@ class CollectV1Worker(appContext: Context, params: WorkerParameters) :

appContext.packageManager.verifyIntentFilter(verificationId, resultCode, failedHosts)

//clear sp and commit here
val editor = sp?.edit()
editor?.clear()?.commit()
//delete sp file
val retOfDel = deContext?.deleteSharedPreferences(packageName)
if (DEBUG) {
Log.d(TAG, "delete sp for $packageName return $retOfDel")
}

Result.success()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,16 @@ class SingleV1RequestWorker(appContext: Context, params: WorkerParameters) :

// Coerce failure results into success so that final collection task gets a chance to run
when (result) {
is Result.Success -> {
val deContext = appContext.createDeviceProtectedStorageContext()
val sp = deContext?.getSharedPreferences(packageName, Context.MODE_PRIVATE)
sp?.edit()?.putInt("$HOST_SUCCESS_PREFIX$host", status.value)?.apply()
Result.success()
}
is Result.Failure -> {
val deContext = appContext.createDeviceProtectedStorageContext()
val sp = deContext?.getSharedPreferences(packageName, Context.MODE_PRIVATE)
sp?.edit()?.putInt("$HOST_FAILURE_PREFIX$host", status.value)?.apply()
Result.success()
}
is Result.Success -> Result.success(
Data.Builder()
.putInt("$HOST_SUCCESS_PREFIX$host", status.value)
.build()
)
is Result.Failure -> Result.success(
Data.Builder()
.putInt("$HOST_FAILURE_PREFIX$host", status.value)
.build()
)
else -> result
}
}
Expand Down

0 comments on commit 515ab1e

Please sign in to comment.