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

@@ -15,12 +15,16 @@
namespace wvdrm {
using wvcdm::WvContentDecryptionModule;
using android::Mutex;
using android::sp;
using android::wp;
using wvcdm::WvContentDecryptionModule;
using wvcdm::WvMetricsSnapshotQueue;
Mutex cdmLock;
// TODO(b/270166158): Make this a loadable/storable when provided
// a special debug property.
sp<WvMetricsSnapshotQueue> sMetricsQueue;
// The strong pointers that keep this object alive live in the plugin objects.
// If all the plugins are deleted, the CDM will be deleted, and subsequent
// invocations of this code will construct a new CDM.
@@ -29,11 +33,16 @@ wp<WvContentDecryptionModule> sCdm;
sp<WvContentDecryptionModule> getCDM() {
Mutex::Autolock lock(cdmLock); // This function is a critical section.
if (sMetricsQueue == nullptr) {
ALOGD("Instantiating CDM metrics queue");
sMetricsQueue = new WvMetricsSnapshotQueue();
}
sp<WvContentDecryptionModule> cdm = sCdm.promote();
if (cdm == NULL) {
ALOGD("Instantiating CDM.");
cdm = new WvContentDecryptionModule();
cdm = new WvContentDecryptionModule(sMetricsQueue.get());
sCdm = cdm;
}