Add on-property-set listener to VNS
Change-Id: Id0b0fb15f42e1af0ca4899ea625bcc77f1320db7
Fix: b/31656523
diff --git a/libvehiclenetwork/java/src/com/android/car/vehiclenetwork/IVehicleNetwork.aidl b/libvehiclenetwork/java/src/com/android/car/vehiclenetwork/IVehicleNetwork.aidl
index d324b8e..a081fd0 100644
--- a/libvehiclenetwork/java/src/com/android/car/vehiclenetwork/IVehicleNetwork.aidl
+++ b/libvehiclenetwork/java/src/com/android/car/vehiclenetwork/IVehicleNetwork.aidl
@@ -33,7 +33,7 @@
VehiclePropValueParcelable getProperty(in VehiclePropValueParcelable value) = 2;
/** For error case, exception will be thrown. */
void subscribe(in IVehicleNetworkListener listener, int property, float sampleRate,
- int zones) = 3;
+ int zones, int flags) = 3;
void unsubscribe(in IVehicleNetworkListener listener, int property) = 4;
/** For testing only. inject events. */
void injectEvent(in VehiclePropValueParcelable value) = 5;
diff --git a/libvehiclenetwork/java/src/com/android/car/vehiclenetwork/IVehicleNetworkListener.aidl b/libvehiclenetwork/java/src/com/android/car/vehiclenetwork/IVehicleNetworkListener.aidl
index b70df82..3acee49 100644
--- a/libvehiclenetwork/java/src/com/android/car/vehiclenetwork/IVehicleNetworkListener.aidl
+++ b/libvehiclenetwork/java/src/com/android/car/vehiclenetwork/IVehicleNetworkListener.aidl
@@ -17,6 +17,7 @@
package com.android.car.vehiclenetwork;
import com.android.car.vehiclenetwork.VehiclePropValuesParcelable;
+import com.android.car.vehiclenetwork.VehiclePropValueParcelable;
/**
* Listener for vehicle network service. Intentionally both way as this is supposed to be
@@ -27,5 +28,6 @@
void onVehicleNetworkEvents(in VehiclePropValuesParcelable values) = 0;
void onHalError(int errorCode, int property, int operation) = 1;
void onHalRestart(boolean inMocking) = 2;
+ void onPropertySet(in VehiclePropValueParcelable value) = 3;
//TODO add specialized onVehicleNetworkEvents for byte array for efficiency
}
diff --git a/libvehiclenetwork/java/src/com/android/car/vehiclenetwork/VehicleNetwork.java b/libvehiclenetwork/java/src/com/android/car/vehiclenetwork/VehicleNetwork.java
index 6724247..471c2c3 100644
--- a/libvehiclenetwork/java/src/com/android/car/vehiclenetwork/VehicleNetwork.java
+++ b/libvehiclenetwork/java/src/com/android/car/vehiclenetwork/VehicleNetwork.java
@@ -20,6 +20,7 @@
import static com.android.car.vehiclenetwork.VehiclePropValueUtil.toFloatArray;
import static com.android.car.vehiclenetwork.VehiclePropValueUtil.toIntArray;
+import android.annotation.IntDef;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
@@ -34,6 +35,8 @@
import com.android.car.vehiclenetwork.VehicleNetworkProto.VehiclePropValues;
import com.android.internal.annotations.GuardedBy;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
import java.lang.ref.WeakReference;
/**
@@ -51,6 +54,7 @@
void onVehicleNetworkEvents(VehiclePropValues values);
void onHalError(int errorCode, int property, int operation);
void onHalRestart(boolean inMocking);
+ void onPropertySet(VehiclePropValue value);
}
public interface VehicleNetworkHalMock {
@@ -61,6 +65,21 @@
void onPropertyUnsubscribe(int property);
}
+ /**
+ * Flags to be used in #subscribe(int, float, int, int).
+ */
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef({
+ SubscribeFlags.HAL_EVENT,
+ SubscribeFlags.SET_CALL,
+ SubscribeFlags.DEFAULT,
+ })
+ public @interface SubscribeFlags {
+ int HAL_EVENT = 0x1;
+ int SET_CALL = 0x2;
+ int DEFAULT = HAL_EVENT;
+ }
+
private static final String TAG = VehicleNetwork.class.getSimpleName();
private final IVehicleNetwork mService;
@@ -422,12 +441,26 @@
}
/**
- * Subscribe given property with given sample rate.
+ * Subscribe given property with given sample rate and zones.
*/
public void subscribe(int property, float sampleRate, int zones)
throws IllegalArgumentException {
try {
- mService.subscribe(mVehicleNetworkListener, property, sampleRate, zones);
+ mService.subscribe(mVehicleNetworkListener, property, sampleRate, zones,
+ SubscribeFlags.DEFAULT);
+ } catch (RemoteException e) {
+ handleRemoteException(e);
+ }
+ }
+
+ /**
+ * Subscribe given property with given sample rate, zones and flags.
+ */
+ @SuppressWarnings("ResourceType")
+ public void subscribe(int property, float sampleRate, int zones, @SubscribeFlags int flags)
+ throws IllegalArgumentException {
+ try {
+ mService.subscribe(mVehicleNetworkListener, property, sampleRate, zones, flags);
} catch (RemoteException e) {
handleRemoteException(e);
}
@@ -575,11 +608,16 @@
mListener.onHalRestart(inMocking);
}
+ private void handleOnPropertySet(VehiclePropValue value) {
+ mListener.onPropertySet(value);
+ }
+
private class EventHandler extends Handler {
private static final int MSG_EVENTS = 0;
private static final int MSG_HAL_ERROR = 1;
private static final int MSG_HAL_RESTART = 2;
+ private static final int MSG_ON_PROPERTY_SET = 3;
private EventHandler(Looper looper) {
super(looper);
@@ -600,6 +638,11 @@
sendMessage(msg);
}
+ private void notifyPropertySet(VehiclePropValue value) {
+ Message msg = obtainMessage(MSG_ON_PROPERTY_SET, value);
+ sendMessage(msg);
+ }
+
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
@@ -612,6 +655,8 @@
case MSG_HAL_RESTART:
handleHalRestart(msg.arg1 == 1);
break;
+ case MSG_ON_PROPERTY_SET:
+ handleOnPropertySet((VehiclePropValue) msg.obj);
default:
Log.w(TAG, "Unknown message:" + msg.what, new RuntimeException());
break;
@@ -623,8 +668,8 @@
private final WeakReference<VehicleNetwork> mVehicleNetwork;
- private IVehicleNetworkListenerImpl(VehicleNetwork vehicleNewotk) {
- mVehicleNetwork = new WeakReference<>(vehicleNewotk);
+ private IVehicleNetworkListenerImpl(VehicleNetwork vehicleNetwork) {
+ mVehicleNetwork = new WeakReference<>(vehicleNetwork);
}
@Override
@@ -636,6 +681,14 @@
}
@Override
+ public void onPropertySet(VehiclePropValueParcelable value) {
+ VehicleNetwork vehicleNetwork = mVehicleNetwork.get();
+ if (vehicleNetwork != null) {
+ vehicleNetwork.mEventHandler.notifyPropertySet(value.value);
+ }
+ }
+
+ @Override
public void onHalError(int errorCode, int property, int operation) {
VehicleNetwork vehicleNetwork = mVehicleNetwork.get();
if (vehicleNetwork != null) {