Skip to content

Commit 50ce223

Browse files
authored
Merge pull request #1220 from smartdevicelink/feature/appinfo_rai
Add AppInfo to RegisterAppInterface RPC
2 parents e419e52 + 96ddf17 commit 50ce223

8 files changed

Lines changed: 295 additions & 1 deletion

File tree

android/sdl_android/src/androidTest/assets/json/RegisterAppInterface.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
"carrier":"nobody",
3030
"maxNumberRFCOMMPorts":2
3131
},
32+
"appInfo":{
33+
"appDisplayName":"Test",
34+
"appBundleID":"com.sample.test",
35+
"appVersion":"1.0",
36+
"appIcon":"icon.png"
37+
},
3238
"appName":"Dumb app",
3339
"ngnMediaScreenAppName":"DA",
3440
"isMediaApplication":true,

android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.smartdevicelink.protocol.enums.FunctionID;
1717
import com.smartdevicelink.proxy.SdlProxyBase;
1818
import com.smartdevicelink.proxy.TTSChunkFactory;
19+
import com.smartdevicelink.proxy.rpc.AppInfo;
1920
import com.smartdevicelink.proxy.rpc.AppServiceCapability;
2021
import com.smartdevicelink.proxy.rpc.AppServiceData;
2122
import com.smartdevicelink.proxy.rpc.AppServiceManifest;
@@ -262,6 +263,7 @@ public class Test {
262263
public static final VrHelpItem GENERAL_VRHELPITEM = new VrHelpItem();
263264
public static final ImageField GENERAL_IMAGEFIELD = new ImageField();
264265
public static final DeviceInfo GENERAL_DEVICEINFO = new DeviceInfo();
266+
public static final AppInfo GENERAL_APPINFO = new AppInfo();
265267
public static final LayoutMode GENERAL_LAYOUTMODE = LayoutMode.LIST_ONLY;
266268
public static final MenuParams GENERAL_MENUPARAMS = new MenuParams();
267269
public static final SoftButton GENERAL_SOFTBUTTON = new SoftButton();
@@ -535,6 +537,7 @@ public void onVoiceCommandSelected() {
535537
public static final JSONObject JSON_SOFTBUTTON = new JSONObject();
536538
public static final JSONObject JSON_MENUPARAMS = new JSONObject();
537539
public static final JSONObject JSON_DEVICEINFO = new JSONObject();
540+
public static final JSONObject JSON_APPINFO = new JSONObject();
538541
public static final JSONObject JSON_VRHELPITEM = new JSONObject();
539542
public static final JSONObject JSON_SCREENPARAMS = new JSONObject();
540543
public static final JSONObject JSON_SDLMSGVERSION = new JSONObject();

android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Validator.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2598,6 +2598,24 @@ public static boolean validateDeviceInfo (DeviceInfo item1, DeviceInfo item2) {
25982598
return true;
25992599
}
26002600

2601+
public static boolean validateAppInfo (AppInfo item1, AppInfo item2) {
2602+
if (item1 == null) {
2603+
return ( item2 == null );
2604+
}
2605+
if (item2 == null) {
2606+
return ( item1 == null );
2607+
}
2608+
2609+
if (item1.getAppDisplayName() != item1.getAppDisplayName()
2610+
|| item1.getAppBundleID() != item2.getAppBundleID()
2611+
|| item1.getAppVersion() != item2.getAppVersion()
2612+
|| item1.getAppIcon() != item2.getAppIcon()) {
2613+
return false;
2614+
}
2615+
2616+
return true;
2617+
}
2618+
26012619
public static boolean validateTemplateColorScheme (TemplateColorScheme item1, TemplateColorScheme item2) {
26022620
if (item1 == null) {
26032621
return ( item2 == null );

android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/RPCConstructorsTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private Map<String, List<Parameter>> getRPCMandatoryParamsMap(String fileName) {
8888
rpcName = "OasisAddress";
8989
} else if(rpcName.equals("ShowConstantTBT")) {
9090
rpcName = "ShowConstantTbt";
91-
} else if (rpcName.equals("EncodedSyncPData") || rpcName.equals("OnEncodedSyncPData") || rpcName.equals("EncodedSyncPDataResponse") || rpcName.equals("AppInfo")){
91+
} else if (rpcName.equals("EncodedSyncPData") || rpcName.equals("OnEncodedSyncPData") || rpcName.equals("EncodedSyncPDataResponse")){
9292
ignoreRPC = true;
9393
}
9494
// -------------------------------------------------------------------------------------------------------------
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Copyright (c) 2019 Livio, Inc.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* Redistributions of source code must retain the above copyright notice, this
9+
* list of conditions and the following disclaimer.
10+
*
11+
* Redistributions in binary form must reproduce the above copyright notice,
12+
* this list of conditions and the following
13+
* disclaimer in the documentation and/or other materials provided with the
14+
* distribution.
15+
*
16+
* Neither the name of the Livio Inc. nor the names of its contributors
17+
* may be used to endorse or promote products derived from this software
18+
* without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30+
* POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
33+
package com.smartdevicelink.test.rpc.datatypes;
34+
35+
import com.smartdevicelink.proxy.rpc.AppInfo;
36+
import com.smartdevicelink.test.JsonUtils;
37+
import com.smartdevicelink.test.Test;
38+
39+
import junit.framework.TestCase;
40+
41+
import org.json.JSONException;
42+
import org.json.JSONObject;
43+
44+
import java.util.Iterator;
45+
46+
/**
47+
* This is a unit test class for the SmartDeviceLink library project class :
48+
* {@link com.smartdevicelink.proxy.rpc.AppInfo}
49+
*/
50+
public class AppInfoTests extends TestCase {
51+
52+
private AppInfo msg;
53+
54+
@Override
55+
public void setUp() {
56+
57+
msg = new AppInfo();
58+
msg.setAppDisplayName(Test.GENERAL_STRING);
59+
msg.setAppBundleID(Test.GENERAL_STRING);
60+
msg.setAppVersion(Test.GENERAL_STRING);
61+
msg.setAppIcon(Test.GENERAL_STRING);
62+
}
63+
64+
/**
65+
* Tests the expected values of the RPC message.
66+
*/
67+
public void testRpcValues () {
68+
// Test Values
69+
String appDisplayName = msg.getAppDisplayName();
70+
String appBundleID = msg.getAppBundleID();
71+
String appVersion = msg.getAppVersion();
72+
String appIcon = msg.getAppIcon();
73+
74+
// Valid Tests
75+
assertEquals(Test.GENERAL_STRING, appDisplayName);
76+
assertEquals(Test.GENERAL_STRING, appBundleID);
77+
assertEquals(Test.GENERAL_STRING, appVersion);
78+
assertEquals(Test.GENERAL_STRING, appIcon);
79+
80+
// Invalid/Null Tests
81+
AppInfo msg = new AppInfo();
82+
assertNotNull(Test.NOT_NULL, msg);
83+
84+
assertNull(Test.NULL, msg.getAppDisplayName());
85+
assertNull(Test.NULL, msg.getAppBundleID());
86+
assertNull(Test.NULL, msg.getAppVersion());
87+
assertNull(Test.NULL, msg.getAppIcon());
88+
}
89+
90+
public void testJson(){
91+
JSONObject reference = new JSONObject();
92+
93+
try{
94+
reference.put(AppInfo.KEY_APP_DISPLAY_NAME, Test.GENERAL_STRING);
95+
reference.put(AppInfo.KEY_APP_BUNDLE_ID, Test.GENERAL_STRING);
96+
reference.put(AppInfo.KEY_APP_VERSION, Test.GENERAL_STRING);
97+
reference.put(AppInfo.KEY_APP_ICON, Test.GENERAL_STRING);
98+
99+
JSONObject underTest = msg.serializeJSON();
100+
assertEquals(Test.MATCH, reference.length(), underTest.length());
101+
102+
Iterator<?> iterator = reference.keys();
103+
while(iterator.hasNext()){
104+
String key = (String) iterator.next();
105+
assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key));
106+
}
107+
} catch(JSONException e){
108+
fail(Test.JSON_FAIL);
109+
}
110+
}
111+
112+
}

android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/RegisterAppInterfaceTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.smartdevicelink.marshal.JsonRPCMarshaller;
44
import com.smartdevicelink.protocol.enums.FunctionID;
55
import com.smartdevicelink.proxy.RPCMessage;
6+
import com.smartdevicelink.proxy.rpc.AppInfo;
67
import com.smartdevicelink.proxy.rpc.DeviceInfo;
78
import com.smartdevicelink.proxy.rpc.RegisterAppInterface;
89
import com.smartdevicelink.proxy.rpc.SdlMsgVersion;
@@ -46,6 +47,7 @@ protected RPCMessage createMessage() {
4647
msg.setAppHMIType(Test.GENERAL_APPHMITYPE_LIST);
4748
msg.setIsMediaApplication(Test.GENERAL_BOOLEAN);
4849
msg.setDeviceInfo(Test.GENERAL_DEVICEINFO);
50+
msg.setAppInfo(Test.GENERAL_APPINFO);
4951
msg.setDayColorScheme(Test.GENERAL_DAYCOLORSCHEME);
5052
msg.setNightColorScheme(Test.GENERAL_NIGHTCOLORSCHEME);
5153

@@ -80,6 +82,7 @@ protected JSONObject getExpectedParameters(int sdlVersion) {
8082
result.put(RegisterAppInterface.KEY_APP_HMI_TYPE, JsonUtils.createJsonArrayOfJsonNames(Test.GENERAL_APPHMITYPE_LIST, SDL_VERSION_UNDER_TEST));
8183
result.put(RegisterAppInterface.KEY_IS_MEDIA_APPLICATION, Test.GENERAL_BOOLEAN);
8284
result.put(RegisterAppInterface.KEY_DEVICE_INFO, Test.JSON_DEVICEINFO);
85+
result.put(RegisterAppInterface.KEY_APP_INFO, Test.JSON_APPINFO);
8386
result.put(RegisterAppInterface.KEY_DAY_COLOR_SCHEME, Test.JSON_DAYCOLORSCHEME);
8487
result.put(RegisterAppInterface.KEY_NIGHT_COLOR_SCHEME, Test.JSON_NIGHTCOLORSCHEME);
8588
} catch (JSONException e) {
@@ -107,6 +110,7 @@ public void testRpcValues () {
107110
List<AppHMIType> testApps = ( (RegisterAppInterface) msg).getAppHMIType();
108111
Boolean testMedia = ( (RegisterAppInterface) msg).getIsMediaApplication();
109112
DeviceInfo testDeviceInfo = ( (RegisterAppInterface) msg).getDeviceInfo();
113+
AppInfo testAppInfo = ( (RegisterAppInterface) msg).getAppInfo();
110114
TemplateColorScheme testDayColorScheme = ( (RegisterAppInterface) msg).getDayColorScheme();
111115
TemplateColorScheme testNightColorScheme = ( (RegisterAppInterface) msg).getNightColorScheme();
112116

@@ -124,6 +128,7 @@ public void testRpcValues () {
124128
assertEquals(Test.MATCH, Test.GENERAL_APPHMITYPE_LIST, testApps);
125129
assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, testMedia);
126130
assertTrue(Test.TRUE, Validator.validateDeviceInfo(Test.GENERAL_DEVICEINFO, testDeviceInfo));
131+
assertTrue(Test.TRUE, Validator.validateAppInfo(Test.GENERAL_APPINFO, testAppInfo));
127132
assertTrue(Test.TRUE, Validator.validateTemplateColorScheme(Test.GENERAL_DAYCOLORSCHEME, testDayColorScheme));
128133
assertTrue(Test.TRUE, Validator.validateTemplateColorScheme(Test.GENERAL_NIGHTCOLORSCHEME, testNightColorScheme));
129134

@@ -145,6 +150,7 @@ public void testRpcValues () {
145150
assertNull(Test.NULL, msg.getAppHMIType());
146151
assertNull(Test.NULL, msg.getIsMediaApplication());
147152
assertNull(Test.NULL, msg.getDeviceInfo());
153+
assertNull(Test.NULL, msg.getAppInfo());
148154
assertNull(Test.NULL, msg.getDayColorScheme());
149155
assertNull(Test.NULL, msg.getNightColorScheme());
150156
}
@@ -193,6 +199,10 @@ public void testJsonConstructor () {
193199
assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, RegisterAppInterface.KEY_NGN_MEDIA_SCREEN_APP_NAME), cmd.getNgnMediaScreenAppName());
194200
assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, RegisterAppInterface.KEY_IS_MEDIA_APPLICATION), cmd.getIsMediaApplication());
195201

202+
JSONObject appInfoObj = JsonUtils.readJsonObjectFromJsonObject(parameters, RegisterAppInterface.KEY_APP_INFO);
203+
AppInfo appInfo = new AppInfo(JsonRPCMarshaller.deserializeJSONObject(appInfoObj));
204+
assertTrue(Test.TRUE, Validator.validateAppInfo(appInfo, cmd.getAppInfo()));
205+
196206
List<String> vrSynonymsList = JsonUtils.readStringListFromJsonObject(parameters, RegisterAppInterface.KEY_VR_SYNONYMS);
197207
List<String> testSynonymsList = cmd.getVrSynonyms();
198208
assertEquals(Test.MATCH, vrSynonymsList.size(), testSynonymsList.size());
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
* Copyright (c) 2019 Livio, Inc.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* Redistributions of source code must retain the above copyright notice, this
9+
* list of conditions and the following disclaimer.
10+
*
11+
* Redistributions in binary form must reproduce the above copyright notice,
12+
* this list of conditions and the following
13+
* disclaimer in the documentation and/or other materials provided with the
14+
* distribution.
15+
*
16+
* Neither the name of the Livio Inc. nor the names of its contributors
17+
* may be used to endorse or promote products derived from this software
18+
* without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30+
* POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
package com.smartdevicelink.proxy.rpc;
33+
34+
import android.support.annotation.NonNull;
35+
36+
import com.smartdevicelink.proxy.RPCStruct;
37+
38+
import java.util.Hashtable;
39+
40+
public class AppInfo extends RPCStruct {
41+
42+
public static final String KEY_APP_DISPLAY_NAME = "appDisplayName";
43+
public static final String KEY_APP_BUNDLE_ID = "appBundleID";
44+
public static final String KEY_APP_VERSION = "appVersion";
45+
public static final String KEY_APP_ICON = "appIcon";
46+
47+
/**
48+
* Constructs a new AppInfo object
49+
*/
50+
public AppInfo() { }
51+
52+
/**
53+
* Constructs a new AppInfo object indicated by the Hashtable parameter
54+
* @param hash The Hashtable to use
55+
*/
56+
public AppInfo(Hashtable<String, Object> hash) {
57+
super(hash);
58+
}
59+
60+
/**
61+
* Constructs a new AppInfo object
62+
* @param appDisplayName - name displayed for the mobile application on the mobile device
63+
* @param appBundleID - package name of the application.
64+
* @param appVersion - build version number of this particular mobile app.
65+
*/
66+
public AppInfo(@NonNull String appDisplayName, String appBundleID, String appVersion){
67+
this();
68+
setAppDisplayName(appDisplayName);
69+
setAppBundleID(appBundleID);
70+
setAppVersion(appVersion);
71+
}
72+
73+
/** Sets the name displayed for the mobile application on the mobile device (can differ from the app name set in the initial RAI request).
74+
* @param appDisplayName - name displayed for the mobile application on the mobile device.
75+
*/
76+
public void setAppDisplayName(@NonNull String appDisplayName) {
77+
setValue(KEY_APP_DISPLAY_NAME, appDisplayName);
78+
}
79+
80+
/** Gets the name displayed for the mobile application on the mobile device (can differ from the app name set in the initial RAI request).
81+
* @return appDisplayName - name displayed for the mobile application on the mobile device.
82+
*/
83+
public String getAppDisplayName() {
84+
return getString(KEY_APP_DISPLAY_NAME);
85+
}
86+
87+
/** Sets package name of the Android application. This supports App Launch strategies for each platform.
88+
* @param appBundleID - package name of the application
89+
*/
90+
public void setAppBundleID(@NonNull String appBundleID) {
91+
setValue(KEY_APP_BUNDLE_ID, appBundleID);
92+
}
93+
94+
/** Gets package name of the Android application. This supports App Launch strategies for each platform.
95+
* @return appBundleID - package name of the application.
96+
*/
97+
public String getAppBundleID() {
98+
return getString(KEY_APP_BUNDLE_ID);
99+
}
100+
101+
/** Sets build version number of this particular mobile app.
102+
* @param appVersion - build version number of this particular mobile app.
103+
*/
104+
public void setAppVersion(@NonNull String appVersion) {
105+
setValue(KEY_APP_VERSION, appVersion);
106+
}
107+
108+
/** Gets build version number of this particular mobile app.
109+
* @return appVersion - build version number of this particular mobile app.
110+
*/
111+
public String getAppVersion() {
112+
return getString(KEY_APP_VERSION);
113+
}
114+
115+
/** Sets file reference to the icon utilized by this app (simplifies the process of setting an app icon during app registration).
116+
* @param appIcon - file reference to the icon utilized by this app
117+
*/
118+
public void setAppIcon(String appIcon) {
119+
setValue(KEY_APP_ICON, appIcon);
120+
}
121+
122+
/** Gets build version number of this particular mobile app.
123+
* @return appIcon - build version number of this particular mobile app.
124+
*/
125+
public String getAppIcon() {
126+
return getString(KEY_APP_ICON);
127+
}
128+
}

0 commit comments

Comments
 (0)