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

Commit 490727e8 authored by Massimo Carli's avatar Massimo Carli
Browse files

Improves SyncedDeviceConfig performance

Remove functional abstraction to improve efficiency
Abstract the way flags value are checked to enable use
of recent flag system

Bug: 270357347
Test: atest WmTests:SynchedDeviceConfigTests

Change-Id: I1ea2df118fe1e0afa565c0169e423f7bd50c838b
parent f60f090e
Loading
Loading
Loading
Loading
+10 −10
Original line number Original line Diff line number Diff line
@@ -20,7 +20,6 @@ import android.annotation.NonNull;
import android.provider.DeviceConfig;
import android.provider.DeviceConfig;


import java.util.Map;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.Executor;


@@ -98,27 +97,28 @@ final class SynchedDeviceConfig implements DeviceConfig.OnPropertiesChangedListe
     * @throws IllegalArgumentException {@code key} isn't recognised.
     * @throws IllegalArgumentException {@code key} isn't recognised.
     */
     */
    boolean getFlagValue(@NonNull String key) {
    boolean getFlagValue(@NonNull String key) {
        return findEntry(key).map(SynchedDeviceConfigEntry::getValue)
        final SynchedDeviceConfigEntry entry = mDeviceConfigEntries.get(key);
                .orElseThrow(() -> new IllegalArgumentException("Unexpected flag name: " + key));
        if (entry == null) {
            throw new IllegalArgumentException("Unexpected flag name: " + key);
        }
        return entry.getValue();
    }
    }


    /**
    /**
     * @return {@code true} if the flag for the given {@code key} was enabled at build time.
     * @return {@code true} if the flag for the given {@code key} was enabled at build time.
     */
     */
    boolean isBuildTimeFlagEnabled(@NonNull String key) {
    boolean isBuildTimeFlagEnabled(@NonNull String key) {
        return findEntry(key).map(SynchedDeviceConfigEntry::isBuildTimeFlagEnabled)
        final SynchedDeviceConfigEntry entry = mDeviceConfigEntries.get(key);
                .orElseThrow(() -> new IllegalArgumentException("Unexpected flag name: " + key));
        if (entry == null) {
            throw new IllegalArgumentException("Unexpected flag name: " + key);
        }
        return entry.isBuildTimeFlagEnabled();
    }
    }


    private boolean isDeviceConfigFlagEnabled(@NonNull String key, boolean defaultValue) {
    private boolean isDeviceConfigFlagEnabled(@NonNull String key, boolean defaultValue) {
        return DeviceConfig.getBoolean(mNamespace, key, defaultValue);
        return DeviceConfig.getBoolean(mNamespace, key, defaultValue);
    }
    }


    @NonNull
    private Optional<SynchedDeviceConfigEntry> findEntry(@NonNull String key) {
        return Optional.ofNullable(mDeviceConfigEntries.get(key));
    }

    static class SynchedDeviceConfigBuilder {
    static class SynchedDeviceConfigBuilder {


        private final String mNamespace;
        private final String mNamespace;