Allow metrics history to outlive the Android CDM.
[ Merge of http://go/wvgerrit/172910 ] The lifecycle of the Android CDM is controlled by Android's strong/ weak pointer functionality. Unfortunately, it does not provide an easily predictable point in the code where the CDM is to be deleted along with the saved metrics. In order to allow the CDM to keep a list of metrics that are persistent with the life of the service, a global thread safe queue is provided which is created when the first CDM is created, but will out live the CDM. The metrics will still be deleted when the DRM service is terminated. Bug: 270166158 Test: adb shell dumpsys android.hardware.drm.IDrmFactory/widevine -m Change-Id: Id98676d8b5278798b4de332cc272cd5b85024244
This commit is contained in:
@@ -86,10 +86,48 @@ std::string WvMetricsSnapshot::GetFormattedTimestamp() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
WvMetricsSnapshotQueue::WvMetricsSnapshotQueue()
|
||||
: capacity_(kMaxSavedMetricsSnapshotCount) {}
|
||||
|
||||
void WvMetricsSnapshotQueue::PushMetrics(WvMetricsSnapshot&& snapshot) {
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
snapshots_.push_front(std::move(snapshot));
|
||||
ReFit();
|
||||
}
|
||||
|
||||
void WvMetricsSnapshotQueue::PushMetrics(const WvMetricsSnapshot& snapshot) {
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
snapshots_.push_front(snapshot);
|
||||
ReFit();
|
||||
}
|
||||
|
||||
bool WvMetricsSnapshotQueue::GetAll(
|
||||
std::vector<WvMetricsSnapshot>* snapshots) const {
|
||||
if (snapshots == nullptr) return false;
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
snapshots->assign(snapshots_.begin(), snapshots_.end());
|
||||
return true;
|
||||
}
|
||||
|
||||
void WvMetricsSnapshotQueue::Clear() {
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
snapshots_.clear();
|
||||
}
|
||||
|
||||
void WvMetricsSnapshotQueue::ReFit() {
|
||||
if (capacity_ > 0 && snapshots_.size() > capacity_) {
|
||||
snapshots_.resize(capacity_);
|
||||
}
|
||||
}
|
||||
|
||||
std::mutex WvContentDecryptionModule::session_sharing_id_generation_lock_;
|
||||
|
||||
WvContentDecryptionModule::WvContentDecryptionModule() {}
|
||||
|
||||
WvContentDecryptionModule::WvContentDecryptionModule(
|
||||
WvMetricsSnapshotQueue* metrics_queue)
|
||||
: saved_metrics_snapshots_(metrics_queue) {}
|
||||
|
||||
WvContentDecryptionModule::~WvContentDecryptionModule() {
|
||||
CryptoSession::DisableDelayedTermination();
|
||||
CloseAllCdms();
|
||||
@@ -497,11 +535,16 @@ CdmResponseType WvContentDecryptionModule::GetAllSavedMetricsSnapshots(
|
||||
if (snapshots == nullptr) {
|
||||
return CdmResponseType(PARAMETER_NULL);
|
||||
}
|
||||
std::unique_lock<std::mutex> auto_lock(cdms_lock_);
|
||||
if (saved_metrics_snapshots_ == nullptr) {
|
||||
snapshots->clear();
|
||||
// Storing the metrics might not be available in some cases.
|
||||
return CdmResponseType(NO_ERROR);
|
||||
}
|
||||
// This has the potential to be an expensive operation. However,
|
||||
// this function is only used during debug reporting.
|
||||
snapshots->assign(saved_metrics_snapshots_.cbegin(),
|
||||
saved_metrics_snapshots_.cend());
|
||||
if (!saved_metrics_snapshots_->GetAll(snapshots)) {
|
||||
return CdmResponseType(UNKNOWN_ERROR);
|
||||
}
|
||||
return CdmResponseType(NO_ERROR);
|
||||
}
|
||||
|
||||
@@ -521,12 +564,9 @@ CdmResponseType WvContentDecryptionModule::GetCurrentMetricsInternal(
|
||||
|
||||
void WvContentDecryptionModule::SaveMetrics(
|
||||
const CdmIdentifier& identifier, drm_metrics::WvCdmMetrics&& metrics) {
|
||||
// Caller should have acquired |cdms_lock_|.
|
||||
saved_metrics_snapshots_.push_front(
|
||||
if (saved_metrics_snapshots_ == nullptr) return;
|
||||
saved_metrics_snapshots_->PushMetrics(
|
||||
WvMetricsSnapshot::MakeSnapshot(identifier, std::move(metrics)));
|
||||
if (saved_metrics_snapshots_.size() > kMaxSavedMetricsSnapshotCount) {
|
||||
saved_metrics_snapshots_.resize(kMaxSavedMetricsSnapshotCount);
|
||||
}
|
||||
}
|
||||
|
||||
WvContentDecryptionModule::CdmInfo::CdmInfo()
|
||||
|
||||
Reference in New Issue
Block a user