summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Grover <joeygrover@gmail.com>2018-08-24 11:41:17 -0400
committerGitHub <noreply@github.com>2018-08-24 11:41:17 -0400
commit303247aba95ac8675e8a95ad621b7e5a29c8caf6 (patch)
tree6bb17c7e4708c75b60357b3dc67e01a8ec0ddbb8
parentae07b1af97a57a5dc372503b49d9e44433fb1830 (diff)
parentf9899542658d19e889873781a28b240cc4b52070 (diff)
downloadsdl_android-303247aba95ac8675e8a95ad621b7e5a29c8caf6.tar.gz
Merge pull request #836 from smartdevicelink/feature/issue_739
Feature/issue 739 choice vr optional
-rw-r--r--sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ChoiceTests.java2
-rw-r--r--sdl_android/src/main/java/com/smartdevicelink/proxy/rpc/Choice.java52
2 files changed, 52 insertions, 2 deletions
diff --git a/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ChoiceTests.java b/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ChoiceTests.java
index e53ea8c2a..0df50f405 100644
--- a/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ChoiceTests.java
+++ b/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ChoiceTests.java
@@ -18,7 +18,7 @@ import com.smartdevicelink.test.Validator;
/**
* This is a unit test class for the SmartDeviceLink library project class :
- * {@link com.smartdevicelink.rpc.Choice}
+ * {@link com.smartdevicelink.proxy.rpc.Choice}
*/
public class ChoiceTests extends TestCase{
diff --git a/sdl_android/src/main/java/com/smartdevicelink/proxy/rpc/Choice.java b/sdl_android/src/main/java/com/smartdevicelink/proxy/rpc/Choice.java
index 989ac2997..e93196bd5 100644
--- a/sdl_android/src/main/java/com/smartdevicelink/proxy/rpc/Choice.java
+++ b/sdl_android/src/main/java/com/smartdevicelink/proxy/rpc/Choice.java
@@ -3,7 +3,9 @@ package com.smartdevicelink.proxy.rpc;
import android.support.annotation.NonNull;
import com.smartdevicelink.proxy.RPCStruct;
+import com.smartdevicelink.util.Version;
+import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
@@ -64,10 +66,12 @@ public class Choice extends RPCStruct {
public static final String KEY_VR_COMMANDS = "vrCommands";
public static final String KEY_CHOICE_ID = "choiceID";
public static final String KEY_IMAGE = "image";
+
/**
* Constructs a newly allocated Choice object
*/
public Choice() { }
+
/**
* Constructs a newly allocated Choice object indicated by the Hashtable parameter
* @param hash The Hashtable to use
@@ -75,18 +79,64 @@ public class Choice extends RPCStruct {
public Choice(Hashtable<String, Object> hash) {
super(hash);
}
+
+ /**
+ * Constructs a newly allocated Choice object
+ * @param choiceID Min: 0 Max: 65535
+ * @param menuName the menu name
+ */
+ public Choice(@NonNull Integer choiceID, @NonNull String menuName) {
+ this();
+ setChoiceID(choiceID);
+ setMenuName(menuName);
+ }
+
/**
* Constructs a newly allocated Choice object
* @param choiceID Min: 0 Max: 65535
* @param menuName the menu name
* @param vrCommands the List of vrCommands
+ *
+ * Deprecated - use {@link #Choice(Integer, String)}
*/
+ @Deprecated
public Choice(@NonNull Integer choiceID, @NonNull String menuName, @NonNull List<String> vrCommands) {
this();
setChoiceID(choiceID);
setMenuName(menuName);
setVrCommands(vrCommands);
}
+
+ /**
+ * VrCommands became optional as of RPC Spec 5.0. On legacy systems, we must still set VrCommands, as
+ * they are expected, even though the developer may not specify them. <br>
+ *
+ * Additionally, VrCommands must be unique, therefore we will use the string value of the command's ID
+ *
+ * @param rpcVersion the rpc spec version that has been negotiated. If value is null the
+ * the max value of RPC spec version this library supports should be used.
+ * @param formatParams if true, the format method will be called on subsequent params
+ */
+ @Override
+ public void format(Version rpcVersion, boolean formatParams){
+
+ if (rpcVersion == null || rpcVersion.getMajor() < 5){
+
+ // make sure there is at least one vr param
+ List<String> existingVrCommands = getVrCommands();
+
+ if (existingVrCommands == null || existingVrCommands.size() == 0) {
+ // if no commands set, set one due to a legacy head unit requirement
+ Integer choiceID = getChoiceID();
+ List<String> vrCommands = new ArrayList<>();
+ vrCommands.add(String.valueOf(choiceID));
+ setVrCommands(vrCommands);
+ }
+ }
+
+ super.format(rpcVersion, formatParams);
+ }
+
/**
* Get the application-scoped identifier that uniquely identifies this choice.
* @return choiceID Min: 0; Max: 65535
@@ -133,7 +183,7 @@ public class Choice extends RPCStruct {
* @param vrCommands the List of vrCommands
* @since SmartDeviceLink 2.0
*/
- public void setVrCommands(@NonNull List<String> vrCommands) {
+ public void setVrCommands(List<String> vrCommands) {
setValue(KEY_VR_COMMANDS, vrCommands);
}
/**