1 /* 2 * Copyright (C) 2023 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 HARDWARE_GOOGLE_PIXEL_PIXELSTATS_DISPLAYSTATSREPORTER_H 18 #define HARDWARE_GOOGLE_PIXEL_PIXELSTATS_DISPLAYSTATSREPORTER_H 19 20 #include <aidl/android/frameworks/stats/IStats.h> 21 #include <hardware/google/pixel/pixelstats/pixelatoms.pb.h> 22 23 #include <string> 24 25 namespace android { 26 namespace hardware { 27 namespace google { 28 namespace pixel { 29 30 using aidl::android::frameworks::stats::IStats; 31 using aidl::android::frameworks::stats::VendorAtomValue; 32 33 /** 34 * A class to upload Pixel Display Stats metrics 35 */ 36 class DisplayStatsReporter { 37 public: 38 DisplayStatsReporter(); 39 40 enum display_stats_type { 41 DISP_PANEL_STATE = 0, 42 DISP_PORT_STATE, 43 HDCP_STATE, 44 DISP_PORT_DSC_STATE, 45 DISP_PORT_MAX_RES_STATE, 46 }; 47 void logDisplayStats(const std::shared_ptr<IStats> &stats_client, 48 const std::vector<std::string> &display_stats_paths, 49 const display_stats_type stats_type); 50 51 private: 52 bool readDisplayErrorCount(const std::string &path, int64_t *val); 53 // Proto messages are 1-indexed and VendorAtom field numbers start at 2, so 54 // store everything in the values array at the index of the field number 55 // -2. 56 static constexpr int kVendorAtomOffset = 2; 57 static constexpr int kNumOfDisplayPanelErrorStats = 4; 58 59 int verifyCount(int val, bool *report_stats); 60 61 /* display state */ 62 struct DisplayPanelErrorStats { 63 int64_t primary_error_count_te; 64 int64_t primary_error_count_unknown; 65 int64_t secondary_error_count_te; 66 int64_t secondary_error_count_unknown; 67 }; 68 struct DisplayPanelErrorStats prev_panel_data_ = {}; 69 void logDisplayPanelErrorStats(const std::shared_ptr<IStats> &stats_client, 70 const std::vector<std::string> &display_stats_paths); 71 bool captureDisplayPanelErrorStats(const std::vector<std::string> &display_stats_paths, 72 struct DisplayPanelErrorStats *cur_data); 73 74 /* displayport state */ 75 enum display_port_error_stats_index { 76 LINK_NEGOTIATION_FAILURES = 0, 77 EDID_READ_FAILURES, 78 DPCD_READ_FAILURES, 79 EDID_INVALID_FAILURES, 80 SINK_COUNT_INVALID_FAILURES, 81 LINK_UNSTABLE_FAILURES, 82 DISPLAY_PORT_ERROR_STATS_SIZE, 83 }; 84 static constexpr int64_t display_port_error_path_index[DISPLAY_PORT_ERROR_STATS_SIZE] = { 85 PixelAtoms::DisplayPortErrorStats::kLinkNegotiationFailuresFieldNumber, 86 PixelAtoms::DisplayPortErrorStats::kEdidReadFailuresFieldNumber, 87 PixelAtoms::DisplayPortErrorStats::kDpcdReadFailuresFieldNumber, 88 PixelAtoms::DisplayPortErrorStats::kEdidInvalidFailuresFieldNumber, 89 PixelAtoms::DisplayPortErrorStats::kSinkCountInvalidFailuresFieldNumber, 90 PixelAtoms::DisplayPortErrorStats::kLinkUnstableFailuresFieldNumber}; 91 int64_t prev_dp_data_[DISPLAY_PORT_ERROR_STATS_SIZE] = {0}; 92 93 void logDisplayPortErrorStats(const std::shared_ptr<IStats> &stats_client, 94 const std::vector<std::string> &displayport_stats_paths); 95 bool captureDisplayPortErrorStats(const std::vector<std::string> &displayport_stats_paths, 96 int64_t *cur_data); 97 98 /* HDCP state */ 99 enum hdcp_auth_type_stats_index { 100 HDCP2_SUCCESS = 0, 101 HDCP2_FALLBACK, 102 HDCP2_FAIL, 103 HDCP1_SUCCESS, 104 HDCP1_FAIL, 105 HDCP0, 106 HDCP_AUTH_TYPE_STATS_SIZE, 107 }; 108 static constexpr int64_t hdcp_auth_type_path_index[HDCP_AUTH_TYPE_STATS_SIZE] = { 109 PixelAtoms::HDCPAuthTypeStats::kHdcp2SuccessCountFieldNumber, 110 PixelAtoms::HDCPAuthTypeStats::kHdcp2FallbackCountFieldNumber, 111 PixelAtoms::HDCPAuthTypeStats::kHdcp2FailCountFieldNumber, 112 PixelAtoms::HDCPAuthTypeStats::kHdcp1SuccessCountFieldNumber, 113 PixelAtoms::HDCPAuthTypeStats::kHdcp1FailCountFieldNumber, 114 PixelAtoms::HDCPAuthTypeStats::kHdcp0CountFieldNumber}; 115 int64_t prev_hdcp_data_[HDCP_AUTH_TYPE_STATS_SIZE] = {0}; 116 117 void logHDCPAuthTypeStats(const std::shared_ptr<IStats> &stats_client, 118 const std::vector<std::string> &hdcp_stats_paths); 119 bool captureHDCPAuthTypeStats(const std::vector<std::string> &hdcp_stats_paths, 120 int64_t *cur_data); 121 122 /* displayport FEC/DSC state */ 123 /* Set the number of paths needed to be collected */ 124 static constexpr int DISPLAY_PORT_DSC_STATS_SIZE = 2; 125 126 int64_t prev_dp_dsc_data_[DISPLAY_PORT_DSC_STATS_SIZE] = {0}; 127 void logDisplayPortFECDSCStats(const std::shared_ptr<IStats> &stats_client, 128 const std::vector<std::string> &displayport_fecdsc_stats_paths); 129 bool captureDisplayPortFECDSCStats( 130 const std::vector<std::string> &displayport_fecdsc_stats_paths, int64_t *cur_data); 131 132 /* displayport maximum resolution state */ 133 /* Set the number of paths needed to be collected */ 134 static constexpr int DISPLAY_PORT_MAX_RES_STATS_SIZE = 11; 135 136 int64_t prev_dp_max_res_data_[DISPLAY_PORT_MAX_RES_STATS_SIZE] = {0}; 137 void logDisplayPortMaxResStats(const std::shared_ptr<IStats> &stats_client, 138 const std::vector<std::string> &displayport_max_res_stats_paths); 139 bool captureDisplayPortMaxResStats( 140 const std::vector<std::string> &displayport_max_res_stats_paths, int64_t *cur_data); 141 }; 142 143 } // namespace pixel 144 } // namespace google 145 } // namespace hardware 146 } // namespace android 147 148 #endif // HARDWARE_GOOGLE_PIXEL_PIXELSTATS_DISPLAYSTATSREPORTER_H 149