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:
Alex Dale
2023-04-27 15:31:39 -07:00
parent 666e26284f
commit 4b267e37f9
3 changed files with 91 additions and 11 deletions

View File

@@ -52,9 +52,39 @@ class WvMetricsSnapshot {
::time_t timestamp_ = 0;
};
class WvMetricsSnapshotQueue
: public android::LightRefBase<WvMetricsSnapshotQueue> {
public:
WvMetricsSnapshotQueue();
explicit WvMetricsSnapshotQueue(size_t capacity) : capacity_(capacity) {}
size_t capacity() const { return capacity_; }
size_t size() const { return snapshots_.size(); }
WvMetricsSnapshotQueue(const WvMetricsSnapshotQueue&) = delete;
WvMetricsSnapshotQueue(WvMetricsSnapshotQueue&&) = delete;
WvMetricsSnapshotQueue& operator=(const WvMetricsSnapshotQueue&) = delete;
WvMetricsSnapshotQueue& operator=(WvMetricsSnapshotQueue&&) = delete;
void PushMetrics(WvMetricsSnapshot&& snapshot);
void PushMetrics(const WvMetricsSnapshot& snapshot);
bool GetAll(std::vector<WvMetricsSnapshot>* snapshots) const;
void Clear();
private:
void ReFit();
const size_t capacity_;
mutable std::mutex mutex_;
std::deque<WvMetricsSnapshot> snapshots_;
};
class WvContentDecryptionModule : public android::RefBase, public TimerHandler {
public:
WvContentDecryptionModule();
explicit WvContentDecryptionModule(WvMetricsSnapshotQueue* metrics_queue);
virtual ~WvContentDecryptionModule();
// Static methods
@@ -308,7 +338,8 @@ class WvContentDecryptionModule : public android::RefBase, public TimerHandler {
// Contains a finite list of histories of different CDM engine instances.
// When a CDM engine is closed, its metrics will be saved.
std::deque<WvMetricsSnapshot> saved_metrics_snapshots_;
// Only used if not null.
WvMetricsSnapshotQueue* saved_metrics_snapshots_ = nullptr;
CORE_DISALLOW_COPY_AND_ASSIGN(WvContentDecryptionModule);
};