• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 #include "sensor_list.h"
18 
19 namespace goldfish {
20 using ahs::V2_1::SensorType;
21 using ahs::V1_0::SensorFlagBits;
22 
23 constexpr char kAospVendor[] = "The Android Open Source Project";
24 
25 const char* const kQemuSensorName[] = {
26     "acceleration",
27     "gyroscope",
28     "magnetic-field",
29     "orientation",
30     "temperature",
31     "proximity",
32     "light",
33     "pressure",
34     "humidity",
35     "magnetic-field-uncalibrated",
36     "gyroscope-uncalibrated",
37     "hinge-angle0",
38     "hinge-angle1",
39     "hinge-angle2",
40     "heart-rate",
41 };
42 
43 const SensorInfo kAllSensors[] = {
44     {
45         .sensorHandle = kSensorHandleAccelerometer,
46         .name = "Goldfish 3-axis Accelerometer",
47         .vendor = kAospVendor,
48         .version = 1,
49         .type = SensorType::ACCELEROMETER,
50         .typeAsString = "android.sensor.accelerometer",
51         .maxRange = 39.3,
52         .resolution = 1.0 / 4032.0,
53         .power = 3.0,
54         .minDelay = 10000,
55         .fifoReservedEventCount = 0,
56         .fifoMaxEventCount = 0,
57         .requiredPermission = "",
58         .maxDelay = 500000,
59         .flags = SensorFlagBits::DATA_INJECTION |
60                  SensorFlagBits::CONTINUOUS_MODE
61     },
62     {
63         .sensorHandle = kSensorHandleGyroscope,
64         .name = "Goldfish 3-axis Gyroscope",
65         .vendor = kAospVendor,
66         .version = 1,
67         .type = SensorType::GYROSCOPE,
68         .typeAsString = "android.sensor.gyroscope",
69         .maxRange = 16.46,
70         .resolution = 1.0 / 1000.0,
71         .power = 3.0,
72         .minDelay = 10000,
73         .fifoReservedEventCount = 0,
74         .fifoMaxEventCount = 0,
75         .requiredPermission = "",
76         .maxDelay = 500000,
77         .flags = SensorFlagBits::DATA_INJECTION |
78                  SensorFlagBits::CONTINUOUS_MODE
79     },
80     {
81         .sensorHandle = kSensorHandleMagneticField,
82         .name = "Goldfish 3-axis Magnetic field sensor",
83         .vendor = kAospVendor,
84         .version = 1,
85         .type = SensorType::MAGNETIC_FIELD,
86         .typeAsString = "android.sensor.magnetic_field",
87         .maxRange = 2000.0,
88         .resolution = .5,
89         .power = 6.7,
90         .minDelay = 10000,
91         .fifoReservedEventCount = 0,
92         .fifoMaxEventCount = 0,
93         .requiredPermission = "",
94         .maxDelay = 500000,
95         .flags = SensorFlagBits::DATA_INJECTION |
96                  SensorFlagBits::CONTINUOUS_MODE
97     },
98     {
99         .sensorHandle = kSensorHandleOrientation,
100         .name = "Goldfish Orientation sensor",
101         .vendor = kAospVendor,
102         .version = 1,
103         .type = SensorType::ORIENTATION,
104         .typeAsString = "android.sensor.orientation",
105         .maxRange = 360.0,
106         .resolution = 1.0,
107         .power = 9.7,
108         .minDelay = 10000,
109         .fifoReservedEventCount = 0,
110         .fifoMaxEventCount = 0,
111         .requiredPermission = "",
112         .maxDelay = 500000,
113         .flags = SensorFlagBits::DATA_INJECTION |
114                  SensorFlagBits::CONTINUOUS_MODE
115     },
116     {
117         .sensorHandle = kSensorHandleAmbientTemperature,
118         .name = "Goldfish Ambient Temperature sensor",
119         .vendor = kAospVendor,
120         .version = 1,
121         .type = SensorType::AMBIENT_TEMPERATURE,
122         .typeAsString = "android.sensor.ambient_temperature",
123         .maxRange = 80.0,
124         .resolution = 1.0,
125         .power = 0.0,
126         .minDelay = 0,
127         .fifoReservedEventCount = 0,
128         .fifoMaxEventCount = 0,
129         .requiredPermission = "",
130         .maxDelay = 0,
131         .flags = SensorFlagBits::DATA_INJECTION |
132                  SensorFlagBits::ON_CHANGE_MODE
133     },
134     {
135         .sensorHandle = kSensorHandleProximity,
136         .name = "Goldfish Proximity sensor",
137         .vendor = kAospVendor,
138         .version = 1,
139         .type = SensorType::PROXIMITY,
140         .typeAsString = "android.sensor.proximity",
141         .maxRange = 1.0,
142         .resolution = 1.0,
143         .power = 20.0,
144         .minDelay = 0,
145         .fifoReservedEventCount = 0,
146         .fifoMaxEventCount = 0,
147         .requiredPermission = "",
148         .maxDelay = 0,
149         .flags = SensorFlagBits::DATA_INJECTION |
150                  SensorFlagBits::ON_CHANGE_MODE |
151                  SensorFlagBits::WAKE_UP
152     },
153     {
154         .sensorHandle = kSensorHandleLight,
155         .name = "Goldfish Light sensor",
156         .vendor = kAospVendor,
157         .version = 1,
158         .type = SensorType::LIGHT,
159         .typeAsString = "android.sensor.light",
160         .maxRange = 40000.0,
161         .resolution = 1.0,
162         .power = 20.0,
163         .minDelay = 0,
164         .fifoReservedEventCount = 0,
165         .fifoMaxEventCount = 0,
166         .requiredPermission = "",
167         .maxDelay = 0,
168         .flags = SensorFlagBits::DATA_INJECTION |
169                  SensorFlagBits::ON_CHANGE_MODE
170     },
171     {
172         .sensorHandle = kSensorHandlePressure,
173         .name = "Goldfish Pressure sensor",
174         .vendor = kAospVendor,
175         .version = 1,
176         .type = SensorType::PRESSURE,
177         .typeAsString = "android.sensor.pressure",
178         .maxRange = 800.0,
179         .resolution = 1.0,
180         .power = 20.0,
181         .minDelay = 10000,
182         .fifoReservedEventCount = 0,
183         .fifoMaxEventCount = 0,
184         .requiredPermission = "",
185         .maxDelay = 500000,
186         .flags = SensorFlagBits::DATA_INJECTION |
187                  SensorFlagBits::CONTINUOUS_MODE
188     },
189     {
190         .sensorHandle = kSensorHandleRelativeHumidity,
191         .name = "Goldfish Humidity sensor",
192         .vendor = kAospVendor,
193         .version = 1,
194         .type = SensorType::RELATIVE_HUMIDITY,
195         .typeAsString = "android.sensor.relative_humidity",
196         .maxRange = 100.0,
197         .resolution = 1.0,
198         .power = 20.0,
199         .minDelay = 0,
200         .fifoReservedEventCount = 0,
201         .fifoMaxEventCount = 0,
202         .requiredPermission = "",
203         .maxDelay = 0,
204         .flags = SensorFlagBits::DATA_INJECTION |
205                  SensorFlagBits::ON_CHANGE_MODE
206     },
207     {
208         .sensorHandle = kSensorHandleMagneticFieldUncalibrated,
209         .name = "Goldfish 3-axis Magnetic field sensor (uncalibrated)",
210         .vendor = kAospVendor,
211         .version = 1,
212         .type = SensorType::MAGNETIC_FIELD_UNCALIBRATED,
213         .typeAsString = "android.sensor.magnetic_field_uncalibrated",
214         .maxRange = 2000.0,
215         .resolution = 0.5,
216         .power = 6.7,
217         .minDelay = 10000,
218         .fifoReservedEventCount = 0,
219         .fifoMaxEventCount = 0,
220         .requiredPermission = "",
221         .maxDelay = 500000,
222         .flags = SensorFlagBits::DATA_INJECTION | 0
223     },
224     {
225         .sensorHandle = kSensorHandleGyroscopeFieldUncalibrated,
226         .name = "Goldfish 3-axis Gyroscope (uncalibrated)",
227         .vendor = kAospVendor,
228         .version = 1,
229         .type = SensorType::GYROSCOPE_UNCALIBRATED,
230         .typeAsString = "android.sensor.gyroscope_uncalibrated",
231         .maxRange = 16.46,
232         .resolution = 1.0 / 1000.0,
233         .power = 3.0,
234         .minDelay = 10000,
235         .fifoReservedEventCount = 0,
236         .fifoMaxEventCount = 0,
237         .requiredPermission = "",
238         .maxDelay = 500000,
239         .flags = SensorFlagBits::DATA_INJECTION |
240                  SensorFlagBits::CONTINUOUS_MODE
241     },
242     {
243         .sensorHandle = kSensorHandleHingeAngle0,
244         .name = "Goldfish hinge sensor0 (in degrees)",
245         .vendor = kAospVendor,
246         .version = 1,
247         .type = SensorType::HINGE_ANGLE,
248         .typeAsString = "android.sensor.hinge_angle",
249         .maxRange = 360,
250         .resolution = 1.0,
251         .power = 3.0,
252         .minDelay = 0,
253         .fifoReservedEventCount = 0,
254         .fifoMaxEventCount = 0,
255         .requiredPermission = "",
256         .maxDelay = 0,
257         .flags = SensorFlagBits::DATA_INJECTION |
258                  SensorFlagBits::ON_CHANGE_MODE |
259                  SensorFlagBits::WAKE_UP
260     },
261     {
262         .sensorHandle = kSensorHandleHingeAngle1,
263         .name = "Goldfish hinge sensor1 (in degrees)",
264         .vendor = kAospVendor,
265         .version = 1,
266         .type = SensorType::HINGE_ANGLE,
267         .typeAsString = "android.sensor.hinge_angle",
268         .maxRange = 360,
269         .resolution = 1.0,
270         .power = 3.0,
271         .minDelay = 0,
272         .fifoReservedEventCount = 0,
273         .fifoMaxEventCount = 0,
274         .requiredPermission = "",
275         .maxDelay = 0,
276         .flags = SensorFlagBits::DATA_INJECTION |
277                  SensorFlagBits::ON_CHANGE_MODE |
278                  SensorFlagBits::WAKE_UP
279     },
280     {
281         .sensorHandle = kSensorHandleHingeAngle2,
282         .name = "Goldfish hinge sensor2 (in degrees)",
283         .vendor = kAospVendor,
284         .version = 1,
285         .type = SensorType::HINGE_ANGLE,
286         .typeAsString = "android.sensor.hinge_angle",
287         .maxRange = 360,
288         .resolution = 1.0,
289         .power = 3.0,
290         .minDelay = 0,
291         .fifoReservedEventCount = 0,
292         .fifoMaxEventCount = 0,
293         .requiredPermission = "",
294         .maxDelay = 0,
295         .flags = SensorFlagBits::DATA_INJECTION |
296                  SensorFlagBits::ON_CHANGE_MODE |
297                  SensorFlagBits::WAKE_UP
298     },
299     {
300         .sensorHandle = kSensorHandleHeartRate,
301         .name = "Goldfish Heart rate sensor",
302         .vendor = kAospVendor,
303         .version = 1,
304         .type = SensorType::HEART_RATE,
305         .typeAsString = "android.sensor.heart_rate",
306         .maxRange = 500.0,
307         .resolution = 1.0,
308         .power = 20.0,
309         .minDelay = 0,
310         .fifoReservedEventCount = 0,
311         .fifoMaxEventCount = 0,
312         .requiredPermission = "android.permission.BODY_SENSORS",
313         .maxDelay = 500000,
314         .flags = SensorFlagBits::DATA_INJECTION |
315                  SensorFlagBits::ON_CHANGE_MODE
316     }};
317 
318 constexpr int kSensorNumber = sizeof(kAllSensors) / sizeof(kAllSensors[0]);
319 
320 static_assert(kSensorNumber == sizeof(kQemuSensorName) / sizeof(kQemuSensorName[0]),
321               "sizes of kAllSensors and kQemuSensorName arrays must match");
322 
getSensorNumber()323 int getSensorNumber() { return kSensorNumber; }
324 
isSensorHandleValid(const int h)325 bool isSensorHandleValid(const int h) {
326     return h >= 0 && h < kSensorNumber;
327 }
328 
getSensorInfoByHandle(const int h)329 const SensorInfo* getSensorInfoByHandle(const int h) {
330     return isSensorHandleValid(h) ? &kAllSensors[h] : nullptr;
331 }
332 
getQemuSensorNameByHandle(const int h)333 const char* getQemuSensorNameByHandle(const int h) {
334     return kQemuSensorName[h];
335 }
336 
337 }  // namespace goldfish
338