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

Commit cb5f26ea authored by Asmita Poddar's avatar Asmita Poddar
Browse files

InputDeviceLightsManager to use InputManagerGlobal

Move InputDeviceLightsManager, along with its associated
functions from InputManager to InputManagerGlobal.

Bug: b/267758905
Test: Pre-submit
Change-Id: Ib253fb0365e7d99d2b2f4fc8cc9bebcd8ca753c9
parent 11d35a35
Loading
Loading
Loading
Loading
+11 −10
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.hardware.input;

import android.annotation.NonNull;
import android.app.ActivityThread;
import android.content.Context;
import android.hardware.lights.Light;
import android.hardware.lights.LightState;
import android.hardware.lights.LightsManager;
@@ -30,22 +31,22 @@ import java.lang.ref.Reference;
import java.util.List;

/**
 * LightsManager manages an input device's lights {@link android.hardware.input.Light}.
 * LightsManager manages an input device's lights {@link android.hardware.lights.Light}
 */
class InputDeviceLightsManager extends LightsManager {
    private static final String TAG = "InputDeviceLightsManager";
    private static final boolean DEBUG = false;

    private final InputManager mInputManager;
    private final InputManagerGlobal mGlobal;

    // The input device ID.
    private final int mDeviceId;
    // Package name
    private final String mPackageName;

    InputDeviceLightsManager(InputManager inputManager, int deviceId) {
        super(ActivityThread.currentActivityThread().getSystemContext());
        mInputManager = inputManager;
    InputDeviceLightsManager(Context context, int deviceId) {
        super(context);
        mGlobal = InputManagerGlobal.getInstance();
        mDeviceId = deviceId;
        mPackageName = ActivityThread.currentPackageName();
    }
@@ -57,7 +58,7 @@ class InputDeviceLightsManager extends LightsManager {
     */
    @Override
    public @NonNull List<Light> getLights() {
        return mInputManager.getLights(mDeviceId);
        return mGlobal.getLights(mDeviceId);
    }

    /**
@@ -68,7 +69,7 @@ class InputDeviceLightsManager extends LightsManager {
    @Override
    public @NonNull LightState getLightState(@NonNull Light light) {
        Preconditions.checkNotNull(light);
        return mInputManager.getLightState(mDeviceId, light);
        return mGlobal.getLightState(mDeviceId, light);
    }

    /**
@@ -77,7 +78,7 @@ class InputDeviceLightsManager extends LightsManager {
    @Override
    public @NonNull LightsSession openSession() {
        final LightsSession session = new InputDeviceLightsSession();
        mInputManager.openLightSession(mDeviceId, mPackageName, session.getToken());
        mGlobal.openLightSession(mDeviceId, mPackageName, session.getToken());
        return session;
    }

@@ -113,7 +114,7 @@ class InputDeviceLightsManager extends LightsManager {
            Preconditions.checkNotNull(request);
            Preconditions.checkArgument(!mClosed);

            mInputManager.requestLights(mDeviceId, request, getToken());
            mGlobal.requestLights(mDeviceId, request, getToken());
        }

        /**
@@ -122,7 +123,7 @@ class InputDeviceLightsManager extends LightsManager {
        @Override
        public void close() {
            if (!mClosed) {
                mInputManager.closeLightSession(mDeviceId, getToken());
                mGlobal.closeLightSession(mDeviceId, getToken());
                mClosed = true;
                mCloseGuard.close();
            }
+1 −74
Original line number Diff line number Diff line
@@ -33,10 +33,7 @@ import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.hardware.BatteryState;
import android.hardware.SensorManager;
import android.hardware.lights.Light;
import android.hardware.lights.LightState;
import android.hardware.lights.LightsManager;
import android.hardware.lights.LightsRequest;
import android.os.Binder;
import android.os.Build;
import android.os.CombinedVibration;
@@ -1499,77 +1496,7 @@ public final class InputManager {
     */
    @NonNull
    public LightsManager getInputDeviceLightsManager(int deviceId) {
        return new InputDeviceLightsManager(InputManager.this, deviceId);
    }

    /**
     * Gets a list of light objects associated with an input device.
     * @return The list of lights, never null.
     */
    @NonNull List<Light> getLights(int deviceId) {
        try {
            return mIm.getLights(deviceId);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Returns the state of an input device light.
     * @return the light state
     */
    @NonNull LightState getLightState(int deviceId, @NonNull Light light) {
        try {
            return mIm.getLightState(deviceId, light.getId());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Request to modify the states of multiple lights.
     *
     * @param request the settings for lights that should change
     */
    void requestLights(int deviceId, @NonNull LightsRequest request, IBinder token) {
        try {
            List<Integer> lightIdList = request.getLights();
            int[] lightIds = new int[lightIdList.size()];
            for (int i = 0; i < lightIds.length; i++) {
                lightIds[i] = lightIdList.get(i);
            }
            List<LightState> lightStateList = request.getLightStates();
            mIm.setLightStates(deviceId, lightIds,
                    lightStateList.toArray(new LightState[0]),
                    token);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Open light session for input device manager
     *
     * @param token The token for the light session
     */
    void openLightSession(int deviceId, String opPkg, @NonNull IBinder token) {
        try {
            mIm.openLightSession(deviceId, opPkg, token);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Close light session
     *
     */
    void closeLightSession(int deviceId, @NonNull IBinder token) {
        try {
            mIm.closeLightSession(deviceId, token);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
        return new InputDeviceLightsManager(getContext(), deviceId);
    }

    /**
+73 −0
Original line number Diff line number Diff line
@@ -27,6 +27,9 @@ import android.hardware.input.InputManager.InputDeviceBatteryListener;
import android.hardware.input.InputManager.InputDeviceListener;
import android.hardware.input.InputManager.KeyboardBacklightListener;
import android.hardware.input.InputManager.OnTabletModeChangedListener;
import android.hardware.lights.Light;
import android.hardware.lights.LightState;
import android.hardware.lights.LightsRequest;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
@@ -903,4 +906,74 @@ public final class InputManagerGlobal {
            throw ex.rethrowFromSystemServer();
        }
    }

    /**
     * Gets a list of light objects associated with an input device.
     * @return The list of lights, never null.
     */
    @NonNull List<Light> getLights(int deviceId) {
        try {
            return mIm.getLights(deviceId);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Returns the state of an input device light.
     * @return the light state
     */
    @NonNull LightState getLightState(int deviceId, @NonNull Light light) {
        try {
            return mIm.getLightState(deviceId, light.getId());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Request to modify the states of multiple lights.
     *
     * @param request the settings for lights that should change
     */
    void requestLights(int deviceId, @NonNull LightsRequest request, IBinder token) {
        try {
            List<Integer> lightIdList = request.getLights();
            int[] lightIds = new int[lightIdList.size()];
            for (int i = 0; i < lightIds.length; i++) {
                lightIds[i] = lightIdList.get(i);
            }
            List<LightState> lightStateList = request.getLightStates();
            mIm.setLightStates(deviceId, lightIds,
                    lightStateList.toArray(new LightState[0]),
                    token);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Open light session for input device manager
     *
     * @param token The token for the light session
     */
    void openLightSession(int deviceId, String opPkg, @NonNull IBinder token) {
        try {
            mIm.openLightSession(deviceId, opPkg, token);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Close light session
     *
     */
    void closeLightSession(int deviceId, @NonNull IBinder token) {
        try {
            mIm.closeLightSession(deviceId, token);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
}