Fix handling of INSUFFICIENT_RESOURCES in LoadEntry

Bug: b/121214641
Merge of http://go/wvgerrit/69703
Test: Android + Linux unit tests

LoadEntry attempts to handle INSUFFICIENT_RESOURCES by deleting an entry
and retrying, but it's possible that the randomly-generated number of
the entry to be deleted might match the entry we want to load. In this
case, we have wasted a retry, since the code just continues on to the
next iteration. This is changed to generate a number different from the
entry to load. Furthermore, if the number of usage entries is 1, we
break since there are no more entries to delete besides the one we want
to load. The code is also changed to call srand in the creation of the
usage_table_header, since without it, rand() would produce the same
values, and similarly, our random generation is changed to use a simple
mod. Tests are modified to reflect these changes.

Change-Id: I95e125b8adbd85d0189f9d40ca15f3fe69e6d6b9
This commit is contained in:
Srujan Gaddam
2019-01-07 16:58:59 -08:00
parent 40bd0d5209
commit 13b5c48512
3 changed files with 54 additions and 24 deletions

View File

@@ -79,6 +79,11 @@ class UsageTableHeader {
// for the objects that DeleteEntry depends on.
void DeleteEntryForTest(uint32_t usage_entry_number);
// TODO(rfrias): Move to utility class
static int64_t GetRandomInRange(size_t upper_bound_exclusive);
static int64_t GetRandomInRangeWithExclusion(size_t upper_bound_exclusive,
size_t exclude);
private:
CdmResponseType MoveEntry(uint32_t from /* usage entry number */,
const CdmUsageEntry& from_usage_entry,
@@ -127,9 +132,6 @@ class UsageTableHeader {
metrics::CryptoMetrics alternate_crypto_metrics_;
// TODO(rfrias): Move to utility class
uint32_t GetRandomInRange(size_t upper_bound_inclusive);
// Test related declarations
friend class UsageTableHeaderTest;