blob: ffc9707b6bc382654c76030206e473b6f5d4bc09 [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);
Ray Essick6ce27e52019-02-15 10:58:05 -080057
58 if (enabled_statsd) {
Robert Shih943123d2021-03-10 02:37:01 -080059 // This field is left here for backward compatibility.
60 // This field is not used anymore.
61 const std::string kUnusedField("unused");
62 android::util::BytesField bf_serialized(kUnusedField.c_str(), kUnusedField.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 {
Robert Shih943123d2021-03-10 02:37:01 -080070 ALOGV("NOT sending: mediadrm data(%s, %s)", vendor.c_str(), description.c_str());
Ray Essick6ce27e52019-02-15 10:58:05 -080071 }
72
Ray Essick6ce27e52019-02-15 10:58:05 -080073 return true;
74}
75
Robert Shihaddf5ee2019-08-19 14:11:13 -070076// drmmanager
Ray Essickf27e9872019-12-07 06:28:46 -080077bool statsd_drmmanager(const mediametrics::Item *item)
Robert Shihaddf5ee2019-08-19 14:11:13 -070078{
Robert Shih5edf2452020-02-08 14:58:05 -080079 using namespace std::string_literals;
Andy Hung3ab1b322020-05-18 10:47:31 -070080 if (item == nullptr) return false;
Robert Shihaddf5ee2019-08-19 14:11:13 -070081
Robert Shih5edf2452020-02-08 14:58:05 -080082 if (!enabled_statsd) {
83 ALOGV("NOT sending: drmmanager data");
84 return true;
85 }
86
Ray Essickf27e9872019-12-07 06:28:46 -080087 const nsecs_t timestamp = MediaMetricsService::roundTime(item->getTimestamp());
Robert Shihaddf5ee2019-08-19 14:11:13 -070088 std::string pkgName = item->getPkgName();
89 int64_t pkgVersionCode = item->getPkgVersionCode();
90 int64_t mediaApexVersion = 0;
91
Ray Essicka38704a2020-06-01 13:56:28 -070092 std::string plugin_id;
93 (void) item->getString("plugin_id", &plugin_id);
94 std::string description;
95 (void) item->getString("description", &description);
Robert Shihaddf5ee2019-08-19 14:11:13 -070096 int32_t method_id = -1;
97 (void) item->getInt32("method_id", &method_id);
Ray Essicka38704a2020-06-01 13:56:28 -070098 std::string mime_types;
99 (void) item->getString("mime_types", &mime_types);
Robert Shihaddf5ee2019-08-19 14:11:13 -0700100
Robert Shih5edf2452020-02-08 14:58:05 -0800101 // Corresponds to the 13 APIs tracked in the MediametricsDrmManagerReported statsd proto
102 // Please see also DrmManager::kMethodIdMap
103 std::array<int64_t, 13> methodCounts{};
104 for (size_t i = 0; i < methodCounts.size() ; i++) {
105 item->getInt64(("method"s + std::to_string(i)).c_str(), &methodCounts[i]);
Robert Shihaddf5ee2019-08-19 14:11:13 -0700106 }
107
Robert Shih5edf2452020-02-08 14:58:05 -0800108 android::util::stats_write(android::util::MEDIAMETRICS_DRMMANAGER_REPORTED,
109 timestamp, pkgName.c_str(), pkgVersionCode, mediaApexVersion,
Ray Essicka38704a2020-06-01 13:56:28 -0700110 plugin_id.c_str(), description.c_str(),
111 method_id, mime_types.c_str(),
Robert Shih5edf2452020-02-08 14:58:05 -0800112 methodCounts[0], methodCounts[1], methodCounts[2],
113 methodCounts[3], methodCounts[4], methodCounts[5],
114 methodCounts[6], methodCounts[7], methodCounts[8],
115 methodCounts[9], methodCounts[10], methodCounts[11],
116 methodCounts[12]);
117
Robert Shihaddf5ee2019-08-19 14:11:13 -0700118 return true;
119}
Ray Essicka38704a2020-06-01 13:56:28 -0700120
Ray Essick6ce27e52019-02-15 10:58:05 -0800121} // namespace android