Add arguments to Widevine lshal debug hook.

Add options to dump Widevine Cdm properties,
Widevine Cdm metrics, or both.

The valid arguments are Cdm Metrics (m|M) or Cdm Properties (p|P).
If no arguments are provided, both Cdm properties and
Cdm metrics will be displayed.

Test: adb shell lshal debug [drm service] [m/p]
  adb shell lshal debug android.hardware.drm@1.3::IDrmFactory/widevine

Bug: 154027349
Change-Id: I95c10dd7d4274226936295c73be4eb1612c2ef6a
This commit is contained in:
Edwin Wong
2020-06-30 17:47:55 -07:00
parent 37b8b51a22
commit 5b8d21164d
7 changed files with 569 additions and 15 deletions

View File

@@ -19,6 +19,7 @@
#include "cutils/properties.h"
#include "wv_cdm_constants.h"
#include "wv_content_decryption_module.h"
#include "wv_metrics.h"
namespace wvdrm {
namespace hardware {
@@ -148,6 +149,39 @@ std::string WVDrmFactory::stringToHex(const std::string& input) {
return output;
}
void WVDrmFactory::printCdmMetrics(FILE* out) {
fprintf(out, "\n**** Widevine Cdm Metrics ****\n");
// Verify that the version of the library that we linked against is
// compatible with the version of the headers we compiled against.
GOOGLE_PROTOBUF_VERIFY_VERSION;
sp<wvcdm::WvContentDecryptionModule> cdm(getCDM());
std::vector<drm_metrics::WvCdmMetrics> metrics;
bool full_list_returned = true;
wvcdm::CdmResponseType result =
cdm->GetMetrics(&metrics, &full_list_returned);
if (metrics.empty()) {
fprintf(out,
"Metrics not available, please retry while streaming a video\n");
} else if (!full_list_returned) {
fprintf(out,
"Not all metrics are returned due to some GetMetric error, "
"please check logcat for possible GetMetric errors.\n");
}
if (result == wvcdm::NO_ERROR) {
for (auto& metric : metrics) {
fprintf(out, "*** Metric size=%zu\n", metric.DebugString().size());
std::string formatted;
wv_metrics::FormatWvCdmMetrics(metric, formatted);
fprintf(out, "%s\n", formatted.c_str());
}
} else {
fprintf(out, "GetMetrics failed, error=%d\n", result);
}
}
void WVDrmFactory::printCdmProperties(FILE* out) {
fprintf(out, "\n**** Widevine CDM properties ****\n");
@@ -155,7 +189,7 @@ void WVDrmFactory::printCdmProperties(FILE* out) {
const bool isLevel1 =
cdm->IsSecurityLevelSupported(wvcdm::CdmSecurityLevel::kSecurityLevelL1);
fprintf(out, "current security level: [%s]\n", isLevel1 ? "L1" : "L3");
fprintf(out, "default security level: [%s]\n", isLevel1 ? "L1" : "L3");
std::map<std::string, std::string> cdmProperties = {
{"version- Widevine CDM:", wvcdm::QUERY_KEY_WVCDM_VERSION},
@@ -165,7 +199,7 @@ void WVDrmFactory::printCdmProperties(FILE* out) {
{"version(minor)- OEM Crypto API:",
wvcdm::QUERY_KEY_OEMCRYPTO_API_MINOR_VERSION},
{"id- device:", wvcdm::QUERY_KEY_DEVICE_ID},
{"id- systen:", wvcdm::QUERY_KEY_SYSTEM_ID},
{"id- system:", wvcdm::QUERY_KEY_SYSTEM_ID},
{"renewal server url:", wvcdm::QUERY_KEY_RENEWAL_SERVER_URL},
{"hdcp level- max:", wvcdm::QUERY_KEY_MAX_HDCP_LEVEL},
{"hdcp level- current:", wvcdm::QUERY_KEY_CURRENT_HDCP_LEVEL},
@@ -192,14 +226,40 @@ void WVDrmFactory::printCdmProperties(FILE* out) {
}
Return<void> WVDrmFactory::debug(const hidl_handle& fd,
const hidl_vec<hidl_string>& /*args*/) {
const hidl_vec<hidl_string>& args) {
if (fd.getNativeHandle() == nullptr || fd->numFds < 1) {
ALOGE("%s: missing fd for writing", __FUNCTION__);
return Void();
}
FILE* out = fdopen(dup(fd->data[0]), "w");
printCdmProperties(out);
fprintf(out, "\nDefault to print all info if no arguments are used.\n");
fprintf(out, "Optional arguments are:\n");
fprintf(out, "\tm:cdm metrics | p:cdm properties\n");
fprintf(out,
"Usage: adb shell lshal debug "
"android.hardware.drm@1.3::IDrmFactory/widevine [m|p]\n");
bool dumpCdmProperties, dumpCdmMetrics = false;
if (args.size() == 0) {
// default to print all info if no arguments are given
dumpCdmProperties = dumpCdmMetrics = true;
} else {
for (auto& str : args) {
fprintf(out, "args: %s\n", str.c_str());
std::string option = str.c_str();
if (option.find('m') != std::string::npos ||
option.find('M') != std::string::npos) {
dumpCdmMetrics = true;
}
if (option.find('p') != std::string::npos ||
option.find('P') != std::string::npos) {
dumpCdmProperties = true;
}
}
}
if (dumpCdmMetrics) printCdmMetrics(out);
if (dumpCdmProperties) printCdmProperties(out);
fclose(out);
return Void();