Move InputDeviceVibratorManager functions to InputManagerGlobal
Move InputDeviceVibratorManager associated functions from InputManager to InputManagerGlobal. Bug: b/267758905 Test: Pre-submit Change-Id: I7a4792e6267e9af2c1f295876562cfd815ac9e58
This commit is contained in:
@@ -45,14 +45,14 @@ final class InputDeviceVibrator extends Vibrator {
|
||||
private final int mDeviceId;
|
||||
private final VibratorInfo mVibratorInfo;
|
||||
private final Binder mToken;
|
||||
private final InputManager mInputManager;
|
||||
private final InputManagerGlobal mGlobal;
|
||||
|
||||
@GuardedBy("mDelegates")
|
||||
private final ArrayMap<OnVibratorStateChangedListener,
|
||||
OnVibratorStateChangedListenerDelegate> mDelegates = new ArrayMap<>();
|
||||
|
||||
InputDeviceVibrator(InputManager inputManager, int deviceId, int vibratorId) {
|
||||
mInputManager = inputManager;
|
||||
InputDeviceVibrator(int deviceId, int vibratorId) {
|
||||
mGlobal = InputManagerGlobal.getInstance();
|
||||
mDeviceId = deviceId;
|
||||
mVibratorInfo = new VibratorInfo.Builder(vibratorId)
|
||||
.setCapabilities(IVibrator.CAP_AMPLITUDE_CONTROL)
|
||||
@@ -93,7 +93,7 @@ final class InputDeviceVibrator extends Vibrator {
|
||||
|
||||
@Override
|
||||
public boolean isVibrating() {
|
||||
return mInputManager.isVibrating(mDeviceId);
|
||||
return mGlobal.isVibrating(mDeviceId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,7 +132,7 @@ final class InputDeviceVibrator extends Vibrator {
|
||||
|
||||
final OnVibratorStateChangedListenerDelegate delegate =
|
||||
new OnVibratorStateChangedListenerDelegate(listener, executor);
|
||||
if (!mInputManager.registerVibratorStateListener(mDeviceId, delegate)) {
|
||||
if (!mGlobal.registerVibratorStateListener(mDeviceId, delegate)) {
|
||||
Log.w(TAG, "Failed to register vibrate state listener");
|
||||
return;
|
||||
}
|
||||
@@ -156,7 +156,7 @@ final class InputDeviceVibrator extends Vibrator {
|
||||
if (mDelegates.containsKey(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");
|
||||
return;
|
||||
}
|
||||
@@ -176,12 +176,12 @@ final class InputDeviceVibrator extends Vibrator {
|
||||
@Override
|
||||
public void vibrate(int uid, String opPkg, @NonNull VibrationEffect effect, String reason,
|
||||
@NonNull VibrationAttributes attributes) {
|
||||
mInputManager.vibrate(mDeviceId, effect, mToken);
|
||||
mGlobal.vibrate(mDeviceId, effect, mToken);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
mInputManager.cancelVibrate(mDeviceId, mToken);
|
||||
mGlobal.cancelVibrate(mDeviceId, mToken);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -40,7 +40,7 @@ public class InputDeviceVibratorManager extends VibratorManager
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
private final Binder mToken;
|
||||
private final InputManager mInputManager;
|
||||
private final InputManagerGlobal mGlobal;
|
||||
|
||||
// The input device Id.
|
||||
private final int mDeviceId;
|
||||
@@ -48,8 +48,8 @@ public class InputDeviceVibratorManager extends VibratorManager
|
||||
@GuardedBy("mVibrators")
|
||||
private final SparseArray<Vibrator> mVibrators = new SparseArray<>();
|
||||
|
||||
public InputDeviceVibratorManager(InputManager inputManager, int deviceId) {
|
||||
mInputManager = inputManager;
|
||||
public InputDeviceVibratorManager(int deviceId) {
|
||||
mGlobal = InputManagerGlobal.getInstance();
|
||||
mDeviceId = deviceId;
|
||||
mToken = new Binder();
|
||||
|
||||
@@ -61,10 +61,10 @@ public class InputDeviceVibratorManager extends VibratorManager
|
||||
mVibrators.clear();
|
||||
InputDevice inputDevice = InputDevice.getDevice(mDeviceId);
|
||||
final int[] vibratorIds =
|
||||
mInputManager.getVibratorIds(mDeviceId);
|
||||
mGlobal.getVibratorIds(mDeviceId);
|
||||
for (int i = 0; i < vibratorIds.length; 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
|
||||
public void vibrate(int uid, String opPkg, @NonNull CombinedVibration effect,
|
||||
String reason, @Nullable VibrationAttributes attributes) {
|
||||
mInputManager.vibrate(mDeviceId, effect, mToken);
|
||||
mGlobal.vibrate(mDeviceId, effect, mToken);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
mInputManager.cancelVibrate(mDeviceId, mToken);
|
||||
mGlobal.cancelVibrate(mDeviceId, mToken);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -36,15 +36,12 @@ import android.hardware.SensorManager;
|
||||
import android.hardware.lights.LightsManager;
|
||||
import android.os.Binder;
|
||||
import android.os.Build;
|
||||
import android.os.CombinedVibration;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.IVibratorStateListener;
|
||||
import android.os.InputEventInjectionSync;
|
||||
import android.os.Process;
|
||||
import android.os.RemoteException;
|
||||
import android.os.SystemClock;
|
||||
import android.os.VibrationEffect;
|
||||
import android.os.Vibrator;
|
||||
import android.os.VibratorManager;
|
||||
import android.util.Log;
|
||||
@@ -1377,7 +1374,7 @@ public final class InputManager {
|
||||
* @hide
|
||||
*/
|
||||
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
|
||||
public VibratorManager getInputDeviceVibratorManager(int deviceId) {
|
||||
return new InputDeviceVibratorManager(InputManager.this, 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();
|
||||
}
|
||||
return new InputDeviceVibratorManager(deviceId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,12 +30,15 @@ import android.hardware.input.InputManager.OnTabletModeChangedListener;
|
||||
import android.hardware.lights.Light;
|
||||
import android.hardware.lights.LightState;
|
||||
import android.hardware.lights.LightsRequest;
|
||||
import android.os.CombinedVibration;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.IVibratorStateListener;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.VibrationEffect;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.view.Display;
|
||||
@@ -976,4 +979,82 @@ public final class InputManagerGlobal {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user