summaryrefslogtreecommitdiffstats
path: root/java/com/android/dialer/common
diff options
context:
space:
mode:
authorzachh <zachh@google.com>2017-12-11 13:57:57 -0800
committerCopybara-Service <copybara-piper@google.com>2017-12-11 15:21:25 -0800
commit05b6a53db23cf8c2d90442d1c84c14fd09519390 (patch)
treef9bdf99f330393d3f5a8e2798ae0f97557296e46 /java/com/android/dialer/common
parent04e88264e69ec2b6974a4d9d6acfa7cd27934e5a (diff)
downloadandroid_packages_apps_Dialer-05b6a53db23cf8c2d90442d1c84c14fd09519390.tar.gz
android_packages_apps_Dialer-05b6a53db23cf8c2d90442d1c84c14fd09519390.tar.bz2
android_packages_apps_Dialer-05b6a53db23cf8c2d90442d1c84c14fd09519390.zip
Don't save UI executor in UiListener.
When an activity is killed by the system, a new UiListener is created and attached, but it doesn't have its executor set. Rather than save it as an instance field, just get the Ui executor when needed, by passing the context to the listen method. Bug: 70510707 Test: unit and manual via "don't keep activities" developer option PiperOrigin-RevId: 178668338 Change-Id: I5360b525377edab5f3a117d1f0f50bf6da6a6f0c
Diffstat (limited to 'java/com/android/dialer/common')
-rw-r--r--java/com/android/dialer/common/concurrent/DialerExecutorComponent.java2
-rw-r--r--java/com/android/dialer/common/concurrent/UiListener.java15
2 files changed, 9 insertions, 8 deletions
diff --git a/java/com/android/dialer/common/concurrent/DialerExecutorComponent.java b/java/com/android/dialer/common/concurrent/DialerExecutorComponent.java
index 7ee30a083..28abf96fd 100644
--- a/java/com/android/dialer/common/concurrent/DialerExecutorComponent.java
+++ b/java/com/android/dialer/common/concurrent/DialerExecutorComponent.java
@@ -36,7 +36,7 @@ public abstract class DialerExecutorComponent {
public <OutputT> UiListener<OutputT> createUiListener(
FragmentManager fragmentManager, String taskId) {
- return UiListener.create(uiExecutorService(), fragmentManager, taskId);
+ return UiListener.create(fragmentManager, taskId);
}
@NonUiParallel
diff --git a/java/com/android/dialer/common/concurrent/UiListener.java b/java/com/android/dialer/common/concurrent/UiListener.java
index 11302d299..9541dbc0c 100644
--- a/java/com/android/dialer/common/concurrent/UiListener.java
+++ b/java/com/android/dialer/common/concurrent/UiListener.java
@@ -18,6 +18,7 @@ package com.android.dialer.common.concurrent;
import android.app.Fragment;
import android.app.FragmentManager;
+import android.content.Context;
import android.os.Bundle;
import android.support.annotation.MainThread;
import android.support.annotation.NonNull;
@@ -29,7 +30,6 @@ import com.android.dialer.common.concurrent.DialerExecutor.SuccessListener;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
-import java.util.concurrent.Executor;
/**
* A headless fragment for use in UI components that interact with ListenableFutures.
@@ -53,19 +53,17 @@ import java.util.concurrent.Executor;
*
* private void userDidSomething() {
* ListenableFuture&lt;MyOutputType&gt; future = callSomeMethodReturningListenableFuture(input);
- * uiListener.listen(future, this::onSuccess, this::onFailure);
+ * uiListener.listen(this, future, this::onSuccess, this::onFailure);
* }
* }
* </pre></code>
*/
public class UiListener<OutputT> extends Fragment {
- private Executor uiThreadExecutor;
private CallbackWrapper<OutputT> callbackWrapper;
@MainThread
- static <OutputT> UiListener<OutputT> create(
- Executor uiThreadExecutor, FragmentManager fragmentManager, String taskId) {
+ static <OutputT> UiListener<OutputT> create(FragmentManager fragmentManager, String taskId) {
@SuppressWarnings("unchecked")
UiListener<OutputT> uiListener =
(UiListener<OutputT>) fragmentManager.findFragmentByTag(taskId);
@@ -73,7 +71,6 @@ public class UiListener<OutputT> extends Fragment {
if (uiListener == null) {
LogUtil.i("UiListener.create", "creating new UiListener for " + taskId);
uiListener = new UiListener<>();
- uiListener.uiThreadExecutor = uiThreadExecutor;
fragmentManager.beginTransaction().add(uiListener, taskId).commit();
}
return uiListener;
@@ -87,12 +84,16 @@ public class UiListener<OutputT> extends Fragment {
*/
@MainThread
public void listen(
+ Context context,
@NonNull ListenableFuture<OutputT> future,
@NonNull SuccessListener<OutputT> successListener,
@NonNull FailureListener failureListener) {
callbackWrapper =
new CallbackWrapper<>(Assert.isNotNull(successListener), Assert.isNotNull(failureListener));
- Futures.addCallback(Assert.isNotNull(future), callbackWrapper, uiThreadExecutor);
+ Futures.addCallback(
+ Assert.isNotNull(future),
+ callbackWrapper,
+ DialerExecutorComponent.get(context).uiExecutorService());
}
private static class CallbackWrapper<OutputT> implements FutureCallback<OutputT> {