aboutsummaryrefslogtreecommitdiff
path: root/car-lib
diff options
context:
space:
mode:
authorSteve Paik <spaik@google.com>2018-06-06 18:11:55 -0700
committerSteve Paik <spaik@google.com>2018-06-07 06:58:17 +0000
commit417631a1fb9a280d365aab6fb8d3b38ccd65e142 (patch)
tree1b7230e4c6b1ba801f539153b875b710dd00e737 /car-lib
parentf5a142d88a464781d592052a41fe37c81b56c74b (diff)
downloadCar-417631a1fb9a280d365aab6fb8d3b38ccd65e142.tar.gz
Fix Sensor test fragment
- Convert sensor test fragment to use car-lib instead of car-support-lib - Remove accelerometer, gyro, compass, gps from sensor test fragment (they are not supported in car-lib) Bug: 80371235 Bug: 79614473 Bug: 79613345 Test: Embedded Kitchen Sink Change-Id: Ideeb4bfcf32bfa1d1e92000c5315ee54748adedb Merged-In: Iffd7c82e3adcde6522d51a562885cc2abb8f11e4
Diffstat (limited to 'car-lib')
-rw-r--r--car-lib/src/android/car/VehiclePropertyType.java62
-rw-r--r--car-lib/src/android/car/hardware/CarSensorManager.java49
2 files changed, 91 insertions, 20 deletions
diff --git a/car-lib/src/android/car/VehiclePropertyType.java b/car-lib/src/android/car/VehiclePropertyType.java
new file mode 100644
index 0000000000..b236d2d643
--- /dev/null
+++ b/car-lib/src/android/car/VehiclePropertyType.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.car;
+
+import android.annotation.IntDef;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+
+/**
+ * Value type of VehicleProperty
+ * @hide
+ */
+public class VehiclePropertyType {
+ public static final int STRING = 0x00100000;
+ public static final int BOOLEAN = 0x00200000;
+ public static final int INT32 = 0x00400000;
+ public static final int INT32_VEC = 0x00410000;
+ public static final int INT64 = 0x00500000;
+ public static final int INT64_VEC = 0x00510000;
+ public static final int FLOAT = 0x00600000;
+ public static final int FLOAT_VEC = 0x00610000;
+ public static final int BYTES = 0x00700000;
+ public static final int MIXED = 0x00e00000;
+ public static final int MASK = 0x00ff0000;
+ /** @hide */
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef({
+ STRING,
+ BOOLEAN,
+ INT32,
+ INT32_VEC,
+ INT64,
+ INT64_VEC,
+ FLOAT,
+ FLOAT_VEC,
+ BYTES,
+ /**
+ * Any combination of scalar or vector types. The exact format must be
+ * provided in the description of the property.
+ */
+ MIXED,
+ MASK
+ })
+ public @interface Enum {}
+ private VehiclePropertyType() {}
+}
diff --git a/car-lib/src/android/car/hardware/CarSensorManager.java b/car-lib/src/android/car/hardware/CarSensorManager.java
index f6cc8dfdbf..253660462f 100644
--- a/car-lib/src/android/car/hardware/CarSensorManager.java
+++ b/car-lib/src/android/car/hardware/CarSensorManager.java
@@ -24,6 +24,7 @@ import android.car.CarApiUtil;
import android.car.CarLibLog;
import android.car.CarManagerBase;
import android.car.CarNotConnectedException;
+import android.car.VehiclePropertyType;
import android.car.hardware.property.CarPropertyManager;
import android.content.Context;
import android.os.Bundle;
@@ -468,26 +469,34 @@ public final class CarSensorManager implements CarManagerBase {
private CarSensorEvent createCarSensorEvent(CarPropertyValue propertyValue) {
CarSensorEvent event = null;
- Object o = propertyValue.getValue();
- if (o instanceof Float) {
- event = new CarSensorEvent(propertyValue.getPropertyId(),
- propertyValue.getTimestamp(), 1, 0, 0);
- event.floatValues[0] = (float) o;
- } else if (o instanceof Integer) {
- event = new CarSensorEvent(propertyValue.getPropertyId(),
- propertyValue.getTimestamp(), 0, 1, 0);
- event.intValues[0] = (int) o;
- } else if (o instanceof Boolean) {
- event = new CarSensorEvent(propertyValue.getPropertyId(),
- propertyValue.getTimestamp(), 0, 1, 0);
- event.intValues[0] = (boolean) o ? 1 : 0;
- } else if (o instanceof Long[]) {
- Long[] value = (Long[]) o;
- event = new CarSensorEvent(propertyValue.getPropertyId(),
- propertyValue.getTimestamp(), 0, 0, value.length);
- for (int i = 0; i < value.length; i++) {
- event.longValues[i] = value[i];
- }
+ switch (propertyValue.getPropertyId() & VehiclePropertyType.MASK) {
+ case VehiclePropertyType.FLOAT:
+ event = new CarSensorEvent(propertyValue.getPropertyId(),
+ propertyValue.getTimestamp(), 1, 0, 0);
+ event.floatValues[0] = (float) propertyValue.getValue();
+ break;
+ case VehiclePropertyType.INT32:
+ event = new CarSensorEvent(propertyValue.getPropertyId(),
+ propertyValue.getTimestamp(), 0, 1, 0);
+ event.intValues[0] = (int) propertyValue.getValue();
+ break;
+ case VehiclePropertyType.BOOLEAN:
+ event = new CarSensorEvent(propertyValue.getPropertyId(),
+ propertyValue.getTimestamp(), 0, 1, 0);
+ event.intValues[0] = (boolean) propertyValue.getValue() ? 1 : 0;
+ break;
+ case VehiclePropertyType.INT64_VEC:
+ Object[] value = (Object[]) propertyValue.getValue();
+ event = new CarSensorEvent(propertyValue.getPropertyId(),
+ propertyValue.getTimestamp(), 0, 0, value.length);
+ for (int i = 0; i < value.length; i++) {
+ event.longValues[i] = (Long) value[i];
+ }
+ break;
+ default:
+ Log.e(TAG, "unhandled VehiclePropertyType for propId="
+ + propertyValue.getPropertyId());
+ break;
}
return event;
}