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

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

Move InputDeviceVibratorManager functions to InputManagerGlobal

Move InputDeviceVibratorManager associated
functions from InputManager to InputManagerGlobal.

Bug: b/267758905
Test: Pre-submit
Change-Id: I7a4792e6267e9af2c1f295876562cfd815ac9e58
parent cb5f26ea
Loading
Loading
Loading
Loading
+8 −8
Original line number Original line Diff line number Diff line
@@ -45,14 +45,14 @@ final class InputDeviceVibrator extends Vibrator {
    private final int mDeviceId;
    private final int mDeviceId;
    private final VibratorInfo mVibratorInfo;
    private final VibratorInfo mVibratorInfo;
    private final Binder mToken;
    private final Binder mToken;
    private final InputManager mInputManager;
    private final InputManagerGlobal mGlobal;


    @GuardedBy("mDelegates")
    @GuardedBy("mDelegates")
    private final ArrayMap<OnVibratorStateChangedListener,
    private final ArrayMap<OnVibratorStateChangedListener,
            OnVibratorStateChangedListenerDelegate> mDelegates = new ArrayMap<>();
            OnVibratorStateChangedListenerDelegate> mDelegates = new ArrayMap<>();


    InputDeviceVibrator(InputManager inputManager, int deviceId, int vibratorId) {
    InputDeviceVibrator(int deviceId, int vibratorId) {
        mInputManager = inputManager;
        mGlobal = InputManagerGlobal.getInstance();
        mDeviceId = deviceId;
        mDeviceId = deviceId;
        mVibratorInfo = new VibratorInfo.Builder(vibratorId)
        mVibratorInfo = new VibratorInfo.Builder(vibratorId)
                .setCapabilities(IVibrator.CAP_AMPLITUDE_CONTROL)
                .setCapabilities(IVibrator.CAP_AMPLITUDE_CONTROL)
@@ -93,7 +93,7 @@ final class InputDeviceVibrator extends Vibrator {


    @Override
    @Override
    public boolean isVibrating() {
    public boolean isVibrating() {
        return mInputManager.isVibrating(mDeviceId);
        return mGlobal.isVibrating(mDeviceId);
    }
    }


    /**
    /**
@@ -132,7 +132,7 @@ final class InputDeviceVibrator extends Vibrator {


            final OnVibratorStateChangedListenerDelegate delegate =
            final OnVibratorStateChangedListenerDelegate delegate =
                    new OnVibratorStateChangedListenerDelegate(listener, executor);
                    new OnVibratorStateChangedListenerDelegate(listener, executor);
            if (!mInputManager.registerVibratorStateListener(mDeviceId, delegate)) {
            if (!mGlobal.registerVibratorStateListener(mDeviceId, delegate)) {
                Log.w(TAG, "Failed to register vibrate state listener");
                Log.w(TAG, "Failed to register vibrate state listener");
                return;
                return;
            }
            }
@@ -156,7 +156,7 @@ final class InputDeviceVibrator extends Vibrator {
            if (mDelegates.containsKey(listener)) {
            if (mDelegates.containsKey(listener)) {
                final OnVibratorStateChangedListenerDelegate delegate = mDelegates.get(listener);
                final OnVibratorStateChangedListenerDelegate delegate = mDelegates.get(listener);


                if (!mInputManager.unregisterVibratorStateListener(mDeviceId, delegate)) {
                if (!mGlobal.unregisterVibratorStateListener(mDeviceId, delegate)) {
                    Log.w(TAG, "Failed to unregister vibrate state listener");
                    Log.w(TAG, "Failed to unregister vibrate state listener");
                    return;
                    return;
                }
                }
@@ -176,12 +176,12 @@ final class InputDeviceVibrator extends Vibrator {
    @Override
    @Override
    public void vibrate(int uid, String opPkg, @NonNull VibrationEffect effect, String reason,
    public void vibrate(int uid, String opPkg, @NonNull VibrationEffect effect, String reason,
            @NonNull VibrationAttributes attributes) {
            @NonNull VibrationAttributes attributes) {
        mInputManager.vibrate(mDeviceId, effect, mToken);
        mGlobal.vibrate(mDeviceId, effect, mToken);
    }
    }


    @Override
    @Override
    public void cancel() {
    public void cancel() {
        mInputManager.cancelVibrate(mDeviceId, mToken);
        mGlobal.cancelVibrate(mDeviceId, mToken);
    }
    }


    @Override
    @Override
+7 −7
Original line number Original line Diff line number Diff line
@@ -40,7 +40,7 @@ public class InputDeviceVibratorManager extends VibratorManager
    private static final boolean DEBUG = false;
    private static final boolean DEBUG = false;


    private final Binder mToken;
    private final Binder mToken;
    private final InputManager mInputManager;
    private final InputManagerGlobal mGlobal;


    // The input device Id.
    // The input device Id.
    private final int mDeviceId;
    private final int mDeviceId;
@@ -48,8 +48,8 @@ public class InputDeviceVibratorManager extends VibratorManager
    @GuardedBy("mVibrators")
    @GuardedBy("mVibrators")
    private final SparseArray<Vibrator> mVibrators = new SparseArray<>();
    private final SparseArray<Vibrator> mVibrators = new SparseArray<>();


    public InputDeviceVibratorManager(InputManager inputManager, int deviceId) {
    public InputDeviceVibratorManager(int deviceId) {
        mInputManager = inputManager;
        mGlobal = InputManagerGlobal.getInstance();
        mDeviceId = deviceId;
        mDeviceId = deviceId;
        mToken = new Binder();
        mToken = new Binder();


@@ -61,10 +61,10 @@ public class InputDeviceVibratorManager extends VibratorManager
            mVibrators.clear();
            mVibrators.clear();
            InputDevice inputDevice = InputDevice.getDevice(mDeviceId);
            InputDevice inputDevice = InputDevice.getDevice(mDeviceId);
            final int[] vibratorIds =
            final int[] vibratorIds =
                    mInputManager.getVibratorIds(mDeviceId);
                    mGlobal.getVibratorIds(mDeviceId);
            for (int i = 0; i < vibratorIds.length; i++) {
            for (int i = 0; i < vibratorIds.length; i++) {
                mVibrators.put(vibratorIds[i],
                mVibrators.put(vibratorIds[i],
                        new InputDeviceVibrator(mInputManager, mDeviceId, vibratorIds[i]));
                        new InputDeviceVibrator(mDeviceId, vibratorIds[i]));
            }
            }
        }
        }
    }
    }
@@ -127,12 +127,12 @@ public class InputDeviceVibratorManager extends VibratorManager
    @Override
    @Override
    public void vibrate(int uid, String opPkg, @NonNull CombinedVibration effect,
    public void vibrate(int uid, String opPkg, @NonNull CombinedVibration effect,
            String reason, @Nullable VibrationAttributes attributes) {
            String reason, @Nullable VibrationAttributes attributes) {
        mInputManager.vibrate(mDeviceId, effect, mToken);
        mGlobal.vibrate(mDeviceId, effect, mToken);
    }
    }


    @Override
    @Override
    public void cancel() {
    public void cancel() {
        mInputManager.cancelVibrate(mDeviceId, mToken);
        mGlobal.cancelVibrate(mDeviceId, mToken);
    }
    }


    @Override
    @Override
+2 −83
Original line number Original line Diff line number Diff line
@@ -36,15 +36,12 @@ import android.hardware.SensorManager;
import android.hardware.lights.LightsManager;
import android.hardware.lights.LightsManager;
import android.os.Binder;
import android.os.Binder;
import android.os.Build;
import android.os.Build;
import android.os.CombinedVibration;
import android.os.Handler;
import android.os.Handler;
import android.os.IBinder;
import android.os.IBinder;
import android.os.IVibratorStateListener;
import android.os.InputEventInjectionSync;
import android.os.InputEventInjectionSync;
import android.os.Process;
import android.os.Process;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.SystemClock;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.os.Vibrator;
import android.os.VibratorManager;
import android.os.VibratorManager;
import android.util.Log;
import android.util.Log;
@@ -1377,7 +1374,7 @@ public final class InputManager {
     * @hide
     * @hide
     */
     */
    public Vibrator getInputDeviceVibrator(int deviceId, int vibratorId) {
    public Vibrator getInputDeviceVibrator(int deviceId, int vibratorId) {
        return new InputDeviceVibrator(this, deviceId, vibratorId);
        return new InputDeviceVibrator(deviceId, vibratorId);
    }
    }


    /**
    /**
@@ -1388,85 +1385,7 @@ public final class InputManager {
     */
     */
    @NonNull
    @NonNull
    public VibratorManager getInputDeviceVibratorManager(int deviceId) {
    public VibratorManager getInputDeviceVibratorManager(int deviceId) {
        return new InputDeviceVibratorManager(InputManager.this, deviceId);
        return new InputDeviceVibratorManager(deviceId);
    }

    /*
     * Get the list of device vibrators
     * @return The list of vibrators IDs
     */
    int[] getVibratorIds(int deviceId) {
        try {
            return mIm.getVibratorIds(deviceId);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }

    /*
     * Perform vibration effect
     */
    void vibrate(int deviceId, VibrationEffect effect, IBinder token) {
        try {
            mIm.vibrate(deviceId, effect, token);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }

    /*
     * Perform combined vibration effect
     */
    void vibrate(int deviceId, CombinedVibration effect, IBinder token) {
        try {
            mIm.vibrateCombined(deviceId, effect, token);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }

    /*
     * Cancel an ongoing vibration
     */
    void cancelVibrate(int deviceId, IBinder token) {
        try {
            mIm.cancelVibrate(deviceId, token);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }

    /*
     * Check if input device is vibrating
     */
    boolean isVibrating(int deviceId)  {
        try {
            return mIm.isVibrating(deviceId);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }

    /**
     * Register input device vibrator state listener
     */
    boolean registerVibratorStateListener(int deviceId, IVibratorStateListener listener) {
        try {
            return mIm.registerVibratorStateListener(deviceId, listener);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }

    /**
     * Unregister input device vibrator state listener
     */
    boolean unregisterVibratorStateListener(int deviceId, IVibratorStateListener listener) {
        try {
            return mIm.unregisterVibratorStateListener(deviceId, listener);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }
    }


    /**
    /**
+81 −0
Original line number Original line Diff line number Diff line
@@ -30,12 +30,15 @@ import android.hardware.input.InputManager.OnTabletModeChangedListener;
import android.hardware.lights.Light;
import android.hardware.lights.Light;
import android.hardware.lights.LightState;
import android.hardware.lights.LightState;
import android.hardware.lights.LightsRequest;
import android.hardware.lights.LightsRequest;
import android.os.CombinedVibration;
import android.os.Handler;
import android.os.Handler;
import android.os.IBinder;
import android.os.IBinder;
import android.os.IVibratorStateListener;
import android.os.Looper;
import android.os.Looper;
import android.os.Message;
import android.os.Message;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.ServiceManager;
import android.os.VibrationEffect;
import android.util.Log;
import android.util.Log;
import android.util.SparseArray;
import android.util.SparseArray;
import android.view.Display;
import android.view.Display;
@@ -976,4 +979,82 @@ public final class InputManagerGlobal {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
    }
    }

    /*
     * Get the list of device vibrators
     * @return The list of vibrators IDs
     */
    int[] getVibratorIds(int deviceId) {
        try {
            return mIm.getVibratorIds(deviceId);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }

    /*
     * Perform vibration effect
     */
    void vibrate(int deviceId, VibrationEffect effect, IBinder token) {
        try {
            mIm.vibrate(deviceId, effect, token);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }

    /*
     * Perform combined vibration effect
     */
    void vibrate(int deviceId, CombinedVibration effect, IBinder token) {
        try {
            mIm.vibrateCombined(deviceId, effect, token);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }

    /*
     * Cancel an ongoing vibration
     */
    void cancelVibrate(int deviceId, IBinder token) {
        try {
            mIm.cancelVibrate(deviceId, token);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }

    /*
     * Check if input device is vibrating
     */
    boolean isVibrating(int deviceId)  {
        try {
            return mIm.isVibrating(deviceId);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }

    /**
     * Register input device vibrator state listener
     */
    boolean registerVibratorStateListener(int deviceId, IVibratorStateListener listener) {
        try {
            return mIm.registerVibratorStateListener(deviceId, listener);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }

    /**
     * Unregister input device vibrator state listener
     */
    boolean unregisterVibratorStateListener(int deviceId, IVibratorStateListener listener) {
        try {
            return mIm.unregisterVibratorStateListener(deviceId, listener);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }
}
}