Files
android/libwvdrmengine/src/WVCDMSingleton.cpp
Alex Dale 4b267e37f9 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
2023-04-27 15:31:39 -07:00

53 lines
1.3 KiB
C++

//
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
//#define LOG_NDEBUG 0
#define LOG_TAG "WVCdm"
#include <utils/Log.h>
#include "WVCDMSingleton.h"
#include "utils/Mutex.h"
#include "utils/RefBase.h"
namespace wvdrm {
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.
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(sMetricsQueue.get());
sCdm = cdm;
}
return cdm;
}
} // namespace wvdrm