• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "parcel.h"
20 namespace OHOS {
21 namespace Sensors {
22 constexpr int32_t MAX_EVENT_SIZE = 16;
23 constexpr int32_t MAX_POINT_SIZE = 16;
24 const std::string VIBRATE_BUTT = "butt";
25 const std::string VIBRATE_TIME = "time";
26 const std::string VIBRATE_PRESET = "preset";
27 const std::string VIBRATE_CUSTOM_HD = "custom.hd";
28 const std::string VIBRATE_CUSTOM_COMPOSITE_EFFECT = "custom.composite.effect";
29 const std::string VIBRATE_CUSTOM_COMPOSITE_TIME = "custom.composite.time";
30 
31 enum VibrateUsage {
32     USAGE_UNKNOWN = 0,
33     USAGE_ALARM = 1,
34     USAGE_RING = 2,
35     USAGE_NOTIFICATION = 3,
36     USAGE_COMMUNICATION = 4,
37     USAGE_TOUCH = 5,
38     USAGE_MEDIA = 6,
39     USAGE_PHYSICAL_FEEDBACK = 7,
40     USAGE_SIMULATE_REALITY = 8,
41     USAGE_MAX = 9,
42 };
43 
44 enum VibrateTag {
45     EVENT_TAG_UNKNOWN = -1,
46     EVENT_TAG_CONTINUOUS = 0,
47     EVENT_TAG_TRANSIENT = 1,
48 };
49 
50 enum VibrateCustomMode {
51     VIBRATE_MODE_HD = 0,
52     VIBRATE_MODE_MAPPING = 1,
53     VIBRATE_MODE_TIMES = 2,
54 };
55 
56 struct VibrateCurvePoint {
57     bool operator<(const VibrateCurvePoint &rhs) const
58     {
59         return time < rhs.time;
60     }
61     int32_t time = 0;
62     int32_t intensity = 0;
63     int32_t frequency = 0;
64 };
65 
66 struct VibrateEvent {
67     bool operator<(const VibrateEvent &rhs) const
68     {
69         return time < rhs.time;
70     }
71 
72     VibrateTag tag;
73     int32_t time = 0;
74     int32_t duration = 0;
75     int32_t intensity = 0;
76     int32_t frequency = 0;
77     int32_t index = 0;
78     std::vector<VibrateCurvePoint> points;
79 };
80 
81 struct VibratePattern : public Parcelable {
82     bool operator<(const VibratePattern &rhs) const
83     {
84         return startTime < rhs.startTime;
85     }
86     int32_t startTime = 0;
87     int32_t patternDuration = 0;
88     std::vector<VibrateEvent> events;
89     void Dump() const;
90     bool Marshalling(Parcel &parcel) const;
91     static VibratePattern* Unmarshalling(Parcel &data);
92 };
93 
94 struct VibratePackage {
95     std::vector<VibratePattern> patterns;
96     int32_t packageDuration = 0;
97     void Dump() const;
98 };
99 
100 struct VibratePackageIPC : public Parcelable {
101     int32_t packageDuration = 0;
102     std::vector<VibratePattern> patterns;
103     void Dump() const;
104     bool Marshalling(Parcel &parcel) const;
105     static VibratePackageIPC* Unmarshalling(Parcel &data);
106 };
107 
108 struct VibratorCapacity : public Parcelable {
109     bool isSupportHdHaptic = false;
110     bool isSupportPresetMapping = false;
111     bool isSupportTimeDelay = false;
112     void Dump() const;
113     int32_t GetVibrateMode();
114     bool Marshalling(Parcel &parcel) const;
115     static VibratorCapacity* Unmarshalling(Parcel &data);
116 };
117 
118 struct VibrateSlice {
119     int32_t time = 0;
120     int32_t duration = 0;
121     int32_t intensity = 0;
122     int32_t frequency = 0;
123 };
124 
125 struct VibrateInfo {
126     std::string mode;
127     std::string packageName;
128     int32_t pid = -1;
129     int32_t uid = -1;
130     int32_t usage = 0;
131     bool systemUsage = false;
132     int32_t duration = 0;
133     std::string effect;
134     int32_t count = 0;
135     int32_t intensity = 0;
136     uint32_t sessionId = 0;
137     VibratePackage package;
138     VibratePackageIPC packageIPC;
139 };
140 
141 struct VibrateParameter : public Parcelable {
142     int32_t intensity = 100;  // from 0 to 100
143     int32_t frequency = 0;    // from -100 to 100
144     int32_t reserved = 0;
145     uint32_t sessionId = 0;
146     void Dump() const;
147     bool Marshalling(Parcel &parcel) const;
148     static VibrateParameter* Unmarshalling(Parcel &data);
149 };
150 
151 
152 struct VibratorInfoIPC : public Parcelable {
153     int32_t deviceId = -1;
154     int32_t vibratorId = -1;
155     std::string deviceName = "";
156     bool isSupportHdHaptic;
157     bool isLocalVibrator;
158     int32_t position = 0;
159     void Dump() const;
160     bool Marshalling(Parcel &parcel) const;
161     static VibratorInfoIPC* Unmarshalling(Parcel &data);
162 };
163 
164 struct VibratorIdentifierIPC : public Parcelable {
165     int32_t deviceId = -1;
166     int32_t vibratorId = -1;
167     int32_t position = 0;
168     bool isLocalVibrator;
169     void Dump() const;
170     bool Marshalling(Parcel &parcel) const;
171     static VibratorIdentifierIPC* Unmarshalling(Parcel &data);
172 };
173 
174 struct EffectInfoIPC : public Parcelable {
175     int32_t duration = -1;
176     bool isSupportEffect;
177     void Dump() const;
178     bool Marshalling(Parcel &parcel) const;
179     static EffectInfoIPC* Unmarshalling(Parcel &data);
180 };
181 
182 struct CustomHapticInfoIPC : public Parcelable {
183     int32_t usage = 0;
184     bool systemUsage;
185     VibrateParameter parameter;
186     void Dump() const;
187     bool Marshalling(Parcel &parcel) const;
188     static CustomHapticInfoIPC* Unmarshalling(Parcel &data);
189 };
190 
191 struct PrimitiveEffectIPC : public Parcelable {
192     int32_t intensity = 0;
193     int32_t usage = 0;
194     bool systemUsage;
195     int32_t count = 0;
196     void Dump() const;
197     bool Marshalling(Parcel &parcel) const;
198     static PrimitiveEffectIPC* Unmarshalling(Parcel &data);
199 };
200 } // namespace Sensors
201 } // namespace OHOS
202 #endif // VIBRATOR_INFOS_H
203