blob: 89d6f8fb2357bb189dbec4b6d0999976be6494df [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
Andy Hung3ab1b322020-05-18 10:47:31 -070053 char *vendor = nullptr;
Ray Essick6ce27e52019-02-15 10:58:05 -080054 (void) item->getCString("vendor", &vendor);
Andy Hung3ab1b322020-05-18 10:47:31 -070055 char *description = nullptr;
Ray Essick6ce27e52019-02-15 10:58:05 -080056 (void) item->getCString("description", &description);
Andy Hung3ab1b322020-05-18 10:47:31 -070057 char *serialized_metrics = nullptr;
Ray Essick6ce27e52019-02-15 10:58:05 -080058 (void) item->getCString("serialized_metrics", &serialized_metrics);
59
60 if (enabled_statsd) {
Andy Hung3ab1b322020-05-18 10:47:31 -070061 android::util::BytesField bf_serialized(serialized_metrics ? serialized_metrics : nullptr,
Ray Essick6ce27e52019-02-15 10:58:05 -080062 serialized_metrics ? strlen(serialized_metrics)
63 : 0);
64 android::util::stats_write(android::util::MEDIAMETRICS_MEDIADRM_REPORTED,
65 timestamp, pkgName.c_str(), pkgVersionCode,
66 mediaApexVersion,
67 vendor, description,
68 bf_serialized);
69 } else {
70 ALOGV("NOT sending: mediadrm private data (len=%zu)",
71 serialized_metrics ? strlen(serialized_metrics) : 0);
72 }
73
74 free(vendor);
75 free(description);
76 free(serialized_metrics);
77 return true;
78}
79
80// widevineCDM
Ray Essickf27e9872019-12-07 06:28:46 -080081bool statsd_widevineCDM(const mediametrics::Item *item)
Ray Essick6ce27e52019-02-15 10:58:05 -080082{
Andy Hung3ab1b322020-05-18 10:47:31 -070083 if (item == nullptr) return false;
Ray Essick6ce27e52019-02-15 10:58:05 -080084
Ray Essickf27e9872019-12-07 06:28:46 -080085 const nsecs_t timestamp = MediaMetricsService::roundTime(item->getTimestamp());
Ray Essick6ce27e52019-02-15 10:58:05 -080086 std::string pkgName = item->getPkgName();
87 int64_t pkgVersionCode = item->getPkgVersionCode();
88 int64_t mediaApexVersion = 0;
89
Andy Hung3ab1b322020-05-18 10:47:31 -070090 char *serialized_metrics = nullptr;
Ray Essick6ce27e52019-02-15 10:58:05 -080091 (void) item->getCString("serialized_metrics", &serialized_metrics);
92
93 if (enabled_statsd) {
Andy Hung3ab1b322020-05-18 10:47:31 -070094 android::util::BytesField bf_serialized(serialized_metrics ? serialized_metrics : nullptr,
Ray Essick6ce27e52019-02-15 10:58:05 -080095 serialized_metrics ? strlen(serialized_metrics)
96 : 0);
97 android::util::stats_write(android::util::MEDIAMETRICS_DRM_WIDEVINE_REPORTED,
98 timestamp, pkgName.c_str(), pkgVersionCode,
99 mediaApexVersion,
100 bf_serialized);
101 } else {
102 ALOGV("NOT sending: widevine private data (len=%zu)",
103 serialized_metrics ? strlen(serialized_metrics) : 0);
104 }
105
106 free(serialized_metrics);
107 return true;
108}
109
Robert Shihaddf5ee2019-08-19 14:11:13 -0700110// drmmanager
Ray Essickf27e9872019-12-07 06:28:46 -0800111bool statsd_drmmanager(const mediametrics::Item *item)
Robert Shihaddf5ee2019-08-19 14:11:13 -0700112{
Robert Shih5edf2452020-02-08 14:58:05 -0800113 using namespace std::string_literals;
Andy Hung3ab1b322020-05-18 10:47:31 -0700114 if (item == nullptr) return false;
Robert Shihaddf5ee2019-08-19 14:11:13 -0700115
Robert Shih5edf2452020-02-08 14:58:05 -0800116 if (!enabled_statsd) {
117 ALOGV("NOT sending: drmmanager data");
118 return true;
119 }
120
Ray Essickf27e9872019-12-07 06:28:46 -0800121 const nsecs_t timestamp = MediaMetricsService::roundTime(item->getTimestamp());
Robert Shihaddf5ee2019-08-19 14:11:13 -0700122 std::string pkgName = item->getPkgName();
123 int64_t pkgVersionCode = item->getPkgVersionCode();
124 int64_t mediaApexVersion = 0;
125
Andy Hung3ab1b322020-05-18 10:47:31 -0700126 char *plugin_id = nullptr;
Robert Shihaddf5ee2019-08-19 14:11:13 -0700127 (void) item->getCString("plugin_id", &plugin_id);
Andy Hung3ab1b322020-05-18 10:47:31 -0700128 char *description = nullptr;
Robert Shihaddf5ee2019-08-19 14:11:13 -0700129 (void) item->getCString("description", &description);
130 int32_t method_id = -1;
131 (void) item->getInt32("method_id", &method_id);
Andy Hung3ab1b322020-05-18 10:47:31 -0700132 char *mime_types = nullptr;
Robert Shihaddf5ee2019-08-19 14:11:13 -0700133 (void) item->getCString("mime_types", &mime_types);
134
Robert Shih5edf2452020-02-08 14:58:05 -0800135 // Corresponds to the 13 APIs tracked in the MediametricsDrmManagerReported statsd proto
136 // Please see also DrmManager::kMethodIdMap
137 std::array<int64_t, 13> methodCounts{};
138 for (size_t i = 0; i < methodCounts.size() ; i++) {
139 item->getInt64(("method"s + std::to_string(i)).c_str(), &methodCounts[i]);
Robert Shihaddf5ee2019-08-19 14:11:13 -0700140 }
141
Robert Shih5edf2452020-02-08 14:58:05 -0800142 android::util::stats_write(android::util::MEDIAMETRICS_DRMMANAGER_REPORTED,
143 timestamp, pkgName.c_str(), pkgVersionCode, mediaApexVersion,
144 plugin_id, description, method_id, mime_types,
145 methodCounts[0], methodCounts[1], methodCounts[2],
146 methodCounts[3], methodCounts[4], methodCounts[5],
147 methodCounts[6], methodCounts[7], methodCounts[8],
148 methodCounts[9], methodCounts[10], methodCounts[11],
149 methodCounts[12]);
150
Robert Shihaddf5ee2019-08-19 14:11:13 -0700151 free(plugin_id);
152 free(description);
153 free(mime_types);
154 return true;
155}
Ray Essick6ce27e52019-02-15 10:58:05 -0800156} // namespace android