summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYiqun Wu <yiqunw@google.com>2019-10-08 18:01:39 -0700
committerandroid-build-merger <android-build-merger@google.com>2019-10-08 18:01:39 -0700
commit3a4a83728d1b839d189413f5ddc88f32c00c1a03 (patch)
treef24e022178b81257fb5736236ad5e91c7e8aaf1e
parent900fa19614a9e4007ef8eec12d31ece114da0c98 (diff)
parent9dfea3b629efe047da17fd65148bdb3617f44e90 (diff)
downloadplatform_packages_apps_Car_Dialer-3a4a83728d1b839d189413f5ddc88f32c00c1a03.tar.gz
platform_packages_apps_Car_Dialer-3a4a83728d1b839d189413f5ddc88f32c00c1a03.tar.bz2
platform_packages_apps_Car_Dialer-3a4a83728d1b839d189413f5ddc88f32c00c1a03.zip
Merge "Update AsyncQueryLiveData to use separate executors." into pi-car-dev
am: 9dfea3b629 Change-Id: I39dfa8fa52034f28293e500278dac3725ef61b93
-rw-r--r--src/com/android/car/dialer/ui/contact/ContactDetailsViewModel.java2
-rw-r--r--src/com/android/car/dialer/ui/contact/ContactListViewModel.java8
-rw-r--r--src/com/android/car/dialer/widget/WorkerExecutor.java53
3 files changed, 6 insertions, 57 deletions
diff --git a/src/com/android/car/dialer/ui/contact/ContactDetailsViewModel.java b/src/com/android/car/dialer/ui/contact/ContactDetailsViewModel.java
index 8cbf6b5c..4cb76b16 100644
--- a/src/com/android/car/dialer/ui/contact/ContactDetailsViewModel.java
+++ b/src/com/android/car/dialer/ui/contact/ContactDetailsViewModel.java
@@ -31,10 +31,10 @@ import androidx.lifecycle.MediatorLiveData;
import androidx.lifecycle.MutableLiveData;
import com.android.car.dialer.storage.FavoriteNumberRepository;
-import com.android.car.dialer.widget.WorkerExecutor;
import com.android.car.telephony.common.Contact;
import com.android.car.telephony.common.InMemoryPhoneBook;
import com.android.car.telephony.common.PhoneNumber;
+import com.android.car.telephony.common.WorkerExecutor;
import java.util.List;
import java.util.concurrent.Future;
diff --git a/src/com/android/car/dialer/ui/contact/ContactListViewModel.java b/src/com/android/car/dialer/ui/contact/ContactListViewModel.java
index b8df3311..a212aabe 100644
--- a/src/com/android/car/dialer/ui/contact/ContactListViewModel.java
+++ b/src/com/android/car/dialer/ui/contact/ContactListViewModel.java
@@ -28,13 +28,14 @@ import androidx.lifecycle.MediatorLiveData;
import com.android.car.dialer.R;
import com.android.car.dialer.livedata.SharedPreferencesLiveData;
import com.android.car.dialer.ui.common.entity.ContactSortingInfo;
-import com.android.car.dialer.widget.WorkerExecutor;
import com.android.car.telephony.common.Contact;
import com.android.car.telephony.common.InMemoryPhoneBook;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import java.util.concurrent.Future;
/**
@@ -69,6 +70,7 @@ public class ContactListViewModel extends AndroidViewModel {
private final SharedPreferencesLiveData mPreferencesLiveData;
private final Context mContext;
+ private final ExecutorService mExecutorService;
private Future<?> mRunnableFuture;
private SortedContactListLiveData(Context context,
@@ -77,6 +79,7 @@ public class ContactListViewModel extends AndroidViewModel {
mContext = context;
mContactListLiveData = contactListLiveData;
mPreferencesLiveData = sharedPreferencesLiveData;
+ mExecutorService = Executors.newSingleThreadExecutor();
addSource(mPreferencesLiveData, (trigger) -> updateSortedContactList());
addSource(mContactListLiveData, (trigger) -> updateSortedContactList());
@@ -104,8 +107,7 @@ public class ContactListViewModel extends AndroidViewModel {
Collections.sort(contactList, comparator);
postValue(new Pair<>(sortMethod, contactList));
};
- mRunnableFuture = WorkerExecutor.getInstance().getSingleThreadExecutor().submit(
- runnable);
+ mRunnableFuture = mExecutorService.submit(runnable);
}
@Override
diff --git a/src/com/android/car/dialer/widget/WorkerExecutor.java b/src/com/android/car/dialer/widget/WorkerExecutor.java
deleted file mode 100644
index 59b3bf16..00000000
--- a/src/com/android/car/dialer/widget/WorkerExecutor.java
+++ /dev/null
@@ -1,53 +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.
- */
-
-package com.android.car.dialer.widget;
-
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-/**
- * WorkerExecutor is a singleton tied to the application to provide {@link ExecutorService} for
- * Dialer to run tasks in background.
- */
-public class WorkerExecutor {
- private static WorkerExecutor sWorkerExecutor;
-
- private ExecutorService mSingleThreadExecutor;
-
- /** Returns the singleton WorkerExecutor for the application. */
- public static WorkerExecutor getInstance() {
- if (sWorkerExecutor == null) {
- sWorkerExecutor = new WorkerExecutor();
- }
- return sWorkerExecutor;
- }
-
- private WorkerExecutor() {
- mSingleThreadExecutor = Executors.newSingleThreadExecutor();
- }
-
- /** Returns the single thread executor. */
- public ExecutorService getSingleThreadExecutor() {
- return mSingleThreadExecutor;
- }
-
- /** Tears down the singleton WorkerExecutor for the application */
- public void tearDown() {
- mSingleThreadExecutor.shutdown();
- sWorkerExecutor = null;
- }
-}