summaryrefslogtreecommitdiff
path: root/keystore/java/android/security/KeyStoreSecurityLevel.java
diff options
context:
space:
mode:
authorJanis Danisevskis <jdanis@google.com>2021-01-22 11:17:43 -0800
committerJanis Danisevskis <jdanis@google.com>2021-01-28 09:23:21 -0800
commitf4c64ad3e20e635008e9614d4e7c65b0aeaf2b10 (patch)
tree207933b892a73f0ca3e883ce42b5d435e59a708a /keystore/java/android/security/KeyStoreSecurityLevel.java
parent5d496eb9b3388daed3ced89bc451b41149756b64 (diff)
Keystore 2.0 SPI: Add back-off hint to BackendBusyException.
BackendBusyException now returns a back-off hint that API users can use to implement their retry loop. Bug: 174761871 Test: N/A Change-Id: I95662a5a5432965de365017eae43c502eb5bfc06
Diffstat (limited to 'keystore/java/android/security/KeyStoreSecurityLevel.java')
-rw-r--r--keystore/java/android/security/KeyStoreSecurityLevel.java7
1 files changed, 4 insertions, 3 deletions
diff --git a/keystore/java/android/security/KeyStoreSecurityLevel.java b/keystore/java/android/security/KeyStoreSecurityLevel.java
index 3ef4aa5b7ec3..56dd7f049828 100644
--- a/keystore/java/android/security/KeyStoreSecurityLevel.java
+++ b/keystore/java/android/security/KeyStoreSecurityLevel.java
@@ -96,20 +96,21 @@ public class KeyStoreSecurityLevel {
} catch (ServiceSpecificException e) {
switch (e.errorCode) {
case ResponseCode.BACKEND_BUSY: {
+ long backOffHint = (long) (Math.random() * 80 + 20);
if (CompatChanges.isChangeEnabled(
KeyStore2.KEYSTORE_OPERATION_CREATION_MAY_FAIL)) {
// Starting with Android S we inform the caller about the
// backend being busy.
- throw new BackendBusyException();
+ throw new BackendBusyException(backOffHint);
} else {
// Before Android S operation creation must always succeed. So we
// just have to retry. We do so with a randomized back-off between
- // 50 and 250ms.
+ // 20 and 100ms.
// It is a little awkward that we cannot break out of this loop
// by interrupting this thread. But that is the expected behavior.
// There is some comfort in the fact that interrupting a thread
// also does not unblock a thread waiting for a binder transaction.
- interruptedPreservingSleep((long) (Math.random() * 200 + 50));
+ interruptedPreservingSleep(backOffHint);
}
break;
}