blob: ac589290f02678a2a3f3cbdf54eed7bc148d760b [file] [log] [blame]
Ray Essick6ce27e52019-02-15 10:58:05 -08001/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//#define LOG_NDEBUG 0
18#define LOG_TAG "statsd_drm"
19#include <utils/Log.h>
20
21#include <stdint.h>
22#include <inttypes.h>
23#include <sys/types.h>
24#include <sys/stat.h>
25#include <sys/time.h>
26#include <dirent.h>
27#include <pthread.h>
28#include <unistd.h>
29
30#include <string.h>
31#include <pwd.h>
32
Ray Essick40e8e5e2019-12-05 20:19:40 -080033#include "MediaMetricsService.h"
Ray Essick6ce27e52019-02-15 10:58:05 -080034#include "iface_statsd.h"
35
36#include <statslog.h>
37
Robert Shih5edf2452020-02-08 14:58:05 -080038#include <array>
39#include <string>
40
Ray Essick6ce27e52019-02-15 10:58:05 -080041namespace android {
42
43// mediadrm
Ray Essickf27e9872019-12-07 06:28:46 -080044bool statsd_mediadrm(const mediametrics::Item *item)
Ray Essick6ce27e52019-02-15 10:58:05 -080045{
Andy Hung3ab1b322020-05-18 10:47:31 -070046 if (item == nullptr) return false;
Ray Essick6ce27e52019-02-15 10:58:05 -080047
Ray Essickf27e9872019-12-07 06:28:46 -080048 const nsecs_t timestamp = MediaMetricsService::roundTime(item->getTimestamp());
Ray Essick6ce27e52019-02-15 10:58:05 -080049 std::string pkgName = item->getPkgName();
50 int64_t pkgVersionCode = item->getPkgVersionCode();
51 int64_t mediaApexVersion = 0;
52
Ray Essicka38704a2020-06-01 13:56:28 -070053 std::string vendor;
54 (void) item->getString("vendor", &vendor);
55 std::string description;
56 (void) item->getString("description", &description);
57 std::string serialized_metrics;
58 (void) item->getString("serialized_metrics", &serialized_metrics);
Ray Essick6ce27e52019-02-15 10:58:05 -080059
60 if (enabled_statsd) {
Ray Essicka38704a2020-06-01 13:56:28 -070061 android::util::BytesField bf_serialized(serialized_metrics.c_str(),
62 serialized_metrics.size());
Ray Essick6ce27e52019-02-15 10:58:05 -080063 android::util::stats_write(android::util::MEDIAMETRICS_MEDIADRM_REPORTED,
64 timestamp, pkgName.c_str(), pkgVersionCode,
65 mediaApexVersion,
Ray Essicka38704a2020-06-01 13:56:28 -070066 vendor.c_str(),
67 description.c_str(),
Ray Essick6ce27e52019-02-15 10:58:05 -080068 bf_serialized);
69 } else {
Ray Essicka38704a2020-06-01 13:56:28 -070070 ALOGV("NOT sending: mediadrm private data (len=%zu)", serialized_metrics.size());
Ray Essick6ce27e52019-02-15 10:58:05 -080071 }
72
Ray Essick6ce27e52019-02-15 10:58:05 -080073 return true;
74}
75
76// widevineCDM
Ray Essickf27e9872019-12-07 06:28:46 -080077bool statsd_widevineCDM(const mediametrics::Item *item)
Ray Essick6ce27e52019-02-15 10:58:05 -080078{
Andy Hung3ab1b322020-05-18 10:47:31 -070079 if (item == nullptr) return false;
Ray Essick6ce27e52019-02-15 10:58:05 -080080
Ray Essickf27e9872019-12-07 06:28:46 -080081 const nsecs_t timestamp = MediaMetricsService::roundTime(item->getTimestamp());
Ray Essick6ce27e52019-02-15 10:58:05 -080082 std::string pkgName = item->getPkgName();
83 int64_t pkgVersionCode = item->getPkgVersionCode();
84 int64_t mediaApexVersion = 0;
85
Ray Essicka38704a2020-06-01 13:56:28 -070086 std::string serialized_metrics;
87 (void) item->getString("serialized_metrics", &serialized_metrics);
Ray Essick6ce27e52019-02-15 10:58:05 -080088
89 if (enabled_statsd) {
Ray Essicka38704a2020-06-01 13:56:28 -070090 android::util::BytesField bf_serialized(serialized_metrics.c_str(),
91 serialized_metrics.size());
Ray Essick6ce27e52019-02-15 10:58:05 -080092 android::util::stats_write(android::util::MEDIAMETRICS_DRM_WIDEVINE_REPORTED,
93 timestamp, pkgName.c_str(), pkgVersionCode,
94 mediaApexVersion,
95 bf_serialized);
96 } else {
Ray Essicka38704a2020-06-01 13:56:28 -070097 ALOGV("NOT sending: widevine private data (len=%zu)", serialized_metrics.size());
Ray Essick6ce27e52019-02-15 10:58:05 -080098 }
99
Ray Essick6ce27e52019-02-15 10:58:05 -0800100 return true;
101}
102
Robert Shihaddf5ee2019-08-19 14:11:13 -0700103// drmmanager
Ray Essickf27e9872019-12-07 06:28:46 -0800104bool statsd_drmmanager(const mediametrics::Item *item)
Robert Shihaddf5ee2019-08-19 14:11:13 -0700105{
Robert Shih5edf2452020-02-08 14:58:05 -0800106 using namespace std::string_literals;
Andy Hung3ab1b322020-05-18 10:47:31 -0700107 if (item == nullptr) return false;
Robert Shihaddf5ee2019-08-19 14:11:13 -0700108
Robert Shih5edf2452020-02-08 14:58:05 -0800109 if (!enabled_statsd) {
110 ALOGV("NOT sending: drmmanager data");
111 return true;
112 }
113
Ray Essickf27e9872019-12-07 06:28:46 -0800114 const nsecs_t timestamp = MediaMetricsService::roundTime(item->getTimestamp());
Robert Shihaddf5ee2019-08-19 14:11:13 -0700115 std::string pkgName = item->getPkgName();
116 int64_t pkgVersionCode = item->getPkgVersionCode();
117 int64_t mediaApexVersion = 0;
118
Ray Essicka38704a2020-06-01 13:56:28 -0700119 std::string plugin_id;
120 (void) item->getString("plugin_id", &plugin_id);
121 std::string description;
122 (void) item->getString("description", &description);
Robert Shihaddf5ee2019-08-19 14:11:13 -0700123 int32_t method_id = -1;
124 (void) item->getInt32("method_id", &method_id);
Ray Essicka38704a2020-06-01 13:56:28 -0700125 std::string mime_types;
126 (void) item->getString("mime_types", &mime_types);
Robert Shihaddf5ee2019-08-19 14:11:13 -0700127
Robert Shih5edf2452020-02-08 14:58:05 -0800128 // Corresponds to the 13 APIs tracked in the MediametricsDrmManagerReported statsd proto
129 // Please see also DrmManager::kMethodIdMap
130 std::array<int64_t, 13> methodCounts{};
131 for (size_t i = 0; i < methodCounts.size() ; i++) {
132 item->getInt64(("method"s + std::to_string(i)).c_str(), &methodCounts[i]);
Robert Shihaddf5ee2019-08-19 14:11:13 -0700133 }
134
Robert Shih5edf2452020-02-08 14:58:05 -0800135 android::util::stats_write(android::util::MEDIAMETRICS_DRMMANAGER_REPORTED,
136 timestamp, pkgName.c_str(), pkgVersionCode, mediaApexVersion,
Ray Essicka38704a2020-06-01 13:56:28 -0700137 plugin_id.c_str(), description.c_str(),
138 method_id, mime_types.c_str(),
Robert Shih5edf2452020-02-08 14:58:05 -0800139 methodCounts[0], methodCounts[1], methodCounts[2],
140 methodCounts[3], methodCounts[4], methodCounts[5],
141 methodCounts[6], methodCounts[7], methodCounts[8],
142 methodCounts[9], methodCounts[10], methodCounts[11],
143 methodCounts[12]);
144
Robert Shihaddf5ee2019-08-19 14:11:13 -0700145 return true;
146}
Ray Essicka38704a2020-06-01 13:56:28 -0700147
Ray Essick6ce27e52019-02-15 10:58:05 -0800148} // namespace android