Ensure ScheduledExecutor is not shutdown before scheduling timeout cleanup. am: d7b0534ae7
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/services/Telecomm/+/31395461
Change-Id: I3ebd629a2a92d5a5cf15100a7b431d805133af68
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/src/com/android/server/telecom/ConnectionServiceWrapper.java b/src/com/android/server/telecom/ConnectionServiceWrapper.java
index 57b7091..de18d74 100644
--- a/src/com/android/server/telecom/ConnectionServiceWrapper.java
+++ b/src/com/android/server/telecom/ConnectionServiceWrapper.java
@@ -78,6 +78,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
@@ -1654,11 +1655,21 @@
}
}
};
- // Post cleanup to the executor service and cache the future, so we can cancel it if
- // needed.
- ScheduledFuture<?> future = mScheduledExecutor.schedule(r.getRunnableToCancel(),
- SERVICE_BINDING_TIMEOUT, TimeUnit.MILLISECONDS);
- mScheduledFutureMap.put(call, future);
+ if (mScheduledExecutor != null && !mScheduledExecutor.isShutdown()) {
+ try {
+ // Post cleanup to the executor service and cache the future,
+ // so we can cancel it if needed.
+ ScheduledFuture<?> future = mScheduledExecutor.schedule(
+ r.getRunnableToCancel(),SERVICE_BINDING_TIMEOUT,
+ TimeUnit.MILLISECONDS);
+ mScheduledFutureMap.put(call, future);
+ } catch (RejectedExecutionException e) {
+ Log.e(this, e, "createConference: mScheduledExecutor was "
+ + "already shutdown");
+ }
+ } else {
+ Log.w(this, "createConference: Scheduled executor is null or shutdown");
+ }
try {
mServiceInterface.createConference(
call.getConnectionManagerPhoneAccount(),
@@ -1778,11 +1789,21 @@
}
}
};
- // Post cleanup to the executor service and cache the future, so we can cancel it if
- // needed.
- ScheduledFuture<?> future = mScheduledExecutor.schedule(r.getRunnableToCancel(),
- SERVICE_BINDING_TIMEOUT, TimeUnit.MILLISECONDS);
- mScheduledFutureMap.put(call, future);
+ if (mScheduledExecutor != null && !mScheduledExecutor.isShutdown()) {
+ try {
+ // Post cleanup to the executor service and cache the future,
+ // so we can cancel it if needed.
+ ScheduledFuture<?> future = mScheduledExecutor.schedule(
+ r.getRunnableToCancel(),SERVICE_BINDING_TIMEOUT,
+ TimeUnit.MILLISECONDS);
+ mScheduledFutureMap.put(call, future);
+ } catch (RejectedExecutionException e) {
+ Log.e(this, e, "createConnection: mScheduledExecutor was "
+ + "already shutdown");
+ }
+ } else {
+ Log.w(this, "createConnection: Scheduled executor is null or shutdown");
+ }
try {
mServiceInterface.createConnection(
call.getConnectionManagerPhoneAccount(),