aboutsummaryrefslogtreecommitdiff
path: root/libvehiclenetwork
diff options
context:
space:
mode:
authorPavel Maltsev <pavelm@google.com>2016-09-27 21:00:41 -0700
committerPavel Maltsev <pavelm@google.com>2016-09-30 11:25:20 -0700
commitb0324b44ecec50074733ac3e0aad6a80a324e4c0 (patch)
treeacd56d1235530bc19515596266f36fb3c9be5392 /libvehiclenetwork
parent5d873a0ab1f5d97a13709d0e663540425a25befb (diff)
downloadCar-b0324b44ecec50074733ac3e0aad6a80a324e4c0.tar.gz
Add on-property-set listener to VNS
Change-Id: Id0b0fb15f42e1af0ca4899ea625bcc77f1320db7 Fix: b/31656523
Diffstat (limited to 'libvehiclenetwork')
-rw-r--r--libvehiclenetwork/include/IVehicleNetwork.h12
-rw-r--r--libvehiclenetwork/include/IVehicleNetworkListener.h9
-rw-r--r--libvehiclenetwork/include/VehicleNetwork.h10
-rw-r--r--libvehiclenetwork/java/src/com/android/car/vehiclenetwork/IVehicleNetwork.aidl2
-rw-r--r--libvehiclenetwork/java/src/com/android/car/vehiclenetwork/IVehicleNetworkListener.aidl2
-rw-r--r--libvehiclenetwork/java/src/com/android/car/vehiclenetwork/VehicleNetwork.java61
-rw-r--r--libvehiclenetwork/libvehiclenetwork-audio-helper/include/VehicleNetworkAudioHelper.h7
-rw-r--r--libvehiclenetwork/libvehiclenetwork-audio-helper/src/VehicleNetworkAudioHelper.cpp4
-rw-r--r--libvehiclenetwork/native/IVehicleNetwork.cpp6
-rw-r--r--libvehiclenetwork/native/IVehicleNetworkListener.cpp23
-rw-r--r--libvehiclenetwork/native/VehicleNetwork.cpp54
11 files changed, 167 insertions, 23 deletions
diff --git a/libvehiclenetwork/include/IVehicleNetwork.h b/libvehiclenetwork/include/IVehicleNetwork.h
index 19e439f858..dd174429a2 100644
--- a/libvehiclenetwork/include/IVehicleNetwork.h
+++ b/libvehiclenetwork/include/IVehicleNetwork.h
@@ -49,7 +49,7 @@ public:
virtual status_t setProperty(const vehicle_prop_value_t& value)= 0;
virtual status_t getProperty(vehicle_prop_value_t* value) = 0;
virtual status_t subscribe(const sp<IVehicleNetworkListener> &listener, int32_t property,
- float sampleRate, int32_t zones) = 0;
+ float sampleRate, int32_t zones, int32_t flags = 0) = 0;
virtual void unsubscribe(const sp<IVehicleNetworkListener> &listener, int32_t property) = 0;
/**
* Inject event for given property. This should work regardless of mocking but usually
@@ -105,6 +105,16 @@ public:
}
};
+struct SubscribeFlags {
+ enum : int32_t {
+ UNDEFINED = 0x00,
+ HAL_EVENT = 0x01,
+ SET_CALL = 0x02,
+
+ DEFAULT = HAL_EVENT,
+ };
+};
+
// ----------------------------------------------------------------------------
}; // namespace android
diff --git a/libvehiclenetwork/include/IVehicleNetworkListener.h b/libvehiclenetwork/include/IVehicleNetworkListener.h
index 139d472afe..9f84f81953 100644
--- a/libvehiclenetwork/include/IVehicleNetworkListener.h
+++ b/libvehiclenetwork/include/IVehicleNetworkListener.h
@@ -55,6 +55,15 @@ public:
* @param inMocking Whether it is in mocking mode or not.
*/
virtual void onHalRestart(bool inMocking) = 0;
+
+ /**
+ * This method gets called if this listener was susbscribed to a property using
+ * SubscribeFlags::SET_CALL flag and set property method was called in
+ * Vehicle Network Service.
+ *
+ * @param value Value that was set by a Vehicle Network Service client.
+ */
+ virtual void onPropertySet(const vehicle_prop_value_t& value) = 0;;
};
// ----------------------------------------------------------------------------
diff --git a/libvehiclenetwork/include/VehicleNetwork.h b/libvehiclenetwork/include/VehicleNetwork.h
index 855d9fcafc..f39af66548 100644
--- a/libvehiclenetwork/include/VehicleNetwork.h
+++ b/libvehiclenetwork/include/VehicleNetwork.h
@@ -46,6 +46,7 @@ public:
virtual void onEvents(sp<VehiclePropValueListHolder>& events) = 0;
virtual void onHalError(int32_t errorCode, int32_t property, int32_t operation) = 0;
virtual void onHalRestart(bool inMocking) = 0;
+ virtual void onPropertySet(const vehicle_prop_value_t& value) = 0;
};
// ----------------------------------------------------------------------------
@@ -56,6 +57,7 @@ class VehicleNetworkEventMessageHandler : public MessageHandler {
EVENT_EVENTS = 0,
EVENT_HAL_ERROR = 1,
EVENT_HAL_RESTART = 2,
+ EVENT_ON_SET = 3,
};
public:
VehicleNetworkEventMessageHandler(const sp<Looper>& looper,
@@ -70,11 +72,14 @@ public:
*/
void handleHalRestart(bool inMocking);
+ void handleOnPropertySet(const vehicle_prop_value_t& value);
+
private:
virtual void handleMessage(const Message& message);
void doHandleHalEvents();
void doHandleHalError();
void doHandleHalRestart();
+ void doHandleOnPropertySet();
private:
mutable Mutex mLock;
sp<Looper> mLooper;
@@ -82,6 +87,7 @@ private:
List<sp<VehiclePropValueListHolder>> mEvents;
List<VehicleHalError*> mHalErrors;
List<bool> mHalRestartEvents;
+ List<vehicle_prop_value_t*> mSetValueEvents;
};
// ----------------------------------------------------------------------------
@@ -116,7 +122,8 @@ public:
status_t setProperty(const vehicle_prop_value_t& value);
/** For generic value getting. value->prop should be set. */
status_t getProperty(vehicle_prop_value_t* value);
- status_t subscribe(int32_t property, float sampleRate, int32_t zones = 0);
+ status_t subscribe(int32_t property, float sampleRate, int32_t zones = 0,
+ int32_t flags = SubscribeFlags::DEFAULT);
void unsubscribe(int32_t property);
// Only for testing purpose
@@ -138,6 +145,7 @@ public:
void onEvents(sp<VehiclePropValueListHolder>& events);
void onHalError(int32_t errorCode, int32_t property, int32_t operation);
void onHalRestart(bool inMocking);
+ void onPropertySet(const vehicle_prop_value_t& value);
private:
VehicleNetwork(sp<IVehicleNetwork>& vehicleNetwork, sp<VehicleNetworkListener> &listener);
diff --git a/libvehiclenetwork/java/src/com/android/car/vehiclenetwork/IVehicleNetwork.aidl b/libvehiclenetwork/java/src/com/android/car/vehiclenetwork/IVehicleNetwork.aidl
index d324b8eb23..a081fd0076 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 @@ interface IVehicleNetwork {
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 b70df82733..3acee4904e 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 @@ interface IVehicleNetworkListener {
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 6724247fe2..471c2c3503 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.isCustomProper
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.VehiclePropValue;
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 @@ public class VehicleNetwork {
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 @@ public class VehicleNetwork {
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 @@ public class VehicleNetwork {
}
/**
- * 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 @@ public class VehicleNetwork {
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 @@ public class VehicleNetwork {
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 @@ public class VehicleNetwork {
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 @@ public class VehicleNetwork {
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 @@ public class VehicleNetwork {
}
@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) {
diff --git a/libvehiclenetwork/libvehiclenetwork-audio-helper/include/VehicleNetworkAudioHelper.h b/libvehiclenetwork/libvehiclenetwork-audio-helper/include/VehicleNetworkAudioHelper.h
index 2763be1e96..220524b383 100644
--- a/libvehiclenetwork/libvehiclenetwork-audio-helper/include/VehicleNetworkAudioHelper.h
+++ b/libvehiclenetwork/libvehiclenetwork-audio-helper/include/VehicleNetworkAudioHelper.h
@@ -58,9 +58,10 @@ public:
bool waitForStreamFocus(int32_t stream, nsecs_t waitTimeNs);
// from VehicleNetworkListener
- virtual void onEvents(sp<VehiclePropValueListHolder>& events) ;
- virtual void onHalError(int32_t errorCode, int32_t property, int32_t operation);
- virtual void onHalRestart(bool inMocking);
+ void onEvents(sp<VehiclePropValueListHolder>& events) override;
+ void onHalError(int32_t errorCode, int32_t property, int32_t operation) override;
+ void onHalRestart(bool inMocking) override;
+ void onPropertySet(const vehicle_prop_value_t& value) override;
private:
void updatePropertiesLocked();
diff --git a/libvehiclenetwork/libvehiclenetwork-audio-helper/src/VehicleNetworkAudioHelper.cpp b/libvehiclenetwork/libvehiclenetwork-audio-helper/src/VehicleNetworkAudioHelper.cpp
index 75b6f6b181..770b2e332c 100644
--- a/libvehiclenetwork/libvehiclenetwork-audio-helper/src/VehicleNetworkAudioHelper.cpp
+++ b/libvehiclenetwork/libvehiclenetwork-audio-helper/src/VehicleNetworkAudioHelper.cpp
@@ -242,4 +242,8 @@ void VehicleNetworkAudioHelper::onHalRestart(bool /*inMocking*/) {
mFocusWait.signal();
}
+void VehicleNetworkAudioHelper::onPropertySet(const vehicle_prop_value_t &value) {
+ // TODO
+}
+
}; // namespace android
diff --git a/libvehiclenetwork/native/IVehicleNetwork.cpp b/libvehiclenetwork/native/IVehicleNetwork.cpp
index ca3892beaf..eb126cd684 100644
--- a/libvehiclenetwork/native/IVehicleNetwork.cpp
+++ b/libvehiclenetwork/native/IVehicleNetwork.cpp
@@ -154,13 +154,14 @@ public:
}
virtual status_t subscribe(const sp<IVehicleNetworkListener> &listener, int32_t property,
- float sampleRate, int32_t zones) {
+ float sampleRate, int32_t zones, int32_t flags) {
Parcel data, reply;
data.writeInterfaceToken(IVehicleNetwork::getInterfaceDescriptor());
data.writeStrongBinder(IInterface::asBinder(listener));
data.writeInt32(property);
data.writeFloat(sampleRate);
data.writeInt32(zones);
+ data.writeInt32(flags);
status_t status = remote()->transact(SUBSCRIBE, data, &reply);
return status;
}
@@ -370,7 +371,8 @@ status_t BnVehicleNetwork::onTransact(uint32_t code, const Parcel& data, Parcel*
}
float sampleRate = data.readFloat();
int32_t zones = data.readInt32();
- r = subscribe(listener, property, sampleRate, zones);
+ int32_t flags = data.readInt32();
+ r = subscribe(listener, property, sampleRate, zones, flags);
BinderUtil::fillNoResultReply(reply);
return r;
} break;
diff --git a/libvehiclenetwork/native/IVehicleNetworkListener.cpp b/libvehiclenetwork/native/IVehicleNetworkListener.cpp
index b8579dcf6d..cd79515926 100644
--- a/libvehiclenetwork/native/IVehicleNetworkListener.cpp
+++ b/libvehiclenetwork/native/IVehicleNetworkListener.cpp
@@ -35,6 +35,7 @@ enum {
ON_EVENTS = IBinder::FIRST_CALL_TRANSACTION,
ON_HAL_ERROR,
ON_HAL_RESTART,
+ ON_PROPERTY_SET,
};
class BpVehicleNetworkListener : public BpInterface<IVehicleNetworkListener>
@@ -78,6 +79,17 @@ public:
data.writeInt32(inMocking ? 1 : 0);
remote()->transact(ON_HAL_RESTART, data, &reply);
}
+
+ virtual void onPropertySet(const vehicle_prop_value_t& value) {
+ Parcel data, reply;
+ data.writeInterfaceToken(IVehicleNetworkListener::getInterfaceDescriptor());
+ status_t r = VehiclePropValueBinderUtil::writeToParcel(data, value);
+ if (r != NO_ERROR) {
+ ALOGE("onPropertySet: failed to write to parcel: %d", r);
+ return;
+ }
+ remote()->transact(ON_PROPERTY_SET, data, &reply);
+ }
};
IMPLEMENT_META_INTERFACE(VehicleNetworkListener, "com.android.car.vehiclenetwork.IVehicleNetworkListener");
@@ -133,6 +145,17 @@ status_t BnVehicleNetworkListener::onTransact(uint32_t code, const Parcel& data,
onHalRestart(inMocking);
return NO_ERROR;
} break;
+ case ON_PROPERTY_SET: {
+ CHECK_INTERFACE(IVehicleNetworkListener, data, reply);
+ ScopedVehiclePropValue value;
+ r = VehiclePropValueBinderUtil::readFromParcel(data, &value.value);
+ if (r == NO_ERROR) {
+ onPropertySet(value.value);
+ } else {
+ ALOGE("onPropertySet: failed to read from parcel: %d", r);
+ }
+ return r;
+ } break;
default:
return BBinder::onTransact(code, data, reply, flags);
}
diff --git a/libvehiclenetwork/native/VehicleNetwork.cpp b/libvehiclenetwork/native/VehicleNetwork.cpp
index 5e57962556..8e8111a370 100644
--- a/libvehiclenetwork/native/VehicleNetwork.cpp
+++ b/libvehiclenetwork/native/VehicleNetwork.cpp
@@ -41,6 +41,7 @@ VehicleNetworkEventMessageHandler::~VehicleNetworkEventMessageHandler() {
}
mHalErrors.clear();
mHalRestartEvents.clear();
+ mSetValueEvents.clear();
}
void VehicleNetworkEventMessageHandler::handleHalEvents(sp<VehiclePropValueListHolder>& events) {
@@ -67,6 +68,12 @@ void VehicleNetworkEventMessageHandler::handleHalRestart(bool inMocking) {
mLooper->sendMessage(this, Message(EVENT_HAL_RESTART));
}
+void VehicleNetworkEventMessageHandler::handleOnPropertySet(const vehicle_prop_value_t& value) {
+ Mutex::Autolock autoLock(mLock);
+ mSetValueEvents.push_back(VehiclePropValueUtil::allocVehicleProp(value));
+ mLooper->sendMessage(this, Message(EVENT_ON_SET));
+}
+
void VehicleNetworkEventMessageHandler::doHandleHalEvents() {
sp<VehiclePropValueListHolder> values;
do {
@@ -115,17 +122,37 @@ void VehicleNetworkEventMessageHandler::doHandleHalRestart() {
}
}
+void VehicleNetworkEventMessageHandler::doHandleOnPropertySet() {
+ vehicle_prop_value_t* value = nullptr;
+ {
+ Mutex::Autolock autoLock(mLock);
+ if (!mSetValueEvents.empty()) {
+ auto itr = mSetValueEvents.begin();
+ value = *itr;
+ mSetValueEvents.erase(itr);
+ }
+ }
+ if (value != nullptr) {
+ mListener->onPropertySet(*value);
+ VehiclePropValueUtil::deleteMembers(value);
+ delete value;
+ }
+}
+
void VehicleNetworkEventMessageHandler::handleMessage(const Message& message) {
switch (message.what) {
- case EVENT_EVENTS:
- doHandleHalEvents();
- break;
- case EVENT_HAL_ERROR:
- doHandleHalError();
- break;
- case EVENT_HAL_RESTART:
- doHandleHalRestart();
- break;
+ case EVENT_EVENTS:
+ doHandleHalEvents();
+ break;
+ case EVENT_HAL_ERROR:
+ doHandleHalError();
+ break;
+ case EVENT_HAL_RESTART:
+ doHandleHalRestart();
+ break;
+ case EVENT_ON_SET:
+ doHandleOnPropertySet();
+ break;
}
}
@@ -272,8 +299,9 @@ status_t VehicleNetwork::getProperty(vehicle_prop_value_t* value) {
return getService()->getProperty(value);
}
-status_t VehicleNetwork::subscribe(int32_t property, float sampleRate, int32_t zones) {
- return getService()->subscribe(this, property, sampleRate, zones);
+status_t VehicleNetwork::subscribe(int32_t property, float sampleRate, int32_t zones,
+ int32_t flags) {
+ return getService()->subscribe(this, property, sampleRate, zones, flags);
}
void VehicleNetwork::unsubscribe(int32_t property) {
@@ -336,4 +364,8 @@ void VehicleNetwork::onHalError(int32_t errorCode, int32_t property, int32_t ope
void VehicleNetwork::onHalRestart(bool inMocking) {
getEventHandler()->handleHalRestart(inMocking);
}
+
+void VehicleNetwork::onPropertySet(const vehicle_prop_value_t& value) {
+ getEventHandler()->handleOnPropertySet(value);
+}
}; // namespace android