-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsensor_info.dart
234 lines (209 loc) · 7.73 KB
/
sensor_info.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
import 'package:snooper_android/model/sensors/sensor_type_wrapper.dart';
class SensorInfo {
/// Name string of the sensor.
/// The name is guaranteed to be unique for a particular sensor type.
final String? name;
/// Generic type of this sensor
final SensorTypeWrapper type;
/// The type of this sensor as a string
final String? stringType;
/// Returns true if the sensor is a wake-up sensor.
///
/// More at:
/// https://developer.android.com/reference/android/hardware/Sensor#isWakeUpSensor()
final bool isWakeUpSensor;
/// Each sensor has exactly one reporting mode associated with it.
/// This method returns the reporting mode constant for this sensor type.
final int reportingMode;
/// Vendor string of this sensor.
final String? vendor;
/// Version of the sensor's module.
final int version;
/// Maximum range of the sensor in the sensor's unit.
final double maximumRange;
/// Resolution of the sensor in the sensor's unit
final double resolution;
/// This value is defined only for continuous and on-change sensors.
/// It is the delay between two sensor events corresponding to the lowest frequency
/// that this sensor supports.
/// When lower frequencies are requested through registerListener() the events will
/// be generated at this frequency instead.
/// It can be used to estimate when the batch FIFO may be full.
/// Older devices may set this value to zero.
/// Ignore this value in case it is negative or zero.
/// The max delay for this sensor in microseconds
final int maxDelay;
/// The minimum delay allowed between two events in microseconds or zero if this
/// sensor only returns a value when the data it's measuring changes.
/// Note that if the app does not have the
/// android.Manifest.permission.HIGH_SAMPLING_RATE_SENSORS permission, the minimum
/// delay is capped at 5000 microseconds (200 Hz).
final int minDelay;
/// The "power" current in mA used by this sensor while in use.
/// Note this is NOT measured in Watts, so to yield milliWatts, nominal voltage
/// of the battery has to be taken into account.
///
/// More at:
/// https://source.android.com/devices/sensors/power-use#power_measurement_process
final double power;
// region API >= 24
/// Returns true if the sensor is a dynamic sensor (sensor added at runtime).
final bool isDynamicSensor;
/// Returns true if the sensor supports sensor additional information API
final bool isAdditionalInfoSupported;
// endregion
// region API >= 31
/// Get the highest supported direct report mode rate level of the sensor.
///
/// More at: https://developer.android.com/reference/android/hardware/SensorDirectChannel#summary
final int highestDirectReportRateLevel;
const SensorInfo({
this.name,
required this.type,
this.stringType,
required this.isWakeUpSensor,
required this.reportingMode,
this.vendor,
required this.version,
required this.maximumRange,
required this.resolution,
required this.maxDelay,
required this.minDelay,
required this.power,
required this.isDynamicSensor,
required this.isAdditionalInfoSupported,
required this.highestDirectReportRateLevel,
});
@override
bool operator ==(Object other) =>
identical(this, other) ||
(other is SensorInfo &&
runtimeType == other.runtimeType &&
name == other.name &&
type == other.type &&
stringType == other.stringType &&
isWakeUpSensor == other.isWakeUpSensor &&
reportingMode == other.reportingMode &&
vendor == other.vendor &&
version == other.version &&
maximumRange == other.maximumRange &&
resolution == other.resolution &&
maxDelay == other.maxDelay &&
minDelay == other.minDelay &&
power == other.power &&
isDynamicSensor == other.isDynamicSensor &&
isAdditionalInfoSupported == other.isAdditionalInfoSupported &&
highestDirectReportRateLevel == other.highestDirectReportRateLevel);
@override
int get hashCode =>
name.hashCode ^
type.hashCode ^
stringType.hashCode ^
isWakeUpSensor.hashCode ^
reportingMode.hashCode ^
vendor.hashCode ^
version.hashCode ^
maximumRange.hashCode ^
resolution.hashCode ^
maxDelay.hashCode ^
minDelay.hashCode ^
power.hashCode ^
isDynamicSensor.hashCode ^
isAdditionalInfoSupported.hashCode ^
highestDirectReportRateLevel.hashCode;
@override
String toString() {
return 'SensorInfo{'
' name: $name,'
' type: $type,'
' stringType: $stringType,'
' isWakeUpSensor: $isWakeUpSensor,'
' reportingMode: $reportingMode,'
' vendor: $vendor,'
' version: $version,'
' maximumRange: $maximumRange,'
' resolution: $resolution,'
' maxDelay: $maxDelay,'
' minDelay: $minDelay,'
' power: $power,'
' isDynamicSensor: $isDynamicSensor,'
' isAdditionalInfoSupported: $isAdditionalInfoSupported,'
' highestDirectReportRateLevel: $highestDirectReportRateLevel,'
'}';
}
SensorInfo copyWith({
String? name,
SensorTypeWrapper? type,
String? stringType,
bool? isWakeUpSensor,
int? reportingMode,
String? vendor,
int? version,
double? maximumRange,
double? resolution,
int? maxDelay,
int? minDelay,
double? power,
bool? isDynamicSensor,
bool? isAdditionalInfoSupported,
int? highestDirectReportRateLevel,
}) {
return SensorInfo(
name: name ?? this.name,
type: type ?? this.type,
stringType: stringType ?? this.stringType,
isWakeUpSensor: isWakeUpSensor ?? this.isWakeUpSensor,
reportingMode: reportingMode ?? this.reportingMode,
vendor: vendor ?? this.vendor,
version: version ?? this.version,
maximumRange: maximumRange ?? this.maximumRange,
resolution: resolution ?? this.resolution,
maxDelay: maxDelay ?? this.maxDelay,
minDelay: minDelay ?? this.minDelay,
power: power ?? this.power,
isDynamicSensor: isDynamicSensor ?? this.isDynamicSensor,
isAdditionalInfoSupported:
isAdditionalInfoSupported ?? this.isAdditionalInfoSupported,
highestDirectReportRateLevel:
highestDirectReportRateLevel ?? this.highestDirectReportRateLevel,
);
}
Map<String, dynamic> toMap() {
return {
'name': name,
'type': type.typeValue,
'stringType': stringType,
'isWakeUpSensor': isWakeUpSensor,
'reportingMode': reportingMode,
'vendor': vendor,
'version': version,
'maximumRange': maximumRange,
'resolution': resolution,
'maxDelay': maxDelay,
'minDelay': minDelay,
'power': power,
'isDynamicSensor': isDynamicSensor,
'isAdditionalInfoSupported': isAdditionalInfoSupported,
'highestDirectReportRateLevel': highestDirectReportRateLevel,
};
}
factory SensorInfo.fromMap(Map<String, dynamic> map) {
return SensorInfo(
name: map['name'] as String?,
type: SensorTypeWrapper(typeValue: map['type'] as int),
stringType: map['stringType'] as String?,
isWakeUpSensor: map['isWakeUpSensor'] as bool,
reportingMode: map['reportingMode'] as int,
vendor: map['vendor'] as String?,
version: map['version'] as int,
maximumRange: map['maximumRange'] as double,
resolution: map['resolution'] as double,
maxDelay: map['maxDelay'] as int,
minDelay: map['minDelay'] as int,
power: map['power'] as double,
isDynamicSensor: map['isDynamicSensor'] as bool,
isAdditionalInfoSupported: map['isAdditionalInfoSupported'] as bool,
highestDirectReportRateLevel: map['highestDirectReportRateLevel'] as int,
);
}
}