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

Commit 450f748c authored by Lucas Silva's avatar Lucas Silva Committed by Automerger Merge Worker
Browse files

Merge "Update Condition Monitor subscription API to remove preconditions."...

Merge "Update Condition Monitor subscription API to remove preconditions." into udc-qpr-dev am: 786ed3c8

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



Change-Id: Ic43882a32a442a596ed8e7d7eec23920457ac929
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 3474dc14 786ed3c8
Loading
Loading
Loading
Loading
+3 −32
Original line number Diff line number Diff line
@@ -215,7 +215,7 @@ public class Monitor {
            mSubscriptions.put(token, state);

            // Add and associate conditions.
            normalizedCondition.getConditions().stream().forEach(condition -> {
            normalizedCondition.getConditions().forEach(condition -> {
                if (!mConditions.containsKey(condition)) {
                    mConditions.put(condition, new ArraySet<>());
                    condition.addCallback(mConditionCallback);
@@ -321,7 +321,6 @@ public class Monitor {
            private final Callback mCallback;
            private final Subscription mNestedSubscription;
            private final ArraySet<Condition> mConditions;
            private final ArraySet<Condition> mPreconditions;

            /**
             * Default constructor specifying the {@link Callback} for the {@link Subscription}.
@@ -337,8 +336,7 @@ public class Monitor {
            private Builder(Subscription nestedSubscription, Callback callback) {
                mNestedSubscription = nestedSubscription;
                mCallback = callback;
                mConditions = new ArraySet();
                mPreconditions = new ArraySet();
                mConditions = new ArraySet<>();
            }

            /**
@@ -351,29 +349,6 @@ public class Monitor {
                return this;
            }

            /**
             * Adds a set of {@link Condition} to be a precondition for {@link Subscription}.
             *
             * @return The updated {@link Builder}.
             */
            public Builder addPreconditions(Set<Condition> condition) {
                if (condition == null) {
                    return this;
                }
                mPreconditions.addAll(condition);
                return this;
            }

            /**
             * Adds a {@link Condition} to be a precondition for {@link Subscription}.
             *
             * @return The updated {@link Builder}.
             */
            public Builder addPrecondition(Condition condition) {
                mPreconditions.add(condition);
                return this;
            }

            /**
             * Adds a set of {@link Condition} to be associated with the {@link Subscription}.
             *
@@ -394,11 +369,7 @@ public class Monitor {
             * @return The resulting {@link Subscription}.
             */
            public Subscription build() {
                final Subscription subscription =
                        new Subscription(mConditions, mCallback, mNestedSubscription);
                return !mPreconditions.isEmpty()
                        ? new Subscription(mPreconditions, null, subscription)
                        : subscription;
                return new Subscription(mConditions, mCallback, mNestedSubscription);
            }
        }
    }
+0 −54
Original line number Diff line number Diff line
@@ -554,60 +554,6 @@ public class ConditionMonitorTest extends SysuiTestCase {
        verify(callback, never()).onConditionsChanged(anyBoolean());
    }

    /**
     * Ensures a subscription is predicated on its precondition.
     */
    @Test
    public void testPrecondition() {
        mCondition1.fakeUpdateCondition(false);
        final Monitor.Callback callback =
                mock(Monitor.Callback.class);

        mCondition2.fakeUpdateCondition(false);

        // Create a nested condition
        mConditionMonitor.addSubscription(new Monitor.Subscription.Builder(callback)
                .addPrecondition(mCondition1)
                .addCondition(mCondition2)
                .build());

        mExecutor.runAllReady();

        // Ensure the nested condition callback is not called at all.
        verify(callback, never()).onActiveChanged(anyBoolean());
        verify(callback, never()).onConditionsChanged(anyBoolean());

        // Update the condition to true and ensure that the nested condition is not triggered.
        mCondition2.fakeUpdateCondition(true);
        verify(callback, never()).onConditionsChanged(anyBoolean());
        mCondition2.fakeUpdateCondition(false);

        // Set precondition and make sure the inner condition becomes active and reports that
        // conditions aren't met
        mCondition1.fakeUpdateCondition(true);
        mExecutor.runAllReady();

        verify(callback).onActiveChanged(eq(true));
        verify(callback).onConditionsChanged(eq(false));

        Mockito.clearInvocations(callback);

        // Update the condition and make sure the callback is updated.
        mCondition2.fakeUpdateCondition(true);
        mExecutor.runAllReady();

        verify(callback).onConditionsChanged(true);

        Mockito.clearInvocations(callback);
        // Invalidate precondition and make sure callback is informed, but the last state is
        // not affected.
        mCondition1.fakeUpdateCondition(false);
        mExecutor.runAllReady();

        verify(callback).onActiveChanged(eq(false));
        verify(callback, never()).onConditionsChanged(anyBoolean());
    }

    /**
     * Ensure preconditions are applied to every subscription added to a monitor.
     */