diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2017-10-20 07:13:02 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2017-10-20 07:13:02 +0000 |
commit | 3c33e34de6f28d1b58b36bad081a9446b98f4c0b (patch) | |
tree | 17069ea8ec3b416696279299e732bdc7ce8d1c25 | |
parent | 6a9f054b73bf13b5d04a2c26faeae1c9df1b16c5 (diff) | |
parent | 9076a39ba3e851edd74be918f50d8aba70396324 (diff) | |
download | Car-oreo-mr1-cts-release.tar.gz |
Snap for 4407597 from 9076a39ba3e851edd74be918f50d8aba70396324 to oc-mr1-releaseandroid-wear-8.1.0_r1android-vts-8.1_r9android-vts-8.1_r8android-vts-8.1_r7android-vts-8.1_r6android-vts-8.1_r5android-vts-8.1_r4android-vts-8.1_r3android-vts-8.1_r14android-vts-8.1_r13android-vts-8.1_r12android-vts-8.1_r11android-vts-8.1_r10android-security-8.1.0_r93android-security-8.1.0_r92android-security-8.1.0_r91android-security-8.1.0_r90android-security-8.1.0_r89android-security-8.1.0_r88android-security-8.1.0_r87android-security-8.1.0_r86android-security-8.1.0_r85android-security-8.1.0_r84android-security-8.1.0_r83android-security-8.1.0_r82android-cts-8.1_r9android-cts-8.1_r8android-cts-8.1_r7android-cts-8.1_r6android-cts-8.1_r5android-cts-8.1_r4android-cts-8.1_r3android-cts-8.1_r25android-cts-8.1_r24android-cts-8.1_r23android-cts-8.1_r22android-cts-8.1_r21android-cts-8.1_r20android-cts-8.1_r2android-cts-8.1_r19android-cts-8.1_r18android-cts-8.1_r17android-cts-8.1_r16android-cts-8.1_r15android-cts-8.1_r14android-cts-8.1_r13android-cts-8.1_r12android-cts-8.1_r11android-cts-8.1_r10android-cts-8.1_r1android-8.1.0_r81android-8.1.0_r80android-8.1.0_r79android-8.1.0_r78android-8.1.0_r77android-8.1.0_r76android-8.1.0_r75android-8.1.0_r74android-8.1.0_r73android-8.1.0_r72android-8.1.0_r71android-8.1.0_r70android-8.1.0_r69android-8.1.0_r68android-8.1.0_r66android-8.1.0_r6android-8.1.0_r5android-8.1.0_r4android-8.1.0_r3android-8.1.0_r23android-8.1.0_r19android-8.1.0_r16android-8.1.0_r15android-8.1.0_r12android-8.1.0_r11android-8.1.0_r10android-8.1.0_r1security-oc-mr1-releaseoreo-mr1-wear-releaseoreo-mr1-vts-releaseoreo-mr1-security-releaseoreo-mr1-s1-releaseoreo-mr1-releaseoreo-mr1-cuttlefish-testingoreo-mr1-cts-releaseoreo-m4-s1-release
Change-Id: I5f01ff0bbb446a98dd9303ab32e2718d998b60ea
67 files changed, 3 insertions, 6954 deletions
diff --git a/CleanSpec.mk b/CleanSpec.mk index d828faa03d..67d5bef3e1 100644 --- a/CleanSpec.mk +++ b/CleanSpec.mk @@ -57,6 +57,9 @@ $(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/androi $(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/android.car_intermediates/src/android/car/hardware/ICarDiagnostic*.java) $(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/android.car7_intermediates/src/android/car/hardware/ICarDiagnostic*.java) +$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/android.car7_intermediates/) +$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/android.car_intermediates/) + # ************************************************ # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST # ************************************************ diff --git a/car-lib/src/android/car/Car.java b/car-lib/src/android/car/Car.java index c0b83f71c5..9a9e531286 100644 --- a/car-lib/src/android/car/Car.java +++ b/car-lib/src/android/car/Car.java @@ -32,7 +32,6 @@ import android.car.media.CarAudioManager; import android.car.navigation.CarNavigationStatusManager; import android.car.CarBluetoothManager; import android.car.test.CarTestManagerBinderWrapper; -import android.car.vms.VmsSubscriberManager; import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -135,12 +134,6 @@ public final class Car { public static final String BLUETOOTH_SERVICE = "car_bluetooth"; /** - * @FutureFeature Cannot drop due to usage in non-flag protected place. - * @hide - */ - public static final String VMS_SUBSCRIBER_SERVICE = "vehicle_map_subscriber_service"; - - /** * Service for testing. This is system app only feature. * Service name for {@link CarTestManager}, to be used in {@link #getCarManager(String)}. * @hide @@ -261,22 +254,6 @@ public final class Car { "android.car.permission.CAR_TEST_SERVICE"; /** - * Permissions necessary to access VMS publisher APIs. - * - * @hide - */ - @FutureFeature - public static final String PERMISSION_VMS_PUBLISHER = "android.car.permission.VMS_PUBLISHER"; - - /** - * Permissions necessary to access VMS subscriber APIs. - * - * @hide - */ - @FutureFeature - public static final String PERMISSION_VMS_SUBSCRIBER = "android.car.permission.VMS_SUBSCRIBER"; - - /** * Permissions necessary to read diagnostic information, including vendor-specific bits. * * @hide @@ -654,11 +631,6 @@ public final class Car { * only pass binder wrapper so that CarTestManager can be constructed outside. */ manager = new CarTestManagerBinderWrapper(binder); break; - case VMS_SUBSCRIBER_SERVICE: - if (FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE) { - manager = new VmsSubscriberManager(binder, mEventHandler); - } - break; case BLUETOOTH_SERVICE: manager = new CarBluetoothManager(binder, mContext); } diff --git a/car-lib/src/android/car/vms/IVmsPublisherClient.aidl b/car-lib/src/android/car/vms/IVmsPublisherClient.aidl deleted file mode 100644 index 96b993b3f4..0000000000 --- a/car-lib/src/android/car/vms/IVmsPublisherClient.aidl +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.vms.IVmsPublisherService; -import android.car.vms.VmsSubscriptionState; - -/** - * @hide - */ -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. This also gives the client - * the token it should use when calling the service. - */ - oneway void setVmsPublisherService(in IBinder token, IVmsPublisherService service) = 0; - - /** - * The VmsPublisherService uses this callback to notify about subscription changes. - * @param subscriptionState all the layers that have subscribers and a sequence 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(in VmsSubscriptionState subscriptionState) = 1; -} diff --git a/car-lib/src/android/car/vms/IVmsPublisherService.aidl b/car-lib/src/android/car/vms/IVmsPublisherService.aidl deleted file mode 100644 index 3c26a1b045..0000000000 --- a/car-lib/src/android/car/vms/IVmsPublisherService.aidl +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.vms.VmsLayer; -import android.car.vms.VmsLayersOffering; -import android.car.vms.VmsSubscriptionState; - -/** - * Exposes publisher services to VMS clients. - * - * @hide - */ -interface IVmsPublisherService { - /** - * Client call to publish a message. - */ - oneway void publish(in IBinder token, in VmsLayer layer, int publisherId, in byte[] message) = 0; - - /** - * Returns the list of VmsLayers that has any clients subscribed to it. - */ - VmsSubscriptionState getSubscriptions() = 1; - - /** - * Sets which layers the publisher can publish under which dependencties. - */ - oneway void setLayersOffering(in IBinder token, in VmsLayersOffering offering) = 2; - - /** - * The first time a publisher calls this API it will store the publisher info and assigns the - * publisher an ID. Between reboots, subsequent calls with the same publisher info will - * return the same ID so that a restarting process can obtain the same ID as it had before. - */ - int getPublisherId(in byte[] publisherInfo) = 3; -} diff --git a/car-lib/src/android/car/vms/IVmsSubscriberClient.aidl b/car-lib/src/android/car/vms/IVmsSubscriberClient.aidl deleted file mode 100644 index d5b56060a7..0000000000 --- a/car-lib/src/android/car/vms/IVmsSubscriberClient.aidl +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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.vms.VmsAssociatedLayer; -import android.car.vms.VmsLayer; - -/** - * @hide - */ -oneway interface IVmsSubscriberClient { - /** - * A VmsService uses this callback to pass messages to subscribers. - */ - void onVmsMessageReceived(in VmsLayer layer, in byte[] payload) = 0; - - void onLayersAvailabilityChanged(in List<VmsAssociatedLayer> availableLayers) = 1; -} diff --git a/car-lib/src/android/car/vms/IVmsSubscriberService.aidl b/car-lib/src/android/car/vms/IVmsSubscriberService.aidl deleted file mode 100644 index d10a6e4728..0000000000 --- a/car-lib/src/android/car/vms/IVmsSubscriberService.aidl +++ /dev/null @@ -1,96 +0,0 @@ -/* - * 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.vms.IVmsSubscriberClient; -import android.car.vms.VmsLayer; - -/** - * @hide - */ -interface IVmsSubscriberService { - /** - * Adds a subscriber to notifications only. - * Should be called when a subscriber registers its callback, and before any subscription to a - * layer is made. - */ - void addVmsSubscriberToNotifications( - in IVmsSubscriberClient subscriber) = 0; - - /** - * Adds a subscriber to a VMS layer. - */ - void addVmsSubscriber( - in IVmsSubscriberClient subscriber, - in VmsLayer layer) = 1; - - /** - * Adds a subscriber to all actively broadcasted layers. - * Publishers will not be notified regarding this request so the state of the service will not - * change. - */ - void addVmsSubscriberPassive(in IVmsSubscriberClient subscriber) = 2; - - /** - * Adds a subscriber to a VMS layer from a specific publisher. - */ - void addVmsSubscriberToPublisher( - in IVmsSubscriberClient subscriber, - in VmsLayer layer, - int publisherId) = 3; - - /** - Â Â * Removes a subscriber to notifications only. - * Should be called when a subscriber unregisters its callback, and after all subscriptions to - * layers are removed. - Â Â */ - void removeVmsSubscriberToNotifications( - in IVmsSubscriberClient subscriber) = 4; - - /** - Â Â * Removes a subscriber to a VMS layer. - Â Â */ - void removeVmsSubscriber( - in IVmsSubscriberClient subscriber, - in VmsLayer layer) = 5; - - /** - * Removes a subscriber to all actively broadcasted layers. - * Publishers will not be notified regarding this request so the state of the service will not - * change. - */ - void removeVmsSubscriberPassive( - in IVmsSubscriberClient subscriber) = 6; - - /** - * Removes a subscriber to a VMS layer from a specific publisher. - */ - void removeVmsSubscriberToPublisher( - in IVmsSubscriberClient subscriber, - in VmsLayer layer, - int publisherId) = 7; - - /** - * Returns a list of available layers from the closure of the publishers offerings. - */ - List<VmsLayer> getAvailableLayers() = 8; - - /** - * Returns a the publisher information for a publisher ID. - */ - byte[] getPublisherInfo(in int publisherId) = 9; -} diff --git a/car-lib/src/android/car/vms/VmsAssociatedLayer.aidl b/car-lib/src/android/car/vms/VmsAssociatedLayer.aidl deleted file mode 100644 index c2cf271549..0000000000 --- a/car-lib/src/android/car/vms/VmsAssociatedLayer.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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 VmsAssociatedLayer;
\ No newline at end of file diff --git a/car-lib/src/android/car/vms/VmsAssociatedLayer.java b/car-lib/src/android/car/vms/VmsAssociatedLayer.java deleted file mode 100644 index 023fd9cbe2..0000000000 --- a/car-lib/src/android/car/vms/VmsAssociatedLayer.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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.*; - -/** - * A VMS Layer with a list of publisher IDs it is associated with. - * - * @hide - */ -@FutureFeature -public final class VmsAssociatedLayer implements Parcelable { - - // The VmsLayer. - private final VmsLayer mLayer; - - // The IDs of the publishers that can publish this VmsLayer. - private final Set<Integer> mPublisherIds; - - public VmsAssociatedLayer(VmsLayer layer, Set<Integer> publisherIds) { - mLayer = layer; - mPublisherIds = Collections.unmodifiableSet(publisherIds); - } - - public VmsLayer getVmsLayer() { - return mLayer; - } - - public Set<Integer> getPublisherIds() { - return mPublisherIds; - } - - @Override - public String toString() { - return "VmsAssociatedLayer{ VmsLayer: " + mLayer + ", Publishers: " + mPublisherIds + "}"; - } - - // Parcelable related methods. - public static final Parcelable.Creator<VmsAssociatedLayer> CREATOR = - new Parcelable.Creator<VmsAssociatedLayer>() { - public VmsAssociatedLayer createFromParcel(Parcel in) { - return new VmsAssociatedLayer(in); - } - - public VmsAssociatedLayer[] newArray(int size) { - return new VmsAssociatedLayer[size]; - } - }; - - @Override - public void writeToParcel(Parcel out, int flags) { - out.writeParcelable(mLayer, flags); - out.writeArray(mPublisherIds.toArray()); - } - - @Override - public boolean equals(Object o) { - if (!(o instanceof VmsAssociatedLayer)) { - return false; - } - VmsAssociatedLayer p = (VmsAssociatedLayer) o; - return Objects.equals(p.mLayer, mLayer) && p.mPublisherIds.equals(mPublisherIds); - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public int hashCode() { - return Objects.hash(mLayer, mPublisherIds); - } - - private VmsAssociatedLayer(Parcel in) { - mLayer = in.readParcelable(VmsLayer.class.getClassLoader()); - - mPublisherIds = Collections.unmodifiableSet( - new HashSet<>(Arrays.asList( - (Integer[]) in.readArray(Integer.class.getClassLoader())))); - } -}
\ No newline at end of file diff --git a/car-lib/src/android/car/vms/VmsLayer.aidl b/car-lib/src/android/car/vms/VmsLayer.aidl deleted file mode 100644 index ff0768a3b6..0000000000 --- a/car-lib/src/android/car/vms/VmsLayer.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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 VmsLayer;
\ No newline at end of file diff --git a/car-lib/src/android/car/vms/VmsLayer.java b/car-lib/src/android/car/vms/VmsLayer.java deleted file mode 100644 index 9125796e51..0000000000 --- a/car-lib/src/android/car/vms/VmsLayer.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * 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.Objects; - -/** - * A VMS Layer which can be subscribed to by VMS clients. - * - * @hide - */ -@FutureFeature -public final class VmsLayer implements Parcelable { - - // The layer Type. - private int mType; - - // The layer Subtype. - private int mSubtype; - - // The layer version. - private int mVersion; - - public VmsLayer(int type, int subtype, int version) { - mType = type; - mSubtype = subtype; - mVersion = version; - } - - public int getType() { - return mType; - } - - public int getSubtype() { - return mSubtype; - } - - public int getVersion() { - return mVersion; - } - - /** - * Checks the two objects for equality by comparing their IDs and Versions. - * - * @param o the {@link VmsLayer} to which this one is to be checked for equality - * @return true if the underlying objects of the VmsLayer are both considered equal - */ - @Override - public boolean equals(Object o) { - if (!(o instanceof VmsLayer)) { - return false; - } - VmsLayer p = (VmsLayer) o; - return Objects.equals(p.mType, mType) && - Objects.equals(p.mSubtype, mSubtype) && - Objects.equals(p.mVersion, mVersion); - } - - /** - * Compute a hash code similarly tp {@link android.util.Pair} - * - * @return a hashcode of the Pair - */ - @Override - public int hashCode() { - return Objects.hash(mType, mSubtype, mVersion); - } - - @Override - public String toString() { - return "VmsLayer{ Type: " + mType + ", Sub type: " + mSubtype + ", Version: " + mVersion + "}"; - } - - - // Parcelable related methods. - public static final Parcelable.Creator<VmsLayer> CREATOR = new - Parcelable.Creator<VmsLayer>() { - public VmsLayer createFromParcel(Parcel in) { - return new VmsLayer(in); - } - - public VmsLayer[] newArray(int size) { - return new VmsLayer[size]; - } - }; - - @Override - public void writeToParcel(Parcel out, int flags) { - out.writeInt(mType); - out.writeInt(mSubtype); - out.writeInt(mVersion); - } - - @Override - public int describeContents() { - return 0; - } - - private VmsLayer(Parcel in) { - readFromParcel(in); - } - - private void readFromParcel(Parcel in) { - mType = in.readInt(); - mSubtype = in.readInt(); - mVersion = in.readInt(); - } -}
\ No newline at end of file diff --git a/car-lib/src/android/car/vms/VmsLayerDependency.aidl b/car-lib/src/android/car/vms/VmsLayerDependency.aidl deleted file mode 100644 index 3e64001b8b..0000000000 --- a/car-lib/src/android/car/vms/VmsLayerDependency.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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 deleted file mode 100644 index 3b82775ae0..0000000000 --- a/car-lib/src/android/car/vms/VmsLayerDependency.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * A dependency for a VMS layer on other VMS layers. - * - * @hide - */ -@FutureFeature -public final class VmsLayerDependency implements Parcelable { - private final VmsLayer mLayer; - private final Set<VmsLayer> mDependency; - - /** - * Construct a dependency for layer on other layers. - */ - public VmsLayerDependency(VmsLayer layer, Set<VmsLayer> dependencies) { - mLayer = layer; - mDependency = Collections.unmodifiableSet(dependencies); - } - - /** - * Constructs a layer without a dependency. - */ - public VmsLayerDependency(VmsLayer layer) { - mLayer = layer; - mDependency = Collections.emptySet(); - } - - public VmsLayer getLayer() { - return mLayer; - } - - /** - * Returns the dependencies. - */ - public Set<VmsLayer> getDependencies() { - return 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]; - } - }; - - public String toString() { - return "VmsLayerDependency{ Layer: " + mLayer + " Dependency: " + mDependency + "}"; - } - - @Override - public void writeToParcel(Parcel out, int flags) { - out.writeParcelable(mLayer, flags); - out.writeParcelableList(new ArrayList<VmsLayer>(mDependency), flags); - } - - @Override - public int describeContents() { - return 0; - } - - private VmsLayerDependency(Parcel in) { - mLayer = in.readParcelable(VmsLayer.class.getClassLoader()); - List<VmsLayer> dependency = new ArrayList<>(); - in.readParcelableList(dependency, VmsLayer.class.getClassLoader()); - mDependency = Collections.unmodifiableSet(new HashSet<VmsLayer>(dependency)); - } -}
\ 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 deleted file mode 100644 index 4231f2daf5..0000000000 --- a/car-lib/src/android/car/vms/VmsLayersOffering.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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 deleted file mode 100644 index 6abffc60a3..0000000000 --- a/car-lib/src/android/car/vms/VmsLayersOffering.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * The state of dependencies for a single publisher. - * - * @hide - */ -@FutureFeature -public final class VmsLayersOffering implements Parcelable { - - private final Set<VmsLayerDependency> mDependencies; - - private final int mPublisherId; - - public VmsLayersOffering(Set<VmsLayerDependency> dependencies, int publisherId) { - mDependencies = Collections.unmodifiableSet(dependencies); - mPublisherId = publisherId; - } - - /** - * Returns the dependencies. - */ - public Set<VmsLayerDependency> getDependencies() { - return mDependencies; - } - - public int getPublisherId() { - return mPublisherId; - } - - 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 String toString() { - return "VmsLayersOffering{" + mDependencies+ "}"; - } - - @Override - public void writeToParcel(Parcel out, int flags) { - - out.writeParcelableList(new ArrayList(mDependencies), flags); - out.writeInt(mPublisherId); - } - - @Override - public int describeContents() { - return 0; - } - - private VmsLayersOffering(Parcel in) { - List<VmsLayerDependency> dependencies = new ArrayList<>(); - in.readParcelableList(dependencies, VmsLayerDependency.class.getClassLoader()); - mDependencies = Collections.unmodifiableSet(new HashSet<>(dependencies)); - mPublisherId = in.readInt(); - } -}
\ No newline at end of file diff --git a/car-lib/src/android/car/vms/VmsOperationRecorder.java b/car-lib/src/android/car/vms/VmsOperationRecorder.java deleted file mode 100644 index c873dce131..0000000000 --- a/car-lib/src/android/car/vms/VmsOperationRecorder.java +++ /dev/null @@ -1,227 +0,0 @@ -package android.car.vms; - -import android.car.annotation.FutureFeature; -import android.util.Log; - -import com.android.internal.annotations.VisibleForTesting; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -/** - * Records VMS operations using the Android Log. - * - * This class records VMS operations. The recorded messages include the VMS operations and its - * arguments encoded as JSON text so that the string can be both read as a log message and easily - * parsed. VmsOperationRecorder is intended to be called after successful state change. - * - * Access the VmsOperationRecorder using the {@link #get()} method, which returns a singleton - * instance. Each VMS operation has a corresponding VmsOperationRecorder method. For instance: - * <pre>{@code - * VmsOperationRecorder.get().subscribe(layer); - * }</pre> - * - * @hide - */ -@FutureFeature -public final class VmsOperationRecorder { - private static final String TAG = "VmsOperationRecorder"; - private static final VmsOperationRecorder INSTANCE = new VmsOperationRecorder(new Writer()); - private final Writer mWriter; - - @VisibleForTesting - public VmsOperationRecorder(Writer writer) { - mWriter = writer; - } - - /** Return the singleton instance. */ - public static VmsOperationRecorder get() { - return INSTANCE; - } - - // VMS Client operations. - - public void subscribe(VmsLayer layer) { - recordOp("subscribe", layer); - } - - public void unsubscribe(VmsLayer layer) { - recordOp("unsubscribe", layer); - } - - public void subscribe(VmsLayer layer, int publisherId) { - recordOp("subscribe", "publisherId", publisherId, layer); - } - - public void unsubscribe(VmsLayer layer, int publisherId) { - recordOp("unsubscribe", "publisherId", publisherId, layer); - } - - public void startMonitoring() { - recordOp("startMonitoring"); - } - - public void stopMonitoring() { - recordOp("stopMonitoring"); - } - - public void setLayersOffering(VmsLayersOffering layersOffering) { - recordOp("setLayersOffering", layersOffering); - } - - public void getPublisherId(int publisherId) { - recordOp("getPublisherId", "publisherId", publisherId); - } - - // VMS Service operations. - - public void addSubscription(int sequenceNumber, VmsLayer layer) { - recordOp("addSubscription", "sequenceNumber", sequenceNumber, layer); - } - - public void removeSubscription(int sequenceNumber, VmsLayer layer) { - recordOp("removeSubscription", "sequenceNumber", sequenceNumber, layer); - } - - public void addPromiscuousSubscription(int sequenceNumber) { - recordOp("addPromiscuousSubscription", "sequenceNumber", sequenceNumber); - } - - public void removePromiscuousSubscription(int sequenceNumber) { - recordOp("removePromiscuousSubscription", "sequenceNumber", sequenceNumber); - } - - public void addHalSubscription(int sequenceNumber, VmsLayer layer) { - recordOp("addHalSubscription", "sequenceNumber", sequenceNumber, layer); - } - - public void removeHalSubscription(int sequenceNumber, VmsLayer layer) { - recordOp("removeHalSubscription", "sequenceNumber", sequenceNumber, layer); - } - - public void setPublisherLayersOffering(VmsLayersOffering layersOffering) { - recordOp("setPublisherLayersOffering", layersOffering); - } - - public void setHalPublisherLayersOffering(VmsLayersOffering layersOffering) { - recordOp("setHalPublisherLayersOffering", layersOffering); - } - - private void recordOp(String operation) { - if (isEnabled()) { - try { - write(new JSONObject().put(operation, new JSONObject())); - } catch (JSONException e) { - Log.e(TAG, e.toString()); - } - } - } - - private void recordOp(String operation, VmsLayer layer) { - if (isEnabled()) { - try { - recordOp(operation, new JSONObject().put("layer", toJson(layer))); - } catch (JSONException e) { - Log.e(TAG, e.toString()); - } - } - } - - private void recordOp(String operation, VmsLayersOffering layersOffering) { - if (isEnabled()) { - try { - JSONObject args = new JSONObject(); - JSONArray offering = toJson(layersOffering); - if (offering.length() > 0) { - args.put("layerDependency", offering); - } - recordOp(operation, args); - } catch (JSONException e) { - Log.e(TAG, e.toString()); - } - } - } - - private void recordOp(String operation, String intArgName, int arg) { - if (isEnabled()) { - try { - recordOp(operation, new JSONObject().put(intArgName, arg)); - } catch (JSONException e) { - Log.e(TAG, e.toString()); - } - } - } - - private void recordOp(String operation, String intArgName, int arg, VmsLayer layer) { - if (isEnabled()) { - try { - recordOp(operation, - new JSONObject().put(intArgName, arg).put("layer", toJson(layer))); - } catch (JSONException e) { - Log.e(TAG, e.toString()); - } - } - } - - private void recordOp(String operation, JSONObject args) { - if (isEnabled()) { - try { - write(new JSONObject().put(operation, args)); - } catch (JSONException e) { - Log.e(TAG, e.toString()); - } - } - } - - private static JSONObject toJson(VmsLayer layer) throws JSONException { - return new JSONObject() - .put("type", layer.getType()) - .put("subtype", layer.getSubtype()) - .put("version", layer.getVersion()); - } - - private static JSONObject toJson(VmsLayerDependency layerDependency) throws JSONException { - JSONObject dep = new JSONObject(); - dep.put("layer", toJson(layerDependency.getLayer())); - if (!layerDependency.getDependencies().isEmpty()) { - JSONArray dependencies = new JSONArray(); - for (VmsLayer dependency : layerDependency.getDependencies()) { - dependencies.put(toJson(dependency)); - } - dep.put("dependency", dependencies); - } - return dep; - } - - private static JSONArray toJson(VmsLayersOffering layersOffering) throws JSONException { - JSONArray offerings = new JSONArray(); - for (VmsLayerDependency layerDependency : layersOffering.getDependencies()) { - offerings.put(toJson(layerDependency)); - } - return offerings; - } - - private boolean isEnabled() { - return mWriter.isEnabled(); - } - - private void write(JSONObject object) { - mWriter.write(object.toString()); - } - - /** @hide */ - @VisibleForTesting - public static class Writer { - private static final String TAG = "VMS.RECORD.EVENT"; - private static final int LEVEL = Log.DEBUG; - - public boolean isEnabled() { - return Log.isLoggable(TAG, LEVEL); - } - - public void write(String msg) { - Log.println(LEVEL, TAG, msg); - } - } -} diff --git a/car-lib/src/android/car/vms/VmsPublisherClientService.java b/car-lib/src/android/car/vms/VmsPublisherClientService.java deleted file mode 100644 index 33ca1f3037..0000000000 --- a/car-lib/src/android/car/vms/VmsPublisherClientService.java +++ /dev/null @@ -1,282 +0,0 @@ -/* - * 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.app.Service; -import android.car.annotation.FutureFeature; -import android.content.Intent; -import android.os.Handler; -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; - -/** - * Services that need VMS publisher services need to inherit from this class and also need to be - * declared in the array vmsPublisherClients located in - * packages/services/Car/service/res/values/config.xml (most likely, this file will be in an overlay - * of the target product. - * - * The {@link com.android.car.VmsPublisherService} will start this service. The callback - * {@link #onVmsPublisherServiceReady()} notifies when VMS publisher services can be used, and the - * publisher can request a publisher ID in order to start publishing. - * - * SystemApi candidate. - * - * @hide - */ -@FutureFeature -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 IBinder mToken = null; - - @Override - public final IBinder onBind(Intent intent) { - if (DBG) { - Log.d(TAG, "onBind, intent: " + intent); - } - return mVmsPublisherClient.asBinder(); - } - - @Override - public final boolean onUnbind(Intent intent) { - if (DBG) { - Log.d(TAG, "onUnbind, intent: " + intent); - } - stopSelf(); - return super.onUnbind(intent); - } - - private void setToken(IBinder token) { - synchronized (mLock) { - mToken = token; - } - } - - /** - * Notifies that the publisher services are ready. - */ - protected abstract void onVmsPublisherServiceReady(); - - /** - * Publishers need to implement this method to receive notifications of subscription changes. - * - * @param subscriptionState the state of the subscriptions. - */ - public abstract void onVmsSubscriptionChange(VmsSubscriptionState subscriptionState); - - /** - * Uses the VmsPublisherService binder to publish messages. - * - * @param layer the layer to publish to. - * @param payload the message to be sent. - * @param publisherId the ID that got assigned to the publisher that published the message by - * VMS core. - * @return if the call to the method VmsPublisherService.publish was successful. - */ - public final void publish(VmsLayer layer, int publisherId, byte[] payload) { - if (DBG) { - Log.d(TAG, "Publishing for layer : " + layer); - } - - IBinder token = getTokenForPublisherServiceThreadSafe(); - - try { - mVmsPublisherService.publish(token, layer, publisherId, payload); - } catch (RemoteException e) { - Log.e(TAG, "unable to publish message: " + payload, e); - } - } - - /** - * Uses the VmsPublisherService binder to set the layers offering. - * - * @param offering the layers that the publisher may publish. - * @return if the call to VmsPublisherService.setLayersOffering was successful. - */ - public final void setLayersOffering(VmsLayersOffering offering) { - if (DBG) { - Log.d(TAG, "Setting layers offering : " + offering); - } - - IBinder token = getTokenForPublisherServiceThreadSafe(); - - try { - mVmsPublisherService.setLayersOffering(token, offering); - VmsOperationRecorder.get().setLayersOffering(offering); - } catch (RemoteException e) { - Log.e(TAG, "unable to set layers offering: " + offering, e); - } - } - - private IBinder getTokenForPublisherServiceThreadSafe() { - 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."); - } - return token; - } - - public final int getPublisherId(byte[] publisherInfo) { - if (mVmsPublisherService == null) { - throw new IllegalStateException("VmsPublisherService not set."); - } - Integer publisherId = null; - try { - Log.i(TAG, "Getting publisher static ID"); - publisherId = mVmsPublisherService.getPublisherId(publisherInfo); - } catch (RemoteException e) { - Log.e(TAG, "unable to invoke binder method.", e); - } - if (publisherId == null) { - throw new IllegalStateException("VmsPublisherService cannot get a publisher static ID."); - } else { - VmsOperationRecorder.get().getPublisherId(publisherId); - } - return publisherId; - } - - /** - * Uses the VmsPublisherService binder to get the state of the subscriptions. - * - * @return list of layer/version or null in case of error. - */ - public final @Nullable VmsSubscriptionState getSubscriptions() { - if (mVmsPublisherService == null) { - throw new IllegalStateException("VmsPublisherService not set."); - } - try { - return mVmsPublisherService.getSubscriptions(); - } catch (RemoteException e) { - Log.e(TAG, "unable to invoke binder method.", e); - } - return null; - } - - private void setVmsPublisherService(IVmsPublisherService service) { - mVmsPublisherService = service; - onVmsPublisherServiceReady(); - } - - /** - * Implements the interface that the VMS service uses to communicate with this client. - */ - 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); - } - - @Override - public void setVmsPublisherService(IBinder token, IVmsPublisherService service) - throws RemoteException { - VmsPublisherClientService vmsPublisherClientService = mVmsPublisherClientService.get(); - if (vmsPublisherClientService == null) return; - if (DBG) { - Log.d(TAG, "setting VmsPublisherService."); - } - Handler handler = vmsPublisherClientService.mHandler; - handler.sendMessage( - handler.obtainMessage(VmsEventHandler.SET_SERVICE_CALLBACK, service)); - vmsPublisherClientService.setToken(token); - } - - @Override - public void onVmsSubscriptionChange(VmsSubscriptionState subscriptionState) - throws RemoteException { - VmsPublisherClientService vmsPublisherClientService = mVmsPublisherClientService.get(); - if (vmsPublisherClientService == null) return; - if (DBG) { - Log.d(TAG, "subscription event: " + subscriptionState); - } - synchronized (mSequenceLock) { - if (subscriptionState.getSequenceNumber() <= mSequence) { - Log.w(TAG, "Sequence out of order. Current sequence = " + mSequence - + "; expected new sequence = " + subscriptionState.getSequenceNumber()); - // Do not propagate old notifications. - return; - } else { - mSequence = subscriptionState.getSequenceNumber(); - } - } - Handler handler = vmsPublisherClientService.mHandler; - handler.sendMessage( - handler.obtainMessage(VmsEventHandler.ON_SUBSCRIPTION_CHANGE_EVENT, - subscriptionState)); - } - } - - /** - * Receives events from the binder thread and dispatches them. - */ - private final static class VmsEventHandler extends Handler { - /** Constants handled in the handler */ - private static final int ON_SUBSCRIPTION_CHANGE_EVENT = 0; - private static final int SET_SERVICE_CALLBACK = 1; - - private final WeakReference<VmsPublisherClientService> mVmsPublisherClientService; - - VmsEventHandler(VmsPublisherClientService service) { - super(Looper.getMainLooper()); - mVmsPublisherClientService = new WeakReference<>(service); - } - - @Override - public void handleMessage(Message msg) { - VmsPublisherClientService service = mVmsPublisherClientService.get(); - if (service == null) return; - switch (msg.what) { - case ON_SUBSCRIPTION_CHANGE_EVENT: - VmsSubscriptionState subscriptionState = (VmsSubscriptionState) msg.obj; - service.onVmsSubscriptionChange(subscriptionState); - break; - case SET_SERVICE_CALLBACK: - service.setVmsPublisherService((IVmsPublisherService) msg.obj); - break; - default: - Log.e(TAG, "Event type not handled: " + msg.what); - break; - } - } - } -} diff --git a/car-lib/src/android/car/vms/VmsSubscriberManager.java b/car-lib/src/android/car/vms/VmsSubscriberManager.java deleted file mode 100644 index 6f6377ca7f..0000000000 --- a/car-lib/src/android/car/vms/VmsSubscriberManager.java +++ /dev/null @@ -1,377 +0,0 @@ -/* - * 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.Car; -import android.car.CarManagerBase; -import android.car.CarNotConnectedException; -import android.car.annotation.FutureFeature; -import android.os.Handler; -import android.os.IBinder; -import android.os.Looper; -import android.os.Message; -import android.os.RemoteException; -import android.util.Log; - -import com.android.internal.annotations.GuardedBy; - -import java.lang.ref.WeakReference; -import java.util.List; - -/** - * API for interfacing with the VmsSubscriberService. It supports a single client callback that can - * (un)subscribe to different layers. Getting notifactions and managing subscriptions is enabled - * after setting the client callback with #registerClientCallback. - * SystemApi candidate - * - * @hide - */ -@FutureFeature -public final class VmsSubscriberManager implements CarManagerBase { - private static final boolean DBG = true; - private static final String TAG = "VmsSubscriberManager"; - - private final Handler mHandler; - private final IVmsSubscriberService mVmsSubscriberService; - private final IVmsSubscriberClient mSubscriberManagerClient; - private final Object mClientCallbackLock = new Object(); - @GuardedBy("mClientCallbackLock") - private VmsSubscriberClientCallback mClientCallback; - - /** - * Interface exposed to VMS subscribers: it is a wrapper of IVmsSubscriberClient. - */ - public interface VmsSubscriberClientCallback { - /** - * Called when the property is updated - */ - void onVmsMessageReceived(VmsLayer layer, byte[] payload); - - /** - * Called when layers availability change - */ - void onLayersAvailabilityChanged(List<VmsLayer> availableLayers); - } - - /** - * Allows to asynchronously dispatch onVmsMessageReceived events. - */ - private final static class VmsEventHandler extends Handler { - /** - * Constants handled in the handler - */ - private static final int ON_RECEIVE_MESSAGE_EVENT = 0; - private static final int ON_AVAILABILITY_CHANGE_EVENT = 1; - - private final WeakReference<VmsSubscriberManager> mMgr; - - VmsEventHandler(VmsSubscriberManager mgr, Looper looper) { - super(looper); - mMgr = new WeakReference<>(mgr); - } - - @Override - public void handleMessage(Message msg) { - VmsSubscriberManager mgr = mMgr.get(); - switch (msg.what) { - case ON_RECEIVE_MESSAGE_EVENT: - if (mgr != null) { - // Parse the message - VmsDataMessage vmsDataMessage = (VmsDataMessage) msg.obj; - - // Dispatch the parsed message - mgr.dispatchOnReceiveMessage(vmsDataMessage.getLayer(), - vmsDataMessage.getPayload()); - } - break; - case ON_AVAILABILITY_CHANGE_EVENT: - if (mgr != null) { - // Parse the message - List<VmsLayer> vmsAvailabilityChangeMessage = (List<VmsLayer>) msg.obj; - - // Dispatch the parsed message - mgr.dispatchOnAvailabilityChangeMessage(vmsAvailabilityChangeMessage); - } - break; - - default: - Log.e(VmsSubscriberManager.TAG, "Event type not handled: " + msg.what); - break; - } - } - } - - public VmsSubscriberManager(IBinder service, Handler handler) { - mVmsSubscriberService = IVmsSubscriberService.Stub.asInterface(service); - mHandler = new VmsEventHandler(this, handler.getLooper()); - mSubscriberManagerClient = new IVmsSubscriberClient.Stub() { - @Override - public void onVmsMessageReceived(VmsLayer layer, byte[] payload) - throws RemoteException { - // Create the data message - VmsDataMessage vmsDataMessage = new VmsDataMessage(layer, payload); - mHandler.sendMessage( - mHandler.obtainMessage( - VmsEventHandler.ON_RECEIVE_MESSAGE_EVENT, - vmsDataMessage)); - } - - @Override - public void onLayersAvailabilityChanged(List<VmsAssociatedLayer> availableLayers) { - mHandler.sendMessage( - mHandler.obtainMessage( - VmsEventHandler.ON_AVAILABILITY_CHANGE_EVENT, - availableLayers)); - } - }; - } - - /** - * Registers the client callback in order to enable communication with the client. - * By registering, the client will start getting notifications, and will be able to subscribe - * to layers. - * <p> - * - * @param clientCallback subscriber callback that will handle onVmsMessageReceived events. - * @throws IllegalStateException if the client callback was already set. - */ - public void registerClientCallback(VmsSubscriberClientCallback clientCallback) - throws CarNotConnectedException { - synchronized (mClientCallbackLock) { - if (mClientCallback != null) { - throw new IllegalStateException("Client callback is already configured."); - } - mClientCallback = clientCallback; - } - try { - mVmsSubscriberService.addVmsSubscriberToNotifications(mSubscriberManagerClient); - } catch (RemoteException e) { - Log.e(TAG, "Could not connect: ", e); - throw new CarNotConnectedException(e); - } - } - - /** - * Unregisters the client callback which disables communication with the client. - * @throws CarNotConnectedException, IllegalStateException - */ - public void unregisterClientCallback() - throws CarNotConnectedException { - - try { - mVmsSubscriberService.removeVmsSubscriberToNotifications(mSubscriberManagerClient); - } catch (RemoteException e) { - Log.e(TAG, "Could not connect: ", e); - throw new CarNotConnectedException(e); - } catch (IllegalStateException e) { - Log.e(TAG, "Could not unsubscribe from notifications"); - throw e; - } - - synchronized (mClientCallbackLock) { - mClientCallback = null; - } - } - - /** - * Returns a serialized publisher information for a publisher ID. - */ - public byte[] getPublisherInfo(int publisherId) - throws CarNotConnectedException, IllegalStateException { - try { - return mVmsSubscriberService.getPublisherInfo(publisherId); - } catch (RemoteException e) { - Log.e(TAG, "Could not connect: ", e); - throw new CarNotConnectedException(e); - } catch (IllegalStateException ex) { - Car.checkCarNotConnectedExceptionFromCarService(ex); - throw new IllegalStateException(ex); - } - } - - /** - * Subscribes to listen to the layer specified. - * - * @param layer the layer to subscribe to. - * @throws IllegalStateException if the client callback was not set via - * {@link #registerClientCallback}. - */ - public void subscribe(VmsLayer layer) throws CarNotConnectedException { - verifySubscriptionIsAllowed(); - try { - mVmsSubscriberService.addVmsSubscriber(mSubscriberManagerClient, layer); - VmsOperationRecorder.get().subscribe(layer); - } catch (RemoteException e) { - Log.e(TAG, "Could not connect: ", e); - throw new CarNotConnectedException(e); - } catch (IllegalStateException ex) { - Car.checkCarNotConnectedExceptionFromCarService(ex); - } - } - - /** - * Subscribes to listen to the layer specified from the publisher specified. - * - * @param layer the layer to subscribe to. - * @param publisherId the publisher of the layer. - * @throws IllegalStateException if the client callback was not set via - * {@link #registerClientCallback}. - */ - public void subscribe(VmsLayer layer, int publisherId) throws CarNotConnectedException { - verifySubscriptionIsAllowed(); - try { - mVmsSubscriberService.addVmsSubscriberToPublisher( - mSubscriberManagerClient, layer, publisherId); - VmsOperationRecorder.get().subscribe(layer, publisherId); - } catch (RemoteException e) { - Log.e(TAG, "Could not connect: ", e); - throw new CarNotConnectedException(e); - } catch (IllegalStateException ex) { - Car.checkCarNotConnectedExceptionFromCarService(ex); - } - } - - public void startMonitoring() throws CarNotConnectedException { - verifySubscriptionIsAllowed(); - try { - mVmsSubscriberService.addVmsSubscriberPassive(mSubscriberManagerClient); - VmsOperationRecorder.get().startMonitoring(); - } catch (RemoteException e) { - Log.e(TAG, "Could not connect: ", e); - throw new CarNotConnectedException(e); - } catch (IllegalStateException ex) { - Car.checkCarNotConnectedExceptionFromCarService(ex); - } - } - - /** - * Unsubscribes from the layer/version specified. - * - * @param layer the layer to unsubscribe from. - * @throws IllegalStateException if the client callback was not set via - * {@link #registerClientCallback}. - */ - public void unsubscribe(VmsLayer layer) { - verifySubscriptionIsAllowed(); - try { - mVmsSubscriberService.removeVmsSubscriber(mSubscriberManagerClient, layer); - VmsOperationRecorder.get().unsubscribe(layer); - } catch (RemoteException e) { - Log.e(TAG, "Failed to unregister subscriber", e); - // ignore - } catch (IllegalStateException ex) { - Car.hideCarNotConnectedExceptionFromCarService(ex); - } - } - - /** - * Unsubscribes from the layer/version specified. - * - * @param layer the layer to unsubscribe from. - * @param publisherId the pubisher of the layer. - * @throws IllegalStateException if the client callback was not set via - * {@link #registerClientCallback}. - */ - public void unsubscribe(VmsLayer layer, int publisherId) { - try { - mVmsSubscriberService.removeVmsSubscriberToPublisher( - mSubscriberManagerClient, layer, publisherId); - VmsOperationRecorder.get().unsubscribe(layer, publisherId); - } catch (RemoteException e) { - Log.e(TAG, "Failed to unregister subscriber", e); - // ignore - } catch (IllegalStateException ex) { - Car.hideCarNotConnectedExceptionFromCarService(ex); - } - } - - public void stopMonitoring() { - try { - mVmsSubscriberService.removeVmsSubscriberPassive(mSubscriberManagerClient); - VmsOperationRecorder.get().stopMonitoring(); - } catch (RemoteException e) { - Log.e(TAG, "Failed to unregister subscriber ", e); - // ignore - } catch (IllegalStateException ex) { - Car.hideCarNotConnectedExceptionFromCarService(ex); - } - } - - private void dispatchOnReceiveMessage(VmsLayer layer, byte[] payload) { - VmsSubscriberClientCallback clientCallback = getClientCallbackThreadSafe(); - if (clientCallback == null) { - Log.e(TAG, "Cannot dispatch received message."); - return; - } - clientCallback.onVmsMessageReceived(layer, payload); - } - - private void dispatchOnAvailabilityChangeMessage(List<VmsLayer> availableLayers) { - VmsSubscriberClientCallback clientCallback = getClientCallbackThreadSafe(); - if (clientCallback == null) { - Log.e(TAG, "Cannot dispatch availability change message."); - return; - } - clientCallback.onLayersAvailabilityChanged(availableLayers); - } - - private VmsSubscriberClientCallback getClientCallbackThreadSafe() { - VmsSubscriberClientCallback clientCallback; - synchronized (mClientCallbackLock) { - clientCallback = mClientCallback; - } - if (clientCallback == null) { - Log.e(TAG, "client callback not set."); - } - return clientCallback; - } - - /* - * Verifies that the subscriber is in a state where it is allowed to subscribe. - */ - private void verifySubscriptionIsAllowed() { - VmsSubscriberClientCallback clientCallback = getClientCallbackThreadSafe(); - if (clientCallback == null) { - throw new IllegalStateException("Cannot subscribe."); - } - } - - /** - * @hide - */ - @Override - public void onCarDisconnected() { - } - - private static final class VmsDataMessage { - private final VmsLayer mLayer; - private final byte[] mPayload; - - public VmsDataMessage(VmsLayer layer, byte[] payload) { - mLayer = layer; - mPayload = payload; - } - - public VmsLayer getLayer() { - return mLayer; - } - - public byte[] getPayload() { - return mPayload; - } - } -} diff --git a/car-lib/src/android/car/vms/VmsSubscriptionState.aidl b/car-lib/src/android/car/vms/VmsSubscriptionState.aidl deleted file mode 100644 index b5ce8fff19..0000000000 --- a/car-lib/src/android/car/vms/VmsSubscriptionState.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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 VmsSubscriptionState;
\ No newline at end of file diff --git a/car-lib/src/android/car/vms/VmsSubscriptionState.java b/car-lib/src/android/car/vms/VmsSubscriptionState.java deleted file mode 100644 index ea433f70b9..0000000000 --- a/car-lib/src/android/car/vms/VmsSubscriptionState.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * 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.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - - -/** - * The list of layers with subscribers. - * - * @hide - */ -@FutureFeature -public final class VmsSubscriptionState implements Parcelable { - private final int mSequenceNumber; - private final Set<VmsLayer> mLayers; - private final Set<VmsAssociatedLayer> mSubscribedLayersFromPublishers; - - /** - * Construcs a summary of the state of the current subscriptions for publishers to consume - * and adjust which layers that the are publishing. - */ - public VmsSubscriptionState(int sequenceNumber, - Set<VmsLayer> subscribedLayers, - Set<VmsAssociatedLayer> layersFromPublishers) { - mSequenceNumber = sequenceNumber; - mLayers = Collections.unmodifiableSet(subscribedLayers); - mSubscribedLayersFromPublishers = Collections.unmodifiableSet(layersFromPublishers); - } - - /** - * Returns the sequence number assigned by the VMS service. Sequence numbers are - * monotonically increasing and help clients ignore potential out-of-order states. - */ - public int getSequenceNumber() { - return mSequenceNumber; - } - - public Set<VmsLayer> getLayers() { - return mLayers; - } - - public Set<VmsAssociatedLayer> getAssociatedLayers() { - return mSubscribedLayersFromPublishers; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("sequence number=").append(mSequenceNumber); - sb.append("; layers={"); - for (VmsLayer layer : mLayers) { - sb.append(layer).append(","); - } - sb.append("}"); - sb.append("; associatedLayers={"); - for (VmsAssociatedLayer layer : mSubscribedLayersFromPublishers) { - sb.append(layer).append(","); - } - sb.append("}"); - return sb.toString(); - } - - public static final Parcelable.Creator<VmsSubscriptionState> CREATOR = new - Parcelable.Creator<VmsSubscriptionState>() { - public VmsSubscriptionState createFromParcel(Parcel in) { - return new VmsSubscriptionState(in); - } - - public VmsSubscriptionState[] newArray(int size) { - return new VmsSubscriptionState[size]; - } - }; - - @Override - public void writeToParcel(Parcel out, int flags) { - out.writeInt(mSequenceNumber); - out.writeParcelableList(new ArrayList(mLayers), flags); - out.writeParcelableList(new ArrayList(mSubscribedLayersFromPublishers), flags); - } - - @Override - public int describeContents() { - return 0; - } - - private VmsSubscriptionState(Parcel in) { - mSequenceNumber = in.readInt(); - - List<VmsLayer> layers = new ArrayList<>(); - in.readParcelableList(layers, VmsLayer.class.getClassLoader()); - mLayers = Collections.unmodifiableSet(new HashSet(layers)); - - List<VmsAssociatedLayer> associatedLayers = new ArrayList<>(); - in.readParcelableList(associatedLayers, VmsAssociatedLayer.class.getClassLoader()); - mSubscribedLayersFromPublishers = Collections.unmodifiableSet(new HashSet(associatedLayers)); - } -}
\ No newline at end of file diff --git a/service/AndroidManifest.xml b/service/AndroidManifest.xml index e39fb9edaa..5c4dfaaca7 100644 --- a/service/AndroidManifest.xml +++ b/service/AndroidManifest.xml @@ -101,17 +101,6 @@ android:protectionLevel="system|signature" android:label="@string/car_permission_label_diag_clear" android:description="@string/car_permission_desc_diag_clear" /> - <permission - android:name="android.car.permission.VMS_PUBLISHER" - android:protectionLevel="system|signature" - android:label="@string/car_permission_label_vms_publisher" - android:description="@string/car_permission_desc_vms_publisher" /> - <permission - android:name="android.car.permission.VMS_SUBSCRIBER" - android:protectionLevel="system|signature" - android:label="@string/car_permission_label_vms_subscriber" - android:description="@string/car_permission_desc_vms_subscriber" /> - <!-- may replace this with system permission if proper one is defined. --> <permission android:name="android.car.permission.CONTROL_APP_BLOCKING" diff --git a/service/res/values/config.xml b/service/res/values/config.xml index 61cef594a7..73028cba2d 100644 --- a/service/res/values/config.xml +++ b/service/res/values/config.xml @@ -74,11 +74,4 @@ <string name="defauiltActivityWhitelist">android,com.android.systemui</string> <!-- Default home activity --> <string name="defaultHomeActivity">com.android.car.overview/com.android.car.overview.StreamOverviewActivity</string> - <!-- The com.android.car.VmsPublisherService will bind to this list of clients --> - <string-array translatable="false" name="vmsPublisherClients"> - </string-array> - <!-- Permissions that the com.android.car.VmsPublisherService is allowed to grant to publishers --> - <string-array translatable="false" name="vmsSafePermissions"> - <item>"android.permission.ACCESS_FINE_LOCATION"</item> - </string-array> </resources> diff --git a/service/res/values/strings.xml b/service/res/values/strings.xml index 6cfff9a8bd..7f826d4cc3 100644 --- a/service/res/values/strings.xml +++ b/service/res/values/strings.xml @@ -116,13 +116,4 @@ <!-- Permission text: apps can clear diagnostic data from the car [CHAR LIMIT=NONE] --> <string name="car_permission_desc_diag_clear">Clear diagnostic data from the car</string> - <!-- Permission text: apps can publish VMS data [CHAR LIMIT=NONE] --> - <string name="car_permission_label_vms_publisher">VMS publisher</string> - <!-- Permission text: apps can send VMS messages to the car [CHAR LIMIT=NONE] --> - <string name="car_permission_desc_vms_publisher">Publish vms messages</string> - - <!-- Permission text: apps can subscribe to VMS data [CHAR LIMIT=NONE] --> - <string name="car_permission_label_vms_subscriber">VMS subscriber</string> - <!-- Permission text: apps can receive VMS messages from the car [CHAR LIMIT=NONE] --> - <string name="car_permission_desc_vms_subscriber">Subscribe to vms messages</string> </resources> diff --git a/service/src/com/android/car/ICarImpl.java b/service/src/com/android/car/ICarImpl.java index bd42454222..bbb86f603a 100644 --- a/service/src/com/android/car/ICarImpl.java +++ b/service/src/com/android/car/ICarImpl.java @@ -72,10 +72,6 @@ public class ICarImpl extends ICar.Stub { private final CarBluetoothService mCarBluetoothService; private final PerUserCarServiceHelper mPerUserCarServiceHelper; private CarDiagnosticService mCarDiagnosticService; - @FutureFeature - private VmsSubscriberService mVmsSubscriberService; - @FutureFeature - private VmsPublisherService mVmsPublisherService; private final CarServiceBase[] mAllServices; @@ -121,10 +117,6 @@ public class ICarImpl extends ICar.Stub { mPerUserCarServiceHelper = new PerUserCarServiceHelper(serviceContext); mCarBluetoothService = new CarBluetoothService(serviceContext, mCarCabinService, mCarSensorService, mPerUserCarServiceHelper); - if (FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE) { - mVmsSubscriberService = new VmsSubscriberService(serviceContext, mHal.getVmsHal()); - mVmsPublisherService = new VmsPublisherService(serviceContext, mHal.getVmsHal()); - } mCarDiagnosticService = new CarDiagnosticService(serviceContext, mHal.getDiagnosticHal()); // Be careful with order. Service depending on other service should be inited later. @@ -150,10 +142,6 @@ public class ICarImpl extends ICar.Stub { mCarDiagnosticService, mPerUserCarServiceHelper )); - if (FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE) { - allServices.add(mVmsSubscriberService); - allServices.add(mVmsPublisherService); - } mAllServices = allServices.toArray(new CarServiceBase[0]); } @@ -233,12 +221,6 @@ public class ICarImpl extends ICar.Stub { case Car.VENDOR_EXTENSION_SERVICE: assertVendorExtensionPermission(mContext); return mCarVendorExtensionService; - case Car.VMS_SUBSCRIBER_SERVICE: - FeatureUtil.assertFeature(FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE); - if (FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE) { - assertVmsSubscriberPermission(mContext); - return mVmsSubscriberService; - } case Car.TEST_SERVICE: { assertPermission(mContext, Car.PERMISSION_CAR_TEST_SERVICE); synchronized (this) { @@ -312,16 +294,6 @@ public class ICarImpl extends ICar.Stub { Car.PERMISSION_CAR_DIAGNOSTIC_CLEAR); } - @FutureFeature - public static void assertVmsPublisherPermission(Context context) { - assertPermission(context, Car.PERMISSION_VMS_PUBLISHER); - } - - @FutureFeature - public static void assertVmsSubscriberPermission(Context context) { - assertPermission(context, Car.PERMISSION_VMS_SUBSCRIBER); - } - public static void assertPermission(Context context, String permission) { if (context.checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) { throw new SecurityException("requires " + permission); diff --git a/service/src/com/android/car/VmsLayersAvailability.java b/service/src/com/android/car/VmsLayersAvailability.java deleted file mode 100644 index 93b917ca0f..0000000000 --- a/service/src/com/android/car/VmsLayersAvailability.java +++ /dev/null @@ -1,200 +0,0 @@ -/* - * 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 com.android.car; - -import android.car.annotation.FutureFeature; -import android.car.vms.VmsAssociatedLayer; -import android.car.vms.VmsLayer; -import android.car.vms.VmsLayerDependency; -import android.car.vms.VmsLayersOffering; -import android.util.Log; -import com.android.internal.annotations.GuardedBy; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; - -/** - * Manages VMS availability for layers. - * <p> - * Each VMS publisher sets its layers offering which are a list of layers the publisher claims - * it might publish. VmsLayersAvailability calculates from all the offering what are the - * available layers. - */ - -@FutureFeature -public class VmsLayersAvailability { - - private static final boolean DBG = true; - private static final String TAG = "VmsLayersAvailability"; - - private final Object mLock = new Object(); - @GuardedBy("mLock") - private final Map<VmsLayer, Set<Set<VmsLayer>>> mPotentialLayersAndDependencies = - new HashMap<>(); - @GuardedBy("mLock") - private Set<VmsAssociatedLayer> mAvailableAssociatedLayers = Collections.EMPTY_SET; - @GuardedBy("mLock") - private Set<VmsAssociatedLayer> mUnavailableAssociatedLayers = Collections.EMPTY_SET; - @GuardedBy("mLock") - private Map<VmsLayer, Set<Integer>> mPotentialLayersAndPublishers = new HashMap<>(); - - /** - * Setting the current layers offerings as reported by publishers. - */ - public void setPublishersOffering(Collection<VmsLayersOffering> publishersLayersOfferings) { - synchronized (mLock) { - reset(); - - for (VmsLayersOffering offering : publishersLayersOfferings) { - for (VmsLayerDependency dependency : offering.getDependencies()) { - VmsLayer layer = dependency.getLayer(); - - // Associate publishers with layers. - Set<Integer> curPotentialLayerAndPublishers = - mPotentialLayersAndPublishers.get(layer); - if (curPotentialLayerAndPublishers == null) { - curPotentialLayerAndPublishers = new HashSet<>(); - mPotentialLayersAndPublishers.put(layer, curPotentialLayerAndPublishers); - } - curPotentialLayerAndPublishers.add(offering.getPublisherId()); - - // Add dependencies for availability calculation. - Set<Set<VmsLayer>> curDependencies = - mPotentialLayersAndDependencies.get(layer); - if (curDependencies == null) { - curDependencies = new HashSet<>(); - mPotentialLayersAndDependencies.put(layer, curDependencies); - } - curDependencies.add(dependency.getDependencies()); - } - } - calculateLayers(); - } - } - - /** - * Returns a collection of all the layers which may be published. - */ - public Set<VmsAssociatedLayer> getAvailableLayers() { - synchronized (mLock) { - return mAvailableAssociatedLayers; - } - } - - /** - * Returns a collection of all the layers which publishers could have published if the - * dependencies were satisfied. - */ - public Set<VmsAssociatedLayer> getUnavailableLayers() { - synchronized (mLock) { - return mUnavailableAssociatedLayers; - } - } - - private void reset() { - synchronized (mLock) { - mPotentialLayersAndDependencies.clear(); - mPotentialLayersAndPublishers.clear(); - mAvailableAssociatedLayers = Collections.EMPTY_SET; - mUnavailableAssociatedLayers = Collections.EMPTY_SET; - } - } - - private void calculateLayers() { - synchronized (mLock) { - Set<VmsLayer> availableLayersSet = new HashSet<>(); - Set<VmsLayer> cyclicAvoidanceAuxiliarySet = new HashSet<>(); - - for (VmsLayer layer : mPotentialLayersAndDependencies.keySet()) { - addLayerToAvailabilityCalculationLocked(layer, - availableLayersSet, - cyclicAvoidanceAuxiliarySet); - } - - mAvailableAssociatedLayers = Collections.unmodifiableSet( - availableLayersSet - .stream() - .map(l -> new VmsAssociatedLayer(l, mPotentialLayersAndPublishers.get(l))) - .collect(Collectors.toSet())); - - mUnavailableAssociatedLayers = Collections.unmodifiableSet( - mPotentialLayersAndDependencies.keySet() - .stream() - .filter(l -> !availableLayersSet.contains(l)) - .map(l -> new VmsAssociatedLayer(l, mPotentialLayersAndPublishers.get(l))) - .collect(Collectors.toSet())); - } - } - - private void addLayerToAvailabilityCalculationLocked(VmsLayer layer, - Set<VmsLayer> currentAvailableLayers, - Set<VmsLayer> cyclicAvoidanceSet) { - if (DBG) { - Log.d(TAG, "addLayerToAvailabilityCalculationLocked: checking layer: " + layer); - } - // If we already know that this layer is supported then we are done. - if (currentAvailableLayers.contains(layer)) { - return; - } - // If there is no offering for this layer we're done. - if (!mPotentialLayersAndDependencies.containsKey(layer)) { - return; - } - // Avoid cyclic dependency. - if (cyclicAvoidanceSet.contains(layer)) { - Log.e(TAG, "Detected a cyclic dependency: " + cyclicAvoidanceSet + " -> " + layer); - return; - } - // A layer may have multiple dependency sets. The layer is available if any dependency - // set is satisfied - for (Set<VmsLayer> dependencies : mPotentialLayersAndDependencies.get(layer)) { - // If layer does not have any dependencies then add to supported. - if (dependencies == null || dependencies.isEmpty()) { - currentAvailableLayers.add(layer); - return; - } - // Add the layer to cyclic avoidance set - cyclicAvoidanceSet.add(layer); - - boolean isSupported = true; - for (VmsLayer dependency : dependencies) { - addLayerToAvailabilityCalculationLocked(dependency, - currentAvailableLayers, - cyclicAvoidanceSet); - - if (!currentAvailableLayers.contains(dependency)) { - isSupported = false; - break; - } - } - cyclicAvoidanceSet.remove(layer); - - if (isSupported) { - currentAvailableLayers.add(layer); - return; - } - } - return; - } -} diff --git a/service/src/com/android/car/VmsPublisherService.java b/service/src/com/android/car/VmsPublisherService.java deleted file mode 100644 index 8a293e5e37..0000000000 --- a/service/src/com/android/car/VmsPublisherService.java +++ /dev/null @@ -1,336 +0,0 @@ -/* - * 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 com.android.car; - -import android.car.annotation.FutureFeature; -import android.car.vms.IVmsSubscriberClient; -import android.car.vms.IVmsPublisherClient; -import android.car.vms.IVmsPublisherService; -import android.car.vms.VmsLayer; -import android.car.vms.VmsLayersOffering; -import android.car.vms.VmsSubscriptionState; -import android.content.ComponentName; -import android.content.Context; -import android.content.Intent; -import android.content.ServiceConnection; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; -import android.os.Binder; -import android.os.IBinder; -import android.os.RemoteException; -import android.os.UserHandle; -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; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * + Receives HAL updates by implementing VmsHalService.VmsHalListener. - * + Binds to publishers and configures them to use this service. - * + Notifies publishers of subscription changes. - */ -@FutureFeature -public class VmsPublisherService extends IVmsPublisherService.Stub - implements CarServiceBase, VmsHalService.VmsHalPublisherListener { - private static final boolean DBG = true; - private static final String TAG = "VmsPublisherService"; - - private final Context mContext; - private final VmsHalService mHal; - private final VmsPublisherManager mPublisherManager; - private Set<String> mSafePermissions; - - public VmsPublisherService(Context context, VmsHalService hal) { - mContext = context; - mHal = hal; - mPublisherManager = new VmsPublisherManager(this); - } - - // Implements CarServiceBase interface. - @Override - public void init() { - mHal.addPublisherListener(this); - // Load permissions that can be granted to publishers. - mSafePermissions = new HashSet<>( - Arrays.asList(mContext.getResources().getStringArray(R.array.vmsSafePermissions))); - // Launch publishers. - String[] publisherNames = mContext.getResources().getStringArray( - R.array.vmsPublisherClients); - for (String publisherName : publisherNames) { - if (TextUtils.isEmpty(publisherName)) { - Log.e(TAG, "empty publisher name"); - continue; - } - ComponentName name = ComponentName.unflattenFromString(publisherName); - if (name == null) { - Log.e(TAG, "invalid publisher name: " + publisherName); - } - mPublisherManager.bind(name); - } - } - - @Override - public void release() { - mPublisherManager.release(); - mHal.removePublisherListener(this); - } - - @Override - public void dump(PrintWriter writer) { - } - - @Override - public void setLayersOffering(IBinder token, VmsLayersOffering offering) { - mHal.setPublisherLayersOffering(token, offering); - } - - // Implements IVmsPublisherService interface. - @Override - public void publish(IBinder token, VmsLayer layer, int publisherId, byte[] payload) { - if (DBG) { - Log.d(TAG, "Publishing for layer: " + layer); - } - ICarImpl.assertVmsPublisherPermission(mContext); - - // Send the message to application listeners. - Set<IVmsSubscriberClient> listeners = - mHal.getSubscribersForLayerFromPublisher(layer, publisherId); - - if (DBG) { - Log.d(TAG, "Number of subscribed apps: " + listeners.size()); - } - for (IVmsSubscriberClient listener : listeners) { - try { - listener.onVmsMessageReceived(layer, payload); - } catch (RemoteException ex) { - Log.e(TAG, "unable to publish to listener: " + listener); - } - } - - // Send the message to HAL - if (mHal.isHalSubscribed(layer)) { - Log.d(TAG, "HAL is subscribed"); - mHal.setDataMessage(layer, payload); - } else { - Log.d(TAG, "HAL is NOT subscribed"); - } - } - - @Override - public VmsSubscriptionState getSubscriptions() { - ICarImpl.assertVmsPublisherPermission(mContext); - return mHal.getSubscriptionState(); - } - - @Override - public int getPublisherId(byte[] publisherInfo) { - ICarImpl.assertVmsPublisherPermission(mContext); - return mHal.getPublisherId(publisherInfo); - } - - // Implements VmsHalListener interface - /** - * This method is only invoked by VmsHalService.notifyPublishers which is synchronized. - * Therefore this method only sees a non-decreasing sequence. - */ - @Override - public void onChange(VmsSubscriptionState subscriptionState) { - // Send the message to application listeners. - for (IVmsPublisherClient client : mPublisherManager.getClients()) { - try { - client.onVmsSubscriptionChange(subscriptionState); - } catch (RemoteException ex) { - Log.e(TAG, "unable to send notification to: " + client, ex); - } - } - } - - /** - * Keeps track of publishers that are using this service. - */ - private static class VmsPublisherManager { - /** - * Allows to modify mPublisherMap and mPublisherConnectionMap as a single unit. - */ - private final Object mLock = new Object(); - @GuardedBy("mLock") - private final Map<String, PublisherConnection> mPublisherConnectionMap = new HashMap<>(); - @GuardedBy("mLock") - private final Map<String, IVmsPublisherClient> mPublisherMap = new HashMap<>(); - private final WeakReference<VmsPublisherService> mPublisherService; - - public VmsPublisherManager(VmsPublisherService publisherService) { - mPublisherService = new WeakReference<>(publisherService); - } - - /** - * Tries to bind to a publisher. - * - * @param name publisher component name (e.g. android.car.vms.logger/.LoggingService). - */ - public void bind(ComponentName name) { - VmsPublisherService publisherService = mPublisherService.get(); - if (publisherService == null) return; - String publisherName = name.flattenToString(); - if (DBG) { - Log.d(TAG, "binding to: " + publisherName); - } - synchronized (mLock) { - if (mPublisherConnectionMap.containsKey(publisherName)) { - // Already registered, nothing to do. - return; - } - grantPermissions(name); - Intent intent = new Intent(); - intent.setComponent(name); - PublisherConnection connection = new PublisherConnection(); - if (publisherService.mContext.bindServiceAsUser(intent, connection, - Context.BIND_AUTO_CREATE, UserHandle.SYSTEM)) { - mPublisherConnectionMap.put(publisherName, connection); - } else { - Log.e(TAG, "unable to bind to: " + publisherName); - } - } - } - - /** - * Removes the publisher and associated connection. - * - * @param name publisher component name (e.g. android.car.vms.Logger). - */ - public void unbind(ComponentName name) { - VmsPublisherService publisherService = mPublisherService.get(); - if (publisherService == null) return; - String publisherName = name.flattenToString(); - if (DBG) { - Log.d(TAG, "unbinding from: " + publisherName); - } - synchronized (mLock) { - boolean found = mPublisherMap.remove(publisherName) != null; - if (found) { - PublisherConnection connection = mPublisherConnectionMap.get(publisherName); - publisherService.mContext.unbindService(connection); - mPublisherConnectionMap.remove(publisherName); - } else { - Log.e(TAG, "unbind: unknown publisher." + publisherName); - } - } - } - - /** - * Returns the list of publishers currently registered. - * - * @return list of publishers. - */ - public List<IVmsPublisherClient> getClients() { - synchronized (mLock) { - return new ArrayList<>(mPublisherMap.values()); - } - } - - public void release() { - VmsPublisherService publisherService = mPublisherService.get(); - if (publisherService == null) return; - for (PublisherConnection connection : mPublisherConnectionMap.values()) { - publisherService.mContext.unbindService(connection); - } - mPublisherConnectionMap.clear(); - mPublisherMap.clear(); - } - - private void grantPermissions(ComponentName component) { - VmsPublisherService publisherService = mPublisherService.get(); - if (publisherService == null) return; - final PackageManager packageManager = publisherService.mContext.getPackageManager(); - final String packageName = component.getPackageName(); - PackageInfo packageInfo; - try { - packageInfo = packageManager.getPackageInfo(packageName, - PackageManager.GET_PERMISSIONS); - } catch (PackageManager.NameNotFoundException e) { - Log.e(TAG, "Error getting package info for " + packageName, e); - return; - } - if (packageInfo.requestedPermissions == null) return; - for (String permission : packageInfo.requestedPermissions) { - if (!publisherService.mSafePermissions.contains(permission)) { - continue; - } - if (packageManager.checkPermission(permission, packageName) - == PackageManager.PERMISSION_GRANTED) { - continue; - } - try { - packageManager.grantRuntimePermission(packageName, permission, - UserHandle.SYSTEM); - Log.d(TAG, "Permission " + permission + " granted to " + packageName); - } catch (SecurityException | IllegalArgumentException e) { - Log.e(TAG, "Error while trying to grant " + permission + " to " + packageName, - e); - } - } - } - - 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 - * and the publisher is configured to use this service. - */ - @Override - public void onServiceConnected(ComponentName name, IBinder binder) { - VmsPublisherService publisherService = mPublisherService.get(); - if (publisherService == null) return; - if (DBG) { - Log.d(TAG, "onServiceConnected, name: " + name + ", binder: " + binder); - } - IVmsPublisherClient service = IVmsPublisherClient.Stub.asInterface(binder); - synchronized (mLock) { - mPublisherMap.put(name.flattenToString(), service); - } - try { - service.setVmsPublisherService(mToken, publisherService); - } catch (RemoteException e) { - Log.e(TAG, "unable to configure publisher: " + name); - } - } - - /** - * Tries to rebind to the publisher service. - */ - @Override - public void onServiceDisconnected(ComponentName name) { - String publisherName = name.flattenToString(); - Log.d(TAG, "onServiceDisconnected, name: " + publisherName); - VmsPublisherManager.this.unbind(name); - VmsPublisherManager.this.bind(name); - } - } - } -} diff --git a/service/src/com/android/car/VmsPublishersInfo.java b/service/src/com/android/car/VmsPublishersInfo.java deleted file mode 100644 index 04ee82f78d..0000000000 --- a/service/src/com/android/car/VmsPublishersInfo.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * 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 com.android.car; - - -import android.car.annotation.FutureFeature; -import java.util.HashMap; -import java.util.Map; -import java.util.List; -import java.util.ArrayList; -import java.util.Arrays; -import com.android.internal.annotations.GuardedBy; -import android.util.Log; - -@FutureFeature -public class VmsPublishersInfo { - private static final String TAG = "VmsPublishersInfo"; - private static final boolean DBG = true; - private final Object mLock = new Object(); - @GuardedBy("mLock") - private final Map<InfoWrapper, Integer> mPublishersIds = new HashMap(); - @GuardedBy("mLock") - private final Map<Integer, byte[]> mPublishersInfo = new HashMap(); - - private static class InfoWrapper { - private final byte[] mInfo; - - public InfoWrapper(byte[] info) { - mInfo = info; - } - - public byte[] getInfo() { - return mInfo; - } - - @Override - public boolean equals(Object o) { - if (!(o instanceof InfoWrapper)) { - return false; - } - InfoWrapper p = (InfoWrapper) o; - return Arrays.equals(this.mInfo, p.mInfo); - } - - @Override - public int hashCode() { - return Arrays.hashCode(mInfo); - } - } - - /** - * Returns the ID associated with the publisher info. When called for the first time for a - * publisher info will store the info and assign an ID - */ - public int getIdForInfo(byte[] publisherInfo) { - Integer publisherId; - InfoWrapper wrappedPublisherInfo = new InfoWrapper(publisherInfo); - synchronized (mLock) { - maybeAddPublisherInfoLocked(wrappedPublisherInfo); - publisherId = mPublishersIds.get(wrappedPublisherInfo); - } - if (DBG) { - Log.i(TAG, "Publisher ID is: " + publisherId); - } - return publisherId; - } - - public byte[] getPublisherInfo(int publisherId) { - synchronized (mLock) { - return mPublishersInfo.get(publisherId).clone(); - } - } - - private void maybeAddPublisherInfoLocked(InfoWrapper wrappedPublisherInfo) { - if (!mPublishersIds.containsKey(wrappedPublisherInfo)) { - // Assign ID to the info - Integer publisherId = mPublishersIds.size(); - - mPublishersIds.put(wrappedPublisherInfo, publisherId); - mPublishersInfo.put(publisherId, wrappedPublisherInfo.getInfo()); - } - } -} - diff --git a/service/src/com/android/car/VmsRouting.java b/service/src/com/android/car/VmsRouting.java deleted file mode 100644 index 2e66781d39..0000000000 --- a/service/src/com/android/car/VmsRouting.java +++ /dev/null @@ -1,414 +0,0 @@ -/* - * 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 com.android.car; - -import android.car.annotation.FutureFeature; -import android.car.vms.IVmsSubscriberClient; -import android.car.vms.VmsAssociatedLayer; -import android.car.vms.VmsLayer; -import android.car.vms.VmsOperationRecorder; -import android.car.vms.VmsSubscriptionState; - -import com.android.internal.annotations.GuardedBy; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; - -/** - * Manages all the VMS subscriptions: - * + Subscriptions to data messages of individual layer + version. - * + Subscriptions to all data messages. - * + HAL subscriptions to layer + version. - */ -@FutureFeature -public class VmsRouting { - private final Object mLock = new Object(); - // A map of Layer + Version to subscribers. - @GuardedBy("mLock") - private Map<VmsLayer, Set<IVmsSubscriberClient>> mLayerSubscriptions = new HashMap<>(); - - @GuardedBy("mLock") - private Map<VmsLayer, Map<Integer, Set<IVmsSubscriberClient>>> mLayerSubscriptionsToPublishers = - new HashMap<>(); - // A set of subscribers that are interested in any layer + version. - @GuardedBy("mLock") - private Set<IVmsSubscriberClient> mPromiscuousSubscribers = new HashSet<>(); - - // A set of all the layers + versions the HAL is subscribed to. - @GuardedBy("mLock") - private Set<VmsLayer> mHalSubscriptions = new HashSet<>(); - - @GuardedBy("mLock") - private Map<VmsLayer, Set<Integer>> mHalSubscriptionsToPublishers = new HashMap<>(); - // A sequence number that is increased every time the subscription state is modified. Note that - // modifying the list of promiscuous subscribers does not affect the subscription state. - @GuardedBy("mLock") - private int mSequenceNumber = 0; - - /** - * Add a subscriber subscription to data messages from a VMS layer. - * - * @param subscriber a VMS subscriber. - * @param layer the layer subscribing to. - */ - public void addSubscription(IVmsSubscriberClient subscriber, VmsLayer layer) { - //TODO(b/36902947): revise if need to sync, and return value. - synchronized (mLock) { - ++mSequenceNumber; - // Get or create the list of subscribers for layer and version. - Set<IVmsSubscriberClient> subscribers = mLayerSubscriptions.get(layer); - - if (subscribers == null) { - subscribers = new HashSet<>(); - mLayerSubscriptions.put(layer, subscribers); - } - // Add the subscriber to the list. - subscribers.add(subscriber); - VmsOperationRecorder.get().addSubscription(mSequenceNumber, layer); - } - } - - /** - * Add a subscriber subscription to all data messages. - * - * @param subscriber a VMS subscriber. - */ - public void addSubscription(IVmsSubscriberClient subscriber) { - synchronized (mLock) { - ++mSequenceNumber; - mPromiscuousSubscribers.add(subscriber); - VmsOperationRecorder.get().addPromiscuousSubscription(mSequenceNumber); - } - } - - /** - * Add a subscriber subscription to data messages from a VMS layer from a specific publisher. - * - * @param subscriber a VMS subscriber. - * @param layer the layer to subscribing to. - * @param publisherId the publisher ID. - */ - public void addSubscription(IVmsSubscriberClient subscriber, VmsLayer layer, int publisherId) { - synchronized (mLock) { - ++mSequenceNumber; - - Map<Integer, Set<IVmsSubscriberClient>> publisherIdsToSubscribersForLayer = - mLayerSubscriptionsToPublishers.get(layer); - - if (publisherIdsToSubscribersForLayer == null) { - publisherIdsToSubscribersForLayer = new HashMap<>(); - mLayerSubscriptionsToPublishers.put(layer, publisherIdsToSubscribersForLayer); - } - - Set<IVmsSubscriberClient> subscribersForPublisher = - publisherIdsToSubscribersForLayer.get(publisherId); - - if (subscribersForPublisher == null) { - subscribersForPublisher = new HashSet<>(); - publisherIdsToSubscribersForLayer.put(publisherId, subscribersForPublisher); - } - - // Add the subscriber to the list. - subscribersForPublisher.add(subscriber); - } - } - - /** - * Remove a subscription for a layer + version and make sure to remove the key if there are no - * more subscribers. - * - * @param subscriber to remove. - * @param layer of the subscription. - */ - public void removeSubscription(IVmsSubscriberClient subscriber, VmsLayer layer) { - synchronized (mLock) { - ++mSequenceNumber; - Set<IVmsSubscriberClient> subscribers = mLayerSubscriptions.get(layer); - - // If there are no subscribers we are done. - if (subscribers == null) { - return; - } - subscribers.remove(subscriber); - VmsOperationRecorder.get().removeSubscription(mSequenceNumber, layer); - - // If there are no more subscribers then remove the list. - if (subscribers.isEmpty()) { - mLayerSubscriptions.remove(layer); - } - } - } - - /** - * Remove a subscriber subscription to all data messages. - * - * @param subscriber a VMS subscriber. - */ - public void removeSubscription(IVmsSubscriberClient subscriber) { - synchronized (mLock) { - ++mSequenceNumber; - mPromiscuousSubscribers.remove(subscriber); - VmsOperationRecorder.get().removePromiscuousSubscription(mSequenceNumber); - } - } - - /** - * Remove a subscription to data messages from a VMS layer from a specific publisher. - * - * @param subscriber a VMS subscriber. - * @param layer the layer to unsubscribing from. - * @param publisherId the publisher ID. - */ - public void removeSubscription(IVmsSubscriberClient subscriber, - VmsLayer layer, - int publisherId) { - synchronized (mLock) { - ++mSequenceNumber; - - Map<Integer, Set<IVmsSubscriberClient>> subscribersToPublishers = - mLayerSubscriptionsToPublishers.get(layer); - - if (subscribersToPublishers == null) { - return; - } - - Set<IVmsSubscriberClient> subscribers = subscribersToPublishers.get(publisherId); - - if (subscribers == null) { - return; - } - subscribers.remove(subscriber); - - if (subscribers.isEmpty()) { - subscribersToPublishers.remove(publisherId); - } - - if (subscribersToPublishers.isEmpty()) { - mLayerSubscriptionsToPublishers.remove(layer); - } - } - } - - /** - * Remove a subscriber from all routes (optional operation). - * - * @param subscriber a VMS subscriber. - */ - public void removeDeadSubscriber(IVmsSubscriberClient subscriber) { - synchronized (mLock) { - // Remove the subscriber from all the routes. - for (VmsLayer layer : mLayerSubscriptions.keySet()) { - removeSubscription(subscriber, layer); - } - // Remove the subscriber from the loggers. - removeSubscription(subscriber); - } - } - - /** - * Returns a list of all the subscribers for a layer from a publisher. This includes - * subscribers that subscribed to this layer from all publishers, subscribed to this layer - * from a specific publisher, and the promiscuous subscribers. - * - * @param layer The layer of the message. - * @param publisherId the ID of the client that published the message to be routed. - * @return a list of the subscribers. - */ - public Set<IVmsSubscriberClient> getSubscribersForLayerFromPublisher(VmsLayer layer, - int publisherId) { - Set<IVmsSubscriberClient> subscribers = new HashSet<>(); - synchronized (mLock) { - // Add the subscribers which explicitly subscribed to this layer - if (mLayerSubscriptions.containsKey(layer)) { - subscribers.addAll(mLayerSubscriptions.get(layer)); - } - - // Add the subscribers which explicitly subscribed to this layer and publisher - if (mLayerSubscriptionsToPublishers.containsKey(layer)) { - if (mLayerSubscriptionsToPublishers.get(layer).containsKey(publisherId)) { - subscribers.addAll(mLayerSubscriptionsToPublishers.get(layer).get(publisherId)); - } - } - - // Add the promiscuous subscribers. - subscribers.addAll(mPromiscuousSubscribers); - } - return subscribers; - } - - /** - * Returns a list with all the subscribers. - */ - public Set<IVmsSubscriberClient> getAllSubscribers() { - Set<IVmsSubscriberClient> subscribers = new HashSet<>(); - synchronized (mLock) { - for (VmsLayer layer : mLayerSubscriptions.keySet()) { - subscribers.addAll(mLayerSubscriptions.get(layer)); - } - // Add the promiscuous subscribers. - subscribers.addAll(mPromiscuousSubscribers); - } - return subscribers; - } - - /** - * Checks if a subscriber is subscribed to any messages. - * - * @param subscriber that may have subscription. - * @return true if the subscriber uis subscribed to messages. - */ - public boolean containsSubscriber(IVmsSubscriberClient subscriber) { - synchronized (mLock) { - // Check if subscriber is subscribed to a layer. - for (Set<IVmsSubscriberClient> layerSubscribers : mLayerSubscriptions.values()) { - if (layerSubscribers.contains(subscriber)) { - return true; - } - } - // Check is subscriber is subscribed to all data messages. - return mPromiscuousSubscribers.contains(subscriber); - } - } - - /** - * Add a layer and version to the HAL subscriptions. - * - * @param layer the HAL subscribes to. - */ - public void addHalSubscription(VmsLayer layer) { - synchronized (mLock) { - ++mSequenceNumber; - mHalSubscriptions.add(layer); - VmsOperationRecorder.get().addHalSubscription(mSequenceNumber, layer); - } - } - - public void addHalSubscriptionToPublisher(VmsLayer layer, int publisherId) { - synchronized (mLock) { - ++mSequenceNumber; - - Set<Integer> publisherIdsForLayer = mHalSubscriptionsToPublishers.get(layer); - if (publisherIdsForLayer == null) { - publisherIdsForLayer = new HashSet<>(); - mHalSubscriptionsToPublishers.put(layer, publisherIdsForLayer); - } - publisherIdsForLayer.add(publisherId); - } - } - - /** - * remove a layer and version to the HAL subscriptions. - * - * @param layer the HAL unsubscribes from. - */ - public void removeHalSubscription(VmsLayer layer) { - synchronized (mLock) { - ++mSequenceNumber; - mHalSubscriptions.remove(layer); - VmsOperationRecorder.get().removeHalSubscription(mSequenceNumber, layer); - } - } - - public void removeHalSubscriptionToPublisher(VmsLayer layer, int publisherId) { - synchronized (mLock) { - ++mSequenceNumber; - - Set<Integer> publisherIdsForLayer = mHalSubscriptionsToPublishers.get(layer); - if (publisherIdsForLayer == null) { - return; - } - publisherIdsForLayer.remove(publisherId); - - if (publisherIdsForLayer.isEmpty()) { - mHalSubscriptionsToPublishers.remove(layer); - } - } - } - - /** - * checks if the HAL is subscribed to a layer. - * - * @param layer - * @return true if the HAL is subscribed to layer. - */ - public boolean isHalSubscribed(VmsLayer layer) { - synchronized (mLock) { - return mHalSubscriptions.contains(layer); - } - } - - /** - * checks if there are subscribers to a layer. - * - * @param layer - * @return true if there are subscribers to layer. - */ - public boolean hasLayerSubscriptions(VmsLayer layer) { - synchronized (mLock) { - return mLayerSubscriptions.containsKey(layer) || mHalSubscriptions.contains(layer); - } - } - - /** - * returns true if there is already a subscription for the layer from publisherId. - * - * @param layer - * @param publisherId - * @return - */ - public boolean hasLayerFromPublisherSubscriptions(VmsLayer layer, int publisherId) { - synchronized (mLock) { - boolean hasClientSubscription = - mLayerSubscriptionsToPublishers.containsKey(layer) && - mLayerSubscriptionsToPublishers.get(layer).containsKey(publisherId); - - boolean hasHalSubscription = mHalSubscriptionsToPublishers.containsKey(layer) && - mHalSubscriptionsToPublishers.get(layer).contains(publisherId); - - return hasClientSubscription || hasHalSubscription; - } - } - - /** - * @return a Set of layers and versions which VMS clients are subscribed to. - */ - public VmsSubscriptionState getSubscriptionState() { - synchronized (mLock) { - Set<VmsLayer> layers = new HashSet<>(); - layers.addAll(mLayerSubscriptions.keySet()); - layers.addAll(mHalSubscriptions); - - - Set<VmsAssociatedLayer> layersFromPublishers = new HashSet<>(); - layersFromPublishers.addAll(mLayerSubscriptionsToPublishers.entrySet() - .stream() - .map(e -> new VmsAssociatedLayer(e.getKey(), e.getValue().keySet())) - .collect(Collectors.toSet())); - layersFromPublishers.addAll(mHalSubscriptionsToPublishers.entrySet() - .stream() - .map(e -> new VmsAssociatedLayer(e.getKey(), e.getValue())) - .collect(Collectors.toSet())); - - return new VmsSubscriptionState(mSequenceNumber, layers, layersFromPublishers); - } - } -}
\ No newline at end of file diff --git a/service/src/com/android/car/VmsSubscriberService.java b/service/src/com/android/car/VmsSubscriberService.java deleted file mode 100644 index 94f0844564..0000000000 --- a/service/src/com/android/car/VmsSubscriberService.java +++ /dev/null @@ -1,353 +0,0 @@ -/* - * 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 com.android.car; - -import android.car.Car; -import android.car.annotation.FutureFeature; -import android.car.vms.IVmsSubscriberClient; -import android.car.vms.IVmsSubscriberService; -import android.car.vms.VmsAssociatedLayer; -import android.car.vms.VmsLayer; -import android.content.Context; -import android.os.IBinder; -import android.os.RemoteException; -import android.util.Log; - -import com.android.car.hal.VmsHalService; -import com.android.internal.annotations.GuardedBy; - -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * + Receives HAL updates by implementing VmsHalService.VmsHalListener. - * + Offers subscriber/publisher services by implementing IVmsService.Stub. - */ -@FutureFeature -public class VmsSubscriberService extends IVmsSubscriberService.Stub - implements CarServiceBase, VmsHalService.VmsHalSubscriberListener { - private static final boolean DBG = true; - private static final String PERMISSION = Car.PERMISSION_VMS_SUBSCRIBER; - private static final String TAG = "VmsSubscriberService"; - - private final Context mContext; - private final VmsHalService mHal; - - @GuardedBy("mSubscriberServiceLock") - private final VmsSubscribersManager mSubscribersManager = new VmsSubscribersManager(); - private final Object mSubscriberServiceLock = new Object(); - - /** - * Keeps track of subscribers of this service. - */ - class VmsSubscribersManager { - /** - * Allows to modify mSubscriberMap and mListenerDeathRecipientMap as a single unit. - */ - private final Object mListenerManagerLock = new Object(); - @GuardedBy("mListenerManagerLock") - private final Map<IBinder, ListenerDeathRecipient> mListenerDeathRecipientMap = - new HashMap<>(); - @GuardedBy("mListenerManagerLock") - private final Map<IBinder, IVmsSubscriberClient> mSubscriberMap = new HashMap<>(); - - class ListenerDeathRecipient implements IBinder.DeathRecipient { - private IBinder mSubscriberBinder; - - ListenerDeathRecipient(IBinder subscriberBinder) { - mSubscriberBinder = subscriberBinder; - } - - /** - * Listener died. Remove it from this service. - */ - @Override - public void binderDied() { - if (DBG) { - Log.d(TAG, "binderDied " + mSubscriberBinder); - } - - // Get the Listener from the Binder - IVmsSubscriberClient subscriber = mSubscriberMap.get(mSubscriberBinder); - - // Remove the subscriber subscriptions. - if (subscriber != null) { - Log.d(TAG, "Removing subscriptions for dead subscriber: " + subscriber); - mHal.removeDeadSubscriber(subscriber); - } else { - Log.d(TAG, "Handling dead binder with no matching subscriber"); - - } - - // Remove binder - VmsSubscribersManager.this.removeListener(mSubscriberBinder); - } - - void release() { - mSubscriberBinder.unlinkToDeath(this, 0); - } - } - - public void release() { - for (ListenerDeathRecipient recipient : mListenerDeathRecipientMap.values()) { - recipient.release(); - } - mListenerDeathRecipientMap.clear(); - mSubscriberMap.clear(); - } - - /** - * Adds the subscriber and a death recipient associated to it. - * - * @param subscriber to be added. - * @throws IllegalArgumentException if the subscriber is null. - * @throws IllegalStateException if it was not possible to link a death recipient to the - * subscriber. - */ - public void add(IVmsSubscriberClient subscriber) { - ICarImpl.assertPermission(mContext, PERMISSION); - if (subscriber == null) { - Log.e(TAG, "register: subscriber is null."); - throw new IllegalArgumentException("subscriber cannot be null."); - } - if (DBG) { - Log.d(TAG, "register: " + subscriber); - } - IBinder subscriberBinder = subscriber.asBinder(); - synchronized (mListenerManagerLock) { - if (mSubscriberMap.containsKey(subscriberBinder)) { - // Already registered, nothing to do. - return; - } - ListenerDeathRecipient deathRecipient = - new ListenerDeathRecipient(subscriberBinder); - try { - subscriberBinder.linkToDeath(deathRecipient, 0); - } catch (RemoteException e) { - Log.e(TAG, "Failed to link death for recipient. ", e); - throw new IllegalStateException(Car.CAR_NOT_CONNECTED_EXCEPTION_MSG); - } - mListenerDeathRecipientMap.put(subscriberBinder, deathRecipient); - mSubscriberMap.put(subscriberBinder, subscriber); - } - } - - /** - * Removes the subscriber and associated death recipient. - * - * @param subscriber to be removed. - * @throws IllegalArgumentException if subscriber is null. - */ - public void remove(IVmsSubscriberClient subscriber) { - if (DBG) { - Log.d(TAG, "unregisterListener"); - } - ICarImpl.assertPermission(mContext, PERMISSION); - if (subscriber == null) { - Log.e(TAG, "unregister: subscriber is null."); - throw new IllegalArgumentException("Listener is null"); - } - IBinder subscriberBinder = subscriber.asBinder(); - removeListener(subscriberBinder); - } - - // Removes the subscriberBinder from the current state. - // The function assumes that binder will exist both in subscriber and death recipients list. - private void removeListener(IBinder subscriberBinder) { - synchronized (mListenerManagerLock) { - boolean found = mSubscriberMap.remove(subscriberBinder) != null; - if (found) { - mListenerDeathRecipientMap.get(subscriberBinder).release(); - mListenerDeathRecipientMap.remove(subscriberBinder); - } else { - Log.e(TAG, "removeListener: subscriber was not previously registered."); - } - } - } - - /** - * Returns list of subscribers currently registered. - * - * @return list of subscribers. - */ - public List<IVmsSubscriberClient> getListeners() { - synchronized (mListenerManagerLock) { - return new ArrayList<>(mSubscriberMap.values()); - } - } - } - - public VmsSubscriberService(Context context, VmsHalService hal) { - mContext = context; - mHal = hal; - } - - // Implements CarServiceBase interface. - @Override - public void init() { - mHal.addSubscriberListener(this); - } - - @Override - public void release() { - mSubscribersManager.release(); - mHal.removeSubscriberListener(this); - } - - @Override - public void dump(PrintWriter writer) { - } - - // Implements IVmsService interface. - @Override - public void addVmsSubscriberToNotifications(IVmsSubscriberClient subscriber) { - synchronized (mSubscriberServiceLock) { - // Add the subscriber so it can subscribe. - mSubscribersManager.add(subscriber); - } - } - - @Override - public void removeVmsSubscriberToNotifications(IVmsSubscriberClient subscriber) { - synchronized (mSubscriberServiceLock) { - if (mHal.containsSubscriber(subscriber)) { - throw new IllegalArgumentException("Subscriber has active subscriptions."); - } - mSubscribersManager.remove(subscriber); - } - } - - @Override - public void addVmsSubscriber(IVmsSubscriberClient subscriber, VmsLayer layer) { - synchronized (mSubscriberServiceLock) { - // Add the subscriber so it can subscribe. - mSubscribersManager.add(subscriber); - - // Add the subscription for the layer. - mHal.addSubscription(subscriber, layer); - } - } - - @Override - public void removeVmsSubscriber(IVmsSubscriberClient subscriber, VmsLayer layer) { - synchronized (mSubscriberServiceLock) { - // Remove the subscription. - mHal.removeSubscription(subscriber, layer); - } - } - - @Override - public void addVmsSubscriberToPublisher(IVmsSubscriberClient subscriber, - VmsLayer layer, - int publisherId) { - synchronized (mSubscriberServiceLock) { - // Add the subscriber so it can subscribe. - mSubscribersManager.add(subscriber); - - // Add the subscription for the layer. - mHal.addSubscription(subscriber, layer, publisherId); - } - } - - @Override - public void removeVmsSubscriberToPublisher(IVmsSubscriberClient subscriber, - VmsLayer layer, - int publisherId) { - synchronized (mSubscriberServiceLock) { - // Remove the subscription. - mHal.removeSubscription(subscriber, layer, publisherId); - } - } - - @Override - public void addVmsSubscriberPassive(IVmsSubscriberClient subscriber) { - synchronized (mSubscriberServiceLock) { - mSubscribersManager.add(subscriber); - mHal.addSubscription(subscriber); - } - } - - @Override - public void removeVmsSubscriberPassive(IVmsSubscriberClient subscriber) { - synchronized (mSubscriberServiceLock) { - // Remove the subscription. - mHal.removeSubscription(subscriber); - } - } - - @Override - public byte[] getPublisherInfo(int publisherId) { - synchronized (mSubscriberServiceLock) { - return mHal.getPublisherInfo(publisherId); - } - } - - @Override - public List<VmsLayer> getAvailableLayers() { - //TODO(asafro): return the list of available layers once logic is implemented. - return Collections.emptyList(); - } - - // Implements VmsHalSubscriberListener interface - @Override - public void onDataMessage(VmsLayer layer, int publisherId, byte[] payload) { - if (DBG) { - Log.d(TAG, "Publishing a message for layer: " + layer); - } - - Set<IVmsSubscriberClient> subscribers = - mHal.getSubscribersForLayerFromPublisher(layer, publisherId); - - for (IVmsSubscriberClient subscriber : subscribers) { - try { - subscriber.onVmsMessageReceived(layer, payload); - } catch (RemoteException e) { - // If we could not send a record, its likely the connection snapped. Let the binder - // death handle the situation. - Log.e(TAG, "onVmsMessageReceived calling failed: ", e); - } - } - } - - @Override - public void onLayersAvaiabilityChange(List<VmsAssociatedLayer> availableLayers) { - if (DBG) { - Log.d(TAG, "Publishing layers availability change: " + availableLayers); - } - - Set<IVmsSubscriberClient> subscribers; - synchronized (mSubscriberServiceLock) { - subscribers = new HashSet<>(mSubscribersManager.getListeners()); - } - - for (IVmsSubscriberClient subscriber : subscribers) { - try { - subscriber.onLayersAvailabilityChanged(availableLayers); - } catch (RemoteException e) { - // If we could not send a record, its likely the connection snapped. Let the binder - // death handle the situation. - Log.e(TAG, "onLayersAvailabilityChanged calling failed: ", e); - } - } - } -} diff --git a/service/src/com/android/car/hal/VehicleHal.java b/service/src/com/android/car/hal/VehicleHal.java index 21f8f51183..44c81d7f88 100644 --- a/service/src/com/android/car/hal/VehicleHal.java +++ b/service/src/com/android/car/hal/VehicleHal.java @@ -80,8 +80,6 @@ public class VehicleHal extends IVehicleCallback.Stub { private final VendorExtensionHalService mVendorExtensionHal; private DiagnosticHalService mDiagnosticHal = null; - @FutureFeature - private VmsHalService mVmsHal; /** Might be re-assigned if Vehicle HAL is reconnected. */ @@ -108,9 +106,6 @@ public class VehicleHal extends IVehicleCallback.Stub { mHvacHal = new HvacHalService(this); mInputHal = new InputHalService(this); mVendorExtensionHal = new VendorExtensionHalService(this); - if (FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE) { - mVmsHal = new VmsHalService(this); - } mDiagnosticHal = new DiagnosticHalService(this); mAllServices.addAll(Arrays.asList(mPowerHal, mSensorHal, @@ -122,9 +117,6 @@ public class VehicleHal extends IVehicleCallback.Stub { mInputHal, mVendorExtensionHal, mDiagnosticHal)); - if (FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE) { - mAllServices.add(mVmsHal); - } mHalClient = new HalClient(vehicle, mHandlerThread.getLooper(), this /*IVehicleCallback*/); } @@ -146,10 +138,6 @@ public class VehicleHal extends IVehicleCallback.Stub { mVendorExtensionHal = null; mDiagnosticHal = null; - if (FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE) { - mVmsHal = null; - } - mHalClient = halClient; } @@ -169,7 +157,6 @@ public class VehicleHal extends IVehicleCallback.Stub { mHvacHal = hvacHal; mInputHal = null; mVendorExtensionHal = null; - mVmsHal = null; mHalClient = halClient; mDiagnosticHal = diagnosticHal; } @@ -281,9 +268,6 @@ public class VehicleHal extends IVehicleCallback.Stub { return mVendorExtensionHal; } - @FutureFeature - public VmsHalService getVmsHal() { return mVmsHal; } - private void assertServiceOwnerLocked(HalServiceBase service, int property) { if (service != mPropertyHandlers.get(property)) { throw new IllegalArgumentException("Property 0x" + toHexString(property) diff --git a/service/src/com/android/car/hal/VmsHalService.java b/service/src/com/android/car/hal/VmsHalService.java deleted file mode 100644 index d20a453fe6..0000000000 --- a/service/src/com/android/car/hal/VmsHalService.java +++ /dev/null @@ -1,850 +0,0 @@ -/* - * 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 com.android.car.hal; - -import static com.android.car.CarServiceUtils.toByteArray; -import static java.lang.Integer.toHexString; - -import android.car.VehicleAreaType; -import android.car.annotation.FutureFeature; -import android.car.vms.IVmsSubscriberClient; -import android.car.vms.VmsLayer; -import android.car.vms.VmsAssociatedLayer; -import android.car.vms.VmsLayerDependency; -import android.car.vms.VmsLayersOffering; -import android.car.vms.VmsOperationRecorder; -import android.car.vms.VmsSubscriptionState; -import android.hardware.automotive.vehicle.V2_0.VehiclePropConfig; -import android.hardware.automotive.vehicle.V2_0.VehiclePropValue; -import android.hardware.automotive.vehicle.V2_0.VehicleProperty; -import android.hardware.automotive.vehicle.V2_0.VmsBaseMessageIntegerValuesIndex; -import android.hardware.automotive.vehicle.V2_0.VmsMessageType; -import android.hardware.automotive.vehicle.V2_0.VmsMessageWithLayerAndPublisherIdIntegerValuesIndex; -import android.hardware.automotive.vehicle.V2_0.VmsOfferingMessageIntegerValuesIndex; -import android.hardware.automotive.vehicle.V2_0.VmsMessageWithLayerIntegerValuesIndex; -import android.os.Binder; -import android.os.IBinder; -import android.util.Log; -import com.android.car.CarLog; -import com.android.car.VmsLayersAvailability; -import com.android.car.VmsPublishersInfo; -import com.android.car.VmsRouting; -import com.android.internal.annotations.GuardedBy; - -import java.io.PrintWriter; -import java.util.Arrays; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.CopyOnWriteArrayList; - -/** - * This is a glue layer between the VehicleHal and the VmsService. It sends VMS properties back and - * forth. - */ -@FutureFeature -public class VmsHalService extends HalServiceBase { - - private static final boolean DBG = true; - private static final int HAL_PROPERTY_ID = VehicleProperty.VEHICLE_MAP_SERVICE; - private static final String TAG = "VmsHalService"; - - private final static List<Integer> AVAILABILITY_MESSAGE_TYPES = Collections.unmodifiableList( - Arrays.asList( - VmsMessageType.AVAILABILITY_RESPONSE, - VmsMessageType.AVAILABILITY_CHANGE)); - - private boolean mIsSupported = false; - private CopyOnWriteArrayList<VmsHalPublisherListener> mPublisherListeners = - new CopyOnWriteArrayList<>(); - private CopyOnWriteArrayList<VmsHalSubscriberListener> mSubscriberListeners = - new CopyOnWriteArrayList<>(); - - private final IBinder mHalPublisherToken = new Binder(); - private final VehicleHal mVehicleHal; - - private final Object mLock = new Object(); - private final VmsRouting mRouting = new VmsRouting(); - @GuardedBy("mLock") - private final Map<IBinder, VmsLayersOffering> mOfferings = new HashMap<>(); - @GuardedBy("mLock") - private final VmsLayersAvailability mAvailableLayers = new VmsLayersAvailability(); - private final VmsPublishersInfo mPublishersInfo = new VmsPublishersInfo(); - - /** - * The VmsPublisherService implements this interface to receive data from the HAL. - */ - public interface VmsHalPublisherListener { - void onChange(VmsSubscriptionState subscriptionState); - } - - /** - * The VmsSubscriberService implements this interface to receive data from the HAL. - */ - public interface VmsHalSubscriberListener { - // Notifies the listener on a data Message from a publisher. - void onDataMessage(VmsLayer layer, int publisherId, byte[] payload); - - // Notifies the listener on a change in available layers. - void onLayersAvaiabilityChange(List<VmsAssociatedLayer> availableLayers); - } - - /** - * The VmsService implements this interface to receive data from the HAL. - */ - protected VmsHalService(VehicleHal vehicleHal) { - mVehicleHal = vehicleHal; - if (DBG) { - Log.d(TAG, "started VmsHalService!"); - } - } - - public void addPublisherListener(VmsHalPublisherListener listener) { - mPublisherListeners.add(listener); - } - - public void addSubscriberListener(VmsHalSubscriberListener listener) { - mSubscriberListeners.add(listener); - } - - public void removePublisherListener(VmsHalPublisherListener listener) { - mPublisherListeners.remove(listener); - } - - public void removeSubscriberListener(VmsHalSubscriberListener listener) { - mSubscriberListeners.remove(listener); - } - - public void addSubscription(IVmsSubscriberClient listener, VmsLayer layer) { - boolean firstSubscriptionForLayer = false; - synchronized (mLock) { - // Check if publishers need to be notified about this change in subscriptions. - firstSubscriptionForLayer = !mRouting.hasLayerSubscriptions(layer); - - // Add the listeners subscription to the layer - mRouting.addSubscription(listener, layer); - } - if (firstSubscriptionForLayer) { - notifyHalPublishers(layer, true); - notifyClientPublishers(); - } - } - - public void removeSubscription(IVmsSubscriberClient listener, VmsLayer layer) { - boolean layerHasSubscribers = true; - synchronized (mLock) { - if (!mRouting.hasLayerSubscriptions(layer)) { - Log.i(TAG, "Trying to remove a layer with no subscription: " + layer); - return; - } - - // Remove the listeners subscription to the layer - mRouting.removeSubscription(listener, layer); - - // Check if publishers need to be notified about this change in subscriptions. - layerHasSubscribers = mRouting.hasLayerSubscriptions(layer); - } - if (!layerHasSubscribers) { - notifyHalPublishers(layer, false); - notifyClientPublishers(); - } - } - - public void addSubscription(IVmsSubscriberClient listener) { - synchronized (mLock) { - mRouting.addSubscription(listener); - } - } - - public void removeSubscription(IVmsSubscriberClient listener) { - synchronized (mLock) { - mRouting.removeSubscription(listener); - } - } - - public void addSubscription(IVmsSubscriberClient listener, VmsLayer layer, int publisherId) { - boolean firstSubscriptionForLayer = false; - synchronized (mLock) { - // Check if publishers need to be notified about this change in subscriptions. - firstSubscriptionForLayer = !(mRouting.hasLayerSubscriptions(layer) || - mRouting.hasLayerFromPublisherSubscriptions(layer, publisherId)); - - // Add the listeners subscription to the layer - mRouting.addSubscription(listener, layer, publisherId); - } - if (firstSubscriptionForLayer) { - notifyHalPublishers(layer, true); - notifyClientPublishers(); - } - } - - public void removeSubscription(IVmsSubscriberClient listener, VmsLayer layer, int publisherId) { - boolean layerHasSubscribers = true; - synchronized (mLock) { - if (!mRouting.hasLayerFromPublisherSubscriptions(layer, publisherId)) { - Log.i(TAG, "Trying to remove a layer with no subscription: " + - layer + ", publisher ID:" + publisherId); - return; - } - - // Remove the listeners subscription to the layer - mRouting.removeSubscription(listener, layer, publisherId); - - // Check if publishers need to be notified about this change in subscriptions. - layerHasSubscribers = mRouting.hasLayerSubscriptions(layer) || - mRouting.hasLayerFromPublisherSubscriptions(layer, publisherId); - } - if (!layerHasSubscribers) { - notifyHalPublishers(layer, false); - notifyClientPublishers(); - } - } - - public void removeDeadSubscriber(IVmsSubscriberClient listener) { - synchronized (mLock) { - mRouting.removeDeadSubscriber(listener); - } - } - - public Set<IVmsSubscriberClient> getSubscribersForLayerFromPublisher(VmsLayer layer, - int publisherId) { - synchronized (mLock) { - return mRouting.getSubscribersForLayerFromPublisher(layer, publisherId); - } - } - - public Set<IVmsSubscriberClient> getAllSubscribers() { - synchronized (mLock) { - return mRouting.getAllSubscribers(); - } - } - - public boolean isHalSubscribed(VmsLayer layer) { - synchronized (mLock) { - return mRouting.isHalSubscribed(layer); - } - } - - public VmsSubscriptionState getSubscriptionState() { - synchronized (mLock) { - return mRouting.getSubscriptionState(); - } - } - - /** - * Assigns an idempotent ID for publisherInfo and stores it. The idempotency in this case means - * that the same publisherInfo will always, within a trip of the vehicle, return the same ID. - * The publisherInfo should be static for a binary and should only change as part of a software - * update. The publisherInfo is a serialized proto message which VMS clients can interpret. - */ - public int getPublisherId(byte[] publisherInfo) { - if (DBG) { - Log.i(TAG, "Getting publisher static ID"); - } - synchronized (mLock) { - return mPublishersInfo.getIdForInfo(publisherInfo); - } - } - - public byte[] getPublisherInfo(int publisherId) { - if (DBG) { - Log.i(TAG, "Getting information for publisher ID: " + publisherId); - } - synchronized (mLock) { - return mPublishersInfo.getPublisherInfo(publisherId); - } - } - - private void addHalSubscription(VmsLayer layer) { - boolean firstSubscriptionForLayer = true; - synchronized (mLock) { - // Check if publishers need to be notified about this change in subscriptions. - firstSubscriptionForLayer = !mRouting.hasLayerSubscriptions(layer); - - // Add the listeners subscription to the layer - mRouting.addHalSubscription(layer); - } - if (firstSubscriptionForLayer) { - notifyHalPublishers(layer, true); - notifyClientPublishers(); - } - } - - private void addHalSubscriptionToPublisher(VmsLayer layer, int publisherId) { - boolean firstSubscriptionForLayer = true; - synchronized (mLock) { - // Check if publishers need to be notified about this change in subscriptions. - firstSubscriptionForLayer = !(mRouting.hasLayerSubscriptions(layer) || - mRouting.hasLayerFromPublisherSubscriptions(layer, publisherId)); - - // Add the listeners subscription to the layer - mRouting.addHalSubscriptionToPublisher(layer, publisherId); - } - if (firstSubscriptionForLayer) { - notifyHalPublishers(layer, publisherId, true); - notifyClientPublishers(); - } - } - - private void removeHalSubscription(VmsLayer layer) { - boolean layerHasSubscribers = true; - synchronized (mLock) { - if (!mRouting.hasLayerSubscriptions(layer)) { - Log.i(TAG, "Trying to remove a layer with no subscription: " + layer); - return; - } - - // Remove the listeners subscription to the layer - mRouting.removeHalSubscription(layer); - - // Check if publishers need to be notified about this change in subscriptions. - layerHasSubscribers = mRouting.hasLayerSubscriptions(layer); - } - if (!layerHasSubscribers) { - notifyHalPublishers(layer, false); - notifyClientPublishers(); - } - } - - public void removeHalSubscriptionFromPublisher(VmsLayer layer, int publisherId) { - boolean layerHasSubscribers = true; - synchronized (mLock) { - if (!mRouting.hasLayerSubscriptions(layer)) { - Log.i(TAG, "Trying to remove a layer with no subscription: " + layer); - return; - } - - // Remove the listeners subscription to the layer - mRouting.removeHalSubscriptionToPublisher(layer, publisherId); - - // Check if publishers need to be notified about this change in subscriptions. - layerHasSubscribers = mRouting.hasLayerSubscriptions(layer) || - mRouting.hasLayerFromPublisherSubscriptions(layer, publisherId); - } - if (!layerHasSubscribers) { - notifyHalPublishers(layer, publisherId, false); - notifyClientPublishers(); - } - } - - public boolean containsSubscriber(IVmsSubscriberClient subscriber) { - synchronized (mLock) { - return mRouting.containsSubscriber(subscriber); - } - } - - public void setPublisherLayersOffering(IBinder publisherToken, VmsLayersOffering offering) { - Set<VmsAssociatedLayer> availableLayers = Collections.EMPTY_SET; - synchronized (mLock) { - updateOffering(publisherToken, offering); - VmsOperationRecorder.get().setPublisherLayersOffering(offering); - availableLayers = mAvailableLayers.getAvailableLayers(); - } - notifyOfAvailabilityChange(availableLayers); - } - - public Set<VmsAssociatedLayer> getAvailableLayers() { - //TODO(b/36872877): wrap available layers in VmsAvailabilityState similar to VmsSubscriptionState. - synchronized (mLock) { - return mAvailableLayers.getAvailableLayers(); - } - } - - /** - * Notify all the publishers and the HAL on subscription changes regardless of who triggered - * the change. - * - * @param layer layer which is being subscribed to or unsubscribed from. - * @param hasSubscribers indicates if the notification is for subscription or unsubscription. - */ - private void notifyHalPublishers(VmsLayer layer, boolean hasSubscribers) { - // notify the HAL - setSubscriptionRequest(layer, hasSubscribers); - } - - private void notifyHalPublishers(VmsLayer layer, int publisherId, boolean hasSubscribers) { - // notify the HAL - setSubscriptionToPublisherRequest(layer, publisherId, hasSubscribers); - } - - private void notifyClientPublishers() { - // Notify the App publishers - for (VmsHalPublisherListener listener : mPublisherListeners) { - // Besides the list of layers, also a timestamp is provided to the clients. - // They should ignore any notification with a timestamp that is older than the most - // recent timestamp they have seen. - listener.onChange(getSubscriptionState()); - } - } - - /** - * Notify all the subscribers and the HAL on layers availability change. - * - * @param availableLayers the layers which publishers claim they made publish. - */ - private void notifyOfAvailabilityChange(Set<VmsAssociatedLayer> availableLayers) { - // notify the HAL - notifyAvailabilityChangeToHal(availableLayers); - - // Notify the App subscribers - for (VmsHalSubscriberListener listener : mSubscriberListeners) { - listener.onLayersAvaiabilityChange(new ArrayList<>(availableLayers)); - } - } - - @Override - public void init() { - if (DBG) { - Log.d(TAG, "init()"); - } - if (mIsSupported) { - mVehicleHal.subscribeProperty(this, HAL_PROPERTY_ID); - } - } - - @Override - public void release() { - if (DBG) { - Log.d(TAG, "release()"); - } - if (mIsSupported) { - mVehicleHal.unsubscribeProperty(this, HAL_PROPERTY_ID); - } - mPublisherListeners.clear(); - mSubscriberListeners.clear(); - } - - @Override - public Collection<VehiclePropConfig> takeSupportedProperties( - Collection<VehiclePropConfig> allProperties) { - List<VehiclePropConfig> taken = new LinkedList<>(); - for (VehiclePropConfig p : allProperties) { - if (p.prop == HAL_PROPERTY_ID) { - taken.add(p); - mIsSupported = true; - if (DBG) { - Log.d(TAG, "takeSupportedProperties: " + toHexString(p.prop)); - } - break; - } - } - return taken; - } - - /** - * Consumes/produces HAL messages. The format of these messages is defined in: - * hardware/interfaces/automotive/vehicle/2.1/types.hal - */ - @Override - public void handleHalEvents(List<VehiclePropValue> values) { - if (DBG) { - Log.d(TAG, "Handling a VMS property change"); - } - for (VehiclePropValue v : values) { - ArrayList<Integer> vec = v.value.int32Values; - int messageType = vec.get(VmsBaseMessageIntegerValuesIndex.MESSAGE_TYPE); - - if (DBG) { - Log.d(TAG, "Handling VMS message type: " + messageType); - } - switch (messageType) { - case VmsMessageType.DATA: - handleDataEvent(vec, toByteArray(v.value.bytes)); - break; - case VmsMessageType.SUBSCRIBE: - handleSubscribeEvent(vec); - break; - case VmsMessageType.UNSUBSCRIBE: - handleUnsubscribeEvent(vec); - break; - case VmsMessageType.SUBSCRIBE_TO_PUBLISHER: - handleSubscribeToPublisherEvent(vec); - break; - case VmsMessageType.UNSUBSCRIBE_TO_PUBLISHER: - handleUnsubscribeFromPublisherEvent(vec); - break; - case VmsMessageType.OFFERING: - handleOfferingEvent(vec); - break; - case VmsMessageType.AVAILABILITY_REQUEST: - handleHalAvailabilityRequestEvent(); - break; - case VmsMessageType.SUBSCRIPTIONS_REQUEST: - handleSubscriptionRequestEvent(); - break; - default: - throw new IllegalArgumentException("Unexpected message type: " + messageType); - } - } - } - - private VmsLayer parseVmsLayerFromSimpleMessageIntegerValues(List<Integer> integerValues) { - return new VmsLayer(integerValues.get(VmsMessageWithLayerIntegerValuesIndex.LAYER_TYPE), - integerValues.get(VmsMessageWithLayerIntegerValuesIndex.LAYER_SUBTYPE), - integerValues.get(VmsMessageWithLayerIntegerValuesIndex.LAYER_VERSION)); - } - - private VmsLayer parseVmsLayerFromDataMessageIntegerValues(List<Integer> integerValues) { - return parseVmsLayerFromSimpleMessageIntegerValues(integerValues); - } - - private int parsePublisherIdFromDataMessageIntegerValues(List<Integer> integerValues) { - return integerValues.get(VmsMessageWithLayerAndPublisherIdIntegerValuesIndex.PUBLISHER_ID); - } - - - /** - * Data message format: - * <ul> - * <li>Message type. - * <li>Layer id. - * <li>Layer version. - * <li>Layer subtype. - * <li>Publisher ID. - * <li>Payload. - * </ul> - */ - private void handleDataEvent(List<Integer> integerValues, byte[] payload) { - VmsLayer vmsLayer = parseVmsLayerFromDataMessageIntegerValues(integerValues); - int publisherId = parsePublisherIdFromDataMessageIntegerValues(integerValues); - if (DBG) { - Log.d(TAG, "Handling a data event for Layer: " + vmsLayer); - } - - // Send the message. - for (VmsHalSubscriberListener listener : mSubscriberListeners) { - listener.onDataMessage(vmsLayer, publisherId, payload); - } - } - - /** - * Subscribe message format: - * <ul> - * <li>Message type. - * <li>Layer id. - * <li>Layer version. - * <li>Layer subtype. - * </ul> - */ - private void handleSubscribeEvent(List<Integer> integerValues) { - VmsLayer vmsLayer = parseVmsLayerFromSimpleMessageIntegerValues(integerValues); - if (DBG) { - Log.d(TAG, "Handling a subscribe event for Layer: " + vmsLayer); - } - addHalSubscription(vmsLayer); - } - - /** - * Subscribe message format: - * <ul> - * <li>Message type. - * <li>Layer id. - * <li>Layer version. - * <li>Layer subtype. - * <li>Publisher ID - * </ul> - */ - private void handleSubscribeToPublisherEvent(List<Integer> integerValues) { - VmsLayer vmsLayer = parseVmsLayerFromSimpleMessageIntegerValues(integerValues); - if (DBG) { - Log.d(TAG, "Handling a subscribe event for Layer: " + vmsLayer); - } - int publisherId = - integerValues.get(VmsMessageWithLayerAndPublisherIdIntegerValuesIndex.PUBLISHER_ID); - addHalSubscriptionToPublisher(vmsLayer, publisherId); - } - - /** - * Unsubscribe message format: - * <ul> - * <li>Message type. - * <li>Layer id. - * <li>Layer version. - * </ul> - */ - private void handleUnsubscribeEvent(List<Integer> integerValues) { - VmsLayer vmsLayer = parseVmsLayerFromSimpleMessageIntegerValues(integerValues); - if (DBG) { - Log.d(TAG, "Handling an unsubscribe event for Layer: " + vmsLayer); - } - removeHalSubscription(vmsLayer); - } - - /** - * Unsubscribe message format: - * <ul> - * <li>Message type. - * <li>Layer id. - * <li>Layer version. - * </ul> - */ - private void handleUnsubscribeFromPublisherEvent(List<Integer> integerValues) { - VmsLayer vmsLayer = parseVmsLayerFromSimpleMessageIntegerValues(integerValues); - int publisherId = - integerValues.get(VmsMessageWithLayerAndPublisherIdIntegerValuesIndex.PUBLISHER_ID); - if (DBG) { - Log.d(TAG, "Handling an unsubscribe event for Layer: " + vmsLayer); - } - removeHalSubscriptionFromPublisher(vmsLayer, publisherId); - } - - private static int NUM_INTEGERS_IN_VMS_LAYER = 3; - - private VmsLayer parseVmsLayerFromIndex(List<Integer> integerValues, int index) { - int layerType = integerValues.get(index++); - int layerSutype = integerValues.get(index++); - int layerVersion = integerValues.get(index++); - return new VmsLayer(layerType, layerSutype, layerVersion); - } - - /** - * Offering message format: - * <ul> - * <li>Message type. - * <li>Publisher ID. - * <li>Number of offerings. - * <li>Each offering consists of: - * <ul> - * <li>Layer id. - * <li>Layer version. - * <li>Number of layer dependencies. - * <li>Layer type/subtype/version. - * </ul> - * </ul> - */ - private void handleOfferingEvent(List<Integer> integerValues) { - int publisherId = integerValues.get(VmsOfferingMessageIntegerValuesIndex.PUBLISHER_ID); - int numLayersDependencies = - integerValues.get( - VmsOfferingMessageIntegerValuesIndex.NUMBER_OF_OFFERS); - int idx = VmsOfferingMessageIntegerValuesIndex.OFFERING_START; - - Set<VmsLayerDependency> offeredLayers = new HashSet<>(); - - // An offering is layerId, LayerVersion, LayerType, NumDeps, <LayerId, LayerVersion> X NumDeps. - for (int i = 0; i < numLayersDependencies; i++) { - VmsLayer offeredLayer = parseVmsLayerFromIndex(integerValues, idx); - idx += NUM_INTEGERS_IN_VMS_LAYER; - - int numDependenciesForLayer = integerValues.get(idx++); - if (numDependenciesForLayer == 0) { - offeredLayers.add(new VmsLayerDependency(offeredLayer)); - } else { - Set<VmsLayer> dependencies = new HashSet<>(); - - for (int j = 0; j < numDependenciesForLayer; j++) { - VmsLayer dependantLayer = parseVmsLayerFromIndex(integerValues, idx); - idx += NUM_INTEGERS_IN_VMS_LAYER; - dependencies.add(dependantLayer); - } - offeredLayers.add(new VmsLayerDependency(offeredLayer, dependencies)); - } - } - // Store the HAL offering. - VmsLayersOffering offering = new VmsLayersOffering(offeredLayers, publisherId); - synchronized (mLock) { - updateOffering(mHalPublisherToken, offering); - VmsOperationRecorder.get().setHalPublisherLayersOffering(offering); - } - } - - /** - * Availability message format: - * <ul> - * <li>Message type. - * <li>Number of layers. - * <li>Layer type/subtype/version. - * </ul> - */ - private void handleHalAvailabilityRequestEvent() { - synchronized (mLock) { - Collection<VmsAssociatedLayer> availableLayers = mAvailableLayers.getAvailableLayers(); - VehiclePropValue vehiclePropertyValue = - toAvailabilityUpdateVehiclePropValue( - availableLayers, - VmsMessageType.AVAILABILITY_RESPONSE); - - setPropertyValue(vehiclePropertyValue); - } - } - - /** - * VmsSubscriptionRequestFormat: - * <ul> - * <li>Message type. - * </ul> - * <p> - * VmsSubscriptionResponseFormat: - * <ul> - * <li>Message type. - * <li>Sequence number. - * <li>Number of layers. - * <li>Layer type/subtype/version. - * </ul> - */ - private void handleSubscriptionRequestEvent() { - VmsSubscriptionState subscription = getSubscriptionState(); - VehiclePropValue vehicleProp = - toTypedVmsVehiclePropValue(VmsMessageType.SUBSCRIPTIONS_RESPONSE); - VehiclePropValue.RawValue v = vehicleProp.value; - v.int32Values.add(subscription.getSequenceNumber()); - Set<VmsLayer> layers = subscription.getLayers(); - v.int32Values.add(layers.size()); - - //TODO(asafro): get the real number of associated layers in the subscriptions - // state and send the associated layers themselves. - v.int32Values.add(0); - - for (VmsLayer layer : layers) { - v.int32Values.add(layer.getType()); - v.int32Values.add(layer.getSubtype()); - v.int32Values.add(layer.getVersion()); - } - setPropertyValue(vehicleProp); - } - - private void updateOffering(IBinder publisherToken, VmsLayersOffering offering) { - Set<VmsAssociatedLayer> availableLayers = Collections.EMPTY_SET; - synchronized (mLock) { - mOfferings.put(publisherToken, offering); - - // Update layers availability. - mAvailableLayers.setPublishersOffering(mOfferings.values()); - - availableLayers = mAvailableLayers.getAvailableLayers(); - } - notifyOfAvailabilityChange(availableLayers); - } - - @Override - public void dump(PrintWriter writer) { - writer.println(TAG); - writer.println("VmsProperty " + (mIsSupported ? "" : "not") + " supported."); - } - - /** - * Updates the VMS HAL property with the given value. - * - * @param layer layer data to update the hal property. - * @param hasSubscribers if it is a subscribe or unsubscribe message. - * @return true if the call to the HAL to update the property was successful. - */ - public boolean setSubscriptionRequest(VmsLayer layer, boolean hasSubscribers) { - VehiclePropValue vehiclePropertyValue = toTypedVmsVehiclePropValueWithLayer( - hasSubscribers ? VmsMessageType.SUBSCRIBE : VmsMessageType.UNSUBSCRIBE, layer); - return setPropertyValue(vehiclePropertyValue); - } - - public boolean setSubscriptionToPublisherRequest(VmsLayer layer, - int publisherId, - boolean hasSubscribers) { - VehiclePropValue vehiclePropertyValue = toTypedVmsVehiclePropValueWithLayer( - hasSubscribers ? - VmsMessageType.SUBSCRIBE_TO_PUBLISHER : - VmsMessageType.UNSUBSCRIBE_TO_PUBLISHER, layer); - vehiclePropertyValue.value.int32Values.add(publisherId); - return setPropertyValue(vehiclePropertyValue); - } - - public boolean setDataMessage(VmsLayer layer, byte[] payload) { - VehiclePropValue vehiclePropertyValue = - toTypedVmsVehiclePropValueWithLayer(VmsMessageType.DATA, layer); - VehiclePropValue.RawValue v = vehiclePropertyValue.value; - v.bytes.ensureCapacity(payload.length); - for (byte b : payload) { - v.bytes.add(b); - } - return setPropertyValue(vehiclePropertyValue); - } - - public boolean notifyAvailabilityChangeToHal(Collection<VmsAssociatedLayer> availableLayers) { - VehiclePropValue vehiclePropertyValue = - toAvailabilityUpdateVehiclePropValue( - availableLayers, - VmsMessageType.AVAILABILITY_CHANGE); - - return setPropertyValue(vehiclePropertyValue); - } - - public boolean setPropertyValue(VehiclePropValue vehiclePropertyValue) { - try { - mVehicleHal.set(vehiclePropertyValue); - return true; - } catch (PropertyTimeoutException e) { - Log.e(CarLog.TAG_PROPERTY, "set, property not ready 0x" + toHexString(HAL_PROPERTY_ID)); - } - return false; - } - - private static VehiclePropValue toTypedVmsVehiclePropValue(int messageType) { - VehiclePropValue vehicleProp = new VehiclePropValue(); - vehicleProp.prop = HAL_PROPERTY_ID; - vehicleProp.areaId = VehicleAreaType.VEHICLE_AREA_TYPE_NONE; - VehiclePropValue.RawValue v = vehicleProp.value; - - v.int32Values.add(messageType); - return vehicleProp; - } - - /** - * Creates a {@link VehiclePropValue} - */ - private static VehiclePropValue toTypedVmsVehiclePropValueWithLayer( - int messageType, VmsLayer layer) { - VehiclePropValue vehicleProp = toTypedVmsVehiclePropValue(messageType); - VehiclePropValue.RawValue v = vehicleProp.value; - v.int32Values.add(layer.getType()); - v.int32Values.add(layer.getSubtype()); - v.int32Values.add(layer.getVersion()); - return vehicleProp; - } - - private static VehiclePropValue toAvailabilityUpdateVehiclePropValue( - Collection<VmsAssociatedLayer> availableAssociatedLayers, int messageType) { - - if (!AVAILABILITY_MESSAGE_TYPES.contains(messageType)) { - throw new IllegalArgumentException("Unsupported availability type: " + messageType); - } - VehiclePropValue vehicleProp = - toTypedVmsVehiclePropValue(messageType); - populateAvailabilityPropValueFields(availableAssociatedLayers, vehicleProp); - return vehicleProp; - - } - - private static void populateAvailabilityPropValueFields( - Collection<VmsAssociatedLayer> availableAssociatedLayers, - VehiclePropValue vehicleProp) { - VehiclePropValue.RawValue v = vehicleProp.value; - int numLayers = availableAssociatedLayers.size(); - v.int32Values.add(numLayers); - for (VmsAssociatedLayer layer : availableAssociatedLayers) { - v.int32Values.add(layer.getVmsLayer().getType()); - v.int32Values.add(layer.getVmsLayer().getSubtype()); - v.int32Values.add(layer.getVmsLayer().getVersion()); - v.int32Values.add(layer.getPublisherIds().size()); - for (int publisherId : layer.getPublisherIds()) { - v.int32Values.add(publisherId); - } - } - } -} diff --git a/tests/VmsPublisherClientSample/Android.mk b/tests/VmsPublisherClientSample/Android.mk deleted file mode 100644 index 2aa6c40194..0000000000 --- a/tests/VmsPublisherClientSample/Android.mk +++ /dev/null @@ -1,37 +0,0 @@ -# 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. -# -# - -LOCAL_PATH:= $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_SRC_FILES := $(call all-java-files-under, src) - -LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res - -LOCAL_PACKAGE_NAME := VmsPublisherClientSample - -LOCAL_MODULE_TAGS := optional - -LOCAL_PRIVILEGED_MODULE := true - -LOCAL_CERTIFICATE := testkey - -LOCAL_PROGUARD_ENABLED := disabled - -LOCAL_JAVA_LIBRARIES += android.car - -include $(BUILD_PACKAGE)
\ No newline at end of file diff --git a/tests/VmsPublisherClientSample/AndroidManifest.xml b/tests/VmsPublisherClientSample/AndroidManifest.xml deleted file mode 100644 index fdc1a318f3..0000000000 --- a/tests/VmsPublisherClientSample/AndroidManifest.xml +++ /dev/null @@ -1,34 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- 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. ---> - -<manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.google.android.car.vms.publisher"> - - <uses-permission android:name="android.car.permission.VMS_PUBLISHER" /> - <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> - <uses-permission android:name="android.permission.CAMERA"/> - - <uses-sdk android:minSdkVersion="25" android:targetSdkVersion='25'/> - - <application android:label="@string/app_name" - android:icon="@mipmap/ic_launcher" - android:directBootAware="true"> - <service android:name=".VmsPublisherClientSampleService" - android:exported="true" - android:singleUser="true"> - </service> - </application> -</manifest> diff --git a/tests/VmsPublisherClientSample/res/mipmap-hdpi/ic_launcher.png b/tests/VmsPublisherClientSample/res/mipmap-hdpi/ic_launcher.png Binary files differdeleted file mode 100644 index cde69bccce..0000000000 --- a/tests/VmsPublisherClientSample/res/mipmap-hdpi/ic_launcher.png +++ /dev/null diff --git a/tests/VmsPublisherClientSample/res/mipmap-mdpi/ic_launcher.png b/tests/VmsPublisherClientSample/res/mipmap-mdpi/ic_launcher.png Binary files differdeleted file mode 100644 index c133a0cbd3..0000000000 --- a/tests/VmsPublisherClientSample/res/mipmap-mdpi/ic_launcher.png +++ /dev/null diff --git a/tests/VmsPublisherClientSample/res/mipmap-xhdpi/ic_launcher.png b/tests/VmsPublisherClientSample/res/mipmap-xhdpi/ic_launcher.png Binary files differdeleted file mode 100644 index bfa42f0e7b..0000000000 --- a/tests/VmsPublisherClientSample/res/mipmap-xhdpi/ic_launcher.png +++ /dev/null diff --git a/tests/VmsPublisherClientSample/res/mipmap-xxhdpi/ic_launcher.png b/tests/VmsPublisherClientSample/res/mipmap-xxhdpi/ic_launcher.png Binary files differdeleted file mode 100644 index 324e72cdd7..0000000000 --- a/tests/VmsPublisherClientSample/res/mipmap-xxhdpi/ic_launcher.png +++ /dev/null diff --git a/tests/VmsPublisherClientSample/res/mipmap-xxxhdpi/ic_launcher.png b/tests/VmsPublisherClientSample/res/mipmap-xxxhdpi/ic_launcher.png Binary files differdeleted file mode 100644 index aee44e1384..0000000000 --- a/tests/VmsPublisherClientSample/res/mipmap-xxxhdpi/ic_launcher.png +++ /dev/null diff --git a/tests/VmsPublisherClientSample/res/values/strings.xml b/tests/VmsPublisherClientSample/res/values/strings.xml deleted file mode 100644 index df8bf057af..0000000000 --- a/tests/VmsPublisherClientSample/res/values/strings.xml +++ /dev/null @@ -1,18 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- 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. ---> -<resources> - <string name="app_name">VmsPublisherClientSample</string> -</resources> diff --git a/tests/VmsPublisherClientSample/src/com/google/android/car/vms/publisher/VmsPublisherClientSampleService.java b/tests/VmsPublisherClientSample/src/com/google/android/car/vms/publisher/VmsPublisherClientSampleService.java deleted file mode 100644 index e235f1e923..0000000000 --- a/tests/VmsPublisherClientSample/src/com/google/android/car/vms/publisher/VmsPublisherClientSampleService.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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 com.google.android.car.vms.publisher; - -import android.car.vms.VmsLayer; -import android.car.vms.VmsPublisherClientService; -import android.car.vms.VmsSubscriptionState; -import android.os.Handler; -import android.os.Message; - -import java.util.concurrent.atomic.AtomicBoolean; - -/** - * This service is launched during the initialization of the VMS publisher service. - * Once onVmsPublisherServiceReady is invoked, it starts publishing a single byte every second. - */ -public class VmsPublisherClientSampleService extends VmsPublisherClientService { - public static final int PUBLISH_EVENT = 0; - public static final VmsLayer TEST_LAYER = new VmsLayer(0, 0, 0); - public static final int PUBLISHER_ID = 1; - - private byte mCounter = 0; - private AtomicBoolean mInitialized = new AtomicBoolean(false); - - private final Handler mHandler = new Handler() { - @Override - public void handleMessage(Message msg) { - if (msg.what == PUBLISH_EVENT && mInitialized.get()) { - periodicPublish(); - } - } - }; - - /** - * Notifies that the publisher services are ready to be used: {@link #publish(VmsLayer, byte[])} - * and {@link #getSubscriptions()}. - */ - @Override - public void onVmsPublisherServiceReady() { - VmsSubscriptionState subscriptionState = getSubscriptions(); - onVmsSubscriptionChange(subscriptionState); - } - - @Override - public void onVmsSubscriptionChange(VmsSubscriptionState subscriptionState) { - if (mInitialized.compareAndSet(false, true)) { - for (VmsLayer layer : subscriptionState.getLayers()) { - if (layer.equals(TEST_LAYER)) { - mHandler.sendEmptyMessage(PUBLISH_EVENT); - } - } - } - } - - @Override - public void onDestroy() { - super.onDestroy(); - mInitialized.set(false); - mHandler.removeMessages(PUBLISH_EVENT); - } - - private void periodicPublish() { - publish(TEST_LAYER, PUBLISHER_ID, new byte[]{mCounter}); - ++mCounter; - mHandler.sendEmptyMessageDelayed(PUBLISH_EVENT, 1000); - } -} diff --git a/tests/VmsSubscriberClientSample/Android.mk b/tests/VmsSubscriberClientSample/Android.mk deleted file mode 100644 index f59e26794f..0000000000 --- a/tests/VmsSubscriberClientSample/Android.mk +++ /dev/null @@ -1,39 +0,0 @@ -# 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. -# -# - -LOCAL_PATH:= $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_SRC_FILES := $(call all-java-files-under, src) - -LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res - -LOCAL_PACKAGE_NAME := VmsSubscriberClientSample - -LOCAL_MODULE_TAGS := optional - -LOCAL_PRIVILEGED_MODULE := true - -LOCAL_CERTIFICATE := platform - -LOCAL_PROGUARD_ENABLED := disabled - -LOCAL_JAVA_LIBRARIES += android.car - -include packages/services/Car/car-support-lib/car-support.mk - -include $(BUILD_PACKAGE)
\ No newline at end of file diff --git a/tests/VmsSubscriberClientSample/AndroidManifest.xml b/tests/VmsSubscriberClientSample/AndroidManifest.xml deleted file mode 100644 index bc798d774d..0000000000 --- a/tests/VmsSubscriberClientSample/AndroidManifest.xml +++ /dev/null @@ -1,35 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- 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. ---> - -<manifest xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:androidprv="http://schemas.android.com/apk/prv/res/android" - package="com.google.android.car.vms.subscriber" - android:sharedUserId="android.uid.system"> - <uses-sdk android:minSdkVersion="25" android:targetSdkVersion='25'/> - - <application android:label="@string/app_name" - android:icon="@mipmap/ic_launcher"> - <meta-data - android:name="android.car.application" - android:resource="@xml/automotive_app_desc"/> - <activity android:name=".VmsSubscriberClientSampleActivity"> - <intent-filter> - <action android:name="android.intent.action.MAIN"/> - <category android:name="android.intent.category.LAUNCHER"/> - </intent-filter> - </activity> - </application> -</manifest>
\ No newline at end of file diff --git a/tests/VmsSubscriberClientSample/res/layout/activity_main.xml b/tests/VmsSubscriberClientSample/res/layout/activity_main.xml deleted file mode 100644 index ce05a4d2ff..0000000000 --- a/tests/VmsSubscriberClientSample/res/layout/activity_main.xml +++ /dev/null @@ -1,20 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<RelativeLayout - xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:tools="http://schemas.android.com/tools" - android:id="@+id/activity_main" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:paddingTop="@dimen/activity_vertical_margin" - android:paddingBottom="@dimen/activity_vertical_margin" - android:paddingLeft="@dimen/activity_horizontal_margin" - android:paddingRight="@dimen/activity_horizontal_margin" - tools:context="vms.apps.android.google.com.java.myapplication.MainActivity"> - - <TextView - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:textAppearance="?android:attr/textAppearanceLarge" - android:text="" - android:id="@+id/textview"/> -</RelativeLayout> diff --git a/tests/VmsSubscriberClientSample/res/mipmap-hdpi/ic_launcher.png b/tests/VmsSubscriberClientSample/res/mipmap-hdpi/ic_launcher.png Binary files differdeleted file mode 100644 index cde69bccce..0000000000 --- a/tests/VmsSubscriberClientSample/res/mipmap-hdpi/ic_launcher.png +++ /dev/null diff --git a/tests/VmsSubscriberClientSample/res/mipmap-mdpi/ic_launcher.png b/tests/VmsSubscriberClientSample/res/mipmap-mdpi/ic_launcher.png Binary files differdeleted file mode 100644 index c133a0cbd3..0000000000 --- a/tests/VmsSubscriberClientSample/res/mipmap-mdpi/ic_launcher.png +++ /dev/null diff --git a/tests/VmsSubscriberClientSample/res/mipmap-xhdpi/ic_launcher.png b/tests/VmsSubscriberClientSample/res/mipmap-xhdpi/ic_launcher.png Binary files differdeleted file mode 100644 index bfa42f0e7b..0000000000 --- a/tests/VmsSubscriberClientSample/res/mipmap-xhdpi/ic_launcher.png +++ /dev/null diff --git a/tests/VmsSubscriberClientSample/res/mipmap-xxhdpi/ic_launcher.png b/tests/VmsSubscriberClientSample/res/mipmap-xxhdpi/ic_launcher.png Binary files differdeleted file mode 100644 index 324e72cdd7..0000000000 --- a/tests/VmsSubscriberClientSample/res/mipmap-xxhdpi/ic_launcher.png +++ /dev/null diff --git a/tests/VmsSubscriberClientSample/res/mipmap-xxxhdpi/ic_launcher.png b/tests/VmsSubscriberClientSample/res/mipmap-xxxhdpi/ic_launcher.png Binary files differdeleted file mode 100644 index aee44e1384..0000000000 --- a/tests/VmsSubscriberClientSample/res/mipmap-xxxhdpi/ic_launcher.png +++ /dev/null diff --git a/tests/VmsSubscriberClientSample/res/values-w820dp/dimens.xml b/tests/VmsSubscriberClientSample/res/values-w820dp/dimens.xml deleted file mode 100644 index 308a1947af..0000000000 --- a/tests/VmsSubscriberClientSample/res/values-w820dp/dimens.xml +++ /dev/null @@ -1,6 +0,0 @@ -<resources> - <!-- Example customization of dimensions originally defined in res/values/dimens.xml - (such as screen margins) for screens with more than 820dp of available width. This - would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). --> - <dimen name="activity_horizontal_margin">64dp</dimen> -</resources> diff --git a/tests/VmsSubscriberClientSample/res/values/colors.xml b/tests/VmsSubscriberClientSample/res/values/colors.xml deleted file mode 100644 index 5a077b3a78..0000000000 --- a/tests/VmsSubscriberClientSample/res/values/colors.xml +++ /dev/null @@ -1,6 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<resources> - <color name="colorPrimary">#3F51B5</color> - <color name="colorPrimaryDark">#303F9F</color> - <color name="colorAccent">#FF4081</color> -</resources> diff --git a/tests/VmsSubscriberClientSample/res/values/dimens.xml b/tests/VmsSubscriberClientSample/res/values/dimens.xml deleted file mode 100644 index acf94cc67b..0000000000 --- a/tests/VmsSubscriberClientSample/res/values/dimens.xml +++ /dev/null @@ -1,5 +0,0 @@ -<resources> - <!-- Default screen margins, per the Android Design guidelines. --> - <dimen name="activity_horizontal_margin">16dp</dimen> - <dimen name="activity_vertical_margin">16dp</dimen> -</resources> diff --git a/tests/VmsSubscriberClientSample/res/values/strings.xml b/tests/VmsSubscriberClientSample/res/values/strings.xml deleted file mode 100644 index 24df55ea7c..0000000000 --- a/tests/VmsSubscriberClientSample/res/values/strings.xml +++ /dev/null @@ -1,3 +0,0 @@ -<resources> - <string name="app_name">VmsSubscriberClientSample</string> -</resources> diff --git a/tests/VmsSubscriberClientSample/res/values/styles.xml b/tests/VmsSubscriberClientSample/res/values/styles.xml deleted file mode 100644 index a7a06158ff..0000000000 --- a/tests/VmsSubscriberClientSample/res/values/styles.xml +++ /dev/null @@ -1,8 +0,0 @@ -<resources> - - <!-- Base application theme. --> - <style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar"> - <!-- Customize your theme here. --> - </style> - -</resources> diff --git a/tests/VmsSubscriberClientSample/res/xml/automotive_app_desc.xml b/tests/VmsSubscriberClientSample/res/xml/automotive_app_desc.xml deleted file mode 100644 index b10ddd01c3..0000000000 --- a/tests/VmsSubscriberClientSample/res/xml/automotive_app_desc.xml +++ /dev/null @@ -1,20 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2015 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. ---> -<automotiveApp> - <uses name="service" /> - <uses name="projection" /> - <uses name="activity" class="com.google.android.car.vms.subscriber.VmsSubscriberClientSampleActivity" /> -</automotiveApp> diff --git a/tests/VmsSubscriberClientSample/src/com/google/android/car/vms/subscriber/VmsSubscriberClientSampleActivity.java b/tests/VmsSubscriberClientSample/src/com/google/android/car/vms/subscriber/VmsSubscriberClientSampleActivity.java deleted file mode 100644 index 3ac0707221..0000000000 --- a/tests/VmsSubscriberClientSample/src/com/google/android/car/vms/subscriber/VmsSubscriberClientSampleActivity.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * 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 com.google.android.car.vms.subscriber; - -import android.app.Activity; -import android.car.vms.VmsLayer; -import android.car.vms.VmsSubscriberManager; -import android.content.pm.PackageManager; -import android.os.Bundle; -import android.support.car.Car; -import android.support.car.CarConnectionCallback; -import android.util.Log; -import android.widget.TextView; - -import java.util.List; - -/** - * Connects to the Car service during onCreate. CarConnectionCallback.onConnected is invoked when - * the connection is ready. Then, it subscribes to a VMS layer/version and updates the TextView when - * a message is received. - */ -public class VmsSubscriberClientSampleActivity extends Activity { - private static final String TAG = "VmsSampleActivity"; - // The layer id and version should match the ones defined in - // com.google.android.car.vms.publisher.VmsPublisherClientSampleService - public static final VmsLayer TEST_LAYER = new VmsLayer(0, 0, 0); - - private Car mCarApi; - private TextView mTextView; - private VmsSubscriberManager mVmsSubscriberManager; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - mTextView = (TextView) findViewById(R.id.textview); - if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)) { - mCarApi = Car.createCar(this, mCarConnectionCallback); - mCarApi.connect(); - } else { - Log.d(TAG, "No automotive feature."); - } - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (mCarApi != null) { - mCarApi.disconnect(); - } - Log.i(TAG, "onDestroy"); - } - - private final CarConnectionCallback mCarConnectionCallback = new CarConnectionCallback() { - @Override - public void onConnected(Car car) { - Log.d(TAG, "Connected to Car Service"); - mVmsSubscriberManager = getVmsSubscriberManager(); - configureSubscriptions(mVmsSubscriberManager); - } - - @Override - public void onDisconnected(Car car) { - Log.d(TAG, "Disconnect from Car Service"); - } - - private VmsSubscriberManager getVmsSubscriberManager() { - try { - return (VmsSubscriberManager) mCarApi.getCarManager( - android.car.Car.VMS_SUBSCRIBER_SERVICE); - } catch (android.support.car.CarNotConnectedException e) { - Log.e(TAG, "Car is not connected!", e); - } - return null; - } - - private void configureSubscriptions(VmsSubscriberManager vmsSubscriberManager) { - try { - vmsSubscriberManager.registerClientCallback(mClientCallback); - vmsSubscriberManager.subscribe(TEST_LAYER); - } catch (android.car.CarNotConnectedException e) { - Log.e(TAG, "Car is not connected!", e); - } - } - }; - - private final VmsSubscriberManager.VmsSubscriberClientCallback mClientCallback = - new VmsSubscriberManager.VmsSubscriberClientCallback() { - @Override - public void onVmsMessageReceived(VmsLayer layer, byte[] payload) { - mTextView.setText(String.valueOf(payload[0])); - } - - @Override - public void onLayersAvailabilityChanged(List<VmsLayer> availableLayers) { - mTextView.setText(String.valueOf(availableLayers)); - } - }; -} diff --git a/tests/carservice_test/AndroidManifest.xml b/tests/carservice_test/AndroidManifest.xml index 6f7ba349aa..6a1e2bfcbf 100644 --- a/tests/carservice_test/AndroidManifest.xml +++ b/tests/carservice_test/AndroidManifest.xml @@ -43,9 +43,5 @@ android:process="com.android.car.carservicetest.activityC"/> <activity android:name="com.android.car.test.SystemActivityMonitoringServiceTest$BlockingActivity" android:taskAffinity="com.android.car.carservicetest.block"/> - <service android:name=".SimpleVmsPublisherClientService" - android:exported="true" - /> - <service android:name=".VmsPublisherClientMockService" android:exported="true" /> </application> </manifest> diff --git a/tests/carservice_test/src/com/android/car/test/SimpleVmsPublisherClientService.java b/tests/carservice_test/src/com/android/car/test/SimpleVmsPublisherClientService.java deleted file mode 100644 index c3c15f5ba3..0000000000 --- a/tests/carservice_test/src/com/android/car/test/SimpleVmsPublisherClientService.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 com.android.car.test; - -import android.car.annotation.FutureFeature; -import android.car.vms.VmsPublisherClientService; -import android.car.vms.VmsSubscriptionState; - -/** - * This service is launched during the tests in VmsPublisherClientServiceTest. - */ -@FutureFeature -public class SimpleVmsPublisherClientService extends VmsPublisherClientService { - @Override - public void onVmsSubscriptionChange(VmsSubscriptionState subscriptionState) { - - } - - @Override - public void onVmsPublisherServiceReady() { - // Publish a property that is going to be verified in the test. - publish(VmsPublisherClientServiceTest.MOCK_PUBLISHER_LAYER, - VmsPublisherClientServiceTest.MOCK_PUBLISHER_ID, - VmsPublisherClientServiceTest.PAYLOAD); - } -} diff --git a/tests/carservice_test/src/com/android/car/test/VmsHalServiceSubscriptionEventTest.java b/tests/carservice_test/src/com/android/car/test/VmsHalServiceSubscriptionEventTest.java deleted file mode 100644 index cad308606a..0000000000 --- a/tests/carservice_test/src/com/android/car/test/VmsHalServiceSubscriptionEventTest.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * 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 com.android.car.test; - -import static org.junit.Assume.assumeTrue; - -import android.car.VehicleAreaType; -import android.car.annotation.FutureFeature; -import android.car.vms.VmsLayer; -import android.hardware.automotive.vehicle.V2_0.VehiclePropValue; -import android.hardware.automotive.vehicle.V2_0.VehiclePropertyAccess; -import android.hardware.automotive.vehicle.V2_0.VehiclePropertyChangeMode; -import android.hardware.automotive.vehicle.V2_0.VehicleProperty; -import android.hardware.automotive.vehicle.V2_0.VmsMessageWithLayerIntegerValuesIndex; -import android.hardware.automotive.vehicle.V2_0.VmsMessageType; -import android.hardware.automotive.vehicle.V2_0.VmsSubscriptionsStateIntegerValuesIndex; -import android.test.suitebuilder.annotation.MediumTest; - -import com.android.car.vehiclehal.VehiclePropValueBuilder; -import com.android.car.vehiclehal.test.MockedVehicleHal; -import com.android.car.vehiclehal.test.MockedVehicleHal.VehicleHalPropertyHandler; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.concurrent.Semaphore; -import java.util.concurrent.TimeUnit; - -@FutureFeature -@MediumTest -public class VmsHalServiceSubscriptionEventTest extends MockedCarTestBase { - private static final String TAG = "VmsHalServiceTest"; - - private HalHandler mHalHandler; - private MockedVehicleHal mHal; - // Used to block until the HAL property is updated in HalHandler.onPropertySet. - private Semaphore mHalHandlerSemaphore; - - @Override - protected synchronized void configureMockedHal() { - mHalHandler = new HalHandler(); - addProperty(VehicleProperty.VEHICLE_MAP_SERVICE, mHalHandler) - .setChangeMode(VehiclePropertyChangeMode.ON_CHANGE) - .setAccess(VehiclePropertyAccess.READ_WRITE) - .setSupportedAreas(VehicleAreaType.VEHICLE_AREA_TYPE_NONE); - } - - @Override - protected void setUp() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - super.setUp(); - mHal = getMockedVehicleHal(); - mHalHandlerSemaphore = new Semaphore(0); - } - - @Override - protected synchronized void tearDown() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - super.tearDown(); - } - - public void testEmptySubscriptions() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - List<VmsLayer> layers = new ArrayList<>(); - subscriptionTestLogic(layers); - } - - public void testOneSubscription() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - List<VmsLayer> layers = Arrays.asList(new VmsLayer(8, 0, 3)); - subscriptionTestLogic(layers); - } - - public void testManySubscriptions() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - List<VmsLayer> layers = Arrays.asList( - new VmsLayer(8, 1, 3), - new VmsLayer(5, 2, 1), - new VmsLayer(3, 3, 9), - new VmsLayer(2, 4, 7), - new VmsLayer(9, 5, 3)); - subscriptionTestLogic(layers); - } - - /** - * First, it subscribes to the given layers. Then it validates that a subscription request - * responds with the same layers. - */ - private void subscriptionTestLogic(List<VmsLayer> layers) throws Exception { - for (VmsLayer layer : layers) { - subscribeViaHal(layer); - } - // Send subscription request. - mHal.injectEvent(createHalSubscriptionRequest()); - // Wait for response. - assertTrue(mHalHandlerSemaphore.tryAcquire(2L, TimeUnit.SECONDS)); - // Validate response. - ArrayList<Integer> v = mHalHandler.getValues(); - int messageType = v.get(VmsSubscriptionsStateIntegerValuesIndex.MESSAGE_TYPE); - int sequenceNumber = v.get(VmsSubscriptionsStateIntegerValuesIndex.SEQUENCE_NUMBER); - int numberLayers = v.get(VmsSubscriptionsStateIntegerValuesIndex.NUMBER_OF_LAYERS); - assertEquals(VmsMessageType.SUBSCRIPTIONS_RESPONSE, messageType); - //TODO(asafro): This assertion makes no sense. need to fix. - //assertEquals(layers.size(), sequenceNumber); - assertEquals(layers.size(), numberLayers); - List<VmsLayer> receivedLayers = new ArrayList<>(); - int start = VmsSubscriptionsStateIntegerValuesIndex.SUBSCRIPTIONS_START; - int end = VmsSubscriptionsStateIntegerValuesIndex.SUBSCRIPTIONS_START + 3 * numberLayers; - while (start < end) { - int type = v.get(start++); - int subtype = v.get(start++); - int version = v.get(start++); - receivedLayers.add(new VmsLayer(type, subtype, version)); - } - assertEquals(new HashSet<>(layers), new HashSet<>(receivedLayers)); - } - - /** - * Subscribes to a layer, waits for the event to propagate back to the HAL layer and validates - * the propagated message. - */ - private void subscribeViaHal(VmsLayer layer) throws Exception { - // Send subscribe request. - mHal.injectEvent(createHalSubscribeRequest(layer)); - // Wait for response. - assertTrue(mHalHandlerSemaphore.tryAcquire(2L, TimeUnit.SECONDS)); - // Validate response. - ArrayList<Integer> v = mHalHandler.getValues(); - int messsageType = v.get(VmsMessageWithLayerIntegerValuesIndex.MESSAGE_TYPE); - int layerId = v.get(VmsMessageWithLayerIntegerValuesIndex.LAYER_TYPE); - int layerVersion = v.get(VmsMessageWithLayerIntegerValuesIndex.LAYER_VERSION); - int fused = v.get(VmsMessageWithLayerIntegerValuesIndex.LAYER_SUBTYPE); - assertEquals(VmsMessageType.SUBSCRIBE, messsageType); - assertEquals(layer.getType(), layerId); - assertEquals(layer.getVersion(), layerVersion); - } - - private VehiclePropValue createHalSubscribeRequest(VmsLayer layer) { - return VehiclePropValueBuilder.newBuilder(VehicleProperty.VEHICLE_MAP_SERVICE) - .addIntValue(VmsMessageType.SUBSCRIBE) - .addIntValue(layer.getType()) - .addIntValue(layer.getSubtype()) - .addIntValue(layer.getVersion()) - .build(); - } - - private VehiclePropValue createHalSubscriptionRequest() { - return VehiclePropValueBuilder.newBuilder(VehicleProperty.VEHICLE_MAP_SERVICE) - .addIntValue(VmsMessageType.SUBSCRIPTIONS_REQUEST) - .build(); - } - - private class HalHandler implements VehicleHalPropertyHandler { - private ArrayList<Integer> mValues; - - @Override - public synchronized void onPropertySet(VehiclePropValue value) { - mValues = value.value.int32Values; - mHalHandlerSemaphore.release(); - } - - public ArrayList<Integer> getValues() { - return mValues; - } - } -}
\ No newline at end of file diff --git a/tests/carservice_test/src/com/android/car/test/VmsOperationRecorderTest.java b/tests/carservice_test/src/com/android/car/test/VmsOperationRecorderTest.java deleted file mode 100644 index 179a194579..0000000000 --- a/tests/carservice_test/src/com/android/car/test/VmsOperationRecorderTest.java +++ /dev/null @@ -1,245 +0,0 @@ -/* - * 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 com.android.car.test; - -import android.car.vms.VmsLayer; -import android.car.vms.VmsLayerDependency; -import android.car.vms.VmsLayersOffering; -import android.car.vms.VmsOperationRecorder; -import android.test.suitebuilder.annotation.MediumTest; -import android.util.Log; - -import junit.framework.TestCase; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; - -@MediumTest -public class VmsOperationRecorderTest extends TestCase { - - /** - * Capture messages that VmsOperationRecorder.Writer would normally pass to Log.d(...). - */ - class TestWriter extends VmsOperationRecorder.Writer { - public String mMsg; - - @Override - public boolean isEnabled() { - return true; - } - - @Override - public void write(String msg) { - super.write(msg); - mMsg = msg; - } - } - - private TestWriter mWriter; - private VmsOperationRecorder mRecorder; - private static final String TAG = "VmsOperationRecorderTest"; - - private static final VmsLayer layer1 = new VmsLayer(1, 3, 2); - private static final VmsLayer layer2 = new VmsLayer(2, 4, 3); - private static final VmsLayer layer3 = new VmsLayer(3, 5, 4); - - private static final VmsLayerDependency layerDependency1 = new VmsLayerDependency(layer3); - private static final VmsLayerDependency layerDependency2 = new VmsLayerDependency(layer1, - new HashSet<VmsLayer>(Arrays.asList(layer2, layer3))); - - private static final VmsLayersOffering layersOffering0 = new VmsLayersOffering( - new HashSet<VmsLayerDependency>(), 66); - private static final VmsLayersOffering layersOffering1 = new VmsLayersOffering( - new HashSet<>(Arrays.asList(layerDependency1)), 66); - private static final VmsLayersOffering layersOffering2 = new VmsLayersOffering( - new HashSet<>(Arrays.asList(layerDependency1, layerDependency2)), 66); - - public void setUp() { - mWriter = new TestWriter(); - mRecorder = new VmsOperationRecorder(mWriter); - } - - public void testSubscribe() throws Exception { - mRecorder.subscribe(layer1); - assertJsonMsgEquals("{'subscribe':{'layer':{'subtype':3,'type':1,'version':2}}}"); - } - - public void testUnsubscribe() throws Exception { - mRecorder.unsubscribe(layer1); - assertJsonMsgEquals("{'unsubscribe':{'layer':{'type':1,'subtype':3,'version':2}}}"); - } - - public void testStartMonitoring() throws Exception { - mRecorder.startMonitoring(); - assertJsonMsgEquals("{'startMonitoring':{}}"); - } - - public void testStopMonitoring() throws Exception { - mRecorder.stopMonitoring(); - assertJsonMsgEquals("{'stopMonitoring':{}}"); - } - - public void testSetLayersOffering0() throws Exception { - mRecorder.setLayersOffering(layersOffering0); - assertJsonMsgEquals("{'setLayersOffering':{}}"); - } - - public void testSetLayersOffering2() throws Exception { - mRecorder.setLayersOffering(layersOffering2); - assertJsonMsgEquals("{'setLayersOffering':{'layerDependency':[" - + "{'layer':{'type':3,'subtype':5,'version':4}}," - + "{'layer':{'type':1,'subtype':3,'version':2},'dependency':[" - + "{'type':2,'subtype':4,'version':3},{'type':3,'subtype':5,'version':4}]}" - + "]}}"); - } - - public void testGetPublisherId() throws Exception { - mRecorder.getPublisherId(9); - assertJsonMsgEquals("{'getPublisherId':{'publisherId':9}}"); - } - - public void testAddSubscription() throws Exception { - mRecorder.addSubscription(42, layer1); - assertJsonMsgEquals( - "{'addSubscription':{'sequenceNumber':42,'layer':{'type':1,'subtype':3,'version':2}}}" - ); - } - - public void testRemoveSubscription() throws Exception { - mRecorder.removeSubscription(42, layer1); - assertJsonMsgEquals("{'removeSubscription':" - + "{'sequenceNumber':42,'layer':{'type':1,'subtype':3,'version':2}}}"); - } - - public void testAddPromiscuousSubscription() throws Exception { - mRecorder.addPromiscuousSubscription(42); - assertJsonMsgEquals("{'addPromiscuousSubscription':{'sequenceNumber':42}}"); - } - - public void testRemovePromiscuousSubscription() throws Exception { - mRecorder.removePromiscuousSubscription(42); - assertJsonMsgEquals("{'removePromiscuousSubscription':{'sequenceNumber':42}}"); - } - - public void testAddHalSubscription() throws Exception { - mRecorder.addHalSubscription(42, layer1); - assertJsonMsgEquals("{'addHalSubscription':" - + "{'sequenceNumber':42,'layer':{'type':1,'subtype':3,'version':2}}}"); - } - - public void testRemoveHalSubscription() throws Exception { - mRecorder.removeHalSubscription(42, layer1); - assertJsonMsgEquals("{'removeHalSubscription':" - + "{'sequenceNumber':42,'layer':{'type':1,'subtype':3,'version':2}}}"); - } - - public void testSetPublisherLayersOffering() throws Exception { - mRecorder.setPublisherLayersOffering(layersOffering1); - assertJsonMsgEquals("{'setPublisherLayersOffering':{'layerDependency':[" - + "{'layer':{'type':3,'subtype':5,'version':4}}]}}"); - } - - public void testSetHalPublisherLayersOffering() throws Exception { - mRecorder.setHalPublisherLayersOffering(layersOffering1); - assertJsonMsgEquals("{'setHalPublisherLayersOffering':{'layerDependency':[" - + "{'layer':{'type':3,'subtype':5,'version':4}}]}}"); - } - - public void testSubscribeToPublisher() throws Exception { - mRecorder.subscribe(layer1, 99); - assertJsonMsgEquals( - "{'subscribe':{'publisherId':99, 'layer':{'type':1,'subtype':3,'version':2}}}"); - } - - public void testUnsubscribeToPublisher() throws Exception { - mRecorder.unsubscribe(layer1, 99); - assertJsonMsgEquals( - "{'unsubscribe':{'publisherId':99, 'layer':{'type':1,'subtype':3,'version':2}}}}"); - } - - private void assertJsonMsgEquals(String expectJson) throws Exception { - // Escaping double quotes in a JSON string is really noisy. The test data uses single - // quotes instead, which gets replaced here. - JSONObject expect = new JSONObject(expectJson.replace("'", "\"")); - JSONObject got = new JSONObject(mWriter.mMsg); - assertTrue(similar(expect, got)); - } - - /* - * Determine if two JSONObjects are similar. - * They must contain the same set of names which must be associated with - * similar values. - */ - private boolean similar(JSONObject expect, JSONObject got) { - try { - if (!expect.keySet().equals(got.keySet())) { - return false; - } - - for (String key : expect.keySet()) { - Object valueExpect = expect.get(key); - Object valueGot = got.get(key); - - if (valueExpect == valueGot) { - continue; - } - - if (valueExpect == null) { - return false; - } - - if (valueExpect instanceof JSONObject) { - return similar((JSONObject) valueExpect, (JSONObject) valueGot); - } else if (valueExpect instanceof JSONArray) { - // Equal JSONArray have the same length and one contains the other. - JSONArray expectArray = (JSONArray) valueExpect; - JSONArray gotArray = (JSONArray) valueGot; - - if (expectArray.length() != gotArray.length()) { - return false; - } - - for (int i = 0; i < expectArray.length(); i++) { - boolean gotContainsSimilar = false; - for (int j = 0; j < gotArray.length(); j++) { - if (similar((JSONObject) expectArray.get(i), - (JSONObject) gotArray.get(j))) { - gotContainsSimilar = true; - break; - } - } - if (!gotContainsSimilar) { - return false; - } - } - } else if (!valueExpect.equals(valueGot)) { - return false; - } - } - - } catch (JSONException e) { - Log.d(TAG, "Could not compare JSONObjects: " + e); - return false; - } - return true; - } -} diff --git a/tests/carservice_test/src/com/android/car/test/VmsPublisherClientMockService.java b/tests/carservice_test/src/com/android/car/test/VmsPublisherClientMockService.java deleted file mode 100644 index 0d5c4278ca..0000000000 --- a/tests/carservice_test/src/com/android/car/test/VmsPublisherClientMockService.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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 com.android.car.test; - -import android.car.annotation.FutureFeature; -import android.car.vms.VmsLayer; -import android.car.vms.VmsLayerDependency; -import android.car.vms.VmsLayersOffering; -import android.car.vms.VmsPublisherClientService; -import android.car.vms.VmsSubscriptionState; -import android.util.Log; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * This service is launched during the tests in VmsPublisherSubscriberTest. It publishes a property - * that is going to be verified in the test. - * - * The service makes offering for pre-defined layers which verifies availability notifications for - * subscribers without them actively being subscribed to a layer, and also echos all the - * subscription requests with an offering for that layer. - * For example, without any subscription request from any client, this service will make offering - * to layer X. If a client will subscribe later to layer Y, this service will respond with offering - * to both layers X and Y. - * - * Note that the subscriber can subscribe before the publisher finishes initialization. To cover - * both potential scenarios, this service publishes the test message in onVmsSubscriptionChange - * and in onVmsPublisherServiceReady. See comments below. - */ -@FutureFeature -public class VmsPublisherClientMockService extends VmsPublisherClientService { - private static final String TAG = "VmsPublisherClientMockService"; - - @Override - public void onVmsSubscriptionChange(VmsSubscriptionState subscriptionState) { - // Case when the publisher finished initialization before the subscription request. - initializeMockPublisher(subscriptionState); - } - - @Override - public void onVmsPublisherServiceReady() { - // Case when the subscription request was sent before the publisher was ready. - VmsSubscriptionState subscriptionState = getSubscriptions(); - initializeMockPublisher(subscriptionState); - } - - private void initializeMockPublisher(VmsSubscriptionState subscriptionState) { - Log.d(TAG, "Initializing Mock publisher"); - int publisherId = getPublisherId(VmsPublisherSubscriberTest.PAYLOAD); - publishIfNeeded(subscriptionState); - declareOffering(subscriptionState, publisherId); - } - - private void publishIfNeeded(VmsSubscriptionState subscriptionState) { - for (VmsLayer layer : subscriptionState.getLayers()) { - if (layer.equals(VmsPublisherSubscriberTest.LAYER)) { - publish(VmsPublisherSubscriberTest.LAYER, - VmsPublisherSubscriberTest.EXPECTED_PUBLISHER_ID, - VmsPublisherSubscriberTest.PAYLOAD); - } - } - } - - private void declareOffering(VmsSubscriptionState subscriptionState, int publisherId) { - Set<VmsLayerDependency> dependencies = new HashSet<>(); - - // Add all layers from the subscription state. - for( VmsLayer layer : subscriptionState.getLayers()) { - dependencies.add(new VmsLayerDependency(layer)); - } - - // Add default test layers. - dependencies.add(new VmsLayerDependency(VmsPublisherSubscriberTest.LAYER)); - - VmsLayersOffering offering = new VmsLayersOffering(dependencies, publisherId); - setLayersOffering(offering); - } -} diff --git a/tests/carservice_test/src/com/android/car/test/VmsPublisherClientServiceTest.java b/tests/carservice_test/src/com/android/car/test/VmsPublisherClientServiceTest.java deleted file mode 100644 index 053bab73f1..0000000000 --- a/tests/carservice_test/src/com/android/car/test/VmsPublisherClientServiceTest.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * 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 com.android.car.test; - -import android.annotation.ArrayRes; -import android.car.VehicleAreaType; -import android.car.annotation.FutureFeature; -import android.car.vms.VmsLayer; -import android.content.Context; -import android.content.ContextWrapper; -import android.content.pm.PackageManager; -import android.content.res.Resources; -import android.hardware.automotive.vehicle.V2_0.VehiclePropValue; -import android.hardware.automotive.vehicle.V2_0.VehiclePropertyAccess; -import android.hardware.automotive.vehicle.V2_0.VehiclePropertyChangeMode; -import android.hardware.automotive.vehicle.V2_0.VehicleProperty; -import android.hardware.automotive.vehicle.V2_0.VmsBaseMessageIntegerValuesIndex; -import android.hardware.automotive.vehicle.V2_0.VmsMessageWithLayerIntegerValuesIndex; -import android.hardware.automotive.vehicle.V2_0.VmsMessageType; -import android.test.suitebuilder.annotation.MediumTest; -import android.util.Log; - -import com.android.car.R; -import com.android.car.vehiclehal.VehiclePropValueBuilder; -import com.android.car.vehiclehal.test.MockedVehicleHal; -import com.android.car.vehiclehal.test.MockedVehicleHal.VehicleHalPropertyHandler; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.concurrent.Semaphore; -import java.util.concurrent.TimeUnit; - -@FutureFeature -@MediumTest -public class VmsPublisherClientServiceTest extends MockedCarTestBase { - private static final String TAG = "VmsPublisherTest"; - private static final int MOCK_PUBLISHER_LAYER_ID = 12; - private static final int MOCK_PUBLISHER_LAYER_VERSION = 34; - private static final int MOCK_PUBLISHER_LAYER_SUBTYPE = 56; - public static final int MOCK_PUBLISHER_ID = 1234; - public static final VmsLayer MOCK_PUBLISHER_LAYER = - new VmsLayer(MOCK_PUBLISHER_LAYER_ID, - MOCK_PUBLISHER_LAYER_SUBTYPE, - MOCK_PUBLISHER_LAYER_VERSION); - public static final byte[] PAYLOAD = new byte[]{1, 1, 2, 3, 5, 8, 13}; - - private HalHandler mHalHandler; - // Used to block until the HAL property is updated in HalHandler.onPropertySet. - private Semaphore mHalHandlerSemaphore; - - @Override - protected synchronized void configureMockedHal() { - mHalHandler = new HalHandler(); - addProperty(VehicleProperty.VEHICLE_MAP_SERVICE, mHalHandler) - .setChangeMode(VehiclePropertyChangeMode.ON_CHANGE) - .setAccess(VehiclePropertyAccess.READ_WRITE) - .setSupportedAreas(VehicleAreaType.VEHICLE_AREA_TYPE_NONE); - } - - /** - * Creates a context with the resource vmsPublisherClients overridden. The overridden value - * contains the name of the test service defined also in this test package. - */ - @Override - protected Context getCarServiceContext() throws PackageManager.NameNotFoundException { - Context context = getContext() - .createPackageContext("com.android.car", Context.CONTEXT_IGNORE_SECURITY); - Resources resources = new Resources(context.getAssets(), - context.getResources().getDisplayMetrics(), - context.getResources().getConfiguration()) { - @Override - public String[] getStringArray(@ArrayRes int id) throws NotFoundException { - if (id == R.array.vmsPublisherClients) { - return new String[]{"com.android.car.test/.SimpleVmsPublisherClientService"}; - } - return super.getStringArray(id); - } - }; - ContextWrapper wrapper = new ContextWrapper(context) { - @Override - public Resources getResources() { - return resources; - } - }; - return wrapper; - } - - private VehiclePropValue getHalSubscriptionRequest() { - return VehiclePropValueBuilder.newBuilder(VehicleProperty.VEHICLE_MAP_SERVICE) - .addIntValue(VmsMessageType.SUBSCRIBE) - .addIntValue(MOCK_PUBLISHER_LAYER_ID) - .addIntValue(MOCK_PUBLISHER_LAYER_SUBTYPE) - .addIntValue(MOCK_PUBLISHER_LAYER_VERSION) - .build(); - } - - @Override - protected void setUp() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - /** - * First init the semaphore, setUp will start a series of events that will ultimately - * update the HAL layer and release this semaphore. - */ - mHalHandlerSemaphore = new Semaphore(0); - super.setUp(); - - // Inject a subscribe event which simulates the HAL is subscribed to the Mock Publisher. - MockedVehicleHal mHal = getMockedVehicleHal(); - mHal.injectEvent(getHalSubscriptionRequest()); - } - - @Override - protected synchronized void tearDown() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - super.tearDown(); - } - - /** - * The method setUp initializes all the Car services, including the VmsPublisherService. - * The VmsPublisherService will start and configure its list of clients. This list was - * overridden in the method getCarServiceContext. - * Therefore, only SimpleVmsPublisherClientService will be started. - * The service SimpleVmsPublisherClientService will publish one message, which is validated in - * this test. - */ - public void testPublish() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - //TODO: This test is using minial synchronisation between clients. - // If more complexity is added this may result in publisher - // publishing before the subscriber subscribed, in which case - // the semaphore will not be released. - assertTrue(mHalHandlerSemaphore.tryAcquire(2L, TimeUnit.SECONDS)); - VehiclePropValue.RawValue rawValue = mHalHandler.getValue().value; - int messageType = rawValue.int32Values.get(VmsMessageWithLayerIntegerValuesIndex.MESSAGE_TYPE); - int layerId = rawValue.int32Values.get(VmsMessageWithLayerIntegerValuesIndex.LAYER_TYPE); - int layerVersion = rawValue.int32Values.get(VmsMessageWithLayerIntegerValuesIndex.LAYER_VERSION); - byte[] payload = new byte[rawValue.bytes.size()]; - for (int i = 0; i < rawValue.bytes.size(); ++i) { - payload[i] = rawValue.bytes.get(i); - } - assertEquals(VmsMessageType.DATA, messageType); - assertEquals(MOCK_PUBLISHER_LAYER_ID, layerId); - assertEquals(MOCK_PUBLISHER_LAYER_VERSION, layerVersion); - assertTrue(Arrays.equals(PAYLOAD, payload)); - } - - private class HalHandler implements VehicleHalPropertyHandler { - private VehiclePropValue mValue; - - @Override - public synchronized void onPropertySet(VehiclePropValue value) { - mValue = value; - - // If this is the data message release the semaphone so the test can continue. - ArrayList<Integer> int32Values = value.value.int32Values; - if (int32Values.get(VmsBaseMessageIntegerValuesIndex.MESSAGE_TYPE) == - VmsMessageType.DATA) { - mHalHandlerSemaphore.release(); - } - } - - @Override - public synchronized VehiclePropValue onPropertyGet(VehiclePropValue value) { - return mValue != null ? mValue : value; - } - - @Override - public synchronized void onPropertySubscribe(int property, int zones, float sampleRate) { - Log.d(TAG, "onPropertySubscribe property " + property + " sampleRate " + sampleRate); - } - - @Override - public synchronized void onPropertyUnsubscribe(int property) { - Log.d(TAG, "onPropertyUnSubscribe property " + property); - } - - public VehiclePropValue getValue() { - return mValue; - } - } -}
\ No newline at end of file diff --git a/tests/carservice_test/src/com/android/car/test/VmsPublisherPermissionsTest.java b/tests/carservice_test/src/com/android/car/test/VmsPublisherPermissionsTest.java deleted file mode 100644 index 1d14c5700d..0000000000 --- a/tests/carservice_test/src/com/android/car/test/VmsPublisherPermissionsTest.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * 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 com.android.car.test; - -import android.annotation.ArrayRes; -import android.car.VehicleAreaType; -import android.car.annotation.FutureFeature; -import android.content.Context; -import android.content.ContextWrapper; -import android.content.pm.PackageManager; -import android.content.res.Resources; -import android.hardware.automotive.vehicle.V2_0.VehiclePropValue; -import android.hardware.automotive.vehicle.V2_0.VehiclePropertyAccess; -import android.hardware.automotive.vehicle.V2_0.VehiclePropertyChangeMode; -import android.hardware.automotive.vehicle.V2_0.VehicleProperty; -import android.hardware.automotive.vehicle.V2_0.VmsBaseMessageIntegerValuesIndex; -import android.hardware.automotive.vehicle.V2_0.VmsMessageType; -import android.test.suitebuilder.annotation.MediumTest; - -import com.android.car.R; -import com.android.car.vehiclehal.VehiclePropValueBuilder; -import com.android.car.vehiclehal.test.MockedVehicleHal; -import com.android.car.vehiclehal.test.MockedVehicleHal.VehicleHalPropertyHandler; - -import java.util.ArrayList; -import java.util.concurrent.Semaphore; -import java.util.concurrent.TimeUnit; - -@FutureFeature -@MediumTest -public class VmsPublisherPermissionsTest extends MockedCarTestBase { - private static final String TAG = "VmsPublisherTest"; - private static final int MOCK_PUBLISHER_LAYER_ID = 0; - private static final int MOCK_PUBLISHER_LAYER_VERSION = 0; - private static final int MOCK_PUBLISHER_LAYER_FUSION_INT_VALUE = 0; - - private HalHandler mHalHandler; - // Used to block until the HAL property is updated in HalHandler.onPropertySet. - private Semaphore mHalHandlerSemaphore; - - @Override - protected synchronized void configureMockedHal() { - mHalHandler = new HalHandler(); - addProperty(VehicleProperty.VEHICLE_MAP_SERVICE, mHalHandler) - .setChangeMode(VehiclePropertyChangeMode.ON_CHANGE) - .setAccess(VehiclePropertyAccess.READ_WRITE) - .setSupportedAreas(VehicleAreaType.VEHICLE_AREA_TYPE_NONE); - } - - /** - * Creates a context with the resource vmsPublisherClients overridden. The overridden value - * contains the name of the test service defined also in this test package. - */ - @Override - protected Context getCarServiceContext() throws PackageManager.NameNotFoundException { - Context context = getContext() - .createPackageContext("com.android.car", Context.CONTEXT_IGNORE_SECURITY); - Resources resources = new Resources(context.getAssets(), - context.getResources().getDisplayMetrics(), - context.getResources().getConfiguration()) { - @Override - public String[] getStringArray(@ArrayRes int id) throws NotFoundException { - if (id == R.array.vmsPublisherClients) { - return new String[]{ - "com.google.android.car.vms.publisher/" - + ".VmsPublisherClientSampleService"}; - } else if (id == R.array.vmsSafePermissions) { - return new String[]{"android.permission.ACCESS_FINE_LOCATION"}; - } - return super.getStringArray(id); - } - }; - ContextWrapper wrapper = new ContextWrapper(context) { - @Override - public Resources getResources() { - return resources; - } - }; - return wrapper; - } - - private VehiclePropValue getHalSubscriptionRequest() { - return VehiclePropValueBuilder.newBuilder(VehicleProperty.VEHICLE_MAP_SERVICE) - .addIntValue(VmsMessageType.SUBSCRIBE) - .addIntValue(MOCK_PUBLISHER_LAYER_ID) - .addIntValue(MOCK_PUBLISHER_LAYER_VERSION) - .addIntValue(MOCK_PUBLISHER_LAYER_FUSION_INT_VALUE) - .build(); - } - - @Override - protected void setUp() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - /** - * First init the semaphore, setUp will start a series of events that will ultimately - * update the HAL layer and release this semaphore. - */ - mHalHandlerSemaphore = new Semaphore(0); - super.setUp(); - - // Inject a subscribe event which simulates the HAL is subscribed to the Sample Publisher. - MockedVehicleHal mHal = getMockedVehicleHal(); - mHal.injectEvent(getHalSubscriptionRequest()); - } - - @Override - protected synchronized void tearDown() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - super.tearDown(); - } - - /** - * The method setUp initializes all the Car services, including the VmsPublisherService. - * The VmsPublisherService will start and configure its list of clients. This list was - * overridden in the method getCarServiceContext. - * Therefore, only VmsPublisherClientSampleService will be started. - * The service VmsPublisherClientSampleService will publish one message, which is validated in - * this test. - */ - public void testPermissions() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - assertTrue(mHalHandlerSemaphore.tryAcquire(2L, TimeUnit.SECONDS)); - // At this point the client initialization finished. Let's validate the permissions. - // The VMS service is only allowed to grant ACCESS_FINE_LOCATION but not CAMERA. - assertTrue( - getContext().getPackageManager().checkPermission( - "android.permission.ACCESS_FINE_LOCATION", - "com.google.android.car.vms.publisher") - == PackageManager.PERMISSION_GRANTED); - assertFalse(getContext().getPackageManager().checkPermission( - "android.permission.CAMERA", "com.google.android.car.vms.publisher") - == PackageManager.PERMISSION_GRANTED); - } - - private class HalHandler implements VehicleHalPropertyHandler { - @Override - public synchronized void onPropertySet(VehiclePropValue value) { - // If this is the data message release the semaphore so the test can continue. - ArrayList<Integer> int32Values = value.value.int32Values; - if (int32Values.get(VmsBaseMessageIntegerValuesIndex.MESSAGE_TYPE) == - VmsMessageType.DATA) { - mHalHandlerSemaphore.release(); - } - } - } -} diff --git a/tests/carservice_test/src/com/android/car/test/VmsPublisherSubscriberTest.java b/tests/carservice_test/src/com/android/car/test/VmsPublisherSubscriberTest.java deleted file mode 100644 index 5b387d2e2c..0000000000 --- a/tests/carservice_test/src/com/android/car/test/VmsPublisherSubscriberTest.java +++ /dev/null @@ -1,238 +0,0 @@ -/* - * 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 com.android.car.test; - -import android.annotation.ArrayRes; -import android.car.Car; -import android.car.VehicleAreaType; -import android.car.annotation.FutureFeature; -import android.car.vms.VmsAssociatedLayer; -import android.car.vms.VmsLayer; -import android.car.vms.VmsSubscriberManager; -import android.content.Context; -import android.content.ContextWrapper; -import android.content.pm.PackageManager; -import android.content.res.Resources; -import android.hardware.automotive.vehicle.V2_0.VehiclePropertyAccess; -import android.hardware.automotive.vehicle.V2_0.VehiclePropertyChangeMode; -import android.hardware.automotive.vehicle.V2_0.VehicleProperty; -import android.test.suitebuilder.annotation.MediumTest; - -import com.android.car.vehiclehal.test.MockedVehicleHal; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.concurrent.Semaphore; -import java.util.concurrent.TimeUnit; - -@FutureFeature -@MediumTest -public class VmsPublisherSubscriberTest extends MockedCarTestBase { - private static final int LAYER_ID = 88; - private static final int LAYER_VERSION = 19; - private static final int LAYER_SUBTYPE = 55; - private static final String TAG = "VmsPubSubTest"; - - // The expected publisher ID is 0 since it the expected assigned ID from the VMS core. - public static final int EXPECTED_PUBLISHER_ID = 0; - public static final VmsLayer LAYER = new VmsLayer(LAYER_ID, LAYER_SUBTYPE, LAYER_VERSION); - public static final VmsAssociatedLayer ASSOCIATED_LAYER = - new VmsAssociatedLayer(LAYER, new HashSet<>(Arrays.asList(EXPECTED_PUBLISHER_ID))); - public static final byte[] PAYLOAD = new byte[]{2, 3, 5, 7, 11, 13, 17}; - - private static final List<VmsAssociatedLayer> AVAILABLE_ASSOCIATED_LAYERS = - new ArrayList<>(Arrays.asList(ASSOCIATED_LAYER)); - - - private static final int SUBSCRIBED_LAYER_ID = 89; - public static final VmsLayer SUBSCRIBED_LAYER = - new VmsLayer(SUBSCRIBED_LAYER_ID, LAYER_SUBTYPE, LAYER_VERSION); - public static final VmsAssociatedLayer ASSOCIATED_SUBSCRIBED_LAYER = - new VmsAssociatedLayer(SUBSCRIBED_LAYER, new HashSet<>(Arrays.asList(EXPECTED_PUBLISHER_ID))); - private static final List<VmsAssociatedLayer> AVAILABLE_ASSOCIATED_LAYERS_WITH_SUBSCRIBED_LAYER = - new ArrayList<>(Arrays.asList(ASSOCIATED_LAYER, ASSOCIATED_SUBSCRIBED_LAYER)); - - - private HalHandler mHalHandler; - // Used to block until a value is propagated to the TestClientCallback.onVmsMessageReceived. - private Semaphore mSubscriberSemaphore; - private Semaphore mAvailabilitySemaphore; - - @Override - protected synchronized void configureMockedHal() { - mHalHandler = new HalHandler(); - addProperty(VehicleProperty.VEHICLE_MAP_SERVICE, mHalHandler) - .setChangeMode(VehiclePropertyChangeMode.ON_CHANGE) - .setAccess(VehiclePropertyAccess.READ_WRITE) - .setSupportedAreas(VehicleAreaType.VEHICLE_AREA_TYPE_NONE); - } - - /** - * Creates a context with the resource vmsPublisherClients overridden. The overridden value - * contains the name of the test service defined also in this test package. - */ - @Override - protected Context getCarServiceContext() throws PackageManager.NameNotFoundException { - Context context = getContext() - .createPackageContext("com.android.car", Context.CONTEXT_IGNORE_SECURITY); - Resources resources = new Resources(context.getAssets(), - context.getResources().getDisplayMetrics(), - context.getResources().getConfiguration()) { - @Override - public String[] getStringArray(@ArrayRes int id) throws NotFoundException { - if (id == com.android.car.R.array.vmsPublisherClients) { - return new String[]{"com.android.car.test/.VmsPublisherClientMockService"}; - } - return super.getStringArray(id); - } - }; - ContextWrapper wrapper = new ContextWrapper(context) { - @Override - public Resources getResources() { - return resources; - } - }; - return wrapper; - } - - @Override - protected void setUp() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - super.setUp(); - mSubscriberSemaphore = new Semaphore(0); - mAvailabilitySemaphore = new Semaphore(0); - } - - @Override - protected synchronized void tearDown() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - super.tearDown(); - } - - /** - * The method setUp initializes all the Car services, including the VmsPublisherService. - * The VmsPublisherService will start and configure its list of clients. This list was - * overridden in the method getCarServiceContext. Therefore, only VmsPublisherClientMockService - * will be started. This test method subscribes to a layer and triggers - * VmsPublisherClientMockService.onVmsSubscriptionChange. In turn, the mock service will publish - * a message, which is validated in this test. - */ - public void testPublisherToSubscriber() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - VmsSubscriberManager vmsSubscriberManager = (VmsSubscriberManager) getCar().getCarManager( - Car.VMS_SUBSCRIBER_SERVICE); - TestClientCallback clientCallback = new TestClientCallback(); - vmsSubscriberManager.registerClientCallback(clientCallback); - vmsSubscriberManager.subscribe(LAYER); - - assertTrue(mSubscriberSemaphore.tryAcquire(2L, TimeUnit.SECONDS)); - assertEquals(LAYER, clientCallback.getLayer()); - assertTrue(Arrays.equals(PAYLOAD, clientCallback.getPayload())); - } - - /** - * The Mock service will get a publisher ID by sending its information when it will get - * ServiceReady as well as on SubscriptionChange. Since clients are not notified when - * publishers are assigned IDs, this test waits until the availability is changed which indicates - * that the Mock service has gotten its ServiceReady and publisherId. - */ - public void testPublisherInfo() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - VmsSubscriberManager vmsSubscriberManager = (VmsSubscriberManager) getCar().getCarManager( - Car.VMS_SUBSCRIBER_SERVICE); - // Subscribe to layer as a way to make sure the mock client completed setting the information. - TestClientCallback clientCallback = new TestClientCallback(); - vmsSubscriberManager.registerClientCallback(clientCallback); - vmsSubscriberManager.subscribe(LAYER); - - assertTrue(mAvailabilitySemaphore.tryAcquire(2L, TimeUnit.SECONDS)); - - byte[] info = vmsSubscriberManager.getPublisherInfo(EXPECTED_PUBLISHER_ID); - assertTrue(Arrays.equals(PAYLOAD, info)); - } - - /** - * The Mock service offers all the subscribed layers as available layers. - * In this test the client subscribes to a layer and verifies that it gets the - * notification that it is available. - */ - public void testAvailabilityWithSubscription() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - VmsSubscriberManager vmsSubscriberManager = (VmsSubscriberManager) getCar().getCarManager( - Car.VMS_SUBSCRIBER_SERVICE); - TestClientCallback clientCallback = new TestClientCallback(); - vmsSubscriberManager.registerClientCallback(clientCallback); - vmsSubscriberManager.subscribe(SUBSCRIBED_LAYER); - - assertTrue(mAvailabilitySemaphore.tryAcquire(2L, TimeUnit.SECONDS)); - assertEquals(AVAILABLE_ASSOCIATED_LAYERS_WITH_SUBSCRIBED_LAYER, clientCallback.getAvailalbeLayers()); - } - - /** - * The Mock service offers all the subscribed layers as available layers, so in this - * test the client subscribes to a layer and verifies that it gets the notification that it - * is available. - */ - public void testAvailabilityWithoutSubscription() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - VmsSubscriberManager vmsSubscriberManager = (VmsSubscriberManager) getCar().getCarManager( - Car.VMS_SUBSCRIBER_SERVICE); - TestClientCallback clientCallback = new TestClientCallback(); - vmsSubscriberManager.registerClientCallback(clientCallback); - - assertTrue(mAvailabilitySemaphore.tryAcquire(2L, TimeUnit.SECONDS)); - assertEquals(AVAILABLE_ASSOCIATED_LAYERS, clientCallback.getAvailalbeLayers()); - } - - private class HalHandler implements MockedVehicleHal.VehicleHalPropertyHandler { - } - - private class TestClientCallback implements VmsSubscriberManager.VmsSubscriberClientCallback { - private VmsLayer mLayer; - private byte[] mPayload; - private List<VmsLayer> mAvailableLayers; - - @Override - public void onVmsMessageReceived(VmsLayer layer, byte[] payload) { - assertEquals(LAYER, layer); - assertTrue(Arrays.equals(PAYLOAD, payload)); - mLayer = layer; - mPayload = payload; - mSubscriberSemaphore.release(); - } - - @Override - public void onLayersAvailabilityChanged(List<VmsLayer> availableLayers) { - mAvailableLayers = availableLayers; - mAvailabilitySemaphore.release(); - } - - public VmsLayer getLayer() { - return mLayer; - } - - public byte[] getPayload() { - return mPayload; - } - - public List<VmsLayer> getAvailalbeLayers() { - return mAvailableLayers; - } - } -} diff --git a/tests/carservice_test/src/com/android/car/test/VmsSubscriberManagerTest.java b/tests/carservice_test/src/com/android/car/test/VmsSubscriberManagerTest.java deleted file mode 100644 index 9e9a5d0844..0000000000 --- a/tests/carservice_test/src/com/android/car/test/VmsSubscriberManagerTest.java +++ /dev/null @@ -1,614 +0,0 @@ -/* - * 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 com.android.car.test; - -import static org.junit.Assume.assumeTrue; - -import android.car.Car; -import android.car.VehicleAreaType; -import android.car.annotation.FutureFeature; -import android.car.vms.VmsAssociatedLayer; -import android.car.vms.VmsLayer; -import android.car.vms.VmsSubscriberManager; -import android.car.vms.VmsSubscriberManager.VmsSubscriberClientCallback; -import android.hardware.automotive.vehicle.V2_0.VehiclePropValue; -import android.hardware.automotive.vehicle.V2_0.VehiclePropertyAccess; -import android.hardware.automotive.vehicle.V2_0.VehiclePropertyChangeMode; -import android.hardware.automotive.vehicle.V2_0.VehicleProperty; -import android.hardware.automotive.vehicle.V2_0.VmsMessageType; -import android.os.SystemClock; -import android.test.suitebuilder.annotation.MediumTest; -import android.util.Log; -import com.android.car.vehiclehal.VehiclePropValueBuilder; -import com.android.car.vehiclehal.test.MockedVehicleHal.VehicleHalPropertyHandler; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.Semaphore; -import java.util.concurrent.TimeUnit; - -@FutureFeature -@MediumTest -public class VmsSubscriberManagerTest extends MockedCarTestBase { - private static final String TAG = "VmsSubscriberManagerTest"; - private static final int PUBLISHER_ID = 17; - private static final int WRONG_PUBLISHER_ID = 26; - private static final Set<Integer> PUBLISHERS_LIST = new HashSet<Integer>(Arrays.asList(PUBLISHER_ID)); - - private static final int SUBSCRIPTION_LAYER_ID = 2; - private static final int SUBSCRIPTION_LAYER_VERSION = 3; - private static final int MOCK_PUBLISHER_LAYER_SUBTYPE = 444; - private static final VmsLayer SUBSCRIPTION_LAYER = new VmsLayer(SUBSCRIPTION_LAYER_ID, - MOCK_PUBLISHER_LAYER_SUBTYPE, - SUBSCRIPTION_LAYER_VERSION); - private static final VmsAssociatedLayer SUBSCRIPTION_ASSOCIATED_LAYER = - new VmsAssociatedLayer(SUBSCRIPTION_LAYER, PUBLISHERS_LIST); - - private static final int SUBSCRIPTION_DEPENDANT_LAYER_ID_1 = 4; - private static final int SUBSCRIPTION_DEPENDANT_LAYER_VERSION_1 = 5; - private static final VmsLayer SUBSCRIPTION_DEPENDANT_LAYER_1 = - new VmsLayer(SUBSCRIPTION_DEPENDANT_LAYER_ID_1, - MOCK_PUBLISHER_LAYER_SUBTYPE, - SUBSCRIPTION_DEPENDANT_LAYER_VERSION_1); - - private static final VmsAssociatedLayer SUBSCRIPTION_DEPENDANT_ASSOCIATED_LAYER_1 = - new VmsAssociatedLayer(SUBSCRIPTION_DEPENDANT_LAYER_1, PUBLISHERS_LIST); - - private static final int SUBSCRIPTION_DEPENDANT_LAYER_ID_2 = 6; - private static final int SUBSCRIPTION_DEPENDANT_LAYER_VERSION_2 = 7; - private static final VmsLayer SUBSCRIPTION_DEPENDANT_LAYER_2 = - new VmsLayer(SUBSCRIPTION_DEPENDANT_LAYER_ID_2, - MOCK_PUBLISHER_LAYER_SUBTYPE, - SUBSCRIPTION_DEPENDANT_LAYER_VERSION_2); - - private static final VmsAssociatedLayer SUBSCRIPTION_DEPENDANT_ASSOCIATED_LAYER_2 = - new VmsAssociatedLayer(SUBSCRIPTION_DEPENDANT_LAYER_2, PUBLISHERS_LIST); - - private static final int SUBSCRIPTION_UNSUPPORTED_LAYER_ID = 100; - private static final int SUBSCRIPTION_UNSUPPORTED_LAYER_VERSION = 200; - - - private HalHandler mHalHandler; - // Used to block until the HAL property is updated in HalHandler.onPropertySet. - private Semaphore mHalHandlerSemaphore; - // Used to block until a value is propagated to the TestClientCallback.onVmsMessageReceived. - private Semaphore mSubscriberSemaphore; - - @Override - protected synchronized void configureMockedHal() { - mHalHandler = new HalHandler(); - addProperty(VehicleProperty.VEHICLE_MAP_SERVICE, mHalHandler) - .setChangeMode(VehiclePropertyChangeMode.ON_CHANGE) - .setAccess(VehiclePropertyAccess.READ_WRITE) - .setSupportedAreas(VehicleAreaType.VEHICLE_AREA_TYPE_NONE); - } - - @Override - protected void setUp() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - super.setUp(); - mSubscriberSemaphore = new Semaphore(0); - mHalHandlerSemaphore = new Semaphore(0); - } - - @Override - protected synchronized void tearDown() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - super.tearDown(); - } - - // Test injecting a value in the HAL and verifying it propagates to a subscriber. - public void testSubscribe() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - VmsSubscriberManager vmsSubscriberManager = (VmsSubscriberManager) getCar().getCarManager( - Car.VMS_SUBSCRIBER_SERVICE); - TestClientCallback clientCallback = new TestClientCallback(); - vmsSubscriberManager.registerClientCallback(clientCallback); - vmsSubscriberManager.subscribe(SUBSCRIPTION_LAYER); - - // Inject a value and wait for its callback in TestClientCallback.onVmsMessageReceived. - VehiclePropValue v = VehiclePropValueBuilder.newBuilder(VehicleProperty.VEHICLE_MAP_SERVICE) - .setAreaId(VehicleAreaType.VEHICLE_AREA_TYPE_NONE) - .setTimestamp(SystemClock.elapsedRealtimeNanos()) - .build(); - v.value.int32Values.add(VmsMessageType.DATA); // MessageType - v.value.int32Values.add(SUBSCRIPTION_LAYER_ID); - v.value.int32Values.add(MOCK_PUBLISHER_LAYER_SUBTYPE); - v.value.int32Values.add(SUBSCRIPTION_LAYER_VERSION); - v.value.int32Values.add(PUBLISHER_ID); - v.value.bytes.add((byte) 0xa); - v.value.bytes.add((byte) 0xb); - assertEquals(0, mSubscriberSemaphore.availablePermits()); - - getMockedVehicleHal().injectEvent(v); - assertTrue(mSubscriberSemaphore.tryAcquire(2L, TimeUnit.SECONDS)); - assertEquals(SUBSCRIPTION_LAYER, clientCallback.getLayer()); - byte[] expectedPayload = {(byte) 0xa, (byte) 0xb}; - assertTrue(Arrays.equals(expectedPayload, clientCallback.getPayload())); - } - - - // Test injecting a value in the HAL and verifying it propagates to a subscriber. - public void testSubscribeToPublisher() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - VmsSubscriberManager vmsSubscriberManager = (VmsSubscriberManager) getCar().getCarManager( - Car.VMS_SUBSCRIBER_SERVICE); - TestClientCallback clientCallback = new TestClientCallback(); - vmsSubscriberManager.registerClientCallback(clientCallback); - vmsSubscriberManager.subscribe(SUBSCRIPTION_LAYER, PUBLISHER_ID); - - // Inject a value and wait for its callback in TestClientCallback.onVmsMessageReceived. - VehiclePropValue v = VehiclePropValueBuilder.newBuilder(VehicleProperty.VEHICLE_MAP_SERVICE) - .setAreaId(VehicleAreaType.VEHICLE_AREA_TYPE_NONE) - .setTimestamp(SystemClock.elapsedRealtimeNanos()) - .build(); - v.value.int32Values.add(VmsMessageType.DATA); // MessageType - v.value.int32Values.add(SUBSCRIPTION_LAYER_ID); - v.value.int32Values.add(MOCK_PUBLISHER_LAYER_SUBTYPE); - v.value.int32Values.add(SUBSCRIPTION_LAYER_VERSION); - v.value.int32Values.add(WRONG_PUBLISHER_ID); - v.value.bytes.add((byte) 0xa); - v.value.bytes.add((byte) 0xb); - assertEquals(0, mSubscriberSemaphore.availablePermits()); - - getMockedVehicleHal().injectEvent(v); - - assertFalse(mSubscriberSemaphore.tryAcquire(2L, TimeUnit.SECONDS)); - } - - // Test injecting a value in the HAL and verifying it propagates to a subscriber. - public void testSubscribeFromPublisher() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - VmsSubscriberManager vmsSubscriberManager = (VmsSubscriberManager) getCar().getCarManager( - Car.VMS_SUBSCRIBER_SERVICE); - TestClientCallback clientCallback = new TestClientCallback(); - vmsSubscriberManager.registerClientCallback(clientCallback); - vmsSubscriberManager.subscribe(SUBSCRIPTION_LAYER, PUBLISHER_ID); - - // Inject a value and wait for its callback in TestClientCallback.onVmsMessageReceived. - VehiclePropValue v = VehiclePropValueBuilder.newBuilder(VehicleProperty.VEHICLE_MAP_SERVICE) - .setAreaId(VehicleAreaType.VEHICLE_AREA_TYPE_NONE) - .setTimestamp(SystemClock.elapsedRealtimeNanos()) - .build(); - v.value.int32Values.add(VmsMessageType.DATA); // MessageType - v.value.int32Values.add(SUBSCRIPTION_LAYER_ID); - v.value.int32Values.add(MOCK_PUBLISHER_LAYER_SUBTYPE); //<- - v.value.int32Values.add(SUBSCRIPTION_LAYER_VERSION); - v.value.int32Values.add(PUBLISHER_ID); - v.value.bytes.add((byte) 0xa); - v.value.bytes.add((byte) 0xb); - assertEquals(0, mSubscriberSemaphore.availablePermits()); - - getMockedVehicleHal().injectEvent(v); - assertTrue(mSubscriberSemaphore.tryAcquire(2L, TimeUnit.SECONDS)); - assertEquals(SUBSCRIPTION_LAYER, clientCallback.getLayer()); - byte[] expectedPayload = {(byte) 0xa, (byte) 0xb}; - assertTrue(Arrays.equals(expectedPayload, clientCallback.getPayload())); - } - - // Test injecting a value in the HAL and verifying it does not propagate to a subscriber. - public void testUnsubscribe() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - VmsSubscriberManager vmsSubscriberManager = (VmsSubscriberManager) getCar().getCarManager( - Car.VMS_SUBSCRIBER_SERVICE); - TestClientCallback clientCallback = new TestClientCallback(); - vmsSubscriberManager.registerClientCallback(clientCallback); - vmsSubscriberManager.subscribe(SUBSCRIPTION_LAYER); - vmsSubscriberManager.unsubscribe(SUBSCRIPTION_LAYER); - - // Inject a value and wait for its callback in TestClientCallback.onVmsMessageReceived. - VehiclePropValue v = VehiclePropValueBuilder.newBuilder(VehicleProperty.VEHICLE_MAP_SERVICE) - .setAreaId(VehicleAreaType.VEHICLE_AREA_TYPE_NONE) - .setTimestamp(SystemClock.elapsedRealtimeNanos()) - .build(); - v.value.int32Values.add(VmsMessageType.DATA); // MessageType - v.value.int32Values.add(SUBSCRIPTION_LAYER_ID); - v.value.int32Values.add(MOCK_PUBLISHER_LAYER_SUBTYPE); - v.value.int32Values.add(SUBSCRIPTION_LAYER_VERSION); - v.value.int32Values.add(PUBLISHER_ID); - v.value.bytes.add((byte) 0xa); - v.value.bytes.add((byte) 0xb); - assertEquals(0, mSubscriberSemaphore.availablePermits()); - - getMockedVehicleHal().injectEvent(v); - assertFalse(mSubscriberSemaphore.tryAcquire(2L, TimeUnit.SECONDS)); - } - - // Test injecting a value in the HAL and verifying it does not propagate to a subscriber. - public void testSubscribeFromWrongPublisher() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - VmsSubscriberManager vmsSubscriberManager = (VmsSubscriberManager) getCar().getCarManager( - Car.VMS_SUBSCRIBER_SERVICE); - TestClientCallback clientCallback = new TestClientCallback(); - vmsSubscriberManager.registerClientCallback(clientCallback); - vmsSubscriberManager.subscribe(SUBSCRIPTION_LAYER, PUBLISHER_ID); - - // Inject a value and wait for its callback in TestClientCallback.onVmsMessageReceived. - VehiclePropValue v = VehiclePropValueBuilder.newBuilder(VehicleProperty.VEHICLE_MAP_SERVICE) - .setAreaId(VehicleAreaType.VEHICLE_AREA_TYPE_NONE) - .setTimestamp(SystemClock.elapsedRealtimeNanos()) - .build(); - v.value.int32Values.add(VmsMessageType.DATA); // MessageType - v.value.int32Values.add(SUBSCRIPTION_LAYER_ID); - v.value.int32Values.add(MOCK_PUBLISHER_LAYER_SUBTYPE); - v.value.int32Values.add(SUBSCRIPTION_LAYER_VERSION); - v.value.int32Values.add(WRONG_PUBLISHER_ID); - v.value.bytes.add((byte) 0xa); - v.value.bytes.add((byte) 0xb); - assertEquals(0, mSubscriberSemaphore.availablePermits()); - - getMockedVehicleHal().injectEvent(v); - assertFalse(mSubscriberSemaphore.tryAcquire(2L, TimeUnit.SECONDS)); - } - - // Test injecting a value in the HAL and verifying it does not propagate to a subscriber. - public void testUnsubscribeFromPublisher() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - VmsSubscriberManager vmsSubscriberManager = (VmsSubscriberManager) getCar().getCarManager( - Car.VMS_SUBSCRIBER_SERVICE); - TestClientCallback clientCallback = new TestClientCallback(); - vmsSubscriberManager.registerClientCallback(clientCallback); - vmsSubscriberManager.subscribe(SUBSCRIPTION_LAYER, PUBLISHER_ID); - vmsSubscriberManager.unsubscribe(SUBSCRIPTION_LAYER, PUBLISHER_ID); - - // Inject a value and wait for its callback in TestClientCallback.onVmsMessageReceived. - VehiclePropValue v = VehiclePropValueBuilder.newBuilder(VehicleProperty.VEHICLE_MAP_SERVICE) - .setAreaId(VehicleAreaType.VEHICLE_AREA_TYPE_NONE) - .setTimestamp(SystemClock.elapsedRealtimeNanos()) - .build(); - v.value.int32Values.add(VmsMessageType.DATA); // MessageType - v.value.int32Values.add(SUBSCRIPTION_LAYER_ID); - v.value.int32Values.add(MOCK_PUBLISHER_LAYER_SUBTYPE); - v.value.int32Values.add(SUBSCRIPTION_LAYER_VERSION); - v.value.int32Values.add(PUBLISHER_ID); - v.value.bytes.add((byte) 0xa); - v.value.bytes.add((byte) 0xb); - assertEquals(0, mSubscriberSemaphore.availablePermits()); - - getMockedVehicleHal().injectEvent(v); - assertFalse(mSubscriberSemaphore.tryAcquire(2L, TimeUnit.SECONDS)); - } - - - // Test injecting a value in the HAL and verifying it propagates to a subscriber. - public void testSubscribeAll() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - VmsSubscriberManager vmsSubscriberManager = (VmsSubscriberManager) getCar().getCarManager( - Car.VMS_SUBSCRIBER_SERVICE); - TestClientCallback clientCallback = new TestClientCallback(); - vmsSubscriberManager.registerClientCallback(clientCallback); - vmsSubscriberManager.startMonitoring(); - - // Inject a value and wait for its callback in TestClientCallback.onVmsMessageReceived. - VehiclePropValue v = VehiclePropValueBuilder.newBuilder(VehicleProperty.VEHICLE_MAP_SERVICE) - .setAreaId(VehicleAreaType.VEHICLE_AREA_TYPE_NONE) - .setTimestamp(SystemClock.elapsedRealtimeNanos()) - .build(); - v.value.int32Values.add(VmsMessageType.DATA); // MessageType - v.value.int32Values.add(SUBSCRIPTION_LAYER_ID); - v.value.int32Values.add(MOCK_PUBLISHER_LAYER_SUBTYPE); - v.value.int32Values.add(SUBSCRIPTION_LAYER_VERSION); - v.value.int32Values.add(PUBLISHER_ID); - v.value.bytes.add((byte) 0xa); - v.value.bytes.add((byte) 0xb); - assertEquals(0, mSubscriberSemaphore.availablePermits()); - - getMockedVehicleHal().injectEvent(v); - assertTrue(mSubscriberSemaphore.tryAcquire(2L, TimeUnit.SECONDS)); - assertEquals(SUBSCRIPTION_LAYER, clientCallback.getLayer()); - byte[] expectedPayload = {(byte) 0xa, (byte) 0xb}; - assertTrue(Arrays.equals(expectedPayload, clientCallback.getPayload())); - } - - // Test injecting a value in the HAL and verifying it propagates to a subscriber. - public void testSimpleAvailableLayers() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - VmsSubscriberManager vmsSubscriberManager = (VmsSubscriberManager) getCar().getCarManager( - Car.VMS_SUBSCRIBER_SERVICE); - TestClientCallback clientCallback = new TestClientCallback(); - vmsSubscriberManager.registerClientCallback(clientCallback); - - // Inject a value and wait for its callback in TestClientCallback.onLayersAvailabilityChanged. - VehiclePropValue v = VehiclePropValueBuilder.newBuilder(VehicleProperty.VEHICLE_MAP_SERVICE) - .setAreaId(VehicleAreaType.VEHICLE_AREA_TYPE_NONE) - .setTimestamp(SystemClock.elapsedRealtimeNanos()) - .build(); - /* - Offering: - Layer | Dependency - =============================== - (2, 3, 444), [17] | {} - - Expected availability: - {(2, 3, 444 [17])} - */ - v.value.int32Values.addAll( - Arrays.asList( - VmsMessageType.OFFERING, // MessageType - PUBLISHER_ID, - 1, // Number of offered layers - - SUBSCRIPTION_LAYER_ID, - MOCK_PUBLISHER_LAYER_SUBTYPE, - SUBSCRIPTION_LAYER_VERSION, - 0 // number of dependencies for layer - ) - ); - - assertEquals(0, mSubscriberSemaphore.availablePermits()); - - getMockedVehicleHal().injectEvent(v); - assertTrue(mSubscriberSemaphore.tryAcquire(2L, TimeUnit.SECONDS)); - List<VmsAssociatedLayer> expectedAvailableLayers = - new ArrayList<>(Arrays.asList(SUBSCRIPTION_ASSOCIATED_LAYER)); - assertTrue(expectedAvailableLayers.containsAll(clientCallback.getAvailableLayers())); - assertEquals(expectedAvailableLayers.size(), clientCallback.getAvailableLayers().size()); - } - - // Test injecting a value in the HAL and verifying it propagates to a subscriber after it has - // subscribed to a layer. - public void testSimpleAvailableLayersAfterSubscription() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - VmsSubscriberManager vmsSubscriberManager = (VmsSubscriberManager) getCar().getCarManager( - Car.VMS_SUBSCRIBER_SERVICE); - TestClientCallback clientCallback = new TestClientCallback(); - vmsSubscriberManager.registerClientCallback(clientCallback); - vmsSubscriberManager.subscribe(SUBSCRIPTION_LAYER); - - // Inject a value and wait for its callback in TestClientCallback.onLayersAvailabilityChanged. - VehiclePropValue v = VehiclePropValueBuilder.newBuilder(VehicleProperty.VEHICLE_MAP_SERVICE) - .setAreaId(VehicleAreaType.VEHICLE_AREA_TYPE_NONE) - .setTimestamp(SystemClock.elapsedRealtimeNanos()) - .build(); - /* - Offering: - Layer | Dependency - =============================== - (2, 3, 444), [17] | {} - - Expected availability: - {(2, 3, 444 [17])} - */ - v.value.int32Values.addAll( - Arrays.asList( - VmsMessageType.OFFERING, // MessageType - PUBLISHER_ID, - 1, // Number of offered layers - - SUBSCRIPTION_LAYER_ID, - MOCK_PUBLISHER_LAYER_SUBTYPE, - SUBSCRIPTION_LAYER_VERSION, - 0 // number of dependencies for layer - ) - ); - - assertEquals(0, mSubscriberSemaphore.availablePermits()); - - getMockedVehicleHal().injectEvent(v); - assertTrue(mSubscriberSemaphore.tryAcquire(2L, TimeUnit.SECONDS)); - List<VmsAssociatedLayer> expectedAvailableLayers = - new ArrayList<>(Arrays.asList(SUBSCRIPTION_ASSOCIATED_LAYER)); - assertTrue(expectedAvailableLayers.containsAll(clientCallback.getAvailableLayers())); - assertEquals(expectedAvailableLayers.size(), clientCallback.getAvailableLayers().size()); - } - - // Test injecting a value in the HAL and verifying it does not propagates to a subscriber after - // it has unregistered its callback. - public void testSimpleAvailableLayersAfterUnregister() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - VmsSubscriberManager vmsSubscriberManager = (VmsSubscriberManager) getCar().getCarManager( - Car.VMS_SUBSCRIBER_SERVICE); - TestClientCallback clientCallback = new TestClientCallback(); - vmsSubscriberManager.registerClientCallback(clientCallback); - vmsSubscriberManager.unregisterClientCallback(); - - - // Inject a value and wait for its callback in TestClientCallback.onLayersAvailabilityChanged. - VehiclePropValue v = VehiclePropValueBuilder.newBuilder(VehicleProperty.VEHICLE_MAP_SERVICE) - .setAreaId(VehicleAreaType.VEHICLE_AREA_TYPE_NONE) - .setTimestamp(SystemClock.elapsedRealtimeNanos()) - .build(); - /* - Offering: - Layer | Dependency - =============================== - (2, 3, 444), [17] | {} - - Expected availability: - {(2, 3, 444 [17])} - */ - v.value.int32Values.addAll( - Arrays.asList( - VmsMessageType.OFFERING, // MessageType - PUBLISHER_ID, - 1, // Number of offered layers - - SUBSCRIPTION_LAYER_ID, - SUBSCRIPTION_LAYER_VERSION, - MOCK_PUBLISHER_LAYER_SUBTYPE, - 0 // number of dependencies for layer - ) - ); - - assertEquals(0, mSubscriberSemaphore.availablePermits()); - getMockedVehicleHal().injectEvent(v); - assertFalse(mSubscriberSemaphore.tryAcquire(2L, TimeUnit.SECONDS)); - } - - // Test injecting a value in the HAL and verifying it does not propagates to a subscriber after - // it has unregistered its callback. - public void testSomething() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - VmsSubscriberManager vmsSubscriberManager = (VmsSubscriberManager) getCar().getCarManager( - Car.VMS_SUBSCRIBER_SERVICE); - TestClientCallback clientCallback = new TestClientCallback(); - vmsSubscriberManager.registerClientCallback(clientCallback); - vmsSubscriberManager.subscribe(SUBSCRIPTION_LAYER); - try { - vmsSubscriberManager.unregisterClientCallback(); - } catch (IllegalArgumentException e) { - return; - } - fail(); - } - - - // Test injecting a value in the HAL and verifying it propagates to a subscriber. - public void testComplexAvailableLayers() throws Exception { - if (!VmsTestUtils.canRunTest(TAG)) return; - VmsSubscriberManager vmsSubscriberManager = (VmsSubscriberManager) getCar().getCarManager( - Car.VMS_SUBSCRIBER_SERVICE); - TestClientCallback clientCallback = new TestClientCallback(); - vmsSubscriberManager.registerClientCallback(clientCallback); - - // Inject a value and wait for its callback in TestClientCallback.onLayersAvailabilityChanged. - VehiclePropValue v = VehiclePropValueBuilder.newBuilder(VehicleProperty.VEHICLE_MAP_SERVICE) - .setAreaId(VehicleAreaType.VEHICLE_AREA_TYPE_NONE) - .setTimestamp(SystemClock.elapsedRealtimeNanos()) - .build(); - /* - Offering: - Layer | Dependency - ==================== - (2, 3, 444), [17] | {} - (4, 5, 444), [17] | {(2, 3)} - (6, 7, 444), [17] | {(2, 3), (4, 5)} - (6, 7, 444), [17] | {(100, 200)} - - Expected availability: - {(2, 3, 444 [17]), (4, 5, 444 [17]), (6, 7, 444 [17])} - */ - - v.value.int32Values.addAll( - Arrays.asList( - VmsMessageType.OFFERING, // MessageType - PUBLISHER_ID, - 4, // Number of offered layers - - SUBSCRIPTION_LAYER_ID, - MOCK_PUBLISHER_LAYER_SUBTYPE, - SUBSCRIPTION_LAYER_VERSION, - 0, // number of dependencies for layer - - SUBSCRIPTION_DEPENDANT_LAYER_ID_1, - MOCK_PUBLISHER_LAYER_SUBTYPE, - SUBSCRIPTION_DEPENDANT_LAYER_VERSION_1, - 1, // number of dependencies for layer - SUBSCRIPTION_LAYER_ID, - MOCK_PUBLISHER_LAYER_SUBTYPE, - SUBSCRIPTION_LAYER_VERSION, - - SUBSCRIPTION_DEPENDANT_LAYER_ID_2, - MOCK_PUBLISHER_LAYER_SUBTYPE, - SUBSCRIPTION_DEPENDANT_LAYER_VERSION_2, - 2, // number of dependencies for layer - SUBSCRIPTION_LAYER_ID, - MOCK_PUBLISHER_LAYER_SUBTYPE, - SUBSCRIPTION_LAYER_VERSION, - SUBSCRIPTION_DEPENDANT_LAYER_ID_1, - MOCK_PUBLISHER_LAYER_SUBTYPE, - SUBSCRIPTION_DEPENDANT_LAYER_VERSION_1, - - SUBSCRIPTION_DEPENDANT_LAYER_ID_2, - MOCK_PUBLISHER_LAYER_SUBTYPE, - SUBSCRIPTION_DEPENDANT_LAYER_VERSION_2, - 1, // number of dependencies for layer - SUBSCRIPTION_UNSUPPORTED_LAYER_ID, - MOCK_PUBLISHER_LAYER_SUBTYPE, - SUBSCRIPTION_UNSUPPORTED_LAYER_VERSION - ) - ); - - assertEquals(0, mSubscriberSemaphore.availablePermits()); - - List<VmsAssociatedLayer> expectedAvailableLayers = - new ArrayList<>(Arrays.asList( - SUBSCRIPTION_ASSOCIATED_LAYER, - SUBSCRIPTION_DEPENDANT_ASSOCIATED_LAYER_1, - SUBSCRIPTION_DEPENDANT_ASSOCIATED_LAYER_2 - )); - getMockedVehicleHal().injectEvent(v); - assertTrue(mSubscriberSemaphore.tryAcquire(2L, TimeUnit.SECONDS)); - assertTrue(expectedAvailableLayers.containsAll(clientCallback.getAvailableLayers())); - assertEquals(expectedAvailableLayers.size(), clientCallback.getAvailableLayers().size()); - } - - private class HalHandler implements VehicleHalPropertyHandler { - private VehiclePropValue mValue; - - @Override - public synchronized void onPropertySet(VehiclePropValue value) { - mValue = value; - mHalHandlerSemaphore.release(); - } - - @Override - public synchronized VehiclePropValue onPropertyGet(VehiclePropValue value) { - return mValue != null ? mValue : value; - } - - @Override - public synchronized void onPropertySubscribe(int property, int zones, float sampleRate) { - Log.d(TAG, "onPropertySubscribe property " + property + " sampleRate " + sampleRate); - } - - @Override - public synchronized void onPropertyUnsubscribe(int property) { - Log.d(TAG, "onPropertyUnSubscribe property " + property); - } - - public VehiclePropValue getValue() { - return mValue; - } - } - - private class TestClientCallback implements VmsSubscriberClientCallback { - private VmsLayer mLayer; - private byte[] mPayload; - private List<VmsLayer> mAvailableLayers = new ArrayList<>(); - - @Override - public void onVmsMessageReceived(VmsLayer layer, byte[] payload) { - Log.d(TAG, "onVmsMessageReceived: layer: " + layer + " Payload: " + payload); - mLayer = layer; - mPayload = payload; - mSubscriberSemaphore.release(); - } - - @Override - public void onLayersAvailabilityChanged(List<VmsLayer> availableLayers) { - Log.d(TAG, "onLayersAvailabilityChanged: Layers: " + availableLayers); - mAvailableLayers.addAll(availableLayers); - mSubscriberSemaphore.release(); - } - - public VmsLayer getLayer() { - return mLayer; - } - - public byte[] getPayload() { - return mPayload; - } - - public List<VmsLayer> getAvailableLayers() { - return mAvailableLayers; - } - } -} diff --git a/tests/carservice_test/src/com/android/car/test/VmsTestUtils.java b/tests/carservice_test/src/com/android/car/test/VmsTestUtils.java deleted file mode 100644 index 2f3af52a09..0000000000 --- a/tests/carservice_test/src/com/android/car/test/VmsTestUtils.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.android.car.test; - -import android.car.annotation.FutureFeature; -import android.util.Log; - -import com.android.car.internal.FeatureConfiguration; - -@FutureFeature -public class VmsTestUtils { - public static boolean canRunTest(String tag) { - if (!FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE) { - Log.i(tag, "Skipping test because ENABLE_VEHICLE_MAP_SERVICE = false"); - } - return FeatureConfiguration.ENABLE_VEHICLE_MAP_SERVICE; - } -} diff --git a/tests/carservice_unit_test/src/com/android/car/VmsLayersAvailabilityTest.java b/tests/carservice_unit_test/src/com/android/car/VmsLayersAvailabilityTest.java deleted file mode 100644 index 4a09d4f89e..0000000000 --- a/tests/carservice_unit_test/src/com/android/car/VmsLayersAvailabilityTest.java +++ /dev/null @@ -1,266 +0,0 @@ -/* - * 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 com.android.car; - -import android.car.vms.VmsAssociatedLayer; -import android.car.vms.VmsLayer; -import android.car.vms.VmsLayerDependency; -import android.car.vms.VmsLayersOffering; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.SmallTest; - -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -@SmallTest -public class VmsLayersAvailabilityTest extends AndroidTestCase { - - private static final VmsLayer LAYER_X = new VmsLayer(1, 1, 2); - private static final VmsLayer LAYER_Y = new VmsLayer(3, 2, 4); - private static final VmsLayer LAYER_Z = new VmsLayer(5, 3, 6); - - private static final int PUBLISHER_ID_1 = 19; - private static final int PUBLISHER_ID_2 = 28; - - private static final Set<Integer> PUBLISHERS_1 = new HashSet<>(Arrays.asList(PUBLISHER_ID_1)); - private static final Set<Integer> PUBLISHERS_2 = new HashSet<>(Arrays.asList(PUBLISHER_ID_2)); - private static final Set<Integer> PUBLISHERS_1_AND_2 = - new HashSet<>(Arrays.asList(PUBLISHER_ID_1, PUBLISHER_ID_2)); - - private static final VmsLayerDependency X_DEPENDS_ON_Y = - new VmsLayerDependency(LAYER_X, new HashSet<VmsLayer>(Arrays.asList(LAYER_Y))); - - private static final VmsLayerDependency X_DEPENDS_ON_Z = - new VmsLayerDependency(LAYER_X, new HashSet<VmsLayer>(Arrays.asList(LAYER_Z))); - - private static final VmsLayerDependency Y_DEPENDS_ON_Z = - new VmsLayerDependency(LAYER_Y, new HashSet<VmsLayer>(Arrays.asList(LAYER_Z))); - - private static final VmsLayerDependency Y_DEPENDS_ON_X = - new VmsLayerDependency(LAYER_Y, new HashSet<VmsLayer>(Arrays.asList(LAYER_X))); - - private static final VmsLayerDependency Z_DEPENDS_ON_X = - new VmsLayerDependency(LAYER_Z, new HashSet<VmsLayer>(Arrays.asList(LAYER_X))); - - private static final VmsLayerDependency Z_DEPENDS_ON_NOTHING = - new VmsLayerDependency(LAYER_Z); - - private static final VmsLayerDependency X_DEPENDS_ON_SELF = - new VmsLayerDependency(LAYER_X, new HashSet<VmsLayer>(Arrays.asList(LAYER_X))); - - private Set<VmsLayersOffering> mOfferings; - private VmsLayersAvailability mLayersAvailability; - - @Override - protected void setUp() throws Exception { - mLayersAvailability = new VmsLayersAvailability(); - mOfferings = new HashSet<>(); - super.setUp(); - } - - public void testNoOffering() { - assertTrue(mLayersAvailability.getAvailableLayers().isEmpty()); - } - - public void testEmptyOffering() { - mLayersAvailability.setPublishersOffering(Collections.EMPTY_LIST); - assertTrue(mLayersAvailability.getAvailableLayers().isEmpty()); - } - - public void testSingleLayerNoDeps() throws Exception { - Set<VmsAssociatedLayer> expectedAvailableAssociatedLayers = new HashSet<>(); - expectedAvailableAssociatedLayers.add(new VmsAssociatedLayer(LAYER_X, PUBLISHERS_2)); - - VmsLayersOffering offering = - new VmsLayersOffering(new HashSet<>(Arrays.asList(new VmsLayerDependency(LAYER_X))), - PUBLISHER_ID_2); - - mOfferings.add(offering); - mLayersAvailability.setPublishersOffering(mOfferings); - - assertEquals(expectedAvailableAssociatedLayers, mLayersAvailability.getAvailableLayers()); - } - - public void testChainOfDependenciesSatisfied() throws Exception { - Set<VmsAssociatedLayer> expectedAvailableAssociatedLayers = new HashSet<>(); - expectedAvailableAssociatedLayers.add(new VmsAssociatedLayer(LAYER_X, PUBLISHERS_1)); - expectedAvailableAssociatedLayers.add(new VmsAssociatedLayer(LAYER_Y, PUBLISHERS_1)); - expectedAvailableAssociatedLayers.add(new VmsAssociatedLayer(LAYER_Z, PUBLISHERS_1)); - - VmsLayersOffering offering = - new VmsLayersOffering( - new HashSet<>(Arrays.asList(X_DEPENDS_ON_Y, Y_DEPENDS_ON_Z, Z_DEPENDS_ON_NOTHING)), - PUBLISHER_ID_1); - - mOfferings.add(offering); - mLayersAvailability.setPublishersOffering(mOfferings); - - assertEquals(expectedAvailableAssociatedLayers, - new HashSet<VmsAssociatedLayer>(mLayersAvailability.getAvailableLayers())); - } - - public void testChainOfDependenciesSatisfiedTwoOfferings() throws Exception { - Set<VmsAssociatedLayer> expectedAvailableAssociatedLayers = new HashSet<>(); - expectedAvailableAssociatedLayers.add(new VmsAssociatedLayer(LAYER_X, PUBLISHERS_1)); - expectedAvailableAssociatedLayers.add(new VmsAssociatedLayer(LAYER_Y, PUBLISHERS_1)); - expectedAvailableAssociatedLayers.add(new VmsAssociatedLayer(LAYER_Z, PUBLISHERS_1)); - - VmsLayersOffering offering1 = - new VmsLayersOffering( - new HashSet<>(Arrays.asList(X_DEPENDS_ON_Y, Y_DEPENDS_ON_Z)), - PUBLISHER_ID_1); - - VmsLayersOffering offering2 = - new VmsLayersOffering(new HashSet<>(Arrays.asList(Z_DEPENDS_ON_NOTHING)), - PUBLISHER_ID_1); - - mOfferings.add(offering1); - mOfferings.add(offering2); - mLayersAvailability.setPublishersOffering(mOfferings); - - assertEquals(expectedAvailableAssociatedLayers, - new HashSet<VmsAssociatedLayer>(mLayersAvailability.getAvailableLayers())); - } - - public void testChainOfDependencieNotSatisfied() throws Exception { - Set<VmsAssociatedLayer> expectedAvailableAssociatedLayers = new HashSet<>(); - VmsLayersOffering offering = - new VmsLayersOffering(new HashSet<>(Arrays.asList(X_DEPENDS_ON_Y, Y_DEPENDS_ON_Z)), - PUBLISHER_ID_1); - - mOfferings.add(offering); - mLayersAvailability.setPublishersOffering(mOfferings); - - assertEquals(expectedAvailableAssociatedLayers, - new HashSet<VmsAssociatedLayer>(mLayersAvailability.getAvailableLayers())); - - Set<VmsAssociatedLayer> expectedUnavailableAssociatedLayers = new HashSet<>(); - expectedUnavailableAssociatedLayers.add(new VmsAssociatedLayer(LAYER_X, PUBLISHERS_1)); - expectedUnavailableAssociatedLayers.add(new VmsAssociatedLayer(LAYER_Y, PUBLISHERS_1)); - - - assertEquals(expectedUnavailableAssociatedLayers, - new HashSet<VmsAssociatedLayer>(mLayersAvailability.getUnavailableLayers())); - } - - public void testOneOfMultipleDependencySatisfied() throws Exception { - Set<VmsAssociatedLayer> expectedAvailableAssociatedLayers = new HashSet<>(); - expectedAvailableAssociatedLayers.add(new VmsAssociatedLayer(LAYER_X, PUBLISHERS_1)); - expectedAvailableAssociatedLayers.add(new VmsAssociatedLayer(LAYER_Z, PUBLISHERS_1)); - - - VmsLayersOffering offering = - new VmsLayersOffering( - new HashSet<>(Arrays.asList( - X_DEPENDS_ON_Y, X_DEPENDS_ON_Z, Z_DEPENDS_ON_NOTHING)), - PUBLISHER_ID_1); - - mOfferings.add(offering); - mLayersAvailability.setPublishersOffering(mOfferings); - - assertEquals(expectedAvailableAssociatedLayers, - new HashSet<VmsAssociatedLayer>(mLayersAvailability.getAvailableLayers())); - } - - public void testCyclicDependency() throws Exception { - Set<VmsAssociatedLayer> expectedAvailableAssociatedLayers = new HashSet<>(); - - VmsLayersOffering offering = - new VmsLayersOffering( - new HashSet<>( - Arrays.asList(X_DEPENDS_ON_Y, Y_DEPENDS_ON_Z, Z_DEPENDS_ON_X)), - PUBLISHER_ID_1); - - mOfferings.add(offering); - mLayersAvailability.setPublishersOffering(mOfferings); - - assertEquals(expectedAvailableAssociatedLayers, - new HashSet<VmsAssociatedLayer>(mLayersAvailability.getAvailableLayers())); - } - - public void testAlmostCyclicDependency() throws Exception { - Set<VmsAssociatedLayer> expectedAvailableAssociatedLayers = new HashSet<>(); - expectedAvailableAssociatedLayers.add(new VmsAssociatedLayer(LAYER_Z, PUBLISHERS_1_AND_2)); - expectedAvailableAssociatedLayers.add(new VmsAssociatedLayer(LAYER_X, PUBLISHERS_1)); - expectedAvailableAssociatedLayers.add(new VmsAssociatedLayer(LAYER_Y, PUBLISHERS_2)); - - VmsLayersOffering offering1 = - new VmsLayersOffering( - new HashSet<>(Arrays.asList(X_DEPENDS_ON_Y, Z_DEPENDS_ON_NOTHING)), - PUBLISHER_ID_1); - - VmsLayersOffering offering2 = - new VmsLayersOffering(new HashSet<>(Arrays.asList(Y_DEPENDS_ON_Z, Z_DEPENDS_ON_X)), - PUBLISHER_ID_2); - - mOfferings.add(offering1); - mOfferings.add(offering2); - mLayersAvailability.setPublishersOffering(mOfferings); - - assertEquals(expectedAvailableAssociatedLayers, mLayersAvailability.getAvailableLayers()); - } - - public void testCyclicDependencyAndLayerWithoutDependency() throws Exception { - Set<VmsAssociatedLayer> expectedAvailableAssociatedLayers = new HashSet<>(); - expectedAvailableAssociatedLayers.add(new VmsAssociatedLayer(LAYER_Z, PUBLISHERS_1)); - - VmsLayersOffering offering1 = - new VmsLayersOffering( - new HashSet<>( - Arrays.asList(X_DEPENDS_ON_Y, Z_DEPENDS_ON_NOTHING)), - PUBLISHER_ID_1); - - VmsLayersOffering offering2 = - new VmsLayersOffering(new HashSet<>(Arrays.asList(Y_DEPENDS_ON_X)), PUBLISHER_ID_2); - - mOfferings.add(offering1); - mOfferings.add(offering2); - mLayersAvailability.setPublishersOffering(mOfferings); - - assertEquals(expectedAvailableAssociatedLayers, - new HashSet<VmsAssociatedLayer>(mLayersAvailability.getAvailableLayers())); - - Set<VmsAssociatedLayer> expectedUnavailableAssociatedLayers = new HashSet<>(); - expectedUnavailableAssociatedLayers.add(new VmsAssociatedLayer(LAYER_X, PUBLISHERS_1)); - expectedUnavailableAssociatedLayers.add(new VmsAssociatedLayer(LAYER_Y, PUBLISHERS_2)); - - assertEquals(expectedUnavailableAssociatedLayers, - new HashSet<VmsAssociatedLayer>(mLayersAvailability.getUnavailableLayers())); - } - - public void testSelfDependency() throws Exception { - Set<VmsAssociatedLayer> expectedAvailableAssociatedLayers = new HashSet<>(); - - VmsLayersOffering offering = - new VmsLayersOffering(new HashSet<>(Arrays.asList(X_DEPENDS_ON_SELF)), - PUBLISHER_ID_1); - - mOfferings.add(offering); - mLayersAvailability.setPublishersOffering(mOfferings); - - assertEquals(expectedAvailableAssociatedLayers, - new HashSet<VmsAssociatedLayer>(mLayersAvailability.getAvailableLayers())); - - Set<VmsAssociatedLayer> expectedUnavailableAssociatedLayers = new HashSet<>(); - expectedUnavailableAssociatedLayers.add(new VmsAssociatedLayer(LAYER_X, PUBLISHERS_1)); - - assertEquals(expectedUnavailableAssociatedLayers, - new HashSet<VmsAssociatedLayer>(mLayersAvailability.getUnavailableLayers())); - } -}
\ No newline at end of file diff --git a/tests/carservice_unit_test/src/com/android/car/VmsPublishersInfoTest.java b/tests/carservice_unit_test/src/com/android/car/VmsPublishersInfoTest.java deleted file mode 100644 index 2b75012950..0000000000 --- a/tests/carservice_unit_test/src/com/android/car/VmsPublishersInfoTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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 com.android.car; - -import android.car.annotation.FutureFeature; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.SmallTest; - -import java.util.Arrays; -import java.util.Map; - -@FutureFeature -@SmallTest -public class VmsPublishersInfoTest extends AndroidTestCase { - public static final byte[] MOCK_INFO_0 = new byte[]{2, 3, 5, 7, 11, 13, 17}; - public static final byte[] SAME_MOCK_INFO_0 = new byte[]{2, 3, 5, 7, 11, 13, 17}; - public static final byte[] MOCK_INFO_1 = new byte[]{2, 3, 5, 7, 11, 13, 17, 19}; - - private VmsPublishersInfo mVmsPublishersInfo; - - @Override - protected void setUp() throws Exception { - super.setUp(); - mVmsPublishersInfo = new VmsPublishersInfo(); - } - - // Test one info sanity - public void testSingleInfo() throws Exception { - int id = mVmsPublishersInfo.getIdForInfo(MOCK_INFO_0); - assertEquals(0, id); - - byte[] info = mVmsPublishersInfo.getPublisherInfo(id); - assertTrue(Arrays.equals(MOCK_INFO_0, info)); - } - - // Test one info sanity - wrong ID fails. - public void testSingleInfoWrongId() throws Exception { - int id = mVmsPublishersInfo.getIdForInfo(MOCK_INFO_0); - assertEquals(0, id); - - try { - byte[] info = mVmsPublishersInfo.getPublisherInfo(id + 1); - } - catch (NullPointerException e) { - return; - } - fail(); - } - - // Test two infos. - public void testTwoInfos() throws Exception { - int id0 = mVmsPublishersInfo.getIdForInfo(MOCK_INFO_0); - int id1 = mVmsPublishersInfo.getIdForInfo(MOCK_INFO_1); - assertEquals(0, id0); - assertEquals(1, id1); - - byte[] info0 = mVmsPublishersInfo.getPublisherInfo(id0); - byte[] info1 = mVmsPublishersInfo.getPublisherInfo(id1); - assertTrue(Arrays.equals(MOCK_INFO_0, info0)); - assertTrue(Arrays.equals(MOCK_INFO_1, info1)); - } - - // Test same info twice get the same ID. - public void testSingleInfoInsertedTwice() throws Exception { - int id = mVmsPublishersInfo.getIdForInfo(MOCK_INFO_0); - assertEquals(0, id); - - int sameId = mVmsPublishersInfo.getIdForInfo(SAME_MOCK_INFO_0); - assertEquals(sameId, id); - } -} diff --git a/tests/carservice_unit_test/src/com/android/car/VmsRoutingTest.java b/tests/carservice_unit_test/src/com/android/car/VmsRoutingTest.java deleted file mode 100644 index 8fe849b705..0000000000 --- a/tests/carservice_unit_test/src/com/android/car/VmsRoutingTest.java +++ /dev/null @@ -1,309 +0,0 @@ -/* - * 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 com.android.car; - -import android.car.vms.IVmsSubscriberClient; -import android.car.vms.VmsAssociatedLayer; -import android.car.vms.VmsLayer; -import android.car.vms.VmsSubscriptionState; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.SmallTest; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.Map; - -@SmallTest -public class VmsRoutingTest extends AndroidTestCase { - private static VmsLayer LAYER_WITH_SUBSCRIPTION_1 = new VmsLayer(1, 1, 2); - private static VmsLayer LAYER_WITH_SUBSCRIPTION_2 = new VmsLayer(1, 3, 3); - private static VmsLayer LAYER_WITHOUT_SUBSCRIPTION = - new VmsLayer(1, 7, 4); - private static int PUBLISHER_ID_1 = 123; - private static int PUBLISHER_ID_2 = 456; - private static int PUBLISHER_ID_UNLISTED = 789; - private VmsRouting mRouting; - - @Override - protected void setUp() throws Exception { - super.setUp(); - mRouting = new VmsRouting(); - } - - public void testAddingSubscribersAndHalLayersNoOverlap() throws Exception { - // Add a subscription to a layer. - MockVmsSubscriber subscriber = new MockVmsSubscriber(); - mRouting.addSubscription(subscriber, LAYER_WITH_SUBSCRIPTION_1); - - // Add a HAL subscription. - mRouting.addHalSubscription(LAYER_WITH_SUBSCRIPTION_2); - - // Verify expected subscriptions are in routing manager. - Set<VmsLayer> expectedSubscriptions = new HashSet<>(); - expectedSubscriptions.add(LAYER_WITH_SUBSCRIPTION_1); - expectedSubscriptions.add(LAYER_WITH_SUBSCRIPTION_2); - VmsSubscriptionState subscriptionState = mRouting.getSubscriptionState(); - assertEquals(2, subscriptionState.getSequenceNumber()); - assertEquals(expectedSubscriptions, - new HashSet<>(subscriptionState.getLayers())); - - // Verify there is only a single subscriber. - assertEquals(1, - mRouting.getSubscribersForLayerFromPublisher( - LAYER_WITH_SUBSCRIPTION_1, PUBLISHER_ID_1).size()); - } - - public void testAddingSubscribersAndHalLayersWithOverlap() throws Exception { - // Add a subscription to a layer. - MockVmsSubscriber subscriber = new MockVmsSubscriber(); - mRouting.addSubscription(subscriber, LAYER_WITH_SUBSCRIPTION_1); - mRouting.addSubscription(subscriber, LAYER_WITH_SUBSCRIPTION_2); - - // Add a HAL subscription to a layer there is already another subscriber for. - mRouting.addHalSubscription(LAYER_WITH_SUBSCRIPTION_2); - - // Verify expected subscriptions are in routing manager. - Set<VmsLayer> expectedSubscriptions = new HashSet<>(); - expectedSubscriptions.add(LAYER_WITH_SUBSCRIPTION_1); - expectedSubscriptions.add(LAYER_WITH_SUBSCRIPTION_2); - VmsSubscriptionState subscriptionState = mRouting.getSubscriptionState(); - assertEquals(3, subscriptionState.getSequenceNumber()); - assertEquals(expectedSubscriptions, - new HashSet<>(subscriptionState.getLayers())); - } - - public void testAddingAndRemovingLayers() throws Exception { - // Add a subscription to a layer. - MockVmsSubscriber subscriber = new MockVmsSubscriber(); - mRouting.addSubscription(subscriber, LAYER_WITH_SUBSCRIPTION_1); - - // Add a HAL subscription. - mRouting.addHalSubscription(LAYER_WITH_SUBSCRIPTION_2); - - // Remove a subscription to a layer. - mRouting.removeSubscription(subscriber, LAYER_WITH_SUBSCRIPTION_1); - - // Update the HAL subscription - mRouting.removeHalSubscription(LAYER_WITH_SUBSCRIPTION_2); - - // Verify there are no subscribers in the routing manager. - VmsSubscriptionState subscriptionState = mRouting.getSubscriptionState(); - assertEquals(4, subscriptionState.getSequenceNumber()); - assertTrue(subscriptionState.getLayers().isEmpty()); - } - - public void testAddingBothTypesOfSubscribers() throws Exception { - // Add a subscription to a layer. - MockVmsSubscriber subscriberForLayer = new MockVmsSubscriber(); - mRouting.addSubscription(subscriberForLayer, LAYER_WITH_SUBSCRIPTION_1); - - // Add a subscription without a layer. - MockVmsSubscriber subscriberWithoutLayer = new MockVmsSubscriber(); - mRouting.addSubscription(subscriberWithoutLayer); - - // Verify 2 subscribers for the layer. - assertEquals(2, - mRouting.getSubscribersForLayerFromPublisher( - LAYER_WITH_SUBSCRIPTION_1, PUBLISHER_ID_1).size()); - - // Add the subscriber with layer as also a subscriber without layer - mRouting.addSubscription(subscriberForLayer); - - // The number of subscribers for the layer should remain the same as before. - assertEquals(2, - mRouting.getSubscribersForLayerFromPublisher( - LAYER_WITH_SUBSCRIPTION_1, PUBLISHER_ID_1).size()); - } - - public void testOnlyRelevantSubscribers() throws Exception { - // Add a subscription to a layer. - MockVmsSubscriber subscriberForLayer = new MockVmsSubscriber(); - mRouting.addSubscription(subscriberForLayer, LAYER_WITH_SUBSCRIPTION_1); - - // Add a subscription without a layer. - MockVmsSubscriber subscriberWithoutLayer = new MockVmsSubscriber(); - mRouting.addSubscription(subscriberWithoutLayer); - - // Verify that only the subscriber without layer is returned. - Set<MockVmsSubscriber> expectedListeneres = new HashSet<MockVmsSubscriber>(); - expectedListeneres.add(subscriberWithoutLayer); - assertEquals(expectedListeneres, - mRouting.getSubscribersForLayerFromPublisher( - LAYER_WITHOUT_SUBSCRIPTION, PUBLISHER_ID_1)); - } - - public void testAddingSubscribersAndHalLayersAndSubscribersToPublishers() throws Exception { - // Add a subscription to a layer. - MockVmsSubscriber subscriber = new MockVmsSubscriber(); - mRouting.addSubscription(subscriber, LAYER_WITH_SUBSCRIPTION_1); - - // Add a HAL subscription. - mRouting.addHalSubscription(LAYER_WITH_SUBSCRIPTION_2); - - mRouting.addSubscription(subscriber, LAYER_WITH_SUBSCRIPTION_1, PUBLISHER_ID_1); - mRouting.addSubscription(subscriber, LAYER_WITH_SUBSCRIPTION_1, PUBLISHER_ID_2); - mRouting.addSubscription(subscriber, LAYER_WITH_SUBSCRIPTION_2, PUBLISHER_ID_2); - - // Verify expected subscriptions are in routing manager. - Set<VmsLayer> expectedSubscriptions = new HashSet<>(); - expectedSubscriptions.add(LAYER_WITH_SUBSCRIPTION_1); - expectedSubscriptions.add(LAYER_WITH_SUBSCRIPTION_2); - - Set<VmsAssociatedLayer> expectedSubscriptionsToPublishers = new HashSet<>(); - expectedSubscriptionsToPublishers.add(new VmsAssociatedLayer(LAYER_WITH_SUBSCRIPTION_1, - new HashSet(Arrays.asList(PUBLISHER_ID_1, PUBLISHER_ID_2)))); - expectedSubscriptionsToPublishers.add(new VmsAssociatedLayer(LAYER_WITH_SUBSCRIPTION_2, - new HashSet(Arrays.asList(PUBLISHER_ID_2)))); - - VmsSubscriptionState subscriptionState = mRouting.getSubscriptionState(); - assertEquals(5, subscriptionState.getSequenceNumber()); - assertEquals(expectedSubscriptions, - new HashSet<>(subscriptionState.getLayers())); - - assertEquals(expectedSubscriptionsToPublishers, - subscriptionState.getAssociatedLayers()); - - // Verify there is only a single subscriber. - assertEquals(1, - mRouting.getSubscribersForLayerFromPublisher( - LAYER_WITH_SUBSCRIPTION_1, PUBLISHER_ID_1).size()); - } - - public void testAddingSubscriberToPublishersAndGetListeneresToDifferentPublisher() - throws Exception { - // Add a subscription to a layer. - MockVmsSubscriber subscriber = new MockVmsSubscriber(); - - mRouting.addSubscription(subscriber, LAYER_WITH_SUBSCRIPTION_2); - mRouting.addSubscription(subscriber, LAYER_WITH_SUBSCRIPTION_1, PUBLISHER_ID_1); - - Set<IVmsSubscriberClient> subscribers; - // Need to route a layer 1 message from publisher 2 so there are no subscribers. - subscribers = - mRouting.getSubscribersForLayerFromPublisher( - LAYER_WITH_SUBSCRIPTION_1, - PUBLISHER_ID_2); - assertEquals(0, subscribers.size()); - - // Need to route a layer 1 message from publisher 1 so there is one subscriber. - subscribers = - mRouting.getSubscribersForLayerFromPublisher( - LAYER_WITH_SUBSCRIPTION_1, - PUBLISHER_ID_1); - assertEquals(1, subscribers.size()); - assertTrue(subscribers.contains(subscriber)); - - // Verify all the messages for LAYER_WITH_SUBSCRIPTION_2 have subscribers since the - // subscription was done without specifying a specific publisher. - subscribers = - mRouting.getSubscribersForLayerFromPublisher( - LAYER_WITH_SUBSCRIPTION_2, - PUBLISHER_ID_UNLISTED); - assertEquals(1, subscribers.size()); - assertTrue(subscribers.contains(subscriber)); - } - - - public void testRemovalOfSubscribersToPublishers() throws Exception { - // Add a subscription to a layer. - MockVmsSubscriber subscriber = new MockVmsSubscriber(); - mRouting.addSubscription(subscriber, LAYER_WITH_SUBSCRIPTION_1); - - // Add a HAL subscription. - mRouting.addHalSubscription(LAYER_WITH_SUBSCRIPTION_2); - - mRouting.addSubscription(subscriber, LAYER_WITH_SUBSCRIPTION_1, PUBLISHER_ID_1); - mRouting.addSubscription(subscriber, LAYER_WITH_SUBSCRIPTION_1, PUBLISHER_ID_2); - mRouting.addSubscription(subscriber, LAYER_WITH_SUBSCRIPTION_2, PUBLISHER_ID_2); - mRouting.removeSubscription(subscriber, LAYER_WITH_SUBSCRIPTION_2, PUBLISHER_ID_2); - - // Verify expected subscriptions are in routing manager. - Set<VmsLayer> expectedSubscriptions = new HashSet<>(); - expectedSubscriptions.add(LAYER_WITH_SUBSCRIPTION_1); - expectedSubscriptions.add(LAYER_WITH_SUBSCRIPTION_2); - - - Set<VmsAssociatedLayer> expectedSubscriptionsToPublishers = new HashSet<>(); - expectedSubscriptionsToPublishers.add(new VmsAssociatedLayer(LAYER_WITH_SUBSCRIPTION_1, - new HashSet(Arrays.asList(PUBLISHER_ID_1, PUBLISHER_ID_2)))); - - VmsSubscriptionState subscriptionState = mRouting.getSubscriptionState(); - assertEquals(6, subscriptionState.getSequenceNumber()); - assertEquals(expectedSubscriptions, - new HashSet<>(subscriptionState.getLayers())); - - assertEquals(expectedSubscriptionsToPublishers, - subscriptionState.getAssociatedLayers()); - - // Verify there is only a single subscriber. - assertEquals(1, - mRouting.getSubscribersForLayerFromPublisher( - LAYER_WITH_SUBSCRIPTION_1, PUBLISHER_ID_1).size()); - } - - public void testRemovalOfSubscribersToPublishersClearListForPublisher() throws Exception { - // Add a subscription to a layer. - MockVmsSubscriber subscriber = new MockVmsSubscriber(); - mRouting.addSubscription(subscriber, LAYER_WITH_SUBSCRIPTION_1); - - // Add a HAL subscription. - mRouting.addHalSubscription(LAYER_WITH_SUBSCRIPTION_2); - - mRouting.addSubscription(subscriber, LAYER_WITH_SUBSCRIPTION_1, PUBLISHER_ID_1); - mRouting.addSubscription(subscriber, LAYER_WITH_SUBSCRIPTION_1, PUBLISHER_ID_2); - mRouting.addSubscription(subscriber, LAYER_WITH_SUBSCRIPTION_2, PUBLISHER_ID_2); - mRouting.removeSubscription(subscriber, LAYER_WITH_SUBSCRIPTION_1, PUBLISHER_ID_1); - - // Verify expected subscriptions are in routing manager. - Set<VmsLayer> expectedSubscriptions = new HashSet<>(); - expectedSubscriptions.add(LAYER_WITH_SUBSCRIPTION_1); - expectedSubscriptions.add(LAYER_WITH_SUBSCRIPTION_2); - - Set<VmsAssociatedLayer> expectedSubscriptionsToPublishers = new HashSet<>(); - expectedSubscriptionsToPublishers.add(new VmsAssociatedLayer(LAYER_WITH_SUBSCRIPTION_1, - new HashSet(Arrays.asList(PUBLISHER_ID_2)))); - expectedSubscriptionsToPublishers.add(new VmsAssociatedLayer(LAYER_WITH_SUBSCRIPTION_2, - new HashSet(Arrays.asList(PUBLISHER_ID_2)))); - - VmsSubscriptionState subscriptionState = mRouting.getSubscriptionState(); - assertEquals(6, subscriptionState.getSequenceNumber()); - assertEquals(expectedSubscriptions, - new HashSet<>(subscriptionState.getLayers())); - - assertEquals(expectedSubscriptionsToPublishers, - subscriptionState.getAssociatedLayers()); - - // Verify there is only a single subscriber. - assertEquals(1, - mRouting.getSubscribersForLayerFromPublisher( - LAYER_WITH_SUBSCRIPTION_1, PUBLISHER_ID_1).size()); - } - - class MockVmsSubscriber extends IVmsSubscriberClient.Stub { - @Override - public void onVmsMessageReceived(VmsLayer layer, byte[] payload) { - } - - @Override - public void onLayersAvailabilityChanged(List<VmsAssociatedLayer> availableLayers) { - } - } -}
\ No newline at end of file |