diff options
author | Asaf Rosenfeld <asafro@google.com> | 2017-03-13 16:24:27 -0700 |
---|---|---|
committer | Asaf Rosenfeld <asafro@google.com> | 2017-03-16 21:24:05 -0700 |
commit | 7bd684ec25febcbd65e32ff59e64f8b1d411aced (patch) | |
tree | 9a58f9d5b79bef075f8667bc6a06015cd1de7dd7 | |
parent | b588b30274fcdd3fe5953838cfa86f38b52f4944 (diff) | |
download | Car-7bd684ec25febcbd65e32ff59e64f8b1d411aced.tar.gz |
Adding a class to describe a single VMS dependency.
Adding a class to describe a publisher layers offering.
Adding a way to publishers to declare their offering.
Adding a token to publishers so that the service can track offering and
potentially have more access control on publishing
Test: Verified tests run
Bug: TBD
Change-Id: Ibad7309608e983169deecf371360d3594a4e2dba
9 files changed, 253 insertions, 14 deletions
diff --git a/car-lib/src/android/car/vms/IVmsPublisherClient.aidl b/car-lib/src/android/car/vms/IVmsPublisherClient.aidl index 761e6e731e..f454a33576 100644 --- a/car-lib/src/android/car/vms/IVmsPublisherClient.aidl +++ b/car-lib/src/android/car/vms/IVmsPublisherClient.aidl @@ -25,9 +25,10 @@ import android.car.vms.VmsLayer; interface IVmsPublisherClient { /** * Once the VmsPublisherService is bound to the client, this callback is used to set the - * binder that the client can use to invoke publisher services. + * binder that the client can use to invoke publisher services. This also gives the client + * the token it should use when calling the service. */ - oneway void setVmsPublisherService(IVmsPublisherService service) = 0; + oneway void setVmsPublisherService(in IBinder token, IVmsPublisherService service) = 0; /** * The VmsPublisherService uses this callback to notify about subscription changes. diff --git a/car-lib/src/android/car/vms/IVmsPublisherService.aidl b/car-lib/src/android/car/vms/IVmsPublisherService.aidl index 6e2f729c45..5e210fe703 100644 --- a/car-lib/src/android/car/vms/IVmsPublisherService.aidl +++ b/car-lib/src/android/car/vms/IVmsPublisherService.aidl @@ -17,6 +17,7 @@ package android.car.vms; import android.car.vms.VmsLayer; +import android.car.vms.VmsLayersOffering; /** * Exposes publisher services to VMS clients. @@ -27,10 +28,15 @@ interface IVmsPublisherService { /** * Client call to publish a message. */ - oneway void publish(int layer, int version, in byte[] message) = 0; + oneway void publish(in IBinder token, int layer, int version, in byte[] message) = 0; /** * Returns whether the layer/version has any clients subscribed to it. */ - List<VmsLayer> getSubscribers() = 1; + List<VmsLayer> getSubscriptions() = 1; + + /** + * Sets which layers the publisher can publish under which dependencties. + */ + oneway void setLayersOffering(in IBinder token, in VmsLayersOffering offering) = 2; } diff --git a/car-lib/src/android/car/vms/VmsLayerDependency.aidl b/car-lib/src/android/car/vms/VmsLayerDependency.aidl new file mode 100644 index 0000000000..3e64001b8b --- /dev/null +++ b/car-lib/src/android/car/vms/VmsLayerDependency.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.vms; + +parcelable VmsLayerDependency;
\ No newline at end of file diff --git a/car-lib/src/android/car/vms/VmsLayerDependency.java b/car-lib/src/android/car/vms/VmsLayerDependency.java new file mode 100644 index 0000000000..254330e3a3 --- /dev/null +++ b/car-lib/src/android/car/vms/VmsLayerDependency.java @@ -0,0 +1,94 @@ +/* + * 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.vms; + +import android.car.annotation.FutureFeature; +import android.os.Parcel; +import android.os.Parcelable; +import java.util.ArrayList; +import java.util.List; + +/** + * A dependency for a VMS layer on other VMS layers. + * + * @hide + */ +@FutureFeature +public final class VmsLayerDependency implements Parcelable { + private final VmsLayer mLayer; + private final List<VmsLayer> mDependency = new ArrayList<>(); + + /** + * Construct a dependency for layer on other layers. + */ + public VmsLayerDependency(VmsLayer layer, List<VmsLayer> dependencies) { + mLayer = layer; + mDependency.addAll(dependencies); + } + + /** + * Constructs a layer without a dependency. + */ + public VmsLayerDependency(VmsLayer layer) { + mLayer = layer; + } + + /** + * Checks if a layer has a dependency. + */ + public boolean hasDependencies() { + return (!mDependency.isEmpty()); + } + + public VmsLayer getLayer() { + return mLayer; + } + + /** + * Returns the dependencies. + */ + public List<VmsLayer> getDependencies() { + return new ArrayList<VmsLayer>(mDependency); + } + + public static final Parcelable.Creator<VmsLayerDependency> CREATOR = new + Parcelable.Creator<VmsLayerDependency>() { + public VmsLayerDependency createFromParcel(Parcel in) { + return new VmsLayerDependency(in); + } + public VmsLayerDependency[] newArray(int size) { + return new VmsLayerDependency[size]; + } + }; + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeParcelable(mLayer, flags); + out.writeParcelableList(mDependency, flags); + } + + @Override + public int describeContents() { + return 0; + } + + private VmsLayerDependency(Parcel in) { + mLayer = in.readParcelable(VmsLayer.class.getClassLoader()); + in.readParcelableList(mDependency, VmsLayer.class.getClassLoader()); + + } +}
\ No newline at end of file diff --git a/car-lib/src/android/car/vms/VmsLayersOffering.aidl b/car-lib/src/android/car/vms/VmsLayersOffering.aidl new file mode 100644 index 0000000000..4231f2daf5 --- /dev/null +++ b/car-lib/src/android/car/vms/VmsLayersOffering.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.vms; + +parcelable VmsLayersOffering;
\ No newline at end of file diff --git a/car-lib/src/android/car/vms/VmsLayersOffering.java b/car-lib/src/android/car/vms/VmsLayersOffering.java new file mode 100644 index 0000000000..e3691bcc06 --- /dev/null +++ b/car-lib/src/android/car/vms/VmsLayersOffering.java @@ -0,0 +1,65 @@ +/* + * 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.vms; + +import android.car.annotation.FutureFeature; +import android.os.Parcel; +import android.os.Parcelable; +import java.util.ArrayList; +import java.util.List; + +/** + * The state of dependencies for a single publisher. + * + * @hide + */ +@FutureFeature +public final class VmsLayersOffering implements Parcelable { + + private final List<VmsLayerDependency> mDependencies = new ArrayList<>(); + + /** + * Returns the dependencies. + */ + public List<VmsLayerDependency> getDependencies() { + return new ArrayList<VmsLayerDependency>(mDependencies); + } + + public static final Parcelable.Creator<VmsLayersOffering> CREATOR = new + Parcelable.Creator<VmsLayersOffering>() { + public VmsLayersOffering createFromParcel(Parcel in) { + return new VmsLayersOffering(in); + } + public VmsLayersOffering[] newArray(int size) { + return new VmsLayersOffering[size]; + } + }; + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeParcelableList(mDependencies, flags); + } + + @Override + public int describeContents() { + return 0; + } + + private VmsLayersOffering(Parcel in) { + in.readParcelableList(mDependencies, VmsLayerDependency.class.getClassLoader()); + } +}
\ No newline at end of file diff --git a/car-lib/src/android/car/vms/VmsPublisherClientService.java b/car-lib/src/android/car/vms/VmsPublisherClientService.java index a3ac1ab686..7cda632e8a 100644 --- a/car-lib/src/android/car/vms/VmsPublisherClientService.java +++ b/car-lib/src/android/car/vms/VmsPublisherClientService.java @@ -52,9 +52,13 @@ public abstract class VmsPublisherClientService extends Service { private static final boolean DBG = true; private static final String TAG = "VmsPublisherClient"; + private final Object mLock = new Object(); + private Handler mHandler = new VmsEventHandler(this); private final VmsPublisherClientBinder mVmsPublisherClient = new VmsPublisherClientBinder(this); private volatile IVmsPublisherService mVmsPublisherService = null; + @GuardedBy("mLock") + private volatile IBinder mToken = null; @Override public final IBinder onBind(Intent intent) { @@ -73,6 +77,12 @@ public abstract class VmsPublisherClientService extends Service { return super.onUnbind(intent); } + public void setToken(IBinder token) { + synchronized (mLock) { + mToken = token; + } + } + /** * Notifies that the publisher services are ready. */ @@ -103,8 +113,17 @@ public abstract class VmsPublisherClientService extends Service { if (mVmsPublisherService == null) { throw new IllegalStateException("VmsPublisherService not set."); } + + IBinder token; + synchronized (mLock) { + token = mToken; + } + if (token == null) { + throw new IllegalStateException("VmsPublisherService does not have a valid token."); + } try { - mVmsPublisherService.publish(layerId, layerVersion, payload); + mVmsPublisherService + .publish(token, layerId, layerVersion, payload); return true; } catch (RemoteException e) { Log.e(TAG, "unable to publish message: " + payload, e); @@ -118,12 +137,12 @@ public abstract class VmsPublisherClientService extends Service { * * @return list of layer/version or null in case of error. */ - public final @Nullable List<VmsLayer> getSubscribers() { + public final @Nullable List<VmsLayer> getSubscriptions() { if (mVmsPublisherService == null) { throw new IllegalStateException("VmsPublisherService not set."); } try { - return mVmsPublisherService.getSubscribers(); + return mVmsPublisherService.getSubscriptions(); } catch (RemoteException e) { Log.e(TAG, "unable to invoke binder method.", e); } @@ -149,7 +168,8 @@ public abstract class VmsPublisherClientService extends Service { } @Override - public void setVmsPublisherService(IVmsPublisherService service) throws RemoteException { + public void setVmsPublisherService(IBinder token, IVmsPublisherService service) + throws RemoteException { VmsPublisherClientService vmsPublisherClientService = mVmsPublisherClientService.get(); if (vmsPublisherClientService == null) return; if (DBG) { @@ -158,6 +178,7 @@ public abstract class VmsPublisherClientService extends Service { Handler handler = vmsPublisherClientService.mHandler; handler.sendMessage( handler.obtainMessage(VmsEventHandler.SET_SERVICE_CALLBACK, service)); + vmsPublisherClientService.setToken(token); } @Override diff --git a/service/src/com/android/car/VmsPublisherService.java b/service/src/com/android/car/VmsPublisherService.java index bcd30523b6..112314f207 100644 --- a/service/src/com/android/car/VmsPublisherService.java +++ b/service/src/com/android/car/VmsPublisherService.java @@ -21,18 +21,18 @@ import android.car.vms.IOnVmsMessageReceivedListener; import android.car.vms.IVmsPublisherClient; import android.car.vms.IVmsPublisherService; import android.car.vms.VmsLayer; +import android.car.vms.VmsLayersOffering; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; +import android.os.Binder; import android.os.IBinder; import android.os.RemoteException; import android.text.TextUtils; import android.util.Log; - import com.android.car.hal.VmsHalService; import com.android.internal.annotations.GuardedBy; - import java.io.PrintWriter; import java.lang.ref.WeakReference; import java.util.ArrayList; @@ -55,6 +55,7 @@ public class VmsPublisherService extends IVmsPublisherService.Stub private final Context mContext; private final VmsHalService mHal; private final VmsPublisherManager mPublisherManager; + private final Map<IBinder, VmsLayersOffering> mRawOffering = new HashMap<>(); public VmsPublisherService(Context context, VmsHalService hal) { mContext = context; @@ -92,9 +93,19 @@ public class VmsPublisherService extends IVmsPublisherService.Stub public void dump(PrintWriter writer) { } + @Override + public void setLayersOffering(IBinder token, VmsLayersOffering offering) { + // Store the raw dependencies + mRawOffering.put(token, offering); + + //TODO(asafro): Calculate the new available layers + + //TODO(asafro): Notify the subscribers that there is a change in availability + } + // Implements IVmsPublisherService interface. @Override - public void publish(int layerId, int layerVersion, byte[] payload) { + public void publish(IBinder token, int layerId, int layerVersion, byte[] payload) { if (DBG) { Log.d(TAG, "Publishing for layer ID: " + layerId + " Version: " + layerVersion); } @@ -125,7 +136,7 @@ public class VmsPublisherService extends IVmsPublisherService.Stub } @Override - public List<VmsLayer> getSubscribers() { + public List<VmsLayer> getSubscriptions() { ICarImpl.assertVmsPublisherPermission(mContext); return mHal.getSubscribedLayers(); } @@ -240,6 +251,9 @@ public class VmsPublisherService extends IVmsPublisherService.Stub } class PublisherConnection implements ServiceConnection { + + private final IBinder mToken = new Binder(); + /** * Once the service binds to a publisher service, the publisher binder is added to * mPublisherMap @@ -257,7 +271,7 @@ public class VmsPublisherService extends IVmsPublisherService.Stub mPublisherMap.put(name.flattenToString(), service); } try { - service.setVmsPublisherService(publisherService); + service.setVmsPublisherService(mToken, publisherService); } catch (RemoteException e) { Log.e(TAG, "unable to configure publisher: " + name); } diff --git a/tests/carservice_test/src/com/android/car/test/VmsPublisherClientMockService.java b/tests/carservice_test/src/com/android/car/test/VmsPublisherClientMockService.java index 4ab8e21026..5d36875b9b 100644 --- a/tests/carservice_test/src/com/android/car/test/VmsPublisherClientMockService.java +++ b/tests/carservice_test/src/com/android/car/test/VmsPublisherClientMockService.java @@ -42,7 +42,7 @@ public class VmsPublisherClientMockService extends VmsPublisherClientService { @Override public void onVmsPublisherServiceReady() { // Case when the subscription request was sent before the publisher was ready. - publishIfNeeded(getSubscribers()); + publishIfNeeded(getSubscriptions()); } private void publishIfNeeded(List<VmsLayer> layers) { |