1 /* 2 * Copyright (c) 2022-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef VIBRATOR_INFOS_H 17 #define VIBRATOR_INFOS_H 18 19 #include <string> 20 #include <unordered_map> 21 #include <vector> 22 23 #include "parcel.h" 24 namespace OHOS { 25 namespace Sensors { 26 constexpr int32_t MAX_EVENT_SIZE = 16; 27 constexpr int32_t MAX_POINT_SIZE = 16; 28 const std::string VIBRATE_BUTT = "butt"; 29 const std::string VIBRATE_TIME = "time"; 30 const std::string VIBRATE_PRESET = "preset"; 31 const std::string VIBRATE_CUSTOM_HD = "custom.hd"; 32 const std::string VIBRATE_CUSTOM_COMPOSITE_EFFECT = "custom.composite.effect"; 33 const std::string VIBRATE_CUSTOM_COMPOSITE_TIME = "custom.composite.time"; 34 35 enum VibrateUsage { 36 USAGE_UNKNOWN = 0, 37 USAGE_ALARM = 1, 38 USAGE_RING = 2, 39 USAGE_NOTIFICATION = 3, 40 USAGE_COMMUNICATION = 4, 41 USAGE_TOUCH = 5, 42 USAGE_MEDIA = 6, 43 USAGE_PHYSICAL_FEEDBACK = 7, 44 USAGE_SIMULATE_REALITY = 8, 45 USAGE_MAX = 9, 46 }; 47 48 enum VibrateTag { 49 EVENT_TAG_UNKNOWN = -1, 50 EVENT_TAG_CONTINUOUS = 0, 51 EVENT_TAG_TRANSIENT = 1, 52 }; 53 54 enum VibrateCustomMode { 55 VIBRATE_MODE_HD = 0, 56 VIBRATE_MODE_MAPPING = 1, 57 VIBRATE_MODE_TIMES = 2, 58 }; 59 60 struct VibrateCurvePoint { 61 bool operator<(const VibrateCurvePoint &rhs) const 62 { 63 return time < rhs.time; 64 } 65 int32_t time = 0; 66 int32_t intensity = 0; 67 int32_t frequency = 0; 68 }; 69 70 struct VibrateEvent { 71 bool operator<(const VibrateEvent &rhs) const 72 { 73 return time < rhs.time; 74 } 75 76 VibrateTag tag; 77 int32_t time = 0; 78 int32_t duration = 0; 79 int32_t intensity = 0; 80 int32_t frequency = 0; 81 int32_t index = 0; 82 std::vector<VibrateCurvePoint> points; 83 }; 84 85 struct VibratePattern { 86 bool operator<(const VibratePattern &rhs) const 87 { 88 return startTime < rhs.startTime; 89 } 90 int32_t startTime = 0; 91 int32_t patternDuration = 0; 92 std::vector<VibrateEvent> events; 93 void Dump() const; 94 bool Marshalling(Parcel &parcel) const; 95 std::optional<VibratePattern> Unmarshalling(Parcel &data); 96 }; 97 98 struct VibratePackage { 99 std::vector<VibratePattern> patterns; 100 int32_t packageDuration = 0; 101 void Dump() const; 102 }; 103 104 struct VibratorCapacity { 105 bool isSupportHdHaptic = false; 106 bool isSupportPresetMapping = false; 107 bool isSupportTimeDelay = false; 108 void Dump() const; 109 int32_t GetVibrateMode(); 110 bool Marshalling(Parcel &parcel) const; 111 std::optional<VibratorCapacity> Unmarshalling(Parcel &data); 112 }; 113 114 struct VibrateSlice { 115 int32_t time = 0; 116 int32_t duration = 0; 117 int32_t intensity = 0; 118 int32_t frequency = 0; 119 }; 120 121 struct VibrateInfo { 122 std::string mode; 123 std::string packageName; 124 int32_t pid = -1; 125 int32_t uid = -1; 126 int32_t usage = 0; 127 bool systemUsage = false; 128 int32_t duration = 0; 129 std::string effect; 130 int32_t count = 0; 131 int32_t intensity = 0; 132 VibratePackage package; 133 }; 134 135 struct VibrateParameter { 136 int32_t intensity = 100; // from 0 to 100 137 int32_t frequency = 0; // from -100 to 100 138 int32_t reserved = 0; 139 void Dump() const; 140 bool Marshalling(Parcel &parcel) const; 141 std::optional<VibrateParameter> Unmarshalling(Parcel &data); 142 }; 143 } // namespace Sensors 144 } // namespace OHOS 145 #endif // VIBRATOR_INFOS_H 146