Merge "AssistContentRequester move binder call to background thread." into sc-dev

This commit is contained in:
TreeHugger Robot
2021-06-02 20:31:53 +00:00
committed by Android (Google) Code Review

View File

@@ -54,6 +54,7 @@ public class AssistContentRequester {
private final IActivityTaskManager mActivityTaskManager;
private final String mPackageName;
private final Executor mCallbackExecutor;
private final Executor mSystemInteractionExecutor;
// If system loses the callback, our internal cache of original callback will also get cleared.
private final Map<Object, Callback> mPendingCallbacks =
@@ -63,6 +64,7 @@ public class AssistContentRequester {
mActivityTaskManager = ActivityTaskManager.getService();
mPackageName = context.getApplicationContext().getPackageName();
mCallbackExecutor = Executors.MAIN_EXECUTOR;
mSystemInteractionExecutor = Executors.UI_HELPER_EXECUTOR;
}
/**
@@ -71,13 +73,16 @@ public class AssistContentRequester {
* @param taskId to query for the content.
* @param callback to call when the content is available, called on the main thread.
*/
public void requestAssistContent(int taskId, Callback callback) {
try {
mActivityTaskManager.requestAssistDataForTask(
new AssistDataReceiver(callback, this), taskId, mPackageName);
} catch (RemoteException e) {
Log.e(TAG, "Requesting assist content failed for task: " + taskId, e);
}
public void requestAssistContent(final int taskId, final Callback callback) {
// ActivityTaskManager interaction here is synchronous, so call off the main thread.
mSystemInteractionExecutor.execute(() -> {
try {
mActivityTaskManager.requestAssistDataForTask(
new AssistDataReceiver(callback, this), taskId, mPackageName);
} catch (RemoteException e) {
Log.e(TAG, "Requesting assist content failed for task: " + taskId, e);
}
});
}
private void executeOnMainExecutor(Runnable callback) {