Close session during capacity check.

[ Merge of http://go/wvgerrit/178217 ]
[ Cherry-pick of http://ag/24029327 ]

For devices with a large number of usage entries, when restoring the
usage table a capacity check is performed.  This checks that a new
entry can be created.  This test was originally added as some devices
might enter a "stuck" state the table cannot be initialized.

To perform this test, a temporary crypto session is created and an
entry is created for that session.  After successfully creating that
entry, the entry is deleted.  However, because the session was left
open, the entry could not be deleted.

This change closes the capacity-check-session before deleting the
entry, as well as includes additional logs for helping future debugs.

Bug: 286176947
Test: usage_table_header_unittest
Test: Android GTS R11 on oriole
Change-Id: I6923de00175f70b2392bfe581ca5f9ae60c4af25
(cherry picked from commit 8b4bbeeb6f440c48a3250b961f7a7dab2472d7e9)
This commit is contained in:
Alex Dale
2023-07-11 15:19:39 -07:00
parent 14f7594f5e
commit bb925c46e5

View File

@@ -384,6 +384,9 @@ CdmResponseType CdmUsageTable::InvalidateEntryInternal(
// sent back to the caller for the CDM as a whole to handle.
const uint32_t pre_defrag_store_counter = store_table_counter_;
const CdmResponseType status = DefragTable(device_files, metrics);
if (status != NO_ERROR) {
LOGW("Failed to defrag usage table: sts = %s", status.ToString().c_str());
}
if (pre_defrag_store_counter == store_table_counter_) {
// It is possible that DefragTable() does not result in any
// changes to the table, and as a result, it will not store the
@@ -470,6 +473,10 @@ bool CdmUsageTable::CapacityCheck(CryptoSession* const crypto_session) {
return false;
}
// Session must be closed before invalidating, otherwise Shrink() will
// fail in call to InvalidateEntry().
local_crypto_session->Close();
status =
InvalidateEntry(temporary_entry_index,
/* defrag_table = */ true, device_files_.get(), metrics);
@@ -482,7 +489,10 @@ bool CdmUsageTable::CapacityCheck(CryptoSession* const crypto_session) {
// The entry should have been deleted from the usage table,
// not just marked as type unknown. Failure to call
// Shrink() may be an indicator of other issues.
LOGE("Failed to shrink table for capacity test");
LOGE(
"Failed to shrink table for capacity test: "
"post_check_size = %zu, check_usage_entry_number = %u",
entry_info_list_.size(), temporary_entry_index);
return false;
}
return true;
@@ -954,7 +964,12 @@ CdmResponseType CdmUsageTable::DefragTable(DeviceFiles* device_files,
if (entries_to_move.empty()) {
LOGD("No valid entries found, shrinking entire table: size = %zu",
entry_info_list_.size());
return Shrink(metrics, static_cast<uint32_t>(entry_info_list_.size()));
const CdmResponseType status =
Shrink(metrics, static_cast<uint32_t>(entry_info_list_.size()));
if (status != NO_ERROR) {
LOGE("Failed to shrink table: sts = %s", status.ToString().c_str());
}
return status;
}
// Step 3: Ignore invalid entries that are after the last valid
@@ -978,7 +993,11 @@ CdmResponseType CdmUsageTable::DefragTable(DeviceFiles* device_files,
last_valid_entry - 1;
LOGD("Removing all entries after the last valid entry: count = %u",
to_remove);
return Shrink(metrics, to_remove);
const CdmResponseType status = Shrink(metrics, to_remove);
if (status != NO_ERROR) {
LOGE("Failed to shrink table: sts = %s", status.ToString().c_str());
}
return status;
}
// Step 4: Move the valid entries to overwrite the invalid entries.
@@ -1106,7 +1125,12 @@ CdmResponseType CdmUsageTable::DefragTable(DeviceFiles* device_files,
LOGD(
"All entries have been invalidated, shrinking entire table: size = %zu",
entry_info_list_.size());
return Shrink(metrics, static_cast<uint32_t>(entry_info_list_.size()));
const CdmResponseType status =
Shrink(metrics, static_cast<uint32_t>(entry_info_list_.size()));
if (status != NO_ERROR) {
LOGE("Failed to shrink table: sts = %s", status.ToString().c_str());
}
return status;
}
const UsageEntryIndex to_remove =
@@ -1125,7 +1149,11 @@ CdmResponseType CdmUsageTable::DefragTable(DeviceFiles* device_files,
// Step 6: Shrink table to the new size.
LOGD("Clean up complete, shrinking table: count = %u", to_remove);
return Shrink(metrics, to_remove);
const CdmResponseType status = Shrink(metrics, to_remove);
if (status != NO_ERROR) {
LOGE("Failed to shrink table: sts = %s", status.ToString().c_str());
}
return status;
} // End Defrag().
CdmResponseType CdmUsageTable::ReleaseOldestEntry(