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

Commit 812cedcf authored by Fabian Kozynski's avatar Fabian Kozynski Committed by Automerger Merge Worker
Browse files

Merge "Fix dispatch in FakeSettings" into sc-v2-dev am: ae77bd58

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

Change-Id: Iad3fc305f0e0ee1d006c8597589186c508bbff88
parents 68a450ee ae77bd58
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -123,11 +123,11 @@ public class FakeSettings implements SecureSettings, GlobalSettings, SystemSetti

        Uri uri = getUriFor(name);
        for (ContentObserver observer : mContentObservers.getOrDefault(key, new ArrayList<>())) {
            observer.dispatchChange(false, List.of(uri), userHandle);
            observer.dispatchChange(false, List.of(uri), 0, userHandle);
        }
        for (ContentObserver observer :
                mContentObserversAllUsers.getOrDefault(uri.toString(), new ArrayList<>())) {
            observer.dispatchChange(false, List.of(uri), userHandle);
            observer.dispatchChange(false, List.of(uri), 0, userHandle);
        }
        return true;
    }
+18 −3
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

@@ -86,7 +87,8 @@ public class FakeSettingsTest extends SysuiTestCase {

        mFakeSettings.putString("cat", "hat");

        verify(mContentObserver).dispatchChange(anyBoolean(), any(Collection.class), anyInt());
        verify(mContentObserver).dispatchChange(anyBoolean(), any(Collection.class), anyInt(),
                anyInt());
    }

    @Test
@@ -96,7 +98,8 @@ public class FakeSettingsTest extends SysuiTestCase {

        mFakeSettings.putString("cat", "hat");

        verify(mContentObserver).dispatchChange(anyBoolean(), any(Collection.class), anyInt());
        verify(mContentObserver).dispatchChange(anyBoolean(), any(Collection.class), anyInt(),
                anyInt());
    }

    @Test
@@ -119,6 +122,18 @@ public class FakeSettingsTest extends SysuiTestCase {
        mFakeSettings.putString("cat", "hat");

        verify(mContentObserver, never()).dispatchChange(
                anyBoolean(), any(Collection.class), anyInt());
                anyBoolean(), any(Collection.class), anyInt(), anyInt());
    }

    @Test
    public void testContentObserverDispatchCorrectUser() {
        int user = 10;
        mFakeSettings.registerContentObserverForUser(
                mFakeSettings.getUriFor("cat"), false, mContentObserver, UserHandle.USER_ALL
        );

        mFakeSettings.putStringForUser("cat", "hat", user);
        verify(mContentObserver).dispatchChange(anyBoolean(), any(Collection.class), anyInt(),
                eq(user));
    }
}