summaryrefslogtreecommitdiff
path: root/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/BaseChoiceSetManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'base/src/main/java/com/smartdevicelink/managers/screen/choiceset/BaseChoiceSetManager.java')
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/choiceset/BaseChoiceSetManager.java104
1 files changed, 52 insertions, 52 deletions
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/BaseChoiceSetManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/BaseChoiceSetManager.java
index 2e590f406..1a5023133 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/BaseChoiceSetManager.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/BaseChoiceSetManager.java
@@ -37,6 +37,8 @@ package com.smartdevicelink.managers.screen.choiceset;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
+import com.livio.taskmaster.Queue;
+import com.livio.taskmaster.Task;
import com.smartdevicelink.managers.BaseSubManager;
import com.smartdevicelink.managers.CompletionListener;
import com.smartdevicelink.managers.file.FileManager;
@@ -64,9 +66,6 @@ import com.smartdevicelink.util.DebugTool;
import java.lang.ref.WeakReference;
import java.util.HashSet;
import java.util.List;
-import java.util.concurrent.Future;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.TimeUnit;
/**
* <strong>ChoiceSetManager</strong> <br>
@@ -74,7 +73,7 @@ import java.util.concurrent.TimeUnit;
* Note: This class must be accessed through the SdlManager. Do not instantiate it by itself. <br>
*/
abstract class BaseChoiceSetManager extends BaseSubManager {
-
+ private static final String TAG = "BaseChoiceSetManager";
// additional state
private static final int CHECKING_VOICE = 0xA0;
private KeyboardProperties keyboardConfiguration;
@@ -90,9 +89,8 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
ChoiceSet pendingPresentationSet;
// We will pass operations into this to be completed
- PausableThreadPoolExecutor executor;
- LinkedBlockingQueue<Runnable> operationQueue;
- Future pendingPresentOperation;
+ Queue transactionQueue;
+ Task pendingPresentOperation;
PresentKeyboardOperation currentlyPresentedKeyboardOperation;
@@ -105,6 +103,10 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
BaseChoiceSetManager(@NonNull ISdl internalInterface, @NonNull FileManager fileManager) {
super(internalInterface);
+ // prepare operations queue
+ transactionQueue = internalInterface.getTaskmaster().createQueue("ChoiceSetManagerQueue", 1, false);
+ transactionQueue.pause(); // pause until HMI ready
+
// capabilities
currentSystemContext = SystemContext.SYSCTXT_MAIN;
currentHMILevel = HMILevel.HMI_NONE;
@@ -118,9 +120,6 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
nextCancelId = choiceCellCancelIdMin;
isVROptional = false;
keyboardConfiguration = defaultKeyboardConfiguration();
- operationQueue = new LinkedBlockingQueue<>();
- executor = new PausableThreadPoolExecutor(1, Runtime.getRuntime().availableProcessors(), 10, TimeUnit.SECONDS, operationQueue);
- executor.pause(); // pause until HMI ready
currentlyPresentedKeyboardOperation = null;
}
@@ -136,8 +135,7 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
public void dispose(){
// cancel the operations
- operationQueue.clear();
- executor.shutdownNow();
+ transactionQueue.close();
currentHMILevel = null;
currentSystemContext = null;
@@ -163,22 +161,22 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
public void onCheckChoiceVROperationComplete(boolean vrOptional) {
isVROptional = vrOptional;
transitionToState(READY);
- DebugTool.logInfo("VR is optional: "+ isVROptional);
+ DebugTool.logInfo(TAG, "VR is optional: "+ isVROptional);
}
@Override
public void onError(String error) {
// At this point, there were errors trying to send a test PICS
// If we reach this state, we cannot use the manager
- DebugTool.logError(error);
+ DebugTool.logError(TAG, error);
transitionToState(ERROR);
// checking VR will always be first in the queue.
// If pre-load operations were added while this was in progress
// clear it from the queue onError.
- operationQueue.clear();
+ transactionQueue.clear();
}
});
- executor.submit(checkChoiceVR);
+ transactionQueue.add(checkChoiceVR, false);
}
/**
@@ -219,7 +217,7 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
listener.onComplete(true);
}
}else {
- DebugTool.logError("There was an error pre loading choice cells");
+ DebugTool.logError(TAG, "There was an error pre loading choice cells");
if (listener != null) {
listener.onComplete(false);
}
@@ -227,9 +225,9 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
}
});
- executor.submit(preloadChoicesOperation);
+ transactionQueue.add(preloadChoicesOperation, false);
} else {
- DebugTool.logError("File Manager was null in preload choice operation");
+ DebugTool.logError(TAG, "File Manager was null in preload choice operation");
}
}
@@ -240,7 +238,7 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
public void deleteChoices(@NonNull List<ChoiceCell> choices){
if (getState() == ERROR) {
- DebugTool.logWarning("Choice Manager In Error State");
+ DebugTool.logWarning(TAG, "Choice Manager In Error State");
return;
}
@@ -253,22 +251,22 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
pendingPresentationChoices.addAll(pendingPresentationSet.getChoices());
}
- if (pendingPresentOperation != null && !pendingPresentOperation.isCancelled() && !pendingPresentOperation.isDone() && (cellsToBeDeleted.retainAll(pendingPresentationChoices) || cellsToBeRemovedFromPending.retainAll(pendingPresentationChoices))){
- pendingPresentOperation.cancel(false);
- DebugTool.logWarning("Attempting to delete choice cells while there is a pending presentation operation. Pending presentation cancelled.");
+ if (pendingPresentOperation != null && pendingPresentOperation.getState() != Task.CANCELED && pendingPresentOperation.getState() != Task.FINISHED && (cellsToBeDeleted.retainAll(pendingPresentationChoices) || cellsToBeRemovedFromPending.retainAll(pendingPresentationChoices))){
+ pendingPresentOperation.cancelTask();
+ DebugTool.logWarning(TAG, "Attempting to delete choice cells while there is a pending presentation operation. Pending presentation cancelled.");
pendingPresentOperation = null;
}
// Remove cells from pending and delete choices
pendingPresentationChoices.removeAll(cellsToBeRemovedFromPending);
- for (Runnable operation : operationQueue){
+ for (Task operation : transactionQueue.getTasksAsList()){
if (!(operation instanceof PreloadChoicesOperation)){ continue; }
((PreloadChoicesOperation) operation).removeChoicesFromUpload(cellsToBeRemovedFromPending);
}
// Find Choices to delete
if (cellsToBeDeleted.size() == 0){
- DebugTool.logInfo("Cells to be deleted size == 0");
+ DebugTool.logInfo(TAG, "Cells to be deleted size == 0");
return;
}
findIdsOnChoices(cellsToBeDeleted);
@@ -277,13 +275,13 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
@Override
public void onComplete(boolean success) {
if (!success){
- DebugTool.logError("Failed to delete choices");
+ DebugTool.logError(TAG, "Failed to delete choices");
return;
}
preloadedChoices.removeAll(cellsToBeDeleted);
}
});
- executor.submit(deleteChoicesOperation);
+ transactionQueue.add(deleteChoicesOperation, false);
}
/**
@@ -295,7 +293,7 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
public void presentChoiceSet(@NonNull final ChoiceSet choiceSet, @Nullable final InteractionMode mode, @Nullable final KeyboardListener keyboardListener){
if (getState() == ERROR) {
- DebugTool.logWarning("Choice Manager In Error State");
+ DebugTool.logWarning(TAG, "Choice Manager In Error State");
return;
}
@@ -303,8 +301,8 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
if (!setUpChoiceSet(choiceSet)){ return; }
if (this.pendingPresentationSet != null && pendingPresentOperation != null){
- pendingPresentOperation.cancel(false);
- DebugTool.logWarning("Presenting a choice set while one is currently presented. Cancelling previous and continuing");
+ pendingPresentOperation.cancelTask();
+ DebugTool.logWarning(TAG, "Presenting a choice set while one is currently presented. Cancelling previous and continuing");
}
this.pendingPresentationSet = choiceSet;
@@ -349,15 +347,16 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
if (keyboardListener == null){
// Non-searchable choice set
- DebugTool.logInfo("Creating non-searchable choice set");
+ DebugTool.logInfo(TAG, "Creating non-searchable choice set");
presentOp = new PresentChoiceSetOperation(internalInterface, pendingPresentationSet, mode, null, null, privateChoiceListener, nextCancelId++);
} else {
// Searchable choice set
- DebugTool.logInfo("Creating searchable choice set");
+ DebugTool.logInfo(TAG, "Creating searchable choice set");
presentOp = new PresentChoiceSetOperation(internalInterface, pendingPresentationSet, mode, keyboardConfiguration, keyboardListener, privateChoiceListener, nextCancelId++);
}
- pendingPresentOperation = executor.submit(presentOp);
+ transactionQueue.add(presentOp, false);
+ pendingPresentOperation = presentOp;
}
/**
@@ -369,19 +368,19 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
*/
public Integer presentKeyboard(@NonNull String initialText, @Nullable KeyboardProperties customKeyboardConfig, @NonNull KeyboardListener listener){
if (initialText == null || initialText.length() == 0){
- DebugTool.logError("initialText cannot be an empty string.");
+ DebugTool.logError(TAG, "initialText cannot be an empty string.");
return null;
}
if (getState() == ERROR) {
- DebugTool.logWarning("Choice Manager In Error State");
+ DebugTool.logWarning(TAG, "Choice Manager In Error State");
return null;
}
if (pendingPresentationSet != null && pendingPresentOperation != null){
- pendingPresentOperation.cancel(false);
+ pendingPresentOperation.cancelTask();
pendingPresentationSet = null;
- DebugTool.logWarning("There is a current or pending choice set, cancelling and continuing.");
+ DebugTool.logWarning(TAG, "There is a current or pending choice set, cancelling and continuing.");
}
if (customKeyboardConfig == null){
@@ -393,11 +392,12 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
}
// Present a keyboard with the choice set that we used to test VR's optional state
- DebugTool.logInfo("Presenting Keyboard - Choice Set Manager");
+ DebugTool.logInfo(TAG, "Presenting Keyboard - Choice Set Manager");
Integer keyboardCancelID = nextCancelId++;
PresentKeyboardOperation keyboardOp = new PresentKeyboardOperation(internalInterface, keyboardConfiguration, initialText, customKeyboardConfig, listener, keyboardCancelID);
currentlyPresentedKeyboardOperation = keyboardOp;
- pendingPresentOperation = executor.submit(keyboardOp);
+ transactionQueue.add(keyboardOp, false);
+ pendingPresentOperation = keyboardOp;
return keyboardCancelID;
}
@@ -410,7 +410,7 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
*/
public void dismissKeyboard(@NonNull Integer cancelID) {
if (getState() == ERROR) {
- DebugTool.logWarning("Choice Manager In Error State");
+ DebugTool.logWarning(TAG, "Choice Manager In Error State");
return;
}
@@ -421,7 +421,7 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
}
// Next, attempt to cancel keyboard operations that have not yet started
- for (Runnable operation : operationQueue){
+ for (Task operation : transactionQueue.getTasksAsList()){
if (!(operation instanceof PresentKeyboardOperation)){ continue; }
PresentKeyboardOperation pendingOp = (PresentKeyboardOperation) operation;
@@ -518,7 +518,7 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
// instead of using the parameter it's more safe to use the convenience method
List<DisplayCapability> capabilities = SystemCapabilityManager.convertToList(capability, DisplayCapability.class);
if (capabilities == null || capabilities.size() == 0) {
- DebugTool.logError("SoftButton Manager - Capabilities sent here are null or empty");
+ DebugTool.logError(TAG, "SoftButton Manager - Capabilities sent here are null or empty");
}else {
DisplayCapability display = capabilities.get(0);
displayName = display.getDisplayName();
@@ -533,7 +533,7 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
@Override
public void onError(String info) {
- DebugTool.logError("Unable to retrieve display capabilities. Many things will probably break. Info: "+ info);
+ DebugTool.logError(TAG, "Unable to retrieve display capabilities. Many things will probably break. Info: "+ info);
defaultMainWindowCapability = null;
}
};
@@ -551,21 +551,21 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
currentHMILevel = onHMIStatus.getHmiLevel();
if (currentHMILevel == HMILevel.HMI_NONE){
- executor.pause();
+ transactionQueue.pause();
}
if (oldHMILevel == HMILevel.HMI_NONE && currentHMILevel != HMILevel.HMI_NONE){
- executor.resume();
+ transactionQueue.resume();
}
currentSystemContext = onHMIStatus.getSystemContext();
if (currentSystemContext == SystemContext.SYSCTXT_HMI_OBSCURED || currentSystemContext == SystemContext.SYSCTXT_ALERT){
- executor.pause();
+ transactionQueue.pause();
}
if (currentSystemContext == SystemContext.SYSCTXT_MAIN && currentHMILevel != HMILevel.HMI_NONE){
- executor.resume();
+ transactionQueue.resume();
}
}
@@ -581,13 +581,13 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
// Choices are not optional here
if (choices == null || choices.size() == 0) {
- DebugTool.logError("Cannot initiate a choice set with no choices");
+ DebugTool.logError(TAG, "Cannot initiate a choice set with no choices");
return false;
}
if (choiceSet.getTimeout() != null) {
if (choiceSet.getTimeout() < 5 || choiceSet.getTimeout() > 100) {
- DebugTool.logWarning("Attempted to create a choice set with a " + choiceSet.getTimeout() + " second timeout; Only 5 - 100 seconds is valid. When using the choice set manager, setTimeout() uses seconds.");
+ DebugTool.logWarning(TAG, "Attempted to create a choice set with a " + choiceSet.getTimeout() + " second timeout; Only 5 - 100 seconds is valid. When using the choice set manager, setTimeout() uses seconds.");
return false;
}
}
@@ -610,19 +610,19 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
// Cell text MUST be unique
if (choiceTextSet.size() < choices.size()) {
- DebugTool.logError("Attempted to create a choice set with duplicate cell text. Cell text must be unique. The choice set will not be set.");
+ DebugTool.logError(TAG, "Attempted to create a choice set with duplicate cell text. Cell text must be unique. The choice set will not be set.");
return false;
}
// All or none of the choices MUST have VR Commands
if (choiceCellWithVoiceCommandCount > 0 && choiceCellWithVoiceCommandCount < choices.size()) {
- DebugTool.logError("If using voice recognition commands, all of the choice set cells must have unique VR commands. There are " + uniqueVoiceCommands.size() + " cells with unique voice commands and " + choices.size() + " total cells. The choice set will not be set.");
+ DebugTool.logError(TAG, "If using voice recognition commands, all of the choice set cells must have unique VR commands. There are " + uniqueVoiceCommands.size() + " cells with unique voice commands and " + choices.size() + " total cells. The choice set will not be set.");
return false;
}
// All VR Commands MUST be unique
if (uniqueVoiceCommands.size() < allVoiceCommandsCount) {
- DebugTool.logError("If using voice recognition commands, all VR commands must be unique. There are " + uniqueVoiceCommands.size() + " unique VR commands and " + allVoiceCommandsCount + " VR commands. The choice set will not be set.");
+ DebugTool.logError(TAG, "If using voice recognition commands, all VR commands must be unique. There are " + uniqueVoiceCommands.size() + " unique VR commands and " + allVoiceCommandsCount + " VR commands. The choice set will not be set.");
return false;
}
return true;