Skip to content

Commit 3b64d4c

Browse files
committed
refactor: Add deprecation annotations for old/ redundant versions of secure store
1 parent f3e9478 commit 3b64d4c

5 files changed

Lines changed: 101 additions & 1 deletion

File tree

app/src/main/java/uk/gov/android/securestore/RetrievalEvent.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ package uk.gov.android.securestore
22

33
import uk.gov.android.securestore.error.SecureStoreErrorType
44

5-
/**
5+
6+
@Deprecated(
7+
"Replace with RetrievalEventV2 to allow handling errors correctly - aim to be removed by 20th of April 2026",
8+
replaceWith = ReplaceWith("java/uk/gov/android/securestore/RetrievalEventV2.kt"),
9+
level = DeprecationLevel.WARNING
10+
)/**
611
* Class to handle the return events when getting data from a [SecureStore]
712
*/
813
sealed class RetrievalEvent {

app/src/main/java/uk/gov/android/securestore/SecureStoreAsync.kt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import androidx.fragment.app.FragmentActivity
55
import kotlinx.coroutines.flow.Flow
66
import uk.gov.android.securestore.authentication.AuthenticatorPromptConfiguration
77

8+
@Deprecated(
9+
"Replace with SecureStoreAsyncV2 to allow handling errors correctly - aim to be removed by 20th of April 2026",
10+
replaceWith = ReplaceWith("java/uk/gov/android/securestore/SecureStoreAsyncV2.kt"),
11+
level = DeprecationLevel.WARNING
12+
)
813
/**
914
* Create an instance of [SecureStoreAsync] to save, query and delete data. Data stored as a key value pair, with the value being a [String]
1015
*/
@@ -15,6 +20,11 @@ interface SecureStoreAsync {
1520
* @param context Just a basic context to allow initialisation of storage
1621
* @param configurationAsync [SecureStorageConfigurationAsync] to allow setting of [AccessControlLevel] and store ID
1722
*/
23+
@Deprecated(
24+
"Replace with SecureStoreAsyncV2.init() to allow handling errors correctly - aim to be removed by 20th of April 2026",
25+
replaceWith = ReplaceWith("java/uk/gov/android/securestore/SecureStoreAsyncV2.kt"),
26+
level = DeprecationLevel.WARNING
27+
)
1828
fun init(
1929
context: Context,
2030
configurationAsync: SecureStorageConfigurationAsync,
@@ -28,6 +38,11 @@ interface SecureStoreAsync {
2838
*
2939
* @throws [uk.gov.android.securestore.error.SecureStorageError] if unable to save
3040
*/
41+
@Deprecated(
42+
"Replace with SecureStoreAsyncV2.upsert() to allow handling errors correctly - aim to be removed by 20th of April 2026",
43+
replaceWith = ReplaceWith("java/uk/gov/android/securestore/SecureStoreAsyncV2.kt"),
44+
level = DeprecationLevel.WARNING
45+
)
3146
suspend fun upsert(key: String, value: String): String
3247

3348
/**
@@ -36,13 +51,23 @@ interface SecureStoreAsync {
3651
* @param [key] The unique identifier for the value to delete
3752
*
3853
*/
54+
@Deprecated(
55+
"Replace with SecureStoreAsyncV2.delete(...) to allow handling errors correctly - aim to be removed by 20th of April 2026",
56+
replaceWith = ReplaceWith("java/uk/gov/android/securestore/SecureStoreAsyncV2.kt"),
57+
level = DeprecationLevel.WARNING
58+
)
3959
fun delete(key: String)
4060

4161
/**
4262
* Delete everything in the SecureStore
4363
*
4464
* @throws [uk.gov.android.securestore.error.SecureStorageError] if unable to delete
4565
*/
66+
@Deprecated(
67+
"Replace with SecureStoreAsyncV2.deleteAll(...) to allow handling errors correctly - aim to be removed by 20th of April 2026",
68+
replaceWith = ReplaceWith("java/uk/gov/android/securestore/SecureStoreAsyncV2.kt"),
69+
level = DeprecationLevel.WARNING
70+
)
4671
suspend fun deleteAll()
4772

4873
/**
@@ -52,6 +77,11 @@ interface SecureStoreAsync {
5277
* @return [RetrievalEvent] to cover success or failure
5378
*
5479
*/
80+
@Deprecated(
81+
"Replace with SecureStoreAsyncV2.retrieve() to allow handling errors correctly - aim to be removed by 20th of April 2026",
82+
replaceWith = ReplaceWith("java/uk/gov/android/securestore/SecureStoreAsyncV2.kt"),
83+
level = DeprecationLevel.WARNING
84+
)
5585
suspend fun retrieve(
5686
vararg key: String,
5787
): RetrievalEvent
@@ -65,6 +95,11 @@ interface SecureStoreAsync {
6595
* @return A [Flow] of [RetrievalEvent]s, allowing for multiple failed attempts for auth
6696
*
6797
*/
98+
@Deprecated(
99+
"Replace with SecureStoreAsyncV2.retrieveWithAuthentication(...) to allow handling errors correctly - aim to be removed by 20th of April 2026",
100+
replaceWith = ReplaceWith("java/uk/gov/android/securestore/SecureStoreAsyncV2.kt"),
101+
level = DeprecationLevel.WARNING
102+
)
68103
suspend fun retrieveWithAuthentication(
69104
vararg key: String,
70105
authPromptConfig: AuthenticatorPromptConfiguration,
@@ -79,5 +114,10 @@ interface SecureStoreAsync {
79114
*
80115
* @throws [uk.gov.android.securestore.error.SecureStorageError] if unable to check for existence
81116
*/
117+
@Deprecated(
118+
"Replace with SecureStoreAsyncV2.exists(...) to allow handling errors correctly - aim to be removed by 20th of April 2026",
119+
replaceWith = ReplaceWith("java/uk/gov/android/securestore/SecureStoreAsyncV2.kt"),
120+
level = DeprecationLevel.WARNING
121+
)
82122
fun exists(key: String): Boolean
83123
}

app/src/main/java/uk/gov/android/securestore/SharedPrefsStoreAsync.kt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,23 @@ import uk.gov.android.securestore.error.SecureStoreErrorType
1717
import kotlin.coroutines.suspendCoroutine
1818

1919
@Suppress("TooGenericExceptionCaught", "TooManyFunctions")
20+
@Deprecated(
21+
"Replace with SecureStoreAsyncV2 to allow handling errors correctly - aim to be removed by 20th of April 2026",
22+
replaceWith = ReplaceWith("java/uk/gov/android/securestore/SharedPrefsStoreAsyncV2.kt"),
23+
level = DeprecationLevel.WARNING
24+
)
2025
class SharedPrefsStoreAsync(
2126
private val authenticator: Authenticator = UserAuthenticator(),
2227
private val hybridCryptoManagerAsync: HybridCryptoManagerAsync = HybridCryptoManagerAsyncImpl(),
2328
) : SecureStoreAsync {
2429
private var configurationAsync: SecureStorageConfigurationAsync? = null
2530
private var sharedPrefs: SharedPreferences? = null
2631

32+
@Deprecated(
33+
"Replace with SecureStoreAsyncV2.init() to allow handling errors correctly - aim to be removed by 20th of April 2026",
34+
replaceWith = ReplaceWith("java/uk/gov/android/securestore/SecureStoreAsyncV2.kt"),
35+
level = DeprecationLevel.WARNING
36+
)
2737
override fun init(
2838
context: Context,
2939
configurationAsync: SecureStorageConfigurationAsync,
@@ -37,6 +47,11 @@ class SharedPrefsStoreAsync(
3747
sharedPrefs = context.getSharedPreferences(configurationAsync.id, Context.MODE_PRIVATE)
3848
}
3949

50+
@Deprecated(
51+
"Replace with SecureStoreAsyncV2.upsert() to allow handling errors correctly - aim to be removed by 20th of April 2026",
52+
replaceWith = ReplaceWith("java/uk/gov/android/securestore/SecureStoreAsyncV2.kt"),
53+
level = DeprecationLevel.WARNING
54+
)
4055
override suspend fun upsert(key: String, value: String): String {
4156
return try {
4257
val result = hybridCryptoManagerAsync.encrypt(value)
@@ -50,12 +65,22 @@ class SharedPrefsStoreAsync(
5065
}
5166
}
5267

68+
@Deprecated(
69+
"Replace with SecureStoreAsyncV2.delete(...) to allow handling errors correctly - aim to be removed by 20th of April 2026",
70+
replaceWith = ReplaceWith("java/uk/gov/android/securestore/SecureStoreAsyncV2.kt"),
71+
level = DeprecationLevel.WARNING
72+
)
5373
override fun delete(key: String) {
5474
sharedPrefs?.edit {
5575
remove(key)
5676
}
5777
}
5878

79+
@Deprecated(
80+
"Replace with SecureStoreAsyncV2.deleteAll(...) to allow handling errors correctly - aim to be removed by 20th of April 2026",
81+
replaceWith = ReplaceWith("java/uk/gov/android/securestore/SecureStoreAsyncV2.kt"),
82+
level = DeprecationLevel.WARNING
83+
)
5984
override suspend fun deleteAll() {
6085
sharedPrefs?.edit {
6186
clear()
@@ -67,6 +92,11 @@ class SharedPrefsStoreAsync(
6792
}
6893
}
6994

95+
@Deprecated(
96+
"Replace with SecureStoreAsyncV2.retrieve() to allow handling errors correctly - aim to be removed by 20th of April 2026",
97+
replaceWith = ReplaceWith("java/uk/gov/android/securestore/SecureStoreAsyncV2.kt"),
98+
level = DeprecationLevel.WARNING
99+
)
70100
override suspend fun retrieve(
71101
vararg key: String,
72102
): RetrievalEvent {
@@ -93,6 +123,11 @@ class SharedPrefsStoreAsync(
93123
)
94124
}
95125

126+
@Deprecated(
127+
"Replace with SecureStoreAsyncV2.retrieveWithAuthentication(...) to allow handling errors correctly - aim to be removed by 20th of April 2026",
128+
replaceWith = ReplaceWith("java/uk/gov/android/securestore/SecureStoreAsyncV2.kt"),
129+
level = DeprecationLevel.WARNING
130+
)
96131
@Suppress("NestedBlockDepth", "LongMethod")
97132
override suspend fun retrieveWithAuthentication(
98133
vararg key: String,
@@ -155,6 +190,11 @@ class SharedPrefsStoreAsync(
155190
return result
156191
}
157192

193+
@Deprecated(
194+
"Replace with SecureStoreAsyncV2.exists(...) to allow handling errors correctly - aim to be removed by 20th of April 2026",
195+
replaceWith = ReplaceWith("java/uk/gov/android/securestore/SecureStoreAsyncV2.kt"),
196+
level = DeprecationLevel.WARNING
197+
)
158198
override fun exists(key: String): Boolean {
159199
return sharedPrefs?.contains(key) == true
160200
}

app/src/main/java/uk/gov/android/securestore/error/ErrorTypeHandler.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ package uk.gov.android.securestore.error
22

33
import android.security.keystore.UserNotAuthenticatedException
44

5+
@Deprecated(
6+
"Replace with ErrorTypeHandlerV2 to allow handling errors correctly - aim to be removed by 20th of April 2026",
7+
replaceWith = ReplaceWith("java/uk/gov/android/securestore/error/ErrorTypeHandlerV2.kt"),
8+
level = DeprecationLevel.WARNING
9+
)
510
object ErrorTypeHandler {
611
fun getErrorType(error: SecureStorageError): SecureStoreErrorType {
712
return when (error.cause) {

app/src/main/java/uk/gov/android/securestore/error/SecureStorageError.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
package uk.gov.android.securestore.error
22

3+
@Deprecated(
4+
"Replace with SecureStorageErrorV2 to allow handling errors correctly - aim to be removed by 20th of April 2026",
5+
replaceWith = ReplaceWith("java/uk/gov/android/securestore/error/SecureStorageErrorV2.kt"),
6+
level = DeprecationLevel.WARNING
7+
)
38
class SecureStorageError(
49
exception: Exception,
510
val type: SecureStoreErrorType = SecureStoreErrorType.GENERAL,
611
) : Error(exception)
712

13+
@Deprecated(
14+
"Replace with SecureStoreErrorTypeV2 to allow handling errors correctly - aim to be removed by 20th of April 2026",
15+
replaceWith = ReplaceWith("java/uk/gov/android/securestore/error/SecureStorageErrorV2.kt"),
16+
level = DeprecationLevel.WARNING
17+
)
818
enum class SecureStoreErrorType {
919
GENERAL,
1020
NOT_FOUND,

0 commit comments

Comments
 (0)