blob: 78d0a22f473b11f615d3f5c54b15be795cb3ff10 [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
38namespace android {
39
40// mediadrm
Andy Hung82a074b2019-12-03 14:16:45 -080041bool statsd_mediadrm(const MediaAnalyticsItem *item)
Ray Essick6ce27e52019-02-15 10:58:05 -080042{
43 if (item == NULL) return false;
44
Andy Hung55aaf522019-12-03 15:07:51 -080045 const nsecs_t timestamp = MediaAnalyticsService::roundTime(item->getTimestamp());
Ray Essick6ce27e52019-02-15 10:58:05 -080046 std::string pkgName = item->getPkgName();
47 int64_t pkgVersionCode = item->getPkgVersionCode();
48 int64_t mediaApexVersion = 0;
49
50 char *vendor = NULL;
51 (void) item->getCString("vendor", &vendor);
52 char *description = NULL;
53 (void) item->getCString("description", &description);
54 char *serialized_metrics = NULL;
55 (void) item->getCString("serialized_metrics", &serialized_metrics);
56
57 if (enabled_statsd) {
58 android::util::BytesField bf_serialized(serialized_metrics ? serialized_metrics : NULL,
59 serialized_metrics ? strlen(serialized_metrics)
60 : 0);
61 android::util::stats_write(android::util::MEDIAMETRICS_MEDIADRM_REPORTED,
62 timestamp, pkgName.c_str(), pkgVersionCode,
63 mediaApexVersion,
64 vendor, description,
65 bf_serialized);
66 } else {
67 ALOGV("NOT sending: mediadrm private data (len=%zu)",
68 serialized_metrics ? strlen(serialized_metrics) : 0);
69 }
70
71 free(vendor);
72 free(description);
73 free(serialized_metrics);
74 return true;
75}
76
77// widevineCDM
Andy Hung82a074b2019-12-03 14:16:45 -080078bool statsd_widevineCDM(const MediaAnalyticsItem *item)
Ray Essick6ce27e52019-02-15 10:58:05 -080079{
80 if (item == NULL) return false;
81
Andy Hung55aaf522019-12-03 15:07:51 -080082 const nsecs_t timestamp = MediaAnalyticsService::roundTime(item->getTimestamp());
Ray Essick6ce27e52019-02-15 10:58:05 -080083 std::string pkgName = item->getPkgName();
84 int64_t pkgVersionCode = item->getPkgVersionCode();
85 int64_t mediaApexVersion = 0;
86
87 char *serialized_metrics = NULL;
88 (void) item->getCString("serialized_metrics", &serialized_metrics);
89
90 if (enabled_statsd) {
91 android::util::BytesField bf_serialized(serialized_metrics ? serialized_metrics : NULL,
92 serialized_metrics ? strlen(serialized_metrics)
93 : 0);
94 android::util::stats_write(android::util::MEDIAMETRICS_DRM_WIDEVINE_REPORTED,
95 timestamp, pkgName.c_str(), pkgVersionCode,
96 mediaApexVersion,
97 bf_serialized);
98 } else {
99 ALOGV("NOT sending: widevine private data (len=%zu)",
100 serialized_metrics ? strlen(serialized_metrics) : 0);
101 }
102
103 free(serialized_metrics);
104 return true;
105}
106
Robert Shihaddf5ee2019-08-19 14:11:13 -0700107// drmmanager
Andy Hung82a074b2019-12-03 14:16:45 -0800108bool statsd_drmmanager(const MediaAnalyticsItem *item)
Robert Shihaddf5ee2019-08-19 14:11:13 -0700109{
110 if (item == NULL) return false;
111
Andy Hung55aaf522019-12-03 15:07:51 -0800112 const nsecs_t timestamp = MediaAnalyticsService::roundTime(item->getTimestamp());
Robert Shihaddf5ee2019-08-19 14:11:13 -0700113 std::string pkgName = item->getPkgName();
114 int64_t pkgVersionCode = item->getPkgVersionCode();
115 int64_t mediaApexVersion = 0;
116
117 char *plugin_id = NULL;
118 (void) item->getCString("plugin_id", &plugin_id);
119 char *description = NULL;
120 (void) item->getCString("description", &description);
121 int32_t method_id = -1;
122 (void) item->getInt32("method_id", &method_id);
123 char *mime_types = NULL;
124 (void) item->getCString("mime_types", &mime_types);
125
126 if (enabled_statsd) {
127 android::util::stats_write(android::util::MEDIAMETRICS_DRMMANAGER_REPORTED,
128 timestamp, pkgName.c_str(), pkgVersionCode,
129 mediaApexVersion,
130 plugin_id, description,
131 method_id, mime_types);
132 } else {
133 ALOGV("NOT sending: drmmanager data");
134 }
135
136 free(plugin_id);
137 free(description);
138 free(mime_types);
139 return true;
140}
Ray Essick6ce27e52019-02-15 10:58:05 -0800141} // namespace android