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 HARDWARE_GOOGLE_PIXELSTATS_V1_0_PIXELSTATS_H 18 #define HARDWARE_GOOGLE_PIXELSTATS_V1_0_PIXELSTATS_H 19 20 #include <hardware/google/pixelstats/1.0/IPixelStats.h> 21 #include <hidl/MQDescriptor.h> 22 #include <hidl/Status.h> 23 24 #include "RateLimiter.h" 25 26 namespace hardware { 27 namespace google { 28 namespace pixelstats { 29 namespace V1_0 { 30 namespace implementation { 31 32 using ::android::sp; 33 using ::android::hardware::hidl_array; 34 using ::android::hardware::hidl_memory; 35 using ::android::hardware::hidl_string; 36 using ::android::hardware::hidl_vec; 37 using ::android::hardware::Return; 38 using ::android::hardware::Void; 39 40 41 struct PixelStats : public IPixelStats { 42 PixelStats(); 43 44 // Methods from ::hardware::google::pixelstats::V1_0::IPixelStats follow. 45 Return<void> reportUsbConnectorConnected() override; 46 Return<void> reportUsbConnectorDisconnected(int32_t duration_millis) override; 47 Return<void> reportUsbAudioConnected(int32_t vid, int32_t pid) override; 48 Return<void> reportUsbAudioDisconnected(int32_t vid, int32_t pid, 49 int32_t duration_millis) override; 50 Return<void> reportSpeakerImpedance(int32_t speakerLocation, int32_t milliOhms) override; 51 Return<void> reportHardwareFailed(HardwareType hardwareType, int32_t hardwareLocation, 52 HardwareErrorCode errorCode) override; 53 Return<void> reportPhysicalDropDetected(int32_t confidence, int32_t accelPeak, 54 int32_t freefallDurationMs) override; 55 Return<void> reportChargeCycles(const hidl_string& buckets) override; 56 Return<void> reportBatteryHealthSnapshot(const BatteryHealthSnapshotArgs& args) override; 57 Return<void> reportSlowIo(IoOperation operation, int32_t count) override; 58 Return<void> reportBatteryCausedShutdown(int32_t voltageMicroV) override; 59 60 private: 61 // At most 150 events per day by default. 62 static constexpr int32_t kDailyRatelimit = 150; 63 64 // each action provides its own per-limit daily rate limit. 65 bool rateLimit(int action, int actionLimit); 66 67 RateLimiter limiter_; 68 }; 69 70 } // namespace implementation 71 } // namespace V1_0 72 } // namespace pixelstats 73 } // namespace google 74 } // namespace hardware 75 76 #endif // HARDWARE_GOOGLE_PIXELSTATS_V1_0_PIXELSTATS_H 77