Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b50ab151 authored by Sergey Nikolaienkov's avatar Sergey Nikolaienkov Committed by Android (Google) Code Review
Browse files

Merge "postAtFrontOfQueue() in ICompanionDeviceService.Stub"

parents 6e1621b2 a4d4186f
Loading
Loading
Loading
Loading
+8 −18
Original line number Diff line number Diff line
@@ -28,9 +28,6 @@ import android.os.Handler;
import android.os.IBinder;
import android.util.Log;


import com.android.internal.util.function.pooled.PooledLambda;

import java.util.Objects;

/**
@@ -185,31 +182,24 @@ public abstract class CompanionDeviceService extends Service {
    public void onBindCompanionDeviceService(@NonNull Intent intent) {
    }

    class Stub extends ICompanionDeviceService.Stub {
    private class Stub extends ICompanionDeviceService.Stub {
        final Handler mMainHandler = Handler.getMain();
        final CompanionDeviceService mService = CompanionDeviceService.this;

        @Override
        public void onDeviceAppeared(AssociationInfo associationInfo) {
            Handler.getMain().post(
                    () -> CompanionDeviceService.this.onDeviceAppeared(associationInfo));
            mMainHandler.postAtFrontOfQueue(() -> mService.onDeviceAppeared(associationInfo));
        }

        @Override
        public void onDeviceDisappeared(AssociationInfo associationInfo) {
            Handler.getMain().post(
                    () -> CompanionDeviceService.this.onDeviceDisappeared(associationInfo));
            mMainHandler.postAtFrontOfQueue(() -> mService.onDeviceDisappeared(associationInfo));
        }

        @Override
        public void onDispatchMessage(int messageId, int associationId, @NonNull byte[] message) {
            Handler.getMain().sendMessage(PooledLambda.obtainMessage(
                    CompanionDeviceService::onDispatchMessage,
                    CompanionDeviceService.this, messageId, associationId, message));
        }

        public final void dispatchMessage(int messageId, int associationId,
                @NonNull byte[] message) {
            Handler.getMain().sendMessage(PooledLambda.obtainMessage(
                    CompanionDeviceService::dispatchMessage,
                    CompanionDeviceService.this, messageId, associationId, message));
            mMainHandler.postAtFrontOfQueue(
                    () -> mService.onDispatchMessage(messageId, associationId, message));
        }
    }
}