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

Commit a4d4186f authored by Sergey Nikolaienkov's avatar Sergey Nikolaienkov
Browse files

postAtFrontOfQueue() in ICompanionDeviceService.Stub

postAtFrontOfQueue() instead of post()-ing at the back of the queue
in ICompanionDeviceService.Stub to prevent "posted" methods are invoked
*before* onUnbind()/onDestroy().

Add missing @Override annotation to onDispatchMessage method.

Clean up dispatchMessage() which is not a part of
ICompanionDeviceService interface.

Make the Stub implementation class private.

Bug: 198485833
Bug: 200940347
Test: atest CtsCompanionDeviceManagerCoreTestCases
Test: atest CtsCompanionDeviceManagerUiAutomationTestCases
Test: atest CtsOsTestCases:CompanionDeviceManagerTest
Change-Id: Ic44e7968b1cef42355631151aa6958fe1ec7dd6e
parent 2ffcd6dc
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));
        }
    }
}