Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 1 | /* |
| 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 Essick | 40e8e5e | 2019-12-05 20:19:40 -0800 | [diff] [blame] | 33 | #include "MediaMetricsService.h" |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 34 | #include "iface_statsd.h" |
| 35 | |
| 36 | #include <statslog.h> |
| 37 | |
Robert Shih | 5edf245 | 2020-02-08 14:58:05 -0800 | [diff] [blame] | 38 | #include <array> |
| 39 | #include <string> |
| 40 | |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 41 | namespace android { |
| 42 | |
| 43 | // mediadrm |
Ray Essick | f27e987 | 2019-12-07 06:28:46 -0800 | [diff] [blame] | 44 | bool statsd_mediadrm(const mediametrics::Item *item) |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 45 | { |
| 46 | if (item == NULL) return false; |
| 47 | |
Ray Essick | f27e987 | 2019-12-07 06:28:46 -0800 | [diff] [blame] | 48 | const nsecs_t timestamp = MediaMetricsService::roundTime(item->getTimestamp()); |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 49 | std::string pkgName = item->getPkgName(); |
| 50 | int64_t pkgVersionCode = item->getPkgVersionCode(); |
| 51 | int64_t mediaApexVersion = 0; |
| 52 | |
| 53 | char *vendor = NULL; |
| 54 | (void) item->getCString("vendor", &vendor); |
| 55 | char *description = NULL; |
| 56 | (void) item->getCString("description", &description); |
| 57 | char *serialized_metrics = NULL; |
| 58 | (void) item->getCString("serialized_metrics", &serialized_metrics); |
| 59 | |
| 60 | if (enabled_statsd) { |
| 61 | android::util::BytesField bf_serialized(serialized_metrics ? serialized_metrics : NULL, |
| 62 | 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 Essick | f27e987 | 2019-12-07 06:28:46 -0800 | [diff] [blame] | 81 | bool statsd_widevineCDM(const mediametrics::Item *item) |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 82 | { |
| 83 | if (item == NULL) return false; |
| 84 | |
Ray Essick | f27e987 | 2019-12-07 06:28:46 -0800 | [diff] [blame] | 85 | const nsecs_t timestamp = MediaMetricsService::roundTime(item->getTimestamp()); |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 86 | std::string pkgName = item->getPkgName(); |
| 87 | int64_t pkgVersionCode = item->getPkgVersionCode(); |
| 88 | int64_t mediaApexVersion = 0; |
| 89 | |
| 90 | char *serialized_metrics = NULL; |
| 91 | (void) item->getCString("serialized_metrics", &serialized_metrics); |
| 92 | |
| 93 | if (enabled_statsd) { |
| 94 | android::util::BytesField bf_serialized(serialized_metrics ? serialized_metrics : NULL, |
| 95 | 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 Shih | addf5ee | 2019-08-19 14:11:13 -0700 | [diff] [blame] | 110 | // drmmanager |
Ray Essick | f27e987 | 2019-12-07 06:28:46 -0800 | [diff] [blame] | 111 | bool statsd_drmmanager(const mediametrics::Item *item) |
Robert Shih | addf5ee | 2019-08-19 14:11:13 -0700 | [diff] [blame] | 112 | { |
Robert Shih | 5edf245 | 2020-02-08 14:58:05 -0800 | [diff] [blame] | 113 | using namespace std::string_literals; |
Robert Shih | addf5ee | 2019-08-19 14:11:13 -0700 | [diff] [blame] | 114 | if (item == NULL) return false; |
| 115 | |
Robert Shih | 5edf245 | 2020-02-08 14:58:05 -0800 | [diff] [blame] | 116 | if (!enabled_statsd) { |
| 117 | ALOGV("NOT sending: drmmanager data"); |
| 118 | return true; |
| 119 | } |
| 120 | |
Ray Essick | f27e987 | 2019-12-07 06:28:46 -0800 | [diff] [blame] | 121 | const nsecs_t timestamp = MediaMetricsService::roundTime(item->getTimestamp()); |
Robert Shih | addf5ee | 2019-08-19 14:11:13 -0700 | [diff] [blame] | 122 | std::string pkgName = item->getPkgName(); |
| 123 | int64_t pkgVersionCode = item->getPkgVersionCode(); |
| 124 | int64_t mediaApexVersion = 0; |
| 125 | |
| 126 | char *plugin_id = NULL; |
| 127 | (void) item->getCString("plugin_id", &plugin_id); |
| 128 | char *description = NULL; |
| 129 | (void) item->getCString("description", &description); |
| 130 | int32_t method_id = -1; |
| 131 | (void) item->getInt32("method_id", &method_id); |
| 132 | char *mime_types = NULL; |
| 133 | (void) item->getCString("mime_types", &mime_types); |
| 134 | |
Robert Shih | 5edf245 | 2020-02-08 14:58:05 -0800 | [diff] [blame] | 135 | // 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 Shih | addf5ee | 2019-08-19 14:11:13 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Robert Shih | 5edf245 | 2020-02-08 14:58:05 -0800 | [diff] [blame] | 142 | 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 Shih | addf5ee | 2019-08-19 14:11:13 -0700 | [diff] [blame] | 151 | free(plugin_id); |
| 152 | free(description); |
| 153 | free(mime_types); |
| 154 | return true; |
| 155 | } |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 156 | } // namespace android |