diff options
18 files changed, 513 insertions, 95 deletions
diff --git a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java index 09cf35a82..bedeb0a39 100755 --- a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java +++ b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java @@ -7,11 +7,9 @@ import android.util.Log; import com.smartdevicelink.transport.SdlBroadcastReceiver; import com.smartdevicelink.transport.SdlRouterService; -import com.smartdevicelink.transport.TransportConstants; public class SdlReceiver extends SdlBroadcastReceiver { private static final String TAG = "SdlBroadcastReciever"; - public static final String RECONNECT_LANG_CHANGE = "RECONNECT_LANG_CHANGE"; @Override public void onSdlEnabled(Context context, Intent intent) { @@ -36,16 +34,5 @@ public class SdlReceiver extends SdlBroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); // Required if overriding this method - - if (intent != null) { - String action = intent.getAction(); - if (action != null){ - if(action.equalsIgnoreCase(TransportConstants.START_ROUTER_SERVICE_ACTION)) { - if (intent.getBooleanExtra(RECONNECT_LANG_CHANGE, false)) { - onSdlEnabled(context, intent); - } - } - } - } } }
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/file/SdlArtworkTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/file/filetypes/SdlArtworkTests.java index 395b06e27..395b06e27 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/file/SdlArtworkTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/file/filetypes/SdlArtworkTests.java diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/file/filetypes/SdlFileTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/file/filetypes/SdlFileTests.java new file mode 100644 index 000000000..7dd13ec7c --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/file/filetypes/SdlFileTests.java @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.file.filetypes; + +import com.smartdevicelink.AndroidTestCase2; +import com.smartdevicelink.test.Test; + +public class SdlFileTests extends AndroidTestCase2 { + + public void testConstructorWithNoParams() { + SdlFile sdlFile; + + // Case 1 (Setting data) + sdlFile = new SdlFile(); + sdlFile.setFileData(Test.GENERAL_BYTE_ARRAY); + assertEquals(sdlFile.getFileData(), Test.GENERAL_BYTE_ARRAY); + sdlFile.setName(null); + assertEquals(sdlFile.getName(), "e9800998ecf8427e"); + sdlFile.setName(Test.GENERAL_STRING); + assertEquals(sdlFile.getName(), Test.GENERAL_STRING); + sdlFile.setType(Test.GENERAL_FILETYPE); + assertEquals(sdlFile.getType(), Test.GENERAL_FILETYPE); + sdlFile.setPersistent(Test.GENERAL_BOOLEAN); + assertEquals(sdlFile.isPersistent(), Test.GENERAL_BOOLEAN); + + // Case 2 (Setting resourceId) + sdlFile = new SdlFile(); + sdlFile.setResourceId(Test.GENERAL_INTEGER); + assertEquals((Integer) sdlFile.getResourceId(), Test.GENERAL_INTEGER); + sdlFile.setName(null); + assertEquals(sdlFile.getName(), "ec9ebc78777cf40d"); + sdlFile.setName(Test.GENERAL_STRING); + assertEquals(sdlFile.getName(), Test.GENERAL_STRING); + sdlFile.setType(Test.GENERAL_FILETYPE); + assertEquals(sdlFile.getType(), Test.GENERAL_FILETYPE); + sdlFile.setPersistent(Test.GENERAL_BOOLEAN); + assertEquals(sdlFile.isPersistent(), Test.GENERAL_BOOLEAN); + + // Case 3 (Setting URI) + sdlFile = new SdlFile(); + sdlFile.setUri(Test.GENERAL_URI); + assertEquals(sdlFile.getUri(), Test.GENERAL_URI); + sdlFile.setName(null); + assertEquals(sdlFile.getName(), "d3467db131372140"); + sdlFile.setName(Test.GENERAL_STRING); + assertEquals(sdlFile.getName(), Test.GENERAL_STRING); + sdlFile.setType(Test.GENERAL_FILETYPE); + assertEquals(sdlFile.getType(), Test.GENERAL_FILETYPE); + sdlFile.setPersistent(Test.GENERAL_BOOLEAN); + assertEquals(sdlFile.isPersistent(), Test.GENERAL_BOOLEAN); + } + + public void testConstructorWithResourceId() { + // Case1 (Set the name manually) + SdlFile sdlFile1 = new SdlFile(Test.GENERAL_STRING, Test.GENERAL_FILETYPE, Test.GENERAL_INTEGER, Test.GENERAL_BOOLEAN); + assertEquals(sdlFile1.getName(), Test.GENERAL_STRING); + assertEquals(sdlFile1.getType(), Test.GENERAL_FILETYPE); + assertEquals((Integer) sdlFile1.getResourceId(), Test.GENERAL_INTEGER); + assertEquals(sdlFile1.isPersistent(), Test.GENERAL_BOOLEAN); + + // Case2 (Let the library generate a name) + SdlFile sdlFile2 = new SdlFile(null, Test.GENERAL_FILETYPE, Test.GENERAL_INTEGER, Test.GENERAL_BOOLEAN); + SdlFile sdlFile3 = new SdlFile(null, Test.GENERAL_FILETYPE, Test.GENERAL_INTEGER, Test.GENERAL_BOOLEAN); + assertEquals(sdlFile2.getName(), sdlFile3.getName()); + assertEquals(sdlFile2.getName(), "ec9ebc78777cf40d"); + assertEquals(sdlFile2.getType(), Test.GENERAL_FILETYPE); + assertEquals((Integer) sdlFile2.getResourceId(), Test.GENERAL_INTEGER); + assertEquals(sdlFile2.isPersistent(), Test.GENERAL_BOOLEAN); + } + + public void testConstructorWithData() { + // Case1 (Set the name manually) + SdlFile sdlFile1 = new SdlFile(Test.GENERAL_STRING, Test.GENERAL_FILETYPE, Test.GENERAL_BYTE_ARRAY, Test.GENERAL_BOOLEAN); + assertEquals(sdlFile1.getName(), Test.GENERAL_STRING); + assertEquals(sdlFile1.getType(), Test.GENERAL_FILETYPE); + assertEquals(sdlFile1.getFileData(), Test.GENERAL_BYTE_ARRAY); + assertEquals(sdlFile1.isPersistent(), Test.GENERAL_BOOLEAN); + + // Case2 (Let the library generate a name) + SdlFile sdlFile2 = new SdlFile(null, Test.GENERAL_FILETYPE, Test.GENERAL_BYTE_ARRAY, Test.GENERAL_BOOLEAN); + SdlFile sdlFile3 = new SdlFile(null, Test.GENERAL_FILETYPE, Test.GENERAL_BYTE_ARRAY, Test.GENERAL_BOOLEAN); + assertEquals(sdlFile2.getName(), sdlFile3.getName()); + assertEquals(sdlFile2.getName(), "e9800998ecf8427e"); + assertEquals(sdlFile2.getType(), Test.GENERAL_FILETYPE); + assertEquals(sdlFile2.getFileData(), Test.GENERAL_BYTE_ARRAY); + assertEquals(sdlFile2.isPersistent(), Test.GENERAL_BOOLEAN); + } + + public void testConstructorWithUri() { + // Case1 (Set the name manually) + SdlFile sdlFile1 = new SdlFile(Test.GENERAL_STRING, Test.GENERAL_FILETYPE, Test.GENERAL_URI, Test.GENERAL_BOOLEAN); + assertEquals(sdlFile1.getName(), Test.GENERAL_STRING); + assertEquals(sdlFile1.getType(), Test.GENERAL_FILETYPE); + assertEquals(sdlFile1.getUri(), Test.GENERAL_URI); + assertEquals(sdlFile1.isPersistent(), Test.GENERAL_BOOLEAN); + + // Case2 (Let the library generate a name) + SdlFile sdlFile2 = new SdlFile(null, Test.GENERAL_FILETYPE, Test.GENERAL_URI, Test.GENERAL_BOOLEAN); + SdlFile sdlFile3 = new SdlFile(null, Test.GENERAL_FILETYPE, Test.GENERAL_URI, Test.GENERAL_BOOLEAN); + assertEquals(sdlFile2.getName(), sdlFile3.getName()); + assertEquals(sdlFile2.getName(), "d3467db131372140"); + assertEquals(sdlFile2.getType(), Test.GENERAL_FILETYPE); + assertEquals(sdlFile2.getUri(), Test.GENERAL_URI); + assertEquals(sdlFile2.isPersistent(), Test.GENERAL_BOOLEAN); + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/video/VideoStreamManagerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/video/VideoStreamManagerTests.java index 34a452f06..e5c8c8ad8 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/video/VideoStreamManagerTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/video/VideoStreamManagerTests.java @@ -19,8 +19,11 @@ import com.smartdevicelink.proxy.interfaces.OnSystemCapabilityListener; import com.smartdevicelink.proxy.rpc.ImageResolution; import com.smartdevicelink.proxy.rpc.OnHMIStatus; import com.smartdevicelink.proxy.rpc.OnTouchEvent; +import com.smartdevicelink.proxy.rpc.RegisterAppInterface; +import com.smartdevicelink.proxy.rpc.RegisterAppInterfaceResponse; import com.smartdevicelink.proxy.rpc.TouchCoord; import com.smartdevicelink.proxy.rpc.TouchEvent; +import com.smartdevicelink.proxy.rpc.VehicleType; import com.smartdevicelink.proxy.rpc.enums.HMILevel; import com.smartdevicelink.proxy.rpc.enums.SystemCapabilityType; import com.smartdevicelink.proxy.rpc.enums.TouchType; @@ -99,6 +102,12 @@ public class VideoStreamManagerTests extends AndroidTestCase2 { ISdl internalInterface = mock(ISdl.class); when(internalInterface.getProtocolVersion()).thenReturn(new Version(5,1,0)); + RegisterAppInterfaceResponse mockRegisterAppInterfaceResponse = new RegisterAppInterfaceResponse(); + VehicleType mockVehicleType = new VehicleType(); + mockVehicleType.setMake("Ford"); + mockRegisterAppInterfaceResponse.setVehicleType(mockVehicleType); + when(internalInterface.getRegisterAppInterfaceResponse()).thenReturn(mockRegisterAppInterfaceResponse); + Answer<Void> onAddServiceListener = new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) { @@ -126,6 +135,13 @@ public class VideoStreamManagerTests extends AndroidTestCase2 { final ISdl internalInterface = mock(ISdl.class); when(internalInterface.getProtocolVersion()).thenReturn((new Version(5,0,0))); + + RegisterAppInterfaceResponse mockRegisterAppInterfaceResponse = new RegisterAppInterfaceResponse(); + VehicleType mockVehicleType = new VehicleType(); + mockVehicleType.setMake("Ford"); + mockRegisterAppInterfaceResponse.setVehicleType(mockVehicleType); + when(internalInterface.getRegisterAppInterfaceResponse()).thenReturn(mockRegisterAppInterfaceResponse); + when(internalInterface.isCapabilitySupported(SystemCapabilityType.VIDEO_STREAMING)).thenReturn(true); final VideoStreamManager videoStreamManager = new VideoStreamManager(internalInterface); @@ -143,6 +159,12 @@ public class VideoStreamManagerTests extends AndroidTestCase2 { public void testRemoteDisplayStream(){ ISdl internalInterface = mock(ISdl.class); + RegisterAppInterfaceResponse mockRegisterAppInterfaceResponse = new RegisterAppInterfaceResponse(); + VehicleType mockVehicleType = new VehicleType(); + mockVehicleType.setMake("Ford"); + mockRegisterAppInterfaceResponse.setVehicleType(mockVehicleType); + when(internalInterface.getRegisterAppInterfaceResponse()).thenReturn(mockRegisterAppInterfaceResponse); + final Set<Object> listenerSet = new HashSet<>(); when(internalInterface.getProtocolVersion()).thenReturn(new Version(5,0,0)); @@ -252,6 +274,13 @@ public class VideoStreamManagerTests extends AndroidTestCase2 { public void testConvertTouchEvent() { ISdl internalInterface = mock(ISdl.class); + + RegisterAppInterfaceResponse mockRegisterAppInterfaceResponse = new RegisterAppInterfaceResponse(); + VehicleType mockVehicleType = new VehicleType(); + mockVehicleType.setMake("Ford"); + mockRegisterAppInterfaceResponse.setVehicleType(mockVehicleType); + when(internalInterface.getRegisterAppInterfaceResponse()).thenReturn(mockRegisterAppInterfaceResponse); + VideoStreamManager videoStreamManager = new VideoStreamManager(internalInterface); List<MotionEvent> motionEventList; long e1TS = 1558124390L, e2TS = 1558125390L, e3TS = 1558126390L; @@ -467,6 +496,12 @@ public class VideoStreamManagerTests extends AndroidTestCase2 { private void assertMotionEventWithScale(int width, int height, float scale) { ISdl internalInterface = mock(ISdl.class); + RegisterAppInterfaceResponse mockRegisterAppInterfaceResponse = new RegisterAppInterfaceResponse(); + VehicleType mockVehicleType = new VehicleType(); + mockVehicleType.setMake("Ford"); + mockRegisterAppInterfaceResponse.setVehicleType(mockVehicleType); + when(internalInterface.getRegisterAppInterfaceResponse()).thenReturn(mockRegisterAppInterfaceResponse); + // Preferred Resolution capability ImageResolution resolution = new ImageResolution(width, height); diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java index 68465b2d4..602e638ae 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java @@ -1,6 +1,7 @@ package com.smartdevicelink.test; import android.graphics.Color; +import android.net.Uri; import android.util.Log; import com.smartdevicelink.R; @@ -264,6 +265,7 @@ public class Test { public static final ImageField GENERAL_IMAGEFIELD = new ImageField(); public static final DeviceInfo GENERAL_DEVICEINFO = new DeviceInfo(); public static final AppInfo GENERAL_APPINFO = new AppInfo(); + public static final Uri GENERAL_URI = Uri.parse("http://www.google.com");; public static final LayoutMode GENERAL_LAYOUTMODE = LayoutMode.LIST_ONLY; public static final MenuParams GENERAL_MENUPARAMS = new MenuParams(); public static final SoftButton GENERAL_SOFTBUTTON = new SoftButton(); diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/proxy/SystemCapabilityManagerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/proxy/SystemCapabilityManagerTests.java index 13815b8d0..489964d7e 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/proxy/SystemCapabilityManagerTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/proxy/SystemCapabilityManagerTests.java @@ -951,6 +951,9 @@ public class SystemCapabilityManagerTests extends AndroidTestCase2 { public void getCapability(SystemCapabilityType systemCapabilityType, OnSystemCapabilityListener scListener) { } @Override + public RegisterAppInterfaceResponse getRegisterAppInterfaceResponse(){return null;} + + @Override public SdlMsgVersion getSdlMsgVersion(){ return null; } diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/video/VideoStreamingParametersTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/video/VideoStreamingParametersTest.java index a81f69eb3..b894eca12 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/video/VideoStreamingParametersTest.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/video/VideoStreamingParametersTest.java @@ -81,6 +81,66 @@ public class VideoStreamingParametersTest extends AndroidTestCase2 { assertEquals(380, height); } + public void testUpdateScale_1_0_Ford_Resolution_800_354() { + preferredResolution = new ImageResolution(800, 354); + + capability.setScale(1.0); + capability.setPreferredResolution(preferredResolution); + + params.update(capability, "Ford"); + + int width = params.getResolution().getResolutionWidth(); + int height = params.getResolution().getResolutionHeight(); + + assertEquals(800, width); + assertEquals(354, height); + } + + public void testUpdateScale_1_3_Lincoln_Resolution_600_900() { + preferredResolution = new ImageResolution(600, 900); + + capability.setScale(1.0); + capability.setPreferredResolution(preferredResolution); + + params.update(capability, "Lincoln"); + + int width = params.getResolution().getResolutionWidth(); + int height = params.getResolution().getResolutionHeight(); + + assertEquals(450, width); + assertEquals(676, height); + } + + public void testUpdateScale_1_3_Ford_Resolution_900_600() { + preferredResolution = new ImageResolution(900, 600); + + capability.setScale(1.0); + capability.setPreferredResolution(preferredResolution); + + params.update(capability, "Ford"); + + int width = params.getResolution().getResolutionWidth(); + int height = params.getResolution().getResolutionHeight(); + + assertEquals(676, width); + assertEquals(450, height); + } + + public void testUpdateScale_1_0_Toyota_Resolution_900_600() { + preferredResolution = new ImageResolution(900, 600); + + capability.setScale(1.0); + capability.setPreferredResolution(preferredResolution); + + params.update(capability, "Toyota"); + + int width = params.getResolution().getResolutionWidth(); + int height = params.getResolution().getResolutionHeight(); + + assertEquals(900, width); + assertEquals(600, height); + } + public void testUpdateCapabilityFormat(){ VideoStreamingCapability capability = new VideoStreamingCapability(); capability.setMaxBitrate(10000); diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/SdlManager.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/SdlManager.java index 37a14aa42..f87839254 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/managers/SdlManager.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/SdlManager.java @@ -867,6 +867,11 @@ public class SdlManager extends BaseSdlManager{ } @Override + public RegisterAppInterfaceResponse getRegisterAppInterfaceResponse() { + return proxy.getRegisterAppInterfaceResponse(); + } + + @Override public boolean isCapabilitySupported(SystemCapabilityType systemCapabilityType){ return proxy.isCapabilitySupported(systemCapabilityType); } diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java index ad837aae3..5f14cb2ed 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java @@ -55,34 +55,34 @@ public class SdlArtwork extends SdlFile implements Cloneable{ /** * Creates a new instance of SdlArtwork - * @param fileName a String value representing the name that will be used to store the file in the head unit + * @param fileName a String value representing the name that will be used to store the file in the head unit. You can pass null if you want the library to auto generate the name * @param fileType a FileType enum value representing the type of the file * @param id an int value representing the android resource id of the file * @param persistentFile a boolean value that indicates if the file is meant to persist between sessions / ignition cycles */ - public SdlArtwork(@NonNull String fileName, @NonNull FileType fileType, int id, boolean persistentFile) { + public SdlArtwork(String fileName, @NonNull FileType fileType, int id, boolean persistentFile) { super(fileName, fileType, id, persistentFile); } /** * Creates a new instance of SdlArtwork - * @param fileName a String value representing the name that will be used to store the file in the head unit + * @param fileName a String value representing the name that will be used to store the file in the head unit. You can pass null if you want the library to auto generate the name * @param fileType a FileType enum value representing the type of the file * @param uri a URI value representing a file's location. Currently, it only supports local files * @param persistentFile a boolean value that indicates if the file is meant to persist between sessions / ignition cycles */ - public SdlArtwork(@NonNull String fileName, @NonNull FileType fileType, Uri uri, boolean persistentFile) { + public SdlArtwork(String fileName, @NonNull FileType fileType, Uri uri, boolean persistentFile) { super(fileName, fileType, uri, persistentFile); } /** * Creates a new instance of SdlArtwork - * @param fileName a String value representing the name that will be used to store the file in the head unit + * @param fileName a String value representing the name that will be used to store the file in the head unit. You can pass null if you want the library to auto generate the name * @param fileType a FileType enum value representing the type of the file * @param data a byte array representing the data of the file * @param persistentFile a boolean value that indicates if the file is meant to persist between sessions / ignition cycles */ - public SdlArtwork(@NonNull String fileName, @NonNull FileType fileType, byte[] data, boolean persistentFile) { + public SdlArtwork(String fileName, @NonNull FileType fileType, byte[] data, boolean persistentFile) { super(fileName, fileType, data, persistentFile); } diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlFile.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlFile.java index f028119c3..5d7e73f5c 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlFile.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlFile.java @@ -38,6 +38,9 @@ import android.support.annotation.NonNull; import com.smartdevicelink.proxy.rpc.enums.FileType; import com.smartdevicelink.proxy.rpc.enums.StaticIconName; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + /** * A class representing data to be uploaded to core */ @@ -49,6 +52,7 @@ public class SdlFile{ private FileType fileType; private boolean persistentFile; private boolean isStaticIcon; + private boolean shouldAutoGenerateName; // Overwrite property by default is set to true in SdlFile constructors indicating that a file can be overwritten private boolean overwrite = true; @@ -59,44 +63,44 @@ public class SdlFile{ /** * Creates a new instance of SdlFile - * @param fileName a String value representing the name that will be used to store the file in the head unit + * @param fileName a String value representing the name that will be used to store the file in the head unit. You can pass null if you want the library to auto generate the name * @param fileType a FileType enum value representing the type of the file * @param id an int value representing the android resource id of the file * @param persistentFile a boolean value that indicates if the file is meant to persist between sessions / ignition cycles */ - public SdlFile(@NonNull String fileName, @NonNull FileType fileType, int id, boolean persistentFile){ - this.fileName = fileName; - this.fileType = fileType; - this.id = id; - this.persistentFile = persistentFile; + public SdlFile(String fileName, @NonNull FileType fileType, int id, boolean persistentFile){ + setName(fileName); + setType(fileType); + setResourceId(id); + setPersistent(persistentFile); } /** * Creates a new instance of SdlFile - * @param fileName a String value representing the name that will be used to store the file in the head unit + * @param fileName a String value representing the name that will be used to store the file in the head unit. You can pass null if you want the library to auto generate the name * @param fileType a FileType enum value representing the type of the file * @param uri a URI value representing a file's location. Currently, it only supports local files * @param persistentFile a boolean value that indicates if the file is meant to persist between sessions / ignition cycles */ - public SdlFile(@NonNull String fileName, @NonNull FileType fileType, Uri uri, boolean persistentFile){ - this.fileName = fileName; - this.fileType = fileType; - this.uri = uri; - this.persistentFile = persistentFile; + public SdlFile(String fileName, @NonNull FileType fileType, Uri uri, boolean persistentFile){ + setName(fileName); + setType(fileType); + setUri(uri); + setPersistent(persistentFile); } /** * Creates a new instance of SdlFile - * @param fileName a String value representing the name that will be used to store the file in the head unit + * @param fileName a String value representing the name that will be used to store the file in the head unit. You can pass null if you want the library to auto generate the name * @param fileType a FileType enum value representing the type of the file * @param data a byte array representing the data of the file * @param persistentFile a boolean value that indicates if the file is meant to persist between sessions / ignition cycles */ - public SdlFile(@NonNull String fileName, @NonNull FileType fileType, byte[] data, boolean persistentFile){ - this.fileName = fileName; - this.fileType = fileType; - this.fileData = data; - this.persistentFile = persistentFile; + public SdlFile(String fileName, @NonNull FileType fileType, byte[] data, boolean persistentFile){ + setName(fileName); + setType(fileType); + setFileData(data); + setPersistent(persistentFile); } /** @@ -104,18 +108,30 @@ public class SdlFile{ * @param staticIconName a StaticIconName enum value representing the name of a static file that comes pre-shipped with the head unit */ public SdlFile(@NonNull StaticIconName staticIconName){ - this.fileName = staticIconName.toString(); - this.fileData = staticIconName.toString().getBytes(); - this.persistentFile = false; - this.isStaticIcon = true; + setName(staticIconName.toString()); + setFileData(staticIconName.toString().getBytes()); + setPersistent(false); + setStaticIcon(true); } /** * Sets the name of the file - * @param fileName a String value representing the name that will be used to store the file in the head unit + * @param fileName a String value representing the name that will be used to store the file in the head unit. You can pass null if you want the library to auto generate the name */ - public void setName(@NonNull String fileName){ - this.fileName = fileName; + public void setName(String fileName) { + if (fileName != null) { + this.shouldAutoGenerateName = false; + this.fileName = fileName; + } else { + this.shouldAutoGenerateName = true; + if (this.getFileData() != null) { + this.fileName = generateFileNameFromData(this.getFileData()); + } else if (this.getUri() != null) { + this.fileName = generateFileNameFromUri(this.getUri()); + } else if (this.getResourceId() != 0) { + this.fileName = generateFileNameFromResourceId(this.getResourceId()); + } + } } /** @@ -132,6 +148,9 @@ public class SdlFile{ */ public void setResourceId(int id){ this.id = id; + if (shouldAutoGenerateName) { + this.fileName = generateFileNameFromResourceId(id); + } } /** @@ -148,6 +167,9 @@ public class SdlFile{ */ public void setUri(Uri uri){ this.uri = uri; + if (shouldAutoGenerateName && uri != null) { + this.fileName = generateFileNameFromUri(uri); + } } /** @@ -164,6 +186,9 @@ public class SdlFile{ */ public void setFileData(byte[] data){ this.fileData = data; + if (shouldAutoGenerateName && data != null) { + this.fileName = generateFileNameFromData(data); + } } /** @@ -239,6 +264,51 @@ public class SdlFile{ } /** + * Generates a file name from data by hashing the data and returning the last 16 chars + * @param data a byte array representing the data of the file + * @return a String value representing the name that will be used to store the file in the head unit + */ + private String generateFileNameFromData(@NonNull byte[] data) { + String result; + MessageDigest messageDigest; + try { + messageDigest = MessageDigest.getInstance("md5"); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + return null; + } + byte[] hash = new byte[0]; + if (messageDigest != null) { + hash = messageDigest.digest(data); + } + StringBuilder stringBuilder = new StringBuilder(2 * hash.length); + for (byte b : hash) { + stringBuilder.append(String.format("%02x", b & 0xff)); + } + String hashString = stringBuilder.toString(); + result = hashString.substring(hashString.length() - 16); + return result; + } + + /** + * Generates a file name from uri by hashing the uri string and returning the last 16 chars + * @param uri a URI value representing a file's location + * @return a String value representing the name that will be used to store the file in the head unit + */ + private String generateFileNameFromUri(@NonNull Uri uri) { + return generateFileNameFromData(uri.toString().getBytes()); + } + + /** + * Generates a file name from resourceId by hashing the id and returning the last 16 chars + * @param id an int value representing the android resource id of the file + * @return a String value representing the name that will be used to store the file in the head unit + */ + private String generateFileNameFromResourceId(int id) { + return generateFileNameFromData("ResourceId".concat(String.valueOf(id)).getBytes()); + } + + /** * Used to compile hashcode for SdlFile for use to compare in overridden equals method * @return Custom hashcode of SdlFile variables */ @@ -270,4 +340,4 @@ public class SdlFile{ // return comparison return hashCode() == o.hashCode(); } -}
\ No newline at end of file +} diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/video/VideoStreamManager.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/video/VideoStreamManager.java index f09897e56..2741ca62c 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/managers/video/VideoStreamManager.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/video/VideoStreamManager.java @@ -74,6 +74,7 @@ import com.smartdevicelink.util.Version; import java.lang.ref.WeakReference; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.FutureTask; @@ -95,6 +96,8 @@ public class VideoStreamManager extends BaseVideoStreamManager { private IVideoStreamListener streamListener; private boolean isTransportAvailable = false; private boolean hasStarted; + private List<HMILevel> streamableLevels = Arrays.asList(HMILevel.HMI_FULL, HMILevel.HMI_LIMITED); + private String vehicleMake = null; // INTERNAL INTERFACES @@ -151,10 +154,10 @@ public class VideoStreamManager extends BaseVideoStreamManager { } HMILevel prevHMILevel = hmiLevel; hmiLevel = onHMIStatus.getHmiLevel(); - if(hmiLevel.equals(HMILevel.HMI_FULL)){ + if (streamableLevels.contains(hmiLevel)) { checkState(); } - if (hasStarted && (prevHMILevel == HMILevel.HMI_FULL || prevHMILevel == HMILevel.HMI_LIMITED) && (hmiLevel == HMILevel.HMI_NONE || hmiLevel == HMILevel.HMI_BACKGROUND)){ + if (hasStarted && (streamableLevels.contains(prevHMILevel)) && (!streamableLevels.contains(hmiLevel))) { internalInterface.stopVideoService(); } } @@ -176,10 +179,12 @@ public class VideoStreamManager extends BaseVideoStreamManager { }; // MANAGER APIs - public VideoStreamManager(ISdl internalInterface){ super(internalInterface); + if(internalInterface.getRegisterAppInterfaceResponse().getVehicleType() != null) { + vehicleMake = internalInterface.getRegisterAppInterfaceResponse().getVehicleType().getMake(); + } virtualDisplayEncoder = new VirtualDisplayEncoder(); hmiLevel = HMILevel.HMI_NONE; @@ -205,7 +210,7 @@ public class VideoStreamManager extends BaseVideoStreamManager { if(this.getState() == SETTING_UP && isTransportAvailable && hmiLevel != null - && hmiLevel.equals(HMILevel.HMI_FULL) + && streamableLevels.contains(hmiLevel) && parameters != null){ stateMachine.transitionToState(StreamingStateMachine.READY); transitionToState(READY); @@ -218,7 +223,7 @@ public class VideoStreamManager extends BaseVideoStreamManager { @Override public void onCapabilityRetrieved(Object capability) { VideoStreamingParameters params = new VideoStreamingParameters(); - params.update((VideoStreamingCapability)capability); //Streaming parameters are ready time to stream + params.update((VideoStreamingCapability)capability, vehicleMake); //Streaming parameters are ready time to stream VideoStreamManager.this.parameters = params; checkState(); @@ -270,7 +275,7 @@ public class VideoStreamManager extends BaseVideoStreamManager { @Override public void onCapabilityRetrieved(Object capability) { VideoStreamingParameters params = new VideoStreamingParameters(); - params.update((VideoStreamingCapability)capability); //Streaming parameters are ready time to stream + params.update((VideoStreamingCapability)capability, vehicleMake); //Streaming parameters are ready time to stream startStreaming(params, encrypted); } @@ -303,8 +308,8 @@ public class VideoStreamManager extends BaseVideoStreamManager { */ protected void startStreaming(VideoStreamingParameters parameters, boolean encrypted){ this.parameters = parameters; - if(hmiLevel != HMILevel.HMI_FULL){ - Log.e(TAG, "Cannot start video service if HMILevel is not FULL."); + if (!streamableLevels.contains(hmiLevel)) { + Log.e(TAG, "Cannot start video service if HMILevel is not FULL or LIMITED."); return; } //Start the video service @@ -399,7 +404,7 @@ public class VideoStreamManager extends BaseVideoStreamManager { * @return boolean (true = yes, false = no) */ public boolean isStreaming(){ - return (stateMachine.getState() == StreamingStateMachine.STARTED) && (hmiLevel == HMILevel.HMI_FULL); + return (stateMachine.getState() == StreamingStateMachine.STARTED) && (streamableLevels.contains(hmiLevel)); } /** @@ -407,7 +412,7 @@ public class VideoStreamManager extends BaseVideoStreamManager { * @return boolean (true = not paused, false = paused) */ public boolean isPaused(){ - return (hasStarted && stateMachine.getState() == StreamingStateMachine.STOPPED) || (hmiLevel != HMILevel.HMI_FULL); + return (hasStarted && stateMachine.getState() == StreamingStateMachine.STOPPED) || (!streamableLevels.contains(hmiLevel)); } /** 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 f6f5c7688..c69011e13 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 @@ -445,6 +445,11 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> }
@Override
+ public RegisterAppInterfaceResponse getRegisterAppInterfaceResponse() {
+ return SdlProxyBase.this.getRegisterAppInterfaceResponse();
+ }
+
+ @Override
public void getCapability(SystemCapabilityType systemCapabilityType, OnSystemCapabilityListener scListener) {
SdlProxyBase.this.getCapability(systemCapabilityType, scListener);
}
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java index bd86f86c2..3313fd0f3 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java @@ -1344,6 +1344,7 @@ public class SdlRouterService extends Service{ // If this is the first time the service has ever connected to this device we want // to ensure we have a record of it setSDLConnectedStatus(address, false); + return FOREGROUND_TIMEOUT; } } // If this is a new device or hasn't connected through SDL we want to limit the exposure @@ -1517,26 +1518,21 @@ public class SdlRouterService extends Service{ private void exitForeground(){ synchronized (NOTIFICATION_LOCK) { if (isForeground && !isPrimaryTransportConnected()) { //Ensure that the service is in the foreground and no longer connected to a transport - this.stopForeground(true); + DebugTool.logInfo("SdlRouterService to exit foreground"); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + this.stopForeground(Service.STOP_FOREGROUND_DETACH); + }else{ + stopForeground(false); + } NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); - if (notificationManager!= null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + if (notificationManager!= null){ try { - boolean notificationHasDisplayed = false; - StatusBarNotification[] notifications = notificationManager.getActiveNotifications(); - for (StatusBarNotification notification : notifications) { - if(notification != null && FOREGROUND_SERVICE_ID == notification.getId()){ - DebugTool.logInfo("Service notification is being displayed"); - notificationHasDisplayed = true; - break; - } - } - if (notificationHasDisplayed) { + notificationManager.cancelAll(); + if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { notificationManager.deleteNotificationChannel(SDL_NOTIFICATION_CHANNEL_ID); } - //else leave the notification channel alone to avoid deleting it before the - //foreground service notification has a chance to be displayed. - } catch (Exception e){ - DebugTool.logError("Issue when deleting notification channel", e); + } catch (Exception e) { + DebugTool.logError("Issue when removing notification and channel", e); } } isForeground = false; diff --git a/base/src/main/java/com/smartdevicelink/proxy/interfaces/ISdl.java b/base/src/main/java/com/smartdevicelink/proxy/interfaces/ISdl.java index 244c34395..3eb082670 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/interfaces/ISdl.java +++ b/base/src/main/java/com/smartdevicelink/proxy/interfaces/ISdl.java @@ -6,6 +6,7 @@ import com.smartdevicelink.protocol.enums.FunctionID; import com.smartdevicelink.protocol.enums.SessionType; import com.smartdevicelink.proxy.RPCMessage; import com.smartdevicelink.proxy.RPCRequest; +import com.smartdevicelink.proxy.rpc.RegisterAppInterfaceResponse; import com.smartdevicelink.proxy.rpc.SdlMsgVersion; import com.smartdevicelink.proxy.rpc.enums.SystemCapabilityType; import com.smartdevicelink.proxy.rpc.listeners.OnMultipleRequestListener; @@ -219,6 +220,12 @@ public interface ISdl { void getCapability(SystemCapabilityType systemCapabilityType, OnSystemCapabilityListener scListener); /** + * Get RegisterAppInterfaceResponse + * @return the RegisterAppInterfaceResponse if available, null if not + */ + RegisterAppInterfaceResponse getRegisterAppInterfaceResponse(); + + /** * Check if capability is supported * @param systemCapabilityType a system capability type that should be checked for support * @return Boolean whether or not the supplied capability type is supported on the connected module diff --git a/base/src/main/java/com/smartdevicelink/streaming/video/VideoStreamingParameters.java b/base/src/main/java/com/smartdevicelink/streaming/video/VideoStreamingParameters.java index ded3a9cd9..e689fb817 100644 --- a/base/src/main/java/com/smartdevicelink/streaming/video/VideoStreamingParameters.java +++ b/base/src/main/java/com/smartdevicelink/streaming/video/VideoStreamingParameters.java @@ -131,9 +131,54 @@ public class VideoStreamingParameters { * Update the values contained in the capability that should have been returned through the SystemCapabilityManager. * This update will use the most preferred streaming format from the module. * @param capability the video streaming capability returned from the SystemCapabilityManager + * @param vehicleMake the vehicle make from the RegisterAppInterfaceResponse * @see com.smartdevicelink.proxy.SystemCapabilityManager * @see VideoStreamingCapability */ + public void update(VideoStreamingCapability capability, String vehicleMake){ + if(capability.getMaxBitrate()!=null){ this.bitrate = capability.getMaxBitrate() * 1000; } // NOTE: the unit of maxBitrate in getSystemCapability is kbps. + double scale = DEFAULT_SCALE; + if(capability.getScale() != null) { scale = capability.getScale(); } + ImageResolution resolution = capability.getPreferredResolution(); + if(resolution!=null){ + + if (vehicleMake != null) { + if ((vehicleMake.contains("Ford") || vehicleMake.contains("Lincoln")) && ((resolution.getResolutionHeight() != null && resolution.getResolutionHeight() > 800) || (resolution.getResolutionWidth() != null && resolution.getResolutionWidth() > 800))) { + scale = 1.0 / 0.75; + } + } + + if(resolution.getResolutionHeight()!=null && resolution.getResolutionHeight() > 0){ this.resolution.setResolutionHeight((int)(resolution.getResolutionHeight() / scale)); } + if(resolution.getResolutionWidth()!=null && resolution.getResolutionWidth() > 0){ this.resolution.setResolutionWidth((int)(resolution.getResolutionWidth() / scale)); } + } + + // This should be the last call as it will return out once a suitable format is found + final List<VideoStreamingFormat> formats = capability.getSupportedFormats(); + if(formats != null && formats.size()>0){ + for(VideoStreamingFormat format : formats){ + for(int i = 0; i < CURRENTLY_SUPPORTED_FORMATS.length; i ++){ + if(CURRENTLY_SUPPORTED_FORMATS[i].equals(format) ){ + this.format = format; + return; + } + } + } + DebugTool.logWarning("The VideoStreamingFormat has not been updated because none of the provided formats are supported."); + + //TODO In the future we should set format to null, but might be a breaking change + // For now, format will remain whatever was set prior to this update + } + + } + + /** + * Update the values contained in the capability that should have been returned through the SystemCapabilityManager. + * This update will use the most preferred streaming format from the module. + * @param capability the video streaming capability returned from the SystemCapabilityManager + * @see com.smartdevicelink.proxy.SystemCapabilityManager + * @see VideoStreamingCapability + */ + @Deprecated public void update(VideoStreamingCapability capability){ if(capability.getMaxBitrate()!=null){ this.bitrate = capability.getMaxBitrate() * 1000; } // NOTE: the unit of maxBitrate in getSystemCapability is kbps. double scale = DEFAULT_SCALE; diff --git a/javaSE/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java b/javaSE/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java index eb947fe0a..fdfec6420 100644 --- a/javaSE/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java +++ b/javaSE/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java @@ -52,23 +52,23 @@ public class SdlArtwork extends SdlFile implements Cloneable{ /** * Creates a new instance of SdlArtwork - * @param fileName a String value representing the name that will be used to store the file in the head unit + * @param fileName a String value representing the name that will be used to store the file in the head unit. You can pass null if you want the library to auto generate the name * @param fileType a FileType enum value representing the type of the file * @param filePath a String value representing the the location of the file * @param persistentFile a boolean value that indicates if the file is meant to persist between sessions / ignition cycles */ - public SdlArtwork(@NonNull String fileName, @NonNull FileType fileType, String filePath, boolean persistentFile) { + public SdlArtwork(String fileName, @NonNull FileType fileType, String filePath, boolean persistentFile) { super(fileName, fileType, filePath, persistentFile); } /** * Creates a new instance of SdlArtwork - * @param fileName a String value representing the name that will be used to store the file in the head unit + * @param fileName a String value representing the name that will be used to store the file in the head unit. You can pass null if you want the library to auto generate the name * @param fileType a FileType enum value representing the type of the file * @param data a byte array representing the data of the file * @param persistentFile a boolean value that indicates if the file is meant to persist between sessions / ignition cycles */ - public SdlArtwork(@NonNull String fileName, @NonNull FileType fileType, byte[] data, boolean persistentFile) { + public SdlArtwork(String fileName, @NonNull FileType fileType, byte[] data, boolean persistentFile) { super(fileName, fileType, data, persistentFile); } diff --git a/javaSE/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlFile.java b/javaSE/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlFile.java index d3a8c1342..eac88d5e6 100644 --- a/javaSE/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlFile.java +++ b/javaSE/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlFile.java @@ -32,9 +32,13 @@ package com.smartdevicelink.managers.file.filetypes; import android.support.annotation.NonNull; + import com.smartdevicelink.proxy.rpc.enums.FileType; import com.smartdevicelink.proxy.rpc.enums.StaticIconName; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + /** * A class representing data to be uploaded to core */ @@ -45,6 +49,7 @@ public class SdlFile{ private FileType fileType; private boolean persistentFile; private boolean isStaticIcon; + private boolean shouldAutoGenerateName; // Overwrite property by default is set to true in SdlFile constructors indicating that a file can be overwritten private boolean overwrite = true; @@ -55,30 +60,30 @@ public class SdlFile{ /** * Creates a new instance of SdlFile - * @param fileName a String value representing the name that will be used to store the file in the head unit + * @param fileName a String value representing the name that will be used to store the file in the head unit. You can pass null if you want the library to auto generate the name * @param fileType a FileType enum value representing the type of the file * @param filePath a String value representing the the location of the file * @param persistentFile a boolean value that indicates if the file is meant to persist between sessions / ignition cycles */ - public SdlFile(@NonNull String fileName, @NonNull FileType fileType, String filePath, boolean persistentFile){ - this.fileName = fileName; - this.fileType = fileType; - this.filePath = filePath; - this.persistentFile = persistentFile; + public SdlFile(String fileName, @NonNull FileType fileType, String filePath, boolean persistentFile){ + setName(fileName); + setType(fileType); + setFilePath(filePath); + setPersistent(persistentFile); } /** * Creates a new instance of SdlFile - * @param fileName a String value representing the name that will be used to store the file in the head unit + * @param fileName a String value representing the name that will be used to store the file in the head unit. You can pass null if you want the library to auto generate the name * @param fileType a FileType enum value representing the type of the file * @param data a byte array representing the data of the file * @param persistentFile a boolean value that indicates if the file is meant to persist between sessions / ignition cycles */ - public SdlFile(@NonNull String fileName, @NonNull FileType fileType, byte[] data, boolean persistentFile){ - this.fileName = fileName; - this.fileType = fileType; - this.fileData = data; - this.persistentFile = persistentFile; + public SdlFile(String fileName, @NonNull FileType fileType, byte[] data, boolean persistentFile){ + setName(fileName); + setType(fileType); + setFileData(data); + setPersistent(persistentFile); } /** @@ -86,18 +91,28 @@ public class SdlFile{ * @param staticIconName a StaticIconName enum value representing the name of a static file that comes pre-shipped with the head unit */ public SdlFile(@NonNull StaticIconName staticIconName){ - this.fileName = staticIconName.toString(); - this.fileData = staticIconName.toString().getBytes(); - this.persistentFile = false; - this.isStaticIcon = true; + setName(staticIconName.toString()); + setFileData(staticIconName.toString().getBytes()); + setPersistent(false); + setStaticIcon(true); } /** * Sets the name of the file - * @param fileName a String value representing the name that will be used to store the file in the head unit + * @param fileName a String value representing the name that will be used to store the file in the head unit. You can pass null if you want the library to auto generate the name */ - public void setName(@NonNull String fileName){ - this.fileName = fileName; + public void setName(String fileName) { + if (fileName != null) { + this.shouldAutoGenerateName = false; + this.fileName = fileName; + } else { + this.shouldAutoGenerateName = true; + if (this.getFileData() != null) { + this.fileName = generateFileNameFromData(this.getFileData()); + } else if (this.getFilePath() != null) { + this.fileName = generateFileNameFromFilePath(this.getFilePath()); + } + } } /** @@ -114,6 +129,9 @@ public class SdlFile{ */ public void setFilePath(String filePath){ this.filePath = filePath; + if (shouldAutoGenerateName && filePath != null) { + this.fileName = generateFileNameFromFilePath(filePath); + } } /** @@ -130,6 +148,9 @@ public class SdlFile{ */ public void setFileData(byte[] data){ this.fileData = data; + if (shouldAutoGenerateName && data != null) { + this.fileName = generateFileNameFromData(data); + } } /** @@ -205,6 +226,42 @@ public class SdlFile{ } /** + * Generates a file name from data by hashing the data and returning the last 16 chars + * @param data a byte array representing the data of the file + * @return a String value representing the name that will be used to store the file in the head unit + */ + private String generateFileNameFromData(@NonNull byte[] data) { + String result; + MessageDigest messageDigest; + try { + messageDigest = MessageDigest.getInstance("md5"); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + return null; + } + byte[] hash = new byte[0]; + if (messageDigest != null) { + hash = messageDigest.digest(data); + } + StringBuilder stringBuilder = new StringBuilder(2 * hash.length); + for (byte b : hash) { + stringBuilder.append(String.format("%02x", b & 0xff)); + } + String hashString = stringBuilder.toString(); + result = hashString.substring(hashString.length() - 16); + return result; + } + + /** + * Generates a file name from filePath by hashing the filePath and returning the last 16 chars + * @param filePath a String value representing the the location of the file + * @return a String value representing the name that will be used to store the file in the head unit + */ + private String generateFileNameFromFilePath(String filePath) { + return generateFileNameFromData(filePath.getBytes()); + } + + /** * Used to compile hashcode for SdlFile for use to compare in equals method * @return Custom hashcode of SdlFile variables */ @@ -235,4 +292,4 @@ public class SdlFile{ // return comparison return hashCode() == o.hashCode(); } -}
\ No newline at end of file +} diff --git a/javaSE/src/main/java/com/smartdevicelink/managers/lifecycle/LifecycleManager.java b/javaSE/src/main/java/com/smartdevicelink/managers/lifecycle/LifecycleManager.java index 5ae5cd8f1..342a8be8a 100644 --- a/javaSE/src/main/java/com/smartdevicelink/managers/lifecycle/LifecycleManager.java +++ b/javaSE/src/main/java/com/smartdevicelink/managers/lifecycle/LifecycleManager.java @@ -1146,6 +1146,11 @@ public class LifecycleManager extends BaseLifecycleManager { } @Override + public RegisterAppInterfaceResponse getRegisterAppInterfaceResponse() { + return raiResponse; + } + + @Override public boolean isCapabilitySupported(SystemCapabilityType systemCapabilityType) { return LifecycleManager.this.systemCapabilityManager.isCapabilitySupported(systemCapabilityType); } |