summaryrefslogtreecommitdiff
path: root/base/src/main/java/com/smartdevicelink/managers/screen/choiceset
diff options
context:
space:
mode:
authorBilal Alsharifi <bilal.alsharifi@gmail.com>2020-06-12 11:17:21 -0400
committerBilal Alsharifi <bilal.alsharifi@gmail.com>2020-06-12 11:17:21 -0400
commit1b15fb34eceec0b7715477c23f9073824638719c (patch)
treeb09c06d9ad92ec5ded86edbe6ae654e7d5eabae0 /base/src/main/java/com/smartdevicelink/managers/screen/choiceset
parentf246f22e16aab9b95cd0a3fd0af084e7a1fc6fcb (diff)
downloadsdl_android-1b15fb34eceec0b7715477c23f9073824638719c.tar.gz
Update ChoiceSetManager to use Taskmaster
Diffstat (limited to 'base/src/main/java/com/smartdevicelink/managers/screen/choiceset')
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/choiceset/AsynchronousOperation.java122
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/choiceset/BaseChoiceSetManager.java52
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/choiceset/CheckChoiceVROptionalOperation.java16
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/choiceset/DeleteChoicesOperation.java12
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PausableThreadPoolExecutor.java72
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PreloadChoicesOperation.java12
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PresentChoiceSetOperation.java28
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PresentKeyboardOperation.java28
8 files changed, 74 insertions, 268 deletions
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/AsynchronousOperation.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/AsynchronousOperation.java
deleted file mode 100644
index c0a1dbb25..000000000
--- a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/AsynchronousOperation.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * 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.
- *
- * Created by Nicole Yarroch on 7/25/19 8:43 AM
- */
-
-package com.smartdevicelink.managers.screen.choiceset;
-
-import com.smartdevicelink.util.DebugTool;
-
-class AsynchronousOperation implements Runnable {
- private static final String TAG = "AsynchronousOperation - ";
- private Thread thread;
- private final Object lock;
- private boolean blocked;
- private boolean executing;
- private boolean finished;
- private boolean cancelled;
-
- AsynchronousOperation() {
- lock = new Object();
- blocked = false;
- executing = false;
- finished = false;
- cancelled = false;
- }
-
- @Override
- public void run() {
- thread = Thread.currentThread();
- DebugTool.logInfo(TAG + "Starting: " + toString());
- if (isCancelled()) {
- finished = true;
- DebugTool.logInfo(TAG + "Operation was cancelled: " + toString());
- return;
- }
-
- executing = true;
- }
-
- void finishOperation() {
- unblock();
- executing = false;
- finished = true;
- cancelled = false;
- DebugTool.logInfo(TAG + "Finishing: " + toString());
- }
-
- boolean isExecuting() {
- return executing;
- }
-
- boolean isFinished() {
- return finished;
- }
-
- void cancel(){
- cancelled = true;
- }
-
- boolean isCancelled() {
- return cancelled;
- }
-
- void block(){
- if (!blocked && !finished) {
- blocked = true;
- DebugTool.logInfo(TAG + "Blocking: " + toString());
- try {
- synchronized (lock) {
- lock.wait();
- }
- } catch (InterruptedException e) {
- DebugTool.logWarning(TAG + "InterruptedException: " + toString());
- finishOperation();
- }
- }
- }
-
- void unblock(){
- if (blocked) {
- blocked = false;
- DebugTool.logInfo(TAG + "Unblocking: " + toString());
- synchronized (lock) {
- lock.notify();
- }
- }
- }
-
- @Override
- public String toString() {
- return this.getClass().getSimpleName() + " (OpId: " + System.identityHashCode(this) + ", OpThread:" + (thread != null ? thread.getName() : "no operating thread") + ", currentThread:" + Thread.currentThread().getName() + ", blocked:" + blocked + ", executing:" + executing + ", finished:" + finished + ", cancelled:" + cancelled + ")";
- }
-}
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..37a871490 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>
@@ -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 operationQueue;
+ 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
+ operationQueue = internalInterface.getTaskmaster().createQueue("ChoiceSetManagerQueue", 1, false);
+ operationQueue.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();
+ operationQueue.close();
currentHMILevel = null;
currentSystemContext = null;
@@ -178,7 +176,7 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
operationQueue.clear();
}
});
- executor.submit(checkChoiceVR);
+ operationQueue.add(checkChoiceVR, false);
}
/**
@@ -227,7 +225,7 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
}
});
- executor.submit(preloadChoicesOperation);
+ operationQueue.add(preloadChoicesOperation, false);
} else {
DebugTool.logError("File Manager was null in preload choice operation");
}
@@ -253,15 +251,15 @@ 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);
+ if (pendingPresentOperation != null && pendingPresentOperation.getState() != Task.CANCELED && pendingPresentOperation.getState() != Task.FINISHED && (cellsToBeDeleted.retainAll(pendingPresentationChoices) || cellsToBeRemovedFromPending.retainAll(pendingPresentationChoices))){
+ pendingPresentOperation.cancelTask();
DebugTool.logWarning("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 : operationQueue.getTasksAsList()){
if (!(operation instanceof PreloadChoicesOperation)){ continue; }
((PreloadChoicesOperation) operation).removeChoicesFromUpload(cellsToBeRemovedFromPending);
}
@@ -283,7 +281,7 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
preloadedChoices.removeAll(cellsToBeDeleted);
}
});
- executor.submit(deleteChoicesOperation);
+ operationQueue.add(deleteChoicesOperation, false);
}
/**
@@ -303,7 +301,7 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
if (!setUpChoiceSet(choiceSet)){ return; }
if (this.pendingPresentationSet != null && pendingPresentOperation != null){
- pendingPresentOperation.cancel(false);
+ pendingPresentOperation.cancelTask();
DebugTool.logWarning("Presenting a choice set while one is currently presented. Cancelling previous and continuing");
}
@@ -357,7 +355,8 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
presentOp = new PresentChoiceSetOperation(internalInterface, pendingPresentationSet, mode, keyboardConfiguration, keyboardListener, privateChoiceListener, nextCancelId++);
}
- pendingPresentOperation = executor.submit(presentOp);
+ operationQueue.add(presentOp, false);
+ pendingPresentOperation = presentOp;
}
/**
@@ -379,7 +378,7 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
}
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.");
}
@@ -397,7 +396,8 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
Integer keyboardCancelID = nextCancelId++;
PresentKeyboardOperation keyboardOp = new PresentKeyboardOperation(internalInterface, keyboardConfiguration, initialText, customKeyboardConfig, listener, keyboardCancelID);
currentlyPresentedKeyboardOperation = keyboardOp;
- pendingPresentOperation = executor.submit(keyboardOp);
+ operationQueue.add(keyboardOp, false);
+ pendingPresentOperation = keyboardOp;
return keyboardCancelID;
}
@@ -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 : operationQueue.getTasksAsList()){
if (!(operation instanceof PresentKeyboardOperation)){ continue; }
PresentKeyboardOperation pendingOp = (PresentKeyboardOperation) operation;
@@ -551,21 +551,21 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
currentHMILevel = onHMIStatus.getHmiLevel();
if (currentHMILevel == HMILevel.HMI_NONE){
- executor.pause();
+ operationQueue.pause();
}
if (oldHMILevel == HMILevel.HMI_NONE && currentHMILevel != HMILevel.HMI_NONE){
- executor.resume();
+ operationQueue.resume();
}
currentSystemContext = onHMIStatus.getSystemContext();
if (currentSystemContext == SystemContext.SYSCTXT_HMI_OBSCURED || currentSystemContext == SystemContext.SYSCTXT_ALERT){
- executor.pause();
+ operationQueue.pause();
}
if (currentSystemContext == SystemContext.SYSCTXT_MAIN && currentHMILevel != HMILevel.HMI_NONE){
- executor.resume();
+ operationQueue.resume();
}
}
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/CheckChoiceVROptionalOperation.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/CheckChoiceVROptionalOperation.java
index 1c427c16b..aaead5ddc 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/CheckChoiceVROptionalOperation.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/CheckChoiceVROptionalOperation.java
@@ -35,6 +35,7 @@
package com.smartdevicelink.managers.screen.choiceset;
+import com.livio.taskmaster.Task;
import com.smartdevicelink.proxy.RPCResponse;
import com.smartdevicelink.proxy.interfaces.ISdl;
import com.smartdevicelink.proxy.rpc.Choice;
@@ -47,24 +48,23 @@ import com.smartdevicelink.util.DebugTool;
import java.lang.ref.WeakReference;
import java.util.Collections;
-class CheckChoiceVROptionalOperation extends AsynchronousOperation {
+class CheckChoiceVROptionalOperation extends Task {
private CheckChoiceVROptionalInterface checkChoiceVROptionalInterface;
private WeakReference<ISdl> internalInterface;
private boolean isVROptional;
CheckChoiceVROptionalOperation(ISdl internalInterface, CheckChoiceVROptionalInterface checkChoiceVROptionalInterface){
- super();
+ super("CheckChoiceVROptionalOperation");
this.internalInterface = new WeakReference<>(internalInterface);
this.checkChoiceVROptionalInterface = checkChoiceVROptionalInterface;
}
@Override
- public void run() {
+ public void onExecute() {
CheckChoiceVROptionalOperation.super.run();
DebugTool.logInfo("Choice Operation: Executing check vr optional operation");
sendTestChoiceNoVR();
- block();
}
/**
@@ -121,7 +121,7 @@ class CheckChoiceVROptionalOperation extends AsynchronousOperation {
checkChoiceVROptionalInterface.onError(response.getInfo());
}
- CheckChoiceVROptionalOperation.super.finishOperation();
+ CheckChoiceVROptionalOperation.super.onFinished();
}
}
@@ -133,7 +133,7 @@ class CheckChoiceVROptionalOperation extends AsynchronousOperation {
checkChoiceVROptionalInterface.onError(info);
}
- CheckChoiceVROptionalOperation.super.finishOperation();
+ CheckChoiceVROptionalOperation.super.onFinished();
}
});
@@ -155,7 +155,7 @@ class CheckChoiceVROptionalOperation extends AsynchronousOperation {
checkChoiceVROptionalInterface.onCheckChoiceVROperationComplete(isVROptional);
}
- CheckChoiceVROptionalOperation.super.finishOperation();
+ CheckChoiceVROptionalOperation.super.onFinished();
}
@Override
@@ -165,7 +165,7 @@ class CheckChoiceVROptionalOperation extends AsynchronousOperation {
checkChoiceVROptionalInterface.onError(info);
}
- CheckChoiceVROptionalOperation.super.finishOperation();
+ CheckChoiceVROptionalOperation.super.onFinished();
}
});
if (internalInterface.get() != null){
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/DeleteChoicesOperation.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/DeleteChoicesOperation.java
index 2fc6c314d..56a8e4e9e 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/DeleteChoicesOperation.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/DeleteChoicesOperation.java
@@ -35,6 +35,7 @@
package com.smartdevicelink.managers.screen.choiceset;
+import com.livio.taskmaster.Task;
import com.smartdevicelink.managers.CompletionListener;
import com.smartdevicelink.proxy.RPCResponse;
import com.smartdevicelink.proxy.interfaces.ISdl;
@@ -48,25 +49,24 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
-class DeleteChoicesOperation extends AsynchronousOperation {
+class DeleteChoicesOperation extends Task {
private WeakReference<ISdl> internalInterface;
private HashSet<ChoiceCell> cellsToDelete;
private CompletionListener completionListener;
DeleteChoicesOperation(ISdl internalInterface, HashSet<ChoiceCell> cellsToDelete, CompletionListener completionListener){
- super();
+ super("DeleteChoicesOperation");
this.internalInterface = new WeakReference<>(internalInterface);
this.cellsToDelete = cellsToDelete;
this.completionListener = completionListener;
}
@Override
- public void run() {
+ public void onExecute() {
DeleteChoicesOperation.super.run();
DebugTool.logInfo("Choice Operation: Executing delete choices operation");
sendDeletions();
- block();
}
private void sendDeletions(){
@@ -88,7 +88,7 @@ class DeleteChoicesOperation extends AsynchronousOperation {
}
DebugTool.logInfo("Successfully deleted choices");
- DeleteChoicesOperation.super.finishOperation();
+ DeleteChoicesOperation.super.onFinished();
}
@Override
@@ -98,7 +98,7 @@ class DeleteChoicesOperation extends AsynchronousOperation {
}
DebugTool.logError("Failed to delete choice: " + info + " | Corr ID: " + correlationId);
- DeleteChoicesOperation.super.finishOperation();
+ DeleteChoicesOperation.super.onFinished();
}
@Override
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PausableThreadPoolExecutor.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PausableThreadPoolExecutor.java
deleted file mode 100644
index 74f1cd85a..000000000
--- a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PausableThreadPoolExecutor.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *
- * Note: This file has been modified from its original form.
- * Site with example code: https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor
- */
-
-package com.smartdevicelink.managers.screen.choiceset;
-
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.ReentrantLock;
-
-class PausableThreadPoolExecutor extends ThreadPoolExecutor {
-
- private boolean isPaused;
- private ReentrantLock threadLock;
- private Condition condition;
-
- PausableThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue) {
- super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
- threadLock = new ReentrantLock();
- condition = threadLock.newCondition();
- }
-
- protected void beforeExecute(Thread t, Runnable r) {
- super.beforeExecute(t, r);
- threadLock.lock();
- try {
- while (isPaused) condition.await();
- } catch (InterruptedException ie) {
- t.interrupt();
- } finally {
- threadLock.unlock();
- }
- }
-
- void pause() {
- threadLock.lock();
- try {
- isPaused = true;
- } finally {
- threadLock.unlock();
- }
- }
-
- void resume() {
- threadLock.lock();
- try {
- isPaused = false;
- condition.signalAll();
- } finally {
- threadLock.unlock();
- }
- }
-
-}
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PreloadChoicesOperation.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PreloadChoicesOperation.java
index 04f0b7d7f..627f6861c 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PreloadChoicesOperation.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PreloadChoicesOperation.java
@@ -37,6 +37,7 @@ package com.smartdevicelink.managers.screen.choiceset;
import android.support.annotation.NonNull;
+import com.livio.taskmaster.Task;
import com.smartdevicelink.managers.CompletionListener;
import com.smartdevicelink.managers.ManagerUtility;
import com.smartdevicelink.managers.file.FileManager;
@@ -62,7 +63,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
-class PreloadChoicesOperation extends AsynchronousOperation {
+class PreloadChoicesOperation extends Task {
private WeakReference<ISdl> internalInterface;
private WeakReference<FileManager> fileManager;
@@ -75,7 +76,7 @@ class PreloadChoicesOperation extends AsynchronousOperation {
PreloadChoicesOperation(ISdl internalInterface, FileManager fileManager, String displayName, WindowCapability defaultMainWindowCapability,
Boolean isVROptional, HashSet<ChoiceCell> cellsToPreload, CompletionListener listener){
- super();
+ super("PreloadChoicesOperation");
this.internalInterface = new WeakReference<>(internalInterface);
this.fileManager = new WeakReference<>(fileManager);
this.displayName = displayName;
@@ -86,7 +87,7 @@ class PreloadChoicesOperation extends AsynchronousOperation {
}
@Override
- public void run() {
+ public void onExecute() {
PreloadChoicesOperation.super.run();
DebugTool.logInfo("Choice Operation: Executing preload choices operation");
preloadCellArtworks(new CompletionListener() {
@@ -95,7 +96,6 @@ class PreloadChoicesOperation extends AsynchronousOperation {
preloadCells();
}
});
- block();
}
void removeChoicesFromUpload(HashSet<ChoiceCell> choices){
@@ -167,14 +167,14 @@ class PreloadChoicesOperation extends AsynchronousOperation {
DebugTool.logInfo("Finished pre loading choice cells");
completionListener.onComplete(true);
- PreloadChoicesOperation.super.finishOperation();
+ PreloadChoicesOperation.super.onFinished();
}
@Override
public void onError(int correlationId, Result resultCode, String info) {
DebugTool.logError("There was an error uploading a choice cell: "+ info + " resultCode: " + resultCode);
- PreloadChoicesOperation.super.finishOperation();
+ PreloadChoicesOperation.super.onFinished();
}
@Override
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PresentChoiceSetOperation.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PresentChoiceSetOperation.java
index 10137b68b..07e42bfc7 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PresentChoiceSetOperation.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PresentChoiceSetOperation.java
@@ -35,6 +35,7 @@
package com.smartdevicelink.managers.screen.choiceset;
+import com.livio.taskmaster.Task;
import com.smartdevicelink.managers.CompletionListener;
import com.smartdevicelink.protocol.enums.FunctionID;
import com.smartdevicelink.proxy.RPCNotification;
@@ -60,7 +61,7 @@ import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
-class PresentChoiceSetOperation extends AsynchronousOperation {
+class PresentChoiceSetOperation extends Task {
private WeakReference<ISdl> internalInterface;
private ChoiceSet choiceSet;
@@ -78,7 +79,7 @@ class PresentChoiceSetOperation extends AsynchronousOperation {
PresentChoiceSetOperation(ISdl internalInterface, ChoiceSet choiceSet, InteractionMode mode,
KeyboardProperties originalKeyboardProperties, KeyboardListener keyboardListener, ChoiceSetSelectionListener choiceSetSelectionListener, Integer cancelID){
- super();
+ super("PresentChoiceSetOperation");
this.internalInterface = new WeakReference<>(internalInterface);
this.keyboardListener = keyboardListener;
this.choiceSet = choiceSet;
@@ -98,16 +99,15 @@ class PresentChoiceSetOperation extends AsynchronousOperation {
}
@Override
- public void run() {
+ public void onExecute() {
PresentChoiceSetOperation.super.run();
DebugTool.logInfo("Choice Operation: Executing present choice set operation");
addListeners();
start();
- block();
}
private void start(){
- if (isCancelled()) {
+ if (getState() == Task.CANCELED) {
finishOperation();
return;
}
@@ -121,7 +121,7 @@ class PresentChoiceSetOperation extends AsynchronousOperation {
updateKeyboardProperties(new CompletionListener() {
@Override
public void onComplete(boolean success) {
- if (isCancelled()) {
+ if (getState() == Task.CANCELED) {
finishOperation();
return;
}
@@ -228,13 +228,13 @@ class PresentChoiceSetOperation extends AsynchronousOperation {
public void onResponse(int correlationId, RPCResponse response) {
updatedKeyboardProperties = false;
DebugTool.logInfo("Successfully reset choice keyboard properties to original config");
- PresentChoiceSetOperation.super.finishOperation();
+ PresentChoiceSetOperation.super.onFinished();
}
@Override
public void onError(int correlationId, Result resultCode, String info) {
DebugTool.logError("Failed to reset choice keyboard properties to original config " + resultCode + ", " + info);
- PresentChoiceSetOperation.super.finishOperation();
+ PresentChoiceSetOperation.super.onFinished();
}
});
@@ -245,7 +245,7 @@ class PresentChoiceSetOperation extends AsynchronousOperation {
DebugTool.logError("Internal Interface null when finishing choice keyboard reset");
}
} else {
- PresentChoiceSetOperation.super.finishOperation();
+ PresentChoiceSetOperation.super.onFinished();
}
}
@@ -253,13 +253,13 @@ class PresentChoiceSetOperation extends AsynchronousOperation {
* Cancels the choice set. If the choice set has not yet been sent to Core, it will not be sent. If the choice set is already presented on Core, the choice set will be dismissed using the `CancelInteraction` RPC.
*/
private void cancelInteraction() {
- if (isFinished()) {
+ if ((getState() == Task.FINISHED)) {
DebugTool.logInfo("This operation has already finished so it can not be canceled.");
return;
- } else if (isCancelled()) {
+ } else if (getState() == Task.CANCELED) {
DebugTool.logInfo("This operation has already been canceled. It will be finished at some point during the operation.");
return;
- } else if (isExecuting()) {
+ } else if ((getState() == Task.IN_PROGRESS)) {
if (sdlMsgVersion.getMajorVersion() < 6){
DebugTool.logWarning("Canceling a presented choice set is not supported on this head unit");
return;
@@ -287,7 +287,7 @@ class PresentChoiceSetOperation extends AsynchronousOperation {
}
} else {
DebugTool.logInfo("Canceling a choice set that has not yet been sent to Core");
- this.cancel();
+ this.cancelTask();
}
}
@@ -346,7 +346,7 @@ class PresentChoiceSetOperation extends AsynchronousOperation {
keyboardRPCListener = new OnRPCNotificationListener() {
@Override
public void onNotified(RPCNotification notification) {
- if (isCancelled()) {
+ if (getState() == Task.CANCELED) {
finishOperation();
return;
}
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PresentKeyboardOperation.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PresentKeyboardOperation.java
index 5089d0c92..dd7ea57a2 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PresentKeyboardOperation.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PresentKeyboardOperation.java
@@ -35,6 +35,7 @@
package com.smartdevicelink.managers.screen.choiceset;
+import com.livio.taskmaster.Task;
import com.smartdevicelink.managers.CompletionListener;
import com.smartdevicelink.protocol.enums.FunctionID;
import com.smartdevicelink.proxy.RPCNotification;
@@ -59,7 +60,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-class PresentKeyboardOperation extends AsynchronousOperation {
+class PresentKeyboardOperation extends Task {
private WeakReference<ISdl> internalInterface;
private KeyboardListener keyboardListener;
@@ -71,7 +72,7 @@ class PresentKeyboardOperation extends AsynchronousOperation {
SdlMsgVersion sdlMsgVersion;
PresentKeyboardOperation(ISdl internalInterface, KeyboardProperties originalKeyboardProperties, String initialText, KeyboardProperties customConfig, KeyboardListener keyboardListener, Integer cancelID){
- super();
+ super("PresentKeyboardOperation");
this.internalInterface = new WeakReference<>(internalInterface);
this.keyboardListener = keyboardListener;
this.originalKeyboardProperties = originalKeyboardProperties;
@@ -83,18 +84,17 @@ class PresentKeyboardOperation extends AsynchronousOperation {
}
@Override
- public void run() {
+ public void onExecute() {
PresentKeyboardOperation.super.run();
DebugTool.logInfo("Keyboard Operation: Executing present keyboard operation");
addListeners();
start();
- block();
}
private void start(){
DebugTool.logInfo("Choice Operation: Executing present keyboard operation");
- if (isCancelled()) {
+ if (getState() == Task.CANCELED) {
finishOperation();
return;
}
@@ -107,7 +107,7 @@ class PresentKeyboardOperation extends AsynchronousOperation {
updateKeyboardProperties(new CompletionListener() {
@Override
public void onComplete(boolean success) {
- if (isCancelled()) {
+ if (getState() == Task.CANCELED) {
finishOperation();
return;
}
@@ -148,13 +148,13 @@ class PresentKeyboardOperation extends AsynchronousOperation {
* This will only dismiss an already presented keyboard if connected to head units running SDL 6.0+.
*/
void dismissKeyboard() {
- if (isFinished()) {
+ if ((getState() == Task.FINISHED)) {
DebugTool.logInfo("This operation has already finished so it can not be canceled.");
return;
- } else if (isCancelled()) {
+ } else if (getState() == Task.CANCELED) {
DebugTool.logInfo("This operation has already been canceled. It will be finished at some point during the operation.");
return;
- } else if (isExecuting()) {
+ } else if (getState() == Task.IN_PROGRESS) {
if (sdlMsgVersion.getMajorVersion() < 6){
DebugTool.logWarning("Canceling a keyboard is not supported on this head unit");
return;
@@ -181,7 +181,7 @@ class PresentKeyboardOperation extends AsynchronousOperation {
}
} else {
DebugTool.logInfo("Canceling a keyboard that has not yet been sent to Core.");
- this.cancel();
+ this.cancelTask();
}
}
@@ -242,13 +242,13 @@ class PresentKeyboardOperation extends AsynchronousOperation {
public void onResponse(int correlationId, RPCResponse response) {
updatedKeyboardProperties = false;
DebugTool.logInfo("Successfully reset choice keyboard properties to original config");
- PresentKeyboardOperation.super.finishOperation();
+ PresentKeyboardOperation.super.onFinished();
}
@Override
public void onError(int correlationId, Result resultCode, String info) {
DebugTool.logError("Failed to reset choice keyboard properties to original config " + resultCode + ", " + info);
- PresentKeyboardOperation.super.finishOperation();
+ PresentKeyboardOperation.super.onFinished();
}
});
@@ -259,7 +259,7 @@ class PresentKeyboardOperation extends AsynchronousOperation {
DebugTool.logError("Internal Interface null when finishing choice keyboard reset");
}
} else {
- PresentKeyboardOperation.super.finishOperation();
+ PresentKeyboardOperation.super.onFinished();
}
}
@@ -286,7 +286,7 @@ class PresentKeyboardOperation extends AsynchronousOperation {
keyboardRPCListener = new OnRPCNotificationListener() {
@Override
public void onNotified(RPCNotification notification) {
- if (isCancelled()) {
+ if (getState() == Task.CANCELED) {
finishOperation();
return;
}