summaryrefslogtreecommitdiffstats
path: root/core/java/android/hardware/input
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2012-04-13 04:09:27 -0700
committerJeff Brown <jeffbrown@google.com>2012-04-13 17:01:15 -0700
commita47425a13c19f95057df78b8bb65bb25657e8753 (patch)
tree675c0d6bf611f2427bb3d11315d410bf9087b20a /core/java/android/hardware/input
parentc2346134bb519a54d50655cbef940fc3fdec60a9 (diff)
downloadframeworks_base-a47425a13c19f95057df78b8bb65bb25657e8753.zip
frameworks_base-a47425a13c19f95057df78b8bb65bb25657e8753.tar.gz
frameworks_base-a47425a13c19f95057df78b8bb65bb25657e8753.tar.bz2
Add support for input devices that have vibrators.
Added a getVibrator() method to InputDevice which returns a Vibrator associated with that input device. Its uses the same API as the system vibrator which makes it easy for applications to be modified to use one or the other. Bug: 6334179 Change-Id: Ifc7f13dbcb778670f3f1c07ccc562334e6109d2e
Diffstat (limited to 'core/java/android/hardware/input')
-rw-r--r--core/java/android/hardware/input/IInputManager.aidl5
-rwxr-xr-xcore/java/android/hardware/input/InputManager.java52
2 files changed, 57 insertions, 0 deletions
diff --git a/core/java/android/hardware/input/IInputManager.aidl b/core/java/android/hardware/input/IInputManager.aidl
index ca8321f..3137947 100644
--- a/core/java/android/hardware/input/IInputManager.aidl
+++ b/core/java/android/hardware/input/IInputManager.aidl
@@ -18,6 +18,7 @@ package android.hardware.input;
import android.hardware.input.KeyboardLayout;
import android.hardware.input.IInputDevicesChangedListener;
+import android.os.IBinder;
import android.view.InputDevice;
import android.view.InputEvent;
@@ -46,4 +47,8 @@ interface IInputManager {
// Registers an input devices changed listener.
void registerInputDevicesChangedListener(IInputDevicesChangedListener listener);
+
+ // Input device vibrator control.
+ void vibrate(int deviceId, in long[] pattern, int repeat, IBinder token);
+ void cancelVibrate(int deviceId, IBinder token);
}
diff --git a/core/java/android/hardware/input/InputManager.java b/core/java/android/hardware/input/InputManager.java
index 35c49a1..b39b823 100755
--- a/core/java/android/hardware/input/InputManager.java
+++ b/core/java/android/hardware/input/InputManager.java
@@ -19,12 +19,14 @@ package android.hardware.input;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.content.Context;
+import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
import android.os.ServiceManager;
+import android.os.Vibrator;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.util.Log;
@@ -587,6 +589,15 @@ public final class InputManager {
}
/**
+ * Gets a vibrator service associated with an input device, assuming it has one.
+ * @return The vibrator, never null.
+ * @hide
+ */
+ public Vibrator getInputDeviceVibrator(int deviceId) {
+ return new InputDeviceVibrator(deviceId);
+ }
+
+ /**
* Listens for changes in input devices.
*/
public interface InputDeviceListener {
@@ -645,4 +656,45 @@ public final class InputManager {
}
}
}
+
+ private final class InputDeviceVibrator extends Vibrator {
+ private final int mDeviceId;
+ private final Binder mToken;
+
+ public InputDeviceVibrator(int deviceId) {
+ mDeviceId = deviceId;
+ mToken = new Binder();
+ }
+
+ @Override
+ public boolean hasVibrator() {
+ return true;
+ }
+
+ @Override
+ public void vibrate(long milliseconds) {
+ vibrate(new long[] { 0, milliseconds}, -1);
+ }
+
+ @Override
+ public void vibrate(long[] pattern, int repeat) {
+ if (repeat >= pattern.length) {
+ throw new ArrayIndexOutOfBoundsException();
+ }
+ try {
+ mIm.vibrate(mDeviceId, pattern, repeat, mToken);
+ } catch (RemoteException ex) {
+ Log.w(TAG, "Failed to vibrate.", ex);
+ }
+ }
+
+ @Override
+ public void cancel() {
+ try {
+ mIm.cancelVibrate(mDeviceId, mToken);
+ } catch (RemoteException ex) {
+ Log.w(TAG, "Failed to cancel vibration.", ex);
+ }
+ }
+ }
}