Publish current prop state in VNS when subscribed
Change-Id: I6962d913ac9d910e4bea7e7e117252ff23f0228a
Fix: 27976343
diff --git a/service/src/com/android/car/DayNightModePolicy.java b/service/src/com/android/car/DayNightModePolicy.java
index 38a5332..efe007a 100644
--- a/service/src/com/android/car/DayNightModePolicy.java
+++ b/service/src/com/android/car/DayNightModePolicy.java
@@ -16,15 +16,11 @@
package com.android.car;
-import android.car.Car;
import android.car.hardware.CarSensorEvent;
import android.car.hardware.CarSensorManager;
import android.content.Context;
-import android.os.SystemClock;
import android.util.Log;
-import com.android.car.hal.SensorHalServiceBase.SensorListener;
-
import java.io.PrintWriter;
//TODO
@@ -50,7 +46,10 @@
}
public static CarSensorEvent getDefaultValue(int sensorType) {
- return createEvent(true /* isNight */);
+ // There's a race condition and timestamp from vehicle HAL could be slightly less
+ // then current call to SystemClock.elapsedRealtimeNanos() will return.
+ // We want vehicle HAL value always override this default value so we set timestamp to 0.
+ return createEvent(true /* isNight */, 0 /* timestamp */);
}
@Override
@@ -91,9 +90,9 @@
// TODO Auto-generated method stub
}
- private static CarSensorEvent createEvent(boolean isNight) {
+ private static CarSensorEvent createEvent(boolean isNight, long timestamp) {
CarSensorEvent event = new CarSensorEvent(CarSensorManager.SENSOR_TYPE_NIGHT,
- SystemClock.elapsedRealtimeNanos(), 0, 1);
+ timestamp, 0, 1);
event.intValues[0] = isNight ? 1 : 0;
return event;
}
diff --git a/service/src/com/android/car/DrivingStatePolicy.java b/service/src/com/android/car/DrivingStatePolicy.java
index 2b2402f..f8baba2 100644
--- a/service/src/com/android/car/DrivingStatePolicy.java
+++ b/service/src/com/android/car/DrivingStatePolicy.java
@@ -24,8 +24,6 @@
import android.os.SystemClock;
import android.util.Log;
-import com.android.car.hal.SensorHalServiceBase.SensorListener;
-
import java.io.PrintWriter;
import java.util.List;
@@ -97,7 +95,10 @@
sensorType);
return null;
}
- return createEvent(CarSensorEvent.DRIVE_STATUS_FULLY_RESTRICTED);
+ // There's a race condition and timestamp from vehicle HAL could be slightly less
+ // then current call to SystemClock.elapsedRealtimeNanos() will return.
+ // We want vehicle HAL value always override this default value so we set timestamp to 0.
+ return createEvent(CarSensorEvent.DRIVE_STATUS_FULLY_RESTRICTED, 0 /* timestamp */);
}
@Override
@@ -202,8 +203,15 @@
}
private static CarSensorEvent createEvent(int drivingState) {
- CarSensorEvent event = new CarSensorEvent(CarSensorManager.SENSOR_TYPE_DRIVING_STATUS,
- SystemClock.elapsedRealtimeNanos(), 0, 1);
+ return createEvent(drivingState, SystemClock.elapsedRealtimeNanos());
+ }
+
+ private static CarSensorEvent createEvent(int drivingState, long timestamp) {
+ CarSensorEvent event = new CarSensorEvent(
+ CarSensorManager.SENSOR_TYPE_DRIVING_STATUS,
+ timestamp,
+ 0 /* float values */,
+ 1 /* int values */);
event.intValues[0] = drivingState;
return event;
}