Confirmationui Rate Limiting App Abort Bug Fix
Increment the rate limiting counter when the application sends an abort
message.
Bug: 138655142
Test: Ran keystore_unit_tests and manually checked behavior of
keystore application with confimrationui.
Merged-In: I5f3af166391a32748a26f7709d30a5ac718499c0
Change-Id: I5f3af166391a32748a26f7709d30a5ac718499c0
diff --git a/keystore/confirmationui_rate_limiting.h b/keystore/confirmationui_rate_limiting.h
index 12c20fa..658bf41 100644
--- a/keystore/confirmationui_rate_limiting.h
+++ b/keystore/confirmationui_rate_limiting.h
@@ -29,8 +29,8 @@
using ConfirmationResponseCode = android::hardware::confirmationui::V1_0::ResponseCode;
-using std::chrono::time_point;
using std::chrono::duration;
+using std::chrono::time_point;
template <typename Clock = std::chrono::steady_clock> class RateLimiting {
private:
@@ -96,7 +96,17 @@
return false;
}
+ // The app is penalized for cancelling a request. Request are rolled back only if
+ // the prompt was cancelled by the system: e.g. a system error or asynchronous event.
+ // When the user cancels the prompt, it is subject to rate limiting.
+ static constexpr const uint_t kInvalidRequester = -1;
+
+ void cancelPrompt() { latest_requester_ = kInvalidRequester; }
+
void processResult(ConfirmationResponseCode rc) {
+ if (latest_requester_ == kInvalidRequester) {
+ return;
+ }
switch (rc) {
case ConfirmationResponseCode::OK:
// reset the counter slot