Revert "Marshal dream overlay connection logic with Handler."
This reverts commit c34a64d044d5e916c9f09e9b1ea34d7ffe3f6fd0.
Reason for revert: Found root cause which is not a threading issue as
addressed here.
Change-Id: I88f36641357e9a9bc350e74b70078db0d289972d
diff --git a/core/java/android/service/dreams/DreamService.java b/core/java/android/service/dreams/DreamService.java
index eca83e5..6a9afdb 100644
--- a/core/java/android/service/dreams/DreamService.java
+++ b/core/java/android/service/dreams/DreamService.java
@@ -251,8 +251,6 @@
// A Queue of pending requests to execute on the overlay.
private final ArrayDeque<Consumer<IDreamOverlay>> mRequests;
- private Handler mHandler = new Handler(Looper.getMainLooper());
-
private boolean mBound;
OverlayConnection() {
@@ -261,40 +259,34 @@
public void bind(Context context, @Nullable ComponentName overlayService,
ComponentName dreamService) {
- mHandler.post(() -> {
- if (overlayService == null) {
- return;
- }
+ if (overlayService == null) {
+ return;
+ }
- final ServiceInfo serviceInfo = fetchServiceInfo(context, dreamService);
+ final ServiceInfo serviceInfo = fetchServiceInfo(context, dreamService);
- final Intent overlayIntent = new Intent();
- overlayIntent.setComponent(overlayService);
- overlayIntent.putExtra(EXTRA_SHOW_COMPLICATIONS,
- fetchShouldShowComplications(context, serviceInfo));
+ final Intent overlayIntent = new Intent();
+ overlayIntent.setComponent(overlayService);
+ overlayIntent.putExtra(EXTRA_SHOW_COMPLICATIONS,
+ fetchShouldShowComplications(context, serviceInfo));
- context.bindService(overlayIntent,
- this, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE);
- mBound = true;
- });
+ context.bindService(overlayIntent,
+ this, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE);
+ mBound = true;
}
public void unbind(Context context) {
- mHandler.post(() -> {
- if (!mBound) {
- return;
- }
+ if (!mBound) {
+ return;
+ }
- context.unbindService(this);
- mBound = false;
- });
+ context.unbindService(this);
+ mBound = false;
}
public void request(Consumer<IDreamOverlay> request) {
- mHandler.post(() -> {
- mRequests.push(request);
- evaluate();
- });
+ mRequests.push(request);
+ evaluate();
}
private void evaluate() {
@@ -312,19 +304,15 @@
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
- mHandler.post(() -> {
- // Store Overlay and execute pending requests.
- mOverlay = IDreamOverlay.Stub.asInterface(service);
- evaluate();
- });
+ // Store Overlay and execute pending requests.
+ mOverlay = IDreamOverlay.Stub.asInterface(service);
+ evaluate();
}
@Override
public void onServiceDisconnected(ComponentName name) {
- mHandler.post(() -> {
- // Clear Overlay binder to prevent further request processing.
- mOverlay = null;
- });
+ // Clear Overlay binder to prevent further request processing.
+ mOverlay = null;
}
}