summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorJulian Kast <julian@livio.com>2020-03-10 12:27:19 -0400
committerJulian Kast <julian@livio.com>2020-03-10 12:27:19 -0400
commit21450c41b8bcbf95d826a2aa8687bd195e85862d (patch)
tree48daafb51dc6c324fdbf8cb1fb6330b851a45592 /android
parent738af48f45a92ac568a075a8ef44a4e31a68f11d (diff)
parent0228f10e4d3d6cc5e0102e7e1abb95455b060bf5 (diff)
downloadsdl_android-21450c41b8bcbf95d826a2aa8687bd195e85862d.tar.gz
Merge branch 'develop' into add_Overwrite_Property
Diffstat (limited to 'android')
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/file/FileManagerTests.java227
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/proxy/RPCRequestFactory.java2
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java2
3 files changed, 101 insertions, 130 deletions
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/file/FileManagerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/file/FileManagerTests.java
index f5186da8a..073c62845 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/file/FileManagerTests.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/file/FileManagerTests.java
@@ -136,21 +136,6 @@ public class FileManagerTests extends AndroidTestCase2 {
}
};
- private Answer<Void> onListFilesFailure = new Answer<Void>() {
- @Override
- public Void answer(InvocationOnMock invocation) {
- Object[] args = invocation.getArguments();
- RPCRequest message = (RPCRequest) args[0];
- if(message instanceof ListFiles){
- int correlationId = message.getCorrelationID();
- ListFilesResponse listFilesResponse = new ListFilesResponse();
- listFilesResponse.setSuccess(false);
- message.getOnRPCResponseListener().onResponse(correlationId, listFilesResponse);
- }
- return null;
- }
- };
-
private Answer<Void> onPutFileSuccess = new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) {
@@ -182,38 +167,40 @@ public class FileManagerTests extends AndroidTestCase2 {
}
};
- private Answer<Void> onSendRequestsSuccess = new Answer<Void>() {
+ private Answer<Void> onListDeleteRequestSuccess = new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
List<RPCRequest> rpcs = (List<RPCRequest>) args[0];
OnMultipleRequestListener listener = (OnMultipleRequestListener) args[1];
- if(rpcs.get(0) instanceof PutFile){
- for(RPCRequest message : rpcs){
+ if (rpcs.get(0) instanceof DeleteFile) {
+ for (RPCRequest message : rpcs) {
int correlationId = message.getCorrelationID();
listener.addCorrelationId(correlationId);
- PutFileResponse putFileResponse = new PutFileResponse();
- putFileResponse.setSuccess(true);
- listener.onResponse(correlationId, putFileResponse);
+ DeleteFileResponse deleteFileResponse = new DeleteFileResponse();
+ deleteFileResponse.setSuccess(true);
+ listener.onResponse(correlationId, deleteFileResponse);
}
+ listener.onFinished();
}
return null;
}
};
- private Answer<Void> onListDeleteRequestSuccess = new Answer<Void>() {
+ private Answer<Void> onListDeleteRequestFail = new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
List<RPCRequest> rpcs = (List<RPCRequest>) args[0];
OnMultipleRequestListener listener = (OnMultipleRequestListener) args[1];
if (rpcs.get(0) instanceof DeleteFile) {
+ Result resultCode = Result.REJECTED;
for (RPCRequest message : rpcs) {
int correlationId = message.getCorrelationID();
listener.addCorrelationId(correlationId);
DeleteFileResponse deleteFileResponse = new DeleteFileResponse();
deleteFileResponse.setSuccess(true);
- listener.onResponse(correlationId, deleteFileResponse);
+ listener.onError(correlationId, resultCode, "Binary data empty");
}
listener.onFinished();
}
@@ -221,20 +208,28 @@ public class FileManagerTests extends AndroidTestCase2 {
}
};
- private Answer<Void> onListDeleteRequestFail = new Answer<Void>() {
+ private Answer<Void> onSendRequestsFailPartialOnError = new Answer<Void>() {
@Override
- public Void answer(InvocationOnMock invocation) {
+ public Void answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
List<RPCRequest> rpcs = (List<RPCRequest>) args[0];
OnMultipleRequestListener listener = (OnMultipleRequestListener) args[1];
- if (rpcs.get(0) instanceof DeleteFile) {
+ if (rpcs.get(0) instanceof PutFile) {
Result resultCode = Result.REJECTED;
+ boolean flip = false;
for (RPCRequest message : rpcs) {
int correlationId = message.getCorrelationID();
listener.addCorrelationId(correlationId);
- DeleteFileResponse deleteFileResponse = new DeleteFileResponse();
- deleteFileResponse.setSuccess(true);
- listener.onError(correlationId, resultCode, "Binary data empty");
+ PutFileResponse putFileResponse = new PutFileResponse();
+ if (flip) {
+ putFileResponse.setSuccess(true);
+ flip = false;
+ listener.onResponse(correlationId, putFileResponse);
+ } else {
+ flip = true;
+ putFileResponse.setSuccess(false);
+ listener.onError(correlationId, resultCode, "Binary data empty");
+ }
}
listener.onFinished();
}
@@ -436,12 +431,16 @@ public class FileManagerTests extends AndroidTestCase2 {
verify(internalInterface, times(5)).sendRequests(any(List.class),any(OnMultipleRequestListener.class));
}
- public void testInitializationSuccess(){
+ /**
+ * Testing the initialization of FileManager
+ */
+ public void testInitializationSuccess() {
ISdl internalInterface = mock(ISdl.class);
- doAnswer(onListFilesSuccess).when(internalInterface).sendRPCRequest(any(ListFiles.class));
+ doAnswer(onListFilesSuccess).when(internalInterface).sendRPC(any(ListFiles.class));
- final FileManager fileManager = new FileManager(internalInterface, mTestContext);
+ FileManagerConfig fileManagerConfig = new FileManagerConfig();
+ final FileManager fileManager = new FileManager(internalInterface, mTestContext, fileManagerConfig);
fileManager.start(new CompletionListener() {
@Override
public void onComplete(boolean success) {
@@ -453,22 +452,6 @@ public class FileManagerTests extends AndroidTestCase2 {
});
}
- public void testInitializationFailure(){
- ISdl internalInterface = mock(ISdl.class);
-
- doAnswer(onListFilesFailure).when(internalInterface).sendRPCRequest(any(ListFiles.class));
-
- final FileManager fileManager = new FileManager(internalInterface, mTestContext);
- fileManager.start(new CompletionListener() {
- @Override
- public void onComplete(boolean success) {
- assertFalse(success);
- assertEquals(fileManager.getState(), BaseSubManager.ERROR);
- assertEquals(BaseFileManager.SPACE_AVAILABLE_MAX_VALUE, fileManager.getBytesAvailable());
- }
- });
- }
-
/**
* Test file upload, success
*/
@@ -498,13 +481,17 @@ public class FileManagerTests extends AndroidTestCase2 {
assertEquals(Test.GENERAL_INT, fileManager.getBytesAvailable());
}
+ /**
+ * Testing failed file upload.
+ */
public void testFileUploadFailure() {
ISdl internalInterface = mock(ISdl.class);
- doAnswer(onListFilesSuccess).when(internalInterface).sendRPCRequest(any(ListFiles.class));
- doAnswer(onPutFileFailure).when(internalInterface).sendRPCRequest(any(PutFile.class));
+ doAnswer(onListFilesSuccess).when(internalInterface).sendRPC(any(ListFiles.class));
+ doAnswer(onPutFileFailure).when(internalInterface).sendRPC(any(PutFile.class));
- final FileManager fileManager = new FileManager(internalInterface, mTestContext);
+ FileManagerConfig fileManagerConfig = new FileManagerConfig();
+ final FileManager fileManager = new FileManager(internalInterface, mTestContext, fileManagerConfig);
fileManager.start(new CompletionListener() {
@Override
public void onComplete(boolean success) {
@@ -610,12 +597,16 @@ public class FileManagerTests extends AndroidTestCase2 {
verify(internalInterface, times(1)).sendRequests(any(List.class), any(OnMultipleRequestListener.class));
}
- public void testInvalidSdlFileInput(){
+ /**
+ * Test to make sure you cannot upload an SdlFile with invalid data
+ */
+ public void testInvalidSdlFileInput() {
ISdl internalInterface = mock(ISdl.class);
- doAnswer(onListFilesSuccess).when(internalInterface).sendRPCRequest(any(ListFiles.class));
+ doAnswer(onListFilesSuccess).when(internalInterface).sendRPC(any(ListFiles.class));
- final FileManager fileManager = new FileManager(internalInterface, mTestContext);
+ FileManagerConfig fileManagerConfig = new FileManagerConfig();
+ final FileManager fileManager = new FileManager(internalInterface, mTestContext, fileManagerConfig);
fileManager.start(new CompletionListener() {
@Override
public void onComplete(boolean success) {
@@ -646,6 +637,12 @@ public class FileManagerTests extends AndroidTestCase2 {
});
}
+ /**
+ * Used to try and upload SdlFiles with invalid data, throw an assert error if file uploads
+ *
+ * @param fileManager - FileManager used to manage and upload files
+ * @param sdlFile - SdlFile with invalid data to test uploading
+ */
private void checkForUploadFailure(FileManager fileManager, SdlFile sdlFile){
boolean error = false;
@@ -661,6 +658,10 @@ public class FileManagerTests extends AndroidTestCase2 {
assertTrue(error);
}
+ /**
+ * Test Invalid SdlArtWork FileTypes
+ * SdlArtwork FileTypes can only be: GRAPHIC_BMP, GRAPHIC_PNG or GRAPHIC_JPEG
+ */
public void testInvalidSdlArtworkInput(){
SdlArtwork sdlArtwork = new SdlArtwork();
// Set invalid type
@@ -715,99 +716,65 @@ public class FileManagerTests extends AndroidTestCase2 {
});
}
- public void testMultipleFileUploadPartialFailure(){
- final String failureReason = "No space available";
-
+ /**
+ * Testing uploading multiple files with some failing.
+ */
+ public void testMultipleFileUploadPartialFailure() {
ISdl internalInterface = mock(ISdl.class);
- doAnswer(onListFilesSuccess).when(internalInterface).sendRPCRequest(any(ListFiles.class));
+ doAnswer(onListFilesSuccess).when(internalInterface).sendRPC(any(ListFiles.class));
+ doAnswer(onSendRequestsFailPartialOnError).when(internalInterface).sendRequests(any(List.class), any(OnMultipleRequestListener.class));
- Answer<Void> onSendRequestsFailure = new Answer<Void>() {
- private int responseNum = 0;
- @Override
- public Void answer(InvocationOnMock invocation) {
- Object[] args = invocation.getArguments();
- List<RPCRequest> rpcs = (List<RPCRequest>) args[0];
- OnMultipleRequestListener listener = (OnMultipleRequestListener) args[1];
- if(rpcs.get(0) instanceof PutFile){
- for(RPCRequest message : rpcs){
- int correlationId = message.getCorrelationID();
- listener.addCorrelationId(correlationId);
- PutFileResponse putFileResponse = new PutFileResponse();
- if(responseNum++ % 2 == 0){
- listener.onError(correlationId, Result.OUT_OF_MEMORY, failureReason);
- }else{
- putFileResponse.setSuccess(true);
- listener.onResponse(correlationId, putFileResponse);
- }
- }
- }
- return null;
- }
- };
- doAnswer(onSendRequestsFailure).when(internalInterface).sendRequests(any(List.class), any(OnMultipleRequestListener.class));
+ SdlFile validFile2 = new SdlFile();
+ validFile2.setName(Test.GENERAL_STRING + "2");
+ validFile2.setFileData(Test.GENERAL_BYTE_ARRAY);
+ validFile2.setPersistent(false);
+ validFile2.setType(FileType.GRAPHIC_JPEG);
- final FileManager fileManager = new FileManager(internalInterface, mTestContext);
- fileManager.start(new CompletionListener() {
- @Override
- public void onComplete(boolean success) {
- assertTrue(success);
- final String baseFileName = "file";
- int fileNum = 0;
- final List<SdlFile> filesToUpload = new ArrayList<>();
- SdlFile sdlFile = new SdlFile();
- sdlFile.setName(baseFileName + fileNum++);
- Uri uri = Uri.parse("android.resource://" + mTestContext.getPackageName() + "/drawable/ic_sdl");
- sdlFile.setUri(uri);
- filesToUpload.add(sdlFile);
+ SdlFile validFile3 = new SdlFile();
+ validFile3.setName(Test.GENERAL_STRING + "3");
+ validFile3.setFileData(Test.GENERAL_BYTE_ARRAY);
+ validFile3.setPersistent(false);
+ validFile3.setType(FileType.GRAPHIC_JPEG);
- sdlFile = new SdlFile();
- sdlFile.setName(baseFileName + fileNum++);
- sdlFile.setResourceId(com.smartdevicelink.test.R.drawable.ic_sdl);
- filesToUpload.add(sdlFile);
+ validFile.setType(FileType.AUDIO_WAVE);
- sdlFile = new SdlFile();
- sdlFile.setName(baseFileName + fileNum++);
- sdlFile.setFileData(Test.GENERAL_BYTE_ARRAY);
- sdlFile.setPersistent(true);
- sdlFile.setType(FileType.BINARY);
- filesToUpload.add(sdlFile);
+ final List<SdlFile> filesToUpload = new ArrayList<>();
+ filesToUpload.add(validFile);
+ filesToUpload.add(validFile2);
+ filesToUpload.add(validFile3);
+ FileManagerConfig fileManagerConfig = new FileManagerConfig();
+ fileManagerConfig.setArtworkRetryCount(0);
+ fileManagerConfig.setFileRetryCount(0);
+ final FileManager fileManager = new FileManager(internalInterface, mTestContext, fileManagerConfig);
+ fileManager.start(new CompletionListener() {
+ @Override
+ public void onComplete(boolean success) {
fileManager.uploadFiles(filesToUpload,
new MultipleFileCompletionListener() {
@Override
public void onComplete(Map<String, String> errors) {
- assertNotNull(errors);
- for(int i = 0; i < filesToUpload.size(); i++){
- if(i % 2 == 0){
- assertTrue(errors.containsKey(filesToUpload.get(i).getName()));
- assertEquals(FileManager.buildErrorString(Result.OUT_OF_MEMORY,
- failureReason), errors.get(filesToUpload.get(i).getName()));
- }else{
- assertFalse(errors.containsKey(filesToUpload.get(i).getName()));
- }
- }
- List <String> uploadedFileNames = fileManager.getRemoteFileNames();
- for(int i = 0; i < filesToUpload.size(); i++){
- if(i % 2 == 0){
- assertFalse(uploadedFileNames.contains(filesToUpload.get(i).getName()));
- }else{
- assertTrue(uploadedFileNames.contains(filesToUpload.get(i).getName()));
- }
- }
+ assertTrue(errors.size() == 2);
}
});
}
});
+ assertFalse(fileManager.hasUploadedFile(validFile) && fileManager.hasUploadedFile(validFile3));
+ assertTrue(fileManager.hasUploadedFile(validFile2));
}
+ /**
+ * Testing uploading multiple SdlArtwork files.
+ */
public void testMultipleArtworkUploadSuccess(){
ISdl internalInterface = mock(ISdl.class);
- doAnswer(onListFilesSuccess).when(internalInterface).sendRPCRequest(any(ListFiles.class));
- doAnswer(onSendRequestsSuccess).when(internalInterface).sendRequests(any(List.class), any(OnMultipleRequestListener.class));
+ doAnswer(onListFilesSuccess).when(internalInterface).sendRPC(any(ListFiles.class));
+ doAnswer(onListFileUploadSuccess).when(internalInterface).sendRequests(any(List.class), any(OnMultipleRequestListener.class));
- final FileManager fileManager = new FileManager(internalInterface, mTestContext);
+ FileManagerConfig fileManagerConfig = new FileManagerConfig();
+ final FileManager fileManager = new FileManager(internalInterface, mTestContext, fileManagerConfig);
fileManager.start(new CompletionListener() {
@Override
public void onComplete(boolean success) {
@@ -843,16 +810,20 @@ public class FileManagerTests extends AndroidTestCase2 {
});
}
+ /**
+ * Testing uploading persistent SdlFile
+ */
public void testPersistentFileUploaded(){
ISdl internalInterface = mock(ISdl.class);
- doAnswer(onListFilesSuccess).when(internalInterface).sendRPCRequest(any(ListFiles.class));
+ doAnswer(onListFilesSuccess).when(internalInterface).sendRPC(any(ListFiles.class));
final SdlFile file = new SdlFile();
file.setName(Test.GENERAL_STRING_LIST.get(0));
file.setPersistent(true);
- final FileManager fileManager = new FileManager(internalInterface, mTestContext);
+ FileManagerConfig fileManagerConfig = new FileManagerConfig();
+ final FileManager fileManager = new FileManager(internalInterface, mTestContext, fileManagerConfig);
fileManager.start(new CompletionListener() {
@Override
public void onComplete(boolean success) {
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/proxy/RPCRequestFactory.java b/android/sdl_android/src/main/java/com/smartdevicelink/proxy/RPCRequestFactory.java
index e787fb77d..d046fe5ad 100644
--- a/android/sdl_android/src/main/java/com/smartdevicelink/proxy/RPCRequestFactory.java
+++ b/android/sdl_android/src/main/java/com/smartdevicelink/proxy/RPCRequestFactory.java
@@ -1022,7 +1022,7 @@ public class RPCRequestFactory {
{
DeviceInfo msg = new DeviceInfo();
msg.setHardware(android.os.Build.MODEL);
- msg.setOs(DeviceInfo.DEVICE_OS);
+ msg.setOs("Android");
msg.setOsVersion(Build.VERSION.RELEASE);
msg.setCarrier(carrierName);
return msg;
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java b/android/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java
index 5c886ff67..f6f5c7688 100644
--- a/android/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java
+++ b/android/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java
@@ -6721,7 +6721,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
DeviceInfo deviceInfo = new DeviceInfo();
deviceInfo.setHardware(android.os.Build.MODEL);
- deviceInfo.setOs(DeviceInfo.DEVICE_OS);
+ deviceInfo.setOs("Android");
deviceInfo.setOsVersion(Build.VERSION.RELEASE);
deviceInfo.setCarrier(carrierName);