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

Commit 8dedb584 authored by Nikolas Havrikov's avatar Nikolas Havrikov
Browse files

Avoid calling the same on change listeners twice

Currently the association store implementation notifies every
OnChangeListener twice: once with a generic onAssociationChanged call
and then with a more specialized call depending on the nature of the
change.

This CL moves the responsibility to decide what kind of change this
should be into the default implementation of the generic
onAssociationChanged method in the interface.
This still allows to override this behavior while alleviating the
need to handle double callbacks in the specialised callback in all
listener implementations.

Test: atest CtsCompanionDeviceManagerCoreTestCases
Test: atest CtsCompanionDeviceManagerUiAutomationTestCases
Change-Id: Idd1150c096ff2e55d805edd2c4c34a2a86ecf7fe
parent ce65b04d
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -49,7 +49,25 @@ public interface AssociationStore {
    /**  Listener for any changes to {@link AssociationInfo}-s. */
    interface OnChangeListener {
        default void onAssociationChanged(
                @ChangeType int changeType, AssociationInfo association) {}
                @ChangeType int changeType, AssociationInfo association) {
            switch (changeType) {
                case CHANGE_TYPE_ADDED:
                    onAssociationAdded(association);
                    break;

                case CHANGE_TYPE_REMOVED:
                    onAssociationRemoved(association);
                    break;

                case CHANGE_TYPE_UPDATED_ADDRESS_CHANGED:
                    onAssociationUpdated(association, true);
                    break;

                case CHANGE_TYPE_UPDATED_ADDRESS_UNCHANGED:
                    onAssociationUpdated(association, false);
                    break;
            }
        }

        default void onAssociationAdded(AssociationInfo association) {}

+0 −18
Original line number Diff line number Diff line
@@ -263,24 +263,6 @@ class AssociationStoreImpl implements AssociationStore {
        synchronized (mListeners) {
            for (OnChangeListener listener : mListeners) {
                listener.onAssociationChanged(changeType, association);

                switch (changeType) {
                    case CHANGE_TYPE_ADDED:
                        listener.onAssociationAdded(association);
                        break;

                    case CHANGE_TYPE_REMOVED:
                        listener.onAssociationRemoved(association);
                        break;

                    case CHANGE_TYPE_UPDATED_ADDRESS_CHANGED:
                        listener.onAssociationUpdated(association, true);
                        break;

                    case CHANGE_TYPE_UPDATED_ADDRESS_UNCHANGED:
                        listener.onAssociationUpdated(association, false);
                        break;
                }
            }
        }
    }