Merge "Revert "Marshal dream overlay connection logic with Handler."" into tm-qpr-dev am: b5e24da991

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18051655

Change-Id: I2b27dbda96473a419141f34e0d2c5fc68bb9e2b4
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Bryce Lee
2022-04-28 20:40:19 +00:00
committed by Automerger Merge Worker

View File

@@ -251,8 +251,6 @@ public class DreamService extends Service implements Window.Callback {
// A Queue of pending requests to execute on the overlay. // A Queue of pending requests to execute on the overlay.
private final ArrayDeque<Consumer<IDreamOverlay>> mRequests; private final ArrayDeque<Consumer<IDreamOverlay>> mRequests;
private Handler mHandler = new Handler(Looper.getMainLooper());
private boolean mBound; private boolean mBound;
OverlayConnection() { OverlayConnection() {
@@ -261,40 +259,34 @@ public class DreamService extends Service implements Window.Callback {
public void bind(Context context, @Nullable ComponentName overlayService, public void bind(Context context, @Nullable ComponentName overlayService,
ComponentName dreamService) { ComponentName dreamService) {
mHandler.post(() -> { if (overlayService == null) {
if (overlayService == null) { return;
return; }
}
final ServiceInfo serviceInfo = fetchServiceInfo(context, dreamService); final ServiceInfo serviceInfo = fetchServiceInfo(context, dreamService);
final Intent overlayIntent = new Intent(); final Intent overlayIntent = new Intent();
overlayIntent.setComponent(overlayService); overlayIntent.setComponent(overlayService);
overlayIntent.putExtra(EXTRA_SHOW_COMPLICATIONS, overlayIntent.putExtra(EXTRA_SHOW_COMPLICATIONS,
fetchShouldShowComplications(context, serviceInfo)); fetchShouldShowComplications(context, serviceInfo));
context.bindService(overlayIntent, context.bindService(overlayIntent,
this, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE); this, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE);
mBound = true; mBound = true;
});
} }
public void unbind(Context context) { public void unbind(Context context) {
mHandler.post(() -> { if (!mBound) {
if (!mBound) { return;
return; }
}
context.unbindService(this); context.unbindService(this);
mBound = false; mBound = false;
});
} }
public void request(Consumer<IDreamOverlay> request) { public void request(Consumer<IDreamOverlay> request) {
mHandler.post(() -> { mRequests.push(request);
mRequests.push(request); evaluate();
evaluate();
});
} }
private void evaluate() { private void evaluate() {
@@ -312,19 +304,15 @@ public class DreamService extends Service implements Window.Callback {
@Override @Override
public void onServiceConnected(ComponentName name, IBinder service) { public void onServiceConnected(ComponentName name, IBinder service) {
mHandler.post(() -> { // Store Overlay and execute pending requests.
// Store Overlay and execute pending requests. mOverlay = IDreamOverlay.Stub.asInterface(service);
mOverlay = IDreamOverlay.Stub.asInterface(service); evaluate();
evaluate();
});
} }
@Override @Override
public void onServiceDisconnected(ComponentName name) { public void onServiceDisconnected(ComponentName name) {
mHandler.post(() -> { // Clear Overlay binder to prevent further request processing.
// Clear Overlay binder to prevent further request processing. mOverlay = null;
mOverlay = null;
});
} }
} }