Add watch dog timer to OEMCrypto L3

Merge from Widevine repo of http://go/wvgerrit/29861

This code adds a watchdog timer to the oemcrypto initialization.  If
initialization does not finish within 5 seconds, the process will
abort.

For branch oc-dr1-dev, unlike nyc-mr2-dev, we save a metric indicating
there was a failure.

Testing: see code in patch 1.  Watch dog was forced while using Play
Movies.  The busy spinner spun for at least 5 seconds, but Play Movies
was able to restart itself.

b/62106796

Change-Id: Ib59f5bc4a484eff1dc386e07a4b198ecb713c69b
This commit is contained in:
Fred Gylys-Colwell
2017-07-13 18:56:47 -07:00
committed by Jeff Tinker
parent a81caa5bf1
commit 08debe83c2
2 changed files with 29 additions and 20 deletions

View File

@@ -418,19 +418,10 @@ class Adapter {
~Adapter() {
}
OEMCryptoResult Initialize() {
/*
* To avoid changing the function signature and function contract - declare
* a one-off metrics group to collect detailed information about how
* oemcrypto was intialized.
*
* TODO(blueeyes): Refactor this to allow Initialize to provide the
* details to the caller or to use the metrics instance provided by
* the caller.
*/
wvcdm::metrics::CryptoMetrics metrics;
OEMCryptoResult Initialize(wvcdm::metrics::CryptoMetrics* metrics) {
if (metrics == nullptr) {
return OEMCrypto_ERROR_INIT_FAILED;
}
level1_ = FunctionPointers(); // start with all null pointers.
level3_ = FunctionPointers(); // start with all null pointers.
LoadLevel3();
@@ -441,7 +432,7 @@ class Adapter {
base_path.c_str());
if (Level3_IsInApp()) {
M_RECORD(
&metrics,
metrics,
oemcrypto_initialization_mode_,
NO_TIME,
wvcdm::metrics::OEMCrypto_INITIALIZED_USING_IN_APP);
@@ -450,7 +441,7 @@ class Adapter {
if (force_level3()) {
LOGW("Test code. User requested falling back to L3");
M_RECORD(
&metrics,
metrics,
oemcrypto_initialization_mode_,
NO_TIME,
wvcdm::metrics::OEMCrypto_INITIALIZED_FORCING_L3);
@@ -460,7 +451,7 @@ class Adapter {
if (!wvcdm::Properties::GetOEMCryptoPath(&library_name)) {
LOGW("L1 library not specified. Falling back to L3");
M_RECORD(
&metrics,
metrics,
oemcrypto_initialization_mode_,
NO_TIME,
wvcdm::metrics::OEMCrypto_INITIALIZED_USING_L3_NO_L1_LIBRARY_PATH);
@@ -471,13 +462,13 @@ class Adapter {
LOGW("Could not load %s. Falling back to L3. %s", library_name.c_str(),
dlerror());
M_RECORD(
&metrics,
metrics,
oemcrypto_initialization_mode_,
NO_TIME,
wvcdm::metrics::OEMCrypto_INITIALIZED_USING_L3_L1_OPEN_FAILED);
return result;
}
if (LoadLevel1(&metrics)) {
if (LoadLevel1(metrics)) {
LOGD("OEMCrypto_Initialize Level 1 success. I will use level 1.");
} else {
level1_ = FunctionPointers(); // revert to all null pointers.
@@ -489,6 +480,9 @@ class Adapter {
}
bool LoadLevel1(wvcdm::metrics::CryptoMetrics* metrics) {
if (metrics == nullptr) {
return false;
}
level1_valid_ = true;
const uint32_t kMinimumVersion = 8;
const uint32_t kMaximumVersion = 13;
@@ -885,7 +879,7 @@ class WatchDog {
delete kAdapter;
}
kAdapter = new Adapter();
status_ = kAdapter->Initialize();
status_ = kAdapter->Initialize(&metrics_);
}
std::string FailureFilename() {
@@ -913,6 +907,11 @@ class WatchDog {
file_system.Remove(filename);
if (size == size_read && flag) {
LOGE("Previous L3 Init failed.");
M_RECORD(
&metrics_,
oemcrypto_initialization_mode_,
NO_TIME,
wvcdm::metrics::OEMCrypto_INITIALIZED_L3_INITIALIZATION_FAILED);
}
}
}
@@ -990,6 +989,15 @@ class WatchDog {
pthread_cond_t condition_;
bool running_;
bool gave_up_;
// A Metrics Group for the different initialization outcomes. Since one
// outcome is a watchdog timeout and abort on the PREVIOUS initialization,
// we put the group here, owned by the watchdog timer.
//
// TODO(blueeyes): Refactor this to allow Initialize to provide the
// details to the caller or to use the metrics instance provided by
// the caller.
wvcdm::metrics::CryptoMetrics metrics_;
};
// Function called by new worker thread in pthread_create.

View File

@@ -73,7 +73,8 @@ typedef enum OEMCryptoInitializationMode {
OEMCrypto_INITIALIZED_USING_L3_COULD_NOT_INSTALL_KEYBOX = 12,
OEMCrypto_INITIALIZED_USING_L1_INSTALLED_KEYBOX = 13,
OEMCrypto_INITIALIZED_USING_L3_INVALID_L1 = 14,
OEMCrypto_INITIALIZED_USING_L1_WITH_PROVISIONING_3_0 = 15
OEMCrypto_INITIALIZED_USING_L1_WITH_PROVISIONING_3_0 = 15,
OEMCrypto_INITIALIZED_L3_INITIALIZATION_FAILED = 16
} OEMCryptoInitializationMode;