diff --git a/libwvdrmengine/cdm/core/src/crypto_session.cpp b/libwvdrmengine/cdm/core/src/crypto_session.cpp index 9f21fb63..2e82e246 100644 --- a/libwvdrmengine/cdm/core/src/crypto_session.cpp +++ b/libwvdrmengine/cdm/core/src/crypto_session.cpp @@ -674,6 +674,7 @@ CdmResponseType CryptoSession::Open(SecurityLevel requested_security_level) { return LOAD_SYSTEM_ID_ERROR; } + // Set up request ID uint64_t request_id_base; OEMCryptoResult random_sts; WithOecReadLock("Open() calling OEMCrypto_GetRandom", [&] { @@ -688,6 +689,22 @@ CdmResponseType CryptoSession::Open(SecurityLevel requested_security_level) { HexEncode(reinterpret_cast(&request_id_index), sizeof(request_id_index)); + // Initialize key session + WithOecSessionLock("Open() calling key_session_.reset()", [&] { + key_session_.reset(new ContentKeySession(oec_session_id_, metrics_)); + }); + + // Set up Usage Table support + // + // This MUST be the last thing in the function because it contains the + // successful return paths of the function. It will attempt to initialize + // usage tables. However, whether they are employed is determined by + // information in the license, which will not be received until later. In case + // usage tables are not even needed, initialization errors here are ignored by + // returning successfully. + // + // TODO(b/141350978): Refactor this code so that it does not have this + // problem. if (!GetApiVersion(&api_version_)) { LOGE("Failed to get API version"); return USAGE_SUPPORT_GET_API_FAILED; @@ -735,9 +752,12 @@ CdmResponseType CryptoSession::Open(SecurityLevel requested_security_level) { metrics_->oemcrypto_usage_table_support_.SetError(result); } - WithOecSessionLock("Open() calling key_session_.reset()", [&] { - key_session_.reset(new ContentKeySession(oec_session_id_, metrics_)); - }); + // Do not add logic after this point as it may never get exercised. In the + // event of errors initializing the usage tables, the code will return early, + // never reaching this point. See the comment above the "Set up Usage Table + // support" section for details. + // + // TODO(b/139973602): Refactor this code. return NO_ERROR; }