diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2017-08-04 22:00:40 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-08-04 22:00:40 +0000 |
commit | 6095198f4732cbc18d5a6d30faedba262d0874ff (patch) | |
tree | 66126acb3abc1de3b4a9b3b30e6396b72e30c391 | |
parent | 7e060bcf0cadced1f9b395889413fa4b98a80328 (diff) | |
parent | a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4c (diff) | |
download | Car-6095198f4732cbc18d5a6d30faedba262d0874ff.tar.gz |
Merge "Add getConfigForSensor to CarSensorManager"
11 files changed, 428 insertions, 42 deletions
diff --git a/car-lib/src/android/car/hardware/CarSensorConfig.aidl b/car-lib/src/android/car/hardware/CarSensorConfig.aidl new file mode 100644 index 0000000000..480f751c54 --- /dev/null +++ b/car-lib/src/android/car/hardware/CarSensorConfig.aidl @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2017 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.hardware; + +parcelable CarSensorConfig; diff --git a/car-lib/src/android/car/hardware/CarSensorConfig.java b/car-lib/src/android/car/hardware/CarSensorConfig.java new file mode 100644 index 0000000000..8ba456b0cf --- /dev/null +++ b/car-lib/src/android/car/hardware/CarSensorConfig.java @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2017 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.hardware; + +import android.os.Bundle; +import android.os.Parcel; +import android.os.Parcelable; +import java.util.ArrayList; + +/** + * A CarSensorConfig object corresponds to a single sensor type coming from the car. + * @hide + */ +public class CarSensorConfig implements Parcelable { + /** List of property specific mapped elements in bundle for WHEEL_TICK_DISTANCE sensor*/ + /** @hide */ + public final static String WHEEL_TICK_DISTANCE_SUPPORTED_WHEELS = + "android.car.wheelTickDistanceSupportedWhheels"; + /** @hide */ + public final static String WHEEL_TICK_DISTANCE_FRONT_LEFT_UM_PER_TICK = + "android.car.wheelTickDistanceFrontLeftUmPerTick"; + /** @hide */ + public final static String WHEEL_TICK_DISTANCE_FRONT_RIGHT_UM_PER_TICK = + "android.car.wheelTickDistanceFrontRightUmPerTick"; + /** @hide */ + public final static String WHEEL_TICK_DISTANCE_REAR_RIGHT_UM_PER_TICK = + "android.car.wheelTickDistanceRearRightUmPerTick"; + /** @hide */ + public final static String WHEEL_TICK_DISTANCE_REAR_LEFT_UM_PER_TICK = + "android.car.wheelTickDistanceRearLeftUmPerTick"; + + /** Config data stored in Bundle */ + private final Bundle mConfig; + private final int mType; + + /** @hide */ + public CarSensorConfig(Parcel in) { + mType = in.readInt(); + mConfig = in.readBundle(); + } + + /** @hide */ + @Override + public int describeContents() { + return 0; + } + + /** @hide */ + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(mType); + dest.writeBundle(mConfig); + } + + /** @hide */ + public static final Parcelable.Creator<CarSensorConfig> CREATOR + = new Parcelable.Creator<CarSensorConfig>() { + public CarSensorConfig createFromParcel(Parcel in) { + return new CarSensorConfig(in); + } + + public CarSensorConfig[] newArray(int size) { + return new CarSensorConfig[size]; + } + }; + + /** @hide */ + public CarSensorConfig(int type, Bundle b) { + mType = type; + mConfig = b.deepCopy(); + } + + private void checkType(int type) { + if (mType == type) { + return; + } + throw new UnsupportedOperationException(String.format( + "Invalid sensor type: expected %d, got %d", type, mType)); + } + + /** @hide */ + public Bundle getBundle() { + return mConfig; + } + + /** @hide */ + public int getInt(String key) { + if (mConfig.containsKey(key)) { + return mConfig.getInt(key); + } else { + throw new IllegalArgumentException("SensorType " + mType + + " does not contain key: " + key); + } + } + + /** @hide */ + public int getType() { + return mType; + } + + /** @hide */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getName() + "["); + sb.append("mType: " + mType); + sb.append("mConfig: " + mConfig.toString()); + sb.append("]"); + return sb.toString(); + } +} diff --git a/car-lib/src/android/car/hardware/CarSensorManager.java b/car-lib/src/android/car/hardware/CarSensorManager.java index 796da7f978..e2bce11b78 100644 --- a/car-lib/src/android/car/hardware/CarSensorManager.java +++ b/car-lib/src/android/car/hardware/CarSensorManager.java @@ -25,6 +25,7 @@ import android.car.CarLibLog; import android.car.CarManagerBase; import android.car.CarNotConnectedException; import android.content.Context; +import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.RemoteException; @@ -513,4 +514,28 @@ public final class CarSensorManager implements CarManagerBase { }); } } + + /** + * Get the config data for the given type. + * + * A CarSensorConfig object is returned for every sensor type. However, if there is no + * config, the data will be empty. + * + * @param sensor type to request + * @return CarSensorConfig object + * @throws CarNotConnectedException if the connection to the car service has been lost. + * @hide + */ + public CarSensorConfig getSensorConfig(@SensorType int type) + throws CarNotConnectedException { + assertSensorType(type); + try { + return mService.getSensorConfig(type); + } catch (IllegalStateException e) { + CarApiUtil.checkCarNotConnectedExceptionFromCarService(e); + } catch(RemoteException e) { + handleCarServiceRemoteExceptionAndThrow(e); + } + return new CarSensorConfig(0, Bundle.EMPTY); + } } diff --git a/car-lib/src/android/car/hardware/ICarSensor.aidl b/car-lib/src/android/car/hardware/ICarSensor.aidl index 6f9e3153fc..e943e0f296 100644 --- a/car-lib/src/android/car/hardware/ICarSensor.aidl +++ b/car-lib/src/android/car/hardware/ICarSensor.aidl @@ -16,6 +16,7 @@ package android.car.hardware; +import android.car.hardware.CarSensorConfig; import android.car.hardware.CarSensorEvent; import android.car.hardware.ICarSensorEventListener; @@ -44,4 +45,9 @@ interface ICarSensor { * be affected. */ void unregisterSensorListener(int sensorType, in ICarSensorEventListener callback) = 3; + + /** + * get config flags and config array for the sensor type + */ + CarSensorConfig getSensorConfig(int sensorType) = 4; } diff --git a/car-support-lib/src/android/support/car/hardware/CarSensorConfig.java b/car-support-lib/src/android/support/car/hardware/CarSensorConfig.java new file mode 100644 index 0000000000..3c71e04cc7 --- /dev/null +++ b/car-support-lib/src/android/support/car/hardware/CarSensorConfig.java @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2017 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.support.car.hardware; + +import android.os.Bundle; +import android.support.annotation.RestrictTo; +import java.util.ArrayList; + +import static android.support.annotation.RestrictTo.Scope.GROUP_ID; + +/** + * A CarSensorConfig object corresponds to a single sensor type coming from the car. + * @hide + */ +public class CarSensorConfig { + /** List of property specific mapped elements in bundle for WHEEL_TICK_DISTANCE sensor*/ + /** @hide */ + public final static String WHEEL_TICK_DISTANCE_SUPPORTED_WHEELS = + "android.car.wheelTickDistanceSupportedWhheels"; + /** @hide */ + public final static String WHEEL_TICK_DISTANCE_FRONT_LEFT_UM_PER_TICK = + "android.car.wheelTickDistanceFrontLeftUmPerTick"; + /** @hide */ + public final static String WHEEL_TICK_DISTANCE_FRONT_RIGHT_UM_PER_TICK = + "android.car.wheelTickDistanceFrontRightUmPerTick"; + /** @hide */ + public final static String WHEEL_TICK_DISTANCE_REAR_RIGHT_UM_PER_TICK = + "android.car.wheelTickDistanceRearRightUmPerTick"; + /** @hide */ + public final static String WHEEL_TICK_DISTANCE_REAR_LEFT_UM_PER_TICK = + "android.car.wheelTickDistanceRearLeftUmPerTick"; + + /** Config data stored in Bundle */ + private final Bundle mConfig; + private final int mType; + + private final static int RAW_BUNDLE_SIZE = 4; + private final static int WHEEL_TICK_DISTANCE_BUNDLE_SIZE = 6; + + /** + * Constructs a {@link CarSensorConfig}. Handled by CarSensorManager implementations. + * App developers need not worry about constructing these objects. + * @hide + */ + @RestrictTo(GROUP_ID) + public CarSensorConfig(int type, Bundle in) { + mType = type; + mConfig = in.deepCopy(); + } + + private void checkType(int type) { + if (mType == type) { + return; + } + throw new UnsupportedOperationException(String.format( + "Invalid sensor type: expected %d, got %d", type, mType)); + } + + /** @hide */ + public int getInt(String key) { + if (mConfig.containsKey(key)) { + return mConfig.getInt(key); + } else { + throw new IllegalArgumentException("SensorType " + mType + + " does not contain key: " + key); + } + } + + /** @hide */ + public int getType() { + return mType; + } + + /** @hide */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getName() + "["); + sb.append("mConfig: " + mConfig.toString()); + sb.append("mType: " + mType); + sb.append("]"); + return sb.toString(); + } +} diff --git a/car-support-lib/src/android/support/car/hardware/CarSensorManager.java b/car-support-lib/src/android/support/car/hardware/CarSensorManager.java index f705a9f4e3..8bddce1d0a 100644 --- a/car-support-lib/src/android/support/car/hardware/CarSensorManager.java +++ b/car-support-lib/src/android/support/car/hardware/CarSensorManager.java @@ -280,4 +280,15 @@ public abstract class CarSensorManager implements CarManagerBase { */ public abstract CarSensorEvent getLatestSensorEvent(@SensorType int type) throws CarNotConnectedException; + + /** + * Get the config data for the given type. + * @param sensor type to request + * @return CarSensorConfig object + * @throws CarNotConnectedException if the connection to the car service has been lost. + * @hide + */ + public abstract CarSensorConfig getSensorConfig(@SensorType int type) + throws CarNotConnectedException; + } diff --git a/car-support-lib/src/android/support/car/hardware/CarSensorManagerEmbedded.java b/car-support-lib/src/android/support/car/hardware/CarSensorManagerEmbedded.java index 5fa207cc9f..0fde10ff26 100644 --- a/car-support-lib/src/android/support/car/hardware/CarSensorManagerEmbedded.java +++ b/car-support-lib/src/android/support/car/hardware/CarSensorManagerEmbedded.java @@ -155,6 +155,16 @@ public class CarSensorManagerEmbedded extends CarSensorManager { } @Override + public CarSensorConfig getSensorConfig(@SensorType int type) + throws CarNotConnectedException { + try { + return convert(mManager.getSensorConfig(type)); + } catch (android.car.CarNotConnectedException e) { + throw new CarNotConnectedException(e); + } + } + + @Override public void onCarDisconnected() { //nothing to do } @@ -176,6 +186,13 @@ public class CarSensorManagerEmbedded extends CarSensorManager { event.intValues, event.longValues); } + private static CarSensorConfig convert(android.car.hardware.CarSensorConfig cfg) { + if (cfg == null) { + return null; + } + return new CarSensorConfig(cfg.getType(), cfg.getBundle()); + } + private static class OnSensorChangedListenerProxy implements android.car.hardware.CarSensorManager.OnSensorChangedListener { diff --git a/service/src/com/android/car/CarSensorService.java b/service/src/com/android/car/CarSensorService.java index 44a33b4bae..171a8c4bf4 100644 --- a/service/src/com/android/car/CarSensorService.java +++ b/service/src/com/android/car/CarSensorService.java @@ -17,6 +17,7 @@ package com.android.car; import android.car.Car; +import android.car.hardware.CarSensorConfig; import android.car.hardware.CarSensorEvent; import android.car.hardware.CarSensorManager; import android.car.hardware.ICarSensor; @@ -565,6 +566,22 @@ public class CarSensorService extends ICarSensor.Stub } } + @Override + public CarSensorConfig getSensorConfig(int sensorType) { + if (Binder.getCallingUid() != Process.myUid()) { + switch (getSensorPermission(sensorType)) { + case PackageManager.PERMISSION_DENIED: + throw new SecurityException("client does not have permission:" + + getPermissionName(sensorType) + + " pid:" + Binder.getCallingPid() + + " uid:" + Binder.getCallingUid()); + case PackageManager.PERMISSION_GRANTED: + break; + } + } + return(mSensorHal.getSensorConfig(sensorType)); + } + private void stopSensor(SensorRecord record, int sensorType) { if (Log.isLoggable(CarLog.TAG_SENSOR, Log.DEBUG)) { Log.d(CarLog.TAG_SENSOR, "stopSensor " + sensorType); diff --git a/service/src/com/android/car/hal/SensorHalService.java b/service/src/com/android/car/hal/SensorHalService.java index 2b84fc4ecf..cf29f810cf 100644 --- a/service/src/com/android/car/hal/SensorHalService.java +++ b/service/src/com/android/car/hal/SensorHalService.java @@ -19,6 +19,7 @@ package com.android.car.hal; import static java.lang.Integer.toHexString; import android.annotation.Nullable; +import android.car.hardware.CarSensorConfig; import android.car.hardware.CarSensorEvent; import android.car.hardware.CarSensorManager; import android.hardware.automotive.vehicle.V2_0.VehicleGear; @@ -29,11 +30,13 @@ import android.hardware.automotive.vehicle.V2_1.VehicleProperty; import android.hardware.automotive.vehicle.V2_0.VehiclePropertyAccess; import android.hardware.automotive.vehicle.V2_0.VehiclePropertyChangeMode; import android.hardware.automotive.vehicle.V2_0.VehiclePropertyType; +import android.os.Bundle; import android.util.Log; import android.util.SparseIntArray; import com.android.car.CarLog; import com.android.car.CarSensorEventFactory; import java.io.PrintWriter; +import java.util.ArrayList; import java.util.LinkedList; import java.util.List; @@ -50,6 +53,7 @@ public class SensorHalService extends SensorHalServiceBase { public interface SensorListener { /** * Sensor events are available. + * * @param events */ void onSensorEvents(List<CarSensorEvent> events); @@ -57,44 +61,44 @@ public class SensorHalService extends SensorHalServiceBase { // Manager property Id to HAL property Id mapping. private final static ManagerToHalPropIdMap mManagerToHalPropIdMap = - ManagerToHalPropIdMap.create( - CarSensorManager.SENSOR_TYPE_CAR_SPEED, VehicleProperty.PERF_VEHICLE_SPEED, - CarSensorManager.SENSOR_TYPE_RPM, VehicleProperty.ENGINE_RPM, - CarSensorManager.SENSOR_TYPE_ODOMETER, VehicleProperty.PERF_ODOMETER, - CarSensorManager.SENSOR_TYPE_GEAR, VehicleProperty.GEAR_SELECTION, - CarSensorManager.SENSOR_TYPE_NIGHT, VehicleProperty.NIGHT_MODE, - CarSensorManager.SENSOR_TYPE_PARKING_BRAKE, VehicleProperty.PARKING_BRAKE_ON, - CarSensorManager.SENSOR_TYPE_DRIVING_STATUS, VehicleProperty.DRIVING_STATUS, - CarSensorManager.SENSOR_TYPE_FUEL_LEVEL, VehicleProperty.FUEL_LEVEL_LOW, - CarSensorManager.SENSOR_TYPE_IGNITION_STATE, VehicleProperty.IGNITION_STATE, - CarSensorManager.SENSOR_TYPE_WHEEL_TICK_DISTANCE, VehicleProperty.WHEEL_TICK, - CarSensorManager.SENSOR_TYPE_ABS_ACTIVE, VehicleProperty.ABS_ACTIVE, - CarSensorManager.SENSOR_TYPE_TRACTION_CONTROL_ACTIVE, - VehicleProperty.TRACTION_CONTROL_ACTIVE - ); + ManagerToHalPropIdMap.create( + CarSensorManager.SENSOR_TYPE_CAR_SPEED, VehicleProperty.PERF_VEHICLE_SPEED, + CarSensorManager.SENSOR_TYPE_RPM, VehicleProperty.ENGINE_RPM, + CarSensorManager.SENSOR_TYPE_ODOMETER, VehicleProperty.PERF_ODOMETER, + CarSensorManager.SENSOR_TYPE_GEAR, VehicleProperty.GEAR_SELECTION, + CarSensorManager.SENSOR_TYPE_NIGHT, VehicleProperty.NIGHT_MODE, + CarSensorManager.SENSOR_TYPE_PARKING_BRAKE, VehicleProperty.PARKING_BRAKE_ON, + CarSensorManager.SENSOR_TYPE_DRIVING_STATUS, VehicleProperty.DRIVING_STATUS, + CarSensorManager.SENSOR_TYPE_FUEL_LEVEL, VehicleProperty.FUEL_LEVEL_LOW, + CarSensorManager.SENSOR_TYPE_IGNITION_STATE, VehicleProperty.IGNITION_STATE, + CarSensorManager.SENSOR_TYPE_WHEEL_TICK_DISTANCE, VehicleProperty.WHEEL_TICK, + CarSensorManager.SENSOR_TYPE_ABS_ACTIVE, VehicleProperty.ABS_ACTIVE, + CarSensorManager.SENSOR_TYPE_TRACTION_CONTROL_ACTIVE, + VehicleProperty.TRACTION_CONTROL_ACTIVE + ); private final static SparseIntArray mMgrGearToHalMap = initSparseIntArray( - VehicleGear.GEAR_NEUTRAL, CarSensorEvent.GEAR_NEUTRAL, - VehicleGear.GEAR_REVERSE, CarSensorEvent.GEAR_REVERSE, - VehicleGear.GEAR_PARK, CarSensorEvent.GEAR_PARK, - VehicleGear.GEAR_DRIVE, CarSensorEvent.GEAR_DRIVE, - VehicleGear.GEAR_LOW, CarSensorEvent.GEAR_FIRST, // Also GEAR_1 - the value is the same. - VehicleGear.GEAR_2, CarSensorEvent.GEAR_SECOND, - VehicleGear.GEAR_3, CarSensorEvent.GEAR_THIRD, - VehicleGear.GEAR_4, CarSensorEvent.GEAR_FOURTH, - VehicleGear.GEAR_5, CarSensorEvent.GEAR_FIFTH, - VehicleGear.GEAR_6, CarSensorEvent.GEAR_SIXTH, - VehicleGear.GEAR_7, CarSensorEvent.GEAR_SEVENTH, - VehicleGear.GEAR_8, CarSensorEvent.GEAR_EIGHTH, - VehicleGear.GEAR_9, CarSensorEvent.GEAR_NINTH); + VehicleGear.GEAR_NEUTRAL, CarSensorEvent.GEAR_NEUTRAL, + VehicleGear.GEAR_REVERSE, CarSensorEvent.GEAR_REVERSE, + VehicleGear.GEAR_PARK, CarSensorEvent.GEAR_PARK, + VehicleGear.GEAR_DRIVE, CarSensorEvent.GEAR_DRIVE, + VehicleGear.GEAR_LOW, CarSensorEvent.GEAR_FIRST, // Also GEAR_1 - the value is the same. + VehicleGear.GEAR_2, CarSensorEvent.GEAR_SECOND, + VehicleGear.GEAR_3, CarSensorEvent.GEAR_THIRD, + VehicleGear.GEAR_4, CarSensorEvent.GEAR_FOURTH, + VehicleGear.GEAR_5, CarSensorEvent.GEAR_FIFTH, + VehicleGear.GEAR_6, CarSensorEvent.GEAR_SIXTH, + VehicleGear.GEAR_7, CarSensorEvent.GEAR_SEVENTH, + VehicleGear.GEAR_8, CarSensorEvent.GEAR_EIGHTH, + VehicleGear.GEAR_9, CarSensorEvent.GEAR_NINTH); private final static SparseIntArray mMgrIgnitionStateToHalMap = initSparseIntArray( - VehicleIgnitionState.UNDEFINED, CarSensorEvent.IGNITION_STATE_UNDEFINED, - VehicleIgnitionState.LOCK, CarSensorEvent.IGNITION_STATE_LOCK, - VehicleIgnitionState.OFF, CarSensorEvent.IGNITION_STATE_OFF, - VehicleIgnitionState.ACC, CarSensorEvent.IGNITION_STATE_ACC, - VehicleIgnitionState.ON, CarSensorEvent.IGNITION_STATE_ON, - VehicleIgnitionState.START, CarSensorEvent.IGNITION_STATE_START); + VehicleIgnitionState.UNDEFINED, CarSensorEvent.IGNITION_STATE_UNDEFINED, + VehicleIgnitionState.LOCK, CarSensorEvent.IGNITION_STATE_LOCK, + VehicleIgnitionState.OFF, CarSensorEvent.IGNITION_STATE_OFF, + VehicleIgnitionState.ACC, CarSensorEvent.IGNITION_STATE_ACC, + VehicleIgnitionState.ON, CarSensorEvent.IGNITION_STATE_ON, + VehicleIgnitionState.START, CarSensorEvent.IGNITION_STATE_START); private SensorListener mSensorListener; @@ -102,15 +106,17 @@ public class SensorHalService extends SensorHalServiceBase { @Override public void init() { + VehiclePropConfig config; // Populate internal values if available - VehiclePropConfig config = mSensorToPropConfig.get( - CarSensorManager.SENSOR_TYPE_WHEEL_TICK_DISTANCE); + synchronized (this) { + config = mSensorToPropConfig.get(CarSensorManager.SENSOR_TYPE_WHEEL_TICK_DISTANCE); + } if (config == null) { Log.e(TAG, "init: unable to get property config for SENSOR_TYPE_WHEEL_TICK_DISTANCE"); } else { - for (int i=0; i<4; i++) { - // ConfigArray starts with Wheels enum at idx 0 - mMicrometersPerWheelTick[i] = config.configArray.get(i+1); + for (int i = 0; i < 4; i++) { + mMicrometersPerWheelTick[i] = config.configArray.get(i + + INDEX_WHEEL_DISTANCE_FRONT_LEFT); } } super.init(); @@ -137,6 +143,7 @@ public class SensorHalService extends SensorHalServiceBase { // Should be used only inside handleHalEvents method. private final LinkedList<CarSensorEvent> mEventsToDispatch = new LinkedList<>(); + @Override public void handleHalEvents(List<VehiclePropValue> values) { for (VehiclePropValue v : values) { @@ -165,7 +172,7 @@ public class SensorHalService extends SensorHalServiceBase { mgrValue = mMgrGearToHalMap.get(halValue, -1); break; case VehicleProperty.IGNITION_STATE: - mgrValue = mMgrIgnitionStateToHalMap.get(halValue, -1); + mgrValue = mMgrIgnitionStateToHalMap.get(halValue, -1); default: break; // Do nothing } @@ -192,7 +199,7 @@ public class SensorHalService extends SensorHalServiceBase { break; case VehiclePropertyType.INT32: Integer mgrVal = mapHalEnumValueToMgr(property, v.value.int32Values.get(0)); - event = mgrVal == null ? null + event = mgrVal == null ? null : CarSensorEventFactory.createIntEvent(sensorType, v.timestamp, mgrVal); break; case VehiclePropertyType.FLOAT: @@ -283,4 +290,50 @@ public class SensorHalService extends SensorHalServiceBase { } return map; } -} + + private static final int INDEX_WHEEL_DISTANCE_ENABLE_FLAG = 0; + private static final int INDEX_WHEEL_DISTANCE_FRONT_LEFT = 1; + private static final int INDEX_WHEEL_DISTANCE_FRONT_RIGHT = 2; + private static final int INDEX_WHEEL_DISTANCE_REAR_RIGHT = 3; + private static final int INDEX_WHEEL_DISTANCE_REAR_LEFT = 4; + private static final int WHEEL_TICK_DISTANCE_BUNDLE_SIZE = 6; + + private Bundle createWheelDistanceTickBundle(ArrayList<Integer> configArray) { + Bundle b = new Bundle(WHEEL_TICK_DISTANCE_BUNDLE_SIZE); + b.putInt(CarSensorConfig.WHEEL_TICK_DISTANCE_SUPPORTED_WHEELS, + configArray.get(INDEX_WHEEL_DISTANCE_ENABLE_FLAG)); + b.putInt(CarSensorConfig.WHEEL_TICK_DISTANCE_FRONT_LEFT_UM_PER_TICK, + configArray.get(INDEX_WHEEL_DISTANCE_FRONT_LEFT)); + b.putInt(CarSensorConfig.WHEEL_TICK_DISTANCE_FRONT_RIGHT_UM_PER_TICK, + configArray.get(INDEX_WHEEL_DISTANCE_FRONT_RIGHT)); + b.putInt(CarSensorConfig.WHEEL_TICK_DISTANCE_REAR_RIGHT_UM_PER_TICK, + configArray.get(INDEX_WHEEL_DISTANCE_REAR_RIGHT)); + b.putInt(CarSensorConfig.WHEEL_TICK_DISTANCE_REAR_LEFT_UM_PER_TICK, + configArray.get(INDEX_WHEEL_DISTANCE_REAR_LEFT)); + return b; + } + + + public CarSensorConfig getSensorConfig(int sensorType) { + VehiclePropConfig cfg; + synchronized (this) { + cfg = mSensorToPropConfig.get(sensorType); + } + if (cfg == null) { + /* Invalid sensor type. */ + throw new IllegalArgumentException("Unknown sensorType = " + sensorType); + } else { + Bundle b; + switch(sensorType) { + case CarSensorManager.SENSOR_TYPE_WHEEL_TICK_DISTANCE: + b = createWheelDistanceTickBundle(cfg.configArray); + break; + default: + /* Unhandled config. Create empty bundle */ + b = Bundle.EMPTY; + break; + } + return new CarSensorConfig(sensorType, b); + } + } +}
\ No newline at end of file diff --git a/tests/EmbeddedKitchenSinkApp/res/values/strings.xml b/tests/EmbeddedKitchenSinkApp/res/values/strings.xml index 75fbceb158..69c57dc025 100644 --- a/tests/EmbeddedKitchenSinkApp/res/values/strings.xml +++ b/tests/EmbeddedKitchenSinkApp/res/values/strings.xml @@ -182,6 +182,7 @@ <string name="sensor_gps">GPS Satellites[%1$s]: inView: %2$s, inUse: %3$s. %4$s</string> <string name="sensor_single_gps_satellite">(%1$s): usedInFix: %2$s, prn: %3$s, snr: %4$s, azimuth: %5$s, elevation: %6$s</string> <string name="sensor_wheel_ticks">Wheel Distance[%1$s]: reset=%2$s, FL=%3$s, FR=%4$s, RL=%5$s, RR=%6$s</string> + <string name="sensor_wheel_ticks_cfg">Wheel Distance Config: Wheels=%1$s, FL=%2$s, FR=%3$s, RL=%4$s, RR=%5$s</string> <string name="sensor_abs_is_active">ABS[%1$s]: isActive=%2$s</string> <string name="sensor_traction_control_is_active">Traction Control[%1$s]: isActive=%2$s</string> diff --git a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/sensor/SensorsTestFragment.java b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/sensor/SensorsTestFragment.java index 082a3f0a6b..d502c75901 100644 --- a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/sensor/SensorsTestFragment.java +++ b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/sensor/SensorsTestFragment.java @@ -24,6 +24,7 @@ import android.location.Location; import android.os.Bundle; import android.os.Handler; import android.support.car.CarNotConnectedException; +import android.support.car.hardware.CarSensorConfig; import android.support.car.hardware.CarSensorEvent; import android.support.car.hardware.CarSensorManager; import android.support.v4.app.Fragment; @@ -285,6 +286,19 @@ public class SensorsTestFragment extends Fragment { getTimestamp(event), mNaString, mNaString, mNaString, mNaString, mNaString)); } + // Get the config data + try { + CarSensorConfig c = mSensorManager.getSensorConfig( + CarSensorManager.SENSOR_TYPE_WHEEL_TICK_DISTANCE); + summary.add(getContext().getString(R.string.sensor_wheel_ticks_cfg, + c.getInt(CarSensorConfig.WHEEL_TICK_DISTANCE_SUPPORTED_WHEELS), + c.getInt(CarSensorConfig.WHEEL_TICK_DISTANCE_FRONT_LEFT_UM_PER_TICK), + c.getInt(CarSensorConfig.WHEEL_TICK_DISTANCE_FRONT_RIGHT_UM_PER_TICK), + c.getInt(CarSensorConfig.WHEEL_TICK_DISTANCE_REAR_LEFT_UM_PER_TICK), + c.getInt(CarSensorConfig.WHEEL_TICK_DISTANCE_REAR_RIGHT_UM_PER_TICK))); + } catch (CarNotConnectedException e) { + Log.e(TAG, "Car not connected or not supported", e); + } break; case CarSensorManager.SENSOR_TYPE_ABS_ACTIVE: summary.add(getContext().getString(R.string.sensor_abs_is_active, |