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

Commit 5ecbf52e authored by Forrest Dunlap's avatar Forrest Dunlap
Browse files

Remove DeviceConfigInterface from Services & refactor...

Remove DeviceConfigInterface from Services & refactor FakeDeviceConfigInterface to use android.provider.DeviceConfigInterface

Test: manual atest
Bug: 142727848

Change-Id: I6bf41df5b30a52887f0f9755c1332c244f19c791
parent 738b7e6c
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
@@ -207,10 +207,3 @@ prebuilt_etc {
    name: "protolog.conf.json.gz",
    src: ":services.core.json.gz",
}

filegroup {
    name: "services.core-sources-deviceconfig-interface",
    srcs: [
        "java/com/android/server/utils/DeviceConfigInterface.java",
    ],
}
+1 −1
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.os.Message;
import android.os.SystemClock;
import android.os.UserHandle;
import android.provider.DeviceConfig;
import android.provider.DeviceConfigInterface;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.IndentingPrintWriter;
@@ -61,7 +62,6 @@ import com.android.server.display.utils.AmbientFilterFactory;
import com.android.server.sensors.SensorManagerInternal;
import com.android.server.sensors.SensorManagerInternal.ProximityActiveListener;
import com.android.server.statusbar.StatusBarManagerInternal;
import com.android.server.utils.DeviceConfigInterface;

import java.io.PrintWriter;
import java.text.SimpleDateFormat;
+0 −121
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.utils;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.provider.DeviceConfig;

import java.util.concurrent.Executor;

/**
 * Abstraction around {@link DeviceConfig} to allow faking device configuration in tests.
 */
public interface DeviceConfigInterface {
    /**
     * @see DeviceConfig#getProperty
     */
    @Nullable
    String getProperty(@NonNull String namespace, @NonNull String name);

    /**
     * @see DeviceConfig#getString
     */
    @NonNull
    String getString(@NonNull String namespace, @NonNull String name, @NonNull String defaultValue);

    /**
     * @see DeviceConfig#getInt
     */
    int getInt(@NonNull String namespace, @NonNull String name, int defaultValue);

    /**
     * @see DeviceConfig#getLong
     */
    long getLong(@NonNull String namespace, @NonNull String name, long defaultValue);

    /**
     * @see DeviceConfig#getBoolean
     */
    boolean getBoolean(@NonNull String namespace, @NonNull String name, boolean defaultValue);

    /**
     * @see DeviceConfig#getFloat
     */
    float getFloat(@NonNull String namespace, @NonNull String name, float defaultValue);

    /**
     * @see DeviceConfig#addOnPropertiesChangedListener
     */
    void addOnPropertiesChangedListener(@NonNull String namespace, @NonNull Executor executor,
            @NonNull DeviceConfig.OnPropertiesChangedListener listener);

    /**
     * @see DeviceConfig#removeOnPropertiesChangedListener
     */
    void removeOnPropertiesChangedListener(
            @NonNull DeviceConfig.OnPropertiesChangedListener listener);

    /**
     * Calls through to the real {@link DeviceConfig}.
     */
    DeviceConfigInterface REAL = new DeviceConfigInterface() {
        @Override
        public String getProperty(String namespace, String name) {
            return DeviceConfig.getProperty(namespace, name);
        }

        @Override
        public String getString(String namespace, String name, String defaultValue) {
            return DeviceConfig.getString(namespace, name, defaultValue);
        }

        @Override
        public int getInt(String namespace, String name, int defaultValue) {
            return DeviceConfig.getInt(namespace, name, defaultValue);
        }

        @Override
        public long getLong(String namespace, String name, long defaultValue) {
            return DeviceConfig.getLong(namespace, name, defaultValue);
        }

        @Override
        public boolean getBoolean(@NonNull String namespace, @NonNull String name,
                boolean defaultValue) {
            return DeviceConfig.getBoolean(namespace, name, defaultValue);
        }

        @Override
        public float getFloat(@NonNull String namespace, @NonNull String name,
                float defaultValue) {
            return DeviceConfig.getFloat(namespace, name, defaultValue);
        }

        @Override
        public void addOnPropertiesChangedListener(String namespace, Executor executor,
                DeviceConfig.OnPropertiesChangedListener listener) {
            DeviceConfig.addOnPropertiesChangedListener(namespace, executor, listener);
        }

        @Override
        public void removeOnPropertiesChangedListener(
                DeviceConfig.OnPropertiesChangedListener listener) {
            DeviceConfig.removeOnPropertiesChangedListener(listener);
        }
    };
}
+1 −1
Original line number Diff line number Diff line
@@ -22,12 +22,12 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.res.Resources;
import android.provider.DeviceConfig;
import android.provider.DeviceConfigInterface;
import android.util.ArraySet;

import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.os.BackgroundThread;
import com.android.server.utils.DeviceConfigInterface;

import java.io.PrintWriter;

+1 −1
Original line number Diff line number Diff line
@@ -21,9 +21,9 @@ import static android.provider.AndroidDeviceConfig.KEY_SYSTEM_GESTURE_EXCLUSION_

import android.provider.AndroidDeviceConfig;
import android.provider.DeviceConfig;
import android.provider.DeviceConfigInterface;

import com.android.internal.annotations.VisibleForTesting;
import com.android.server.utils.DeviceConfigInterface;

import java.io.PrintWriter;
import java.util.Objects;
Loading