• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
33 #include "MediaAnalyticsService.h"
34 #include "iface_statsd.h"
35 
36 #include <statslog.h>
37 
38 namespace android {
39 
40 // mediadrm
statsd_mediadrm(MediaAnalyticsItem * item)41 bool statsd_mediadrm(MediaAnalyticsItem *item)
42 {
43     if (item == NULL) return false;
44 
45     nsecs_t timestamp = item->getTimestamp();
46     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
statsd_widevineCDM(MediaAnalyticsItem * item)78 bool statsd_widevineCDM(MediaAnalyticsItem *item)
79 {
80     if (item == NULL) return false;
81 
82     nsecs_t timestamp = item->getTimestamp();
83     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 
107 } // namespace android
108