Adam Stone | f0e618d | 2018-01-17 19:20:41 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | #ifndef DRM_METRICS_H_ |
| 18 | #define DRM_METRICS_H_ |
| 19 | |
Adam Stone | cea91ce | 2018-01-22 19:23:28 -0800 | [diff] [blame] | 20 | #include <map> |
| 21 | |
| 22 | #include <android/hardware/drm/1.0/types.h> |
Adam Stone | 28f27c3 | 2018-02-05 15:07:48 -0800 | [diff] [blame] | 23 | #include <android/hardware/drm/1.1/types.h> |
Robert Shih | a503326 | 2019-05-06 14:15:12 -0700 | [diff] [blame] | 24 | #include <android/hardware/drm/1.2/types.h> |
Adam Stone | 637b785 | 2018-01-30 12:09:36 -0800 | [diff] [blame] | 25 | #include <binder/PersistableBundle.h> |
Adam Stone | f0e618d | 2018-01-17 19:20:41 -0800 | [diff] [blame] | 26 | #include <media/CounterMetric.h> |
| 27 | #include <media/EventMetric.h> |
Robert Shih | 82ea6be | 2019-11-07 17:47:23 -0800 | [diff] [blame] | 28 | #include <sys/types.h> |
Adam Stone | f0e618d | 2018-01-17 19:20:41 -0800 | [diff] [blame] | 29 | |
| 30 | namespace android { |
| 31 | |
| 32 | /** |
| 33 | * This class contains the definition of metrics captured within MediaDrm. |
| 34 | * It also contains a method for exporting all of the metrics to a |
Adam Stone | 568b3c4 | 2018-01-31 12:57:16 -0800 | [diff] [blame] | 35 | * PersistableBundle. |
Adam Stone | f0e618d | 2018-01-17 19:20:41 -0800 | [diff] [blame] | 36 | */ |
| 37 | class MediaDrmMetrics { |
| 38 | public: |
| 39 | explicit MediaDrmMetrics(); |
Adam Stone | fb679e3 | 2018-02-07 10:25:48 -0800 | [diff] [blame] | 40 | virtual ~MediaDrmMetrics() {}; |
Adam Stone | cea91ce | 2018-01-22 19:23:28 -0800 | [diff] [blame] | 41 | // Count of openSession calls. |
Adam Stone | f0e618d | 2018-01-17 19:20:41 -0800 | [diff] [blame] | 42 | CounterMetric<status_t> mOpenSessionCounter; |
Adam Stone | cea91ce | 2018-01-22 19:23:28 -0800 | [diff] [blame] | 43 | // Count of closeSession calls. |
| 44 | CounterMetric<status_t> mCloseSessionCounter; |
| 45 | // Count and timing of getKeyRequest calls. |
Adam Stone | fb679e3 | 2018-02-07 10:25:48 -0800 | [diff] [blame] | 46 | EventMetric<status_t> mGetKeyRequestTimeUs; |
Adam Stone | cea91ce | 2018-01-22 19:23:28 -0800 | [diff] [blame] | 47 | // Count and timing of provideKeyResponse calls. |
Adam Stone | fb679e3 | 2018-02-07 10:25:48 -0800 | [diff] [blame] | 48 | EventMetric<status_t> mProvideKeyResponseTimeUs; |
Adam Stone | cea91ce | 2018-01-22 19:23:28 -0800 | [diff] [blame] | 49 | // Count of getProvisionRequest calls. |
| 50 | CounterMetric<status_t> mGetProvisionRequestCounter; |
| 51 | // Count of provideProvisionResponse calls. |
| 52 | CounterMetric<status_t> mProvideProvisionResponseCounter; |
Adam Stone | f0e618d | 2018-01-17 19:20:41 -0800 | [diff] [blame] | 53 | |
Adam Stone | cea91ce | 2018-01-22 19:23:28 -0800 | [diff] [blame] | 54 | // Count of key status events broken out by status type. |
Robert Shih | a503326 | 2019-05-06 14:15:12 -0700 | [diff] [blame] | 55 | CounterMetric<::android::hardware::drm::V1_2::KeyStatusType> |
Adam Stone | cea91ce | 2018-01-22 19:23:28 -0800 | [diff] [blame] | 56 | mKeyStatusChangeCounter; |
| 57 | // Count of events broken out by event type |
| 58 | CounterMetric<::android::hardware::drm::V1_0::EventType> mEventCounter; |
| 59 | |
| 60 | // Count getPropertyByteArray calls to retrieve the device unique id. |
| 61 | CounterMetric<status_t> mGetDeviceUniqueIdCounter; |
| 62 | |
Adam Stone | 568b3c4 | 2018-01-31 12:57:16 -0800 | [diff] [blame] | 63 | // Adds a session start time record. |
| 64 | void SetSessionStart(const Vector<uint8_t>& sessionId); |
Adam Stone | f0e618d | 2018-01-17 19:20:41 -0800 | [diff] [blame] | 65 | |
Adam Stone | 568b3c4 | 2018-01-31 12:57:16 -0800 | [diff] [blame] | 66 | // Adds a session end time record. |
| 67 | void SetSessionEnd(const Vector<uint8_t>& sessionId); |
| 68 | |
Adam Stone | fb679e3 | 2018-02-07 10:25:48 -0800 | [diff] [blame] | 69 | // The app package name is the application package name that is using the |
| 70 | // instance. The app package name is held here for convenience. It is not |
| 71 | // serialized or exported with the metrics. |
| 72 | void SetAppPackageName(const String8& appPackageName) { mAppPackageName = appPackageName; } |
| 73 | const String8& GetAppPackageName() { return mAppPackageName; } |
| 74 | |
Robert Shih | 82ea6be | 2019-11-07 17:47:23 -0800 | [diff] [blame] | 75 | void SetAppUid(uid_t appUid) { mAppUid = appUid; } |
| 76 | uid_t GetAppUid() const { return mAppUid; } |
| 77 | |
Adam Stone | fb679e3 | 2018-02-07 10:25:48 -0800 | [diff] [blame] | 78 | // Get the serialized metrics. Metrics are formatted as a serialized |
| 79 | // DrmFrameworkMetrics proto. If there is a failure serializing the metrics, |
| 80 | // this returns an error. The parameter |serlializedMetrics| is owned by the |
| 81 | // caller and must not be null. |
| 82 | status_t GetSerializedMetrics(std::string* serializedMetrics); |
| 83 | |
Robert Shih | 9353881 | 2019-11-12 12:21:35 -0800 | [diff] [blame^] | 84 | // Get copy of session lifetimes. |
| 85 | std::map<std::string, std::pair<int64_t, int64_t>> GetSessionLifespans() const; |
Adam Stone | 28f27c3 | 2018-02-05 15:07:48 -0800 | [diff] [blame] | 86 | |
Adam Stone | fb679e3 | 2018-02-07 10:25:48 -0800 | [diff] [blame] | 87 | protected: |
| 88 | // This is visible for testing only. |
| 89 | virtual int64_t GetCurrentTimeMs(); |
| 90 | |
Adam Stone | 568b3c4 | 2018-01-31 12:57:16 -0800 | [diff] [blame] | 91 | private: |
| 92 | // Session lifetimes. A pair of values representing the milliseconds since |
| 93 | // epoch, UTC. The first value is the start time, the second is the end time. |
Adam Stone | fb679e3 | 2018-02-07 10:25:48 -0800 | [diff] [blame] | 94 | std::map<std::string, std::pair<int64_t, int64_t>> mSessionLifespans; |
| 95 | |
| 96 | String8 mAppPackageName; |
Robert Shih | 82ea6be | 2019-11-07 17:47:23 -0800 | [diff] [blame] | 97 | uid_t mAppUid{~0u}; |
Adam Stone | f0e618d | 2018-01-17 19:20:41 -0800 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | } // namespace android |
| 101 | |
| 102 | #endif // DRM_METRICS_H_ |