Skip to content

Commit be7f985

Browse files
author
Kostiantyn Sologubov
authored
Merge branch 'develop' into SDL-0234-Proxy-Library-RPC-Generation
2 parents 0e7012d + e1b059a commit be7f985

39 files changed

Lines changed: 1862 additions & 325 deletions

File tree

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ build/
7373
/.idea/libraries
7474
/captures
7575
.externalNativeBuild
76+
gradle/
77+
gradlew
78+
gradlew.bat
7679

7780
##############################
7881
# Python
@@ -81,4 +84,4 @@ build/
8184
*__pycache__
8285
*htmlcov
8386
*.coverage
84-
*.pytest_cache
87+
*.pytest_cache

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77

88
import com.smartdevicelink.transport.SdlBroadcastReceiver;
99
import com.smartdevicelink.transport.SdlRouterService;
10-
import com.smartdevicelink.transport.TransportConstants;
1110

1211
public class SdlReceiver extends SdlBroadcastReceiver {
1312
private static final String TAG = "SdlBroadcastReciever";
14-
public static final String RECONNECT_LANG_CHANGE = "RECONNECT_LANG_CHANGE";
1513

1614
@Override
1715
public void onSdlEnabled(Context context, Intent intent) {
@@ -36,16 +34,5 @@ public Class<? extends SdlRouterService> defineLocalSdlRouterClass() {
3634
@Override
3735
public void onReceive(Context context, Intent intent) {
3836
super.onReceive(context, intent); // Required if overriding this method
39-
40-
if (intent != null) {
41-
String action = intent.getAction();
42-
if (action != null){
43-
if(action.equalsIgnoreCase(TransportConstants.START_ROUTER_SERVICE_ACTION)) {
44-
if (intent.getBooleanExtra(RECONNECT_LANG_CHANGE, false)) {
45-
onSdlEnabled(context, intent);
46-
}
47-
}
48-
}
49-
}
5037
}
5138
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.smartdevicelink.transport.BaseTransportConfig;
2626
import com.smartdevicelink.transport.TCPTransportConfig;
2727

28+
import org.mockito.Mockito;
2829
import org.mockito.invocation.InvocationOnMock;
2930
import org.mockito.stubbing.Answer;
3031

@@ -60,6 +61,8 @@ public class SdlManagerTests extends AndroidTestCase2 {
6061
public void setUp() throws Exception{
6162
super.setUp();
6263

64+
mTestContext = Mockito.mock(Context.class);
65+
6366
// set transport
6467
transport = new TCPTransportConfig(TCP_PORT, DEV_MACHINE_IP_ADDRESS, true);
6568

@@ -125,6 +128,7 @@ public LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language langua
125128
builder.setLockScreenConfig(lockScreenConfig);
126129
builder.setMinimumProtocolVersion(Test.GENERAL_VERSION);
127130
builder.setMinimumRPCVersion(Test.GENERAL_VERSION);
131+
builder.setContext(mTestContext);
128132
manager = builder.build();
129133

130134
// mock SdlProxyBase and set it manually

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/file/FileManagerTests.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,4 +925,60 @@ public void onComplete(Map<String, String> errors) {
925925
});
926926
verify(internalInterface, times(1)).sendRequests(any(List.class), any(OnMultipleRequestListener.class));
927927
}
928+
929+
/**
930+
* Test custom overridden SdlFile equals method
931+
*/
932+
public void testSdlFileEquals() {
933+
// Case 1: object is null, assertFalse
934+
SdlFile artwork1 = new SdlFile("image1", FileType.GRAPHIC_PNG, 1, true);
935+
SdlFile artwork2 = null;
936+
assertFalse(artwork1.equals(artwork2));
937+
938+
// Case 2 SoftButtonObjects are the same, assertTrue
939+
assertTrue(artwork1.equals(artwork1));
940+
941+
// Case 3: object is not an instance of SoftButtonObject, assertFalse
942+
assertFalse(artwork1.equals("Test"));
943+
944+
// Case 4: different StaticIcon status, assertFalse
945+
artwork1.setStaticIcon(true);
946+
artwork2 = new SdlFile("image1", FileType.GRAPHIC_PNG, 1, true);
947+
artwork2.setStaticIcon(false);
948+
assertFalse(artwork1.equals(artwork2));
949+
950+
// Case 5: different Persistent status, assertFalse
951+
artwork1 = new SdlFile("image1", FileType.GRAPHIC_PNG, 1, false);
952+
artwork2 = new SdlFile("image1", FileType.GRAPHIC_PNG, 1, true);
953+
assertFalse(artwork1.equals(artwork2));
954+
955+
// Case 6: different name, assertFalse
956+
artwork2 = new SdlFile("image2", FileType.GRAPHIC_PNG, 1, false);
957+
assertFalse(artwork1.equals(artwork2));
958+
959+
// Case 7: different Uri
960+
Uri uri1 = Uri.parse("testUri1");
961+
Uri uri2 = Uri.parse("testUri2");
962+
artwork1 = new SdlFile("image1", FileType.GRAPHIC_PNG, uri1, false);
963+
artwork2 = new SdlFile("image1", FileType.GRAPHIC_PNG, uri2, false);
964+
assertFalse(artwork1.equals(artwork2));
965+
966+
// Case 8: different FileData
967+
artwork1 = new SdlFile("image1", FileType.GRAPHIC_PNG, 1, false);
968+
artwork2 = new SdlFile("image1", FileType.GRAPHIC_PNG, 1, false);
969+
byte[] GENERAL_BYTE_ARRAY2 = new byte[2];
970+
artwork1.setFileData(Test.GENERAL_BYTE_ARRAY);
971+
artwork2.setFileData(GENERAL_BYTE_ARRAY2);
972+
assertFalse(artwork1.equals(artwork2));
973+
974+
// Case 9 different FileType, assertFalse
975+
artwork1 = new SdlFile("image1", FileType.GRAPHIC_PNG, 1, false);
976+
artwork2 = new SdlFile("image1", FileType.AUDIO_WAVE, 1, false);
977+
assertFalse(artwork1.equals(artwork2));
978+
979+
// Case 10: they are equal, assertTrue
980+
artwork1 = new SdlFile("image1", FileType.GRAPHIC_PNG, 1, false);
981+
artwork2 = new SdlFile("image1", FileType.GRAPHIC_PNG, 1, false);
982+
assertTrue(artwork1.equals(artwork2));
983+
}
928984
}

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/file/SdlArtworkTests.java renamed to android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/file/filetypes/SdlArtworkTests.java

File renamed without changes.
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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.managers.file.filetypes;
34+
35+
import com.smartdevicelink.AndroidTestCase2;
36+
import com.smartdevicelink.test.Test;
37+
38+
public class SdlFileTests extends AndroidTestCase2 {
39+
40+
public void testConstructorWithNoParams() {
41+
SdlFile sdlFile;
42+
43+
// Case 1 (Setting data)
44+
sdlFile = new SdlFile();
45+
sdlFile.setFileData(Test.GENERAL_BYTE_ARRAY);
46+
assertEquals(sdlFile.getFileData(), Test.GENERAL_BYTE_ARRAY);
47+
sdlFile.setName(null);
48+
assertEquals(sdlFile.getName(), "e9800998ecf8427e");
49+
sdlFile.setName(Test.GENERAL_STRING);
50+
assertEquals(sdlFile.getName(), Test.GENERAL_STRING);
51+
sdlFile.setType(Test.GENERAL_FILETYPE);
52+
assertEquals(sdlFile.getType(), Test.GENERAL_FILETYPE);
53+
sdlFile.setPersistent(Test.GENERAL_BOOLEAN);
54+
assertEquals(sdlFile.isPersistent(), Test.GENERAL_BOOLEAN);
55+
56+
// Case 2 (Setting resourceId)
57+
sdlFile = new SdlFile();
58+
sdlFile.setResourceId(Test.GENERAL_INTEGER);
59+
assertEquals((Integer) sdlFile.getResourceId(), Test.GENERAL_INTEGER);
60+
sdlFile.setName(null);
61+
assertEquals(sdlFile.getName(), "ec9ebc78777cf40d");
62+
sdlFile.setName(Test.GENERAL_STRING);
63+
assertEquals(sdlFile.getName(), Test.GENERAL_STRING);
64+
sdlFile.setType(Test.GENERAL_FILETYPE);
65+
assertEquals(sdlFile.getType(), Test.GENERAL_FILETYPE);
66+
sdlFile.setPersistent(Test.GENERAL_BOOLEAN);
67+
assertEquals(sdlFile.isPersistent(), Test.GENERAL_BOOLEAN);
68+
69+
// Case 3 (Setting URI)
70+
sdlFile = new SdlFile();
71+
sdlFile.setUri(Test.GENERAL_URI);
72+
assertEquals(sdlFile.getUri(), Test.GENERAL_URI);
73+
sdlFile.setName(null);
74+
assertEquals(sdlFile.getName(), "d3467db131372140");
75+
sdlFile.setName(Test.GENERAL_STRING);
76+
assertEquals(sdlFile.getName(), Test.GENERAL_STRING);
77+
sdlFile.setType(Test.GENERAL_FILETYPE);
78+
assertEquals(sdlFile.getType(), Test.GENERAL_FILETYPE);
79+
sdlFile.setPersistent(Test.GENERAL_BOOLEAN);
80+
assertEquals(sdlFile.isPersistent(), Test.GENERAL_BOOLEAN);
81+
}
82+
83+
public void testConstructorWithResourceId() {
84+
// Case1 (Set the name manually)
85+
SdlFile sdlFile1 = new SdlFile(Test.GENERAL_STRING, Test.GENERAL_FILETYPE, Test.GENERAL_INTEGER, Test.GENERAL_BOOLEAN);
86+
assertEquals(sdlFile1.getName(), Test.GENERAL_STRING);
87+
assertEquals(sdlFile1.getType(), Test.GENERAL_FILETYPE);
88+
assertEquals((Integer) sdlFile1.getResourceId(), Test.GENERAL_INTEGER);
89+
assertEquals(sdlFile1.isPersistent(), Test.GENERAL_BOOLEAN);
90+
91+
// Case2 (Let the library generate a name)
92+
SdlFile sdlFile2 = new SdlFile(null, Test.GENERAL_FILETYPE, Test.GENERAL_INTEGER, Test.GENERAL_BOOLEAN);
93+
SdlFile sdlFile3 = new SdlFile(null, Test.GENERAL_FILETYPE, Test.GENERAL_INTEGER, Test.GENERAL_BOOLEAN);
94+
assertEquals(sdlFile2.getName(), sdlFile3.getName());
95+
assertEquals(sdlFile2.getName(), "ec9ebc78777cf40d");
96+
assertEquals(sdlFile2.getType(), Test.GENERAL_FILETYPE);
97+
assertEquals((Integer) sdlFile2.getResourceId(), Test.GENERAL_INTEGER);
98+
assertEquals(sdlFile2.isPersistent(), Test.GENERAL_BOOLEAN);
99+
}
100+
101+
public void testConstructorWithData() {
102+
// Case1 (Set the name manually)
103+
SdlFile sdlFile1 = new SdlFile(Test.GENERAL_STRING, Test.GENERAL_FILETYPE, Test.GENERAL_BYTE_ARRAY, Test.GENERAL_BOOLEAN);
104+
assertEquals(sdlFile1.getName(), Test.GENERAL_STRING);
105+
assertEquals(sdlFile1.getType(), Test.GENERAL_FILETYPE);
106+
assertEquals(sdlFile1.getFileData(), Test.GENERAL_BYTE_ARRAY);
107+
assertEquals(sdlFile1.isPersistent(), Test.GENERAL_BOOLEAN);
108+
109+
// Case2 (Let the library generate a name)
110+
SdlFile sdlFile2 = new SdlFile(null, Test.GENERAL_FILETYPE, Test.GENERAL_BYTE_ARRAY, Test.GENERAL_BOOLEAN);
111+
SdlFile sdlFile3 = new SdlFile(null, Test.GENERAL_FILETYPE, Test.GENERAL_BYTE_ARRAY, Test.GENERAL_BOOLEAN);
112+
assertEquals(sdlFile2.getName(), sdlFile3.getName());
113+
assertEquals(sdlFile2.getName(), "e9800998ecf8427e");
114+
assertEquals(sdlFile2.getType(), Test.GENERAL_FILETYPE);
115+
assertEquals(sdlFile2.getFileData(), Test.GENERAL_BYTE_ARRAY);
116+
assertEquals(sdlFile2.isPersistent(), Test.GENERAL_BOOLEAN);
117+
}
118+
119+
public void testConstructorWithUri() {
120+
// Case1 (Set the name manually)
121+
SdlFile sdlFile1 = new SdlFile(Test.GENERAL_STRING, Test.GENERAL_FILETYPE, Test.GENERAL_URI, Test.GENERAL_BOOLEAN);
122+
assertEquals(sdlFile1.getName(), Test.GENERAL_STRING);
123+
assertEquals(sdlFile1.getType(), Test.GENERAL_FILETYPE);
124+
assertEquals(sdlFile1.getUri(), Test.GENERAL_URI);
125+
assertEquals(sdlFile1.isPersistent(), Test.GENERAL_BOOLEAN);
126+
127+
// Case2 (Let the library generate a name)
128+
SdlFile sdlFile2 = new SdlFile(null, Test.GENERAL_FILETYPE, Test.GENERAL_URI, Test.GENERAL_BOOLEAN);
129+
SdlFile sdlFile3 = new SdlFile(null, Test.GENERAL_FILETYPE, Test.GENERAL_URI, Test.GENERAL_BOOLEAN);
130+
assertEquals(sdlFile2.getName(), sdlFile3.getName());
131+
assertEquals(sdlFile2.getName(), "d3467db131372140");
132+
assertEquals(sdlFile2.getType(), Test.GENERAL_FILETYPE);
133+
assertEquals(sdlFile2.getUri(), Test.GENERAL_URI);
134+
assertEquals(sdlFile2.isPersistent(), Test.GENERAL_BOOLEAN);
135+
}
136+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package com.smartdevicelink.managers.lockscreen;
2+
3+
import android.content.Context;
4+
import android.content.SharedPreferences;
5+
import android.graphics.Bitmap;
6+
7+
import com.smartdevicelink.AndroidTestCase2;
8+
import com.smartdevicelink.util.AndroidTools;
9+
10+
import org.json.JSONException;
11+
import org.json.JSONObject;
12+
import org.junit.rules.TemporaryFolder;
13+
import org.mockito.Mockito;
14+
15+
import java.io.File;
16+
import java.io.IOException;
17+
import java.math.BigInteger;
18+
import java.security.MessageDigest;
19+
import java.security.NoSuchAlgorithmException;
20+
21+
import static org.mockito.ArgumentMatchers.any;
22+
import static org.mockito.ArgumentMatchers.anyInt;
23+
import static org.mockito.ArgumentMatchers.anyString;
24+
import static org.mockito.ArgumentMatchers.isNull;
25+
import static org.mockito.Mockito.times;
26+
import static org.mockito.Mockito.verify;
27+
28+
public class LockScreenDeviceIconManagerTests extends AndroidTestCase2 {
29+
30+
TemporaryFolder tempFolder = new TemporaryFolder();
31+
private LockScreenDeviceIconManager lockScreenDeviceIconManager;
32+
private static final String ICON_URL = "https://i.imgur.com/TgkvOIZ.png";
33+
private static final String LAST_UPDATED_TIME = "lastUpdatedTime";
34+
private static final String STORED_PATH = "storedPath";
35+
36+
public void setup() throws Exception {
37+
super.setUp();
38+
}
39+
40+
public void tearDown() throws Exception {
41+
super.tearDown();
42+
}
43+
44+
public void testRetrieveIconShouldCallOnErrorTwiceWhenGivenURLThatCannotDownloadAndIconIsNotCached() {
45+
final SharedPreferences sharedPrefs = Mockito.mock(SharedPreferences.class);
46+
final Context context = Mockito.mock(Context.class);
47+
final LockScreenDeviceIconManager.OnIconRetrievedListener listener = Mockito.mock(LockScreenDeviceIconManager.OnIconRetrievedListener.class);
48+
49+
Mockito.when(context.getSharedPreferences(anyString(), anyInt())).thenReturn(sharedPrefs);
50+
Mockito.when(sharedPrefs.getString(anyString(), (String) isNull())).thenReturn(null);
51+
52+
lockScreenDeviceIconManager = new LockScreenDeviceIconManager(context);
53+
lockScreenDeviceIconManager.retrieveIcon("", listener);
54+
verify(listener, times(2)).onError(anyString());
55+
}
56+
57+
public void testRetrieveIconShouldCallOnImageOnImageRetrievedWithIconWhenIconUpdateTimeIsNullFromSharedPref() {
58+
final SharedPreferences sharedPrefs = Mockito.mock(SharedPreferences.class);
59+
final Context context = Mockito.mock(Context.class);
60+
final LockScreenDeviceIconManager.OnIconRetrievedListener listener = Mockito.mock(LockScreenDeviceIconManager.OnIconRetrievedListener.class);
61+
62+
Mockito.when(context.getSharedPreferences(anyString(), anyInt())).thenReturn(sharedPrefs);
63+
Mockito.when(sharedPrefs.getString(anyString(), (String) isNull())).thenReturn(null);
64+
65+
lockScreenDeviceIconManager = new LockScreenDeviceIconManager(context);
66+
lockScreenDeviceIconManager.retrieveIcon(ICON_URL, listener);
67+
verify(listener, times(1)).onImageRetrieved((Bitmap) any());
68+
}
69+
70+
71+
public void testRetrieveIconShouldCallOnImageOnImageRetrievedWithIconWhenCachedIconExpired() {
72+
final SharedPreferences sharedPrefs = Mockito.mock(SharedPreferences.class);
73+
final Context context = Mockito.mock(Context.class);
74+
final LockScreenDeviceIconManager.OnIconRetrievedListener listener = Mockito.mock(LockScreenDeviceIconManager.OnIconRetrievedListener.class);
75+
76+
Mockito.when(context.getSharedPreferences(anyString(), anyInt())).thenReturn(sharedPrefs);
77+
Mockito.when(sharedPrefs.getString(anyString(), (String) isNull())).thenReturn(daysToMillisecondsAsString(31));
78+
79+
lockScreenDeviceIconManager = new LockScreenDeviceIconManager(context);
80+
lockScreenDeviceIconManager.retrieveIcon(ICON_URL, listener);
81+
verify(listener, times(1)).onImageRetrieved((Bitmap) any());
82+
}
83+
84+
public void testRetrieveIconShouldCallOnImageRetrievedWithIconWhenCachedIconIsUpToDate() {
85+
final SharedPreferences sharedPrefs = Mockito.mock(SharedPreferences.class);
86+
final Context context = Mockito.mock(Context.class);
87+
final SharedPreferences.Editor sharedPrefsEditor = Mockito.mock(SharedPreferences.Editor.class);
88+
final LockScreenDeviceIconManager.OnIconRetrievedListener listener = Mockito.mock(LockScreenDeviceIconManager.OnIconRetrievedListener.class);
89+
90+
Mockito.when(context.getSharedPreferences(anyString(), anyInt())).thenReturn(sharedPrefs);
91+
Mockito.when(sharedPrefs.getString(anyString(), (String) isNull())).thenReturn(daysToMillisecondsAsString(15));
92+
Mockito.when(sharedPrefs.edit()).thenReturn(sharedPrefsEditor);
93+
Mockito.when(sharedPrefsEditor.clear()).thenReturn(sharedPrefsEditor);
94+
95+
lockScreenDeviceIconManager = new LockScreenDeviceIconManager(context);
96+
lockScreenDeviceIconManager.retrieveIcon(ICON_URL, listener);
97+
verify(listener, times(1)).onImageRetrieved((Bitmap) any());
98+
}
99+
100+
private String daysToMillisecondsAsString(int days) {
101+
long milliSeconds = (long) days * 24 * 60 * 60 * 1000;
102+
long previousDay = System.currentTimeMillis() - milliSeconds;
103+
return String.valueOf(previousDay);
104+
}
105+
}

0 commit comments

Comments
 (0)