diff options
author | Antonio Cortes <antoniocortes@google.com> | 2017-03-10 15:15:28 -0800 |
---|---|---|
committer | Antonio Cortes <antoniocortes@google.com> | 2017-03-14 09:12:15 -0700 |
commit | 9db963a2178a46510c479500c46d00104996369d (patch) | |
tree | c203d58d883aac267959a06d1154bb0e3016c44c /car-lib/src/android | |
parent | 0389bcc45e0a23131510ceec6d27ba0919c118ef (diff) | |
download | Car-9db963a2178a46510c479500c46d00104996369d.tar.gz |
Return all the layers when reporting subscription data
This helps publishers to make better decisions about what publish.
Test: runtest -x packages/services/Car/tests/carservice_test/src/com/android/car/test/VmsPublisherClientServiceTest.java
Test: runtest -x packages/services/Car/tests/carservice_test/src/com/android/car/test/VmsPublisherSubscriberTest.java
Test: runtest -x packages/services/Car/tests/carservice_test/src/com/android/car/test/VmsSubscriberManagerTest.java
Test: runtest -x packages/services/Car/tests/carservice_unit_test/src/com/android/car/VmsRoutingTest.java
Bug: 36137379
Change-Id: I8e94414ad74550b4029f06638c09d4ef5be3ed32
Diffstat (limited to 'car-lib/src/android')
-rw-r--r-- | car-lib/src/android/car/vms/IVmsPublisherClient.aidl | 7 | ||||
-rw-r--r-- | car-lib/src/android/car/vms/IVmsPublisherService.aidl | 4 | ||||
-rw-r--r-- | car-lib/src/android/car/vms/VmsPublisherClientService.java | 73 |
3 files changed, 50 insertions, 34 deletions
diff --git a/car-lib/src/android/car/vms/IVmsPublisherClient.aidl b/car-lib/src/android/car/vms/IVmsPublisherClient.aidl index d9652f09f9..761e6e731e 100644 --- a/car-lib/src/android/car/vms/IVmsPublisherClient.aidl +++ b/car-lib/src/android/car/vms/IVmsPublisherClient.aidl @@ -17,6 +17,7 @@ package android.car.vms; import android.car.vms.IVmsPublisherService; +import android.car.vms.VmsLayer; /** * @hide @@ -30,6 +31,10 @@ interface IVmsPublisherClient { /** * The VmsPublisherService uses this callback to notify about subscription changes. + * @param layers all the layers that have subscribers. + * @param sequence a monotonicallly increasing number, clients should ignore any packet with a + * sequence number that is less than the highest sequence number they have seen + * thus far. */ - oneway void onVmsSubscriptionChange(int layer, int version, boolean hasSubscribers) = 1; + oneway void onVmsSubscriptionChange(in List<VmsLayer> layers, long sequence) = 1; } diff --git a/car-lib/src/android/car/vms/IVmsPublisherService.aidl b/car-lib/src/android/car/vms/IVmsPublisherService.aidl index 17dd924ab8..6e2f729c45 100644 --- a/car-lib/src/android/car/vms/IVmsPublisherService.aidl +++ b/car-lib/src/android/car/vms/IVmsPublisherService.aidl @@ -16,6 +16,8 @@ package android.car.vms; +import android.car.vms.VmsLayer; + /** * Exposes publisher services to VMS clients. * @@ -30,5 +32,5 @@ interface IVmsPublisherService { /** * Returns whether the layer/version has any clients subscribed to it. */ - boolean hasSubscribers(int layer, int version) = 1; + List<VmsLayer> getSubscribers() = 1; } diff --git a/car-lib/src/android/car/vms/VmsPublisherClientService.java b/car-lib/src/android/car/vms/VmsPublisherClientService.java index 4dc49977dc..a3ac1ab686 100644 --- a/car-lib/src/android/car/vms/VmsPublisherClientService.java +++ b/car-lib/src/android/car/vms/VmsPublisherClientService.java @@ -25,9 +25,13 @@ import android.os.IBinder; import android.os.Looper; import android.os.Message; import android.os.RemoteException; +import android.annotation.Nullable; import android.util.Log; +import com.android.internal.annotations.GuardedBy; + import java.lang.ref.WeakReference; +import java.util.List; /** * Services that need VMS publisher services need to inherit from this class and also need to be @@ -37,7 +41,7 @@ import java.lang.ref.WeakReference; * * The {@link com.android.car.VmsPublisherService} will start this service. The callback * {@link #onVmsPublisherServiceReady()} notifies when VMS publisher services (i.e. - * {@link #publish(int, int, byte[])} and {@link #hasSubscribers(int, int)}) can be used. + * {@link #publish(int, int, byte[])} and {@link #getSubscribers()}) can be used. * * SystemApi candidate. * @@ -79,11 +83,10 @@ public abstract class VmsPublisherClientService extends Service { * TODO(antoniocortes): evaluate adding subscriber id to the list of parameters. This should be * implemented together with the routing in VmsPublisherService. * - * @param layer the layer id of this notification. - * @param version the layer's version of this notification. - * @param hasSubscribers if this layer/version has subscribers or not. + * @param layers layers with subscribers. + * @param sequence monotonically increasing sequence. */ - public abstract void onVmsSubscriptionChange(int layer, int version, boolean hasSubscribers); + public abstract void onVmsSubscriptionChange(List<VmsLayer> layers, long sequence); /** * Uses the VmsPublisherService binder to publish messages. @@ -110,21 +113,21 @@ public abstract class VmsPublisherClientService extends Service { } /** - * Uses the VmsPublisherService binder to query whether this layer/version has any subscribers. + * Uses the VmsPublisherService binder to get the list of layer/version that have any + * subscribers. * - * @return true if the call to VmsPublisherService.layerHasSubscribers was successful and the - * layer/version has subscribers. + * @return list of layer/version or null in case of error. */ - public final boolean hasSubscribers(int layer, int version) { + public final @Nullable List<VmsLayer> getSubscribers() { if (mVmsPublisherService == null) { throw new IllegalStateException("VmsPublisherService not set."); } try { - return mVmsPublisherService.hasSubscribers(layer, version); + return mVmsPublisherService.getSubscribers(); } catch (RemoteException e) { Log.e(TAG, "unable to invoke binder method.", e); } - return false; + return null; } private void setVmsPublisherService(IVmsPublisherService service) { @@ -137,6 +140,9 @@ public abstract class VmsPublisherClientService extends Service { */ private static class VmsPublisherClientBinder extends IVmsPublisherClient.Stub { private final WeakReference<VmsPublisherClientService> mVmsPublisherClientService; + @GuardedBy("mSequenceLock") + private long mSequence = -1; + private final Object mSequenceLock = new Object(); public VmsPublisherClientBinder(VmsPublisherClientService vmsPublisherClientService) { mVmsPublisherClientService = new WeakReference<>(vmsPublisherClientService); @@ -155,18 +161,28 @@ public abstract class VmsPublisherClientService extends Service { } @Override - public void onVmsSubscriptionChange(int layer, int version, boolean hasSubscribers) + public void onVmsSubscriptionChange(List<VmsLayer> layers, long sequence) throws RemoteException { VmsPublisherClientService vmsPublisherClientService = mVmsPublisherClientService.get(); if (vmsPublisherClientService == null) return; if (DBG) { - Log.d(TAG, "subscription event, layer: " + layer + ", version: " + version - + ", hasSubscribers: " + hasSubscribers); + Log.d(TAG, "subscription event, # layers: " + layers.size() + + ", sequence: " + sequence); + } + synchronized (mSequenceLock) { + if (sequence <= mSequence) { + Log.w(TAG, "Sequence out of order. Current sequence = " + mSequence + + "; expected new sequence = " + sequence); + // Do not propagate old notifications. + return; + } else { + mSequence = sequence; + } } Handler handler = vmsPublisherClientService.mHandler; handler.sendMessage( handler.obtainMessage(VmsEventHandler.ON_SUBSCRIPTION_CHANGE_EVENT, - new OnVmsSubscriptionChangeData(layer, version, hasSubscribers))); + new OnVmsSubscriptionChangeData(layers, sequence))); } } @@ -192,8 +208,7 @@ public abstract class VmsPublisherClientService extends Service { switch (msg.what) { case ON_SUBSCRIPTION_CHANGE_EVENT: OnVmsSubscriptionChangeData data = (OnVmsSubscriptionChangeData) msg.obj; - service.onVmsSubscriptionChange(data.getLayer(), data.getVersion(), - data.hasSubscribers()); + service.onVmsSubscriptionChange(data.getLayers(), data.getSequence()); break; case SET_SERVICE_CALLBACK: service.setVmsPublisherService((IVmsPublisherService) msg.obj); @@ -209,26 +224,20 @@ public abstract class VmsPublisherClientService extends Service { * Used to forward data from the binder thread to the main thread. */ private static final class OnVmsSubscriptionChangeData { - private int mLayer; - private int mVersion; - private boolean mHasSubscribers; - - public OnVmsSubscriptionChangeData(int layer, int version, boolean hasSubscribers) { - mLayer = layer; - mVersion = version; - mHasSubscribers = hasSubscribers; - } + private final List<VmsLayer> mLayers; + private final long mSequence; - public int getLayer() { - return mLayer; + public OnVmsSubscriptionChangeData(List<VmsLayer> layers, long sequence) { + mLayers = layers; + mSequence = sequence; } - public int getVersion() { - return mVersion; + public List<VmsLayer> getLayers() { + return mLayers; } - public boolean hasSubscribers() { - return mHasSubscribers; + public long getSequence() { + return mSequence; } } } |