summaryrefslogtreecommitdiff
path: root/base/src/main/java/com/smartdevicelink/managers
diff options
context:
space:
mode:
Diffstat (limited to 'base/src/main/java/com/smartdevicelink/managers')
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseSystemCapabilityManager.java15
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java77
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/PresentAlertOperation.java21
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/TextAndGraphicUpdateOperation.java62
4 files changed, 118 insertions, 57 deletions
diff --git a/base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseSystemCapabilityManager.java b/base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseSystemCapabilityManager.java
index 1f6c663a8..927200876 100644
--- a/base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseSystemCapabilityManager.java
+++ b/base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseSystemCapabilityManager.java
@@ -172,6 +172,15 @@ abstract class BaseSystemCapabilityManager {
// if there are imageTypes in the response, we must assume graphics are supported
convertedCapabilities.setGraphicSupported(defaultMainWindow.getImageTypeSupported() != null && defaultMainWindow.getImageTypeSupported().size() > 0);
+ if (cachedSystemCapabilities.containsKey(SystemCapabilityType.DISPLAY)) {
+ // Copied from the RAI response, since this parameter is not present in WindowCapability
+ DisplayCapabilities displayCapabilitiesOld = (DisplayCapabilities) cachedSystemCapabilities.get(SystemCapabilityType.DISPLAY);
+ convertedCapabilities.setScreenParams(displayCapabilitiesOld.getScreenParams());
+ if (displayCapabilitiesOld.getMediaClockFormats() != null) {
+ convertedCapabilities.setMediaClockFormats(displayCapabilitiesOld.getMediaClockFormats());
+ }
+ }
+
return convertedCapabilities;
}
@@ -246,7 +255,11 @@ abstract class BaseSystemCapabilityManager {
for (WindowCapability windowCapability : display.getWindowCapabilities()) {
int currentWindowID = windowCapability.getWindowID() != null ? windowCapability.getWindowID() : PredefinedWindows.DEFAULT_WINDOW.getValue();
if (currentWindowID == windowID) {
- return windowCapability;
+ // Clone WindowCapability to prevent modification of stored WindowCapability in SystemCapabilityManager
+ WindowCapability windowCapabilityCopy = (WindowCapability) windowCapability.clone();
+ // A null windowID is assumed to be the DefaultWindow according to the spec, but that can be hard for developers to check, so set it explicitly.
+ windowCapabilityCopy.setWindowID(windowID);
+ return windowCapabilityCopy;
}
}
return null;
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java
index 0a201fc22..92bc82817 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java
@@ -87,7 +87,6 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
private MetadataType textField1Type, textField2Type, textField3Type, textField4Type;
private TemplateConfiguration templateConfiguration;
TextAndGraphicUpdateOperation updateOperation;
- private CompletionListener currentOperationListener;
Queue transactionQueue;
//Constructors
@@ -175,36 +174,13 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
}
if (isDirty) {
isDirty = false;
- sdlUpdate(true, listener);
+ sdlUpdate(listener);
} else if (listener != null) {
listener.onComplete(true);
}
}
- private synchronized void sdlUpdate(Boolean supersedePreviousOperations, final CompletionListener listener) {
- if (this.transactionQueue.getTasksAsList().size() > 0 && supersedePreviousOperations) {
- // Transactions already in queue, we need to clear it out
- transactionQueue.clear();
- updateOperation = null;
- if (currentOperationListener != null) {
- currentOperationListener.onComplete(false);
- }
- }
-
- // Task can be READY, about to start and popped of the queue, so we have to cancel it, to prevent it from starting
- if (updateOperation != null && updateOperation.getState() == Task.READY && supersedePreviousOperations) {
- updateOperation.cancelTask();
- if (currentOperationListener != null) {
- currentOperationListener.onComplete(false);
- }
- }
-
- // If Task is IN_PROGRESS, it’s not on the queue, we need to mark it as cancelled. The task will return at some point when it checks its status and call the listener back
- if (updateOperation != null && updateOperation.getState() == Task.IN_PROGRESS && supersedePreviousOperations) {
- updateOperation.cancelTask();
- }
-
- currentOperationListener = listener;
+ private synchronized void sdlUpdate(final CompletionListener listener) {
CurrentScreenDataUpdatedListener currentScreenDataUpdateListener = new CurrentScreenDataUpdatedListener() {
@Override
@@ -217,13 +193,16 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
}
@Override
- public void onError() {
+ public void onError(TextAndGraphicState errorState) {
// Invalidate data that's different from our current screen data
resetFieldsToCurrentScreenData();
+ if (errorState != null) {
+ updatePendingOperationsWithFailedScreenState(errorState);
+ }
}
};
- updateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager.get(), defaultMainWindowCapability, currentScreenData, currentState(), currentOperationListener, currentScreenDataUpdateListener);
+ updateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager.get(), defaultMainWindowCapability, currentScreenData, currentState(), listener, currentScreenDataUpdateListener);
transactionQueue.add(updateOperation, false);
}
@@ -257,10 +236,20 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
}
}
+ void updatePendingOperationsWithFailedScreenState(TextAndGraphicState errorState) {
+ for (Task task : transactionQueue.getTasksAsList()) {
+ if (!(task instanceof TextAndGraphicUpdateOperation)) {
+ continue;
+ }
+ ((TextAndGraphicUpdateOperation) task).setCurrentScreenData(currentScreenData);
+ ((TextAndGraphicUpdateOperation) task).updateTargetStateWithErrorState(errorState);
+ }
+ }
+
interface CurrentScreenDataUpdatedListener {
void onUpdate(TextAndGraphicState newState);
- void onError();
+ void onError(TextAndGraphicState errorState);
}
@@ -317,7 +306,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
this.textAlignment = textAlignment;
// If we aren't batching, send the update immediately, if we are, set ourselves as dirty (so we know we should send an update after the batch ends)
if (!batchingUpdates) {
- sdlUpdate(true, null);
+ sdlUpdate(null);
} else {
isDirty = true;
}
@@ -330,7 +319,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setMediaTrackTextField(String mediaTrackTextField) {
this.mediaTrackTextField = mediaTrackTextField;
if (!batchingUpdates) {
- sdlUpdate(true, null);
+ sdlUpdate(null);
} else {
isDirty = true;
}
@@ -343,7 +332,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setTextField1(String textField1) {
this.textField1 = textField1;
if (!batchingUpdates) {
- sdlUpdate(true, null);
+ sdlUpdate(null);
} else {
isDirty = true;
}
@@ -356,7 +345,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setTextField2(String textField2) {
this.textField2 = textField2;
if (!batchingUpdates) {
- sdlUpdate(true, null);
+ sdlUpdate(null);
} else {
isDirty = true;
}
@@ -369,7 +358,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setTextField3(String textField3) {
this.textField3 = textField3;
if (!batchingUpdates) {
- sdlUpdate(true, null);
+ sdlUpdate(null);
} else {
isDirty = true;
}
@@ -382,7 +371,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setTextField4(String textField4) {
this.textField4 = textField4;
if (!batchingUpdates) {
- sdlUpdate(true, null);
+ sdlUpdate(null);
} else {
isDirty = true;
}
@@ -395,7 +384,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setTextField1Type(MetadataType textField1Type) {
this.textField1Type = textField1Type;
if (!batchingUpdates) {
- sdlUpdate(true, null);
+ sdlUpdate(null);
} else {
isDirty = true;
}
@@ -408,7 +397,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setTextField2Type(MetadataType textField2Type) {
this.textField2Type = textField2Type;
if (!batchingUpdates) {
- sdlUpdate(true, null);
+ sdlUpdate(null);
} else {
isDirty = true;
}
@@ -421,7 +410,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setTextField3Type(MetadataType textField3Type) {
this.textField3Type = textField3Type;
if (!batchingUpdates) {
- sdlUpdate(true, null);
+ sdlUpdate(null);
} else {
isDirty = true;
}
@@ -434,7 +423,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setTextField4Type(MetadataType textField4Type) {
this.textField4Type = textField4Type;
if (!batchingUpdates) {
- sdlUpdate(true, null);
+ sdlUpdate(null);
} else {
isDirty = true;
}
@@ -447,7 +436,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setTitle(String title) {
this.title = title;
if (!batchingUpdates) {
- sdlUpdate(true, null);
+ sdlUpdate(null);
} else {
isDirty = true;
}
@@ -460,7 +449,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setPrimaryGraphic(SdlArtwork primaryGraphic) {
this.primaryGraphic = primaryGraphic;
if (!batchingUpdates) {
- sdlUpdate(true, null);
+ sdlUpdate(null);
} else {
isDirty = true;
}
@@ -473,7 +462,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setSecondaryGraphic(SdlArtwork secondaryGraphic) {
this.secondaryGraphic = secondaryGraphic;
if (!batchingUpdates) {
- sdlUpdate(true, null);
+ sdlUpdate(null);
} else {
isDirty = true;
}
@@ -491,7 +480,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void changeLayout(TemplateConfiguration templateConfiguration, CompletionListener listener) {
setTemplateConfiguration(templateConfiguration);
if (!batchingUpdates) {
- sdlUpdate(true, listener);
+ sdlUpdate(listener);
} else {
isDirty = true;
}
@@ -554,7 +543,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
updateTransactionQueueSuspended();
if (hasData()) {
// HAX: Capability updates cannot supersede earlier updates because of the case where a developer batched a `changeLayout` call w/ T&G changes on < 6.0 systems could cause this to come in before the operation completes. That would cause the operation to report a "failure" (because it was superseded by this call) when in fact the operation didn't fail at all and is just being adjusted.
- sdlUpdate(false, null);
+ sdlUpdate(null);
}
}
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/PresentAlertOperation.java b/base/src/main/java/com/smartdevicelink/managers/screen/PresentAlertOperation.java
index a85901d3c..31163627c 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/PresentAlertOperation.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/PresentAlertOperation.java
@@ -77,6 +77,8 @@ public class PresentAlertOperation extends Task {
boolean isAlertPresented;
static int SOFTBUTTON_COUNT = 4;
private BaseAlertManager.AlertSoftButtonClearListener alertSoftButtonClearListener;
+ Boolean alertIconUploaded;
+ private List<SdlArtwork> artworksToBeUploaded;
public PresentAlertOperation(ISdl internalInterface, AlertView alertView, WindowCapability currentCapabilities, List<SpeechCapabilities> speechCapabilities, FileManager fileManager, Integer cancelId, AlertCompletionListener listener, BaseAlertManager.AlertSoftButtonClearListener alertSoftButtonClearListener) {
super("PresentAlertOperation");
@@ -89,6 +91,7 @@ public class PresentAlertOperation extends Task {
this.cancelId = cancelId;
this.isAlertPresented = false;
this.alertSoftButtonClearListener = alertSoftButtonClearListener;
+ alertIconUploaded = false;
this.alertView.canceledListener = new AlertCanceledListener() {
@Override
@@ -237,10 +240,15 @@ public class PresentAlertOperation extends Task {
* @param listener - CompletionListener called when all images have been uploaded.
*/
private void uploadImages(final CompletionListener listener) {
- List<SdlArtwork> artworksToBeUploaded = new ArrayList<>();
+ artworksToBeUploaded = new ArrayList<>();
- if (supportsAlertIcon() && fileManager.get() != null && fileManager.get().fileNeedsUpload(alertView.getIcon())) {
- artworksToBeUploaded.add(alertView.getIcon());
+ if (supportsAlertIcon() && alertView.getIcon() != null && fileManager.get() != null) {
+ if (fileManager.get().fileNeedsUpload(alertView.getIcon())) {
+ artworksToBeUploaded.add(alertView.getIcon());
+
+ } else if (fileManager.get().hasUploadedFile(alertView.getIcon()) || alertView.getIcon().isStaticIcon()) {
+ alertIconUploaded = true;
+ }
}
if (alertView.getSoftButtons() != null) {
@@ -275,6 +283,9 @@ public class PresentAlertOperation extends Task {
} else {
DebugTool.logInfo(TAG, "All alert images uploaded");
}
+ if (artworksToBeUploaded.contains(alertView.getIcon()) && (errors == null || !errors.containsKey(alertView.getIcon().getName()))) {
+ alertIconUploaded = true;
+ }
listener.onComplete(true);
}
});
@@ -362,9 +373,7 @@ public class PresentAlertOperation extends Task {
alert = assembleAlertText(alert);
alert.setDuration(alertView.getTimeout() * 1000);
- if (alertView.getIcon() != null && supportsAlertIcon() && !(fileManager.get().hasUploadedFile(alertView.getIcon()))) {
- alert.setAlertIcon(alertView.getIcon().getImageRPC());
- }
+ alert.setAlertIcon(alertIconUploaded ? alertView.getIcon().getImageRPC() : null);
alert.setProgressIndicator(alertView.isShowWaitIndicator());
alert.setCancelID(this.cancelId);
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/TextAndGraphicUpdateOperation.java b/base/src/main/java/com/smartdevicelink/managers/screen/TextAndGraphicUpdateOperation.java
index 683820ee5..be6d6115f 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/TextAndGraphicUpdateOperation.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/TextAndGraphicUpdateOperation.java
@@ -1,5 +1,7 @@
package com.smartdevicelink.managers.screen;
+import androidx.annotation.NonNull;
+
import com.livio.taskmaster.Task;
import com.smartdevicelink.managers.CompletionListener;
import com.smartdevicelink.managers.ISdl;
@@ -24,6 +26,8 @@ import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
+
/**
* Created by Julian Kast on 8/23/20.
@@ -92,6 +96,51 @@ class TextAndGraphicUpdateOperation extends Task {
}
}
+ void updateTargetStateWithErrorState(@NonNull TextAndGraphicState errorState){
+ if (Objects.equals(errorState.getTextField1(), updatedState.getTextField1())){
+ updatedState.setTextField1(currentScreenData.getTextField1());
+ }
+ if (Objects.equals(errorState.getTextField2(), updatedState.getTextField2())){
+ updatedState.setTextField2(currentScreenData.getTextField2());
+ }
+ if (Objects.equals(errorState.getTextField3(), updatedState.getTextField3())){
+ updatedState.setTextField3(currentScreenData.getTextField3());
+ }
+ if (Objects.equals(errorState.getTextField4(), updatedState.getTextField4())){
+ updatedState.setTextField4(currentScreenData.getTextField4());
+ }
+ if (Objects.equals(errorState.getMediaTrackTextField(), updatedState.getMediaTrackTextField())){
+ updatedState.setMediaTrackTextField(currentScreenData.getMediaTrackTextField());
+ }
+ if (Objects.equals(errorState.getTitle(), updatedState.getTitle())){
+ updatedState.setTitle(currentScreenData.getTitle());
+ }
+ if (Objects.equals(errorState.getPrimaryGraphic(), updatedState.getPrimaryGraphic())){
+ updatedState.setPrimaryGraphic(currentScreenData.getPrimaryGraphic());
+ }
+ if (Objects.equals(errorState.getSecondaryGraphic(), updatedState.getSecondaryGraphic())){
+ updatedState.setSecondaryGraphic(currentScreenData.getSecondaryGraphic());
+ }
+ if (Objects.equals(errorState.getTextAlignment(), updatedState.getTextAlignment())){
+ updatedState.setTextAlignment(currentScreenData.getTextAlignment());
+ }
+ if (Objects.equals(errorState.getTextField1Type(), updatedState.getTextField1Type())){
+ updatedState.setTextField1Type(currentScreenData.getTextField1Type());
+ }
+ if (Objects.equals(errorState.getTextField2Type(), updatedState.getTextField2Type())){
+ updatedState.setTextField2Type(currentScreenData.getTextField2Type());
+ }
+ if (Objects.equals(errorState.getTextField3Type(), updatedState.getTextField3Type())){
+ updatedState.setTextField3Type(currentScreenData.getTextField3Type());
+ }
+ if (Objects.equals(errorState.getTextField4Type(), updatedState.getTextField4Type())){
+ updatedState.setTextField4Type(currentScreenData.getTextField4Type());
+ }
+ if (Objects.equals(errorState.getTemplateConfiguration(), updatedState.getTemplateConfiguration())){
+ updatedState.setTemplateConfiguration(currentScreenData.getTemplateConfiguration());
+ }
+ }
+
void updateGraphicsAndShow(Show show) {
if (!shouldUpdatePrimaryImage() && !shouldUpdateSecondaryImage()) {
DebugTool.logInfo(TAG, "No images to send, sending text");
@@ -129,7 +178,6 @@ class TextAndGraphicUpdateOperation extends Task {
finishOperation(success);
}
});
-
}
});
}
@@ -144,7 +192,7 @@ class TextAndGraphicUpdateOperation extends Task {
updateCurrentScreenDataFromShow(show);
} else {
DebugTool.logInfo(TAG, "Text and Graphic Show failed");
- currentScreenDataUpdateListener.onError();
+ currentScreenDataUpdateListener.onError(updatedState);
}
listener.onComplete(response.getSuccess());
@@ -154,11 +202,10 @@ class TextAndGraphicUpdateOperation extends Task {
internalInterface.get().sendRPC(show);
} else {
DebugTool.logInfo(TAG, "ISdl is null Text and Graphic update failed");
- currentScreenDataUpdateListener.onError();
+ currentScreenDataUpdateListener.onError(updatedState);
finishOperation(false);
return;
}
-
}
@SuppressWarnings("deprecation")
@@ -171,7 +218,7 @@ class TextAndGraphicUpdateOperation extends Task {
updateCurrentScreenDataFromSetDisplayLayout(setLayout);
} else {
DebugTool.logInfo(TAG, "Text and Graphic SetDisplayLayout failed");
- currentScreenDataUpdateListener.onError();
+ currentScreenDataUpdateListener.onError(updatedState);
}
listener.onComplete(response.getSuccess());
}
@@ -180,7 +227,7 @@ class TextAndGraphicUpdateOperation extends Task {
internalInterface.get().sendRPC(setLayout);
} else {
DebugTool.logInfo(TAG, "ISdl is null Text and Graphic update failed");
- currentScreenDataUpdateListener.onError();
+ currentScreenDataUpdateListener.onError(updatedState);
finishOperation(false);
return;
}
@@ -586,6 +633,9 @@ class TextAndGraphicUpdateOperation extends Task {
if (show.getSecondaryGraphic() != null) {
currentScreenData.setSecondaryGraphic(updatedState.getSecondaryGraphic());
}
+ if (show.getTemplateConfiguration() != null) {
+ currentScreenData.setTemplateConfiguration(updatedState.getTemplateConfiguration());
+ }
if (currentScreenDataUpdateListener != null) {
currentScreenDataUpdateListener.onUpdate(currentScreenData);
}