Skip to content

Commit 05b6219

Browse files
kboskinJulianKastAKalinich-LuxoftVadymLuchkoIryna Lytvynenko (GitHub)
authored
Feature/0293 oem android specific (#1604)
* [0293] - Implement Android specific part * [0293] - Fix tag name * [0293] - Fix hardware version * [0293] - Fix supported_vehicle_type.xml * [0293] - Applied logs * [0293] - Remove the check * [0293] - Remove the check * [0293] - Remove the check * [0293] - Remove the check * [0293] - Handle NPE * [0293] - Add mocks * [0293] - Update the deserialization function * [0293] - Update the deserialization function, fix shared preferences * [0293] - Update the logic * [0293] - Update parsing method * [0293] - Migrate to separate class * [0293] - Fix tests * [0293] - Fix tests * [0293] - Fix tests * [0293] - Fix comments * [0293] - Rename variables * [0293] - Apply latest patch * [0293] - Fix comments * Rollbacking the patch This reverts commit 23bc6d5. * Revert "[0293]" This reverts commit a77b24c. * [0293] - Update according to the latest revision * [0293] - Remove javadoc * [0293] - Align variables with Livio proposal * Apply suggestions from code review [0293] - Fix pr comments Co-authored-by: Julian Kast <Julian.kast@livio.io> * [0296] - Fix pr comments * [0296] - Fix pr comments * [0293] - Fix pr comments * [0293] - Fix PR comments * [0293] - Fix javaSE project compilation * Apply suggestions from code review Co-authored-by: Julian Kast <Julian.kast@livio.io> * [0293] - Fix pr comments * [0293] - Fix protocol version * [0293] - Fix protocol version in header * Increment ROUTER_SERVICE_VERSION_NUMBER * fixup! Increment ROUTER_SERVICE_VERSION_NUMBER * Fix crash in broadcast receiver Added missing device null check * Add missing vehicle type check * Update onSystemInfoReceived logic * Update old router service check * Fix foreground service icon for unsupported app * Add vehicle type check to SDL receiver Also, common functions were moved out to AndroidTools class * Include vehicle type into the ping intent In this case corresponding SDL receiver will be able to check if vehicle type is supported by specific OEM app or not * Fix extracting metadata from manifest * Fix initial protocol version for StartService SDL core will respond with negotiated version: Core with V1-4 will respond with max own supported version and won't include VI into ack bson parameters Core with V5+ will respond with negotiated protocol version and include VI into ack bson parameters if core supports it * Replace broadcast receiver with callback * fix notifications on disconnect * fix connection after disconnect * replace ISessionListener * Revert changes in the SdlManagerListener * Remove changes in the 'HelloSdlApp' * Fix logic in the deserialization vehicle method * Update after comment discussion * Update after comment discussion * Revert changes * Remove ISessionListener and lifecycle onError call before onClose * Update unit test and SdlService * Fix shutting down the RPC service * Add a version check * Add some Java Docs and apply suggested changes * Fix saving vehicle type * Fix Java Docs * Fix Java Docs * Fix some potential NPE * Refactor some names * Refactor to more generic approach * Remove vehicleType param from callback * Add return statement * Code Review Fixes * Code Review Fixes * Fix some potential NPE * Fix checkIfVehicleSupported Co-authored-by: kboskin <kboskin> Co-authored-by: Julian Kast <Julian.kast@livio.io> Co-authored-by: Andrii Kalinich <AKalinich@luxoft.com> Co-authored-by: Vadym Luchko (gitHub) <vluchko@luxoft.com> Co-authored-by: Iryna Lytvynenko (GitHub) <ILytvynenko@luxoft.com> Co-authored-by: Yaroslav Lutsenko (GitHub) <yaroslav.lutsenko@dxc.com> Co-authored-by: Yaroslav Lutsenko (GitHub) <86004378+YaroslavLutsenko@users.noreply.github.com>
1 parent bfb0350 commit 05b6219

18 files changed

Lines changed: 815 additions & 55 deletions

File tree

android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/VehicleTypeTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99
import org.json.JSONException;
1010
import org.json.JSONObject;
11+
import org.junit.Assert;
1112

13+
import java.util.HashMap;
14+
import java.util.Hashtable;
1215
import java.util.Iterator;
1316

1417
public class VehicleTypeTest extends TestCase {
@@ -72,4 +75,15 @@ public void testJson() {
7275
fail(TestValues.JSON_FAIL);
7376
}
7477
}
78+
79+
public void testHashMapConstructor() {
80+
Hashtable<String, Object> store = msg.getStore();
81+
HashMap<String, Object> hashMap = new HashMap(store);
82+
VehicleType type = new VehicleType(hashMap);
83+
84+
Assert.assertEquals(type.getMake(), msg.getMake());
85+
Assert.assertEquals(type.getModel(), msg.getModel());
86+
Assert.assertEquals(type.getModelYear(), msg.getModelYear());
87+
Assert.assertEquals(type.getTrim(), msg.getTrim());
88+
}
7589
}

android/sdl_android/src/androidTest/java/com/smartdevicelink/test/util/SdlAppInfoTests.java

Lines changed: 112 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,21 @@
4242
import androidx.test.ext.junit.runners.AndroidJUnit4;
4343

4444
import com.smartdevicelink.R;
45+
import com.smartdevicelink.proxy.rpc.VehicleType;
46+
import com.smartdevicelink.test.TestValues;
4547
import com.smartdevicelink.util.SdlAppInfo;
4648

4749
import org.junit.Before;
4850
import org.junit.Test;
4951
import org.junit.runner.RunWith;
5052

5153
import java.util.ArrayList;
54+
import java.util.Arrays;
5255
import java.util.Collections;
5356
import java.util.List;
5457

5558
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
59+
import static junit.framework.Assert.assertTrue;
5660
import static junit.framework.TestCase.assertEquals;
5761
import static junit.framework.TestCase.assertFalse;
5862
import static junit.framework.TestCase.assertNotNull;
@@ -85,7 +89,7 @@ public void setUp() throws Exception {
8589
@Test
8690
public void testConstructorWithDefaultData() {
8791

88-
SdlAppInfo info = new SdlAppInfo(defaultResolveInfo, defaultPackageInfo);
92+
SdlAppInfo info = new SdlAppInfo(defaultResolveInfo, defaultPackageInfo, context);
8993

9094
assertNotNull(info);
9195

@@ -105,10 +109,10 @@ public void testConstructorWithDefaultData() {
105109
*/
106110
@Test
107111
public void testCompareVersion() {
108-
SdlAppInfo defaultInfo = new SdlAppInfo(defaultResolveInfo, defaultPackageInfo);
112+
SdlAppInfo defaultInfo = new SdlAppInfo(defaultResolveInfo, defaultPackageInfo, context);
109113

110114
int newVersion = context.getResources().getInteger(R.integer.sdl_router_service_version_value) + 1;
111-
SdlAppInfo testInfo = new SdlAppInfo(createResolveInfo(newVersion, "com.smartdevicelink.test2", "com.smartdevicelink.test2.SdlRouterService", false), defaultPackageInfo);
115+
SdlAppInfo testInfo = new SdlAppInfo(createResolveInfo(newVersion, "com.smartdevicelink.test2", "com.smartdevicelink.test2.SdlRouterService", false), defaultPackageInfo, context);
112116

113117
List<SdlAppInfo> infos = new ArrayList<>();
114118
infos.add(defaultInfo);
@@ -126,10 +130,10 @@ public void testCompareVersion() {
126130
*/
127131
@Test
128132
public void testCompareVersionAndCustom() {
129-
SdlAppInfo defaultInfo = new SdlAppInfo(defaultResolveInfo, defaultPackageInfo);
133+
SdlAppInfo defaultInfo = new SdlAppInfo(defaultResolveInfo, defaultPackageInfo, context);
130134

131135
int newVersion = context.getResources().getInteger(R.integer.sdl_router_service_version_value) + 1;
132-
SdlAppInfo testInfo = new SdlAppInfo(createResolveInfo(newVersion, "com.smartdevicelink.test2", "com.smartdevicelink.test2.SdlRouterService", true), defaultPackageInfo);
136+
SdlAppInfo testInfo = new SdlAppInfo(createResolveInfo(newVersion, "com.smartdevicelink.test2", "com.smartdevicelink.test2.SdlRouterService", true), defaultPackageInfo, context);
133137

134138
List<SdlAppInfo> infos = new ArrayList<>();
135139
infos.add(defaultInfo);
@@ -147,12 +151,12 @@ public void testCompareVersionAndCustom() {
147151
*/
148152
@Test
149153
public void testCompareUpdatedTime() {
150-
SdlAppInfo defaultInfo = new SdlAppInfo(defaultResolveInfo, defaultPackageInfo);
154+
SdlAppInfo defaultInfo = new SdlAppInfo(defaultResolveInfo, defaultPackageInfo, context);
151155

152156
PackageInfo packageInfo = new PackageInfo();
153157
packageInfo.firstInstallTime = defaultPackageInfo.firstInstallTime;
154158
packageInfo.lastUpdateTime = defaultPackageInfo.lastUpdateTime + 500;
155-
SdlAppInfo testInfo = new SdlAppInfo(defaultResolveInfo, packageInfo);
159+
SdlAppInfo testInfo = new SdlAppInfo(defaultResolveInfo, packageInfo, context);
156160

157161
List<SdlAppInfo> infos = new ArrayList<>();
158162
infos.add(defaultInfo);
@@ -179,5 +183,106 @@ public ResolveInfo createResolveInfo(int routerServiceVersion, String packageNam
179183
return info;
180184
}
181185

186+
@Test
187+
public void testDeserializeVehicleInfo() {
188+
VehicleType type = new VehicleType();
189+
type.setMake("SDL");
190+
type.setModel("Car");
191+
type.setModelYear("2019");
192+
type.setTrim("GT");
193+
List<VehicleType> deserializedList = SdlAppInfo.deserializeSupportedVehicles(getInstrumentation().getContext().getResources().getXml(com.smartdevicelink.test.R.xml.supported_vehicle_type));
194+
assertTrue(deserializedList.contains(type));
195+
assertEquals(1, deserializedList.size());
196+
}
197+
198+
@Test
199+
public void testVehicleTypeSupported() {
200+
// tests check with all params
201+
VehicleType type1 = new VehicleType();
202+
type1.setMake(TestValues.GENERAL_STRING);
203+
type1.setModel(TestValues.GENERAL_STRING);
204+
type1.setMake(TestValues.GENERAL_STRING);
205+
type1.setTrim(TestValues.GENERAL_STRING);
206+
207+
VehicleType type2 = new VehicleType();
208+
type2.setMake(TestValues.GENERAL_STRING);
209+
type2.setModel(TestValues.GENERAL_STRING);
210+
type2.setModelYear(TestValues.GENERAL_INTEGER.toString());
211+
type2.setTrim(TestValues.GENERAL_STRING);
212+
213+
List<VehicleType> supportedVehicleList = Arrays.asList(type1, type2);
214+
assertTrue(SdlAppInfo.checkIfVehicleSupported(supportedVehicleList, type2));
215+
216+
// tests check with not all params in connectedVehicle
217+
VehicleType connectedVehicle = new VehicleType();
218+
219+
// make only param
220+
connectedVehicle.setMake(TestValues.GENERAL_STRING);
221+
assertTrue(SdlAppInfo.checkIfVehicleSupported(supportedVehicleList, connectedVehicle));
222+
223+
// make and model params
224+
connectedVehicle.setModel(TestValues.GENERAL_STRING);
225+
assertTrue(SdlAppInfo.checkIfVehicleSupported(supportedVehicleList, connectedVehicle));
226+
227+
// make, model and year params
228+
connectedVehicle.setModelYear(TestValues.GENERAL_STRING);
229+
assertTrue(SdlAppInfo.checkIfVehicleSupported(supportedVehicleList, connectedVehicle));
230+
231+
// make, model and trim params
232+
connectedVehicle.setModelYear(null);
233+
connectedVehicle.setTrim(TestValues.GENERAL_STRING);
234+
assertTrue(SdlAppInfo.checkIfVehicleSupported(supportedVehicleList, connectedVehicle));
235+
236+
// tests check with not all params in supportedVehicle
237+
VehicleType supportedVehicle = new VehicleType();
238+
supportedVehicle.setMake(TestValues.GENERAL_STRING);
239+
240+
// make param only
241+
assertTrue(SdlAppInfo.checkIfVehicleSupported(Collections.singletonList(supportedVehicle), connectedVehicle));
242+
243+
// make and model params
244+
supportedVehicle.setModel(TestValues.GENERAL_STRING);
245+
assertTrue(SdlAppInfo.checkIfVehicleSupported(Collections.singletonList(supportedVehicle), connectedVehicle));
246+
247+
// make, model and trim params
248+
supportedVehicle.setTrim(TestValues.GENERAL_STRING);
249+
assertTrue(SdlAppInfo.checkIfVehicleSupported(Collections.singletonList(supportedVehicle), connectedVehicle));
250+
251+
// make, model and trim params
252+
supportedVehicle.setTrim(TestValues.GENERAL_STRING);
253+
assertTrue(SdlAppInfo.checkIfVehicleSupported(Collections.singletonList(supportedVehicle), connectedVehicle));
254+
255+
// make, model and trim params
256+
connectedVehicle.setTrim(null);
257+
connectedVehicle.setModelYear(TestValues.GENERAL_INTEGER.toString());
258+
supportedVehicle.setModelYear(TestValues.GENERAL_INTEGER.toString());
259+
assertTrue(SdlAppInfo.checkIfVehicleSupported(Collections.singletonList(supportedVehicle), connectedVehicle));
260+
}
261+
262+
@Test
263+
public void testVehicleTypeNotSupported() {
264+
VehicleType type1 = new VehicleType();
265+
266+
type1.setModel(TestValues.GENERAL_STRING);
267+
type1.setMake(TestValues.GENERAL_INTEGER.toString());
268+
type1.setTrim(TestValues.GENERAL_STRING);
269+
type1.setModelYear(TestValues.GENERAL_STRING);
270+
271+
VehicleType type2 = new VehicleType();
272+
273+
type2.setModel(TestValues.GENERAL_STRING);
274+
type2.setMake(TestValues.GENERAL_INTEGER.toString());
275+
type2.setTrim(TestValues.GENERAL_STRING);
276+
type2.setModelYear(TestValues.GENERAL_STRING);
277+
278+
VehicleType type3 = new VehicleType();
279+
280+
type3.setModel(TestValues.GENERAL_STRING);
281+
type3.setMake(TestValues.GENERAL_STRING);
282+
type3.setTrim(TestValues.GENERAL_STRING);
283+
type3.setModelYear(TestValues.GENERAL_INTEGER.toString());
284+
285+
assertFalse(SdlAppInfo.checkIfVehicleSupported(Arrays.asList(type1, type2), type3));
286+
}
182287

183288
}

android/sdl_android/src/androidTest/java/com/smartdevicelink/test/utl/AndroidToolsTests.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
package com.smartdevicelink.test.utl;
22

33
import android.content.ComponentName;
4+
import android.content.Context;
5+
import android.content.SharedPreferences;
46

57
import androidx.test.ext.junit.runners.AndroidJUnit4;
68

9+
import com.smartdevicelink.proxy.rpc.VehicleType;
710
import com.smartdevicelink.util.AndroidTools;
811

912
import junit.framework.Assert;
1013

14+
import org.json.JSONException;
1115
import org.junit.Test;
1216
import org.junit.runner.RunWith;
17+
import org.mockito.Mockito;
1318

1419
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
20+
import static org.mockito.ArgumentMatchers.anyInt;
21+
import static org.mockito.ArgumentMatchers.anyString;
22+
import static org.mockito.Mockito.mock;
23+
import static org.mockito.Mockito.when;
1524

1625
@RunWith(AndroidJUnit4.class)
1726
public class AndroidToolsTests {
@@ -39,4 +48,32 @@ public void testIsServiceExportedNull() {
3948

4049
}
4150

51+
@Test
52+
public void testVehicleTypeSave() throws JSONException {
53+
Context mMockContext = mock(Context.class);
54+
VehicleType mMockVehicleType = new VehicleType();
55+
String mAddress = "1234";
56+
57+
mMockVehicleType.setMake("Ford");
58+
mMockVehicleType.setTrim("GT");
59+
mMockVehicleType.setModel("Mustang");
60+
mMockVehicleType.setModelYear("2019");
61+
62+
SharedPreferences.Editor editor = mock(SharedPreferences.Editor.class);
63+
when(editor.commit()).thenReturn(true);
64+
65+
SharedPreferences sharedPrefs = Mockito.mock(SharedPreferences.class);
66+
when(mMockContext.getSharedPreferences(anyString(), anyInt())).thenReturn(sharedPrefs);
67+
when(sharedPrefs.edit()).thenReturn(editor);
68+
when(sharedPrefs.getString(mAddress, null)).thenReturn(mMockVehicleType.serializeJSON().toString());
69+
70+
AndroidTools.saveVehicleType(mMockContext, mMockVehicleType, mAddress);
71+
VehicleType type = new VehicleType(AndroidTools.getVehicleTypeFromPrefs(mMockContext, mAddress));
72+
73+
org.junit.Assert.assertEquals(type.getMake(), mMockVehicleType.getMake());
74+
org.junit.Assert.assertEquals(type.getModel(), mMockVehicleType.getModel());
75+
org.junit.Assert.assertEquals(type.getModelYear(), mMockVehicleType.getModelYear());
76+
org.junit.Assert.assertEquals(type.getTrim(), mMockVehicleType.getTrim());
77+
}
78+
4279
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resource>
3+
<vehicle-type
4+
make="SDL"
5+
model="Car"
6+
modelYear="2019"
7+
trim="GT" />
8+
9+
<vehicle-type
10+
make="SDL2"
11+
modelYear="2019" />
12+
</resource>

android/sdl_android/src/main/java/com/smartdevicelink/managers/lifecycle/LifecycleManager.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import com.smartdevicelink.exception.SdlExceptionCause;
4141
import com.smartdevicelink.protocol.ISdlServiceListener;
4242
import com.smartdevicelink.protocol.enums.SessionType;
43+
import com.smartdevicelink.proxy.rpc.VehicleType;
4344
import com.smartdevicelink.proxy.rpc.enums.SdlDisconnectedReason;
4445
import com.smartdevicelink.proxy.rpc.enums.SystemCapabilityType;
4546
import com.smartdevicelink.security.SdlSecurityBase;
@@ -49,9 +50,12 @@
4950
import com.smartdevicelink.transport.MultiplexTransportConfig;
5051
import com.smartdevicelink.transport.TCPTransportConfig;
5152
import com.smartdevicelink.transport.enums.TransportType;
53+
import com.smartdevicelink.transport.utl.TransportRecord;
54+
import com.smartdevicelink.util.AndroidTools;
5255
import com.smartdevicelink.util.DebugTool;
5356

5457
import java.lang.ref.WeakReference;
58+
import java.util.List;
5559

5660
/**
5761
* The lifecycle manager creates a central point for all SDL session logic to converge. It should only be used by
@@ -98,6 +102,29 @@ void cycle(SdlDisconnectedReason disconnectedReason) {
98102
}
99103
}
100104

105+
@Override
106+
void saveVehicleType(String address, VehicleType type) {
107+
AndroidTools.saveVehicleType(contextWeakReference.get(), type, address);
108+
}
109+
110+
@Override
111+
void saveVehicleType(List<TransportRecord> activeTransports, VehicleType type) {
112+
if (activeTransports == null || activeTransports.isEmpty() || type == null) {
113+
DebugTool.logWarning(TAG, "Unable to save vehicle type");
114+
return;
115+
}
116+
117+
for (TransportRecord record: activeTransports) {
118+
if (record.getType() == TransportType.BLUETOOTH) {
119+
String address = record.getAddress();
120+
if (address != null && !address.isEmpty()) {
121+
saveVehicleType(address, type);
122+
}
123+
break;
124+
}
125+
}
126+
}
127+
101128
@RestrictTo(RestrictTo.Scope.LIBRARY)
102129
public void setContext(Context context) {
103130
this.contextWeakReference = new WeakReference<>(context);

0 commit comments

Comments
 (0)