diff options
author | Julian Kast <julian.kast@live.com> | 2022-06-21 10:14:59 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-21 10:14:59 -0400 |
commit | a0e389010b6dd2c514f70076fb92330ad5c5b3c8 (patch) | |
tree | 2db86ec6b6d8362711cb9a686893666ca87aef76 | |
parent | 16b2ab698a70294c0e060dd88883936a6288b6b8 (diff) | |
download | sdl_android-a0e389010b6dd2c514f70076fb92330ad5c5b3c8.tar.gz |
1738 - Soft button manager image upload fix (#1811)
* check isGraphicSupported in SoftButtonManager
* Remove log from testing
* fix formatting
* Unit test updates
* Add unit test to test when graphic is not supported. Align with iOS on uploading graphic when no capability is retrieved
* Fix logic to allow for static images to still be uploaded if dynamic are not supported
* Fix logic in uploading softbuttons, align with iOS
* Revert log back to a warning
* Add unit test
* Refactor isGraphicSupported to isDynamicGraphicSupported
3 files changed, 113 insertions, 4 deletions
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/SoftButtonManagerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/SoftButtonManagerTests.java index 67e7384e9..7e0890e18 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/SoftButtonManagerTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/SoftButtonManagerTests.java @@ -140,6 +140,7 @@ public class SoftButtonManagerTests { taskmaster.start(); when(internalInterface.getTaskmaster()).thenReturn(taskmaster); softButtonManager = new SoftButtonManager(internalInterface, fileManager); + softButtonManager.isDynamicGraphicSupported = true; // When internalInterface.sendRPC() is called inside SoftButtonManager: @@ -516,4 +517,27 @@ public class SoftButtonManagerTests { assertEquals(stateListUnique, softButtonObject.getStates()); } + + @Test + public void testSoftButtonManagerGraphicNotSupported() { + softButtonManager.isDynamicGraphicSupported = false; + fileManagerUploadArtworksListenerCalledCounter = 0; + internalInterfaceSendRPCListenerCalledCounter = 0; + + softButtonManager.setSoftButtonObjects(Arrays.asList(softButtonObject1, softButtonObject2)); + assertEquals("SoftButtonManager is uploading artwork, when graphic is not supported", 0, fileManagerUploadArtworksListenerCalledCounter); + } + + @Test + public void testSoftButtonManagerDynamicImageNotSupportedNoText() { + softButtonManager.isDynamicGraphicSupported = false; + fileManagerUploadArtworksListenerCalledCounter = 0; + internalInterfaceSendRPCListenerCalledCounter = 0; + + SoftButtonState softButtonState = new SoftButtonState("testState", null, new SdlArtwork("image", FileType.GRAPHIC_PNG, 1, true)); + SoftButtonObject softButtonObject = new SoftButtonObject("obj1", softButtonState, null); + + softButtonManager.setSoftButtonObjects(Arrays.asList(softButtonObject)); + assertEquals("SoftButtonManager is uploading artwork, when graphic is not supported", 0, fileManagerUploadArtworksListenerCalledCounter); + } } diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/BaseSoftButtonManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/BaseSoftButtonManager.java index 4d93be501..ab9159c33 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/BaseSoftButtonManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/BaseSoftButtonManager.java @@ -43,6 +43,7 @@ import com.smartdevicelink.managers.lifecycle.OnSystemCapabilityListener; import com.smartdevicelink.managers.lifecycle.SystemCapabilityManager; import com.smartdevicelink.protocol.enums.FunctionID; import com.smartdevicelink.proxy.RPCNotification; +import com.smartdevicelink.proxy.rpc.DisplayCapabilities; import com.smartdevicelink.proxy.rpc.DisplayCapability; import com.smartdevicelink.proxy.rpc.OnButtonEvent; import com.smartdevicelink.proxy.rpc.OnButtonPress; @@ -58,7 +59,6 @@ import com.smartdevicelink.util.DebugTool; import java.lang.ref.WeakReference; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; @@ -71,6 +71,7 @@ abstract class BaseSoftButtonManager extends BaseSubManager { private static final String TAG = "BaseSoftButtonManager"; private final WeakReference<FileManager> fileManager; SoftButtonCapabilities softButtonCapabilities; + boolean isDynamicGraphicSupported; private CopyOnWriteArrayList<SoftButtonObject> softButtonObjects; private HMILevel currentHMILevel; private final OnSystemCapabilityListener onDisplayCapabilityListener; @@ -99,6 +100,11 @@ abstract class BaseSoftButtonManager extends BaseSubManager { this.currentHMILevel = null; this.transactionQueue = newTransactionQueue(); this.batchQueue = new ArrayList<>(); + DisplayCapabilities displayCapabilities = null; + if (internalInterface.getSystemCapabilityManager() != null) { + displayCapabilities = (DisplayCapabilities) this.internalInterface.getSystemCapabilityManager().getCapability(SystemCapabilityType.DISPLAY, null, false); + } + isDynamicGraphicSupported = (displayCapabilities != null && displayCapabilities.getGraphicSupported() != null) ? displayCapabilities.getGraphicSupported() : true; this.updateListener = new SoftButtonObject.UpdateListener() { @Override @@ -152,7 +158,7 @@ abstract class BaseSoftButtonManager extends BaseSubManager { // Auto-send an updated Show if we have new capabilities if (softButtonObjects != null && !softButtonObjects.isEmpty() && softButtonCapabilities != null && !softButtonCapabilitiesEquals(oldSoftButtonCapabilities, softButtonCapabilities)) { - SoftButtonReplaceOperation operation = new SoftButtonReplaceOperation(internalInterface, fileManager, softButtonCapabilities, softButtonObjects, getCurrentMainField1()); + SoftButtonReplaceOperation operation = new SoftButtonReplaceOperation(internalInterface, fileManager, softButtonCapabilities, softButtonObjects, getCurrentMainField1(), isDynamicGraphicSupported); transactionQueue.add(operation, false); } } @@ -311,7 +317,7 @@ abstract class BaseSoftButtonManager extends BaseSubManager { this.softButtonObjects = softButtonObjects; // We only need to pass the first softButtonCapabilities in the array due to the fact that all soft button capabilities are the same (i.e. there is no way to assign a softButtonCapabilities to a specific soft button). - SoftButtonReplaceOperation operation = new SoftButtonReplaceOperation(internalInterface, fileManager.get(), softButtonCapabilities, softButtonObjects, getCurrentMainField1()); + SoftButtonReplaceOperation operation = new SoftButtonReplaceOperation(internalInterface, fileManager.get(), softButtonCapabilities, softButtonObjects, getCurrentMainField1(), isDynamicGraphicSupported); if (batchUpdates) { batchQueue.clear(); diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/SoftButtonReplaceOperation.java b/base/src/main/java/com/smartdevicelink/managers/screen/SoftButtonReplaceOperation.java index b157c4cb9..f39fe279b 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/SoftButtonReplaceOperation.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/SoftButtonReplaceOperation.java @@ -10,6 +10,7 @@ import com.smartdevicelink.proxy.RPCResponse; import com.smartdevicelink.proxy.rpc.Show; import com.smartdevicelink.proxy.rpc.SoftButton; import com.smartdevicelink.proxy.rpc.SoftButtonCapabilities; +import com.smartdevicelink.proxy.rpc.enums.ImageType; import com.smartdevicelink.proxy.rpc.enums.SoftButtonType; import com.smartdevicelink.proxy.rpc.listeners.OnRPCResponseListener; import com.smartdevicelink.util.DebugTool; @@ -30,14 +31,16 @@ class SoftButtonReplaceOperation extends Task { private final SoftButtonCapabilities softButtonCapabilities; private final CopyOnWriteArrayList<SoftButtonObject> softButtonObjects; private String currentMainField1; + private Boolean isDynamicGraphicSupported; - SoftButtonReplaceOperation(ISdl internalInterface, FileManager fileManager, SoftButtonCapabilities softButtonCapabilities, CopyOnWriteArrayList<SoftButtonObject> softButtonObjects, String currentMainField1) { + SoftButtonReplaceOperation(ISdl internalInterface, FileManager fileManager, SoftButtonCapabilities softButtonCapabilities, CopyOnWriteArrayList<SoftButtonObject> softButtonObjects, String currentMainField1, Boolean isDynamicGraphicSupported) { super("SoftButtonReplaceOperation"); this.internalInterface = new WeakReference<>(internalInterface); this.fileManager = new WeakReference<>(fileManager); this.softButtonCapabilities = softButtonCapabilities; this.softButtonObjects = softButtonObjects; this.currentMainField1 = currentMainField1; + this.isDynamicGraphicSupported = isDynamicGraphicSupported; } @Override @@ -65,6 +68,18 @@ class SoftButtonReplaceOperation extends Task { onFinished(); } }); + } else if (!supportsDynamicSoftButtonImages()) { + DebugTool.logInfo(TAG, "Soft button images are not supported. Attempting to send text and static image only soft buttons. If any button does not contain text and/or a static image, no buttons will be sent."); + sendCurrentStateStaticImageOnlySoftButtons(new CompletionListener() { + @Override + public void onComplete(boolean success) { + if (!success) { + DebugTool.logError(TAG, "Buttons will not be sent because the module does not support dynamic images and some of the buttons do not have text or static images"); + } + onFinished(); + } + }); + } else if (currentStateHasImages() && !allCurrentStateImagesAreUploaded()) { // If there are images that aren't uploaded // Send text buttons if all the soft buttons have text @@ -128,6 +143,13 @@ class SoftButtonReplaceOperation extends Task { } return; } + if (!supportsDynamicSoftButtonImages()) { + DebugTool.logInfo(TAG, "Head unit does not support dynamic images, skipping upload"); + if (completionListener != null) { + completionListener.onComplete(false); + } + return; + } DebugTool.logInfo(TAG, "Uploading soft button initial artworks"); if (fileManager.get() != null) { @@ -236,6 +258,59 @@ class SoftButtonReplaceOperation extends Task { } } + // Send soft buttons for the current state that only contain text and static images only, if possible. + private void sendCurrentStateStaticImageOnlySoftButtons(final CompletionListener completionListener) { + if (getState() == Task.CANCELED) { + onFinished(); + } + + DebugTool.logInfo(TAG, "Preparing to send text and static image only soft buttons"); + List<SoftButton> textButtons = new ArrayList<>(); + for (SoftButtonObject softButtonObject : softButtonObjects) { + SoftButton softButton = softButtonObject.getCurrentStateSoftButton(); + if (softButton.getText() == null && softButton.getImage() != null && softButton.getImage().getImageType() == ImageType.DYNAMIC) { + DebugTool.logWarning(TAG, "Attempted to create text and static image only buttons, but some buttons don't support text and have dynamic images, so no soft buttons will be sent."); + if (completionListener != null) { + completionListener.onComplete(false); + } + return; + } + + + if (softButton.getImage() != null && softButton.getImage().getImageType() == ImageType.DYNAMIC) { + // We should create a new softButtonObject rather than modifying the original one + SoftButton textAndStaticImageOnlySoftButton = new SoftButton(SoftButtonType.SBT_TEXT, softButton.getSoftButtonID()); + textAndStaticImageOnlySoftButton.setText(softButton.getText()); + textAndStaticImageOnlySoftButton.setSystemAction(softButton.getSystemAction()); + textAndStaticImageOnlySoftButton.setIsHighlighted(softButton.getIsHighlighted()); + textAndStaticImageOnlySoftButton.setImage(softButton.getImage()); + textButtons.add(textAndStaticImageOnlySoftButton); + } else { + textButtons.add(softButton); + } + } + + Show show = new Show(); + show.setOnRPCResponseListener(new OnRPCResponseListener() { + @Override + public void onResponse(int correlationId, RPCResponse response) { + if (response.getSuccess()) { + DebugTool.logInfo(TAG, "Finished sending text and static image only soft buttons"); + } else { + DebugTool.logWarning(TAG, "Failed to update soft buttons with text and static image only buttons"); + } + if (completionListener != null) { + completionListener.onComplete(response.getSuccess()); + } + } + }); + show.setMainField1(currentMainField1); + show.setSoftButtons(textButtons); + if (internalInterface.get() != null) { + internalInterface.get().sendRPC(show); + } + } + // Returns text soft buttons representing the current states of the button objects, or returns if _any_ of the buttons' current states are image only buttons. private void sendCurrentStateTextOnlySoftButtons(final CompletionListener completionListener) { @@ -303,6 +378,10 @@ class SoftButtonReplaceOperation extends Task { return true; } + private boolean supportsDynamicSoftButtonImages() { + return softButtonCapabilities != null && Boolean.TRUE.equals(isDynamicGraphicSupported) && Boolean.TRUE.equals(softButtonCapabilities.getImageSupported()); + } + private boolean supportsSoftButtonImages() { return softButtonCapabilities != null && Boolean.TRUE.equals(softButtonCapabilities.getImageSupported()); } |