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::V1_0::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 };
38 
39 const SensorInfo kAllSensors[] = {
40     {
41         .sensorHandle = kSensorHandleAccelerometer,
42         .name = "Goldfish 3-axis Accelerometer",
43         .vendor = kAospVendor,
44         .version = 1,
45         .type = SensorType::ACCELEROMETER,
46         .typeAsString = "android.sensor.accelerometer",
47         .maxRange = 39.3,
48         .resolution = 1.0 / 4032.0,
49         .power = 3.0,
50         .minDelay = 10000,
51         .fifoReservedEventCount = 0,
52         .fifoMaxEventCount = 0,
53         .requiredPermission = "",
54         .maxDelay = 500000,
55         .flags = SensorFlagBits::DATA_INJECTION |
56                  SensorFlagBits::CONTINUOUS_MODE
57     },
58     {
59         .sensorHandle = kSensorHandleGyroscope,
60         .name = "Goldfish 3-axis Gyroscope",
61         .vendor = kAospVendor,
62         .version = 1,
63         .type = SensorType::GYROSCOPE,
64         .typeAsString = "android.sensor.gyroscope",
65         .maxRange = 16.46,
66         .resolution = 1.0 / 1000.0,
67         .power = 3.0,
68         .minDelay = 10000,
69         .fifoReservedEventCount = 0,
70         .fifoMaxEventCount = 0,
71         .requiredPermission = "",
72         .maxDelay = 500000,
73         .flags = SensorFlagBits::DATA_INJECTION |
74                  SensorFlagBits::CONTINUOUS_MODE
75     },
76     {
77         .sensorHandle = kSensorHandleMagneticField,
78         .name = "Goldfish 3-axis Magnetic field sensor",
79         .vendor = kAospVendor,
80         .version = 1,
81         .type = SensorType::MAGNETIC_FIELD,
82         .typeAsString = "android.sensor.magnetic_field",
83         .maxRange = 2000.0,
84         .resolution = .5,
85         .power = 6.7,
86         .minDelay = 10000,
87         .fifoReservedEventCount = 0,
88         .fifoMaxEventCount = 0,
89         .requiredPermission = "",
90         .maxDelay = 500000,
91         .flags = SensorFlagBits::DATA_INJECTION |
92                  SensorFlagBits::CONTINUOUS_MODE
93     },
94     {
95         .sensorHandle = kSensorHandleOrientation,
96         .name = "Goldfish Orientation sensor",
97         .vendor = kAospVendor,
98         .version = 1,
99         .type = SensorType::ORIENTATION,
100         .typeAsString = "android.sensor.orientation",
101         .maxRange = 360.0,
102         .resolution = 1.0,
103         .power = 9.7,
104         .minDelay = 10000,
105         .fifoReservedEventCount = 0,
106         .fifoMaxEventCount = 0,
107         .requiredPermission = "",
108         .maxDelay = 500000,
109         .flags = SensorFlagBits::DATA_INJECTION |
110                  SensorFlagBits::CONTINUOUS_MODE
111     },
112     {
113         .sensorHandle = kSensorHandleAmbientTemperature,
114         .name = "Goldfish Ambient Temperature sensor",
115         .vendor = kAospVendor,
116         .version = 1,
117         .type = SensorType::AMBIENT_TEMPERATURE,
118         .typeAsString = "android.sensor.ambient_temperature",
119         .maxRange = 80.0,
120         .resolution = 1.0,
121         .power = 0.0,
122         .minDelay = 0,
123         .fifoReservedEventCount = 0,
124         .fifoMaxEventCount = 0,
125         .requiredPermission = "",
126         .maxDelay = 0,
127         .flags = SensorFlagBits::DATA_INJECTION |
128                  SensorFlagBits::ON_CHANGE_MODE
129     },
130     {
131         .sensorHandle = kSensorHandleProximity,
132         .name = "Goldfish Proximity sensor",
133         .vendor = kAospVendor,
134         .version = 1,
135         .type = SensorType::PROXIMITY,
136         .typeAsString = "android.sensor.proximity",
137         .maxRange = 1.0,
138         .resolution = 1.0,
139         .power = 20.0,
140         .minDelay = 0,
141         .fifoReservedEventCount = 0,
142         .fifoMaxEventCount = 0,
143         .requiredPermission = "",
144         .maxDelay = 0,
145         .flags = SensorFlagBits::DATA_INJECTION |
146                  SensorFlagBits::ON_CHANGE_MODE |
147                  SensorFlagBits::WAKE_UP
148     },
149     {
150         .sensorHandle = kSensorHandleLight,
151         .name = "Goldfish Light sensor",
152         .vendor = kAospVendor,
153         .version = 1,
154         .type = SensorType::LIGHT,
155         .typeAsString = "android.sensor.light",
156         .maxRange = 40000.0,
157         .resolution = 1.0,
158         .power = 20.0,
159         .minDelay = 0,
160         .fifoReservedEventCount = 0,
161         .fifoMaxEventCount = 0,
162         .requiredPermission = "",
163         .maxDelay = 0,
164         .flags = SensorFlagBits::DATA_INJECTION |
165                  SensorFlagBits::ON_CHANGE_MODE
166     },
167     {
168         .sensorHandle = kSensorHandlePressure,
169         .name = "Goldfish Pressure sensor",
170         .vendor = kAospVendor,
171         .version = 1,
172         .type = SensorType::PRESSURE,
173         .typeAsString = "android.sensor.pressure",
174         .maxRange = 800.0,
175         .resolution = 1.0,
176         .power = 20.0,
177         .minDelay = 10000,
178         .fifoReservedEventCount = 0,
179         .fifoMaxEventCount = 0,
180         .requiredPermission = "",
181         .maxDelay = 500000,
182         .flags = SensorFlagBits::DATA_INJECTION |
183                  SensorFlagBits::CONTINUOUS_MODE
184     },
185     {
186         .sensorHandle = kSensorHandleRelativeHumidity,
187         .name = "Goldfish Humidity sensor",
188         .vendor = kAospVendor,
189         .version = 1,
190         .type = SensorType::RELATIVE_HUMIDITY,
191         .typeAsString = "android.sensor.relative_humidity",
192         .maxRange = 100.0,
193         .resolution = 1.0,
194         .power = 20.0,
195         .minDelay = 0,
196         .fifoReservedEventCount = 0,
197         .fifoMaxEventCount = 0,
198         .requiredPermission = "",
199         .maxDelay = 0,
200         .flags = SensorFlagBits::DATA_INJECTION |
201                  SensorFlagBits::ON_CHANGE_MODE
202     },
203     {
204         .sensorHandle = kSensorHandleMagneticFieldUncalibrated,
205         .name = "Goldfish 3-axis Magnetic field sensor (uncalibrated)",
206         .vendor = kAospVendor,
207         .version = 1,
208         .type = SensorType::MAGNETIC_FIELD_UNCALIBRATED,
209         .typeAsString = "android.sensor.magnetic_field_uncalibrated",
210         .maxRange = 2000.0,
211         .resolution = 0.5,
212         .power = 6.7,
213         .minDelay = 10000,
214         .fifoReservedEventCount = 0,
215         .fifoMaxEventCount = 0,
216         .requiredPermission = "",
217         .maxDelay = 500000,
218         .flags = SensorFlagBits::DATA_INJECTION | 0
219     },
220     {
221         .sensorHandle = kSensorHandleGyroscopeFieldUncalibrated,
222         .name = "Goldfish 3-axis Gyroscope (uncalibrated)",
223         .vendor = kAospVendor,
224         .version = 1,
225         .type = SensorType::GYROSCOPE_UNCALIBRATED,
226         .typeAsString = "android.sensor.gyroscope_uncalibrated",
227         .maxRange = 16.46,
228         .resolution = 1.0 / 1000.0,
229         .power = 3.0,
230         .minDelay = 10000,
231         .fifoReservedEventCount = 0,
232         .fifoMaxEventCount = 0,
233         .requiredPermission = "",
234         .maxDelay = 500000,
235         .flags = SensorFlagBits::DATA_INJECTION |
236                  SensorFlagBits::CONTINUOUS_MODE
237     },
238 };
239 
240 constexpr int kSensorNumber = sizeof(kAllSensors) / sizeof(kAllSensors[0]);
241 
242 static_assert(kSensorNumber == sizeof(kQemuSensorName) / sizeof(kQemuSensorName[0]),
243               "sizes of kAllSensors and kQemuSensorName arrays must match");
244 
getSensorNumber()245 int getSensorNumber() { return kSensorNumber; }
246 
isSensorHandleValid(const int h)247 bool isSensorHandleValid(const int h) {
248     return h >= 0 && h < kSensorNumber;
249 }
250 
getSensorInfoByHandle(const int h)251 const SensorInfo* getSensorInfoByHandle(const int h) {
252     return isSensorHandleValid(h) ? &kAllSensors[h] : nullptr;
253 }
254 
getQemuSensorNameByHandle(const int h)255 const char* getQemuSensorNameByHandle(const int h) {
256     return kQemuSensorName[h];
257 }
258 
259 }  // namespace goldfish
260