Merge changes I7a4792e6,Ib253fb03 into udc-dev
* changes: Move InputDeviceVibratorManager functions to InputManagerGlobal InputDeviceLightsManager to use InputManagerGlobal
This commit is contained in:
committed by
Android (Google) Code Review
commit
ba8a8ceb8f
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -33,21 +33,15 @@ 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;
|
||||
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;
|
||||
@@ -1380,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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1391,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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1499,77 +1415,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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,12 +27,18 @@ 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.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;
|
||||
@@ -903,4 +909,152 @@ 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();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 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