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

Commit b8540e47 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add tests to ensure input settings are loaded on boot" into udc-qpr-dev am: 6f780529

parents 8f2f7775 6f780529
Loading
Loading
Loading
Loading
+21 −36
Original line number Diff line number Diff line
@@ -46,7 +46,6 @@ import android.view.InputDevice;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.input.BatteryController.UEventManager.UEventBatteryListener;

import java.io.PrintWriter;
import java.util.Arrays;
@@ -102,8 +101,9 @@ final class BatteryController {
    @GuardedBy("mLock")
    private BluetoothBatteryManager.BluetoothBatteryListener mBluetoothBatteryListener;

    BatteryController(Context context, NativeInputManagerService nativeService, Looper looper) {
        this(context, nativeService, looper, new UEventManager() {},
    BatteryController(Context context, NativeInputManagerService nativeService, Looper looper,
            UEventManager uEventManager) {
        this(context, nativeService, looper, uEventManager,
                new LocalBluetoothBatteryManager(context, looper));
    }

@@ -567,7 +567,7 @@ final class BatteryController {
        private BluetoothAdapter.OnMetadataChangedListener mBluetoothMetadataListener;

        @Nullable
        private UEventBatteryListener mUEventBatteryListener;
        private BatteryController.UEventBatteryListener mUEventBatteryListener;

        DeviceMonitor(int deviceId) {
            mState = new State(deviceId);
@@ -630,7 +630,7 @@ final class BatteryController {
                return;
            }
            final int deviceId = mState.deviceId;
            mUEventBatteryListener = new UEventBatteryListener() {
            mUEventBatteryListener = new BatteryController.UEventBatteryListener() {
                @Override
                public void onBatteryUEvent(long eventTime) {
                    handleUEventNotification(deviceId, eventTime);
@@ -898,15 +898,10 @@ final class BatteryController {
        }
    }

    // An interface used to change the API of UEventObserver to a more test-friendly format.
    @VisibleForTesting
    interface UEventManager {

    @VisibleForTesting
        abstract class UEventBatteryListener {
            private final UEventObserver mObserver = new UEventObserver() {
    abstract static class UEventBatteryListener extends UEventManager.UEventListener {
        @Override
                public void onUEvent(UEvent event) {
        public void onUEvent(UEventObserver.UEvent event) {
            final long eventTime = SystemClock.uptimeMillis();
            if (DEBUG) {
                Slog.d(TAG,
@@ -920,20 +915,10 @@ final class BatteryController {
            }
            UEventBatteryListener.this.onBatteryUEvent(eventTime);
        }
            };

        public abstract void onBatteryUEvent(long eventTime);
    }

        default void addListener(UEventBatteryListener listener, String match) {
            listener.mObserver.startObserving(match);
        }

        default void removeListener(UEventBatteryListener listener) {
            listener.mObserver.stopObserving();
        }
    }

    // An interface used to change the API of adding a bluetooth battery listener to a more
    // test-friendly format.
    @VisibleForTesting
+12 −4
Original line number Diff line number Diff line
@@ -393,10 +393,12 @@ public class InputManagerService extends IInputManager.Stub
    static class Injector {
        private final Context mContext;
        private final Looper mLooper;
        private final UEventManager mUEventManager;

        Injector(Context context, Looper looper) {
        Injector(Context context, Looper looper, UEventManager uEventManager) {
            mContext = context;
            mLooper = looper;
            mUEventManager = uEventManager;
        }

        Context getContext() {
@@ -407,6 +409,10 @@ public class InputManagerService extends IInputManager.Stub
            return mLooper;
        }

        UEventManager getUEventManager() {
            return mUEventManager;
        }

        NativeInputManagerService getNativeService(InputManagerService service) {
            return new NativeInputManagerService.NativeImpl(service, mLooper.getQueue());
        }
@@ -417,7 +423,7 @@ public class InputManagerService extends IInputManager.Stub
    }

    public InputManagerService(Context context) {
        this(new Injector(context, DisplayThread.get().getLooper()));
        this(new Injector(context, DisplayThread.get().getLooper(), new UEventManager() {}));
    }

    @VisibleForTesting
@@ -432,10 +438,12 @@ public class InputManagerService extends IInputManager.Stub
        mSettingsObserver = new InputSettingsObserver(mContext, mHandler, this, mNative);
        mKeyboardLayoutManager = new KeyboardLayoutManager(mContext, mNative, mDataStore,
                injector.getLooper());
        mBatteryController = new BatteryController(mContext, mNative, injector.getLooper());
        mBatteryController = new BatteryController(mContext, mNative, injector.getLooper(),
                injector.getUEventManager());
        mKeyboardBacklightController = InputFeatureFlagProvider.isKeyboardBacklightControlEnabled()
                ? new KeyboardBacklightController(mContext, mNative, mDataStore,
                injector.getLooper()) : new KeyboardBacklightControllerInterface() {};
                        injector.getLooper(), injector.getUEventManager())
                : new KeyboardBacklightControllerInterface() {};
        mKeyRemapper = new KeyRemapper(mContext, mNative, mDataStore, injector.getLooper());

        mUseDevInputEventForAudioJack =
+9 −7
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ final class KeyboardBacklightController implements
    private final PersistentDataStore mDataStore;
    private final Handler mHandler;
    private final AnimatorFactory mAnimatorFactory;
    private final UEventManager mUEventManager;
    // Always access on handler thread or need to lock this for synchronization.
    private final SparseArray<KeyboardBacklightState> mKeyboardBacklights = new SparseArray<>(1);
    // Maintains state if all backlights should be on or turned off
@@ -123,19 +124,21 @@ final class KeyboardBacklightController implements
    }

    KeyboardBacklightController(Context context, NativeInputManagerService nativeService,
            PersistentDataStore dataStore, Looper looper) {
        this(context, nativeService, dataStore, looper, ValueAnimator::ofInt);
            PersistentDataStore dataStore, Looper looper, UEventManager uEventManager) {
        this(context, nativeService, dataStore, looper, ValueAnimator::ofInt, uEventManager);
    }

    @VisibleForTesting
    KeyboardBacklightController(Context context, NativeInputManagerService nativeService,
            PersistentDataStore dataStore, Looper looper, AnimatorFactory animatorFactory) {
            PersistentDataStore dataStore, Looper looper, AnimatorFactory animatorFactory,
            UEventManager uEventManager) {
        mContext = context;
        mNative = nativeService;
        mDataStore = dataStore;
        mHandler = new Handler(looper, this::handleMessage);
        mAnimatorFactory = animatorFactory;
        mAmbientController = new AmbientKeyboardBacklightController(context, looper);
        mUEventManager = uEventManager;
    }

    @Override
@@ -152,13 +155,12 @@ final class KeyboardBacklightController implements
        // We want to observe creation of such LED nodes since they might be created after device
        // FD created and InputDevice creation logic doesn't initialize LED nodes which leads to
        // backlight not working.
        UEventObserver observer = new UEventObserver() {
        mUEventManager.addListener(new UEventManager.UEventListener() {
            @Override
            public void onUEvent(UEvent event) {
            public void onUEvent(UEventObserver.UEvent event) {
                onKeyboardBacklightUEvent(event);
            }
        };
        observer.startObserving(UEVENT_KEYBOARD_BACKLIGHT_TAG);
        }, UEVENT_KEYBOARD_BACKLIGHT_TAG);

        if (InputFeatureFlagProvider.isAmbientKeyboardBacklightControlEnabled()) {
            // Start ambient backlight controller
+42 −0
Original line number Diff line number Diff line
/*
 * Copyright 2023 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.input;

import android.os.UEventObserver;

/** An interface used to change the API of UEventObserver to a more test-friendly format. */
interface UEventManager {

    abstract class UEventListener {
        private final UEventObserver mObserver = new UEventObserver() {
            @Override
            public void onUEvent(UEvent event) {
                UEventListener.this.onUEvent(event);
            }
        };

        public abstract void onUEvent(UEventObserver.UEvent event);
    }

    default void addListener(UEventListener listener, String match) {
        listener.mObserver.startObserving(match);
    }

    default void removeListener(UEventListener listener) {
        listener.mObserver.stopObserving();
    }
}
+1 −2
Original line number Diff line number Diff line
@@ -40,8 +40,7 @@ import androidx.test.core.app.ApplicationProvider
import com.android.server.input.BatteryController.BluetoothBatteryManager
import com.android.server.input.BatteryController.BluetoothBatteryManager.BluetoothBatteryListener
import com.android.server.input.BatteryController.POLLING_PERIOD_MILLIS
import com.android.server.input.BatteryController.UEventManager
import com.android.server.input.BatteryController.UEventManager.UEventBatteryListener
import com.android.server.input.BatteryController.UEventBatteryListener
import com.android.server.input.BatteryController.USI_BATTERY_VALIDITY_DURATION_MILLIS
import org.hamcrest.Description
import org.hamcrest.Matcher
Loading