Properly close plugins on SIGTERM and exit
test: adb reboot while playing netflix and check logcat to make sure session are closed. [ Merge of http://go/wvgerrit/133063 ] bug: 193099676 Change-Id: I375695673b0c366e09fb857f5ae7a9cb6b946779
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#define WV_DRM_PLUGIN_H_
|
||||
|
||||
#include <map>
|
||||
#include <list>
|
||||
|
||||
#include "cdm_client_property_set.h"
|
||||
#include "cdm_identifier.h"
|
||||
@@ -18,6 +19,7 @@
|
||||
#include "HidlTypes.h"
|
||||
#include "WVGenericCryptoInterface.h"
|
||||
#include "WVTypes.h"
|
||||
#include <utils/Mutex.h>
|
||||
|
||||
namespace wvdrm {
|
||||
namespace hardware {
|
||||
@@ -26,6 +28,7 @@ namespace V1_4 {
|
||||
namespace widevine {
|
||||
|
||||
using std::map;
|
||||
using android::Mutex;
|
||||
using wvcdm::CdmIdentifier;
|
||||
using wvcdm::CdmKeyStatusMap;
|
||||
using wvcdm::CdmSessionId;
|
||||
@@ -45,6 +48,8 @@ struct WVDrmPlugin : public ::drm::V1_4::IDrmPlugin, IDrmPluginListener,
|
||||
|
||||
virtual ~WVDrmPlugin();
|
||||
|
||||
void Close();
|
||||
|
||||
Return<void> openSession(openSession_cb _hidl_cb) override;
|
||||
|
||||
Return<void> openSession_1_1(SecurityLevel securityLevel, openSession_1_1_cb _hidl_cb) override;
|
||||
@@ -450,6 +455,47 @@ struct WVDrmPlugin : public ::drm::V1_4::IDrmPlugin, IDrmPluginListener,
|
||||
uint32_t getNextUniqueId();
|
||||
} mCdmIdentifierBuilder;
|
||||
|
||||
// Properly close plugins on SIGTERM then exit
|
||||
class Terminator {
|
||||
public:
|
||||
static void Register(WVDrmPlugin* plugin) { instance().DoRegister(plugin); }
|
||||
static void Forget(WVDrmPlugin* plugin) { instance().DoForget(plugin); }
|
||||
static void Terminate(int /*signal*/) { instance().DoTerminate(); }
|
||||
|
||||
private:
|
||||
WVDRM_DISALLOW_COPY_AND_ASSIGN(Terminator);
|
||||
|
||||
Terminator() {
|
||||
signal(SIGTERM, Terminate);
|
||||
}
|
||||
|
||||
static Terminator& instance() {
|
||||
static Terminator instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void DoRegister(WVDrmPlugin* plugin) {
|
||||
Mutex::Autolock lock(mLock);
|
||||
mPlugins.push_back(plugin);
|
||||
}
|
||||
|
||||
void DoForget(WVDrmPlugin* plugin) {
|
||||
Mutex::Autolock lock(mLock);
|
||||
mPlugins.remove(plugin);
|
||||
}
|
||||
|
||||
void DoTerminate() {
|
||||
Mutex::Autolock lock(mLock);
|
||||
for_each(mPlugins.begin(), mPlugins.end(), [] (WVDrmPlugin* plugin) {
|
||||
plugin->Close();
|
||||
});
|
||||
exit(0);
|
||||
}
|
||||
|
||||
std::list<WVDrmPlugin*> mPlugins;
|
||||
Mutex mLock;
|
||||
};
|
||||
|
||||
sp<wvcdm::WvContentDecryptionModule> const mCDM;
|
||||
WVGenericCryptoInterface* mCrypto;
|
||||
map<CdmSessionId, CryptoSession> mCryptoSessions;
|
||||
|
||||
@@ -196,10 +196,17 @@ WVDrmPlugin::WVDrmPlugin(const sp<WvContentDecryptionModule>& cdm,
|
||||
mCDM(cdm),
|
||||
mCrypto(crypto),
|
||||
mCryptoSessions(),
|
||||
mAppPackageName(appPackageName) {}
|
||||
mAppPackageName(appPackageName) {
|
||||
Terminator::Register(this);
|
||||
}
|
||||
|
||||
WVDrmPlugin::~WVDrmPlugin() {
|
||||
wvcdm::SetLoggingUid(mCdmIdentifierBuilder.user_id());
|
||||
Terminator::Forget(this);
|
||||
Close();
|
||||
}
|
||||
|
||||
void WVDrmPlugin::Close() {
|
||||
typedef map<CdmSessionId, CryptoSession>::iterator mapIterator;
|
||||
for (mapIterator iter = mCryptoSessions.begin();
|
||||
iter != mCryptoSessions.end();
|
||||
|
||||
Reference in New Issue
Block a user