From 5b2ec87670f46aa2d2c309bfe02207ac0a20daed Mon Sep 17 00:00:00 2001 From: Tuan Nguyen Date: Tue, 16 Jul 2019 10:37:28 -0700 Subject: [PATCH 01/20] Multiple Module, 1st batch --- .../protocol/enums/FunctionID.java | 64 +++++----- .../proxy/rpc/AudioControlCapabilities.java | 16 +++ .../proxy/rpc/ButtonCapabilities.java | 79 +++++++----- .../proxy/rpc/ButtonPress.java | 17 +++ .../proxy/rpc/ClimateControlCapabilities.java | 17 +++ .../proxy/rpc/GetInteriorVehicleData.java | 17 +++ .../rpc/GetInteriorVehicleDataConsent.java | 53 ++++++++ ...GetInteriorVehicleDataConsentResponse.java | 45 +++++++ .../com/smartdevicelink/proxy/rpc/Grid.java | 120 ++++++++++++++++++ .../rpc/HMISettingsControlCapabilities.java | 17 +++ .../proxy/rpc/LightControlCapabilities.java | 17 +++ .../smartdevicelink/proxy/rpc/ModuleData.java | 17 +++ .../smartdevicelink/proxy/rpc/ModuleInfo.java | 85 +++++++++++++ .../proxy/rpc/RadioControlCapabilities.java | 17 +++ .../rpc/ReleaseInteriorVehicleDataModule.java | 53 ++++++++ ...easeInteriorVehicleDataModuleResponse.java | 26 ++++ .../proxy/rpc/SeatControlCapabilities.java | 17 +++ .../proxy/rpc/SeatLocation.java | 32 +++++ .../proxy/rpc/SeatLocationCapability.java | 85 +++++++++++++ .../proxy/rpc/SetGlobalProperties.java | 79 +++++++----- .../proxy/rpc/SystemCapability.java | 9 +- .../proxy/rpc/enums/GlobalProperty.java | 69 +++++----- .../proxy/rpc/enums/SystemCapabilityType.java | 21 +++ 23 files changed, 845 insertions(+), 127 deletions(-) create mode 100644 base/src/main/java/com/smartdevicelink/proxy/rpc/GetInteriorVehicleDataConsent.java create mode 100644 base/src/main/java/com/smartdevicelink/proxy/rpc/GetInteriorVehicleDataConsentResponse.java create mode 100644 base/src/main/java/com/smartdevicelink/proxy/rpc/Grid.java create mode 100644 base/src/main/java/com/smartdevicelink/proxy/rpc/ModuleInfo.java create mode 100644 base/src/main/java/com/smartdevicelink/proxy/rpc/ReleaseInteriorVehicleDataModule.java create mode 100644 base/src/main/java/com/smartdevicelink/proxy/rpc/ReleaseInteriorVehicleDataModuleResponse.java create mode 100644 base/src/main/java/com/smartdevicelink/proxy/rpc/SeatLocation.java create mode 100644 base/src/main/java/com/smartdevicelink/proxy/rpc/SeatLocationCapability.java diff --git a/base/src/main/java/com/smartdevicelink/protocol/enums/FunctionID.java b/base/src/main/java/com/smartdevicelink/protocol/enums/FunctionID.java index c59dccfc93..5a8909e2c5 100644 --- a/base/src/main/java/com/smartdevicelink/protocol/enums/FunctionID.java +++ b/base/src/main/java/com/smartdevicelink/protocol/enums/FunctionID.java @@ -1,34 +1,34 @@ -/* - * Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the SmartDeviceLink Consortium, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ +/* + * Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the SmartDeviceLink Consortium, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package com.smartdevicelink.protocol.enums; import java.util.EnumSet; @@ -100,6 +100,8 @@ public enum FunctionID{ GET_APP_SERVICE_DATA(53, "GetAppServiceData"), GET_FILE(54, "GetFile"), PERFORM_APP_SERVICES_INTERACTION(55, "PerformAppServiceInteraction"), + GET_INTERIOR_VEHICLE_CONSENT(56, "GetInteriorVehicleDataConsentID"), + RELEASE_INTERIOR_VEHICLE_MODULE(57, "ReleaseInteriorVehicleDataModuleID"), // NOTIFICATIONS ON_HMI_STATUS(32768, "OnHMIStatus"), diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/AudioControlCapabilities.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/AudioControlCapabilities.java index c8e2d6d033..4210c9c2b2 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/AudioControlCapabilities.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/AudioControlCapabilities.java @@ -44,6 +44,7 @@ public class AudioControlCapabilities extends RPCStruct { public static final String KEY_VOLUME_AVAILABLE = "volumeAvailable"; public static final String KEY_EQUALIZER_AVAILABLE = "equalizerAvailable"; public static final String KEY_EQUALIZER_MAX_CHANNEL_ID = "equalizerMaxChannelId"; + public static final String KEY_MODULE_INFO = "moduleInfo"; /** * Constructs a newly allocated AudioControlCapabilities object @@ -178,4 +179,19 @@ public Integer getEqualizerMaxChannelId() { return getInteger(KEY_EQUALIZER_MAX_CHANNEL_ID); } + /** + * Sets ModuleInfo for this capability + * @param info the ModuleInfo to be set + */ + public void setModuleInfo(ModuleInfo info) { + setValue(KEY_MODULE_INFO, info); + } + + /** + * Gets a ModuleInfo of this capability + * @return module info of this capability + */ + public ModuleInfo getModuleInfo() { + return (ModuleInfo) getObject(ModuleInfo.class, KEY_MODULE_INFO); + } } diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/ButtonCapabilities.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/ButtonCapabilities.java index b92d3ef16b..f5ad5df6fc 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/ButtonCapabilities.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/ButtonCapabilities.java @@ -1,34 +1,34 @@ -/* - * Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the SmartDeviceLink Consortium, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ +/* + * Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the SmartDeviceLink Consortium, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package com.smartdevicelink.proxy.rpc; import android.support.annotation.NonNull; @@ -97,6 +97,7 @@ public class ButtonCapabilities extends RPCStruct { public static final String KEY_SHORT_PRESS_AVAILABLE = "shortPressAvailable"; public static final String KEY_LONG_PRESS_AVAILABLE = "longPressAvailable"; public static final String KEY_UP_DOWN_AVAILABLE = "upDownAvailable"; + public static final String KEY_MODULE_INFO = "moduleInfo"; /** * Constructs a newly allocated ButtonCapabilities object */ @@ -178,4 +179,20 @@ public Boolean getUpDownAvailable() { public void setUpDownAvailable( @NonNull Boolean upDownAvailable ) { setValue(KEY_UP_DOWN_AVAILABLE, upDownAvailable); } + + /** + * Sets ModuleInfo for this capability + * @param info the ModuleInfo to be set + */ + public void setModuleInfo(ModuleInfo info) { + setValue(KEY_MODULE_INFO, info); + } + + /** + * Gets a ModuleInfo of this capability + * @return module info of this capability + */ + public ModuleInfo getModuleInfo() { + return (ModuleInfo) getObject(ModuleInfo.class, KEY_MODULE_INFO); + } } diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/ButtonPress.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/ButtonPress.java index 2272198be8..1872138c52 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/ButtonPress.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/ButtonPress.java @@ -49,6 +49,7 @@ public class ButtonPress extends RPCRequest { public static final String KEY_MODULE_TYPE = "moduleType"; public static final String KEY_BUTTON_NAME = "buttonName"; public static final String KEY_BUTTON_PRESS_MODE = "buttonPressMode"; + public static final String KEY_MODULE_ID = "moduleId"; /** * Constructs a new ButtonPress object @@ -136,4 +137,20 @@ public ButtonPressMode getButtonPressMode() { public void setButtonPressMode(@NonNull ButtonPressMode buttonPressMode) { setParameters(KEY_BUTTON_PRESS_MODE, buttonPressMode); } + + /** + * Sets the module id for this object + * @param id the id to be set + */ + public void setModuleId(String id) { + setParameters(KEY_MODULE_ID, id); + } + + /** + * Gets the module id of this object + * @return the module id of this object + */ + public String getModuleId() { + return getString(KEY_MODULE_ID); + } } diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/ClimateControlCapabilities.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/ClimateControlCapabilities.java index 6961faf944..7e6b52c494 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/ClimateControlCapabilities.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/ClimateControlCapabilities.java @@ -61,6 +61,7 @@ public class ClimateControlCapabilities extends RPCStruct{ public static final String KEY_HEATED_WIND_SHIELD_AVAILABLE = "heatedWindshieldAvailable"; public static final String KEY_HEATED_REAR_WINDOW_AVAILABLE = "heatedRearWindowAvailable"; public static final String KEY_HEATED_MIRRORS_AVAILABLE = "heatedMirrorsAvailable"; + public static final String KEY_MODULE_INFO = "moduleInfo"; public ClimateControlCapabilities() { } @@ -403,4 +404,20 @@ public void setHeatedMirrorsAvailable(Boolean heatedMirrorsAvailable) { public Boolean getHeatedMirrorsAvailable() { return getBoolean(KEY_HEATED_MIRRORS_AVAILABLE); } + + /** + * Sets ModuleInfo for this capability + * @param info the ModuleInfo to be set + */ + public void setModuleInfo(ModuleInfo info) { + setValue(KEY_MODULE_INFO, info); + } + + /** + * Gets a ModuleInfo of this capability + * @return module info of this capability + */ + public ModuleInfo getModuleInfo() { + return (ModuleInfo) getObject(ModuleInfo.class, KEY_MODULE_INFO); + } } diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/GetInteriorVehicleData.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/GetInteriorVehicleData.java index fecf4463f7..a2999ae3bc 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/GetInteriorVehicleData.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/GetInteriorVehicleData.java @@ -49,6 +49,7 @@ public class GetInteriorVehicleData extends RPCRequest { public static final String KEY_MODULE_TYPE = "moduleType"; public static final String KEY_SUBSCRIBE = "subscribe"; + public static final String KEY_MODULE_ID = "moduleId"; /** * Constructs a new GetInteriorVehicleData object @@ -118,4 +119,20 @@ public void setSubscribe(Boolean subscribe) { public Boolean getSubscribe() { return getBoolean(KEY_SUBSCRIBE); } + + /** + * Sets the Module ID for this class + * @param id the id to be set + */ + public void setModuleId(String id) { + setParameters(KEY_MODULE_ID, id); + } + + /** + * Gets the Module ID of this class + * @return the Module ID of this class + */ + public String getModuleId() { + return getString(KEY_MODULE_ID); + } } diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/GetInteriorVehicleDataConsent.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/GetInteriorVehicleDataConsent.java new file mode 100644 index 0000000000..f765bb5d04 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/GetInteriorVehicleDataConsent.java @@ -0,0 +1,53 @@ +package com.smartdevicelink.proxy.rpc; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCRequest; +import com.smartdevicelink.proxy.rpc.enums.ModuleType; + +import java.util.Hashtable; +import java.util.List; + +public class GetInteriorVehicleDataConsent extends RPCRequest { + public static final String KEY_MODULE_TYPE = "moduleType"; + public static final String KEY_MODULE_ID = "moduleIds"; + + public GetInteriorVehicleDataConsent() { + super(FunctionID.GET_INTERIOR_VEHICLE_CONSENT.toString()); + } + + public GetInteriorVehicleDataConsent(Hashtable hash) { + super(hash); + } + + /** + * Sets the Module Type for this class + * @param type the Module Type to be set + */ + public void setModuleType(ModuleType type) { + setParameters(KEY_MODULE_TYPE, type); + } + + /** + * Gets the Module Type of this class + * @return the Module Type of this class + */ + public ModuleType getModuleType() { + return (ModuleType) getObject(ModuleType.class, KEY_MODULE_TYPE); + } + + /** + * Sets the Module Ids for this class + * @param ids the ids to be set + */ + public void setModuleIds(List ids) { + setParameters(KEY_MODULE_ID, ids); + } + + /** + * Gets the Module Ids of this class + * @return the Module Ids + */ + public List getModuleIds() { + return (List) getObject(String.class, KEY_MODULE_ID); + } +} diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/GetInteriorVehicleDataConsentResponse.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/GetInteriorVehicleDataConsentResponse.java new file mode 100644 index 0000000000..5041a444de --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/GetInteriorVehicleDataConsentResponse.java @@ -0,0 +1,45 @@ +package com.smartdevicelink.proxy.rpc; + +import android.support.annotation.NonNull; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCResponse; +import com.smartdevicelink.proxy.rpc.enums.Result; + +import java.util.Hashtable; +import java.util.List; + +public class GetInteriorVehicleDataConsentResponse extends RPCResponse { + + public static final String KEY_ALLOWED = "allowed"; + + public GetInteriorVehicleDataConsentResponse() { + super(FunctionID.GET_INTERIOR_VEHICLE_CONSENT.toString()); + } + + public GetInteriorVehicleDataConsentResponse(Hashtable hash) { + super(hash); + } + + public GetInteriorVehicleDataConsentResponse(@NonNull Boolean success, @NonNull Result resultCode) { + this(); + setSuccess(success); + setResultCode(resultCode); + } + + /** + * Sets the list of allowances for this class + * @param allowances the allowances to be set + */ + public void setAllowances(List allowances) { + setParameters(KEY_ALLOWED, allowances); + } + + /** + * Gets the list of allowances of this class + * @return the list of allowances of this class + */ + public List getAllowances() { + return (List) getObject(Boolean.class, KEY_ALLOWED); + } +} diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/Grid.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/Grid.java new file mode 100644 index 0000000000..2a7e524786 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/Grid.java @@ -0,0 +1,120 @@ +package com.smartdevicelink.proxy.rpc; + +import com.smartdevicelink.proxy.RPCStruct; + +import java.util.Hashtable; + +/** + * Struct that describes a location (origin coordinates and span) of a vehicle component (Module) + */ + +public class Grid extends RPCStruct { + public static final String KEY_COLUMN = "KEY_COLUMN"; + public static final String KEY_ROW = "KEY_ROW"; + public static final String KEY_LEVEL = "KEY_LEVEL"; + public static final String KEY_COL_SPAN = "KEY_COL_SPAN"; + public static final String KEY_ROW_SPAN = "KEY_ROW_SPAN"; + public static final String KEY_LEVEL_SPAN = "KEY_LEVEL_SPAN"; + + public Grid() {} + + public Grid(Hashtable hash) { + super(hash); + } + + /** + * Sets the column of this Grid + * @param col the column to be set + */ + public void setColumn(Integer col) { + setValue(KEY_COLUMN, col); + } + + /** + * Get the column value of this Grid + * @return the column value + */ + public Integer getCol() { + return getInteger(KEY_COLUMN); + } + + /** + * Sets the row's value of this Grid + * @param row the row to be set + */ + public void setRow(Integer row) { + setValue(KEY_ROW, row); + } + + /** + * Gets the row value of this Grid + * @return the row value + */ + public Integer getRow() { + return getInteger(KEY_ROW); + } + + /** + * Sets the level value of this Grid + * @param level the level to be set + */ + public void setLevel(Integer level) { + setValue(KEY_LEVEL, level); + } + + /** + * Gets the level value of this Grid + * @return the level + */ + public Integer getLevel() { + return getInteger(KEY_LEVEL); + } + + /** + * Sets the column span of this Grid + * @param span the span to be set + */ + public void setColSpan(Integer span) { + setValue(KEY_COL_SPAN, span); + } + + /** + * Gets the column span of this Grid + * @return the column span + */ + public Integer getColSpan() { + return getInteger(KEY_COL_SPAN); + } + + /** + * Sets the row span of this Grid + * @param span the span to be set + */ + public void setRowSpan(Integer span) { + setValue(KEY_ROW_SPAN, span); + } + + /** + * Gets the row span of this Grid + * @return the row span + */ + public Integer getRowSpan() { + return getInteger(KEY_ROW_SPAN); + } + + /** + * Sets the level span of this Grid + * @param span the span to be set + */ + public void setLevelSpan(Integer span) { + setValue(KEY_LEVEL_SPAN, span); + } + + /** + * Gets the level span of this Grid + * @return the level span + */ + public Integer getLevelSpan() { + return getInteger(KEY_LEVEL_SPAN); + } +} diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/HMISettingsControlCapabilities.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/HMISettingsControlCapabilities.java index 80b030ad23..c9a7d690f9 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/HMISettingsControlCapabilities.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/HMISettingsControlCapabilities.java @@ -42,6 +42,7 @@ public class HMISettingsControlCapabilities extends RPCStruct { public static final String KEY_DISTANCE_UNIT_AVAILABLE = "distanceUnitAvailable"; public static final String KEY_TEMPERATURE_UNIT_AVAILABLE = "temperatureUnitAvailable"; public static final String KEY_DISPLAY_MODE_UNIT_AVAILABLE = "displayModeUnitAvailable"; + public static final String KEY_MODULE_INFO = "moduleInfo"; /** * Constructs a new HMISettingsControlCapabilities object @@ -135,4 +136,20 @@ public void setDisplayModeUnitAvailable(Boolean displayModeUnitAvailable) { public Boolean getDisplayModeUnitAvailable() { return getBoolean(KEY_DISPLAY_MODE_UNIT_AVAILABLE); } + + /** + * Sets ModuleInfo for this capability + * @param info the ModuleInfo to be set + */ + public void setModuleInfo(ModuleInfo info) { + setValue(KEY_MODULE_INFO, info); + } + + /** + * Gets a ModuleInfo of this capability + * @return module info of this capability + */ + public ModuleInfo getModuleInfo() { + return (ModuleInfo) getObject(ModuleInfo.class, KEY_MODULE_INFO); + } } diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/LightControlCapabilities.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/LightControlCapabilities.java index 2c1e634553..a3b66467cf 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/LightControlCapabilities.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/LightControlCapabilities.java @@ -41,6 +41,7 @@ public class LightControlCapabilities extends RPCStruct { public static final String KEY_MODULE_NAME = "moduleName"; public static final String KEY_SUPPORTED_LIGHTS = "supportedLights"; + public static final String KEY_MODULE_INFO = "moduleInfo"; /** * Constructs a new LightControlCapabilities object @@ -106,4 +107,20 @@ public List getSupportedLights() { public void setSupportedLights(@NonNull List supportedLights) { setValue(KEY_SUPPORTED_LIGHTS, supportedLights); } + + /** + * Sets ModuleInfo for this capability + * @param info the ModuleInfo to be set + */ + public void setModuleInfo(ModuleInfo info) { + setValue(KEY_MODULE_INFO, info); + } + + /** + * Gets a ModuleInfo of this capability + * @return module info of this capability + */ + public ModuleInfo getModuleInfo() { + return (ModuleInfo) getObject(ModuleInfo.class, KEY_MODULE_INFO); + } } diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/ModuleData.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/ModuleData.java index 8f11dc5560..26cf08684b 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/ModuleData.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/ModuleData.java @@ -46,6 +46,7 @@ public class ModuleData extends RPCStruct { public static final String KEY_AUDIO_CONTROL_DATA = "audioControlData"; public static final String KEY_LIGHT_CONTROL_DATA = "lightControlData"; public static final String KEY_HMI_SETTINGS_CONTROL_DATA = "hmiSettingsControlData"; + public static final String KEY_MODULE_ID = "moduleId"; public ModuleData() { } @@ -186,4 +187,20 @@ public void setHmiSettingsControlData(HMISettingsControlData hmiSettingsControlD public HMISettingsControlData getHmiSettingsControlData() { return (HMISettingsControlData) getObject(HMISettingsControlData.class, KEY_HMI_SETTINGS_CONTROL_DATA); } + + /** + * Sets the Module ID of the ModuleData class + * @param id the id to be set + */ + public void setModuleId(String id) { + setValue(KEY_MODULE_ID, id); + } + + /** + * Gets the Module ID of the ModuleData class + * @return the Module ID + */ + public String getModuleId() { + return getString(KEY_MODULE_ID); + } } diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/ModuleInfo.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/ModuleInfo.java new file mode 100644 index 0000000000..28e106d6c6 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/ModuleInfo.java @@ -0,0 +1,85 @@ +package com.smartdevicelink.proxy.rpc; + +import com.smartdevicelink.proxy.RPCStruct; + +import java.util.Hashtable; + +/** + * Struct that describes a module within different SystemCapabilities + */ +public class ModuleInfo extends RPCStruct { + public static final String KEY_MODULE_ID = "KEY_MODULE_ID"; + public static final String KEY_MODULE_LOCATION = "KEY_MODULE_LOCATION"; + public static final String KEY_MODULE_SERVICE_AREA = "KEY_MODULE_SERVICE_AREA"; + public static final String KEY_MULTIPLE_ACCESS_ALLOWED = "KEY_MULTIPLE_ACCESS_ALLOWED"; + + public ModuleInfo(){} + + public ModuleInfo(Hashtable hash) { + super(hash); + } + + /** + * Sets the Module ID for this Module + * @param id the id to be set + */ + public void setModuleId(String id) { + setValue(KEY_MODULE_ID, id); + } + + /** + * Gets the Module ID for this module + * @return the Module ID as a String + */ + public String getModuleId() { + return getString(KEY_MODULE_ID); + } + + /** + * Sets the location of this Module + * @param location the location to be set + */ + public void setModuleGridLocation(Grid location) { + setValue(KEY_MODULE_LOCATION, location); + } + + /** + * Gets the location of this Module + * @return the location of this Module + */ + public Grid getModuleGridLocation() { + return (Grid) getObject(Grid.class, KEY_MODULE_LOCATION); + } + + /** + * Sets the service area of this Module + * @param serviceArea the service area of this Module + */ + public void setModuleServiceArea(Grid serviceArea) { + setValue(KEY_MODULE_SERVICE_AREA, serviceArea); + } + + /** + * Gets the service area of this Module + * @return the service area of this Module + */ + public Grid getModuleServiceArea() { + return (Grid) getObject(Grid.class, KEY_MODULE_SERVICE_AREA); + } + + /** + * Sets the multiple access allowance for this Module + * @param isMultipleAccess the access to be set + */ + public void setMultipleAccessAllowance(Boolean isMultipleAccess) { + setValue(KEY_MULTIPLE_ACCESS_ALLOWED, isMultipleAccess); + } + + /** + * Gets the multiple allowance access of this Module + * @return the multiple access allowance of this Module + */ + public Boolean getMultipleAccessAllowance() { + return getBoolean(KEY_MULTIPLE_ACCESS_ALLOWED); + } +} diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/RadioControlCapabilities.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/RadioControlCapabilities.java index da987e48ac..e04a45d650 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/RadioControlCapabilities.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/RadioControlCapabilities.java @@ -54,6 +54,7 @@ public class RadioControlCapabilities extends RPCStruct{ public static final String KEY_HD_RADIO_ENABLE_AVAILABLE = "hdRadioEnableAvailable"; public static final String KEY_SIRIUS_XM_RADIO_AVAILABLE = "siriusxmRadioAvailable"; public static final String KEY_SIS_DATA_AVAILABLE = "sisDataAvailable"; + public static final String KEY_MODULE_INFO = "moduleInfo"; public RadioControlCapabilities() { } @@ -340,4 +341,20 @@ public void setSisDataAvailable(Boolean sisDataAvailable) { public Boolean getSisDataAvailable() { return getBoolean(KEY_SIS_DATA_AVAILABLE); } + + /** + * Sets ModuleInfo for this capability + * @param info the ModuleInfo to be set + */ + public void setModuleInfo(ModuleInfo info) { + setValue(KEY_MODULE_INFO, info); + } + + /** + * Gets a ModuleInfo of this capability + * @return module info of this capability + */ + public ModuleInfo getModuleInfo() { + return (ModuleInfo) getObject(ModuleInfo.class, KEY_MODULE_INFO); + } } diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/ReleaseInteriorVehicleDataModule.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/ReleaseInteriorVehicleDataModule.java new file mode 100644 index 0000000000..88b532d8e4 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/ReleaseInteriorVehicleDataModule.java @@ -0,0 +1,53 @@ +package com.smartdevicelink.proxy.rpc; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCRequest; +import com.smartdevicelink.proxy.rpc.enums.ModuleType; + +import java.util.Hashtable; +import java.util.List; + +public class ReleaseInteriorVehicleDataModule extends RPCRequest { + public static final String KEY_MODULE_TYPE = "moduleType"; + public static final String KEY_MODULE_ID = "moduleId"; + + public ReleaseInteriorVehicleDataModule() { + super(FunctionID.RELEASE_INTERIOR_VEHICLE_MODULE.toString()); + } + + public ReleaseInteriorVehicleDataModule(Hashtable hash) { + super(hash); + } + + /** + * Sets the Module Type for this class + * @param type the Module Type to be set + */ + public void setModuleType(ModuleType type) { + setParameters(KEY_MODULE_TYPE, type); + } + + /** + * Gets the Module Type of this class + * @return the Module Type of this class + */ + public ModuleType getModuleType() { + return (ModuleType) getObject(ModuleType.class, KEY_MODULE_TYPE); + } + + /** + * Sets the Module Ids for this class + * @param id the ids to be set + */ + public void setModuleId(String id) { + setParameters(KEY_MODULE_ID, id); + } + + /** + * Gets the Module Id of this class + * @return the Module Ids + */ + public String getModuleIds() { + return getString(KEY_MODULE_ID); + } +} diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/ReleaseInteriorVehicleDataModuleResponse.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/ReleaseInteriorVehicleDataModuleResponse.java new file mode 100644 index 0000000000..61d8df98a2 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/ReleaseInteriorVehicleDataModuleResponse.java @@ -0,0 +1,26 @@ +package com.smartdevicelink.proxy.rpc; + +import android.support.annotation.NonNull; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCResponse; +import com.smartdevicelink.proxy.rpc.enums.Result; + +import java.util.Hashtable; + +public class ReleaseInteriorVehicleDataModuleResponse extends RPCResponse { + + public ReleaseInteriorVehicleDataModuleResponse() { + super(FunctionID.RELEASE_INTERIOR_VEHICLE_MODULE.toString()); + } + + public ReleaseInteriorVehicleDataModuleResponse(Hashtable hash) { + super(hash); + } + + public ReleaseInteriorVehicleDataModuleResponse(@NonNull Boolean success, @NonNull Result resultCode) { + this(); + setSuccess(success); + setResultCode(resultCode); + } +} \ No newline at end of file diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/SeatControlCapabilities.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/SeatControlCapabilities.java index 3c875d0d1c..d56a321a2b 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/SeatControlCapabilities.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/SeatControlCapabilities.java @@ -54,6 +54,7 @@ public class SeatControlCapabilities extends RPCStruct { public static final String KEY_MASSAGE_MODE_AVAILABLE = "massageModeAvailable"; public static final String KEY_MASSAGE_CUSHION_FIRMNESS_AVAILABLE = "massageCushionFirmnessAvailable"; public static final String KEY_MEMORY_AVAILABLE = "memoryAvailable"; + public static final String KEY_MODULE_INFO = "moduleInfo"; /** * Constructs a new SeatControlCapabilities object @@ -367,4 +368,20 @@ public void setMemoryAvailable(Boolean memoryAvailable) { public Boolean getMemoryAvailable() { return getBoolean(KEY_MEMORY_AVAILABLE); } + + /** + * Sets ModuleInfo for this capability + * @param info the ModuleInfo to be set + */ + public void setModuleInfo(ModuleInfo info) { + setValue(KEY_MODULE_INFO, info); + } + + /** + * Gets a ModuleInfo of this capability + * @return module info of this capability + */ + public ModuleInfo getModuleInfo() { + return (ModuleInfo) getObject(ModuleInfo.class, KEY_MODULE_INFO); + } } diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/SeatLocation.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/SeatLocation.java new file mode 100644 index 0000000000..a4b33d1bd0 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/SeatLocation.java @@ -0,0 +1,32 @@ +package com.smartdevicelink.proxy.rpc; + +import com.smartdevicelink.proxy.RPCStruct; + +import java.util.Hashtable; + +public class SeatLocation extends RPCStruct { + public static final String KEY_GRID = "grid"; + + public SeatLocation(){} + + public SeatLocation(Hashtable hash) { + super(hash); + } + + /** + * Sets grid data for this seat location + * @param grid the grid to be set + */ + public void setGrid(Grid grid) { + setValue(KEY_GRID, grid); + } + + /** + * Gets the Grid of this seat location + * @return the grid of this seat location + */ + public Grid getGrid() { + return (Grid) getObject(Grid.class, KEY_GRID); + } + +} diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/SeatLocationCapability.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/SeatLocationCapability.java new file mode 100644 index 0000000000..8c1c23c1b9 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/SeatLocationCapability.java @@ -0,0 +1,85 @@ +package com.smartdevicelink.proxy.rpc; + +import android.security.KeyChain; + +import com.smartdevicelink.proxy.RPCStruct; + +import java.util.Hashtable; +import java.util.List; + +public class SeatLocationCapability extends RPCStruct { + public static final String KEY_ROWS = "rows"; + public static final String KEY_COLS = "columns"; + public static final String KEY_LEVELS = "levels"; + public static final String KEY_SEATS = "seats"; + + public SeatLocationCapability(){} + + public SeatLocationCapability(Hashtable hash) { + super(hash); + } + + /** + * Sets the seat rows for this capability + * @param rows rows to be set + */ + public void setRows(Integer rows) { + setValue(KEY_ROWS, rows); + } + + /** + * Gets the seat rows of this capability + * @return the seat rows + */ + public Integer getRows() { + return getInteger(KEY_ROWS); + } + + /** + * Sets the seat columns for this capability + * @param cols the seat columns to be set + */ + public void setCols(Integer cols) { + setValue(KEY_COLS, cols); + } + + /** + * Gets the seat columns of this capability + * @return the seat columns + */ + public Integer getCols() { + return getInteger(KEY_COLS); + } + + /** + * Sets the levels for this capability + * @param levels the levels to be set + */ + public void setLevels(Integer levels) { + setValue(KEY_LEVELS, levels); + } + + /** + * Gets the seat levels of this capability + * @return the seat levels + */ + public Integer getLevels() { + return getInteger(KEY_LEVELS); + } + + /** + * Sets the seat locations for this capability + * @param locations the locations to be set + */ + public void setSeats(List locations) { + setValue(KEY_SEATS, locations); + } + + /** + * Gets the seat locations of this capability + * @return the seat locations + */ + public List getSeatLocations() { + return (List) getObject(SeatLocation.class, KEY_SEATS); + } +} diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/SetGlobalProperties.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/SetGlobalProperties.java index 62aca46578..f35d8547d5 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/SetGlobalProperties.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/SetGlobalProperties.java @@ -1,34 +1,34 @@ -/* - * Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the SmartDeviceLink Consortium, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ +/* + * Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the SmartDeviceLink Consortium, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package com.smartdevicelink.proxy.rpc; import com.smartdevicelink.protocol.enums.FunctionID; @@ -144,6 +144,7 @@ public class SetGlobalProperties extends RPCRequest { public static final String KEY_HELP_PROMPT = "helpPrompt"; public static final String KEY_TIMEOUT_PROMPT = "timeoutPrompt"; public static final String KEY_VR_HELP = "vrHelp"; + public static final String KEY_USER_LOCATION = "userLocation"; /** * Constructs a new SetGlobalProperties object */ @@ -302,6 +303,22 @@ public void setKeyboardProperties(KeyboardProperties keyboardProperties) { setParameters(KEY_KEYBOARD_PROPERTIES, keyboardProperties); } + /** + * Sets the user seat location + * @param location the location to be set + */ + public void setUserLocation(SeatLocation location) { + setParameters(KEY_USER_LOCATION, location); + } + + /** + * Gets the user seat location + * @return the user seat location + */ + public SeatLocation getUserLocation() { + return (SeatLocation) getObject(SeatLocation.class, KEY_USER_LOCATION); + } + @SuppressWarnings("unchecked") public KeyboardProperties getKeyboardProperties() { return (KeyboardProperties) getObject(KeyboardProperties.class, KEY_KEYBOARD_PROPERTIES); diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/SystemCapability.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/SystemCapability.java index 82cb366d76..c2511a3327 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/SystemCapability.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/SystemCapability.java @@ -49,6 +49,7 @@ public class SystemCapability extends RPCStruct { public static final String KEY_VIDEO_STREAMING_CAPABILITY = "videoStreamingCapability"; public static final String KEY_REMOTE_CONTROL_CAPABILITY = "remoteControlCapability"; public static final String KEY_APP_SERVICES_CAPABILITIES = "appServicesCapabilities"; + public static final String KEY_SEAT_LOCATION_CAPABILITY = "seatLocationCapability"; public SystemCapability(){} @@ -93,7 +94,9 @@ public RPCStruct getCapabilityForType(SystemCapabilityType type) { return (RPCStruct) getObject(RemoteControlCapabilities.class, KEY_REMOTE_CONTROL_CAPABILITY); }else if(type.equals(SystemCapabilityType.APP_SERVICES)){ return (RPCStruct) getObject(AppServicesCapabilities.class, KEY_APP_SERVICES_CAPABILITIES); - }else{ + }else if(type.equals(SystemCapabilityType.SEAT_LOCATION)){ + return (RPCStruct) getObject(SeatLocationCapability.class, KEY_SEAT_LOCATION_CAPABILITY); + }else{ return null; } } @@ -111,7 +114,9 @@ public void setCapabilityForType(SystemCapabilityType type, RPCStruct capability setValue(KEY_REMOTE_CONTROL_CAPABILITY, capability); }else if(type.equals(SystemCapabilityType.APP_SERVICES)){ setValue(KEY_APP_SERVICES_CAPABILITIES, capability); - }else{ + }else if(type.equals(SystemCapabilityType.SEAT_LOCATION)){ + setValue(KEY_SEAT_LOCATION_CAPABILITY, capability); + }else{ return; } } diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/enums/GlobalProperty.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/enums/GlobalProperty.java index d6a0a63aa0..9e3de9a6b0 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/enums/GlobalProperty.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/enums/GlobalProperty.java @@ -1,34 +1,34 @@ -/* - * Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the SmartDeviceLink Consortium, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ +/* + * Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the SmartDeviceLink Consortium, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package com.smartdevicelink.proxy.rpc.enums; /** @@ -68,7 +68,12 @@ public enum GlobalProperty{ * The on-screen keyboard configuration of setGlobalProperties */ - KEYBOARDPROPERTIES; + KEYBOARDPROPERTIES, + + /** + * The user seat location of setGlobalProperties + */ + USER_LOCATION; /** * Convert String to GlobalProperty diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/enums/SystemCapabilityType.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/enums/SystemCapabilityType.java index 69ead06027..e7bf1474ab 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/enums/SystemCapabilityType.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/enums/SystemCapabilityType.java @@ -475,6 +475,27 @@ public enum SystemCapabilityType { */ APP_SERVICES (true), + /** + * Available Synchronously after Register App Interface response
+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Enum NameReturn TypeDescriptionRequires Async?Notes
APP_SERVICESAppServicesCapabilitiesReturns APP_SERVICESNAvailable Asynchronously, Call is synchronous after initial call
+ */ + SEAT_LOCATION (true), + ; boolean IS_QUERYABLE; From d51ee4427cbb65695468a166601713c775a183d7 Mon Sep 17 00:00:00 2001 From: Tuan Nguyen Date: Tue, 16 Jul 2019 15:15:05 -0700 Subject: [PATCH 02/20] - handle new response msg for GetInteriorVehicleDataConsentResponse and ReleaseInteriorVehicleDataModuleResponse in SdlProxyBase - change hash keys in Grid and ModuleInfo - refractor method names and constants --- .../smartdevicelink/proxy/SdlProxyBase.java | 30 ++++++++ .../protocol/enums/FunctionID.java | 2 +- .../proxy/interfaces/IProxyListenerBase.java | 68 ++++++++++--------- .../rpc/GetInteriorVehicleDataConsent.java | 2 +- ...GetInteriorVehicleDataConsentResponse.java | 2 +- .../com/smartdevicelink/proxy/rpc/Grid.java | 18 ++--- .../smartdevicelink/proxy/rpc/ModuleInfo.java | 12 ++-- 7 files changed, 85 insertions(+), 49 deletions(-) diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java b/android/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java index 56e1c85444..4e4917e880 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java @@ -3694,6 +3694,36 @@ public void run() { _proxyListener.onPerformAppServiceInteractionResponse( msg); onRPCResponseReceived(msg); } + } else if (functionName.equals(FunctionID.GET_INTERIOR_VEHICLE_DATA_CONSENT)) { + final GetInteriorVehicleDataConsentResponse msg = new GetInteriorVehicleDataConsentResponse(hash); + msg.format(rpcSpecVersion, true); + if (_callbackToUIThread) { + _mainUIHandler.post(new Runnable() { + @Override + public void run() { + _proxyListener.onGetInteriorVehicleDataConsentResponse(msg); + onRPCResponseReceived(msg); + } + }); + } else { + _proxyListener.onGetInteriorVehicleDataConsentResponse(msg); + onRPCResponseReceived(msg); + } + } else if (functionName.equals(FunctionID.RELEASE_INTERIOR_VEHICLE_MODULE)) { + final ReleaseInteriorVehicleDataModuleResponse msg = new ReleaseInteriorVehicleDataModuleResponse(hash); + msg.format(rpcSpecVersion, true); + if (_callbackToUIThread) { + _mainUIHandler.post(new Runnable() { + @Override + public void run() { + _proxyListener.onReleaseInteriorVehicleDataModuleResponse(msg); + onRPCResponseReceived(msg); + } + }); + } else { + _proxyListener.onReleaseInteriorVehicleDataModuleResponse(msg); + onRPCResponseReceived(msg); + } } else { if (_sdlMsgVersion != null) { DebugTool.logError("Unrecognized response Message: " + functionName + diff --git a/base/src/main/java/com/smartdevicelink/protocol/enums/FunctionID.java b/base/src/main/java/com/smartdevicelink/protocol/enums/FunctionID.java index 5a8909e2c5..909d75aceb 100644 --- a/base/src/main/java/com/smartdevicelink/protocol/enums/FunctionID.java +++ b/base/src/main/java/com/smartdevicelink/protocol/enums/FunctionID.java @@ -100,7 +100,7 @@ public enum FunctionID{ GET_APP_SERVICE_DATA(53, "GetAppServiceData"), GET_FILE(54, "GetFile"), PERFORM_APP_SERVICES_INTERACTION(55, "PerformAppServiceInteraction"), - GET_INTERIOR_VEHICLE_CONSENT(56, "GetInteriorVehicleDataConsentID"), + GET_INTERIOR_VEHICLE_DATA_CONSENT(56, "GetInteriorVehicleDataConsentID"), RELEASE_INTERIOR_VEHICLE_MODULE(57, "ReleaseInteriorVehicleDataModuleID"), // NOTIFICATIONS diff --git a/base/src/main/java/com/smartdevicelink/proxy/interfaces/IProxyListenerBase.java b/base/src/main/java/com/smartdevicelink/proxy/interfaces/IProxyListenerBase.java index 45b5abcc02..feb3780aca 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/interfaces/IProxyListenerBase.java +++ b/base/src/main/java/com/smartdevicelink/proxy/interfaces/IProxyListenerBase.java @@ -1,34 +1,34 @@ -/* - * Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the SmartDeviceLink Consortium, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ +/* + * Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the SmartDeviceLink Consortium, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package com.smartdevicelink.proxy.interfaces; import com.smartdevicelink.proxy.callbacks.OnServiceEnded; @@ -52,6 +52,7 @@ import com.smartdevicelink.proxy.rpc.GetCloudAppPropertiesResponse; import com.smartdevicelink.proxy.rpc.GetDTCsResponse; import com.smartdevicelink.proxy.rpc.GetFileResponse; +import com.smartdevicelink.proxy.rpc.GetInteriorVehicleDataConsentResponse; import com.smartdevicelink.proxy.rpc.GetInteriorVehicleDataResponse; import com.smartdevicelink.proxy.rpc.GetSystemCapabilityResponse; import com.smartdevicelink.proxy.rpc.GetVehicleDataResponse; @@ -84,6 +85,7 @@ import com.smartdevicelink.proxy.rpc.PublishAppServiceResponse; import com.smartdevicelink.proxy.rpc.PutFileResponse; import com.smartdevicelink.proxy.rpc.ReadDIDResponse; +import com.smartdevicelink.proxy.rpc.ReleaseInteriorVehicleDataModuleResponse; import com.smartdevicelink.proxy.rpc.ResetGlobalPropertiesResponse; import com.smartdevicelink.proxy.rpc.ScrollableMessageResponse; import com.smartdevicelink.proxy.rpc.SendHapticDataResponse; @@ -412,6 +414,10 @@ public interface IProxyListenerBase { public void onOnAppServiceData(OnAppServiceData notification); + public void onGetInteriorVehicleDataConsentResponse(GetInteriorVehicleDataConsentResponse response); + + public void onReleaseInteriorVehicleDataModuleResponse(ReleaseInteriorVehicleDataModuleResponse response); + public void onOnSystemCapabilityUpdated(OnSystemCapabilityUpdated notification); } \ No newline at end of file diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/GetInteriorVehicleDataConsent.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/GetInteriorVehicleDataConsent.java index f765bb5d04..15f9ed2054 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/GetInteriorVehicleDataConsent.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/GetInteriorVehicleDataConsent.java @@ -12,7 +12,7 @@ public class GetInteriorVehicleDataConsent extends RPCRequest { public static final String KEY_MODULE_ID = "moduleIds"; public GetInteriorVehicleDataConsent() { - super(FunctionID.GET_INTERIOR_VEHICLE_CONSENT.toString()); + super(FunctionID.GET_INTERIOR_VEHICLE_DATA_CONSENT.toString()); } public GetInteriorVehicleDataConsent(Hashtable hash) { diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/GetInteriorVehicleDataConsentResponse.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/GetInteriorVehicleDataConsentResponse.java index 5041a444de..631d2e4d94 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/GetInteriorVehicleDataConsentResponse.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/GetInteriorVehicleDataConsentResponse.java @@ -14,7 +14,7 @@ public class GetInteriorVehicleDataConsentResponse extends RPCResponse { public static final String KEY_ALLOWED = "allowed"; public GetInteriorVehicleDataConsentResponse() { - super(FunctionID.GET_INTERIOR_VEHICLE_CONSENT.toString()); + super(FunctionID.GET_INTERIOR_VEHICLE_DATA_CONSENT.toString()); } public GetInteriorVehicleDataConsentResponse(Hashtable hash) { diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/Grid.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/Grid.java index 2a7e524786..80e8fac2c2 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/Grid.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/Grid.java @@ -9,12 +9,12 @@ */ public class Grid extends RPCStruct { - public static final String KEY_COLUMN = "KEY_COLUMN"; - public static final String KEY_ROW = "KEY_ROW"; - public static final String KEY_LEVEL = "KEY_LEVEL"; - public static final String KEY_COL_SPAN = "KEY_COL_SPAN"; - public static final String KEY_ROW_SPAN = "KEY_ROW_SPAN"; - public static final String KEY_LEVEL_SPAN = "KEY_LEVEL_SPAN"; + public static final String KEY_COLUMN = "col"; + public static final String KEY_ROW = "row"; + public static final String KEY_LEVEL = "level"; + public static final String KEY_COL_SPAN = "colspan"; + public static final String KEY_ROW_SPAN = "rowspan"; + public static final String KEY_LEVEL_SPAN = "levelspan"; public Grid() {} @@ -34,7 +34,7 @@ public void setColumn(Integer col) { * Get the column value of this Grid * @return the column value */ - public Integer getCol() { + public Integer getColumn() { return getInteger(KEY_COLUMN); } @@ -74,7 +74,7 @@ public Integer getLevel() { * Sets the column span of this Grid * @param span the span to be set */ - public void setColSpan(Integer span) { + public void setColumnSpan(Integer span) { setValue(KEY_COL_SPAN, span); } @@ -82,7 +82,7 @@ public void setColSpan(Integer span) { * Gets the column span of this Grid * @return the column span */ - public Integer getColSpan() { + public Integer getColumnSpan() { return getInteger(KEY_COL_SPAN); } diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/ModuleInfo.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/ModuleInfo.java index 28e106d6c6..eef2fb5f0f 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/ModuleInfo.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/ModuleInfo.java @@ -8,10 +8,10 @@ * Struct that describes a module within different SystemCapabilities */ public class ModuleInfo extends RPCStruct { - public static final String KEY_MODULE_ID = "KEY_MODULE_ID"; - public static final String KEY_MODULE_LOCATION = "KEY_MODULE_LOCATION"; - public static final String KEY_MODULE_SERVICE_AREA = "KEY_MODULE_SERVICE_AREA"; - public static final String KEY_MULTIPLE_ACCESS_ALLOWED = "KEY_MULTIPLE_ACCESS_ALLOWED"; + public static final String KEY_MODULE_ID = "moduleId"; + public static final String KEY_MODULE_LOCATION = "location"; + public static final String KEY_MODULE_SERVICE_AREA = "serviceArea"; + public static final String KEY_MULTIPLE_ACCESS_ALLOWED = "allowMultipleAccess"; public ModuleInfo(){} @@ -39,7 +39,7 @@ public String getModuleId() { * Sets the location of this Module * @param location the location to be set */ - public void setModuleGridLocation(Grid location) { + public void setModuleLocation(Grid location) { setValue(KEY_MODULE_LOCATION, location); } @@ -47,7 +47,7 @@ public void setModuleGridLocation(Grid location) { * Gets the location of this Module * @return the location of this Module */ - public Grid getModuleGridLocation() { + public Grid getModuleLocation() { return (Grid) getObject(Grid.class, KEY_MODULE_LOCATION); } From 57325d17659731aca39bbdaf73c8b2cee30d361d Mon Sep 17 00:00:00 2001 From: Tuan Nguyen Date: Wed, 17 Jul 2019 08:14:30 -0700 Subject: [PATCH 03/20] Add overridden methods onGetInteriorVehicleDataConsentResponse and onReleaseInteriorVehicleDataModuleResponse to ProxyBridge --- .../com/smartdevicelink/managers/ProxyBridge.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/ProxyBridge.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/ProxyBridge.java index e9d58a3fec..da741cf226 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/managers/ProxyBridge.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/ProxyBridge.java @@ -58,6 +58,7 @@ import com.smartdevicelink.proxy.rpc.GetCloudAppPropertiesResponse; import com.smartdevicelink.proxy.rpc.GetDTCsResponse; import com.smartdevicelink.proxy.rpc.GetFileResponse; +import com.smartdevicelink.proxy.rpc.GetInteriorVehicleDataConsentResponse; import com.smartdevicelink.proxy.rpc.GetInteriorVehicleDataResponse; import com.smartdevicelink.proxy.rpc.GetSystemCapabilityResponse; import com.smartdevicelink.proxy.rpc.GetVehicleDataResponse; @@ -92,6 +93,7 @@ import com.smartdevicelink.proxy.rpc.PutFileResponse; import com.smartdevicelink.proxy.rpc.ReadDIDResponse; import com.smartdevicelink.proxy.rpc.RegisterAppInterfaceResponse; +import com.smartdevicelink.proxy.rpc.ReleaseInteriorVehicleDataModuleResponse; import com.smartdevicelink.proxy.rpc.ResetGlobalPropertiesResponse; import com.smartdevicelink.proxy.rpc.ScrollableMessageResponse; import com.smartdevicelink.proxy.rpc.SendHapticDataResponse; @@ -632,6 +634,16 @@ public void onOnAppServiceData(OnAppServiceData notification){ onRPCReceived(notification); } + @Override + public void onGetInteriorVehicleDataConsentResponse(GetInteriorVehicleDataConsentResponse response) { + onRPCReceived(response); + } + + @Override + public void onReleaseInteriorVehicleDataModuleResponse(ReleaseInteriorVehicleDataModuleResponse response) { + onRPCReceived(response); + } + @Override public void onOnSystemCapabilityUpdated(OnSystemCapabilityUpdated notification){ onRPCReceived(notification); From ec6a6ef0ec9e7d74608c6d6f726d7254ea2b1748 Mon Sep 17 00:00:00 2001 From: Tuan Nguyen Date: Wed, 17 Jul 2019 09:19:17 -0700 Subject: [PATCH 04/20] Fix test cases, add more enum to enum tests and refractor functionId names. --- .../smartdevicelink/test/rpc/enums/GlobalPropertyTests.java | 4 ++++ .../test/rpc/enums/SystemCapabilityTypeTests.java | 4 ++++ .../java/com/smartdevicelink/protocol/enums/FunctionID.java | 4 ++-- .../com/smartdevicelink/proxy/rpc/enums/GlobalProperty.java | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/GlobalPropertyTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/GlobalPropertyTests.java index 422ab808c8..38caad1097 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/GlobalPropertyTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/GlobalPropertyTests.java @@ -32,6 +32,8 @@ public void testValidEnums () { GlobalProperty enumMenuIcon = GlobalProperty.valueForString(example); example = "KEYBOARDPROPERTIES"; GlobalProperty enumKeyboardProperties = GlobalProperty.valueForString(example); + example = "USERLOCATION"; + GlobalProperty enumUserLocation = GlobalProperty.valueForString(example); assertNotNull("HELPPROMPT returned null", enumHelpPrompt); assertNotNull("TIMEOUTPROMPT returned null", enumTimeoutPrompt); @@ -40,6 +42,7 @@ public void testValidEnums () { assertNotNull("MENUNAME returned null", enumMenuName); assertNotNull("MENUICON returned null", enumMenuIcon); assertNotNull("KEYBOARDPROPERTIES returned null", enumKeyboardProperties); + assertNotNull("USERLOCATION returned null", enumUserLocation); } /** @@ -84,6 +87,7 @@ public void testListEnum() { enumTestList.add(GlobalProperty.MENUNAME); enumTestList.add(GlobalProperty.MENUICON); enumTestList.add(GlobalProperty.KEYBOARDPROPERTIES); + enumTestList.add(GlobalProperty.USERLOCATION); assertTrue("Enum value list does not match enum class list", enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SystemCapabilityTypeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SystemCapabilityTypeTests.java index f0f876d003..f186eb4544 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SystemCapabilityTypeTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SystemCapabilityTypeTests.java @@ -48,6 +48,8 @@ public void testValidEnums () { SystemCapabilityType enumPCM = SystemCapabilityType.valueForString(example); example = "APP_SERVICES"; SystemCapabilityType enumAppServices = SystemCapabilityType.valueForString(example); + example = "SEAT_LOCATION"; + SystemCapabilityType enumSeatLocation = SystemCapabilityType.valueForString(example); assertNotNull("NAVIGATION returned null", enumNavigation); assertNotNull("PHONE_CALL returned null", enumPhoneCall); @@ -64,6 +66,7 @@ public void testValidEnums () { assertNotNull("VOICE_RECOGNITION returned null", enumVoiceRecognition); assertNotNull("PCM_STREAMING", enumPCM); assertNotNull("APP_SERVICES", enumAppServices); + assertNotNull("SEAT_LOCATION return null", enumSeatLocation); } /** @@ -116,6 +119,7 @@ public void testListEnum() { enumTestList.add(SystemCapabilityType.VOICE_RECOGNITION); enumTestList.add(SystemCapabilityType.PCM_STREAMING); enumTestList.add(SystemCapabilityType.APP_SERVICES); + enumTestList.add(SystemCapabilityType.SEAT_LOCATION); assertTrue("Enum value list does not match enum class list", enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); diff --git a/base/src/main/java/com/smartdevicelink/protocol/enums/FunctionID.java b/base/src/main/java/com/smartdevicelink/protocol/enums/FunctionID.java index 909d75aceb..83cac91d66 100644 --- a/base/src/main/java/com/smartdevicelink/protocol/enums/FunctionID.java +++ b/base/src/main/java/com/smartdevicelink/protocol/enums/FunctionID.java @@ -100,8 +100,8 @@ public enum FunctionID{ GET_APP_SERVICE_DATA(53, "GetAppServiceData"), GET_FILE(54, "GetFile"), PERFORM_APP_SERVICES_INTERACTION(55, "PerformAppServiceInteraction"), - GET_INTERIOR_VEHICLE_DATA_CONSENT(56, "GetInteriorVehicleDataConsentID"), - RELEASE_INTERIOR_VEHICLE_MODULE(57, "ReleaseInteriorVehicleDataModuleID"), + GET_INTERIOR_VEHICLE_DATA_CONSENT(56, "GetInteriorVehicleDataConsent"), + RELEASE_INTERIOR_VEHICLE_MODULE(57, "ReleaseInteriorVehicleDataModule"), // NOTIFICATIONS ON_HMI_STATUS(32768, "OnHMIStatus"), diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/enums/GlobalProperty.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/enums/GlobalProperty.java index 9e3de9a6b0..0990ef5ad7 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/enums/GlobalProperty.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/enums/GlobalProperty.java @@ -73,7 +73,7 @@ public enum GlobalProperty{ /** * The user seat location of setGlobalProperties */ - USER_LOCATION; + USERLOCATION; /** * Convert String to GlobalProperty From 340acfa13db5882621a25e0d9beb6299862b723c Mon Sep 17 00:00:00 2001 From: Tuan Nguyen Date: Fri, 19 Jul 2019 15:55:05 -0700 Subject: [PATCH 05/20] Add tests for ModuleInfo --- .../java/com/smartdevicelink/test/Test.java | 2 + .../com/smartdevicelink/test/Validator.java | 37 ++++++++ .../test/rpc/datatypes/ModuleInfoTests.java | 91 +++++++++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ModuleInfoTests.java diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java index c77894e932..a9c92a8672 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java @@ -33,6 +33,7 @@ import com.smartdevicelink.proxy.rpc.DeviceInfo; import com.smartdevicelink.proxy.rpc.DisplayCapabilities; import com.smartdevicelink.proxy.rpc.EqualizerSettings; +import com.smartdevicelink.proxy.rpc.Grid; import com.smartdevicelink.proxy.rpc.HMICapabilities; import com.smartdevicelink.proxy.rpc.HMIPermissions; import com.smartdevicelink.proxy.rpc.HMISettingsControlCapabilities; @@ -406,6 +407,7 @@ public class Test { public static final HapticRect GENERAL_HAPTIC_RECT = new HapticRect(); public static final FuelType GENERAL_FUELTYPE = FuelType.GASOLINE; public static final LockScreenConfig GENERAL_LOCKSCREENCONFIG = new LockScreenConfig(); + public static final Grid GENERAL_GRID = new Grid(); public static final List GENERAL_LONG_LIST = Arrays.asList(new Long[]{ 1L, 2L }); public static final List GENERAL_TURN_LIST = new ArrayList(); diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Validator.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Validator.java index 5172e40531..51c587b143 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Validator.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Validator.java @@ -31,6 +31,7 @@ import com.smartdevicelink.proxy.rpc.EqualizerSettings; import com.smartdevicelink.proxy.rpc.FuelRange; import com.smartdevicelink.proxy.rpc.GPSData; +import com.smartdevicelink.proxy.rpc.Grid; import com.smartdevicelink.proxy.rpc.HMICapabilities; import com.smartdevicelink.proxy.rpc.HMIPermissions; import com.smartdevicelink.proxy.rpc.HMISettingsControlCapabilities; @@ -3582,4 +3583,40 @@ public static boolean validateVideoStreamingCapability(VideoStreamingCapability return true; } + + public static boolean validateGrid(Grid g1, Grid g2) { + String tag = "validateGrid"; + if (g1 == null) { + return (g2 == null); + } + if (g2 == null) { + return (g1 == null); + } + if (g1.getColumn() != g2.getColumn()) { + log(tag, "Columns do not match"); + return false; + } + if (g1.getRow() != g2.getRow()) { + log(tag, "Rows do not match"); + return false; + } + if (g1.getLevel() != g2.getLevel()) { + log(tag, "Levels do not match"); + return false; + } + if (g1.getColumnSpan() != g2.getColumnSpan()) { + log(tag, "Column spans do not match"); + return false; + } + if (g1.getRowSpan() != g2.getRowSpan()) { + log(tag, "Row spans do not match"); + return false; + } + if (g1.getLevelSpan() != g2.getLevelSpan()) { + log(tag, "Level spans do not match"); + return false; + } + + return true; + } } diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ModuleInfoTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ModuleInfoTests.java new file mode 100644 index 0000000000..be818a514e --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ModuleInfoTests.java @@ -0,0 +1,91 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.Grid; +import com.smartdevicelink.proxy.rpc.ModuleInfo; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; +import java.util.Iterator; + +public class ModuleInfoTests extends TestCase { + private ModuleInfo msg; + + @Override + public void setUp() { + msg = new ModuleInfo(); + msg.setModuleId(Test.GENERAL_STRING); + msg.setModuleLocation(Test.GENERAL_GRID); + msg.setModuleServiceArea(Test.GENERAL_GRID); + msg.setMultipleAccessAllowance(Test.GENERAL_BOOLEAN); + } + + public void testRpcValues() { + String id = msg.getModuleId(); + Grid loc = msg.getModuleLocation(); + Grid area = msg.getModuleServiceArea(); + boolean isAllowed = msg.getMultipleAccessAllowance(); + + //valid tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, id); + assertEquals(Test.MATCH, Test.GENERAL_GRID, loc); + assertEquals(Test.MATCH, Test.GENERAL_GRID, area); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, isAllowed); + + //null test + ModuleInfo msg = new ModuleInfo(); + assertNull(Test.NULL, msg.getModuleId()); + assertNull(Test.NULL, msg.getModuleLocation()); + assertNull(Test.NULL, msg.getModuleServiceArea()); + assertNull(Test.NULL, msg.getMultipleAccessAllowance()); + } + + public void testJson() { + JSONObject original = new JSONObject(); + try { + original.put(ModuleInfo.KEY_MODULE_ID, Test.GENERAL_STRING); + original.put(ModuleInfo.KEY_MODULE_LOCATION, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_GRID.getStore())); + original.put(ModuleInfo.KEY_MODULE_SERVICE_AREA, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_GRID.getStore())); + original.put(ModuleInfo.KEY_MULTIPLE_ACCESS_ALLOWED, Test.GENERAL_BOOLEAN); + + JSONObject serialized = msg.serializeJSON(); + assertEquals(Test.MATCH, original.length(), serialized.length()); + Iterator iter = original.keys(); + while (iter.hasNext()) { + String key = iter.next(); + if (key.equals(ModuleInfo.KEY_MODULE_LOCATION) || key.equals(ModuleInfo.KEY_MODULE_SERVICE_AREA)) { + doTestJson(original, serialized, key); + } else if (key.equals(ModuleInfo.KEY_MODULE_ID)) { + String s1 = new ModuleInfo(JsonRPCMarshaller.deserializeJSONObject(original)).getModuleId(); + String s2 = new ModuleInfo(JsonRPCMarshaller.deserializeJSONObject(serialized)).getModuleId(); + assertEquals(Test.MATCH, s1, s2); + } else if (key.equals(ModuleInfo.KEY_MULTIPLE_ACCESS_ALLOWED)) { + boolean b1 = new ModuleInfo(JsonRPCMarshaller.deserializeJSONObject(original)).getMultipleAccessAllowance(); + boolean b2 = new ModuleInfo(JsonRPCMarshaller.deserializeJSONObject(serialized)).getMultipleAccessAllowance(); + assertEquals(Test.MATCH, b1, b2); + } + } + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + } + + private void doTestJson(JSONObject obj1, JSONObject obj2, String key) { + try { + JSONObject o1 = (JSONObject) JsonUtils.readObjectFromJsonObject(obj1, key); + JSONObject o2 = (JSONObject) JsonUtils.readObjectFromJsonObject(obj2, key); + Hashtable h1 = JsonRPCMarshaller.deserializeJSONObject(o1); + Hashtable h2 = JsonRPCMarshaller.deserializeJSONObject(o2); + assertTrue(Test.TRUE, Validator.validateGrid(new Grid(h1), new Grid(h2))); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + } +} From 638fa96ab26a224f81d184246bd867a6e4f01e9c Mon Sep 17 00:00:00 2001 From: Tuan Nguyen Date: Tue, 23 Jul 2019 13:18:02 -0700 Subject: [PATCH 06/20] Add unit tests for SeatLocationCapability --- .../java/com/smartdevicelink/test/Test.java | 9 ++ .../com/smartdevicelink/test/Validator.java | 12 ++ .../SeatLocationCapabilityTests.java | 103 ++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SeatLocationCapabilityTests.java diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java index a9c92a8672..32f23b62bb 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java @@ -74,6 +74,8 @@ import com.smartdevicelink.proxy.rpc.SdlMsgVersion; import com.smartdevicelink.proxy.rpc.SeatControlCapabilities; import com.smartdevicelink.proxy.rpc.SeatControlData; +import com.smartdevicelink.proxy.rpc.SeatLocation; +import com.smartdevicelink.proxy.rpc.SeatLocationCapability; import com.smartdevicelink.proxy.rpc.SeatMemoryAction; import com.smartdevicelink.proxy.rpc.SingleTireStatus; import com.smartdevicelink.proxy.rpc.SisData; @@ -408,6 +410,8 @@ public class Test { public static final FuelType GENERAL_FUELTYPE = FuelType.GASOLINE; public static final LockScreenConfig GENERAL_LOCKSCREENCONFIG = new LockScreenConfig(); public static final Grid GENERAL_GRID = new Grid(); + public static final List GENERAL_SEAT_LIST = new ArrayList<>(1); + public static final SeatLocation GENERAL_SEAT_LOCATION = new SeatLocation(); public static final List GENERAL_LONG_LIST = Arrays.asList(new Long[]{ 1L, 2L }); public static final List GENERAL_TURN_LIST = new ArrayList(); @@ -491,6 +495,7 @@ public void onVoiceCommandSelected() { public static final JSONArray JSON_RADIOCONTROLCAPABILITIES = new JSONArray(); public static final JSONArray JSON_CLIMATECONTROLCAPABILITIES = new JSONArray(); public static final JSONArray JSON_TEXTFIELDTYPES = new JSONArray(); + public static final JSONArray JSON_SEAT_LOCATIONS = new JSONArray(); public static final JSONObject JSON_TURN = new JSONObject(); public static final JSONObject JSON_IMAGE = new JSONObject(); public static final JSONObject JSON_CHOICE = new JSONObject(); @@ -518,6 +523,7 @@ public void onVoiceCommandSelected() { public static final JSONObject JSON_RGBCOLOR = new JSONObject(); public static final JSONObject JSON_DAYCOLORSCHEME = new JSONObject(); public static final JSONObject JSON_NIGHTCOLORSCHEME = new JSONObject(); + public static final JSONObject JSON_GRID = new JSONObject(); static { GENERAL_TOUCHEVENTCAPABILITIES.setDoublePressAvailable(GENERAL_BOOLEAN); @@ -670,6 +676,7 @@ public void onVoiceCommandSelected() { GENERAL_MEDIACLOCKFORMAT_LIST.add(MediaClockFormat.CLOCK1); GENERAL_MEDIACLOCKFORMAT_LIST.add(MediaClockFormat.CLOCK2); + GENERAL_SEAT_LIST.add(GENERAL_SEAT_LOCATION); GENERAL_IMAGE.setValue(GENERAL_STRING); GENERAL_IMAGE.setImageType(GENERAL_IMAGETYPE); @@ -1240,6 +1247,8 @@ public void onVoiceCommandSelected() { JSON_TEXTFIELDTYPES.put(MetadataType.MEDIA_ALBUM); JSON_TEXTFIELDTYPES.put(MetadataType.MEDIA_ARTIST); + JSON_SEAT_LOCATIONS.put(JSON_GRID); + } catch (JSONException e) { Log.e("Test", "Static Json Construction Failed.", e); } diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Validator.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Validator.java index 51c587b143..1a93637d13 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Validator.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Validator.java @@ -73,6 +73,8 @@ import com.smartdevicelink.proxy.rpc.SdlMsgVersion; import com.smartdevicelink.proxy.rpc.SeatControlCapabilities; import com.smartdevicelink.proxy.rpc.SeatControlData; +import com.smartdevicelink.proxy.rpc.SeatLocation; +import com.smartdevicelink.proxy.rpc.SeatLocationCapability; import com.smartdevicelink.proxy.rpc.SeatMemoryAction; import com.smartdevicelink.proxy.rpc.SingleTireStatus; import com.smartdevicelink.proxy.rpc.SisData; @@ -3619,4 +3621,14 @@ public static boolean validateGrid(Grid g1, Grid g2) { return true; } + + public static boolean validateSeatLocation(SeatLocation cap1, SeatLocation cap2) { + if (cap1 == null) { + return (cap2 == null); + } + if (cap2 == null) { + return (cap1 == null); + } + return validateGrid(cap1.getGrid(), cap2.getGrid()); + } } diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SeatLocationCapabilityTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SeatLocationCapabilityTests.java new file mode 100644 index 0000000000..956809914e --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SeatLocationCapabilityTests.java @@ -0,0 +1,103 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import android.util.Log; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.Grid; +import com.smartdevicelink.proxy.rpc.SeatLocation; +import com.smartdevicelink.proxy.rpc.SeatLocationCapability; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; + +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.Hashtable; +import java.util.Iterator; +import java.util.List; + +public class SeatLocationCapabilityTests extends TestCase { + + private SeatLocationCapability msg; + + @Override + public void setUp() { + msg = new SeatLocationCapability(); + msg.setCols(Test.GENERAL_INT); + msg.setRows(Test.GENERAL_INT); + msg.setLevels(Test.GENERAL_INT); + msg.setSeats(Test.GENERAL_SEAT_LIST); + } + + public void testRpcValues() { + int row = msg.getRows(); + int col = msg.getCols(); + int level = msg.getLevels(); + List seats = msg.getSeatLocations(); + + //valid tests + assertEquals(Test.MATCH, row, Test.GENERAL_INT); + assertEquals(Test.MATCH, col, Test.GENERAL_INT); + assertEquals(Test.MATCH, level, Test.GENERAL_INT); + assertEquals(Test.MATCH, seats.size(), Test.GENERAL_SEAT_LIST.size()); + for (int i = 0; i < Test.GENERAL_SEAT_LIST.size(); i++) { + assertTrue(Test.TRUE, Validator.validateGrid(Test.GENERAL_SEAT_LIST.get(i).getGrid(), seats.get(i).getGrid())); + } + + //null tests + SeatLocationCapability msg = new SeatLocationCapability(); + assertNull(Test.NULL, msg.getCols()); + assertNull(Test.NULL, msg.getRows()); + assertNull(Test.NULL, msg.getLevels()); + assertNull(Test.NULL, msg.getSeatLocations()); + } + + public void testJson() { + JSONObject original = new JSONObject(); + try { + original.put(SeatLocationCapability.KEY_COLS, Test.GENERAL_INT); + original.put(SeatLocationCapability.KEY_ROWS, Test.GENERAL_INT); + original.put(SeatLocationCapability.KEY_LEVELS, Test.GENERAL_INT); + original.put(SeatLocationCapability.KEY_SEATS, Test.JSON_SEAT_LOCATIONS); + + JSONObject serialized = msg.serializeJSON(); + assertEquals(serialized.length(), original.length()); + + Iterator iter = original.keys(); + String key = ""; + while (iter.hasNext()) { + key = iter.next(); + if (key.equals(SeatLocationCapability.KEY_COLS)) { + int i1 = new SeatLocationCapability(JsonRPCMarshaller.deserializeJSONObject(original)).getCols(); + int i2 = new SeatLocationCapability(JsonRPCMarshaller.deserializeJSONObject(serialized)).getCols(); + assertEquals(Test.MATCH, i1, i2); + } else if (key.equals(SeatLocationCapability.KEY_ROWS)) { + int i1 = new SeatLocationCapability(JsonRPCMarshaller.deserializeJSONObject(original)).getRows(); + int i2 = new SeatLocationCapability(JsonRPCMarshaller.deserializeJSONObject(serialized)).getRows(); + assertEquals(Test.MATCH, i1, i2); + } else if (key.equals(SeatLocationCapability.KEY_LEVELS)) { + int i1 = new SeatLocationCapability(JsonRPCMarshaller.deserializeJSONObject(original)).getLevels(); + int i2 = new SeatLocationCapability(JsonRPCMarshaller.deserializeJSONObject(serialized)).getLevels(); + assertEquals(Test.MATCH, i1, i2); + } else if (key.equals(SeatLocationCapability.KEY_SEATS)) { + JSONArray arr1 = JsonUtils.readJsonArrayFromJsonObject(original, key); + JSONArray arr2 = JsonUtils.readJsonArrayFromJsonObject(serialized, key); + assertEquals(Test.MATCH, arr1.length(), arr2.length()); + for (int i = 0; i < Test.GENERAL_SEAT_LIST.size(); i++) { + Hashtable h1 = JsonRPCMarshaller.deserializeJSONObject(arr1.getJSONObject(i)); + Hashtable h2 = JsonRPCMarshaller.deserializeJSONObject(arr2.getJSONObject(i)); + assertTrue(Test.MATCH, Validator.validateSeatLocation(new SeatLocation(h1), new SeatLocation(h2))); + } + } + } + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + } +} From ccfd846e228c9ca7c15e1e875b3d06710af2f90c Mon Sep 17 00:00:00 2001 From: Tuan Nguyen Date: Wed, 24 Jul 2019 10:27:10 -0700 Subject: [PATCH 07/20] Add unit tests for Grid, SeatLocation, GetInteriorVehicleDataConsent Fix comment in SystemCapabilityType --- .../proxy/rpc/enums/SystemCapabilityType.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/enums/SystemCapabilityType.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/enums/SystemCapabilityType.java index e7bf1474ab..f5fce314e0 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/enums/SystemCapabilityType.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/enums/SystemCapabilityType.java @@ -148,6 +148,13 @@ * N * Available Asynchronously, Call is synchronous after initial call * + * + * SEAT_LOCATION + * SeatLocationCapability + * Returns SEAT_LOCATION + * N + * Available Asynchronously, Call is synchronous after initial call + * * * */ @@ -486,9 +493,9 @@ public enum SystemCapabilityType { * Notes * * - * APP_SERVICES - * AppServicesCapabilities - * Returns APP_SERVICES + * SEAT_LOCATION + * SeatLocationCapability + * Returns SEAT_LOCATION * N * Available Asynchronously, Call is synchronous after initial call * From 2941586b2fa1f503f5af59e603ee9ef49e2b5718 Mon Sep 17 00:00:00 2001 From: Tuan Nguyen Date: Wed, 24 Jul 2019 10:28:28 -0700 Subject: [PATCH 08/20] Add unit tests for Grid, SeatLocation, GetInteriorVehicleDataConsent Fix comment in SystemCapabilityType --- .../json/GetInteriorVehicleDataConsent.json | 24 +++++ .../java/com/smartdevicelink/test/Test.java | 1 + .../test/rpc/datatypes/GridTests.java | 93 +++++++++++++++++++ .../test/rpc/datatypes/SeatLocationTests.java | 48 ++++++++++ .../GetInteriorVehicleDataConsentTests.java | 92 ++++++++++++++++++ 5 files changed, 258 insertions(+) create mode 100644 android/sdl_android/src/androidTest/assets/json/GetInteriorVehicleDataConsent.json create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/GridTests.java create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SeatLocationTests.java create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetInteriorVehicleDataConsentTests.java diff --git a/android/sdl_android/src/androidTest/assets/json/GetInteriorVehicleDataConsent.json b/android/sdl_android/src/androidTest/assets/json/GetInteriorVehicleDataConsent.json new file mode 100644 index 0000000000..d5008c494b --- /dev/null +++ b/android/sdl_android/src/androidTest/assets/json/GetInteriorVehicleDataConsent.json @@ -0,0 +1,24 @@ +{ + "request":{ + "name":"GetInteriorVehicleDataConsent", + "correlationID":168, + "parameters":{ + "moduleType":"CLIMATE", + "moduleIds" :[ + "A0A", + "R0A" + ] + } + }, + "response":{ + "name":"GetInteriorVehicleDataConsent", + "correlationID":169, + "info": "Consent info", + "success": "true", + "resultCode": "SUCCESS", + "allowed": [ + "true", + "false" + ] + } +} \ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java index 32f23b62bb..1466fb1bc7 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java @@ -33,6 +33,7 @@ import com.smartdevicelink.proxy.rpc.DeviceInfo; import com.smartdevicelink.proxy.rpc.DisplayCapabilities; import com.smartdevicelink.proxy.rpc.EqualizerSettings; +import com.smartdevicelink.proxy.rpc.GetInteriorVehicleDataConsent; import com.smartdevicelink.proxy.rpc.Grid; import com.smartdevicelink.proxy.rpc.HMICapabilities; import com.smartdevicelink.proxy.rpc.HMIPermissions; diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/GridTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/GridTests.java new file mode 100644 index 0000000000..32e745d109 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/GridTests.java @@ -0,0 +1,93 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.Grid; +import com.smartdevicelink.test.Test; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Iterator; + +public class GridTests extends TestCase { + + private Grid msg; + + @Override + public void setUp() { + msg = new Grid(); + msg.setColumn(Test.GENERAL_INT); + msg.setRow(Test.GENERAL_INT); + msg.setLevel(Test.GENERAL_INT); + msg.setColumnSpan(Test.GENERAL_INT); + msg.setRowSpan(Test.GENERAL_INT); + msg.setLevelSpan(Test.GENERAL_INT); + } + + public void testRpcValues() { + int col = msg.getColumn(); + int row = msg.getRow(); + int level = msg.getLevel(); + int colSpan = msg.getColumnSpan(); + int rowSpan = msg.getRowSpan(); + int levelSpan = msg.getLevelSpan(); + + //valid tests + assertEquals(Test.MATCH, col, Test.GENERAL_INT); + assertEquals(Test.MATCH, row, Test.GENERAL_INT); + assertEquals(Test.MATCH, level, Test.GENERAL_INT); + assertEquals(Test.MATCH, colSpan, Test.GENERAL_INT); + assertEquals(Test.MATCH, rowSpan, Test.GENERAL_INT); + assertEquals(Test.MATCH, levelSpan, Test.GENERAL_INT); + + //null tests + Grid msg = new Grid(); + assertNull(Test.NULL, msg.getColumn()); + assertNull(Test.NULL, msg.getRow()); + assertNull(Test.NULL, msg.getLevel()); + assertNull(Test.NULL, msg.getColumnSpan()); + assertNull(Test.NULL, msg.getRowSpan()); + assertNull(Test.NULL, msg.getLevelSpan()); + } + + public void testJson() { + JSONObject original = new JSONObject(); + try { + original.put(Grid.KEY_COLUMN, Test.GENERAL_INT); + original.put(Grid.KEY_ROW, Test.GENERAL_INT); + original.put(Grid.KEY_LEVEL, Test.GENERAL_INT); + original.put(Grid.KEY_COL_SPAN, Test.GENERAL_INT); + original.put(Grid.KEY_ROW_SPAN, Test.GENERAL_INT); + original.put(Grid.KEY_LEVEL_SPAN, Test.GENERAL_INT); + + JSONObject serialized = msg.serializeJSON(); + assertEquals(serialized.length(), original.length()); + + Iterator iter = original.keys(); + String key = ""; + Grid grid1, grid2; + while (iter.hasNext()) { + key = iter.next(); + grid1 = new Grid(JsonRPCMarshaller.deserializeJSONObject(original)); + grid2 = new Grid(JsonRPCMarshaller.deserializeJSONObject(serialized)); + if (key.equals(Grid.KEY_COLUMN)) { + assertEquals(Test.MATCH, grid1.getColumn(), grid2.getColumn()); + } else if (key.equals(Grid.KEY_ROW)) { + assertEquals(Test.MATCH, grid1.getRow(), grid2.getRow()); + } else if (key.equals(Grid.KEY_LEVEL)) { + assertEquals(Test.MATCH, grid1.getLevel(), grid2.getLevel()); + } else if (key.equals(Grid.KEY_COL_SPAN)) { + assertEquals(Test.MATCH, grid1.getColumnSpan(), grid2.getColumnSpan()); + } else if (key.equals(Grid.KEY_ROW_SPAN)) { + assertEquals(Test.MATCH, grid1.getRowSpan(), grid2.getRowSpan()); + } else if (key.equals(Grid.KEY_LEVEL_SPAN)) { + assertEquals(Test.MATCH, grid1.getLevelSpan(), grid2.getLevelSpan()); + } + } + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SeatLocationTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SeatLocationTests.java new file mode 100644 index 0000000000..6a102fc66a --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SeatLocationTests.java @@ -0,0 +1,48 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.Grid; +import com.smartdevicelink.proxy.rpc.SeatLocation; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +public class SeatLocationTests extends TestCase { + + private SeatLocation msg; + + @Override + public void setUp() { + msg = new SeatLocation(); + msg.setGrid(Test.GENERAL_GRID); + } + + public void testRpcValues() { + Grid grid = msg.getGrid(); + + //valid test + assertTrue(Validator.validateGrid(Test.GENERAL_GRID, grid)); + + //null test + SeatLocation msg = new SeatLocation(); + assertNull(Test.NULL, msg.getGrid()); + } + + public void testJson() { + JSONObject original = new JSONObject(); + try { + original.put(SeatLocation.KEY_GRID, Test.GENERAL_GRID); + + JSONObject serialized = msg.serializeJSON(); + assertEquals(serialized.length(), original.length()); + assertTrue(Test.TRUE, Validator.validateSeatLocation(new SeatLocation(JsonRPCMarshaller.deserializeJSONObject(original)), + new SeatLocation(JsonRPCMarshaller.deserializeJSONObject(serialized)))); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetInteriorVehicleDataConsentTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetInteriorVehicleDataConsentTests.java new file mode 100644 index 0000000000..a126cf4e51 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetInteriorVehicleDataConsentTests.java @@ -0,0 +1,92 @@ +package com.smartdevicelink.test.rpc.requests; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.GetInteriorVehicleDataConsent; +import com.smartdevicelink.proxy.rpc.enums.ModuleType; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; +import java.util.List; + +public class GetInteriorVehicleDataConsentTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + GetInteriorVehicleDataConsent msg = new GetInteriorVehicleDataConsent(); + msg.setModuleType(Test.GENERAL_MODULETYPE); + msg.setModuleIds(Test.GENERAL_STRING_LIST); + return msg; + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + try { + result.put(GetInteriorVehicleDataConsent.KEY_MODULE_TYPE, Test.GENERAL_MODULETYPE); + result.put(GetInteriorVehicleDataConsent.KEY_MODULE_ID, JsonUtils.createJsonArray(Test.GENERAL_STRING_LIST)); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + return result; + } + + @Override + protected String getCommandType() { + return FunctionID.GET_INTERIOR_VEHICLE_DATA_CONSENT.toString(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_REQUEST; + } + + public void testRpcValues() { + ModuleType type = ((GetInteriorVehicleDataConsent) msg).getModuleType(); + List ids = ((GetInteriorVehicleDataConsent) msg).getModuleIds(); + + //valid tests + assertEquals(Test.MATCH, Test.GENERAL_MODULETYPE, type); + assertEquals(Test.MATCH, Test.GENERAL_STRING_LIST, ids); + + //null tests + GetInteriorVehicleDataConsent msg = new GetInteriorVehicleDataConsent(); + assertNull(Test.NULL, msg.getModuleType()); + assertNull(Test.NULL, msg.getModuleIds()); + + } + + public void testJsonConstructor() { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + GetInteriorVehicleDataConsent cmd = new GetInteriorVehicleDataConsent(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(parameters, GetInteriorVehicleDataConsent.KEY_MODULE_TYPE).toString(), cmd.getModuleType().toString()); + assertEquals(Test.MATCH, JsonUtils.readStringListFromJsonObject(parameters, GetInteriorVehicleDataConsent.KEY_MODULE_ID), cmd.getModuleIds()); + + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + } + + +} From 3e4e2e88dee92345b049c199751aa22989aeeacf Mon Sep 17 00:00:00 2001 From: Tuan Nguyen Date: Wed, 24 Jul 2019 14:18:29 -0700 Subject: [PATCH 09/20] Add test for GetInteriorVehicleDataConsentResponse --- .../json/GetInteriorVehicleDataConsent.json | 15 ++-- .../com/smartdevicelink/test/JsonUtils.java | 18 +++++ .../java/com/smartdevicelink/test/Test.java | 3 +- ...teriorVehicleDataConsentResponseTests.java | 76 +++++++++++++++++++ 4 files changed, 103 insertions(+), 9 deletions(-) create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetInteriorVehicleDataConsentResponseTests.java diff --git a/android/sdl_android/src/androidTest/assets/json/GetInteriorVehicleDataConsent.json b/android/sdl_android/src/androidTest/assets/json/GetInteriorVehicleDataConsent.json index d5008c494b..5ab1c6c41e 100644 --- a/android/sdl_android/src/androidTest/assets/json/GetInteriorVehicleDataConsent.json +++ b/android/sdl_android/src/androidTest/assets/json/GetInteriorVehicleDataConsent.json @@ -4,7 +4,7 @@ "correlationID":168, "parameters":{ "moduleType":"CLIMATE", - "moduleIds" :[ + "moduleIds":[ "A0A", "R0A" ] @@ -13,12 +13,11 @@ "response":{ "name":"GetInteriorVehicleDataConsent", "correlationID":169, - "info": "Consent info", - "success": "true", - "resultCode": "SUCCESS", - "allowed": [ - "true", - "false" - ] + "parameters":{ + "allowed":[ + true, + true + ] + } } } \ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/JsonUtils.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/JsonUtils.java index 375de93627..5cb0cf719b 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/JsonUtils.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/JsonUtils.java @@ -170,6 +170,24 @@ public static List readIntegerListFromJsonObject(JSONObject json, Strin return null; } + + public static List readBooleanListFromJsonObject(JSONObject json, String key){ + JSONArray jsonArray = readJsonArrayFromJsonObject(json, key); + + if(jsonArray != null){ + int len = jsonArray.length(); + List result = new ArrayList<>(len); + for(int i=0; i readDoubleListFromJsonObject(JSONObject json, String key){ JSONArray jsonArray = readJsonArrayFromJsonObject(json, key); diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java index 1466fb1bc7..e2b0df4969 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java @@ -411,7 +411,6 @@ public class Test { public static final FuelType GENERAL_FUELTYPE = FuelType.GASOLINE; public static final LockScreenConfig GENERAL_LOCKSCREENCONFIG = new LockScreenConfig(); public static final Grid GENERAL_GRID = new Grid(); - public static final List GENERAL_SEAT_LIST = new ArrayList<>(1); public static final SeatLocation GENERAL_SEAT_LOCATION = new SeatLocation(); public static final List GENERAL_LONG_LIST = Arrays.asList(new Long[]{ 1L, 2L }); @@ -461,6 +460,8 @@ public class Test { public static final List GENERAL_WEATHERDATA_LIST = Arrays.asList(GENERAL_WEATHERDATA); public static final List GENERAL_WEATHERALERT_LIST = Arrays.asList(GENERAL_WEATHERALERT); public static final List GENERAL_NAVIGATION_INSTRUCTION_LIST = Arrays.asList(GENERAL_NAVIGATION_INSTRUCTION); + public static final List GENERAL_SEAT_LIST = new ArrayList<>(1); + public static final List GENERAL_BOOLEAN_LIST = Arrays.asList(new Boolean[]{Boolean.TRUE, Boolean.TRUE}); public static final int GENERAL_MENU_MAX_ID = 2000000000; public static final MenuCell GENERAL_MENUCELL = new MenuCell(GENERAL_STRING,null, null, new MenuSelectionListener() { @Override diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetInteriorVehicleDataConsentResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetInteriorVehicleDataConsentResponseTests.java new file mode 100644 index 0000000000..5b8cff3cef --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetInteriorVehicleDataConsentResponseTests.java @@ -0,0 +1,76 @@ +package com.smartdevicelink.test.rpc.responses; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.GetInteriorVehicleDataConsent; +import com.smartdevicelink.proxy.rpc.GetInteriorVehicleDataConsentResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; +import java.util.List; + +public class GetInteriorVehicleDataConsentResponseTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + GetInteriorVehicleDataConsentResponse msg = new GetInteriorVehicleDataConsentResponse(); + msg.setAllowances(Test.GENERAL_BOOLEAN_LIST); + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType() { + return FunctionID.GET_INTERIOR_VEHICLE_DATA_CONSENT.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try{ + result.put(GetInteriorVehicleDataConsentResponse.KEY_ALLOWED, JsonUtils.createJsonArray(Test.GENERAL_BOOLEAN_LIST)); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + return result; + } + + public void testRpcValues() { + List list = ((GetInteriorVehicleDataConsentResponse) msg).getAllowances(); + assertEquals(Test.MATCH, list, Test.GENERAL_BOOLEAN_LIST); + } + + public void testJsonConstructor() { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + GetInteriorVehicleDataConsentResponse cmd = new GetInteriorVehicleDataConsentResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readBooleanListFromJsonObject(parameters, + GetInteriorVehicleDataConsentResponse.KEY_ALLOWED), cmd.getAllowances()); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + } +} From 4e17c37e260b1f7205500bec36902d3679263a12 Mon Sep 17 00:00:00 2001 From: Tuan Nguyen Date: Wed, 24 Jul 2019 15:01:49 -0700 Subject: [PATCH 10/20] Add unit tests for ReleaseInteriorVehicleDataModule and ReleaseInteriorVehicleDataModuleResponse --- .../json/ReleaseInteriorVehicleDataModule.json | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 android/sdl_android/src/androidTest/assets/json/ReleaseInteriorVehicleDataModule.json diff --git a/android/sdl_android/src/androidTest/assets/json/ReleaseInteriorVehicleDataModule.json b/android/sdl_android/src/androidTest/assets/json/ReleaseInteriorVehicleDataModule.json new file mode 100644 index 0000000000..9f9f600961 --- /dev/null +++ b/android/sdl_android/src/androidTest/assets/json/ReleaseInteriorVehicleDataModule.json @@ -0,0 +1,14 @@ +{ + "request":{ + "name":"ReleaseInteriorVehicleDataModule", + "correlationID":172, + "parameters":{ + "moduleType":"CLIMATE", + "moduleIds":"A0A" + } + }, + "response":{ + "name":"ReleaseInteriorVehicleDataModule", + "correlationID":173 + } +} \ No newline at end of file From ff6852961d809b13d4169890ba029e7a8efa10d8 Mon Sep 17 00:00:00 2001 From: Tuan Nguyen Date: Wed, 24 Jul 2019 15:02:48 -0700 Subject: [PATCH 11/20] Add unit tests for ReleaseInteriorVehicleDataModule and ReleaseInteriorVehicleDataModuleResponse --- .../GetInteriorVehicleDataConsentTests.java | 1 - ...ReleaseInteriorVehicleDataModuleTests.java | 85 +++++++++++++++++++ ...nteriorVehicleDataModuleResponseTests.java | 57 +++++++++++++ .../rpc/ReleaseInteriorVehicleDataModule.java | 2 +- 4 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/ReleaseInteriorVehicleDataModuleTests.java create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ReleaseInteriorVehicleDataModuleResponseTests.java diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetInteriorVehicleDataConsentTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetInteriorVehicleDataConsentTests.java index a126cf4e51..486b08b492 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetInteriorVehicleDataConsentTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetInteriorVehicleDataConsentTests.java @@ -82,7 +82,6 @@ public void testJsonConstructor() { JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(parameters, GetInteriorVehicleDataConsent.KEY_MODULE_TYPE).toString(), cmd.getModuleType().toString()); assertEquals(Test.MATCH, JsonUtils.readStringListFromJsonObject(parameters, GetInteriorVehicleDataConsent.KEY_MODULE_ID), cmd.getModuleIds()); - } catch (JSONException e) { fail(Test.JSON_FAIL); } diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/ReleaseInteriorVehicleDataModuleTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/ReleaseInteriorVehicleDataModuleTests.java new file mode 100644 index 0000000000..711e4c9770 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/ReleaseInteriorVehicleDataModuleTests.java @@ -0,0 +1,85 @@ +package com.smartdevicelink.test.rpc.requests; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.ReleaseInteriorVehicleDataModule; +import com.smartdevicelink.proxy.rpc.enums.ModuleType; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + +public class ReleaseInteriorVehicleDataModuleTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + ReleaseInteriorVehicleDataModule msg = new ReleaseInteriorVehicleDataModule(); + msg.setModuleType(Test.GENERAL_MODULETYPE); + msg.setModuleId(Test.GENERAL_STRING); + return msg; + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + try { + result.put(ReleaseInteriorVehicleDataModule.KEY_MODULE_TYPE, Test.GENERAL_MODULETYPE); + result.put(ReleaseInteriorVehicleDataModule.KEY_MODULE_ID, Test.GENERAL_STRING); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + return result; + } + + @Override + protected String getCommandType() { + return FunctionID.RELEASE_INTERIOR_VEHICLE_MODULE.toString(); + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_REQUEST; + } + + public void testRpcValues() { + ModuleType type = ((ReleaseInteriorVehicleDataModule) msg).getModuleType(); + String id = ((ReleaseInteriorVehicleDataModule) msg).getModuleId(); + + //valid tests + assertEquals(Test.MATCH, Test.GENERAL_MODULETYPE, type); + assertEquals(Test.MATCH, Test.GENERAL_STRING, id); + + //null tests + ReleaseInteriorVehicleDataModule msg = new ReleaseInteriorVehicleDataModule(); + assertNull(Test.NULL, msg.getModuleType()); + assertNull(Test.NULL, msg.getModuleId()); + } + + public void testJsonConstructor() { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + ReleaseInteriorVehicleDataModule cmd = new ReleaseInteriorVehicleDataModule(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(parameters, ReleaseInteriorVehicleDataModule.KEY_MODULE_TYPE).toString(), cmd.getModuleType().toString()); + assertEquals(Test.MATCH, JsonUtils.readStringListFromJsonObject(parameters, ReleaseInteriorVehicleDataModule.KEY_MODULE_ID), cmd.getModuleId()); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ReleaseInteriorVehicleDataModuleResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ReleaseInteriorVehicleDataModuleResponseTests.java new file mode 100644 index 0000000000..9bedadd97b --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ReleaseInteriorVehicleDataModuleResponseTests.java @@ -0,0 +1,57 @@ +package com.smartdevicelink.test.rpc.responses; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.GetInteriorVehicleDataConsentResponse; +import com.smartdevicelink.proxy.rpc.ReleaseInteriorVehicleDataModuleResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + +public class ReleaseInteriorVehicleDataModuleResponseTests extends BaseRpcTests { + @Override + protected RPCMessage createMessage() { + ReleaseInteriorVehicleDataModuleResponse msg = new ReleaseInteriorVehicleDataModuleResponse(); + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType() { + return FunctionID.RELEASE_INTERIOR_VEHICLE_MODULE.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + return new JSONObject(); + } + + public void testJsonConstructor() { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + ReleaseInteriorVehicleDataModuleResponse cmd = new ReleaseInteriorVehicleDataModuleResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + } +} diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/ReleaseInteriorVehicleDataModule.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/ReleaseInteriorVehicleDataModule.java index 88b532d8e4..85555ca86b 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/ReleaseInteriorVehicleDataModule.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/ReleaseInteriorVehicleDataModule.java @@ -47,7 +47,7 @@ public void setModuleId(String id) { * Gets the Module Id of this class * @return the Module Ids */ - public String getModuleIds() { + public String getModuleId() { return getString(KEY_MODULE_ID); } } From 535dae399d71ce364bf7cb5df1454f184f777a69 Mon Sep 17 00:00:00 2001 From: Tuan Nguyen Date: Thu, 25 Jul 2019 09:25:57 -0700 Subject: [PATCH 12/20] Add more unit tests --- .../java/com/smartdevicelink/test/Test.java | 12 ++++++++ .../com/smartdevicelink/test/Validator.java | 24 +++++++++++++++ .../AudioControlCapabilitiesTests.java | 21 ++++++++++++-- .../datatypes/ButtonCapabilitiesTests.java | 20 +++++++++++-- .../ClimateControlCapabilitiesTests.java | 15 ++++++++++ .../HMISettingsControlCapabilitiesTests.java | 20 +++++++++++-- .../LightControlCapabilitiesTests.java | 16 +++++++++- .../test/rpc/datatypes/ModuleDataTests.java | 5 ++++ .../test/rpc/datatypes/ModuleInfoTests.java | 29 ++----------------- .../RadioControlCapabilitiesTests.java | 20 +++++++++++-- .../test/rpc/requests/ButtonPressTests.java | 6 ++++ .../requests/GetInteriorVehicleDataTests.java | 6 ++++ 12 files changed, 158 insertions(+), 36 deletions(-) diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java index e2b0df4969..dd00d5ed54 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java @@ -56,6 +56,7 @@ import com.smartdevicelink.proxy.rpc.MenuParams; import com.smartdevicelink.proxy.rpc.MetadataTags; import com.smartdevicelink.proxy.rpc.ModuleData; +import com.smartdevicelink.proxy.rpc.ModuleInfo; import com.smartdevicelink.proxy.rpc.NavigationCapability; import com.smartdevicelink.proxy.rpc.NavigationInstruction; import com.smartdevicelink.proxy.rpc.NavigationServiceData; @@ -412,6 +413,7 @@ public class Test { public static final LockScreenConfig GENERAL_LOCKSCREENCONFIG = new LockScreenConfig(); public static final Grid GENERAL_GRID = new Grid(); public static final SeatLocation GENERAL_SEAT_LOCATION = new SeatLocation(); + public static final ModuleInfo GENERAL_MODULE_INFO = new ModuleInfo(); public static final List GENERAL_LONG_LIST = Arrays.asList(new Long[]{ 1L, 2L }); public static final List GENERAL_TURN_LIST = new ArrayList(); @@ -526,6 +528,7 @@ public void onVoiceCommandSelected() { public static final JSONObject JSON_DAYCOLORSCHEME = new JSONObject(); public static final JSONObject JSON_NIGHTCOLORSCHEME = new JSONObject(); public static final JSONObject JSON_GRID = new JSONObject(); + public static final JSONObject JSON_MODULE_INFO = new JSONObject(); static { GENERAL_TOUCHEVENTCAPABILITIES.setDoublePressAvailable(GENERAL_BOOLEAN); @@ -1045,6 +1048,10 @@ public void onVoiceCommandSelected() { GENERAL_NAVIGATION_INSTRUCTION.setDrivingSide(GENERAL_DIRECTION); GENERAL_NAVIGATION_INSTRUCTION.setDetails(GENERAL_STRING); GENERAL_NAVIGATION_INSTRUCTION.setImage(GENERAL_IMAGE); + GENERAL_MODULE_INFO.setModuleId(Test.GENERAL_STRING); + GENERAL_MODULE_INFO.setModuleLocation(Test.GENERAL_GRID); + GENERAL_MODULE_INFO.setModuleServiceArea(Test.GENERAL_GRID); + GENERAL_MODULE_INFO.setMultipleAccessAllowance(Test.GENERAL_BOOLEAN); try { @@ -1250,6 +1257,11 @@ public void onVoiceCommandSelected() { JSON_TEXTFIELDTYPES.put(MetadataType.MEDIA_ARTIST); JSON_SEAT_LOCATIONS.put(JSON_GRID); + JSON_MODULE_INFO.put(ModuleInfo.KEY_MODULE_ID, Test.GENERAL_STRING); + JSON_MODULE_INFO.put(ModuleInfo.KEY_MODULE_LOCATION, Test.JSON_GRID); + JSON_MODULE_INFO.put(ModuleInfo.KEY_MODULE_SERVICE_AREA, Test.JSON_GRID); + JSON_MODULE_INFO.put(ModuleInfo.KEY_MULTIPLE_ACCESS_ALLOWED, Test.GENERAL_BOOLEAN); + } catch (JSONException e) { Log.e("Test", "Static Json Construction Failed.", e); diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Validator.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Validator.java index 1a93637d13..2ea70a09a6 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Validator.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Validator.java @@ -53,6 +53,7 @@ import com.smartdevicelink.proxy.rpc.MediaServiceManifest; import com.smartdevicelink.proxy.rpc.MenuParams; import com.smartdevicelink.proxy.rpc.ModuleData; +import com.smartdevicelink.proxy.rpc.ModuleInfo; import com.smartdevicelink.proxy.rpc.MyKey; import com.smartdevicelink.proxy.rpc.NavigationCapability; import com.smartdevicelink.proxy.rpc.NavigationInstruction; @@ -3622,6 +3623,29 @@ public static boolean validateGrid(Grid g1, Grid g2) { return true; } + public static boolean validateModuleInfo(ModuleInfo m1, ModuleInfo m2) { + if (m1 == null) { + return (m2 == null); + } + if (m2 == null) { + return (m1 == null); + } + if (!m1.getModuleId().equals(m2.getModuleId())) { + return false; + } + if (!m1.getMultipleAccessAllowance().equals(m2.getMultipleAccessAllowance())) { + return false; + } + if (!validateGrid(m1.getModuleLocation(), m2.getModuleLocation())) { + return false; + } + if (!validateGrid(m1.getModuleServiceArea(), m2.getModuleServiceArea())) { + return false; + } + + return true; + } + public static boolean validateSeatLocation(SeatLocation cap1, SeatLocation cap2) { if (cap1 == null) { return (cap2 == null); diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AudioControlCapabilitiesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AudioControlCapabilitiesTests.java index 524a6bde22..5351bf7a1b 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AudioControlCapabilitiesTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AudioControlCapabilitiesTests.java @@ -1,14 +1,18 @@ package com.smartdevicelink.test.rpc.datatypes; +import com.smartdevicelink.marshal.JsonRPCMarshaller; import com.smartdevicelink.proxy.rpc.AudioControlCapabilities; +import com.smartdevicelink.proxy.rpc.ModuleInfo; import com.smartdevicelink.test.JsonUtils; import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; import junit.framework.TestCase; import org.json.JSONException; import org.json.JSONObject; +import java.util.Hashtable; import java.util.Iterator; /** @@ -30,6 +34,7 @@ public void setUp() { msg.setEqualizerAvailable(Test.GENERAL_BOOLEAN); msg.setVolumeAvailable(Test.GENERAL_BOOLEAN); msg.setEqualizerMaxChannelId(Test.GENERAL_INT); + msg.setModuleInfo(Test.GENERAL_MODULE_INFO); } /** @@ -44,6 +49,7 @@ public void testRpcValues() { Boolean volumeAvailable = msg.getVolumeAvailable(); Boolean equalizerAvailable = msg.getEqualizerAvailable(); int equalizerMaxChannelId = msg.getEqualizerMaxChannelId(); + ModuleInfo info = msg.getModuleInfo(); // Valid Tests assertEquals(Test.MATCH, Test.GENERAL_STRING, moduleName); @@ -52,6 +58,7 @@ public void testRpcValues() { assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, (boolean) volumeAvailable); assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, (boolean) equalizerAvailable); assertEquals(Test.MATCH, Test.GENERAL_INT, equalizerMaxChannelId); + assertEquals(Test.MATCH, Test.GENERAL_MODULE_INFO, info); // Invalid/Null Tests AudioControlCapabilities msg = new AudioControlCapabilities(); @@ -63,6 +70,7 @@ public void testRpcValues() { assertNull(Test.NULL, msg.getVolumeAvailable()); assertNull(Test.NULL, msg.getEqualizerAvailable()); assertNull(Test.NULL, msg.getEqualizerMaxChannelId()); + assertNull(Test.NULL, msg.getModuleInfo()); } public void testJson() { @@ -76,6 +84,7 @@ public void testJson() { reference.put(AudioControlCapabilities.KEY_VOLUME_AVAILABLE, Test.GENERAL_BOOLEAN); reference.put(AudioControlCapabilities.KEY_EQUALIZER_AVAILABLE, Test.GENERAL_BOOLEAN); reference.put(AudioControlCapabilities.KEY_EQUALIZER_MAX_CHANNEL_ID, Test.GENERAL_INT); + reference.put(AudioControlCapabilities.KEY_MODULE_INFO, Test.JSON_MODULE_INFO); JSONObject underTest = msg.serializeJSON(); assertEquals(Test.MATCH, reference.length(), underTest.length()); @@ -83,9 +92,15 @@ public void testJson() { Iterator iterator = reference.keys(); while (iterator.hasNext()) { String key = (String) iterator.next(); - - assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key)); - + if (key.equals(AudioControlCapabilities.KEY_MODULE_INFO)) { + JSONObject o1 = (JSONObject) JsonUtils.readObjectFromJsonObject(reference, key); + JSONObject o2 = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable h1 = JsonRPCMarshaller.deserializeJSONObject(o1); + Hashtable h2 = JsonRPCMarshaller.deserializeJSONObject(o2); + assertTrue(Test.TRUE, Validator.validateModuleInfo(new ModuleInfo(h1), new ModuleInfo(h2))); + } else { + assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key)); + } } } catch (JSONException e) { fail(Test.JSON_FAIL); diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ButtonCapabilitiesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ButtonCapabilitiesTests.java index 4365ceafa7..71f7d3ecf1 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ButtonCapabilitiesTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ButtonCapabilitiesTests.java @@ -1,15 +1,19 @@ package com.smartdevicelink.test.rpc.datatypes; +import com.smartdevicelink.marshal.JsonRPCMarshaller; import com.smartdevicelink.proxy.rpc.ButtonCapabilities; +import com.smartdevicelink.proxy.rpc.ModuleInfo; import com.smartdevicelink.proxy.rpc.enums.ButtonName; import com.smartdevicelink.test.JsonUtils; import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; import junit.framework.TestCase; import org.json.JSONException; import org.json.JSONObject; +import java.util.Hashtable; import java.util.Iterator; /** @@ -28,6 +32,7 @@ public void setUp(){ msg.setName(Test.GENERAL_BUTTONNAME); msg.setShortPressAvailable(Test.GENERAL_BOOLEAN); msg.setUpDownAvailable(Test.GENERAL_BOOLEAN); + msg.setModuleInfo(Test.GENERAL_MODULE_INFO); } @@ -40,12 +45,14 @@ public void testRpcValues () { boolean longPress = msg.getLongPressAvailable(); boolean upDown = msg.getUpDownAvailable(); ButtonName buttonName = msg.getName(); + ModuleInfo info = msg.getModuleInfo(); // Valid Tests assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, shortPress); assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, longPress); assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, upDown); assertEquals(Test.MATCH, Test.GENERAL_BUTTONNAME, buttonName); + assertEquals(Test.MATCH, Test.GENERAL_MODULE_INFO, info); // Invalid/Null Tests ButtonCapabilities msg = new ButtonCapabilities(); @@ -65,15 +72,24 @@ public void testJson(){ reference.put(ButtonCapabilities.KEY_LONG_PRESS_AVAILABLE, Test.GENERAL_BOOLEAN); reference.put(ButtonCapabilities.KEY_UP_DOWN_AVAILABLE, Test.GENERAL_BOOLEAN); reference.put(ButtonCapabilities.KEY_NAME, Test.GENERAL_BUTTONNAME); + reference.put(ButtonCapabilities.KEY_MODULE_INFO, Test.JSON_MODULE_INFO); JSONObject underTest = msg.serializeJSON(); assertEquals(Test.MATCH, reference.length(), underTest.length()); Iterator iterator = reference.keys(); - while(iterator.hasNext()){ + while (iterator.hasNext()) { String key = (String) iterator.next(); - assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key)); + if (key.equals(ButtonCapabilities.KEY_MODULE_INFO)) { + JSONObject o1 = (JSONObject) JsonUtils.readObjectFromJsonObject(reference, key); + JSONObject o2 = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable h1 = JsonRPCMarshaller.deserializeJSONObject(o1); + Hashtable h2 = JsonRPCMarshaller.deserializeJSONObject(o2); + assertTrue(Test.TRUE, Validator.validateModuleInfo(new ModuleInfo(h1), new ModuleInfo(h2))); + } else { + assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key)); + } } } catch(JSONException e){ fail(Test.JSON_FAIL); diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ClimateControlCapabilitiesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ClimateControlCapabilitiesTests.java index c391eb4eb3..2220329910 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ClimateControlCapabilitiesTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ClimateControlCapabilitiesTests.java @@ -1,10 +1,13 @@ package com.smartdevicelink.test.rpc.datatypes; +import com.smartdevicelink.marshal.JsonRPCMarshaller; import com.smartdevicelink.proxy.rpc.ClimateControlCapabilities; +import com.smartdevicelink.proxy.rpc.ModuleInfo; import com.smartdevicelink.proxy.rpc.enums.DefrostZone; import com.smartdevicelink.proxy.rpc.enums.VentilationMode; import com.smartdevicelink.test.JsonUtils; import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; import junit.framework.TestCase; @@ -13,6 +16,7 @@ import org.json.JSONObject; import java.util.ArrayList; +import java.util.Hashtable; import java.util.Iterator; import java.util.List; @@ -44,6 +48,7 @@ public void setUp(){ msg.setHeatedWindshieldAvailable(Test.GENERAL_BOOLEAN); msg.setHeatedRearWindowAvailable(Test.GENERAL_BOOLEAN); msg.setHeatedMirrorsAvailable(Test.GENERAL_BOOLEAN); + msg.setModuleInfo(Test.GENERAL_MODULE_INFO); } /** @@ -67,6 +72,7 @@ public void testRpcValues () { boolean heatedWindshieldAvailable = msg.getHeatedWindshieldAvailable(); boolean heatedRearWindowAvailable = msg.getHeatedRearWindowAvailable(); boolean heatedMirrorsAvailable = msg.getHeatedMirrorsAvailable(); + ModuleInfo info = msg.getModuleInfo(); // Valid Tests assertEquals(Test.MATCH, Test.GENERAL_STRING, moduleName); @@ -79,6 +85,7 @@ public void testRpcValues () { assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, dualModeEnableAvailable); assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, defrostZoneAvailable); assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, ventilationModeAvailable); + assertEquals(Test.MATCH, Test.GENERAL_MODULE_INFO, info); assertEquals(Test.MATCH, Test.GENERAL_DEFROSTZONE_LIST.size(), defrostZone.size()); assertEquals(Test.MATCH, Test.GENERAL_VENTILATIONMODE_LIST.size(), ventilationMode.size()); @@ -113,6 +120,7 @@ public void testRpcValues () { assertNull(Test.NULL, msg.getHeatedWindshieldAvailable()); assertNull(Test.NULL, msg.getHeatedRearWindowAvailable()); assertNull(Test.NULL, msg.getHeatedMirrorsAvailable()); + assertNull(Test.NULL, msg.getModuleInfo()); } public void testJson(){ @@ -135,6 +143,7 @@ public void testJson(){ reference.put(ClimateControlCapabilities.KEY_HEATED_WIND_SHIELD_AVAILABLE, Test.GENERAL_BOOLEAN); reference.put(ClimateControlCapabilities.KEY_HEATED_REAR_WINDOW_AVAILABLE, Test.GENERAL_BOOLEAN); reference.put(ClimateControlCapabilities.KEY_HEATED_MIRRORS_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(ClimateControlCapabilities.KEY_MODULE_INFO, Test.JSON_MODULE_INFO); JSONObject underTest = msg.serializeJSON(); assertEquals(Test.MATCH, reference.length(), underTest.length()); @@ -169,6 +178,12 @@ public void testJson(){ ventilationModeListTest.add( (VentilationMode)ventilationModeArrayTest.get(index) ); } assertTrue(Test.TRUE, ventilationModeListReference.containsAll(ventilationModeListTest) && ventilationModeListTest.containsAll(ventilationModeListReference)); + } else if (key.equals(ClimateControlCapabilities.KEY_MODULE_INFO)) { + JSONObject o1 = (JSONObject) JsonUtils.readObjectFromJsonObject(reference, key); + JSONObject o2 = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable h1 = JsonRPCMarshaller.deserializeJSONObject(o1); + Hashtable h2 = JsonRPCMarshaller.deserializeJSONObject(o2); + assertTrue(Test.TRUE, Validator.validateModuleInfo(new ModuleInfo(h1), new ModuleInfo(h2))); } else{ assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key)); } diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HMISettingsControlCapabilitiesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HMISettingsControlCapabilitiesTests.java index 620868b408..aa49bf0ac5 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HMISettingsControlCapabilitiesTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HMISettingsControlCapabilitiesTests.java @@ -1,14 +1,18 @@ package com.smartdevicelink.test.rpc.datatypes; +import com.smartdevicelink.marshal.JsonRPCMarshaller; import com.smartdevicelink.proxy.rpc.HMISettingsControlCapabilities; +import com.smartdevicelink.proxy.rpc.ModuleInfo; import com.smartdevicelink.test.JsonUtils; import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; import junit.framework.TestCase; import org.json.JSONException; import org.json.JSONObject; +import java.util.Hashtable; import java.util.Iterator; /** @@ -27,6 +31,7 @@ public void setUp() { msg.setDistanceUnitAvailable(Test.GENERAL_BOOLEAN); msg.setTemperatureUnitAvailable(Test.GENERAL_BOOLEAN); msg.setDisplayModeUnitAvailable(Test.GENERAL_BOOLEAN); + msg.setModuleInfo(Test.GENERAL_MODULE_INFO); } /** @@ -38,12 +43,14 @@ public void testRpcValues() { Boolean distanceUnitAvailable = msg.getDistanceUnitAvailable(); Boolean temperatureUnitAvailable = msg.getTemperatureUnitAvailable(); Boolean displayModeUnitAvailable = msg.getDisplayModeUnitAvailable(); + ModuleInfo info = msg.getModuleInfo(); // Valid Tests assertEquals(Test.MATCH, Test.GENERAL_STRING, moduleName); assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, (boolean) distanceUnitAvailable); assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, (boolean) temperatureUnitAvailable); assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, (boolean) displayModeUnitAvailable); + assertEquals(Test.MATCH, Test.GENERAL_MODULE_INFO, info); // Invalid/Null Tests HMISettingsControlCapabilities msg = new HMISettingsControlCapabilities(); @@ -53,6 +60,7 @@ public void testRpcValues() { assertNull(Test.NULL, msg.getDistanceUnitAvailable()); assertNull(Test.NULL, msg.getTemperatureUnitAvailable()); assertNull(Test.NULL, msg.getDisplayModeUnitAvailable()); + assertNull(Test.NULL, msg.getModuleInfo()); } public void testJson() { @@ -63,6 +71,7 @@ public void testJson() { reference.put(HMISettingsControlCapabilities.KEY_DISTANCE_UNIT_AVAILABLE, Test.GENERAL_BOOLEAN); reference.put(HMISettingsControlCapabilities.KEY_TEMPERATURE_UNIT_AVAILABLE, Test.GENERAL_BOOLEAN); reference.put(HMISettingsControlCapabilities.KEY_DISPLAY_MODE_UNIT_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(HMISettingsControlCapabilities.KEY_MODULE_INFO, Test.JSON_MODULE_INFO); JSONObject underTest = msg.serializeJSON(); assertEquals(Test.MATCH, reference.length(), underTest.length()); @@ -70,8 +79,15 @@ public void testJson() { Iterator iterator = reference.keys(); while (iterator.hasNext()) { String key = (String) iterator.next(); - - assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key)); + if (key.equals(HMISettingsControlCapabilities.KEY_MODULE_INFO)) { + JSONObject o1 = (JSONObject) JsonUtils.readObjectFromJsonObject(reference, key); + JSONObject o2 = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable h1 = JsonRPCMarshaller.deserializeJSONObject(o1); + Hashtable h2 = JsonRPCMarshaller.deserializeJSONObject(o2); + assertTrue(Test.TRUE, Validator.validateModuleInfo(new ModuleInfo(h1), new ModuleInfo(h2))); + } else { + assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key)); + } } } catch (JSONException e) { fail(Test.JSON_FAIL); diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/LightControlCapabilitiesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/LightControlCapabilitiesTests.java index 4ebd7f467a..ad6e5a4acf 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/LightControlCapabilitiesTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/LightControlCapabilitiesTests.java @@ -3,6 +3,7 @@ import com.smartdevicelink.marshal.JsonRPCMarshaller; import com.smartdevicelink.proxy.rpc.LightCapabilities; import com.smartdevicelink.proxy.rpc.LightControlCapabilities; +import com.smartdevicelink.proxy.rpc.ModuleInfo; import com.smartdevicelink.test.JsonUtils; import com.smartdevicelink.test.Test; import com.smartdevicelink.test.Validator; @@ -13,6 +14,7 @@ import org.json.JSONException; import org.json.JSONObject; +import java.util.Hashtable; import java.util.Iterator; import java.util.List; @@ -30,6 +32,7 @@ public void setUp() { msg.setModuleName(Test.GENERAL_STRING); msg.setSupportedLights(Test.GENERAL_LIGHTCAPABILITIES_LIST); + msg.setModuleInfo(Test.GENERAL_MODULE_INFO); } /** @@ -39,10 +42,12 @@ public void testRpcValues() { // Test Values String moduleName = msg.getModuleName(); List supportedLights = msg.getSupportedLights(); + ModuleInfo info = msg.getModuleInfo(); // Valid Tests assertEquals(Test.MATCH, Test.GENERAL_STRING, moduleName); assertEquals(Test.MATCH, Test.GENERAL_LIGHTCAPABILITIES_LIST.size(), supportedLights.size()); + assertEquals(Test.MATCH, Test.GENERAL_MODULE_INFO, info); assertTrue(Test.TRUE, Validator.validateLightCapabilitiesList(Test.GENERAL_LIGHTCAPABILITIES_LIST, supportedLights)); @@ -52,6 +57,7 @@ public void testRpcValues() { assertNull(Test.NULL, msg.getModuleName()); assertNull(Test.NULL, msg.getSupportedLights()); + assertNull(Test.NULL, msg.getModuleInfo()); } public void testJson() { @@ -60,6 +66,7 @@ public void testJson() { try { reference.put(LightControlCapabilities.KEY_MODULE_NAME, Test.GENERAL_STRING); reference.put(LightControlCapabilities.KEY_SUPPORTED_LIGHTS, Test.GENERAL_LIGHTCAPABILITIES_LIST); + reference.put(LightControlCapabilities.KEY_MODULE_INFO, Test.JSON_MODULE_INFO); JSONObject underTest = msg.serializeJSON(); assertEquals(Test.MATCH, reference.length(), underTest.length()); @@ -75,7 +82,14 @@ public void testJson() { for (LightCapabilities lc : lcReference) { assertTrue(Validator.validateLightCapabilities(lc, new LightCapabilities(JsonRPCMarshaller.deserializeJSONObject(lsArray.getJSONObject(i++))))); } - } else { + } else if(key.equals(LightControlCapabilities.KEY_MODULE_INFO)) { + JSONObject o1 = (JSONObject) JsonUtils.readObjectFromJsonObject(reference, key); + JSONObject o2 = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable h1 = JsonRPCMarshaller.deserializeJSONObject(o1); + Hashtable h2 = JsonRPCMarshaller.deserializeJSONObject(o2); + assertTrue(Test.TRUE, Validator.validateModuleInfo(new ModuleInfo(h1), new ModuleInfo(h2))); + } + else { assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key)); } } diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ModuleDataTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ModuleDataTests.java index b553587ade..7f4a78b274 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ModuleDataTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ModuleDataTests.java @@ -39,6 +39,7 @@ public void setUp() { msg.setAudioControlData(Test.GENERAL_AUDIOCONTROLDATA); msg.setHmiSettingsControlData(Test.GENERAL_HMISETTINGSCONTROLDATA); msg.setLightControlData(Test.GENERAL_LIGHTCONTROLDATA); + msg.setModuleId(Test.GENERAL_STRING); } /** @@ -53,6 +54,7 @@ public void testRpcValues() { AudioControlData audioControlData = msg.getAudioControlData(); HMISettingsControlData hmiSettingsControlData = msg.getHmiSettingsControlData(); LightControlData lightControlData = msg.getLightControlData(); + String moduleId = msg.getModuleId(); // Valid Tests assertEquals(Test.MATCH, Test.GENERAL_MODULETYPE, moduleType); @@ -62,6 +64,7 @@ public void testRpcValues() { assertTrue(Test.TRUE, Validator.validateAudioControlData(Test.GENERAL_AUDIOCONTROLDATA, audioControlData)); assertTrue(Test.TRUE, Validator.validateHMISettingsControlData(Test.GENERAL_HMISETTINGSCONTROLDATA, hmiSettingsControlData)); assertTrue(Test.TRUE, Validator.validateLightControlData(Test.GENERAL_LIGHTCONTROLDATA, lightControlData)); + assertEquals(Test.MATCH, Test.GENERAL_STRING, moduleId); // Invalid/Null Tests ModuleData msg = new ModuleData(); @@ -74,6 +77,7 @@ public void testRpcValues() { assertNull(Test.NULL, msg.getAudioControlData()); assertNull(Test.NULL, msg.getHmiSettingsControlData()); assertNull(Test.NULL, msg.getLightControlData()); + assertNull(Test.NULL, msg.getModuleId()); } public void testJson() { @@ -87,6 +91,7 @@ public void testJson() { reference.put(ModuleData.KEY_AUDIO_CONTROL_DATA, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_AUDIOCONTROLDATA.getStore())); reference.put(ModuleData.KEY_HMI_SETTINGS_CONTROL_DATA, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_HMISETTINGSCONTROLDATA.getStore())); reference.put(ModuleData.KEY_LIGHT_CONTROL_DATA, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_LIGHTCONTROLDATA.getStore())); + reference.put(ModuleData.KEY_MODULE_ID, Test.GENERAL_STRING); JSONObject underTest = msg.serializeJSON(); assertEquals(Test.MATCH, reference.length(), underTest.length()); diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ModuleInfoTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ModuleInfoTests.java index be818a514e..142d5ef23a 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ModuleInfoTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ModuleInfoTests.java @@ -57,33 +57,10 @@ public void testJson() { JSONObject serialized = msg.serializeJSON(); assertEquals(Test.MATCH, original.length(), serialized.length()); - Iterator iter = original.keys(); - while (iter.hasNext()) { - String key = iter.next(); - if (key.equals(ModuleInfo.KEY_MODULE_LOCATION) || key.equals(ModuleInfo.KEY_MODULE_SERVICE_AREA)) { - doTestJson(original, serialized, key); - } else if (key.equals(ModuleInfo.KEY_MODULE_ID)) { - String s1 = new ModuleInfo(JsonRPCMarshaller.deserializeJSONObject(original)).getModuleId(); - String s2 = new ModuleInfo(JsonRPCMarshaller.deserializeJSONObject(serialized)).getModuleId(); - assertEquals(Test.MATCH, s1, s2); - } else if (key.equals(ModuleInfo.KEY_MULTIPLE_ACCESS_ALLOWED)) { - boolean b1 = new ModuleInfo(JsonRPCMarshaller.deserializeJSONObject(original)).getMultipleAccessAllowance(); - boolean b2 = new ModuleInfo(JsonRPCMarshaller.deserializeJSONObject(serialized)).getMultipleAccessAllowance(); - assertEquals(Test.MATCH, b1, b2); - } - } - } catch (JSONException e) { - fail(Test.JSON_FAIL); - } - } - private void doTestJson(JSONObject obj1, JSONObject obj2, String key) { - try { - JSONObject o1 = (JSONObject) JsonUtils.readObjectFromJsonObject(obj1, key); - JSONObject o2 = (JSONObject) JsonUtils.readObjectFromJsonObject(obj2, key); - Hashtable h1 = JsonRPCMarshaller.deserializeJSONObject(o1); - Hashtable h2 = JsonRPCMarshaller.deserializeJSONObject(o2); - assertTrue(Test.TRUE, Validator.validateGrid(new Grid(h1), new Grid(h2))); + Hashtable h1 = JsonRPCMarshaller.deserializeJSONObject(original); + Hashtable h2 = JsonRPCMarshaller.deserializeJSONObject(serialized); + assertTrue(Test.TRUE, Validator.validateModuleInfo(new ModuleInfo(h1), new ModuleInfo(h2))); } catch (JSONException e) { fail(Test.JSON_FAIL); } diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/RadioControlCapabilitiesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/RadioControlCapabilitiesTests.java index 915e779a7d..df51ce0164 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/RadioControlCapabilitiesTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/RadioControlCapabilitiesTests.java @@ -1,14 +1,18 @@ package com.smartdevicelink.test.rpc.datatypes; +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.ModuleInfo; import com.smartdevicelink.proxy.rpc.RadioControlCapabilities; import com.smartdevicelink.test.JsonUtils; import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; import junit.framework.TestCase; import org.json.JSONException; import org.json.JSONObject; +import java.util.Hashtable; import java.util.Iterator; /** @@ -36,6 +40,7 @@ public void setUp(){ msg.setHdRadioEnableAvailable(Test.GENERAL_BOOLEAN); msg.setSiriusXMRadioAvailable(Test.GENERAL_BOOLEAN); msg.setSisDataAvailable(Test.GENERAL_BOOLEAN); + msg.setModuleInfo(Test.GENERAL_MODULE_INFO); } /** @@ -56,6 +61,7 @@ public void testRpcValues () { boolean hdRadioEnableAvailable = msg.getHdRadioEnableAvailable(); boolean siriusXMRadioAvailable = msg.getSiriusXMRadioAvailable(); boolean sisDataAvailable = msg.getSisDataAvailable(); + ModuleInfo info = msg.getModuleInfo(); // Valid Tests @@ -72,6 +78,7 @@ public void testRpcValues () { assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, hdRadioEnableAvailable); assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, siriusXMRadioAvailable); assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, sisDataAvailable); + assertEquals(Test.MATCH, Test.GENERAL_MODULE_INFO, info); // Invalid/Null Tests RadioControlCapabilities msg = new RadioControlCapabilities(); @@ -90,6 +97,7 @@ public void testRpcValues () { assertNull(Test.NULL, msg.getHdRadioEnableAvailable()); assertNull(Test.NULL, msg.getSiriusXMRadioAvailable()); assertNull(Test.NULL, msg.getSisDataAvailable()); + assertNull(Test.NULL, msg.getModuleInfo()); } public void testJson(){ @@ -109,6 +117,7 @@ public void testJson(){ reference.put(RadioControlCapabilities.KEY_HD_RADIO_ENABLE_AVAILABLE, Test.GENERAL_BOOLEAN); reference.put(RadioControlCapabilities.KEY_SIRIUS_XM_RADIO_AVAILABLE, Test.GENERAL_BOOLEAN); reference.put(RadioControlCapabilities.KEY_SIS_DATA_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(RadioControlCapabilities.KEY_MODULE_INFO, Test.JSON_MODULE_INFO); JSONObject underTest = msg.serializeJSON(); assertEquals(Test.MATCH, reference.length(), underTest.length()); @@ -116,8 +125,15 @@ public void testJson(){ Iterator iterator = reference.keys(); while(iterator.hasNext()){ String key = (String) iterator.next(); - - assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key)); + if (key.equals(RadioControlCapabilities.KEY_MODULE_INFO)) { + JSONObject o1 = (JSONObject) JsonUtils.readObjectFromJsonObject(reference, key); + JSONObject o2 = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable h1 = JsonRPCMarshaller.deserializeJSONObject(o1); + Hashtable h2 = JsonRPCMarshaller.deserializeJSONObject(o2); + assertTrue(Test.TRUE, Validator.validateModuleInfo(new ModuleInfo(h1), new ModuleInfo(h2))); + } else { + assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key)); + } } } catch(JSONException e){ diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/ButtonPressTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/ButtonPressTests.java index f16a3a87c5..6f90585d45 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/ButtonPressTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/ButtonPressTests.java @@ -30,6 +30,7 @@ protected RPCMessage createMessage(){ msg.setModuleType(Test.GENERAL_MODULETYPE); msg.setButtonPressMode(Test.GENERAL_BUTTONPRESSMODE); msg.setButtonName(Test.GENERAL_BUTTONNAME); + msg.setModuleId(Test.GENERAL_STRING); return msg; } @@ -52,6 +53,7 @@ protected JSONObject getExpectedParameters(int sdlVersion){ result.put(ButtonPress.KEY_MODULE_TYPE, Test.GENERAL_MODULETYPE); result.put(ButtonPress.KEY_BUTTON_NAME, Test.GENERAL_BUTTONNAME); result.put(ButtonPress.KEY_BUTTON_PRESS_MODE, Test.GENERAL_BUTTONPRESSMODE); + result.put(ButtonPress.KEY_MODULE_ID, Test.GENERAL_STRING); }catch(JSONException e){ fail(Test.JSON_FAIL); } @@ -67,11 +69,13 @@ public void testRpcValues () { ModuleType testModuleType = ( (ButtonPress) msg ).getModuleType(); ButtonName testButtonName = ( (ButtonPress) msg ).getButtonName(); ButtonPressMode testButtonPressMode = ( (ButtonPress) msg ).getButtonPressMode(); + String testButtonId = ((ButtonPress) msg).getModuleId(); // Valid Tests assertEquals(Test.MATCH, Test.GENERAL_MODULETYPE, testModuleType); assertEquals(Test.MATCH, Test.GENERAL_BUTTONNAME, testButtonName); assertEquals(Test.MATCH, Test.GENERAL_BUTTONPRESSMODE, testButtonPressMode); + assertEquals(Test.MATCH, Test.GENERAL_STRING, testButtonId); // Invalid/Null Tests ButtonPress msg = new ButtonPress(); @@ -81,6 +85,7 @@ public void testRpcValues () { assertNull(Test.NULL, msg.getModuleType()); assertNull(Test.NULL, msg.getButtonName()); assertNull(Test.NULL, msg.getButtonPressMode()); + assertNull(Test.NULL, msg.getModuleId()); } /** @@ -106,6 +111,7 @@ public void testJsonConstructor () { assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(parameters, ButtonPress.KEY_MODULE_TYPE).toString(), cmd.getModuleType().toString()); assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(parameters, ButtonPress.KEY_BUTTON_NAME).toString(), cmd.getButtonName().toString()); assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(parameters, ButtonPress.KEY_BUTTON_PRESS_MODE).toString(), cmd.getButtonPressMode().toString()); + assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(parameters, ButtonPress.KEY_MODULE_ID), cmd.getModuleId()); }catch (JSONException e) { fail(Test.JSON_FAIL); } diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetInteriorVehicleDataTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetInteriorVehicleDataTests.java index 5a08d42663..dd175ae6f6 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetInteriorVehicleDataTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetInteriorVehicleDataTests.java @@ -27,6 +27,7 @@ protected RPCMessage createMessage(){ msg.setModuleType(Test.GENERAL_MODULETYPE); msg.setSubscribe(Test.GENERAL_BOOLEAN); + msg.setModuleId(Test.GENERAL_STRING); return msg; } @@ -48,6 +49,7 @@ protected JSONObject getExpectedParameters(int sdlVersion){ try{ result.put(GetInteriorVehicleData.KEY_MODULE_TYPE, Test.GENERAL_MODULETYPE); result.put(GetInteriorVehicleData.KEY_SUBSCRIBE, Test.GENERAL_BOOLEAN); + result.put(GetInteriorVehicleData.KEY_MODULE_ID, Test.GENERAL_STRING); }catch(JSONException e){ fail(Test.JSON_FAIL); } @@ -62,10 +64,12 @@ public void testRpcValues () { // Test Values ModuleType testModuleType = ( (GetInteriorVehicleData) msg ).getModuleType(); boolean testSubscribed = ( (GetInteriorVehicleData) msg ).getSubscribe(); + String testModuleId = ((GetInteriorVehicleData) msg).getModuleId(); // Valid Tests assertEquals(Test.MATCH, Test.GENERAL_MODULETYPE, testModuleType); assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, testSubscribed); + assertEquals(Test.MATCH, Test.GENERAL_STRING, testModuleId); // Invalid/Null Tests GetInteriorVehicleData msg = new GetInteriorVehicleData(); @@ -74,6 +78,7 @@ public void testRpcValues () { assertNull(Test.NULL, msg.getModuleType()); assertNull(Test.NULL, msg.getSubscribe()); + assertNull(Test.NULL, msg.getModuleId()); } /** @@ -98,6 +103,7 @@ public void testJsonConstructor () { assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(parameters, GetInteriorVehicleData.KEY_MODULE_TYPE).toString(), cmd.getModuleType().toString()); assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(parameters, GetInteriorVehicleData.KEY_SUBSCRIBE), cmd.getSubscribe()); + assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(parameters, GetInteriorVehicleData.KEY_MODULE_ID), cmd.getModuleId()); }catch (JSONException e) { fail(Test.JSON_FAIL); } From 7ba046bfa990c3f63d485269e0ae0e314ca30368 Mon Sep 17 00:00:00 2001 From: Tuan Nguyen Date: Mon, 29 Jul 2019 11:31:24 -0700 Subject: [PATCH 13/20] Merge new changes from develop branch --- .../src/androidTest/assets/json/CloseApplication.json | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 android/sdl_android/src/androidTest/assets/json/CloseApplication.json diff --git a/android/sdl_android/src/androidTest/assets/json/CloseApplication.json b/android/sdl_android/src/androidTest/assets/json/CloseApplication.json new file mode 100644 index 0000000000..d58666311e --- /dev/null +++ b/android/sdl_android/src/androidTest/assets/json/CloseApplication.json @@ -0,0 +1,11 @@ +{ + "request":{ + "name":"CloseApplication", + "correlationID":131 + }, + "response":{ + "name":"CloseApplicationResponse", + "correlationID":131, + "parameters":{} + } +} \ No newline at end of file From 0d0da4a88ba6e9051dd3f3a8a21e5946f444f949 Mon Sep 17 00:00:00 2001 From: Tuan Nguyen Date: Mon, 29 Jul 2019 11:32:24 -0700 Subject: [PATCH 14/20] Merge new changes from develop branch --- .../assets/json/UnpublishAppService.json | 13 + .../CheckChoiceVROptionalOperationTests.java | 87 +++ .../screen/choiceset/ChoiceCellTests.java | 122 ++++ .../choiceset/ChoiceSetLayoutTests.java | 92 +++ .../choiceset/ChoiceSetManagerTests.java | 238 +++++++ .../screen/choiceset/ChoiceSetTests.java | 101 +++ .../DeleteChoicesOperationTests.java | 81 +++ .../PreloadChoicesOperationTests.java | 134 ++++ .../PresentChoiceSetOperationTests.java | 105 +++ .../PresentKeyboardOperationTests.java | 83 +++ .../screen/menu/MenuConfigurationTests.java | 63 ++ .../test/rpc/enums/MenuLayoutTests.java | 100 +++ .../rpc/requests/CloseApplicationTests.java | 109 ++++ .../requests/UnpublishAppServiceTests.java | 144 +++++ .../CloseApplicationResponseTests.java | 110 ++++ .../UnpublishAppServiceResponseTests.java | 110 ++++ .../util/MediaStreamingStatusTests.java | 170 +++++ .../screen/choiceset/ChoiceSetManager.java | 55 ++ .../util/MediaStreamingStatus.java | 300 +++++++++ .../choiceset/BaseChoiceSetManager.java | 598 ++++++++++++++++++ .../CheckChoiceVROptionalInterface.java | 41 ++ .../CheckChoiceVROptionalOperation.java | 177 ++++++ .../managers/screen/choiceset/ChoiceCell.java | 260 ++++++++ .../managers/screen/choiceset/ChoiceSet.java | 388 ++++++++++++ .../screen/choiceset/ChoiceSetLayout.java | 46 ++ .../choiceset/ChoiceSetSelectionListener.java | 40 ++ .../choiceset/DeleteChoicesOperation.java | 117 ++++ ...eyboardAutocompleteCompletionListener.java | 55 ++ ...eyboardCharacterSetCompletionListener.java | 12 + .../screen/choiceset/KeyboardListener.java | 87 +++ .../choiceset/PausableThreadPoolExecutor.java | 72 +++ .../choiceset/PreloadChoicesOperation.java | 269 ++++++++ .../choiceset/PresentChoiceSetOperation.java | 312 +++++++++ .../choiceset/PresentKeyboardOperation.java | 263 ++++++++ .../screen/menu/MenuConfiguration.java | 95 +++ .../proxy/rpc/CloseApplication.java | 61 ++ .../proxy/rpc/CloseApplicationResponse.java | 61 ++ .../proxy/rpc/UnpublishAppService.java | 95 +++ .../rpc/UnpublishAppServiceResponse.java | 62 ++ .../proxy/rpc/enums/MenuLayout.java | 57 ++ .../screen/choiceset/ChoiceSetManager.java | 55 ++ 41 files changed, 5440 insertions(+) create mode 100644 android/sdl_android/src/androidTest/assets/json/UnpublishAppService.json create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/CheckChoiceVROptionalOperationTests.java create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/ChoiceCellTests.java create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetLayoutTests.java create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetManagerTests.java create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetTests.java create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/DeleteChoicesOperationTests.java create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PreloadChoicesOperationTests.java create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PresentChoiceSetOperationTests.java create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PresentKeyboardOperationTests.java create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuConfigurationTests.java create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/MenuLayoutTests.java create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/CloseApplicationTests.java create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/UnpublishAppServiceTests.java create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/CloseApplicationResponseTests.java create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/UnpublishAppServiceResponseTests.java create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/util/MediaStreamingStatusTests.java create mode 100644 android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetManager.java create mode 100644 android/sdl_android/src/main/java/com/smartdevicelink/util/MediaStreamingStatus.java create mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/choiceset/BaseChoiceSetManager.java create mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/choiceset/CheckChoiceVROptionalInterface.java create mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/choiceset/CheckChoiceVROptionalOperation.java create mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceCell.java create mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSet.java create mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetLayout.java create mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetSelectionListener.java create mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/choiceset/DeleteChoicesOperation.java create mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/choiceset/KeyboardAutocompleteCompletionListener.java create mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/choiceset/KeyboardCharacterSetCompletionListener.java create mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/choiceset/KeyboardListener.java create mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PausableThreadPoolExecutor.java create mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PreloadChoicesOperation.java create mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PresentChoiceSetOperation.java create mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PresentKeyboardOperation.java create mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuConfiguration.java create mode 100644 base/src/main/java/com/smartdevicelink/proxy/rpc/CloseApplication.java create mode 100644 base/src/main/java/com/smartdevicelink/proxy/rpc/CloseApplicationResponse.java create mode 100644 base/src/main/java/com/smartdevicelink/proxy/rpc/UnpublishAppService.java create mode 100644 base/src/main/java/com/smartdevicelink/proxy/rpc/UnpublishAppServiceResponse.java create mode 100644 base/src/main/java/com/smartdevicelink/proxy/rpc/enums/MenuLayout.java create mode 100644 javaSE/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetManager.java diff --git a/android/sdl_android/src/androidTest/assets/json/UnpublishAppService.json b/android/sdl_android/src/androidTest/assets/json/UnpublishAppService.json new file mode 100644 index 0000000000..70521a278b --- /dev/null +++ b/android/sdl_android/src/androidTest/assets/json/UnpublishAppService.json @@ -0,0 +1,13 @@ +{ + "request":{ + "name":"UnpublishAppService", + "correlationID":184, + "parameters":{ + "serviceID":"test" + } + }, + "response":{ + "name":"UnpublishAppServiceResponse", + "correlationID":185 + } +} \ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/CheckChoiceVROptionalOperationTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/CheckChoiceVROptionalOperationTests.java new file mode 100644 index 0000000000..a47528348c --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/CheckChoiceVROptionalOperationTests.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Created by brettywhite on 6/12/19 1:52 PM + * + */ + +package com.smartdevicelink.managers.screen.choiceset; + +import com.smartdevicelink.AndroidTestCase2; +import com.smartdevicelink.managers.screen.choiceset.CheckChoiceVROptionalInterface; +import com.smartdevicelink.managers.screen.choiceset.CheckChoiceVROptionalOperation; +import com.smartdevicelink.proxy.interfaces.ISdl; +import com.smartdevicelink.proxy.rpc.Choice; +import com.smartdevicelink.proxy.rpc.CreateInteractionChoiceSet; +import com.smartdevicelink.proxy.rpc.DeleteInteractionChoiceSet; + +import static org.mockito.Mockito.mock; + +public class CheckChoiceVROptionalOperationTests extends AndroidTestCase2 { + + private CheckChoiceVROptionalOperation checkChoiceVROptionalOperation; + + @Override + public void setUp() throws Exception{ + super.setUp(); + + ISdl internalInterface = mock(ISdl.class); + CheckChoiceVROptionalInterface checkChoiceVROptionalInterface = mock(CheckChoiceVROptionalInterface.class); + checkChoiceVROptionalOperation = new CheckChoiceVROptionalOperation(internalInterface, checkChoiceVROptionalInterface); + } + + @Override + public void tearDown() throws Exception { + super.tearDown(); + } + + public void testCreateChoiceNoVR(){ + CreateInteractionChoiceSet setNoVR = checkChoiceVROptionalOperation.testCellWithVR(false); + assertNotNull(setNoVR); + // This set only has one choice + Choice choice = setNoVR.getChoiceSet().get(0); + assertNull(choice.getVrCommands()); + } + + public void testCreateChoiceWithVR(){ + CreateInteractionChoiceSet setNoVR = checkChoiceVROptionalOperation.testCellWithVR(true); + assertNotNull(setNoVR); + // This set only has one choice + Choice choice = setNoVR.getChoiceSet().get(0); + assertEquals(choice.getVrCommands().get(0), "Test VR"); + } + + public void testDeleteInteractionChoiceSet(){ + DeleteInteractionChoiceSet deleteSet = checkChoiceVROptionalOperation.createDeleteInteractionChoiceSet(); + assertNotNull(deleteSet); + } + +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/ChoiceCellTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/ChoiceCellTests.java new file mode 100644 index 0000000000..0bf6af4a5e --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/ChoiceCellTests.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.choiceset; + +import com.smartdevicelink.AndroidTestCase2; +import com.smartdevicelink.managers.file.filetypes.SdlArtwork; +import com.smartdevicelink.proxy.rpc.enums.FileType; +import com.smartdevicelink.test.Test; + +public class ChoiceCellTests extends AndroidTestCase2 { + + private static final int MAX_ID = 2000000000; + private SdlArtwork artwork = new SdlArtwork("image", FileType.GRAPHIC_PNG, 1, true); + + @Override + public void setUp() throws Exception{ + super.setUp(); + } + + @Override + public void tearDown() throws Exception { + super.tearDown(); + } + + public void testSettersAndGetters(){ + + // set everything + ChoiceCell choiceCell = new ChoiceCell(Test.GENERAL_STRING); + choiceCell.setSecondaryText(Test.GENERAL_STRING); + choiceCell.setTertiaryText(Test.GENERAL_STRING); + choiceCell.setVoiceCommands(Test.GENERAL_STRING_LIST); + choiceCell.setArtwork(artwork); + choiceCell.setSecondaryArtwork(artwork); + + // use getters and assert equality + assertEquals(choiceCell.getText(), Test.GENERAL_STRING); + assertEquals(choiceCell.getSecondaryText(), Test.GENERAL_STRING); + assertEquals(choiceCell.getTertiaryText(), Test.GENERAL_STRING); + assertEquals(choiceCell.getVoiceCommands(), Test.GENERAL_STRING_LIST); + assertEquals(choiceCell.getArtwork(), artwork); + assertEquals(choiceCell.getSecondaryArtwork(), artwork); + assertEquals(choiceCell.getChoiceId(), MAX_ID); + } + + public void testConstructors() { + // first constructor was tested in previous method, use the rest here + + ChoiceCell choiceCell = new ChoiceCell(Test.GENERAL_STRING, Test.GENERAL_STRING_LIST, artwork); + choiceCell.setSecondaryText(Test.GENERAL_STRING); + choiceCell.setTertiaryText(Test.GENERAL_STRING); + choiceCell.setSecondaryArtwork(artwork); + assertEquals(choiceCell.getText(), Test.GENERAL_STRING); + assertEquals(choiceCell.getSecondaryText(), Test.GENERAL_STRING); + assertEquals(choiceCell.getTertiaryText(), Test.GENERAL_STRING); + assertEquals(choiceCell.getVoiceCommands(), Test.GENERAL_STRING_LIST); + assertEquals(choiceCell.getArtwork(), artwork); + assertEquals(choiceCell.getSecondaryArtwork(), artwork); + assertEquals(choiceCell.getChoiceId(), MAX_ID); + + + choiceCell = new ChoiceCell(Test.GENERAL_STRING, Test.GENERAL_STRING, Test.GENERAL_STRING, Test.GENERAL_STRING_LIST, artwork, artwork); + assertEquals(choiceCell.getText(), Test.GENERAL_STRING); + assertEquals(choiceCell.getSecondaryText(), Test.GENERAL_STRING); + assertEquals(choiceCell.getTertiaryText(), Test.GENERAL_STRING); + assertEquals(choiceCell.getVoiceCommands(), Test.GENERAL_STRING_LIST); + assertEquals(choiceCell.getArtwork(), artwork); + assertEquals(choiceCell.getSecondaryArtwork(), artwork); + assertEquals(choiceCell.getChoiceId(), MAX_ID); + } + + public void testCellEquality(){ + + ChoiceCell choiceCell = new ChoiceCell(Test.GENERAL_STRING, Test.GENERAL_STRING_LIST, artwork); + choiceCell.setSecondaryText(Test.GENERAL_STRING); + choiceCell.setTertiaryText(Test.GENERAL_STRING); + choiceCell.setSecondaryArtwork(artwork); + + ChoiceCell choiceCell2 = new ChoiceCell(Test.GENERAL_STRING, Test.GENERAL_STRING_LIST, artwork); + choiceCell2.setSecondaryText(Test.GENERAL_STRING); + choiceCell2.setTertiaryText(Test.GENERAL_STRING); + choiceCell2.setSecondaryArtwork(artwork); + + ChoiceCell choiceCell3 = new ChoiceCell(Test.GENERAL_STRING, Test.GENERAL_STRING_LIST, artwork); + choiceCell3.setSecondaryText(Test.GENERAL_STRING); + choiceCell3.setTertiaryText(Test.GENERAL_STRING); + + // Make sure our overridden method works, even though these are different objects in memory + assertTrue(choiceCell.equals(choiceCell2)); + assertFalse(choiceCell.equals(choiceCell3)); + + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetLayoutTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetLayoutTests.java new file mode 100644 index 0000000000..3f147f1284 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetLayoutTests.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.choiceset; + +import com.smartdevicelink.AndroidTestCase2; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class ChoiceSetLayoutTests extends AndroidTestCase2 { + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums() { + ChoiceSetLayout choiceSetLayoutList = ChoiceSetLayout.valueForString("CHOICE_SET_LAYOUT_LIST"); + ChoiceSetLayout choiceSetLayoutTiles = ChoiceSetLayout.valueForString("CHOICE_SET_LAYOUT_TILES"); + assertNotNull("CHOICE_SET_LAYOUT_LIST returned null", choiceSetLayoutList); + assertNotNull("choiceSetLayoutTiles returned null", choiceSetLayoutTiles); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum() { + String example = "deFaUlt"; + try { + ChoiceSetLayout temp = ChoiceSetLayout.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum() { + String example = null; + try { + ChoiceSetLayout temp = ChoiceSetLayout.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of DynamicMenuUpdatesMode. + */ + public void testListEnum() { + List enumValueList = Arrays.asList(ChoiceSetLayout.values()); + + List enumTestList = new ArrayList<>(); + enumTestList.add(ChoiceSetLayout.CHOICE_SET_LAYOUT_LIST); + enumTestList.add(ChoiceSetLayout.CHOICE_SET_LAYOUT_TILES); + + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetManagerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetManagerTests.java new file mode 100644 index 0000000000..e52f7b2731 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetManagerTests.java @@ -0,0 +1,238 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Created by brettywhite on 6/11/19 9:58 AM + * + */ + +package com.smartdevicelink.managers.screen.choiceset; + +import com.smartdevicelink.AndroidTestCase2; +import com.smartdevicelink.managers.BaseSubManager; +import com.smartdevicelink.managers.file.FileManager; +import com.smartdevicelink.proxy.interfaces.ISdl; +import com.smartdevicelink.proxy.rpc.KeyboardProperties; +import com.smartdevicelink.proxy.rpc.enums.HMILevel; +import com.smartdevicelink.proxy.rpc.enums.KeyboardLayout; +import com.smartdevicelink.proxy.rpc.enums.KeypressMode; +import com.smartdevicelink.proxy.rpc.enums.Language; +import com.smartdevicelink.proxy.rpc.enums.SystemContext; +import com.smartdevicelink.proxy.rpc.enums.TriggerSource; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; + +import static org.mockito.Mockito.mock; + +public class ChoiceSetManagerTests extends AndroidTestCase2 { + + private ChoiceSetManager csm; + + @Override + public void setUp() throws Exception{ + super.setUp(); + + ISdl internalInterface = mock(ISdl.class); + FileManager fileManager = mock(FileManager.class); + csm = new ChoiceSetManager(internalInterface, fileManager); + + assertEquals(csm.getState(), BaseSubManager.SETTING_UP); + assertEquals(csm.currentSystemContext, SystemContext.SYSCTXT_MAIN); + assertEquals(csm.currentHMILevel, HMILevel.HMI_NONE); + assertEquals(csm.choiceCellIdMin, 1); + assertEquals(csm.nextChoiceId, 1); + assertFalse(csm.isVROptional); + assertNotNull(csm.fileManager); + assertNotNull(csm.preloadedChoices); + assertNotNull(csm.pendingPreloadChoices); + assertNotNull(csm.operationQueue); + assertNotNull(csm.executor); + assertNotNull(csm.hmiListener); + assertNotNull(csm.displayListener); + assertNull(csm.pendingPresentOperation); + } + + @Override + public void tearDown() throws Exception { + + csm.dispose(); + + assertNull(csm.currentHMILevel); + assertNull(csm.currentSystemContext); + assertNull(csm.displayCapabilities); + assertNull(csm.pendingPresentationSet); + assertNull(csm.pendingPresentOperation); + + assertEquals(csm.operationQueue.size(), 0); + assertEquals(csm.nextChoiceId, 1); + + assertTrue(csm.executor.isShutdown()); + assertTrue(csm.isVROptional); + + assertEquals(csm.getState(), BaseSubManager.SHUTDOWN); + + super.tearDown(); + } + + public void testDefaultKeyboardConfiguration(){ + KeyboardProperties properties = csm.defaultKeyboardConfiguration(); + assertEquals(properties.getLanguage(), Language.EN_US); + assertEquals(properties.getKeyboardLayout(), KeyboardLayout.QWERTY); + assertEquals(properties.getKeypressMode(), KeypressMode.RESEND_CURRENT_ENTRY); + } + + public void testSetupChoiceSet(){ + + ChoiceSetSelectionListener choiceSetSelectionListener = new ChoiceSetSelectionListener() { + @Override + public void onChoiceSelected(ChoiceCell choiceCell, TriggerSource triggerSource, int rowIndex) {} + + @Override + public void onError(String error) {} + }; + + // Cannot send choice set with empty or null choice list + ChoiceSet choiceSet1 = new ChoiceSet("test", Collections.emptyList(), choiceSetSelectionListener); + assertFalse(csm.setUpChoiceSet(choiceSet1)); + + // cells cant have duplicate text + ChoiceCell cell1 = new ChoiceCell("test"); + ChoiceCell cell2 = new ChoiceCell("test"); + ChoiceSet choiceSet2 = new ChoiceSet("test", Arrays.asList(cell1, cell2), choiceSetSelectionListener); + assertFalse(csm.setUpChoiceSet(choiceSet2)); + + // cells cannot mix and match VR / non-VR + ChoiceCell cell3 = new ChoiceCell("test", Collections.singletonList("Test"), null); + ChoiceCell cell4 = new ChoiceCell("test2"); + ChoiceSet choiceSet3 = new ChoiceSet("test", Arrays.asList(cell3, cell4), choiceSetSelectionListener); + assertFalse(csm.setUpChoiceSet(choiceSet3)); + + // VR Commands must be unique + ChoiceCell cell5 = new ChoiceCell("test", Collections.singletonList("Test"), null); + ChoiceCell cell6 = new ChoiceCell("test2", Collections.singletonList("Test"), null); + ChoiceSet choiceSet4 = new ChoiceSet("test", Arrays.asList(cell5, cell6), choiceSetSelectionListener); + assertFalse(csm.setUpChoiceSet(choiceSet4)); + + // Passing Case + ChoiceCell cell7 = new ChoiceCell("test", Collections.singletonList("Test"), null); + ChoiceCell cell8 = new ChoiceCell("test2", Collections.singletonList("Test2"), null); + ChoiceSet choiceSet5 = new ChoiceSet("test", Arrays.asList(cell7, cell8), choiceSetSelectionListener); + assertTrue(csm.setUpChoiceSet(choiceSet5)); + } + + public void testFindIfPresent(){ + + ChoiceCell cell1 = new ChoiceCell("test"); + ChoiceCell cell2 = new ChoiceCell("test2"); + ChoiceCell cell3 = new ChoiceCell("test3"); + HashSet cellSet = new HashSet<>(); + cellSet.add(cell1); + cellSet.add(cell2); + + assertNotNull(csm.findIfPresent(cell1, cellSet)); + assertNull(csm.findIfPresent(cell3, cellSet)); + } + + public void testUpdateIdsOnChoices(){ + + ChoiceCell cell1 = new ChoiceCell("test"); + ChoiceCell cell2 = new ChoiceCell("test2"); + ChoiceCell cell3 = new ChoiceCell("test3"); + HashSet cellSet = new HashSet<>(); + cellSet.add(cell1); + cellSet.add(cell2); + cellSet.add(cell3); + // Cells are initially set to MAX_ID + assertEquals(cell1.getChoiceId(), 2000000000); + assertEquals(cell2.getChoiceId(), 2000000000); + assertEquals(cell3.getChoiceId(), 2000000000); + csm.updateIdsOnChoices(cellSet); + // We are looking for unique IDs + assertNotSame(cell1.getChoiceId(), 2000000000); + assertNotSame(cell2.getChoiceId(), 2000000000); + assertNotSame(cell3.getChoiceId(), 2000000000); + } + + public void testChoicesToBeRemovedFromPendingWithArray(){ + + ChoiceCell cell1 = new ChoiceCell("test"); + ChoiceCell cell2 = new ChoiceCell("test2"); + ChoiceCell cell3 = new ChoiceCell("test3"); + + HashSet pendingPreloadSet = new HashSet<>(); + pendingPreloadSet.add(cell1); + pendingPreloadSet.add(cell2); + pendingPreloadSet.add(cell3); + + csm.pendingPreloadChoices.clear(); + csm.pendingPreloadChoices = pendingPreloadSet; + + List choices = new ArrayList<>(); + choices.add(cell2); + + HashSet returnedChoices = csm.choicesToBeRemovedFromPendingWithArray(choices); + + assertEquals(returnedChoices.size(), 1); + for (ChoiceCell cell : returnedChoices){ + assertEquals(cell.getText(), "test2"); + } + } + + public void testChoicesToBeUploadedWithArray(){ + + ChoiceCell cell1 = new ChoiceCell("test"); + ChoiceCell cell2 = new ChoiceCell("test2"); + ChoiceCell cell3 = new ChoiceCell("test3"); + + HashSet pendingDeleteSet = new HashSet<>(); + pendingDeleteSet.add(cell1); + pendingDeleteSet.add(cell2); + pendingDeleteSet.add(cell3); + + csm.preloadedChoices.clear(); + csm.preloadedChoices = pendingDeleteSet; + + List choices = new ArrayList<>(); + choices.add(cell2); + + HashSet returnedChoices = csm.choicesToBeDeletedWithArray(choices); + + assertEquals(returnedChoices.size(), 1); + for (ChoiceCell cell : returnedChoices){ + assertEquals(cell.getText(), "test2"); + } + + } + +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetTests.java new file mode 100644 index 0000000000..3d7a30a79c --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetTests.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.choiceset; + +import com.smartdevicelink.AndroidTestCase2; +import com.smartdevicelink.test.Test; + +import java.util.Arrays; +import java.util.List; + +import static org.mockito.Mockito.mock; + +public class ChoiceSetTests extends AndroidTestCase2 { + + private ChoiceSetSelectionListener listener; + private ChoiceSetLayout layout; + private List choices; + private Integer defaultTimeout; + + @Override + public void setUp() throws Exception{ + super.setUp(); + + listener = mock(ChoiceSetSelectionListener.class); + layout = ChoiceSetLayout.CHOICE_SET_LAYOUT_LIST; + defaultTimeout = 10; + choices = Arrays.asList(new ChoiceCell(Test.GENERAL_STRING), new ChoiceCell(Test.GENERAL_STRING)); + } + + @Override + public void tearDown() throws Exception { + super.tearDown(); + } + + public void testSettersAndGetters(){ + + // test small constructor + ChoiceSet choiceSet = new ChoiceSet(Test.GENERAL_STRING, choices, listener); + + // use getters and assert equality + assertEquals(choiceSet.getTitle(), Test.GENERAL_STRING); + assertEquals(choiceSet.getLayout(), layout); + assertEquals(choiceSet.getTimeout(), defaultTimeout); + assertEquals(choiceSet.getChoices(), choices); + assertEquals(choiceSet.getChoiceSetSelectionListener(), listener); + } + + public void testConstructors() { + + // first constructor was tested in previous method, use the rest here + ChoiceSet choiceSet = new ChoiceSet(Test.GENERAL_STRING, layout, Test.GENERAL_INTEGER, Test.GENERAL_STRING, Test.GENERAL_STRING, Test.GENERAL_STRING, Test.GENERAL_VRHELPITEM_LIST, Test.GENERAL_KEYBOARDPROPERTIES, choices, listener); + assertEquals(choiceSet.getTitle(), Test.GENERAL_STRING); + assertEquals(choiceSet.getInitialPrompt().get(0).getText(),Test.GENERAL_STRING); + assertEquals(choiceSet.getHelpPrompt().get(0).getText(), Test.GENERAL_STRING); + assertEquals(choiceSet.getTimeoutPrompt().get(0).getText(), Test.GENERAL_STRING); + assertEquals(choiceSet.getLayout(), layout); + assertEquals(choiceSet.getTimeout(), Test.GENERAL_INTEGER); + assertEquals(choiceSet.getChoices(), choices); + assertEquals(choiceSet.getChoiceSetSelectionListener(), listener); + + ChoiceSet choiceSet2 = new ChoiceSet(Test.GENERAL_STRING, layout, Test.GENERAL_INTEGER, Test.GENERAL_TTSCHUNK_LIST, Test.GENERAL_TTSCHUNK_LIST, Test.GENERAL_TTSCHUNK_LIST, Test.GENERAL_VRHELPITEM_LIST, Test.GENERAL_KEYBOARDPROPERTIES, choices, listener); + assertEquals(choiceSet2.getTitle(), Test.GENERAL_STRING); + assertEquals(choiceSet2.getInitialPrompt(),Test.GENERAL_TTSCHUNK_LIST); + assertEquals(choiceSet2.getHelpPrompt(), Test.GENERAL_TTSCHUNK_LIST); + assertEquals(choiceSet2.getTimeoutPrompt(), Test.GENERAL_TTSCHUNK_LIST); + assertEquals(choiceSet2.getLayout(), layout); + assertEquals(choiceSet2.getTimeout(), Test.GENERAL_INTEGER); + assertEquals(choiceSet2.getChoices(), choices); + assertEquals(choiceSet2.getChoiceSetSelectionListener(), listener); + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/DeleteChoicesOperationTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/DeleteChoicesOperationTests.java new file mode 100644 index 0000000000..3a9eed3941 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/DeleteChoicesOperationTests.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Created by brettywhite on 6/12/19 1:52 PM + * + */ + +package com.smartdevicelink.managers.screen.choiceset; + +import com.smartdevicelink.AndroidTestCase2; +import com.smartdevicelink.managers.screen.choiceset.ChoiceCell; +import com.smartdevicelink.managers.screen.choiceset.DeleteChoicesOperation; +import com.smartdevicelink.proxy.interfaces.ISdl; +import com.smartdevicelink.proxy.rpc.DeleteInteractionChoiceSet; + +import java.util.HashSet; +import java.util.List; + +import static org.mockito.Mockito.mock; + +public class DeleteChoicesOperationTests extends AndroidTestCase2 { + + private DeleteChoicesOperation deleteChoicesOperation; + + @Override + public void setUp() throws Exception{ + super.setUp(); + + ChoiceCell cell1 = new ChoiceCell("cell 1"); + ChoiceCell cell2 = new ChoiceCell("cell 2"); + HashSet cellsToDelete = new HashSet<>(); + cellsToDelete.add(cell1); + cellsToDelete.add(cell2); + + ISdl internalInterface = mock(ISdl.class); + deleteChoicesOperation = new DeleteChoicesOperation(internalInterface, cellsToDelete, null); + } + + @Override + public void tearDown() throws Exception { + super.tearDown(); + } + + public void testCreateListDeleteInteractionSets(){ + List deletes = deleteChoicesOperation.createDeleteSets(); + assertNotNull(deletes); + assertEquals(deletes.size(), 2); + for (DeleteInteractionChoiceSet delete : deletes) { + assertNotNull(delete); + } + } + +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PreloadChoicesOperationTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PreloadChoicesOperationTests.java new file mode 100644 index 0000000000..514d88bca0 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PreloadChoicesOperationTests.java @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Created by brettywhite on 6/12/19 1:52 PM + * + */ + +package com.smartdevicelink.managers.screen.choiceset; + +import com.smartdevicelink.AndroidTestCase2; +import com.smartdevicelink.managers.file.FileManager; +import com.smartdevicelink.managers.file.filetypes.SdlArtwork; +import com.smartdevicelink.managers.screen.choiceset.ChoiceCell; +import com.smartdevicelink.managers.screen.choiceset.PreloadChoicesOperation; +import com.smartdevicelink.proxy.interfaces.ISdl; +import com.smartdevicelink.proxy.rpc.DisplayCapabilities; +import com.smartdevicelink.proxy.rpc.ImageField; +import com.smartdevicelink.proxy.rpc.TextField; +import com.smartdevicelink.proxy.rpc.enums.CharacterSet; +import com.smartdevicelink.proxy.rpc.enums.FileType; +import com.smartdevicelink.proxy.rpc.enums.ImageFieldName; +import com.smartdevicelink.proxy.rpc.enums.TextFieldName; +import com.smartdevicelink.test.Test; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; + +import static org.mockito.Mockito.mock; + +public class PreloadChoicesOperationTests extends AndroidTestCase2 { + + private PreloadChoicesOperation preloadChoicesOperation; + + @Override + public void setUp() throws Exception{ + + super.setUp(); + + ChoiceCell cell1 = new ChoiceCell("cell 1"); + ChoiceCell cell2 = new ChoiceCell("cell 2", null, Test.GENERAL_ARTWORK); + HashSet cellsToPreload = new HashSet<>(); + cellsToPreload.add(cell1); + cellsToPreload.add(cell2); + + ImageField imageField = new ImageField(ImageFieldName.choiceImage, Arrays.asList(FileType.GRAPHIC_PNG, FileType.GRAPHIC_JPEG)); + TextField textField = new TextField(TextFieldName.menuName, CharacterSet.CID1SET, 2, 2); + + DisplayCapabilities displayCapabilities = new DisplayCapabilities(); + displayCapabilities.setGraphicSupported(true); + displayCapabilities.setImageFields(Collections.singletonList(imageField)); + displayCapabilities.setTextFields(Collections.singletonList(textField)); + + ISdl internalInterface = mock(ISdl.class); + FileManager fileManager = mock(FileManager.class); + preloadChoicesOperation = new PreloadChoicesOperation(internalInterface, fileManager, displayCapabilities, true, cellsToPreload, null); + } + + @Override + public void tearDown() throws Exception { + super.tearDown(); + } + + public void testHasTextFieldOfName(){ + + TextField textField = new TextField(); + textField.setName(TextFieldName.secondaryText); + + DisplayCapabilities capabilities = new DisplayCapabilities(); + capabilities.setTextFields(Collections.singletonList(textField)); + + boolean test = preloadChoicesOperation.hasTextFieldOfName(TextFieldName.secondaryText); + assertFalse(test); + + boolean test2 = preloadChoicesOperation.hasTextFieldOfName(TextFieldName.menuName); + assertTrue(test2); + } + + public void testHasImageFieldOfName(){ + + ImageField imageField = new ImageField(); + imageField.setName(ImageFieldName.choiceImage); + + DisplayCapabilities capabilities = new DisplayCapabilities(); + capabilities.setImageFields(Collections.singletonList(imageField)); + + boolean test = preloadChoicesOperation.hasImageFieldOfName(ImageFieldName.choiceImage); + assertTrue(test); + + boolean test2 = preloadChoicesOperation.hasImageFieldOfName(ImageFieldName.appIcon); + assertFalse(test2); + } + + public void testArtworkNeedsUpload(){ + boolean test = preloadChoicesOperation.artworkNeedsUpload(Test.GENERAL_ARTWORK); + assertTrue(test); + } + + public void testArtworksToUpload(){ + List artworksToUpload = preloadChoicesOperation.artworksToUpload(); + assertNotNull(artworksToUpload); + assertEquals(artworksToUpload.size(), 1); + } + +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PresentChoiceSetOperationTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PresentChoiceSetOperationTests.java new file mode 100644 index 0000000000..ea5204eae5 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PresentChoiceSetOperationTests.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Created by brettywhite on 6/12/19 1:52 PM + * + */ + +package com.smartdevicelink.managers.screen.choiceset; + +import com.smartdevicelink.AndroidTestCase2; +import com.smartdevicelink.proxy.interfaces.ISdl; +import com.smartdevicelink.proxy.rpc.KeyboardProperties; +import com.smartdevicelink.proxy.rpc.PerformInteraction; +import com.smartdevicelink.proxy.rpc.enums.InteractionMode; +import com.smartdevicelink.proxy.rpc.enums.KeyboardLayout; +import com.smartdevicelink.proxy.rpc.enums.KeypressMode; +import com.smartdevicelink.proxy.rpc.enums.Language; +import com.smartdevicelink.proxy.rpc.enums.LayoutMode; + +import java.util.Collections; + +import static org.mockito.Mockito.mock; + +public class PresentChoiceSetOperationTests extends AndroidTestCase2 { + + private PresentChoiceSetOperation presentChoiceSetOperation; + + @Override + public void setUp() throws Exception{ + super.setUp(); + + ISdl internalInterface = mock(ISdl.class); + KeyboardListener keyboardListener = mock(KeyboardListener.class); + ChoiceSetSelectionListener choiceSetSelectionListener = mock(ChoiceSetSelectionListener.class); + ChoiceCell cell1 = new ChoiceCell("Cell1"); + cell1.setChoiceId(0); + ChoiceSet choiceSet = new ChoiceSet("Test", Collections.singletonList(cell1), choiceSetSelectionListener); + presentChoiceSetOperation = new PresentChoiceSetOperation(internalInterface, choiceSet, InteractionMode.MANUAL_ONLY, getKeyBoardProperties(), keyboardListener, choiceSetSelectionListener); + } + + @Override + public void tearDown() throws Exception { + super.tearDown(); + } + + public void testGetLayoutMode(){ + // First we will check knowing our keyboard listener is NOT NULL + assertEquals(presentChoiceSetOperation.getLayoutMode(), LayoutMode.LIST_WITH_SEARCH); + presentChoiceSetOperation.keyboardListener = null; + assertEquals(presentChoiceSetOperation.getLayoutMode(), LayoutMode.LIST_ONLY); + } + + public void testGetPerformInteraction(){ + PerformInteraction pi = presentChoiceSetOperation.getPerformInteraction(); + assertEquals(pi.getInitialText(), "Test"); + assertNull(pi.getHelpPrompt()); + assertNull(pi.getTimeoutPrompt()); + assertNull(pi.getVrHelp()); + assertEquals(pi.getTimeout(), Integer.valueOf(10000)); + assertEquals(presentChoiceSetOperation.getLayoutMode(), LayoutMode.LIST_WITH_SEARCH); + } + + public void testSetSelectedCellWithId(){ + assertNull(presentChoiceSetOperation.selectedCellRow); + presentChoiceSetOperation.setSelectedCellWithId(0); + assertEquals(presentChoiceSetOperation.selectedCellRow, Integer.valueOf(0)); + } + + private KeyboardProperties getKeyBoardProperties(){ + KeyboardProperties properties = new KeyboardProperties(); + properties.setLanguage(Language.EN_US); + properties.setKeyboardLayout(KeyboardLayout.QWERTZ); + properties.setKeypressMode(KeypressMode.RESEND_CURRENT_ENTRY); + return properties; + } + +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PresentKeyboardOperationTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PresentKeyboardOperationTests.java new file mode 100644 index 0000000000..ccf4982937 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PresentKeyboardOperationTests.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Created by brettywhite on 6/12/19 1:52 PM + * + */ + +package com.smartdevicelink.managers.screen.choiceset; + +import com.smartdevicelink.AndroidTestCase2; +import com.smartdevicelink.proxy.interfaces.ISdl; +import com.smartdevicelink.proxy.rpc.KeyboardProperties; +import com.smartdevicelink.proxy.rpc.PerformInteraction; +import com.smartdevicelink.proxy.rpc.enums.KeyboardLayout; +import com.smartdevicelink.proxy.rpc.enums.KeypressMode; +import com.smartdevicelink.proxy.rpc.enums.Language; +import com.smartdevicelink.proxy.rpc.enums.LayoutMode; + +import static org.mockito.Mockito.mock; + +public class PresentKeyboardOperationTests extends AndroidTestCase2 { + + private PresentKeyboardOperation presentKeyboardOperation; + + @Override + public void setUp() throws Exception{ + super.setUp(); + + ISdl internalInterface = mock(ISdl.class); + KeyboardListener keyboardListener = mock(KeyboardListener.class); + presentKeyboardOperation = new PresentKeyboardOperation(internalInterface, getKeyBoardProperties(), "Test", null, keyboardListener); + } + + @Override + public void tearDown() throws Exception { + super.tearDown(); + } + + public void testGetPerformInteraction(){ + PerformInteraction pi = presentKeyboardOperation.getPerformInteraction(); + assertEquals(pi.getInitialText(), "Test"); + assertNull(pi.getHelpPrompt()); + assertNull(pi.getTimeoutPrompt()); + assertNull(pi.getVrHelp()); + assertEquals(pi.getInteractionLayout(), LayoutMode.KEYBOARD); + } + + private KeyboardProperties getKeyBoardProperties(){ + KeyboardProperties properties = new KeyboardProperties(); + properties.setLanguage(Language.EN_US); + properties.setKeyboardLayout(KeyboardLayout.QWERTZ); + properties.setKeypressMode(KeypressMode.RESEND_CURRENT_ENTRY); + return properties; + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuConfigurationTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuConfigurationTests.java new file mode 100644 index 0000000000..62f6ccb92e --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuConfigurationTests.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Created by brettywhite on 7/18/19 3:36 PM + * + */ + +package com.smartdevicelink.managers.screen.menu; + +import com.smartdevicelink.AndroidTestCase2; +import com.smartdevicelink.test.Test; + +public class MenuConfigurationTests extends AndroidTestCase2 { + + + @Override + public void setUp() throws Exception{ + super.setUp(); + } + + @Override + public void tearDown() throws Exception { + super.tearDown(); + } + + public void testSettersAndGetters(){ + + // set everything - we only use the constructor to set variables in the Menu Manager + MenuConfiguration menuConfiguration = new MenuConfiguration(Test.GENERAL_MENU_LAYOUT, Test.GENERAL_MENU_LAYOUT); + + // use getters and assert equality + assertEquals(menuConfiguration.getMenuLayout(), Test.GENERAL_MENU_LAYOUT); + assertEquals(menuConfiguration.getSubMenuLayout(), Test.GENERAL_MENU_LAYOUT); + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/MenuLayoutTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/MenuLayoutTests.java new file mode 100644 index 0000000000..f92de1f94f --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/MenuLayoutTests.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Created by brettywhite on 7/17/19 12:04 PM + * + */ + +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.MenuLayout; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class MenuLayoutTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums() { + String example = "LIST"; + MenuLayout enumList = MenuLayout.valueForString(example); + example = "TILES"; + MenuLayout enumTiles = MenuLayout.valueForString(example); + + assertNotNull("LIST returned null", enumList); + assertNotNull("TILES returned null", enumTiles); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum() { + String example = "TooLs"; + try { + MenuLayout temp = MenuLayout.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum() { + String example = null; + try { + MenuLayout temp = MenuLayout.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of MenuLayout. + */ + public void testListEnum() { + List enumValueList = Arrays.asList(MenuLayout.values()); + + List enumTestList = new ArrayList<>(); + enumTestList.add(MenuLayout.LIST); + enumTestList.add(MenuLayout.TILES); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +} \ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/CloseApplicationTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/CloseApplicationTests.java new file mode 100644 index 0000000000..9d8debf20b --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/CloseApplicationTests.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Created by Nicole Yarroch on 7/11/19 10:06 AM + */ + +package com.smartdevicelink.test.rpc.requests; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.CloseApplication; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.CloseApplication} + */ +public class CloseApplicationTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + return new CloseApplication(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType(){ + return FunctionID.CLOSE_APPLICATION.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + CloseApplication msg = new CloseApplication(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + CloseApplication cmd = new CloseApplication(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } + catch (JSONException e) { + fail(Test.JSON_FAIL); + } + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/UnpublishAppServiceTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/UnpublishAppServiceTests.java new file mode 100644 index 0000000000..1bc0532f84 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/UnpublishAppServiceTests.java @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Created by brettywhite on 7/12/19 2:12 PM + * + */ + +package com.smartdevicelink.test.rpc.requests; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.UnpublishAppService; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.UnpublishAppService} + */ +public class UnpublishAppServiceTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + UnpublishAppService msg = new UnpublishAppService(); + msg.setServiceID(Test.GENERAL_STRING); + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType() { + return FunctionID.UNPUBLISH_APP_SERVICE.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(UnpublishAppService.KEY_SERVICE_ID, Test.GENERAL_STRING); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + String copy = ( (UnpublishAppService) msg ).getServiceID(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, copy); + + // Invalid/Null Tests + UnpublishAppService msg = new UnpublishAppService(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.MATCH, msg.getServiceID()); + } + + /** + * Tests constructor with required params + */ + public void testRequiredParamsConstructor () { + + UnpublishAppService msg = new UnpublishAppService(Test.GENERAL_STRING); + assertNotNull(Test.NOT_NULL, msg); + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, msg.getServiceID()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + UnpublishAppService cmd = new UnpublishAppService(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + + String serviceID = JsonUtils.readStringFromJsonObject(parameters, UnpublishAppService.KEY_SERVICE_ID); + assertEquals(Test.MATCH, Test.GENERAL_STRING, serviceID); + } catch (JSONException e) { + e.printStackTrace(); + } + } + +} \ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/CloseApplicationResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/CloseApplicationResponseTests.java new file mode 100644 index 0000000000..dac0190c74 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/CloseApplicationResponseTests.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Created by Nicole Yarroch on 7/11/19 10:47 AM + */ + +package com.smartdevicelink.test.rpc.responses; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.CloseApplicationResponse; +import com.smartdevicelink.proxy.rpc.UnregisterAppInterfaceResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.CloseApplicationResponse} + */ +public class CloseApplicationResponseTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + return new CloseApplicationResponse(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.CLOSE_APPLICATION.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + CloseApplicationResponse msg = new CloseApplicationResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + CloseApplicationResponse cmd = new CloseApplicationResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } catch (JSONException e) { + e.printStackTrace(); + } + } + +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/UnpublishAppServiceResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/UnpublishAppServiceResponseTests.java new file mode 100644 index 0000000000..ce99a1a4a2 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/UnpublishAppServiceResponseTests.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Created by brettywhite on 7/12/19 2:12 PM + * + */ + +package com.smartdevicelink.test.rpc.responses; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.UnpublishAppServiceResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.UnpublishAppServiceResponse} + */ +public class UnpublishAppServiceResponseTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + return new UnpublishAppServiceResponse(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.UNPUBLISH_APP_SERVICE.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + UnpublishAppServiceResponse msg = new UnpublishAppServiceResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + UnpublishAppServiceResponse cmd = new UnpublishAppServiceResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } catch (JSONException e) { + e.printStackTrace(); + } + } + +} \ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/util/MediaStreamingStatusTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/util/MediaStreamingStatusTests.java new file mode 100644 index 0000000000..471bc19f05 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/util/MediaStreamingStatusTests.java @@ -0,0 +1,170 @@ +package com.smartdevicelink.util; + +import android.content.Context; +import android.media.AudioDeviceInfo; +import android.media.AudioManager; +import android.os.Build; + +import com.smartdevicelink.AndroidTestCase2; +import com.smartdevicelink.managers.SdlManager; +import com.smartdevicelink.managers.SdlManagerListener; +import com.smartdevicelink.proxy.rpc.enums.AppHMIType; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.transport.MultiplexTransportConfig; + +import org.mockito.Mock; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; + +import java.util.Vector; + +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; + +public class MediaStreamingStatusTests extends AndroidTestCase2 { + + + + @Mock + private AudioManager audioManager = mock(AudioManager.class); + + @Mock + Context mockedContext; + + MediaStreamingStatus defaultMediaStreamingStatus; + + private Answer onGetSystemService = new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + Object[] args = invocation.getArguments(); + String serviceName = (String) args[0]; + if(serviceName != null && serviceName.equalsIgnoreCase(Context.AUDIO_SERVICE)){ + return audioManager; + }else{ + return null; + } + } + }; + + + @Override + public void setUp() throws Exception{ + mockedContext = mock(Context.class); + doAnswer(onGetSystemService).when(mockedContext).getSystemService(Context.AUDIO_SERVICE); + defaultMediaStreamingStatus = new MediaStreamingStatus(mockedContext, mock(MediaStreamingStatus.Callback.class)); + } + + + public void testEmptyAudioDeviceInfoList(){ + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + assertNotNull(mockedContext); + MediaStreamingStatus mediaStreamingStatus = new MediaStreamingStatus(mockedContext, new MediaStreamingStatus.Callback() { + @Override + public void onAudioNoLongerAvailable() { + + } + }); + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) throws Throwable { + return new AudioDeviceInfo[0]; + } + }).when(audioManager).getDevices(AudioManager.GET_DEVICES_OUTPUTS); + + + assertFalse(mediaStreamingStatus.isAudioOutputAvailable()); + } + } + + public void testNullAudioDeviceInfoList(){ + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + assertNotNull(mockedContext); + MediaStreamingStatus mediaStreamingStatus = new MediaStreamingStatus(mockedContext, mock(MediaStreamingStatus.Callback.class)); + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) throws Throwable { + return null; + } + }).when(audioManager).getDevices(AudioManager.GET_DEVICES_OUTPUTS); + + assertFalse(mediaStreamingStatus.isAudioOutputAvailable()); + } + } + + + public void testSdlManagerMedia(){ + SdlManager.Builder builder = new SdlManager.Builder(getContext(), Test.GENERAL_FULL_APP_ID, Test.GENERAL_STRING, mock(SdlManagerListener.class)); + Vector appType = new Vector<>(); + appType.add(AppHMIType.MEDIA); + builder.setAppTypes(appType); + MultiplexTransportConfig multiplexTransportConfig = new MultiplexTransportConfig(getContext(),Test.GENERAL_FULL_APP_ID); + + assertNull(multiplexTransportConfig.requiresAudioSupport()); + builder.setTransportType(multiplexTransportConfig); + + SdlManager manager = builder.build(); + manager.start(); + + //Original reference should be updated + assertTrue(multiplexTransportConfig.requiresAudioSupport()); + } + + public void testSdlManagerNonMedia(){ + SdlManager.Builder builder = new SdlManager.Builder(getContext(), Test.GENERAL_FULL_APP_ID, Test.GENERAL_STRING, mock(SdlManagerListener.class)); + Vector appType = new Vector<>(); + appType.add(AppHMIType.DEFAULT); + builder.setAppTypes(appType); + MultiplexTransportConfig multiplexTransportConfig = new MultiplexTransportConfig(getContext(),Test.GENERAL_FULL_APP_ID); + + assertNull(multiplexTransportConfig.requiresAudioSupport()); + builder.setTransportType(multiplexTransportConfig); + + SdlManager manager = builder.build(); + manager.start(); + + //Original reference should be updated + assertFalse(multiplexTransportConfig.requiresAudioSupport()); + } + + public void testAcceptedBTDevices(){ + MediaStreamingStatus mediaStreamingStatus = spy(new MediaStreamingStatus(getContext(), mock(MediaStreamingStatus.Callback.class))); + + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) throws Throwable { + return true; + } + }).when(mediaStreamingStatus).isBluetoothActuallyAvailable(); + + assertTrue(mediaStreamingStatus.isBluetoothActuallyAvailable()); + assertTrue(mediaStreamingStatus.isSupportedAudioDevice(AudioDeviceInfo.TYPE_BLUETOOTH_A2DP)); + } + + public void testAcceptedUSBDevices(){ + MediaStreamingStatus mediaStreamingStatus = spy(new MediaStreamingStatus(getContext(), mock(MediaStreamingStatus.Callback.class))); + + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) throws Throwable { + return true; + } + }).when(mediaStreamingStatus).isUsbActuallyConnected(); + + assertTrue(mediaStreamingStatus.isUsbActuallyConnected()); + assertTrue(mediaStreamingStatus.isSupportedAudioDevice(AudioDeviceInfo.TYPE_USB_DEVICE)); + assertTrue(mediaStreamingStatus.isSupportedAudioDevice(AudioDeviceInfo.TYPE_USB_ACCESSORY)); + assertTrue(mediaStreamingStatus.isSupportedAudioDevice(AudioDeviceInfo.TYPE_USB_HEADSET)); + assertTrue(mediaStreamingStatus.isSupportedAudioDevice(AudioDeviceInfo.TYPE_DOCK)); + } + + public void testAcceptedLineDevices(){ + assertTrue(defaultMediaStreamingStatus.isSupportedAudioDevice(AudioDeviceInfo.TYPE_LINE_ANALOG)); + assertTrue(defaultMediaStreamingStatus.isSupportedAudioDevice(AudioDeviceInfo.TYPE_LINE_DIGITAL)); + assertTrue(defaultMediaStreamingStatus.isSupportedAudioDevice(AudioDeviceInfo.TYPE_AUX_LINE)); + assertTrue(defaultMediaStreamingStatus.isSupportedAudioDevice(AudioDeviceInfo.TYPE_WIRED_HEADSET)); + assertTrue(defaultMediaStreamingStatus.isSupportedAudioDevice(AudioDeviceInfo.TYPE_WIRED_HEADPHONES)); + } + + +} diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetManager.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetManager.java new file mode 100644 index 0000000000..f470b8a68a --- /dev/null +++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetManager.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.choiceset; + +import android.support.annotation.NonNull; + +import com.smartdevicelink.managers.file.FileManager; +import com.smartdevicelink.proxy.interfaces.ISdl; + +/** + * ChoiceSetManager
+ * ChoiceSetManager gives the developer the ability to control how soft choice sets are displayed on the head unit.
+ * Note: This class must be accessed through the SdlManager->ScreenManager. Do not instantiate it by itself.
+ */ +public class ChoiceSetManager extends BaseChoiceSetManager { + + /** + * Creates a new instance of the ChoiceSetManager + * + * @param internalInterface + */ + public ChoiceSetManager(@NonNull ISdl internalInterface, @NonNull FileManager fileManager) { + super(internalInterface, fileManager); + } +} diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/util/MediaStreamingStatus.java b/android/sdl_android/src/main/java/com/smartdevicelink/util/MediaStreamingStatus.java new file mode 100644 index 0000000000..143b6c6460 --- /dev/null +++ b/android/sdl_android/src/main/java/com/smartdevicelink/util/MediaStreamingStatus.java @@ -0,0 +1,300 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.util; + +import android.annotation.SuppressLint; +import android.bluetooth.BluetoothAdapter; +import android.bluetooth.BluetoothDevice; +import android.bluetooth.BluetoothProfile; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.media.AudioDeviceInfo; +import android.media.AudioManager; +import android.os.Build; +import android.support.annotation.NonNull; + +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.List; + + +/** + * Possible improvements + * + * - Narrow down list of acceptable audio devices + * - Add ability to listen for when audio devices become available, and then connect + * - Improve redundant calls to create String arrays for action arrays + */ + +public class MediaStreamingStatus { + private static final Object BROADCAST_RECEIVER_LOCK = new Object(); + + private boolean broadcastReceiverValid = true; + private WeakReference contextWeakReference; + private Callback callback; + private List intentList; + + public MediaStreamingStatus(@NonNull Context context, @NonNull Callback callback){ + contextWeakReference = new WeakReference<>(context); + this.callback = callback; + intentList = new ArrayList<>(); + //This is a default action that should be added + intentList.add(AudioManager.ACTION_AUDIO_BECOMING_NOISY); + } + + public void clear(){ + callback = null; + unregisterBroadcastReceiver(); + contextWeakReference.clear(); + + } + + /* + + Working order + --------------------------------------------------------------------------------------------- + 1. If API level >= 23, use AudioManager to get connected audio output devices. + Covers ~ 74.8% of Android devices as of 5/30/2019 + This will return for a number of different supported audio devices. Full list can be seen + in the isSupportedAudioDevice method. + + 2. If API level >= 3 && <=22, use the BluetoothManager to detect A2DP connection. + Covers ~ 25.2% of Android devices not covered in option 1 as of 5/30/2019 + This will enforce that bluetooth is connected as an audio output. No other type of audio + device can currently be detected. + + 3. If API level <= 2, return false. + Covers <1% of Android devices not covered by cases 1 and 2. + + Other options considered included: + - BluetoothAdapter.getProfileConnectionState(BluetoothProfile.A2DP) == STATE_CONNECTED || STATE_CONNECTING ; + - MediaRouter.getSelectedRoute(MediaRouter.ROUTE_TYPE_LIVE_AUDIO).getDeviceType() == MediaRouter.RouteInfo.DEVICE_TYPE_BLUETOOTH ; + + */ + + @SuppressLint("MissingPermission") + public synchronized boolean isAudioOutputAvailable() { + Context context = contextWeakReference.get(); + if(context == null){ return false;} + + AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); + + // If API level 23+ audio manager can iterate over all current devices to see if a supported + // device is present. + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){ + AudioDeviceInfo[] deviceInfos = audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS); + if(deviceInfos != null) { + for (AudioDeviceInfo deviceInfo : deviceInfos) { + if (deviceInfo != null && isSupportedAudioDevice(deviceInfo.getType())) { + return true; + } + } + } + return false; + } + + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.CUPCAKE + && android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { + + return audioManager.isBluetoothA2dpOn(); + } + + //If an acceptable audio device hasn't been found or the API level is too low, then only a + //value of false can be returned as there is not enough information to determine if an audio + //device is available. + return false; + } + + /** + * This method will check to ensure that the device is supported. If possible, it will also + * check against known variables and flags to ensure that that device is connected. This is + * required as the AudioManager tends to be untrustworthy. + * @param audioDevice + * @return + */ + boolean isSupportedAudioDevice(int audioDevice){ + DebugTool.logInfo("Audio device connected: " + audioDevice); + switch (audioDevice){ + case AudioDeviceInfo.TYPE_BLUETOOTH_A2DP: + if(isBluetoothActuallyAvailable()) { + setupBluetoothBroadcastReceiver(); + return true; //Make sure this doesn't fall to any other logic after this point + } + return false; + case AudioDeviceInfo.TYPE_DOCK: + case AudioDeviceInfo.TYPE_USB_ACCESSORY: + case AudioDeviceInfo.TYPE_USB_DEVICE: + case AudioDeviceInfo.TYPE_USB_HEADSET: + if(isUsbActuallyConnected()) { + setupUSBBroadcastReceiver(); + return true; + } + return false; + case AudioDeviceInfo.TYPE_LINE_ANALOG: + case AudioDeviceInfo.TYPE_LINE_DIGITAL: + case AudioDeviceInfo.TYPE_WIRED_HEADSET: + case AudioDeviceInfo.TYPE_WIRED_HEADPHONES: + case AudioDeviceInfo.TYPE_AUX_LINE: + setupHeadsetBroadcastReceiver(); + return true; + } + return false; + } + + @SuppressLint("MissingPermission") + boolean isBluetoothActuallyAvailable(){ + BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); + if(adapter == null || !adapter.isEnabled() ){ + //False positive + return false; + } + if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH ){ + int state = adapter.getProfileConnectionState(BluetoothProfile.A2DP); + if(state != BluetoothAdapter.STATE_CONNECTING && state != BluetoothAdapter.STATE_CONNECTED){ + //False positive + return false; + } + } + + return true; + } + + boolean isUsbActuallyConnected(){ + Context context = contextWeakReference.get(); + if(context != null){ + return AndroidTools.isUSBCableConnected(context); + } + //default to true + return true; + } + + + private void setupBluetoothBroadcastReceiver(){ + String[] actions = new String[4]; + actions[0] = BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED; + actions[1] = BluetoothAdapter.ACTION_STATE_CHANGED; + actions[2] = BluetoothDevice.ACTION_ACL_DISCONNECTED; + actions[3] = BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED; + + listenForIntents(actions); + } + + private void setupHeadsetBroadcastReceiver(){ + String[] actions = new String[1]; + actions[0] = AudioManager.ACTION_HEADSET_PLUG; + + listenForIntents(actions); + } + + private void setupUSBBroadcastReceiver(){ + String[] actions = new String[1]; + actions[0] = Intent.ACTION_BATTERY_CHANGED; + + listenForIntents(actions); + } + + private void listenForIntents(@NonNull String[] actions){ + if(intentList != null){ + //Add each intent + int preAddSize = intentList.size(); + + for(String action : actions){ + if(action != null && action.length() > 0 && !intentList.contains(action)){ + intentList.add(action); + } + } + + if(preAddSize != intentList.size()){ + synchronized (BROADCAST_RECEIVER_LOCK){ + broadcastReceiverValid = true; + } + updateBroadcastReceiver(); + } + } + } + + private void updateBroadcastReceiver() { + //The broadcast receiver has not been setup for this yet + Context context = contextWeakReference.get(); + if (context != null) { + IntentFilter intentFilter = new IntentFilter(); + for (String intentAction : intentList) { + intentFilter.addAction(intentAction); + } + unregisterBroadcastReceiver(); + //Re-register receiver + context.registerReceiver(broadcastReceiver, intentFilter); + + } + + } + + private void unregisterBroadcastReceiver(){ + Context context = contextWeakReference.get(); + if(context != null) { + try{ + context.unregisterReceiver(broadcastReceiver); + }catch (Exception e){ + //Ignore the exception + } + } + } + + private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + synchronized (BROADCAST_RECEIVER_LOCK) { + if (!isAudioOutputAvailable()) { + if (broadcastReceiverValid) { + broadcastReceiverValid = false; + //No audio device is acceptable any longer + if (callback != null) { + callback.onAudioNoLongerAvailable(); + } + + intentList.clear(); + unregisterBroadcastReceiver(); + } + } + } + } + }; + + + public interface Callback{ + void onAudioNoLongerAvailable(); + } + +} diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/BaseChoiceSetManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/BaseChoiceSetManager.java new file mode 100644 index 0000000000..9770898bcf --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/BaseChoiceSetManager.java @@ -0,0 +1,598 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Created by brettywhite on 2019-06-11. + */ + +package com.smartdevicelink.managers.screen.choiceset; + +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + +import com.smartdevicelink.managers.BaseSubManager; +import com.smartdevicelink.managers.CompletionListener; +import com.smartdevicelink.managers.file.FileManager; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCNotification; +import com.smartdevicelink.proxy.interfaces.ISdl; +import com.smartdevicelink.proxy.interfaces.OnSystemCapabilityListener; +import com.smartdevicelink.proxy.rpc.DisplayCapabilities; +import com.smartdevicelink.proxy.rpc.KeyboardProperties; +import com.smartdevicelink.proxy.rpc.OnHMIStatus; +import com.smartdevicelink.proxy.rpc.enums.HMILevel; +import com.smartdevicelink.proxy.rpc.enums.InteractionMode; +import com.smartdevicelink.proxy.rpc.enums.KeyboardLayout; +import com.smartdevicelink.proxy.rpc.enums.KeypressMode; +import com.smartdevicelink.proxy.rpc.enums.Language; +import com.smartdevicelink.proxy.rpc.enums.SystemCapabilityType; +import com.smartdevicelink.proxy.rpc.enums.SystemContext; +import com.smartdevicelink.proxy.rpc.enums.TriggerSource; +import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener; +import com.smartdevicelink.util.DebugTool; + +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.concurrent.Future; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; + +/** + * ChoiceSetManager
+ *

+ * Note: This class must be accessed through the SdlManager. Do not instantiate it by itself.
+ */ +abstract class BaseChoiceSetManager extends BaseSubManager { + + // additional state + private static final int CHECKING_VOICE = 0xA0; + private KeyboardProperties keyboardConfiguration; + final WeakReference fileManager; + + OnRPCNotificationListener hmiListener; + OnSystemCapabilityListener displayListener; + HMILevel currentHMILevel; + DisplayCapabilities displayCapabilities; + SystemContext currentSystemContext; + HashSet preloadedChoices, pendingPreloadChoices; + ChoiceSet pendingPresentationSet; + private List waitingChoices; + private CompletionListener waitingListener; + + // We will pass operations into this to be completed + PausableThreadPoolExecutor executor; + LinkedBlockingQueue operationQueue; + Future pendingPresentOperation; + + int nextChoiceId; + final int choiceCellIdMin = 1; + boolean isVROptional; + + BaseChoiceSetManager(@NonNull ISdl internalInterface, @NonNull FileManager fileManager) { + super(internalInterface); + + // capabilities + currentSystemContext = SystemContext.SYSCTXT_MAIN; + currentHMILevel = HMILevel.HMI_NONE; + addListeners(); + + // setting/instantiating class vars + this.fileManager = new WeakReference<>(fileManager); + preloadedChoices = new HashSet<>(); + pendingPreloadChoices = new HashSet<>(); + nextChoiceId = choiceCellIdMin; + isVROptional = false; + keyboardConfiguration = defaultKeyboardConfiguration(); + operationQueue = new LinkedBlockingQueue<>(); + executor = new PausableThreadPoolExecutor(1, Runtime.getRuntime().availableProcessors(), 10, TimeUnit.SECONDS, operationQueue); + executor.pause(); // pause until HMI ready + } + + @Override + public void start(CompletionListener listener){ + transitionToState(CHECKING_VOICE); + checkVoiceOptional(); + super.start(listener); + } + + @Override + public void dispose(){ + + // cancel the operations + operationQueue.clear(); + executor.shutdownNow(); + + currentHMILevel = null; + currentSystemContext = null; + displayCapabilities = null; + + pendingPresentationSet = null; + pendingPresentOperation = null; + waitingChoices = null; + waitingListener = null; + isVROptional = true; + nextChoiceId = choiceCellIdMin; + + // remove listeners + internalInterface.removeOnRPCNotificationListener(FunctionID.ON_HMI_STATUS, hmiListener); + internalInterface.removeOnSystemCapabilityListener(SystemCapabilityType.DISPLAY, displayListener); + + super.dispose(); + } + + private void checkVoiceOptional(){ + + CheckChoiceVROptionalOperation checkChoiceVR = new CheckChoiceVROptionalOperation(internalInterface, new CheckChoiceVROptionalInterface() { + @Override + public void onCheckChoiceVROperationComplete(boolean vrOptional) { + isVROptional = vrOptional; + transitionToState(READY); + DebugTool.logInfo("VR is optional: "+ isVROptional); + } + + @Override + public void onError(String error) { + // At this point, there were errors trying to send a test CICS + // If we reach this state, we cannot use the manager + DebugTool.logError(error); + transitionToState(ERROR); + // checking VR will always be first in the queue. + // If pre-load operations were added while this was in progress + // clear it from the queue onError. + operationQueue.clear(); + } + }); + executor.submit(checkChoiceVR); + } + + /** + * Preload choices to improve performance while presenting a choice set at a later time + * @param choices - a list of ChoiceCell objects that will be part of a choice set later + * @param listener - a completion listener to inform when the operation is complete + */ + public void preloadChoices(@NonNull List choices, @Nullable final CompletionListener listener){ + + if (!isReady()){ + waitingChoices = new ArrayList<>(choices); + waitingListener = listener; + DebugTool.logInfo("Preload pending choice set manager being ready"); + return; + } + + final HashSet choicesToUpload = new HashSet<>(choices); + choicesToUpload.removeAll(preloadedChoices); + choicesToUpload.removeAll(pendingPreloadChoices); + + if (choicesToUpload.size() == 0){ + if (listener != null){ + listener.onComplete(true); + } + return; + } + + updateIdsOnChoices(choicesToUpload); + + // Add the preload cells to the pending preload choices + pendingPreloadChoices.addAll(choicesToUpload); + + if (fileManager.get() != null) { + PreloadChoicesOperation preloadChoicesOperation = new PreloadChoicesOperation(internalInterface, fileManager.get(), displayCapabilities, isVROptional, choicesToUpload, new CompletionListener() { + @Override + public void onComplete(boolean success) { + if (success){ + preloadedChoices.addAll(choicesToUpload); + pendingPreloadChoices.removeAll(choicesToUpload); + if (listener != null){ + listener.onComplete(true); + } + waitingChoices = null; + waitingListener = null; + }else { + DebugTool.logError("There was an error pre loading choice cells"); + if (listener != null){ + listener.onComplete(false); + } + waitingChoices = null; + waitingListener = null; + } + } + }); + + executor.submit(preloadChoicesOperation); + } else { + DebugTool.logError("File Manager was null in preload choice operation"); + } + } + + /** + * Deletes choices that were sent previously + * @param choices - A list of ChoiceCell objects + */ + public void deleteChoices(@NonNull List choices){ + + if (!isReady()){ return; } + + // Find cells to be deleted that are already uploaded or are pending upload + final HashSet cellsToBeDeleted = choicesToBeDeletedWithArray(choices); + HashSet cellsToBeRemovedFromPending = choicesToBeRemovedFromPendingWithArray(choices); + // If choices are deleted that are already uploaded or pending and are used by a pending presentation, cancel it and send an error + HashSet pendingPresentationChoices = new HashSet<>(); + if (pendingPresentationSet != null && pendingPresentationSet.getChoices() != null) { + pendingPresentationChoices.addAll(pendingPresentationSet.getChoices()); + } + + if (pendingPresentOperation != null && !pendingPresentOperation.isCancelled() && !pendingPresentOperation.isDone() && (cellsToBeDeleted.retainAll(pendingPresentationChoices) || cellsToBeRemovedFromPending.retainAll(pendingPresentationChoices))){ + pendingPresentOperation.cancel(true); + DebugTool.logWarning("Attempting to delete choice cells while there is a pending presentation operation. Pending presentation cancelled."); + pendingPresentOperation = null; + } + + // Remove cells from pending and delete choices + pendingPresentationChoices.removeAll(cellsToBeRemovedFromPending); + for (Runnable operation : operationQueue){ + if (!(operation instanceof PreloadChoicesOperation)){ continue; } + ((PreloadChoicesOperation) operation).removeChoicesFromUpload(cellsToBeRemovedFromPending); + } + + // Find Choices to delete + if (cellsToBeDeleted.size() == 0){ + DebugTool.logInfo("Cells to be deleted size == 0"); + return; + } + findIdsOnChoices(cellsToBeDeleted); + + DeleteChoicesOperation deleteChoicesOperation = new DeleteChoicesOperation(internalInterface, cellsToBeDeleted, new CompletionListener() { + @Override + public void onComplete(boolean success) { + if (!success){ + DebugTool.logError("Failed to delete choices"); + return; + } + preloadedChoices.removeAll(cellsToBeDeleted); + } + }); + executor.submit(deleteChoicesOperation); + } + + /** + * Presents a choice set + * @param choiceSet - The choice set to be presented. This can include Choice Cells that were preloaded or not + * @param mode - The intended interaction mode + * @param keyboardListener - A keyboard listener to capture user input + */ + public void presentChoiceSet(@NonNull final ChoiceSet choiceSet, @Nullable final InteractionMode mode, @Nullable final KeyboardListener keyboardListener){ + + if (!isReady()){ return; } + + // Perform additional checks against the ChoiceSet + if (!setUpChoiceSet(choiceSet)){ return; } + + if (this.pendingPresentationSet != null && pendingPresentOperation != null){ + pendingPresentOperation.cancel(true); + DebugTool.logWarning("Presenting a choice set while one is currently presented. Cancelling previous and continuing"); + } + + this.pendingPresentationSet = choiceSet; + preloadChoices(this.pendingPresentationSet.getChoices(), new CompletionListener() { + @Override + public void onComplete(boolean success) { + if (!success){ + choiceSet.getChoiceSetSelectionListener().onError("There was an error pre-loading choice set choices"); + }else{ + sendPresentOperation(keyboardListener, mode); + } + } + }); + } + + private void sendPresentOperation(KeyboardListener keyboardListener, InteractionMode mode){ + + if (mode == null){ + mode = InteractionMode.MANUAL_ONLY; + } + + findIdsOnChoiceSet(pendingPresentationSet); + // Pass back the information to the developer + ChoiceSetSelectionListener privateChoiceListener = new ChoiceSetSelectionListener() { + @Override + public void onChoiceSelected(ChoiceCell choiceCell, TriggerSource triggerSource, int rowIndex) { + if (pendingPresentationSet.getChoiceSetSelectionListener() != null){ + pendingPresentationSet.getChoiceSetSelectionListener().onChoiceSelected(choiceCell, triggerSource,rowIndex); + } + pendingPresentationSet = null; + pendingPresentOperation = null; + } + + @Override + public void onError(String error) { + if (pendingPresentationSet.getChoiceSetSelectionListener() != null){ + pendingPresentationSet.getChoiceSetSelectionListener().onError(error); + } + pendingPresentationSet = null; + pendingPresentOperation = null; + } + }; + + PresentChoiceSetOperation presentOp; + + if (keyboardListener == null){ + // Non-searchable choice set + DebugTool.logInfo("Creating non-searchable choice set"); + presentOp = new PresentChoiceSetOperation(internalInterface, pendingPresentationSet, mode, null, null, privateChoiceListener); + } else { + // Searchable choice set + DebugTool.logInfo("Creating searchable choice set"); + presentOp = new PresentChoiceSetOperation(internalInterface, pendingPresentationSet, mode, keyboardConfiguration, keyboardListener, privateChoiceListener); + } + + pendingPresentOperation = executor.submit(presentOp); + } + + /** + * Presents a keyboard on the Head unit to capture user input + * @param initialText - The initial text that is used as a placeholder text. It might not work on some head units. + * @param customKeyboardConfig - the custom keyboard configuration to be used when the keyboard is displayed + * @param listener - A keyboard listener to capture user input + */ + public void presentKeyboard(@NonNull String initialText, @Nullable KeyboardProperties customKeyboardConfig, @NonNull KeyboardListener listener){ + + if (initialText == null || initialText.length() == 0){ + DebugTool.logError("initialText cannot be an empty string."); + return; + } + + if (!isReady()){ return; } + + if (pendingPresentationSet != null && pendingPresentOperation != null){ + pendingPresentOperation.cancel(true); + pendingPresentationSet = null; + DebugTool.logWarning("There is a current or pending choice set, cancelling and continuing."); + } + + if (customKeyboardConfig == null){ + if (this.keyboardConfiguration != null){ + customKeyboardConfig = this.keyboardConfiguration; + } else { + customKeyboardConfig = defaultKeyboardConfiguration(); + } + } + + // Present a keyboard with the choice set that we used to test VR's optional state + DebugTool.logInfo("Presenting Keyboard - Choice Set Manager"); + PresentKeyboardOperation keyboardOp = new PresentKeyboardOperation(internalInterface, keyboardConfiguration, initialText, customKeyboardConfig, listener); + pendingPresentOperation = executor.submit(keyboardOp); + } + + /** + * Set a custom keyboard configuration for this session. If set to null, it will reset to default keyboard configuration. + * @param keyboardConfiguration - the custom keyboard configuration to be used when the keyboard is displayed + */ + public void setKeyboardConfiguration(@Nullable KeyboardProperties keyboardConfiguration){ + if (keyboardConfiguration == null){ + this.keyboardConfiguration = defaultKeyboardConfiguration(); + } else{ + KeyboardProperties properties = new KeyboardProperties(); + properties.setLanguage((keyboardConfiguration.getLanguage() == null ? Language.EN_US : keyboardConfiguration.getLanguage())); + properties.setKeyboardLayout((keyboardConfiguration.getKeyboardLayout() == null ? KeyboardLayout.QWERTZ : keyboardConfiguration.getKeyboardLayout())); + properties.setKeypressMode((keyboardConfiguration.getKeypressMode() == null ? KeypressMode.RESEND_CURRENT_ENTRY : keyboardConfiguration.getKeypressMode())); + properties.setLimitedCharacterList(keyboardConfiguration.getLimitedCharacterList()); + properties.setAutoCompleteText(keyboardConfiguration.getAutoCompleteText()); + this.keyboardConfiguration = properties; + } + } + + // GETTERS + + /** + * @return A set of choice cells that have been preloaded to the head unit + */ + public HashSet getPreloadedChoices(){ + return this.preloadedChoices; + } + + // CHOICE SET MANAGEMENT HELPERS + + HashSet choicesToBeDeletedWithArray(List choices){ + HashSet choicesSet = new HashSet<>(choices); + choicesSet.retainAll(this.preloadedChoices); + return choicesSet; + } + + HashSet choicesToBeRemovedFromPendingWithArray(List choices){ + HashSet choicesSet = new HashSet<>(choices); + choicesSet.retainAll(this.pendingPreloadChoices); + return choicesSet; + } + + void updateIdsOnChoices(HashSet choices){ + for (ChoiceCell cell : choices){ + cell.setChoiceId(this.nextChoiceId); + this.nextChoiceId++; + } + } + + private void findIdsOnChoiceSet(ChoiceSet choiceSet){ + findIdsOnChoices(new HashSet<>(choiceSet.getChoices())); + } + + private void findIdsOnChoices(HashSet choices){ + for (ChoiceCell cell : choices){ + ChoiceCell uploadCell = null; + if (pendingPreloadChoices.contains(cell)){ + uploadCell = findIfPresent(cell, pendingPreloadChoices); + }else if (preloadedChoices.contains(cell)){ + uploadCell = findIfPresent(cell, preloadedChoices); + } + if (uploadCell != null ){ + cell.setChoiceId(uploadCell.getChoiceId()); + } + } + } + + ChoiceCell findIfPresent(ChoiceCell cell, HashSet set){ + if (set.contains(cell)) { + for (ChoiceCell setCell : set) { + if (setCell.equals(cell)) + return setCell; + } + } + return null; + } + + // LISTENERS + + private void addListeners(){ + // DISPLAY CAPABILITIES - via SCM + displayListener = new OnSystemCapabilityListener() { + @Override + public void onCapabilityRetrieved(Object capability) { + displayCapabilities = (DisplayCapabilities) capability; + } + + @Override + public void onError(String info) { + DebugTool.logError("Unable to retrieve display capabilities. Many things will probably break. Info: "+ info); + } + }; + internalInterface.getCapability(SystemCapabilityType.DISPLAY, displayListener); + + // HMI UPDATES + hmiListener = new OnRPCNotificationListener() { + @Override + public void onNotified(RPCNotification notification) { + OnHMIStatus hmiStatus = (OnHMIStatus) notification; + HMILevel oldHMILevel = currentHMILevel; + currentHMILevel = hmiStatus.getHmiLevel(); + + if (currentHMILevel == HMILevel.HMI_NONE){ + executor.pause(); + } + + if (oldHMILevel == HMILevel.HMI_NONE && currentHMILevel != HMILevel.HMI_NONE){ + executor.resume(); + if (waitingChoices != null && waitingChoices.size() > 0){ + DebugTool.logInfo("Pending Preload Choices now being sent"); + preloadChoices(waitingChoices, waitingListener); + } + } + + currentSystemContext = hmiStatus.getSystemContext(); + + if (currentSystemContext == SystemContext.SYSCTXT_HMI_OBSCURED || currentSystemContext == SystemContext.SYSCTXT_ALERT){ + executor.pause(); + } + + if (currentSystemContext == SystemContext.SYSCTXT_MAIN && currentHMILevel != HMILevel.HMI_NONE){ + executor.resume(); + if (waitingChoices != null && waitingChoices.size() > 0){ + DebugTool.logInfo("Pending Preload Choices now being sent"); + preloadChoices(waitingChoices, waitingListener); + } + } + + } + }; + internalInterface.addOnRPCNotificationListener(FunctionID.ON_HMI_STATUS, hmiListener); + } + + // ADDITIONAL HELPERS + + boolean setUpChoiceSet(ChoiceSet choiceSet) { + + List choices = choiceSet.getChoices(); + + // Choices are not optional here + if (choices == null || choices.size() == 0) { + DebugTool.logError("Cannot initiate a choice set with no choices"); + return false; + } + + if (choiceSet.getTimeout() != null) { + if (choiceSet.getTimeout() < 5 || choiceSet.getTimeout() > 100) { + DebugTool.logWarning("Attempted to create a choice set with a " + choiceSet.getTimeout() + " second timeout; Only 5 - 100 seconds is valid. When using the choice set manager, setTimeout() uses seconds."); + return false; + } + } + + HashSet choiceTextSet = new HashSet<>(); + HashSet uniqueVoiceCommands = new HashSet<>(); + int allVoiceCommandsCount = 0; + int choiceCellWithVoiceCommandCount = 0; + + for (ChoiceCell cell : choices) { + + choiceTextSet.add(cell.getText()); + + if (cell.getVoiceCommands() != null) { + uniqueVoiceCommands.addAll(cell.getVoiceCommands()); + choiceCellWithVoiceCommandCount += 1; + allVoiceCommandsCount += cell.getVoiceCommands().size(); + } + } + + // Cell text MUST be unique + if (choiceTextSet.size() < choices.size()) { + DebugTool.logError("Attempted to create a choice set with duplicate cell text. Cell text must be unique. The choice set will not be set."); + return false; + } + + // All or none of the choices MUST have VR Commands + if (choiceCellWithVoiceCommandCount > 0 && choiceCellWithVoiceCommandCount < choices.size()) { + DebugTool.logError("If using voice recognition commands, all of the choice set cells must have unique VR commands. There are " + uniqueVoiceCommands.size() + " cells with unique voice commands and " + choices.size() + " total cells. The choice set will not be set."); + return false; + } + + // All VR Commands MUST be unique + if (uniqueVoiceCommands.size() < allVoiceCommandsCount) { + DebugTool.logError("If using voice recognition commands, all VR commands must be unique. There are " + uniqueVoiceCommands.size() + " unique VR commands and " + allVoiceCommandsCount + " VR commands. The choice set will not be set."); + return false; + } + return true; + } + + KeyboardProperties defaultKeyboardConfiguration(){ + KeyboardProperties defaultProperties = new KeyboardProperties(); + defaultProperties.setLanguage(Language.EN_US); + defaultProperties.setKeyboardLayout(KeyboardLayout.QWERTY); + defaultProperties.setKeypressMode(KeypressMode.RESEND_CURRENT_ENTRY); + return defaultProperties; + } + + @SuppressWarnings("BooleanMethodIsAlwaysInverted") + private boolean isReady(){ + if (getState() != READY){ + DebugTool.logWarning("Choice Manager In Not-Ready State"); + return false; + } + return true; + } +} diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/CheckChoiceVROptionalInterface.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/CheckChoiceVROptionalInterface.java new file mode 100644 index 0000000000..f40c26e5c5 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/CheckChoiceVROptionalInterface.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Created by brettywhite on 6/12/19 1:52 PM + * + */ + +package com.smartdevicelink.managers.screen.choiceset; + +interface CheckChoiceVROptionalInterface { + void onCheckChoiceVROperationComplete(boolean vrOptional); + void onError(String error); +} diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/CheckChoiceVROptionalOperation.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/CheckChoiceVROptionalOperation.java new file mode 100644 index 0000000000..074f89947b --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/CheckChoiceVROptionalOperation.java @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Created by brettywhite on 6/12/19 1:52 PM + * + */ + +package com.smartdevicelink.managers.screen.choiceset; + +import com.smartdevicelink.proxy.RPCResponse; +import com.smartdevicelink.proxy.interfaces.ISdl; +import com.smartdevicelink.proxy.rpc.Choice; +import com.smartdevicelink.proxy.rpc.CreateInteractionChoiceSet; +import com.smartdevicelink.proxy.rpc.DeleteInteractionChoiceSet; +import com.smartdevicelink.proxy.rpc.enums.Result; +import com.smartdevicelink.proxy.rpc.listeners.OnRPCResponseListener; +import com.smartdevicelink.util.DebugTool; + +import java.lang.ref.WeakReference; +import java.util.Collections; + +class CheckChoiceVROptionalOperation implements Runnable { + + private CheckChoiceVROptionalInterface checkChoiceVROptionalInterface; + private WeakReference internalInterface; + private boolean isVROptional; + + CheckChoiceVROptionalOperation(ISdl internalInterface, CheckChoiceVROptionalInterface checkChoiceVROptionalInterface){ + this.internalInterface = new WeakReference<>(internalInterface); + this.checkChoiceVROptionalInterface = checkChoiceVROptionalInterface; + } + + @Override + public void run() { + DebugTool.logInfo("Choice Operation: Executing check vr optional operation"); + sendTestChoiceNoVR(); + } + + /** + * As VR used to me mandatory, we first will sent a choice cell WITHOUT VR. If this succeeds, we are good, + * if not check again without. + */ + private void sendTestChoiceNoVR() { + CreateInteractionChoiceSet cics = testCellWithVR(false); + cics.setOnRPCResponseListener(new OnRPCResponseListener() { + @Override + public void onResponse(int correlationId, RPCResponse response) { + if (response.getSuccess()) { + // The request was successful, now send the SDLPerformInteraction RPC + DebugTool.logInfo("Connected head unit supports choice cells without voice commands. " + + "Cells without voice will be sent without voice from now on (no placeholder voice)."); + isVROptional = true; + deleteTestChoiceSet(); + }else{ + sendTestChoiceWithVR(); + } + } + + @Override + public void onError(int correlationId, Result resultCode, String info){ + DebugTool.logError("There was an error in the check choice vr optional operation. Send test choice with no VR failed. Error: " + info + " resultCode: " + resultCode); + isVROptional = false; + if (checkChoiceVROptionalInterface != null){ + checkChoiceVROptionalInterface.onError(info); + } + } + }); + + if (internalInterface.get() != null) { + internalInterface.get().sendRPC(cics); + } + } + + /** + * The initial request failed. Try again without VR, if this fails, return and put CSM in error state + */ + private void sendTestChoiceWithVR(){ + CreateInteractionChoiceSet cics = testCellWithVR(true); + cics.setOnRPCResponseListener(new OnRPCResponseListener() { + @Override + public void onResponse(int correlationId, RPCResponse response) { + if (response.getSuccess()) { + // The request was successful, now send the SDLPerformInteraction RPC + DebugTool.logWarning("Connected head unit does not support choice cells without voice commands. " + + "Cells without voice will be sent with placeholder voices from now on."); + isVROptional = false; + deleteTestChoiceSet(); + }else{ + DebugTool.logError("Connected head unit has rejected all choice cells, choice manager disabled. Error: " + response.getInfo()); + isVROptional = false; + if (checkChoiceVROptionalInterface != null){ + checkChoiceVROptionalInterface.onError(response.getInfo()); + } + } + } + + @Override + public void onError(int correlationId, Result resultCode, String info){ + DebugTool.logError("There was an error in the check choice vr optional operation. Send test choice with VR failed. Error: " + info + " resultCode: " + resultCode); + isVROptional = false; + if (checkChoiceVROptionalInterface != null){ + checkChoiceVROptionalInterface.onError(info); + } + } + }); + + if (internalInterface.get() != null) { + internalInterface.get().sendRPC(cics); + } + } + + private void deleteTestChoiceSet(){ + DeleteInteractionChoiceSet delete = createDeleteInteractionChoiceSet(); + delete.setOnRPCResponseListener(new OnRPCResponseListener() { + @Override + public void onResponse(int correlationId, RPCResponse response) { + if (response.getSuccess() != null){ + DebugTool.logInfo("Delete choice test set: "+ response.getSuccess()); + } + + if (checkChoiceVROptionalInterface != null){ + checkChoiceVROptionalInterface.onCheckChoiceVROperationComplete(isVROptional); + } + } + + @Override + public void onError(int correlationId, Result resultCode, String info){ + DebugTool.logError("There was an error presenting the keyboard. Finishing operation - choice set manager - . Error: " + info + " resultCode: " + resultCode); + if (checkChoiceVROptionalInterface != null){ + checkChoiceVROptionalInterface.onError(info); + } + } + }); + if (internalInterface.get() != null){ + internalInterface.get().sendRPC(delete); + } + } + + DeleteInteractionChoiceSet createDeleteInteractionChoiceSet(){ + return new DeleteInteractionChoiceSet(0); + } + + CreateInteractionChoiceSet testCellWithVR(boolean hasVR){ + Choice choice = new Choice(0, "Test Cell"); + choice.setVrCommands((hasVR ? Collections.singletonList("Test VR") : null)); + choice.setIgnoreAddingVRItems(true); + return new CreateInteractionChoiceSet(0, Collections.singletonList(choice)); + } +} diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceCell.java new file mode 100644 index 0000000000..c96825c564 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceCell.java @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.choiceset; + +import android.support.annotation.NonNull; + +import com.smartdevicelink.managers.file.filetypes.SdlArtwork; + +import java.util.List; + +public class ChoiceCell { + private String text, secondaryText, tertiaryText; + private List voiceCommands; + private SdlArtwork artwork, secondaryArtwork; + private Integer choiceId; + + /** + * MAX ID for cells - Cannot use Integer.MAX_INT as the value is too high. + */ + private static final int MAX_ID = 2000000000; + + /** + * Initialize the cell with text and nothing else. + * + * @param text - The primary text of the cell. + */ + public ChoiceCell(@NonNull String text) { + setText(text); + setChoiceId(MAX_ID); + } + + /** + * Initialize the cell with text, optional artwork, and optional voice commands + * + * @param text - The primary text of the cell + * @param voiceCommands - Strings that can be spoken by the user to activate this cell in a voice or both interaction mode + * @param artwork - The primary artwork of the cell + */ + public ChoiceCell(@NonNull String text, List voiceCommands, SdlArtwork artwork) { + setText(text); + setVoiceCommands(voiceCommands); + setArtwork(artwork); + setChoiceId(MAX_ID); + } + + /** + * Initialize the cell with all optional items + * + * @param text - The primary text + * @param secondaryText - The secondary text + * @param tertiaryText - The tertiary text + * @param voiceCommands - Strings that can be spoken by the user to activate this cell in a voice or both interaction mode + * @param artwork - The primary artwork of the cell + * @param secondaryArtwork - The secondary artwork of the cell + */ + public ChoiceCell(@NonNull String text, String secondaryText, String tertiaryText, List voiceCommands, SdlArtwork artwork, SdlArtwork secondaryArtwork) { + setText(text); + setSecondaryText(secondaryText); + setTertiaryText(tertiaryText); + setVoiceCommands(voiceCommands); + setArtwork(artwork); + setSecondaryArtwork(secondaryArtwork); + setChoiceId(MAX_ID); + } + + /** + * Maps to Choice.menuName. The primary text of the cell. Duplicates within an `ChoiceSet` + * are not permitted and will result in the `ChoiceSet` failing to initialize. + * @return The primary text of the cell + */ + public String getText() { + return text; + } + + /** + * @param text - Maps to Choice.menuName. The primary text of the cell. Duplicates within an `ChoiceSet` + * are not permitted and will result in the `ChoiceSet` failing to initialize. + */ + void setText(@NonNull String text) { + this.text = text; + } + + /** + * Maps to Choice.secondaryText. Optional secondary text of the cell, if available. Duplicates + * within an `ChoiceSet` are permitted. + * @return Optional secondary text of the cell + */ + public String getSecondaryText() { + return secondaryText; + } + + /** + * @param secondaryText - Maps to Choice.secondaryText. Optional secondary text of the cell, if + * available. Duplicates within an `ChoiceSet` are permitted. + */ + void setSecondaryText(String secondaryText) { + this.secondaryText = secondaryText; + } + + /** + * Maps to Choice.tertiaryText. Optional tertiary text of the cell, if available. Duplicates within an `ChoiceSet` are permitted. + * @return Optional tertiary text of the cell + */ + public String getTertiaryText() { + return tertiaryText; + } + + /** + * @param tertiaryText - Maps to Choice.tertiaryText. Optional tertiary text of the cell, if + * available. Duplicates within an `ChoiceSet` are permitted. + */ + void setTertiaryText(String tertiaryText) { + this.tertiaryText = tertiaryText; + } + + /** + * Maps to Choice.vrCommands. Optional voice commands the user can speak to activate the cell. + * If not set and the head unit requires it, this will be set to the number in the list that this + * item appears. However, this would be a very poor experience for a user if the choice set is + * presented as a voice only interaction or both interaction mode. Therefore, consider not setting + * this only when you know the choice set will be presented as a touch only interaction. + * @return The list of voice command strings + */ + public List getVoiceCommands() { + return voiceCommands; + } + + /** + * @param voiceCommands - Maps to Choice.vrCommands. Optional voice commands the user can speak to activate the cell. + * If not set and the head unit requires it, this will be set to the number in the list that this + * item appears. However, this would be a very poor experience for a user if the choice set is + * presented as a voice only interaction or both interaction mode. Therefore, consider not setting + * this only when you know the choice set will be presented as a touch only interaction. + */ + void setVoiceCommands(List voiceCommands) { + this.voiceCommands = voiceCommands; + } + + /** + * Maps to Choice.image. Optional image for the cell. This will be uploaded before the cell is + * used when the cell is preloaded or presented for the first time. + * @return The SdlArtwork + */ + public SdlArtwork getArtwork() { + return artwork; + } + + /** + * @param artwork - Maps to Choice.image. Optional image for the cell. This will be uploaded + * before the cell is used when the cell is preloaded or presented for the first time. + */ + void setArtwork(SdlArtwork artwork) { + this.artwork = artwork; + } + + /** + * Maps to Choice.secondaryImage. Optional secondary image for the cell. This will be uploaded + * before the cell is used when the cell is preloaded or presented for the first time. + * @return The SdlArtwork + */ + public SdlArtwork getSecondaryArtwork() { + return secondaryArtwork; + } + + /** + * @param secondaryArtwork - Maps to Choice.secondaryImage. Optional secondary image for the cell. + * This will be uploaded before the cell is used when the cell is preloaded or presented for the first time. + */ + void setSecondaryArtwork(SdlArtwork secondaryArtwork) { + this.secondaryArtwork = secondaryArtwork; + } + + /** + * NOTE: USED INTERNALLY + * Set the choice Id. + * @param choiceId - the choice Id + */ + void setChoiceId(int choiceId) { + this.choiceId = choiceId; + } + + /** + * NOTE: USED INTERNALLY + * Get the choiceId + * @return the choiceId for this Choice Cell + */ + int getChoiceId() { + return choiceId; + } + + @Override + public int hashCode() { + int result = 1; + result += ((getText() == null) ? 0 : Integer.rotateLeft(getText().hashCode(), 1)); + result += ((getSecondaryText() == null) ? 0 : Integer.rotateLeft(getSecondaryText().hashCode(), 2)); + result += ((getTertiaryText() == null) ? 0 : Integer.rotateLeft(getTertiaryText().hashCode(), 3)); + result += ((getArtwork() == null || getArtwork().getName() == null) ? 0 : Integer.rotateLeft(getArtwork().getName().hashCode(), 4)); + result += ((getSecondaryArtwork() == null || getSecondaryArtwork().getName() == null) ? 0 : Integer.rotateLeft(getSecondaryArtwork().getName().hashCode(), 5)); + result += ((getVoiceCommands() == null) ? 0 : Integer.rotateLeft(getVoiceCommands().hashCode(), 6)); + return result; + } + + /** + * Uses our custom hashCode for ChoiceCell objects + * @param o - The object to compare + * @return boolean of whether the objects are the same or not + */ + @Override + public boolean equals(Object o) { + if (o == null) { return false; } + // if this is the same memory address, its the same + if (this == o) return true; + // if this is not an instance of this class, not the same + if (!(o instanceof ChoiceCell)) return false; + // return comparison + return hashCode() == o.hashCode(); + } + + /** + * @return A string description of the cell, useful for debugging. + */ + @Override @NonNull + public String toString() { + return "ChoiceCell: ID: " + this.choiceId + " Text: " + text+ " - Secondary Text: "+ secondaryText+" - Tertiary Text: "+ tertiaryText+ " " + + "| Artwork Names: "+ ((getArtwork() == null || getArtwork().getName() == null) ? "Primary Art null" : getArtwork().getName()) + + " Secondary Art - "+((getSecondaryArtwork() == null || getSecondaryArtwork().getName() == null) ? "Secondary Art null" : getSecondaryArtwork().getName()) + + " | Voice Commands Size: "+ ((getVoiceCommands() == null) ? 0 : getVoiceCommands().size()); + } + +} diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSet.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSet.java new file mode 100644 index 0000000000..7a1c0b1380 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSet.java @@ -0,0 +1,388 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.choiceset; + +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import com.smartdevicelink.proxy.TTSChunkFactory; +import com.smartdevicelink.proxy.rpc.KeyboardProperties; +import com.smartdevicelink.proxy.rpc.TTSChunk; +import com.smartdevicelink.proxy.rpc.VrHelpItem; +import com.smartdevicelink.util.DebugTool; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; + +public class ChoiceSet { + private String title; + private List initialPrompt, timeoutPrompt, helpPrompt; + private ChoiceSetLayout layout; + private Integer timeout; + private List choices; + private List vrHelpList; + private ChoiceSetSelectionListener choiceSetSelectionListener; + private KeyboardProperties customKeyboardConfiguration; + + // defaults + private Integer defaultTimeout = 10; + private ChoiceSetLayout defaultLayout = ChoiceSetLayout.CHOICE_SET_LAYOUT_LIST; + + /** + * Initialize with a title, listener, and choices. It will use the default timeout and layout, + * all other properties (such as prompts) will be `null`. + * + * @param title - The choice set's title + * @param listener - The choice set listener called after the user has interacted with your choice set + * @param choices - The choices to be displayed to the user for interaction + */ + public ChoiceSet(@NonNull String title, @NonNull List choices, @NonNull ChoiceSetSelectionListener listener) { + + setTitle(title); + setChoiceSetSelectionListener(listener); + setChoices(choices); + + // defaults + setLayout(defaultLayout); + setTimeout(defaultTimeout); + + // things to do + checkChoiceSetParameters(); + } + + /** + * Constructor with all possible properties. + * + * @param title - The choice set's title + * @param listener - The choice set listener called after the user has interacted with your choice set + * @param layout - The layout of choice options (Manual/touch only) + * @param timeout - The timeout of a touch interaction (Manual/touch only). This is set to seconds if using the screen manager. + * @param initialPrompt - A voice prompt spoken to the user when this set is displayed + * @param timeoutPrompt - A voice prompt spoken to the user when the set times out (Voice only) + * @param helpPrompt - A voice prompt spoken to the user when the user asks for "help" + * @param helpList - A table list of text and images shown to the user during a voice recognition session for this choice set (Voice only) + * @param choices - The list of choices presented to the user either as a manual/touch interaction or via the user's voice + * @param customKeyboardConfiguration - Implement this in order to provide a custom keyboard configuration to just this keyboard. To apply default settings to all keyboards, see ScreenManager.setKeyboardConfiguration + */ + public ChoiceSet(@NonNull String title, @Nullable ChoiceSetLayout layout, @Nullable Integer timeout, @Nullable String initialPrompt, @Nullable String timeoutPrompt, @Nullable String helpPrompt, @Nullable List helpList, @Nullable KeyboardProperties customKeyboardConfiguration, @NonNull List choices, @NonNull ChoiceSetSelectionListener listener) { + + setTitle(title); + setChoiceSetSelectionListener(listener); + setLayout(layout); + setTimeout(timeout); + setChoices(choices); + setCustomKeyboardConfiguration(customKeyboardConfiguration); + + // Help the dev by creating TTS chunks for them + if (initialPrompt != null){ + setInitialPrompt(TTSChunkFactory.createSimpleTTSChunks(initialPrompt)); + } + + if (timeoutPrompt != null){ + setTimeoutPrompt(TTSChunkFactory.createSimpleTTSChunks(timeoutPrompt)); + } + + if (helpPrompt != null){ + setHelpPrompt(TTSChunkFactory.createSimpleTTSChunks(helpPrompt)); + } + + // things to do + checkChoiceSetParameters(); + setVrHelpList(helpList); + } + + /** + * Constructor with all possible properties. + * + * @param title - The choice set's title + * @param listener - The choice set listener called after the user has interacted with your choice set + * @param layout - The layout of choice options (Manual/touch only) + * @param timeout - The timeout of a touch interaction (Manual/touch only). This is set to seconds if using the screen manager. + * @param initialPrompt - A voice prompt spoken to the user when this set is displayed + * @param timeoutPrompt - A voice prompt spoken to the user when the set times out (Voice only) + * @param helpPrompt - A voice prompt spoken to the user when the user asks for "help" + * @param helpList - A table list of text and images shown to the user during a voice recognition session for this choice set (Voice only) + * @param choices - The list of choices presented to the user either as a manual/touch interaction or via the user's voice + * @param customKeyboardConfiguration - Implement this in order to provide a custom keyboard configuration to just this keyboard. To apply default settings to all keyboards, see ScreenManager.setKeyboardConfiguration + */ + public ChoiceSet(@NonNull String title, @Nullable ChoiceSetLayout layout, @Nullable Integer timeout, @Nullable List initialPrompt, @Nullable List timeoutPrompt, @Nullable List helpPrompt, @Nullable List helpList, @Nullable KeyboardProperties customKeyboardConfiguration, @NonNull List choices, @NonNull ChoiceSetSelectionListener listener) { + + setTitle(title); + setChoiceSetSelectionListener(listener); + setInitialPrompt(initialPrompt); + setTimeoutPrompt(timeoutPrompt); + setHelpPrompt(helpPrompt); + setChoices(choices); + setTimeout(timeout); + setLayout(layout); + setCustomKeyboardConfiguration(customKeyboardConfiguration); + + // things to do + checkChoiceSetParameters(); + setVrHelpList(helpList); + } + + /** + * Maps to PerformInteraction.initialText. The title of the choice set, and/or the initial text on a keyboard prompt. + * @return the title + */ + public String getTitle() { + return title; + } + + /** + * @param title - Maps to PerformInteraction.initialText. The title of the choice set, and/or the initial text on a keyboard prompt. + */ + public void setTitle(String title) { + this.title = title; + checkChoiceSetParameters(); + } + + /** + * Maps to PerformInteraction.initialPrompt. The initial prompt spoken to the user at the start of an interaction. + * @return The list of TTSChunks + */ + public List getInitialPrompt() { + return initialPrompt; + } + + /** + * @param initialPrompt - Maps to PerformInteraction.initialPrompt. The initial prompt spoken to the user at the start of an interaction. + */ + public void setInitialPrompt(List initialPrompt) { + this.initialPrompt = initialPrompt; + } + + /** + * Maps to PerformInteraction.timeoutPrompt. This text is spoken when a VR interaction times out. + * If this set is presented in a manual (non-voice) only interaction, this will be ignored. + * @return - The list of TTS Chunks + */ + public List getTimeoutPrompt() { + return timeoutPrompt; + } + + /** + * @param timeoutPrompt - Maps to PerformInteraction.timeoutPrompt. This text is spoken when a + * VR interaction times out. If this set is presented in a manual (non-voice) only interaction, this will be ignored. + */ + public void setTimeoutPrompt(List timeoutPrompt) { + this.timeoutPrompt = timeoutPrompt; + } + + /** + * Maps to PerformInteraction.helpPrompt. This is the spoken string when a user speaks "help" when the interaction is occurring. + * @return The List of TTS Chunks + */ + public List getHelpPrompt() { + return helpPrompt; + } + + /** + * @param helpPrompt - Maps to PerformInteraction.helpPrompt. This is the spoken string when a user + * speaks "help" when the interaction is occurring. + */ + public void setHelpPrompt(List helpPrompt) { + this.helpPrompt = helpPrompt; + } + + /** + * Maps to PerformInteraction.vrHelp. This is a list of help text presented to the user when + * they are in a voice recognition interaction from your choice set of options. If this set is + * presented in a touch only interaction, this will be ignored. + * + * Note: That while VRHelpItem's position will be automatically set based on position in the + * array, the image will need to uploaded by you before use using the FileManager. + * + * @return The List of VR Help Items + */ + public List getVrHelpList() { + return vrHelpList; + } + + /** + * @param vrHelpList - Maps to PerformInteraction.vrHelp. This is a list of help text presented to the user when + * they are in a voice recognition interaction from your choice set of options. If this set is + * presented in a touch only interaction, this will be ignored. + * + * Note: That while SDLVRHelpItem's position will be automatically set based on position in the + * array, the image will need to uploaded by you before use using the FileManager. + */ + public void setVrHelpList(List vrHelpList) { + this.vrHelpList = setUpHelpItems(vrHelpList); + } + + /** + * Maps to PerformInteraction.interactionLayout. Whether the presented choices are arranged as + * a set of tiles or a list. + * @return The ChoiceSetLayout + */ + public ChoiceSetLayout getLayout() { + return layout; + } + + /** + * @param layout - Maps to PerformInteraction.interactionLayout. Whether the presented choices + * are arranged as a set of tiles or a list. + */ + public void setLayout(ChoiceSetLayout layout) { + if (layout == null){ + this.layout = defaultLayout; + } else { + this.layout = layout; + } + } + + /** + * Maps to PerformInteraction.timeout. This applies only to a manual selection (not a voice + * selection, which has its timeout handled by the system). Defaults to `defaultTimeout`. + * @return The Timeout + */ + public Integer getTimeout() { + return timeout; + } + + /** + * @param timeout - Maps to PerformInteraction.timeout. This applies only to a manual selection + * (not a voice selection, which has its timeout handled by the system). Defaults to `defaultTimeout`. + * This is set to seconds if using the screen manager. + */ + public void setTimeout(Integer timeout) { + if (timeout == null) { + this.timeout = defaultTimeout; + } else { + this.timeout = timeout; + } + checkChoiceSetParameters(); + } + + /** + * The choices to be displayed to the user within this choice set. These choices could match + * those already preloaded + * + * This is limited to 100 items. If you attempt to set more than 100 items, the set will not + * have any items (this array will be empty). + * @return The List of ChoiceCells + */ + public List getChoices() { + return choices; + } + + /** + * @param choices - The choices to be displayed to the user within this choice set. These choices could match + * those already preloaded + * + * This is limited to 100 items. If you attempt to set more than 100 items, the set will not + * have any items (this array will be empty). + */ + public void setChoices(List choices) { + this.choices = choices; + checkChoiceSetParameters(); + } + + /** + * The listener of this choice set, called when the user interacts with it. + * @return The listener + */ + public ChoiceSetSelectionListener getChoiceSetSelectionListener() { + return choiceSetSelectionListener; + } + + /** + * @param choiceSetSelectionListener The listener of this choice set, called when the user interacts with it. + */ + public void setChoiceSetSelectionListener(ChoiceSetSelectionListener choiceSetSelectionListener) { + this.choiceSetSelectionListener = choiceSetSelectionListener; + } + + /** + * Implement this in order to provide a custom keyboard configuration to just this keyboard. + * To apply default settings to all keyboards, see ScreenManager.setKeyboardConfiguration + * @param customKeyboardConfiguration - the keyboard config used for this choice set + */ + public void setCustomKeyboardConfiguration(KeyboardProperties customKeyboardConfiguration) { + this.customKeyboardConfiguration = customKeyboardConfiguration; + } + + /** + * Implement this in order to provide a custom keyboard configuration to just this keyboard. + * To apply default settings to all keyboards, see ScreenManager.setKeyboardConfiguration + * @return the custom keyboard configuration + */ + public KeyboardProperties getCustomKeyboardConfiguration() { + return customKeyboardConfiguration; + } + + // HELPERS + + private void checkChoiceSetParameters(){ + if (DebugTool.isDebugEnabled()) { + if (getTitle() != null) { + if (getTitle().length() == 0 || getTitle().length() > 500) { + DebugTool.logWarning("Attempted to create a choice set with a title of " + getTitle().length() + " length. Only 500 characters are supported."); + } + } + if (getTimeout() != null) { + if (getTimeout() < 5 || getTimeout() > 100) { + DebugTool.logWarning("Attempted to create a choice set with a " + getTimeout() + " second timeout; Only 5 - 100 seconds is valid"); + } + } + if (getChoices() != null) { + if (getChoices().size() == 0 || getChoices().size() > 100) { + DebugTool.logWarning("Attempted to create a choice set with "+getChoices().size()+" choices; Only 1 - 100 choices are valid"); + } + } + } + } + + private List setUpHelpItems(List helpItems){ + List clonedHelpItems = null; + VrHelpItem clonedHelpItem; + if (helpItems != null) { + clonedHelpItems = new ArrayList<>(); + if (!helpItems.isEmpty()) { + for (int i = 0; i < helpItems.size(); i++) { + // clone helpItem so we don't modify the develop copy + clonedHelpItem = new VrHelpItem((Hashtable) helpItems.get(i).getStore().clone()); + + // set help item positioning + clonedHelpItem.setPosition(i + 1); + + clonedHelpItems.add(clonedHelpItem); + } + } + } + return clonedHelpItems; + } + +} diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetLayout.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetLayout.java new file mode 100644 index 0000000000..312accd75d --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetLayout.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.choiceset; + +public enum ChoiceSetLayout { + CHOICE_SET_LAYOUT_LIST, + CHOICE_SET_LAYOUT_TILES; + + public static ChoiceSetLayout valueForString(String value) { + try { + return valueOf(value); + } catch (Exception e) { + return null; + } + } +} diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetSelectionListener.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetSelectionListener.java new file mode 100644 index 0000000000..5f477b58ac --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetSelectionListener.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.choiceset; + +import com.smartdevicelink.proxy.rpc.enums.TriggerSource; + +public interface ChoiceSetSelectionListener { + void onChoiceSelected(ChoiceCell choiceCell, TriggerSource triggerSource, int rowIndex); + void onError(String error); +} diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/DeleteChoicesOperation.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/DeleteChoicesOperation.java new file mode 100644 index 0000000000..fdb01ae384 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/DeleteChoicesOperation.java @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Created by brettywhite on 6/12/19 1:52 PM + * + */ + +package com.smartdevicelink.managers.screen.choiceset; + +import com.smartdevicelink.managers.CompletionListener; +import com.smartdevicelink.proxy.RPCResponse; +import com.smartdevicelink.proxy.interfaces.ISdl; +import com.smartdevicelink.proxy.rpc.DeleteInteractionChoiceSet; +import com.smartdevicelink.proxy.rpc.enums.Result; +import com.smartdevicelink.proxy.rpc.listeners.OnMultipleRequestListener; +import com.smartdevicelink.util.DebugTool; + +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; + +class DeleteChoicesOperation implements Runnable { + + private WeakReference internalInterface; + private HashSet cellsToDelete; + private CompletionListener completionListener; + + DeleteChoicesOperation(ISdl internalInterface, HashSet cellsToDelete, CompletionListener completionListener){ + this.internalInterface = new WeakReference<>(internalInterface); + this.cellsToDelete = cellsToDelete; + this.completionListener = completionListener; + } + + @Override + public void run() { + DebugTool.logInfo("Choice Operation: Executing delete choices operation"); + sendDeletions(); + } + + private void sendDeletions(){ + + List deleteChoices = createDeleteSets(); + + if (deleteChoices.size() > 0) { + + if (internalInterface.get() != null) { + internalInterface.get().sendRequests(deleteChoices, new OnMultipleRequestListener() { + @Override + public void onUpdate(int remainingRequests) { + } + + @Override + public void onFinished() { + if (completionListener != null) { + completionListener.onComplete(true); + } + DebugTool.logInfo("Successfully deleted choices"); + } + + @Override + public void onError(int correlationId, Result resultCode, String info) { + if (completionListener != null) { + completionListener.onComplete(false); + } + DebugTool.logError("Failed to delete choice: " + info + " | Corr ID: " + correlationId); + } + + @Override + public void onResponse(int correlationId, RPCResponse response) { + } + }); + } + } else{ + if (completionListener != null) { + completionListener.onComplete(true); + } + DebugTool.logInfo("No Choices to delete, continue"); + } + } + + List createDeleteSets(){ + List deleteChoices = new ArrayList<>(cellsToDelete.size()); + for (ChoiceCell cell : cellsToDelete){ + deleteChoices.add(new DeleteInteractionChoiceSet(cell.getChoiceId())); + } + return deleteChoices; + } +} diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/KeyboardAutocompleteCompletionListener.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/KeyboardAutocompleteCompletionListener.java new file mode 100644 index 0000000000..9925090193 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/KeyboardAutocompleteCompletionListener.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.choiceset; + +import com.smartdevicelink.proxy.SystemCapabilityManager; +import com.smartdevicelink.proxy.rpc.enums.SystemCapabilityType; + +import java.util.List; + +public interface KeyboardAutocompleteCompletionListener { + + /** + * This listener is called when you wish to update your autocomplete text in response to the user's input + * @param updatedAutoCompleteText - The new autocomplete text to use + * @deprecated use {@link #onUpdatedAutoCompleteList(List)} instead + */ + @Deprecated + void onUpdatedAutoCompleteText(String updatedAutoCompleteText); + + /** + * This listener is called when you wish to update your autocomplete suggestions list in response to the user's input + * @param updatedAutoCompleteList - The new autocomplete suggestions list to use + */ + void onUpdatedAutoCompleteList(List updatedAutoCompleteList); +} diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/KeyboardCharacterSetCompletionListener.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/KeyboardCharacterSetCompletionListener.java new file mode 100644 index 0000000000..7221bf7d12 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/KeyboardCharacterSetCompletionListener.java @@ -0,0 +1,12 @@ +package com.smartdevicelink.managers.screen.choiceset; + +import java.util.List; + +public interface KeyboardCharacterSetCompletionListener { + + /** + * This listener is called when you wish to update your keyboard's limitedCharacterSet in response to the user's input + * @param updatedCharacterSet - The new set of characters to use + */ + void onUpdatedCharacterSet(List updatedCharacterSet); +} diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/KeyboardListener.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/KeyboardListener.java new file mode 100644 index 0000000000..a92fafa759 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/KeyboardListener.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.choiceset; + +import com.smartdevicelink.proxy.rpc.enums.KeyboardEvent; + +public interface KeyboardListener { + + /** + * The keyboard session completed with some input. + * + * This will be sent upon ENTRY_SUBMITTED or ENTRY_VOICE. If the event is ENTRY_VOICE, the user + * requested to start a voice session in order to submit input to this keyboard. This MUST be + * handled by you. Start an Audio Pass Thru session if supported. + * + * @param inputText - The submitted input text on the keyboard + * @param event - ENTRY_SUBMITTED if the user pressed the submit button on the keyboard, ENTRY_VOICE + * if the user requested that a voice session begin + */ + void onUserDidSubmitInput(String inputText, KeyboardEvent event); + + /** + * The keyboard session aborted. + * + * This will be sent if the keyboard event ENTRY_CANCELLED or ENTRY_ABORTED is sent + * + * @param event - ENTRY_CANCELLED if the user cancelled the keyboard input, or ENTRY_ABORTED if + * the system aborted the input due to a higher priority event + */ + void onKeyboardDidAbortWithReason(KeyboardEvent event); + + /** + * Implement this in order to provide a custom keyboard configuration to just this keyboard. To + * apply default settings to all keyboards, see SDLScreenManager.keyboardConfiguration + * + * @param currentInputText - The user's full current input text + * @param keyboardAutocompleteCompletionListener - A listener to update the autoCompleteText + */ + void updateAutocompleteWithInput(String currentInputText, KeyboardAutocompleteCompletionListener keyboardAutocompleteCompletionListener); + + /** + * Implement this if you wish to update the limitedCharacterSet as the user updates their input. + * This is called upon a KEYPRESS event. + * + * @param currentInputText - The user's full current input text + * @param keyboardCharacterSetCompletionListener - A listener to update the limitedCharacterSet + */ + void updateCharacterSetWithInput(String currentInputText, KeyboardCharacterSetCompletionListener keyboardCharacterSetCompletionListener); + + /** + * Implement this to be notified of all events occurring on the keyboard + * + * @param event - The event that occurred + * @param currentInputText - The user's full current input text + */ + void onKeyboardDidSendEvent(KeyboardEvent event, String currentInputText); +} \ No newline at end of file diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PausableThreadPoolExecutor.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PausableThreadPoolExecutor.java new file mode 100644 index 0000000000..74f1cd85a4 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PausableThreadPoolExecutor.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2019 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. + * + * + * Note: This file has been modified from its original form. + * Site with example code: https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor + */ + +package com.smartdevicelink.managers.screen.choiceset; + +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.ReentrantLock; + +class PausableThreadPoolExecutor extends ThreadPoolExecutor { + + private boolean isPaused; + private ReentrantLock threadLock; + private Condition condition; + + PausableThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue workQueue) { + super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue); + threadLock = new ReentrantLock(); + condition = threadLock.newCondition(); + } + + protected void beforeExecute(Thread t, Runnable r) { + super.beforeExecute(t, r); + threadLock.lock(); + try { + while (isPaused) condition.await(); + } catch (InterruptedException ie) { + t.interrupt(); + } finally { + threadLock.unlock(); + } + } + + void pause() { + threadLock.lock(); + try { + isPaused = true; + } finally { + threadLock.unlock(); + } + } + + void resume() { + threadLock.lock(); + try { + isPaused = false; + condition.signalAll(); + } finally { + threadLock.unlock(); + } + } + +} diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PreloadChoicesOperation.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PreloadChoicesOperation.java new file mode 100644 index 0000000000..f3d708998c --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PreloadChoicesOperation.java @@ -0,0 +1,269 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Created by brettywhite on 6/12/19 1:52 PM + * + */ + +package com.smartdevicelink.managers.screen.choiceset; + +import android.support.annotation.NonNull; + +import com.smartdevicelink.managers.CompletionListener; +import com.smartdevicelink.managers.file.FileManager; +import com.smartdevicelink.managers.file.MultipleFileCompletionListener; +import com.smartdevicelink.managers.file.filetypes.SdlArtwork; +import com.smartdevicelink.proxy.RPCResponse; +import com.smartdevicelink.proxy.interfaces.ISdl; +import com.smartdevicelink.proxy.rpc.Choice; +import com.smartdevicelink.proxy.rpc.CreateInteractionChoiceSet; +import com.smartdevicelink.proxy.rpc.DisplayCapabilities; +import com.smartdevicelink.proxy.rpc.Image; +import com.smartdevicelink.proxy.rpc.ImageField; +import com.smartdevicelink.proxy.rpc.TextField; +import com.smartdevicelink.proxy.rpc.enums.ImageFieldName; +import com.smartdevicelink.proxy.rpc.enums.Result; +import com.smartdevicelink.proxy.rpc.enums.TextFieldName; +import com.smartdevicelink.proxy.rpc.listeners.OnMultipleRequestListener; +import com.smartdevicelink.util.DebugTool; + +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; + +class PreloadChoicesOperation implements Runnable { + + private WeakReference internalInterface; + private WeakReference fileManager; + private DisplayCapabilities displayCapabilities; + private HashSet cellsToUpload; + private CompletionListener completionListener; + private boolean isRunning; + private boolean isVROptional; + + PreloadChoicesOperation(ISdl internalInterface, FileManager fileManager, DisplayCapabilities displayCapabilities, + Boolean isVROptional, HashSet cellsToPreload, CompletionListener listener){ + this.internalInterface = new WeakReference<>(internalInterface); + this.fileManager = new WeakReference<>(fileManager); + this.displayCapabilities = displayCapabilities; + this.isVROptional = isVROptional; + this.cellsToUpload = cellsToPreload; + this.completionListener = listener; + } + + @Override + public void run() { + DebugTool.logInfo("Choice Operation: Executing preload choices operation"); + preloadCellArtworks(new CompletionListener() { + @Override + public void onComplete(boolean success) { + preloadCells(); + } + }); + } + + void removeChoicesFromUpload(HashSet choices){ + if (isRunning){ return; } + cellsToUpload.removeAll(choices); + } + + private void preloadCellArtworks(@NonNull final CompletionListener listener){ + isRunning = true; + + List artworksToUpload = artworksToUpload(); + + if (artworksToUpload.size() == 0){ + DebugTool.logInfo("Choice Preload: No Choice Artworks to upload"); + listener.onComplete(true); + isRunning = false; + return; + } + + if (fileManager.get() != null){ + fileManager.get().uploadArtworks(artworksToUpload, new MultipleFileCompletionListener() { + @Override + public void onComplete(Map errors) { + if (errors != null && errors.size() > 0){ + DebugTool.logError("Error uploading choice cell Artworks: "+ errors.toString()); + listener.onComplete(false); + isRunning = false; + }else{ + DebugTool.logInfo("Choice Artworks Uploaded"); + listener.onComplete(true); + isRunning = false; + } + } + }); + }else{ + DebugTool.logError("File manager is null in choice preload operation"); + listener.onComplete(false); + isRunning = false; + } + } + + private void preloadCells(){ + isRunning = true; + List choiceRPCs = new ArrayList<>(cellsToUpload.size()); + for (ChoiceCell cell : cellsToUpload){ + CreateInteractionChoiceSet csCell = choiceFromCell(cell); + if (csCell != null){ + choiceRPCs.add(csCell); + } + } + + if (choiceRPCs.size() == 0){ + DebugTool.logError(" All Choice cells to send are null, so the choice set will not be shown"); + completionListener.onComplete(true); + isRunning = false; + return; + } + + if (internalInterface.get() != null){ + internalInterface.get().sendRequests(choiceRPCs, new OnMultipleRequestListener() { + @Override + public void onUpdate(int remainingRequests) { + + } + + @Override + public void onFinished() { + isRunning = false; + DebugTool.logInfo("Finished pre loading choice cells"); + completionListener.onComplete(true); + } + + @Override + public void onError(int correlationId, Result resultCode, String info) { + DebugTool.logError("There was an error uploading a choice cell: "+ info + " resultCode: " + resultCode); + } + + @Override + public void onResponse(int correlationId, RPCResponse response) { + + } + }); + }else{ + DebugTool.logError("Internal Interface null in preload choice operation"); + isRunning = false; + completionListener.onComplete(false); + } + } + + private CreateInteractionChoiceSet choiceFromCell(ChoiceCell cell){ + + List vrCommands; + if (cell.getVoiceCommands() == null){ + vrCommands = isVROptional ? null : Collections.singletonList(String.valueOf(cell.getChoiceId())); + }else{ + vrCommands = cell.getVoiceCommands(); + } + + String menuName = hasTextFieldOfName(TextFieldName.menuName) ? cell.getText() : null; + if (menuName == null){ + DebugTool.logError("Could not convert Choice Cell to CreateInteractionChoiceSet. It will not be shown. Cell: "+ cell.toString()); + return null; + } + + String secondaryText = hasTextFieldOfName(TextFieldName.secondaryText) ? cell.getSecondaryText() : null; + String tertiaryText = hasTextFieldOfName(TextFieldName.tertiaryText) ? cell.getTertiaryText() : null; + + Image image = hasImageFieldOfName(ImageFieldName.choiceImage) && cell.getArtwork() != null ? cell.getArtwork().getImageRPC() : null; + Image secondaryImage = hasImageFieldOfName(ImageFieldName.choiceSecondaryImage) && cell.getSecondaryArtwork() != null ? cell.getSecondaryArtwork().getImageRPC() : null; + + Choice choice = new Choice(cell.getChoiceId(), menuName); + choice.setVrCommands(vrCommands); + choice.setSecondaryText(secondaryText); + choice.setTertiaryText(tertiaryText); + choice.setIgnoreAddingVRItems(true); + + if (fileManager.get() != null){ + if (image != null && fileManager.get().hasUploadedFile(cell.getArtwork())) { + choice.setImage(image); + } + if (secondaryImage != null && fileManager.get().hasUploadedFile(cell.getSecondaryArtwork())) { + choice.setSecondaryImage(secondaryImage); + } + } + + return new CreateInteractionChoiceSet(choice.getChoiceID(), Collections.singletonList(choice)); + } + + // HELPERS + + List artworksToUpload(){ + List artworksToUpload = new ArrayList<>(cellsToUpload.size()); + for (ChoiceCell cell : cellsToUpload){ + if (hasImageFieldOfName(ImageFieldName.choiceImage) && artworkNeedsUpload(cell.getArtwork())){ + artworksToUpload.add(cell.getArtwork()); + } + if (hasImageFieldOfName(ImageFieldName.choiceSecondaryImage) && artworkNeedsUpload(cell.getSecondaryArtwork())){ + artworksToUpload.add(cell.getSecondaryArtwork()); + } + } + return artworksToUpload; + } + + boolean artworkNeedsUpload(SdlArtwork artwork){ + if (fileManager.get() != null){ + return (artwork != null && !fileManager.get().hasUploadedFile(artwork) && !artwork.isStaticIcon()); + } + return false; + } + + boolean hasImageFieldOfName(ImageFieldName name){ + if (displayCapabilities == null ){ return false; } + if (displayCapabilities.getGraphicSupported() == null || !displayCapabilities.getGraphicSupported()) { return false; } + if (displayCapabilities.getImageFields() != null){ + for (ImageField field : displayCapabilities.getImageFields()){ + if (field.getName().equals(name)){ + return true; + } + } + } + return false; + } + + boolean hasTextFieldOfName(TextFieldName name){ + if (displayCapabilities == null ){ return false; } + if (displayCapabilities.getTextFields() != null){ + for (TextField field : displayCapabilities.getTextFields()){ + if (field.getName().equals(name)){ + return true; + } + } + } + return false; + } + +} \ No newline at end of file diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PresentChoiceSetOperation.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PresentChoiceSetOperation.java new file mode 100644 index 0000000000..e170dd89e2 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PresentChoiceSetOperation.java @@ -0,0 +1,312 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Created by brettywhite on 6/12/19 1:52 PM + * + */ + +package com.smartdevicelink.managers.screen.choiceset; + +import com.smartdevicelink.managers.CompletionListener; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCNotification; +import com.smartdevicelink.proxy.RPCResponse; +import com.smartdevicelink.proxy.interfaces.ISdl; +import com.smartdevicelink.proxy.rpc.KeyboardProperties; +import com.smartdevicelink.proxy.rpc.OnKeyboardInput; +import com.smartdevicelink.proxy.rpc.PerformInteraction; +import com.smartdevicelink.proxy.rpc.PerformInteractionResponse; +import com.smartdevicelink.proxy.rpc.SetGlobalProperties; +import com.smartdevicelink.proxy.rpc.enums.InteractionMode; +import com.smartdevicelink.proxy.rpc.enums.KeyboardEvent; +import com.smartdevicelink.proxy.rpc.enums.LayoutMode; +import com.smartdevicelink.proxy.rpc.enums.Result; +import com.smartdevicelink.proxy.rpc.enums.TriggerSource; +import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener; +import com.smartdevicelink.proxy.rpc.listeners.OnRPCResponseListener; +import com.smartdevicelink.util.DebugTool; + +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.List; + +class PresentChoiceSetOperation implements Runnable { + + private WeakReference internalInterface; + private ChoiceSet choiceSet; + private InteractionMode presentationMode; + private KeyboardProperties originalKeyboardProperties, keyboardProperties; + private ChoiceCell selectedCell; + private TriggerSource selectedTriggerSource; + private boolean updatedKeyboardProperties; + private OnRPCNotificationListener keyboardRPCListener; + private ChoiceSetSelectionListener choiceSetSelectionListener; + Integer selectedCellRow; + KeyboardListener keyboardListener; + + PresentChoiceSetOperation(ISdl internalInterface, ChoiceSet choiceSet, InteractionMode mode, + KeyboardProperties originalKeyboardProperties, KeyboardListener keyboardListener, ChoiceSetSelectionListener choiceSetSelectionListener){ + this.internalInterface = new WeakReference<>(internalInterface); + this.keyboardListener = keyboardListener; + this.choiceSet = choiceSet; + this.presentationMode = mode; + this.originalKeyboardProperties = originalKeyboardProperties; + this.keyboardProperties = originalKeyboardProperties; + this.selectedCellRow = null; + this.choiceSetSelectionListener = choiceSetSelectionListener; + } + + @Override + public void run() { + DebugTool.logInfo("Choice Operation: Executing present choice set operation"); + addListeners(); + start(); + } + + private void start(){ + // Check if we're using a keyboard (searchable) choice set and setup keyboard properties if we need to + if (keyboardListener != null && choiceSet.getCustomKeyboardConfiguration() != null){ + keyboardProperties = choiceSet.getCustomKeyboardConfiguration(); + updatedKeyboardProperties = true; + } + + updateKeyboardProperties(new CompletionListener() { + @Override + public void onComplete(boolean success) { + presentChoiceSet(); + } + }); + } + + // SENDING REQUESTS + + private void updateKeyboardProperties(final CompletionListener listener){ + if (keyboardProperties == null){ + if (listener != null){ + listener.onComplete(false); + } + return; + } + SetGlobalProperties setGlobalProperties = new SetGlobalProperties(); + setGlobalProperties.setKeyboardProperties(keyboardProperties); + setGlobalProperties.setOnRPCResponseListener(new OnRPCResponseListener() { + @Override + public void onResponse(int correlationId, RPCResponse response) { + + if (!response.getSuccess()){ + if (listener != null){ + listener.onComplete(false); + } + DebugTool.logError("Error Setting keyboard properties in present choice set operation"); + return; + } + + updatedKeyboardProperties = true; + + if (listener != null){ + listener.onComplete(true); + } + DebugTool.logInfo("Success Setting keyboard properties in present choice set operation"); + } + + @Override + public void onError(int correlationId, Result resultCode, String info) { + DebugTool.logError("Error Setting keyboard properties in present keyboard operation - choice manager - " + info); + super.onError(correlationId, resultCode, info); + } + }); + if (internalInterface.get() != null){ + internalInterface.get().sendRPC(setGlobalProperties); + } else { + DebugTool.logError("Internal interface null - present choice set op - choice"); + } + } + + private void presentChoiceSet() { + PerformInteraction pi = getPerformInteraction(); + pi.setOnRPCResponseListener(new OnRPCResponseListener() { + @Override + public void onResponse(int correlationId, RPCResponse response) { + if (!response.getSuccess()){ + DebugTool.logError("Presenting Choice set failed: "+ response.getInfo()); + + if (choiceSetSelectionListener != null){ + choiceSetSelectionListener.onError(response.getInfo()); + } + finishOperation(); + } + + PerformInteractionResponse performInteractionResponse = (PerformInteractionResponse) response; + setSelectedCellWithId(performInteractionResponse.getChoiceID()); + selectedTriggerSource = performInteractionResponse.getTriggerSource(); + + if (choiceSetSelectionListener != null && selectedCell != null && selectedTriggerSource != null && selectedCellRow != null){ + choiceSetSelectionListener.onChoiceSelected(selectedCell, selectedTriggerSource, selectedCellRow); + } + + finishOperation(); + } + }); + if (internalInterface.get() != null){ + internalInterface.get().sendRPC(pi); + }else { + DebugTool.logError("Internal Interface null when presenting choice set in operation"); + } + } + + private void finishOperation() { + + if (updatedKeyboardProperties) { + // We need to reset the keyboard properties + SetGlobalProperties setGlobalProperties = new SetGlobalProperties(); + setGlobalProperties.setKeyboardProperties(originalKeyboardProperties); + setGlobalProperties.setOnRPCResponseListener(new OnRPCResponseListener() { + @Override + public void onResponse(int correlationId, RPCResponse response) { + updatedKeyboardProperties = false; + DebugTool.logInfo("Successfully reset choice keyboard properties to original config"); + } + }); + + if (internalInterface.get() != null) { + internalInterface.get().sendRPC(setGlobalProperties); + internalInterface.get().removeOnRPCNotificationListener(FunctionID.ON_KEYBOARD_INPUT, keyboardRPCListener); + } else { + DebugTool.logError("Internal Interface null when finishing choice keyboard reset"); + } + } + } + + // GETTERS + + PerformInteraction getPerformInteraction() { + + PerformInteraction pi = new PerformInteraction(choiceSet.getTitle(), presentationMode, getChoiceIds()); + pi.setInitialPrompt(choiceSet.getInitialPrompt()); + pi.setHelpPrompt(choiceSet.getHelpPrompt()); + pi.setTimeoutPrompt(choiceSet.getTimeoutPrompt()); + pi.setVrHelp(choiceSet.getVrHelpList()); + pi.setTimeout(choiceSet.getTimeout() * 1000); + pi.setInteractionLayout(getLayoutMode()); + return pi; + } + + LayoutMode getLayoutMode() { + switch (choiceSet.getLayout()){ + case CHOICE_SET_LAYOUT_LIST: + return keyboardListener != null ? LayoutMode.LIST_WITH_SEARCH : LayoutMode.LIST_ONLY; + case CHOICE_SET_LAYOUT_TILES: + return keyboardListener != null ? LayoutMode.ICON_WITH_SEARCH : LayoutMode.ICON_ONLY; + } + return LayoutMode.LIST_ONLY; // default + } + + private List getChoiceIds() { + + List choiceIds = new ArrayList<>(choiceSet.getChoices().size()); + for (ChoiceCell cell : choiceSet.getChoices()){ + choiceIds.add(cell.getChoiceId()); + } + return choiceIds; + } + + // HELPERS + + void setSelectedCellWithId(Integer cellId){ + if (choiceSet.getChoices() != null && cellId != null) { + List cells = choiceSet.getChoices(); + for (int i = 0; i < cells.size(); i++) { + if (cells.get(i).getChoiceId() == cellId) { + selectedCell = cells.get(i); + selectedCellRow = i; + return; + } + } + } + } + + // LISTENERS + + private void addListeners(){ + + keyboardRPCListener = new OnRPCNotificationListener() { + @Override + public void onNotified(RPCNotification notification) { + + if (keyboardListener == null){ + DebugTool.logError("Received Keyboard Input But Listener is null"); + return; + } + + OnKeyboardInput onKeyboard = (OnKeyboardInput) notification; + keyboardListener.onKeyboardDidSendEvent(onKeyboard.getEvent(), onKeyboard.getData()); + + if (onKeyboard.getEvent().equals(KeyboardEvent.ENTRY_VOICE) || onKeyboard.getEvent().equals(KeyboardEvent.ENTRY_SUBMITTED)){ + // Submit Voice or Text + keyboardListener.onUserDidSubmitInput(onKeyboard.getData(), onKeyboard.getEvent()); + } else if (onKeyboard.getEvent().equals(KeyboardEvent.KEYPRESS)){ + // Notify of Keypress + keyboardListener.updateAutocompleteWithInput(onKeyboard.getData(), new KeyboardAutocompleteCompletionListener() { + @Override + public void onUpdatedAutoCompleteText(String updatedAutoCompleteText) { + keyboardProperties.setAutoCompleteText(updatedAutoCompleteText); + updateKeyboardProperties(null); + } + + @Override + public void onUpdatedAutoCompleteList(List updatedAutoCompleteList) { + keyboardProperties.setAutoCompleteList(updatedAutoCompleteList != null ? updatedAutoCompleteList : new ArrayList()); + keyboardProperties.setAutoCompleteText(updatedAutoCompleteList != null && !updatedAutoCompleteList.isEmpty() ? updatedAutoCompleteList.get(0) : null); + updateKeyboardProperties(null); + } + }); + + keyboardListener.updateCharacterSetWithInput(onKeyboard.getData(), new KeyboardCharacterSetCompletionListener() { + @Override + public void onUpdatedCharacterSet(List updatedCharacterSet) { + keyboardProperties.setLimitedCharacterList(updatedCharacterSet); + updateKeyboardProperties(null); + } + }); + } else if (onKeyboard.getEvent().equals(KeyboardEvent.ENTRY_ABORTED) || onKeyboard.getEvent().equals(KeyboardEvent.ENTRY_CANCELLED)){ + // Notify of abort / Cancellation + keyboardListener.onKeyboardDidAbortWithReason(onKeyboard.getEvent()); + } + } + }; + + if (internalInterface.get() != null) { + internalInterface.get().addOnRPCNotificationListener(FunctionID.ON_KEYBOARD_INPUT, keyboardRPCListener); + } else { + DebugTool.logError("Present Choice Set Keyboard Listener Not Added"); + } + } +} \ No newline at end of file diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PresentKeyboardOperation.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PresentKeyboardOperation.java new file mode 100644 index 0000000000..06d86edd5a --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PresentKeyboardOperation.java @@ -0,0 +1,263 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Created by brettywhite on 6/12/19 1:52 PM + * + */ + +package com.smartdevicelink.managers.screen.choiceset; + +import com.smartdevicelink.managers.CompletionListener; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCNotification; +import com.smartdevicelink.proxy.RPCResponse; +import com.smartdevicelink.proxy.interfaces.ISdl; +import com.smartdevicelink.proxy.rpc.KeyboardProperties; +import com.smartdevicelink.proxy.rpc.OnKeyboardInput; +import com.smartdevicelink.proxy.rpc.PerformInteraction; +import com.smartdevicelink.proxy.rpc.SetGlobalProperties; +import com.smartdevicelink.proxy.rpc.enums.InteractionMode; +import com.smartdevicelink.proxy.rpc.enums.KeyboardEvent; +import com.smartdevicelink.proxy.rpc.enums.LayoutMode; +import com.smartdevicelink.proxy.rpc.enums.Result; +import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener; +import com.smartdevicelink.proxy.rpc.listeners.OnRPCResponseListener; +import com.smartdevicelink.util.DebugTool; + +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +class PresentKeyboardOperation implements Runnable { + + private WeakReference internalInterface; + private KeyboardListener keyboardListener; + private KeyboardProperties originalKeyboardProperties, keyboardProperties, customConfig; + private boolean updatedKeyboardProperties; + private String initialText; + private OnRPCNotificationListener keyboardRPCListener; + + PresentKeyboardOperation(ISdl internalInterface, KeyboardProperties originalKeyboardProperties, String initialText, KeyboardProperties customConfig, KeyboardListener keyboardListener){ + this.internalInterface = new WeakReference<>(internalInterface); + this.keyboardListener = keyboardListener; + this.originalKeyboardProperties = originalKeyboardProperties; + this.keyboardProperties = originalKeyboardProperties; + this.customConfig = customConfig; + this.initialText = initialText; + } + + @Override + public void run() { + addListeners(); + start(); + } + + private void start(){ + DebugTool.logInfo("Choice Operation: Executing present keyboard operation"); + if (keyboardListener != null){ + keyboardProperties = customConfig; + updatedKeyboardProperties = true; + } + + updateKeyboardProperties(new CompletionListener() { + @Override + public void onComplete(boolean success) { + presentKeyboard(); + } + }); + } + + // SENDING REQUESTS + + private void presentKeyboard(){ + + if (internalInterface.get() != null){ + + PerformInteraction pi = getPerformInteraction(); + pi.setOnRPCResponseListener(new OnRPCResponseListener() { + @Override + public void onResponse(int correlationId, RPCResponse response) { + finishOperation(); + } + + @Override + public void onError(int correlationId, Result resultCode, String info){ + DebugTool.logError("There was an error presenting the keyboard. Finishing operation - choice set manager - . Error: " + info + " resultCode: " + resultCode); + finishOperation(); + } + }); + + internalInterface.get().sendRPC(pi); + + }else{ + DebugTool.logError("Internal Interface null in present keyboard operation - choice"); + } + + } + + private void updateKeyboardProperties(final CompletionListener listener){ + + if (keyboardProperties == null){ + if (listener != null){ + listener.onComplete(false); + } + return; + } + + SetGlobalProperties setGlobalProperties = new SetGlobalProperties(); + setGlobalProperties.setKeyboardProperties(keyboardProperties); + setGlobalProperties.setOnRPCResponseListener(new OnRPCResponseListener() { + @Override + public void onResponse(int correlationId, RPCResponse response) { + + if (!response.getSuccess()){ + if (listener != null){ + listener.onComplete(false); + } + DebugTool.logError("Error Setting keyboard properties in present keyboard operation - choice manager"); + return; + } + + updatedKeyboardProperties = true; + + if (listener != null){ + listener.onComplete(true); + } + DebugTool.logInfo("Success Setting keyboard properties in present keyboard operation - choice manager"); + } + + @Override + public void onError(int correlationId, Result resultCode, String info) { + DebugTool.logError("Error Setting keyboard properties in present keyboard operation - choice manager - " + info); + super.onError(correlationId, resultCode, info); + } + }); + + if (internalInterface.get() != null){ + internalInterface.get().sendRPC(setGlobalProperties); + } else { + DebugTool.logError("Internal interface null - present keyboard op - choice"); + } + } + + private void finishOperation() { + + if (updatedKeyboardProperties) { + // We need to reset the keyboard properties + SetGlobalProperties setGlobalProperties = new SetGlobalProperties(); + setGlobalProperties.setKeyboardProperties(originalKeyboardProperties); + setGlobalProperties.setOnRPCResponseListener(new OnRPCResponseListener() { + @Override + public void onResponse(int correlationId, RPCResponse response) { + updatedKeyboardProperties = false; + DebugTool.logInfo("Successfully reset choice keyboard properties to original config"); + } + }); + + if (internalInterface.get() != null) { + internalInterface.get().sendRPC(setGlobalProperties); + internalInterface.get().removeOnRPCNotificationListener(FunctionID.ON_KEYBOARD_INPUT, keyboardRPCListener); + } else { + DebugTool.logError("Internal Interface null when finishing choice keyboard reset"); + } + } + } + + // GETTERS + + PerformInteraction getPerformInteraction() { + PerformInteraction pi = new PerformInteraction(); + pi.setInitialText(initialText); + pi.setInteractionMode(InteractionMode.MANUAL_ONLY); + pi.setInteractionChoiceSetIDList(Collections.emptyList()); + pi.setInteractionLayout(LayoutMode.KEYBOARD); + return pi; + } + + // LISTENERS + + private void addListeners(){ + + keyboardRPCListener = new OnRPCNotificationListener() { + @Override + public void onNotified(RPCNotification notification) { + + if (keyboardListener == null){ + DebugTool.logError("Received Keyboard Input But Listener is null"); + return; + } + + OnKeyboardInput onKeyboard = (OnKeyboardInput) notification; + keyboardListener.onKeyboardDidSendEvent(onKeyboard.getEvent(), onKeyboard.getData()); + + if (onKeyboard.getEvent().equals(KeyboardEvent.ENTRY_VOICE) || onKeyboard.getEvent().equals(KeyboardEvent.ENTRY_SUBMITTED)){ + // Submit Voice or Text + keyboardListener.onUserDidSubmitInput(onKeyboard.getData(), onKeyboard.getEvent()); + } else if (onKeyboard.getEvent().equals(KeyboardEvent.KEYPRESS)){ + // Notify of Keypress + keyboardListener.updateAutocompleteWithInput(onKeyboard.getData(), new KeyboardAutocompleteCompletionListener() { + @Override + public void onUpdatedAutoCompleteText(String updatedAutoCompleteText) { + keyboardProperties.setAutoCompleteText(updatedAutoCompleteText); + updateKeyboardProperties(null); + } + + @Override + public void onUpdatedAutoCompleteList(List updatedAutoCompleteList) { + keyboardProperties.setAutoCompleteList(updatedAutoCompleteList != null ? updatedAutoCompleteList : new ArrayList()); + keyboardProperties.setAutoCompleteText(updatedAutoCompleteList != null && !updatedAutoCompleteList.isEmpty() ? updatedAutoCompleteList.get(0) : null); + updateKeyboardProperties(null); + } + }); + + keyboardListener.updateCharacterSetWithInput(onKeyboard.getData(), new KeyboardCharacterSetCompletionListener() { + @Override + public void onUpdatedCharacterSet(List updatedCharacterSet) { + keyboardProperties.setLimitedCharacterList(updatedCharacterSet); + updateKeyboardProperties(null); + } + }); + } else if (onKeyboard.getEvent().equals(KeyboardEvent.ENTRY_ABORTED) || onKeyboard.getEvent().equals(KeyboardEvent.ENTRY_CANCELLED)){ + // Notify of abort / Cancellation + keyboardListener.onKeyboardDidAbortWithReason(onKeyboard.getEvent()); + } + + } + }; + + if (internalInterface.get() != null) { + internalInterface.get().addOnRPCNotificationListener(FunctionID.ON_KEYBOARD_INPUT, keyboardRPCListener); + } else { + DebugTool.logError("Present Keyboard Listener Not Added - choice manager"); + } + } +} \ No newline at end of file diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuConfiguration.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuConfiguration.java new file mode 100644 index 0000000000..501c12d626 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuConfiguration.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Created by brettywhite on 7/18/19 3:28 PM + * + */ + +package com.smartdevicelink.managers.screen.menu; + +import android.support.annotation.NonNull; + +import com.smartdevicelink.proxy.rpc.enums.MenuLayout; + +public class MenuConfiguration { + + private MenuLayout mainMenuLayout, defaultSubmenuLayout; + + public MenuConfiguration(@NonNull MenuLayout mainMenuLayout, @NonNull MenuLayout defaultSubmenuLayout){ + setMenuLayout(mainMenuLayout); + setSubMenuLayout(defaultSubmenuLayout); + } + + /** + * Changes the default main menu layout. Defaults to `MenuLayoutList`. + * @param mainMenuLayout - the layout of the main menu + */ + private void setMenuLayout(@NonNull MenuLayout mainMenuLayout){ + this.mainMenuLayout = mainMenuLayout; + } + + /** + * Changes the default main menu layout. Defaults to `MenuLayoutList`. + * @return - the layout of the main menu + */ + public MenuLayout getMenuLayout() { + return this.mainMenuLayout; + } + + /** + * Changes the default submenu layout. To change this for an individual submenu, set the + * `menuLayout` property on the `MenuCell` constructor for creating a cell with sub-cells. + * Defaults to `MenuLayoutList`. + * @param defaultSubmenuLayout - the MenuLayout for this sub menu + */ + private void setSubMenuLayout(@NonNull MenuLayout defaultSubmenuLayout){ + this.defaultSubmenuLayout = defaultSubmenuLayout; + } + + /** + * Changes the default submenu layout. To change this for an individual submenu, set the + * `menuLayout` property on the `MenuCell` constructor for creating a cell with sub-cells. + * Defaults to `MenuLayoutList`. + * @return - the MenuLayout for this sub menu + */ + public MenuLayout getSubMenuLayout() { + return defaultSubmenuLayout; + } + + /** + * @return A string description of the cell, useful for debugging. + */ + @Override @NonNull + public String toString() { + return "MenuConfiguration: MenuLayout = "+ this.mainMenuLayout + " | SubMenuLayout = "+ this.defaultSubmenuLayout; + } + +} diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/CloseApplication.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/CloseApplication.java new file mode 100644 index 0000000000..3173024826 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/CloseApplication.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Created by Nicole Yarroch on 7/10/19 3:55 PM + */ + +package com.smartdevicelink.proxy.rpc; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCRequest; + +import java.util.Hashtable; + +/** + * Used by an app to set itself to a `HMILevel` of `NONE`. The app will close but will still be registered. If the app is a navigation app it will no longer be used as the preferred mobile-navigation application by the module. + */ +public class CloseApplication extends RPCRequest { + /** + * Constructs a new CloseApplication object + */ + public CloseApplication() { + super(FunctionID.CLOSE_APPLICATION.toString()); + } + + /** + * Constructs a new CloseApplication object indicated by the Hashtable parameter + * + * @param hash The Hashtable to use + */ + public CloseApplication(Hashtable hash) { + super(hash); + } +} diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/CloseApplicationResponse.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/CloseApplicationResponse.java new file mode 100644 index 0000000000..8724e7190c --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/CloseApplicationResponse.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Created by Nicole Yarroch on 7/10/19 3:55 PM + */ + +package com.smartdevicelink.proxy.rpc; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCResponse; + +import java.util.Hashtable; + +/** + * Response to the request to close this app on the module. + */ +public class CloseApplicationResponse extends RPCResponse { + /** + * Constructs a new CloseApplicationResponse object + */ + public CloseApplicationResponse() { + super(FunctionID.CLOSE_APPLICATION.toString()); + } + + /** + * Constructs a new CloseApplicationResponse object indicated by the Hashtable parameter + * + * @param hash The Hashtable to use + */ + public CloseApplicationResponse(Hashtable hash) { + super(hash); + } +} diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/UnpublishAppService.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/UnpublishAppService.java new file mode 100644 index 0000000000..7ad2d8d553 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/UnpublishAppService.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Created by brettywhite on 7/12/19 11:36 AM + * + */ + +package com.smartdevicelink.proxy.rpc; + +import android.support.annotation.NonNull; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCRequest; + +import java.util.Hashtable; + +/** + * Unpublish an existing service published by this application. + */ +public class UnpublishAppService extends RPCRequest { + + public static final String KEY_SERVICE_ID = "serviceID"; + + /** + * Constructs a new UnpublishAppService object + */ + public UnpublishAppService() { + super(FunctionID.UNPUBLISH_APP_SERVICE.toString()); + } + + /** + * Constructs a new UnpublishAppService object indicated by the Hashtable parameter + * + * @param hash The Hashtable to use + */ + public UnpublishAppService(Hashtable hash) { + super(hash); + } + + /** + * Constructs a new UnpublishAppService object with the required serviceID + * @param serviceID - set the service ID for the service to be unpublished + */ + public UnpublishAppService(@NonNull String serviceID){ + this(); + setServiceID(serviceID); + } + + // SETTERS AND GETTERS + + /** + * The ID of the service to be unpublished. + * @param serviceID - set the service ID for the service to be unpublished + */ + public void setServiceID(String serviceID){ + setParameters(KEY_SERVICE_ID, serviceID); + } + + /** + * The ID of the service to be unpublished. + * @return - get the service ID for the service to be unpublished + */ + public String getServiceID(){ + return getString(KEY_SERVICE_ID); + } + +} \ No newline at end of file diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/UnpublishAppServiceResponse.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/UnpublishAppServiceResponse.java new file mode 100644 index 0000000000..06f2f13ae2 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/UnpublishAppServiceResponse.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Created by brettywhite on 7/12/19 11:37 AM + * + */ + +package com.smartdevicelink.proxy.rpc; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCResponse; + +import java.util.Hashtable; + +/** + * The response to UnpublishAppService + */ +public class UnpublishAppServiceResponse extends RPCResponse { + /** + * Constructs a new UnpublishAppServiceResponse object + */ + public UnpublishAppServiceResponse() { + super(FunctionID.UNPUBLISH_APP_SERVICE.toString()); + } + + /** + * Constructs a new UnpublishAppServiceResponse object indicated by the Hashtable parameter + * + * @param hash The Hashtable to use + */ + public UnpublishAppServiceResponse(Hashtable hash) { + super(hash); + } +} diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/enums/MenuLayout.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/enums/MenuLayout.java new file mode 100644 index 0000000000..fcda7b4987 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/enums/MenuLayout.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Created by brettywhite on 7/17/19 12:00 PM + * + */ + +package com.smartdevicelink.proxy.rpc.enums; + +/** + * How the main menu or submenu is laid out on screen + */ +public enum MenuLayout { + + LIST, + + TILES, + + ; + + public static MenuLayout valueForString(String value) { + try { + return valueOf(value); + } catch (Exception e) { + return null; + } + } + +} diff --git a/javaSE/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetManager.java b/javaSE/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetManager.java new file mode 100644 index 0000000000..f470b8a68a --- /dev/null +++ b/javaSE/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetManager.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.choiceset; + +import android.support.annotation.NonNull; + +import com.smartdevicelink.managers.file.FileManager; +import com.smartdevicelink.proxy.interfaces.ISdl; + +/** + * ChoiceSetManager
+ * ChoiceSetManager gives the developer the ability to control how soft choice sets are displayed on the head unit.
+ * Note: This class must be accessed through the SdlManager->ScreenManager. Do not instantiate it by itself.
+ */ +public class ChoiceSetManager extends BaseChoiceSetManager { + + /** + * Creates a new instance of the ChoiceSetManager + * + * @param internalInterface + */ + public ChoiceSetManager(@NonNull ISdl internalInterface, @NonNull FileManager fileManager) { + super(internalInterface, fileManager); + } +} From 17b2216d1aaf0c661d3bef315add6f5d070928ce Mon Sep 17 00:00:00 2001 From: Tuan Nguyen Date: Mon, 29 Jul 2019 13:05:38 -0700 Subject: [PATCH 15/20] Resolve more conflict. --- .../smartdevicelink/proxy/rpc/RadioControlCapabilities.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/RadioControlCapabilities.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/RadioControlCapabilities.java index d30ecc8749..22d1d892e5 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/RadioControlCapabilities.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/RadioControlCapabilities.java @@ -54,11 +54,8 @@ public class RadioControlCapabilities extends RPCStruct{ public static final String KEY_HD_RADIO_ENABLE_AVAILABLE = "hdRadioEnableAvailable"; public static final String KEY_SIRIUS_XM_RADIO_AVAILABLE = "siriusxmRadioAvailable"; public static final String KEY_SIS_DATA_AVAILABLE = "sisDataAvailable"; -<<<<<<< HEAD public static final String KEY_MODULE_INFO = "moduleInfo"; -======= public static final String KEY_AVAILABLE_HD_CHANNELS_AVAILABLE = "availableHdChannelsAvailable"; ->>>>>>> develop_mainRepo public RadioControlCapabilities() { } From 12e01066a0b4b7bc39c3610fb45c61e35ed8694a Mon Sep 17 00:00:00 2001 From: Tuan Nguyen Date: Wed, 31 Jul 2019 11:13:21 -0700 Subject: [PATCH 16/20] Attempt a work-around to fix failed test suite on server. --- .../sdl_android/src/androidTest/AndroidManifest.xml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/android/sdl_android/src/androidTest/AndroidManifest.xml b/android/sdl_android/src/androidTest/AndroidManifest.xml index 5231061fda..e9f5cadc99 100644 --- a/android/sdl_android/src/androidTest/AndroidManifest.xml +++ b/android/sdl_android/src/androidTest/AndroidManifest.xml @@ -7,9 +7,13 @@ - + + android:name="android.test.InstrumentationTestRunner" + android:targetPackage="com.smartdevicelink.test" + + From 3ede8b30e9c0311db6369adaf3035717012fd568 Mon Sep 17 00:00:00 2001 From: Tuan Nguyen Date: Wed, 31 Jul 2019 12:48:26 -0700 Subject: [PATCH 17/20] Revert "Attempt a work-around to fix failed test suite on server." This reverts commit 12e01066a0b4b7bc39c3610fb45c61e35ed8694a. --- .../sdl_android/src/androidTest/AndroidManifest.xml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/android/sdl_android/src/androidTest/AndroidManifest.xml b/android/sdl_android/src/androidTest/AndroidManifest.xml index e9f5cadc99..5231061fda 100644 --- a/android/sdl_android/src/androidTest/AndroidManifest.xml +++ b/android/sdl_android/src/androidTest/AndroidManifest.xml @@ -7,13 +7,9 @@ - - android:name="android.test.InstrumentationTestRunner" - android:targetPackage="com.smartdevicelink.test" - - + From 3f49e16ef6dd382d00dca126c2d0b4d13e37c6eb Mon Sep 17 00:00:00 2001 From: Tuan Nguyen Date: Tue, 13 Aug 2019 10:51:07 -0700 Subject: [PATCH 18/20] Removed unused import. --- .../com/smartdevicelink/proxy/rpc/SeatLocationCapability.java | 1 - 1 file changed, 1 deletion(-) diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/SeatLocationCapability.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/SeatLocationCapability.java index 8c1c23c1b9..db1668787f 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/SeatLocationCapability.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/SeatLocationCapability.java @@ -1,6 +1,5 @@ package com.smartdevicelink.proxy.rpc; -import android.security.KeyChain; import com.smartdevicelink.proxy.RPCStruct; From f6a773cdff1b49969a37bdcbb4b7b31521940351 Mon Sep 17 00:00:00 2001 From: Tuan Nguyen Date: Tue, 13 Aug 2019 13:40:28 -0700 Subject: [PATCH 19/20] Fix per code review recommendations: remove unused imports and attempt to fix indentation. Fix function id to match mobile API spec. --- .../src/androidTest/java/com/smartdevicelink/test/Test.java | 2 -- .../androidTest/java/com/smartdevicelink/test/Validator.java | 1 - .../smartdevicelink/test/rpc/datatypes/ModuleInfoTests.java | 2 -- .../test/rpc/datatypes/SeatLocationCapabilityTests.java | 4 ---- .../test/rpc/requests/GetInteriorVehicleDataConsentTests.java | 1 - .../responses/GetInteriorVehicleDataConsentResponseTests.java | 1 - .../ReleaseInteriorVehicleDataModuleResponseTests.java | 1 - .../java/com/smartdevicelink/protocol/enums/FunctionID.java | 4 ++-- .../com/smartdevicelink/proxy/rpc/ButtonCapabilities.java | 2 +- .../proxy/rpc/GetInteriorVehicleDataConsent.java | 1 + .../proxy/rpc/GetInteriorVehicleDataConsentResponse.java | 1 + .../proxy/rpc/ReleaseInteriorVehicleDataModule.java | 1 - .../com/smartdevicelink/proxy/rpc/SeatLocationCapability.java | 1 + 13 files changed, 6 insertions(+), 16 deletions(-) diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java index 2b76968a0c..9ddf7fb97b 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java @@ -35,7 +35,6 @@ import com.smartdevicelink.proxy.rpc.DeviceInfo; import com.smartdevicelink.proxy.rpc.DisplayCapabilities; import com.smartdevicelink.proxy.rpc.EqualizerSettings; -import com.smartdevicelink.proxy.rpc.GetInteriorVehicleDataConsent; import com.smartdevicelink.proxy.rpc.Grid; import com.smartdevicelink.proxy.rpc.HMICapabilities; import com.smartdevicelink.proxy.rpc.HMIPermissions; @@ -79,7 +78,6 @@ import com.smartdevicelink.proxy.rpc.SeatControlCapabilities; import com.smartdevicelink.proxy.rpc.SeatControlData; import com.smartdevicelink.proxy.rpc.SeatLocation; -import com.smartdevicelink.proxy.rpc.SeatLocationCapability; import com.smartdevicelink.proxy.rpc.SeatMemoryAction; import com.smartdevicelink.proxy.rpc.SingleTireStatus; import com.smartdevicelink.proxy.rpc.SisData; diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Validator.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Validator.java index 8534dc057e..f7b64b27b4 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Validator.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Validator.java @@ -75,7 +75,6 @@ import com.smartdevicelink.proxy.rpc.SeatControlCapabilities; import com.smartdevicelink.proxy.rpc.SeatControlData; import com.smartdevicelink.proxy.rpc.SeatLocation; -import com.smartdevicelink.proxy.rpc.SeatLocationCapability; import com.smartdevicelink.proxy.rpc.SeatMemoryAction; import com.smartdevicelink.proxy.rpc.SingleTireStatus; import com.smartdevicelink.proxy.rpc.SisData; diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ModuleInfoTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ModuleInfoTests.java index 142d5ef23a..508c216f6a 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ModuleInfoTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ModuleInfoTests.java @@ -3,7 +3,6 @@ import com.smartdevicelink.marshal.JsonRPCMarshaller; import com.smartdevicelink.proxy.rpc.Grid; import com.smartdevicelink.proxy.rpc.ModuleInfo; -import com.smartdevicelink.test.JsonUtils; import com.smartdevicelink.test.Test; import com.smartdevicelink.test.Validator; @@ -13,7 +12,6 @@ import org.json.JSONObject; import java.util.Hashtable; -import java.util.Iterator; public class ModuleInfoTests extends TestCase { private ModuleInfo msg; diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SeatLocationCapabilityTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SeatLocationCapabilityTests.java index 956809914e..847564adb4 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SeatLocationCapabilityTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SeatLocationCapabilityTests.java @@ -1,9 +1,7 @@ package com.smartdevicelink.test.rpc.datatypes; -import android.util.Log; import com.smartdevicelink.marshal.JsonRPCMarshaller; -import com.smartdevicelink.proxy.rpc.Grid; import com.smartdevicelink.proxy.rpc.SeatLocation; import com.smartdevicelink.proxy.rpc.SeatLocationCapability; import com.smartdevicelink.test.JsonUtils; @@ -16,8 +14,6 @@ import org.json.JSONException; import org.json.JSONObject; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Hashtable; import java.util.Iterator; import java.util.List; diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetInteriorVehicleDataConsentTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetInteriorVehicleDataConsentTests.java index 486b08b492..0f21a2076f 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetInteriorVehicleDataConsentTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetInteriorVehicleDataConsentTests.java @@ -10,7 +10,6 @@ import com.smartdevicelink.test.Test; import com.smartdevicelink.test.json.rpc.JsonFileReader; -import junit.framework.TestCase; import org.json.JSONException; import org.json.JSONObject; diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetInteriorVehicleDataConsentResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetInteriorVehicleDataConsentResponseTests.java index 5b8cff3cef..b77e056c95 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetInteriorVehicleDataConsentResponseTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetInteriorVehicleDataConsentResponseTests.java @@ -3,7 +3,6 @@ import com.smartdevicelink.marshal.JsonRPCMarshaller; import com.smartdevicelink.protocol.enums.FunctionID; import com.smartdevicelink.proxy.RPCMessage; -import com.smartdevicelink.proxy.rpc.GetInteriorVehicleDataConsent; import com.smartdevicelink.proxy.rpc.GetInteriorVehicleDataConsentResponse; import com.smartdevicelink.test.BaseRpcTests; import com.smartdevicelink.test.JsonUtils; diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ReleaseInteriorVehicleDataModuleResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ReleaseInteriorVehicleDataModuleResponseTests.java index 9bedadd97b..f1d2b6e5a3 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ReleaseInteriorVehicleDataModuleResponseTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ReleaseInteriorVehicleDataModuleResponseTests.java @@ -3,7 +3,6 @@ import com.smartdevicelink.marshal.JsonRPCMarshaller; import com.smartdevicelink.protocol.enums.FunctionID; import com.smartdevicelink.proxy.RPCMessage; -import com.smartdevicelink.proxy.rpc.GetInteriorVehicleDataConsentResponse; import com.smartdevicelink.proxy.rpc.ReleaseInteriorVehicleDataModuleResponse; import com.smartdevicelink.test.BaseRpcTests; import com.smartdevicelink.test.JsonUtils; diff --git a/base/src/main/java/com/smartdevicelink/protocol/enums/FunctionID.java b/base/src/main/java/com/smartdevicelink/protocol/enums/FunctionID.java index 112e26bb41..e1d6e5573c 100644 --- a/base/src/main/java/com/smartdevicelink/protocol/enums/FunctionID.java +++ b/base/src/main/java/com/smartdevicelink/protocol/enums/FunctionID.java @@ -103,8 +103,8 @@ public enum FunctionID{ UNPUBLISH_APP_SERVICE(56, "UnpublishAppService"), CLOSE_APPLICATION(58, "CloseApplication"), SHOW_APP_MENU(59, "ShowAppMenu"), - GET_INTERIOR_VEHICLE_DATA_CONSENT(60, "GetInteriorVehicleDataConsent"), - RELEASE_INTERIOR_VEHICLE_MODULE(61, "ReleaseInteriorVehicleDataModule"), + GET_INTERIOR_VEHICLE_DATA_CONSENT(62, "GetInteriorVehicleDataConsent"), + RELEASE_INTERIOR_VEHICLE_MODULE(63, "ReleaseInteriorVehicleDataModule"), // NOTIFICATIONS ON_HMI_STATUS(32768, "OnHMIStatus"), diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/ButtonCapabilities.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/ButtonCapabilities.java index f5ad5df6fc..41dcb774d1 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/ButtonCapabilities.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/ButtonCapabilities.java @@ -97,7 +97,7 @@ public class ButtonCapabilities extends RPCStruct { public static final String KEY_SHORT_PRESS_AVAILABLE = "shortPressAvailable"; public static final String KEY_LONG_PRESS_AVAILABLE = "longPressAvailable"; public static final String KEY_UP_DOWN_AVAILABLE = "upDownAvailable"; - public static final String KEY_MODULE_INFO = "moduleInfo"; + public static final String KEY_MODULE_INFO = "moduleInfo"; /** * Constructs a newly allocated ButtonCapabilities object */ diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/GetInteriorVehicleDataConsent.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/GetInteriorVehicleDataConsent.java index 15f9ed2054..459aeaf053 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/GetInteriorVehicleDataConsent.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/GetInteriorVehicleDataConsent.java @@ -47,6 +47,7 @@ public void setModuleIds(List ids) { * Gets the Module Ids of this class * @return the Module Ids */ + @SuppressWarnings("unchecked") public List getModuleIds() { return (List) getObject(String.class, KEY_MODULE_ID); } diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/GetInteriorVehicleDataConsentResponse.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/GetInteriorVehicleDataConsentResponse.java index 631d2e4d94..ee610aa1e0 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/GetInteriorVehicleDataConsentResponse.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/GetInteriorVehicleDataConsentResponse.java @@ -39,6 +39,7 @@ public void setAllowances(List allowances) { * Gets the list of allowances of this class * @return the list of allowances of this class */ + @SuppressWarnings("unchecked") public List getAllowances() { return (List) getObject(Boolean.class, KEY_ALLOWED); } diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/ReleaseInteriorVehicleDataModule.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/ReleaseInteriorVehicleDataModule.java index 85555ca86b..81bee25512 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/ReleaseInteriorVehicleDataModule.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/ReleaseInteriorVehicleDataModule.java @@ -5,7 +5,6 @@ import com.smartdevicelink.proxy.rpc.enums.ModuleType; import java.util.Hashtable; -import java.util.List; public class ReleaseInteriorVehicleDataModule extends RPCRequest { public static final String KEY_MODULE_TYPE = "moduleType"; diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/SeatLocationCapability.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/SeatLocationCapability.java index db1668787f..3fc34bada4 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/SeatLocationCapability.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/SeatLocationCapability.java @@ -78,6 +78,7 @@ public void setSeats(List locations) { * Gets the seat locations of this capability * @return the seat locations */ + @SuppressWarnings("unchecked") public List getSeatLocations() { return (List) getObject(SeatLocation.class, KEY_SEATS); } From 7fae28aaf51b97819829bd3d6d5dd358be2e5cc2 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Fri, 6 Sep 2019 11:16:09 -0400 Subject: [PATCH 20/20] fix bracket --- .../com/smartdevicelink/proxy/rpc/SystemCapability.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/SystemCapability.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/SystemCapability.java index 54543034cc..2ea1867422 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/SystemCapability.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/SystemCapability.java @@ -117,10 +117,11 @@ public void setCapabilityForType(SystemCapabilityType type, Object capability){ setValue(KEY_REMOTE_CONTROL_CAPABILITY, capability); }else if(type.equals(SystemCapabilityType.APP_SERVICES)){ setValue(KEY_APP_SERVICES_CAPABILITIES, capability); - }else if(type.equals(SystemCapabilityType.SEAT_LOCATION)){ + }else if(type.equals(SystemCapabilityType.SEAT_LOCATION)){ setValue(KEY_SEAT_LOCATION_CAPABILITY, capability); - }else if(type.equals(SystemCapabilityType.DISPLAYS)){ - setValue(KEY_DISPLAY_CAPABILITIES, capability);else{ + }else if(type.equals(SystemCapabilityType.DISPLAYS)) { + setValue(KEY_DISPLAY_CAPABILITIES, capability); + }else{ return; } }