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

Commit 04c47f21 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Accept null brightness configs."

parents fc027600 0ae08d0c
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -1849,7 +1849,6 @@ public final class DisplayManagerService extends SystemService {
            if (packageName != null && !validatePackageName(getCallingUid(), packageName)) {
                packageName = null;
            }
            Preconditions.checkNotNull(c);
            final long token = Binder.clearCallingIdentity();
            try {
                setBrightnessConfigurationForUserInternal(c, userId, packageName);
+12 −6
Original line number Diff line number Diff line
@@ -598,7 +598,8 @@ final class PersistentDataStore {
        private boolean setBrightnessConfigurationForUser(BrightnessConfiguration c,
                int userSerial, String packageName) {
            BrightnessConfiguration currentConfig = mConfigurations.get(userSerial);
            if (currentConfig == null || !currentConfig.equals(c)) {
            if (currentConfig != c && (currentConfig == null || !currentConfig.equals(c))) {
                if (c != null) {
                    if (packageName == null) {
                        mPackageNames.remove(userSerial);
                    } else {
@@ -606,6 +607,11 @@ final class PersistentDataStore {
                    }
                    mTimeStamps.put(userSerial, System.currentTimeMillis());
                    mConfigurations.put(userSerial, c);
                } else {
                    mPackageNames.remove(userSerial);
                    mTimeStamps.delete(userSerial);
                    mConfigurations.remove(userSerial);
                }
                return true;
            }
            return false;
+17 −0
Original line number Diff line number Diff line
@@ -171,6 +171,23 @@ public class PersistentDataStoreTest {
                newDataStore.getBrightnessConfiguration(0 /*userSerial*/));
    }

    @Test
    public void testNullBrightnessConfiguration() {
        final float[] lux = { 0f, 10f };
        final float[] nits = {1f, 100f };
        final BrightnessConfiguration config = new BrightnessConfiguration.Builder(lux, nits)
                .setDescription("a description")
                .build();
        mDataStore.loadIfNeeded();
        assertNull(mDataStore.getBrightnessConfiguration(0 /*userSerial*/));

        mDataStore.setBrightnessConfigurationForUser(config, 0, "packagename");
        assertNotNull(mDataStore.getBrightnessConfiguration(0 /*userSerial*/));

        mDataStore.setBrightnessConfigurationForUser(null, 0, "packagename");
        assertNull(mDataStore.getBrightnessConfiguration(0 /*userSerial*/));
    }

    public class TestInjector extends PersistentDataStore.Injector {
        private InputStream mReadStream;
        private OutputStream mWriteStream;