Skip to content

Commit 3ddcd58

Browse files
committed
Merge branch 'develop' of https://github.com/smartdevicelink/sdl_android into feature/sdl_0301_sdl_device_listener
2 parents 01a47b1 + 6b52e38 commit 3ddcd58

98 files changed

Lines changed: 4008 additions & 3787 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/android.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
script: ./android/gradlew -p ./android :sdl_android:connectedCheck
2626

2727
- name: Hello Sdl Android Tests
28-
run: ./android/gradlew -p ./android :hello_sdl_android:build
28+
run: ./android/gradlew -p ./android/hello_sdl_android test
2929

3030
- name: Sdl JavaSE Tests
3131
run: ./javaSE/gradlew -p ./javaSE test

android/hello_sdl_android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 28
4+
compileSdkVersion 29
55
defaultConfig {
66
applicationId "com.sdl.hellosdlandroid"
77
minSdkVersion 14

android/hello_sdl_android/src/main/AndroidManifest.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,15 @@
3939
android:resource="@xml/accessory_filter" />
4040
</activity>
4141

42-
<service android:name="com.sdl.hellosdlandroid.SdlService" >
42+
<service
43+
android:name="com.sdl.hellosdlandroid.SdlService"
44+
android:foregroundServiceType="connectedDevice">
4345
</service>
4446
<service
4547
android:name=".SdlRouterService"
4648
android:exported="true"
47-
android:process="com.smartdevicelink.router">
49+
android:process="com.smartdevicelink.router"
50+
android:foregroundServiceType="connectedDevice">
4851
<intent-filter>
4952
<action android:name="com.smartdevicelink.router.service"/>
5053
</intent-filter>

android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlService.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,20 +198,44 @@ public void onError(String info, Exception e) {
198198
}
199199

200200
@Override
201-
public LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language){
202-
String appName;
201+
public LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language) {
202+
return null;
203+
}
204+
205+
@Override
206+
public LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language, Language hmiLanguage) {
207+
boolean isNeedUpdate = false;
208+
String appName = APP_NAME;
209+
String ttsName = APP_NAME;
203210
switch (language) {
204211
case ES_MX:
212+
isNeedUpdate = true;
213+
ttsName = APP_NAME_ES;
214+
break;
215+
case FR_CA:
216+
isNeedUpdate = true;
217+
ttsName = APP_NAME_FR;
218+
break;
219+
default:
220+
break;
221+
}
222+
switch (hmiLanguage) {
223+
case ES_MX:
224+
isNeedUpdate = true;
205225
appName = APP_NAME_ES;
206226
break;
207227
case FR_CA:
228+
isNeedUpdate = true;
208229
appName = APP_NAME_FR;
209230
break;
210231
default:
211-
return null;
232+
break;
233+
}
234+
if (isNeedUpdate) {
235+
return new LifecycleConfigurationUpdate(appName, null, TTSChunkFactory.createSimpleTTSChunks(ttsName), null);
236+
} else {
237+
return null;
212238
}
213-
214-
return new LifecycleConfigurationUpdate(appName,null,TTSChunkFactory.createSimpleTTSChunks(appName), null);
215239
}
216240
};
217241

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/SdlManagerTests.java

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
import android.content.Context;
44

55
import com.smartdevicelink.AndroidTestCase2;
6-
import com.smartdevicelink.exception.SdlException;
76
import com.smartdevicelink.managers.lifecycle.LifecycleConfigurationUpdate;
87
import com.smartdevicelink.managers.lockscreen.LockScreenConfig;
98
import com.smartdevicelink.protocol.enums.FunctionID;
109
import com.smartdevicelink.proxy.RPCMessage;
1110
import com.smartdevicelink.proxy.RPCRequest;
1211
import com.smartdevicelink.proxy.RPCResponse;
13-
import com.smartdevicelink.proxy.SdlProxyBase;
12+
import com.smartdevicelink.proxy.interfaces.ISdl;
1413
import com.smartdevicelink.proxy.rpc.GetAppServiceDataResponse;
1514
import com.smartdevicelink.proxy.rpc.GetVehicleData;
1615
import com.smartdevicelink.proxy.rpc.OnAppServiceData;
@@ -49,7 +48,7 @@ public class SdlManagerTests extends AndroidTestCase2 {
4948
private TemplateColorScheme templateColorScheme;
5049
private int listenerCalledCounter;
5150
private SdlManager sdlManager;
52-
private SdlProxyBase sdlProxyBase;
51+
private ISdl internalInterface;
5352

5453
// transport related
5554
@SuppressWarnings("FieldCanBeLocal")
@@ -110,7 +109,12 @@ public void onError(String info, Exception e) {
110109
}
111110

112111
@Override
113-
public LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language){
112+
public LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language) {
113+
return null;
114+
}
115+
116+
@Override
117+
public LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language, Language hmiLanguage) {
114118
return null;
115119
}
116120
};
@@ -131,9 +135,9 @@ public LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language langua
131135
builder.setContext(mTestContext);
132136
manager = builder.build();
133137

134-
// mock SdlProxyBase and set it manually
135-
sdlProxyBase = mock(SdlProxyBase.class);
136-
manager.setProxy(sdlProxyBase);
138+
// mock internalInterface and set it manually
139+
internalInterface = mock(ISdl.class);
140+
manager._internalInterface = internalInterface;
137141

138142
return manager;
139143
}
@@ -166,6 +170,7 @@ public void testManagerSetters() {
166170
assertEquals("heyApp", sdlManager.getShortAppName());
167171
assertEquals(appType, sdlManager.getAppTypes());
168172
assertEquals(Language.EN_US, sdlManager.getHmiLanguage());
173+
assertEquals(Language.EN_US, sdlManager.getLanguage());
169174
assertEquals(transport, sdlManager.getTransport());
170175
assertEquals(templateColorScheme, sdlManager.getDayColorScheme());
171176
assertEquals(templateColorScheme, sdlManager.getNightColorScheme());
@@ -178,8 +183,11 @@ public void testManagerSetters() {
178183

179184
public void testStartingManager(){
180185
listenerCalledCounter = 0;
181-
182-
sdlManager.start();
186+
187+
try {
188+
sdlManager.start();
189+
} catch (Exception e) {
190+
}
183191

184192
// Create and force all sub managers to be ready manually. Because SdlManager will not start until all sub managers are ready.
185193
// Note: SdlManager.initialize() will not be called automatically by proxy as in real life because we have mock proxy not a real one
@@ -192,7 +200,7 @@ public void testStartingManager(){
192200
sdlManager.getLockScreenManager().transitionToState(BaseSubManager.READY);
193201

194202
// Make sure the listener is called exactly once
195-
assertEquals("Listener was not called or called more/less frequently than expected", listenerCalledCounter, 1);
203+
assertEquals("Listener was not called or called more/less frequently than expected", 1, listenerCalledCounter);
196204
}
197205

198206
public void testManagerStates() {
@@ -308,7 +316,7 @@ public void testManagerStates() {
308316
public void testSendRPC(){
309317
listenerCalledCounter = 0;
310318

311-
// When sdlProxyBase.sendRPCRequest() is called, create a fake success response
319+
// When internalInterface.sendRPC() is called, create a fake success response
312320
Answer<Void> answer = new Answer<Void>() {
313321
@Override
314322
public Void answer(InvocationOnMock invocation) {
@@ -320,11 +328,7 @@ public Void answer(InvocationOnMock invocation) {
320328
return null;
321329
}
322330
};
323-
try {
324-
doAnswer(answer).when(sdlProxyBase).sendRPC(any(RPCMessage.class));
325-
} catch (SdlException e) {
326-
e.printStackTrace();
327-
}
331+
doAnswer(answer).when(internalInterface).sendRPC(any(RPCMessage.class));
328332

329333

330334
// Test send RPC request
@@ -341,7 +345,7 @@ public void onResponse(int correlationId, RPCResponse response) {
341345
sdlManager.sendRPC(request);
342346

343347
// Make sure the listener is called exactly once
344-
assertEquals("Listener was not called or called more/less frequently than expected", listenerCalledCounter, 1);
348+
assertEquals("Listener was not called or called more/less frequently than expected", 1, listenerCalledCounter);
345349
}
346350

347351
public void testSendRPCs(){
@@ -352,10 +356,10 @@ public void testSendSequentialRPCs(){
352356
testSendMultipleRPCs(true);
353357
}
354358

355-
private void testSendMultipleRPCs(boolean sequentialSend){
359+
private void testSendMultipleRPCs(boolean sequentialSend) {
356360
listenerCalledCounter = 0;
357361

358-
// When sdlProxyBase.sendRPCRequests() is called, call listener.onFinished() to fake the response
362+
// When internalInterface.sendRPCs() is called, call listener.onFinished() to fake the response
359363
final Answer<Void> answer = new Answer<Void>() {
360364
@Override
361365
public Void answer(InvocationOnMock invocation) {
@@ -365,34 +369,34 @@ public Void answer(InvocationOnMock invocation) {
365369
return null;
366370
}
367371
};
368-
try {
369-
if (sequentialSend){
370-
doAnswer(answer).when(sdlProxyBase).sendSequentialRequests(any(List.class), any(OnMultipleRequestListener.class));
371372

372-
} else {
373-
doAnswer(answer).when(sdlProxyBase).sendRequests(any(List.class), any(OnMultipleRequestListener.class));
374-
}
375-
} catch (SdlException e) {
376-
e.printStackTrace();
373+
if (sequentialSend) {
374+
doAnswer(answer).when(internalInterface).sendSequentialRPCs(any(List.class), any(OnMultipleRequestListener.class));
375+
376+
} else {
377+
doAnswer(answer).when(internalInterface).sendRPCs(any(List.class), any(OnMultipleRequestListener.class));
377378
}
378379

379380

380381
// Test send RPC requests
381382
List<RPCMessage> rpcsList = Arrays.asList(new GetVehicleData(), new Show(), new OnAppServiceData(), new GetAppServiceDataResponse());
382383
OnMultipleRequestListener onMultipleRequestListener = new OnMultipleRequestListener() {
383384
@Override
384-
public void onUpdate(int remainingRequests) { }
385+
public void onUpdate(int remainingRequests) {
386+
}
385387

386388
@Override
387389
public void onFinished() {
388390
listenerCalledCounter++;
389391
}
390392

391393
@Override
392-
public void onError(int correlationId, Result resultCode, String info) {}
394+
public void onError(int correlationId, Result resultCode, String info) {
395+
}
393396

394397
@Override
395-
public void onResponse(int correlationId, RPCResponse response) {}
398+
public void onResponse(int correlationId, RPCResponse response) {
399+
}
396400
};
397401
if (sequentialSend) {
398402
sdlManager.sendSequentialRPCs(rpcsList, onMultipleRequestListener);
@@ -402,7 +406,6 @@ public void onResponse(int correlationId, RPCResponse response) {}
402406

403407

404408
// Make sure the listener is called exactly once
405-
assertEquals("Listener was not called or called more/less frequently than expected", listenerCalledCounter, 1);
409+
assertEquals("Listener was not called or called more/less frequently than expected", 1, listenerCalledCounter);
406410
}
407-
408411
}

android/sdl_android/src/androidTest/java/com/smartdevicelink/test/proxy/SystemCapabilityManagerTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.util.SparseArray;
44

55
import com.smartdevicelink.AndroidTestCase2;
6+
import com.smartdevicelink.managers.ManagerUtility;
67
import com.smartdevicelink.protocol.enums.FunctionID;
78
import com.smartdevicelink.protocol.enums.SessionType;
89
import com.smartdevicelink.proxy.RPCMessage;
@@ -138,6 +139,8 @@ private List<DisplayCapability> createDisplayCapabilityList(DisplayCapabilities
138139
defaultWindowCapability.setSoftButtonCapabilities(softButton);
139140

140141
if (display == null) {
142+
defaultWindowCapability.setTextFields(ManagerUtility.WindowCapabilityUtility.getAllTextFields());
143+
defaultWindowCapability.setImageFields(ManagerUtility.WindowCapabilityUtility.getAllImageFields());
141144
displayCapability.setWindowCapabilities(Collections.singletonList(defaultWindowCapability));
142145
return Collections.singletonList(displayCapability);
143146
}
@@ -198,6 +201,12 @@ public void testParseRAI() {
198201

199202
}
200203

204+
public void testNullDisplayCapabilitiesEnablesAllTextAndImageFields() {
205+
List<DisplayCapability> displayCapabilityList = createDisplayCapabilityList(null, Test.GENERAL_BUTTONCAPABILITIES_LIST, Test.GENERAL_SOFTBUTTONCAPABILITIES_LIST);
206+
assertEquals(displayCapabilityList.get(0).getWindowCapabilities().get(0).getTextFields().size(), 29);
207+
assertEquals(displayCapabilityList.get(0).getWindowCapabilities().get(0).getImageFields().size(), 14);
208+
}
209+
201210
public void testGetVSCapability(){
202211
VideoStreamingCapability vsCapability = new VideoStreamingCapability();
203212
vsCapability.setMaxBitrate(Test.GENERAL_INT);
@@ -945,6 +954,11 @@ public void sendRequests(List<? extends RPCRequest> rpcs, OnMultipleRequestListe
945954

946955
}
947956

957+
@Override
958+
public void sendRPCs(List<? extends RPCMessage> rpcs, OnMultipleRequestListener listener) {
959+
960+
}
961+
948962
@Override
949963
public void sendSequentialRPCs(List<? extends RPCMessage> rpcs, OnMultipleRequestListener listener) {
950964

android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/MultiplexTransportTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package com.smartdevicelink.transport;
22

3+
import android.os.Bundle;
4+
import android.os.Handler;
5+
import android.os.Looper;
6+
import android.os.Message;
7+
38
import com.smartdevicelink.AndroidTestCase2;
49
import com.smartdevicelink.protocol.SdlPacket;
510
import com.smartdevicelink.test.SdlUnitTestContants;
@@ -80,4 +85,18 @@ public void testThreadRecoverability(){
8085
Assert.fail("NPE in MultiplexTransport constructor");
8186
}
8287
}
88+
89+
// test for setting error state.
90+
public void testSetState() {
91+
final Bundle bundle = new Bundle();
92+
MultiplexBluetoothTransport btTransport = new MultiplexBluetoothTransport(new Handler(Looper.getMainLooper()) {
93+
@Override
94+
public void handleMessage(Message message) {
95+
assertTrue(message.getData().equals(bundle));
96+
}
97+
});
98+
btTransport.start();
99+
bundle.putByte(MultiplexBaseTransport.ERROR_REASON_KEY, MultiplexBaseTransport.REASON_SPP_ERROR);
100+
btTransport.setState(MultiplexBaseTransport.STATE_ERROR, bundle);
101+
}
83102
}

0 commit comments

Comments
 (0)