Loading core/java/android/hardware/input/IInputManager.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -83,7 +83,7 @@ interface IInputManager { int isMicMuted(); // Input device vibrator control. void vibrate(int deviceId, in long[] pattern, int repeat, IBinder token); void vibrate(int deviceId, in long[] pattern, in int[] amplitudes, int repeat, IBinder token); void cancelVibrate(int deviceId, IBinder token); void setPointerIconType(int typeId); Loading core/java/android/hardware/input/InputManager.java +5 −2 Original line number Diff line number Diff line Loading @@ -54,8 +54,8 @@ import com.android.internal.os.SomeArgs; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.concurrent.Executor; import java.util.List; import java.util.concurrent.Executor; /** * Provides information about input devices and available key layouts. Loading Loading @@ -1298,14 +1298,17 @@ public final class InputManager { public void vibrate(int uid, String opPkg, VibrationEffect effect, String reason, AudioAttributes attributes) { long[] pattern; int[] amplitudes; int repeat; if (effect instanceof VibrationEffect.OneShot) { VibrationEffect.OneShot oneShot = (VibrationEffect.OneShot) effect; pattern = new long[] { 0, oneShot.getDuration() }; amplitudes = new int[] { 0, oneShot.getAmplitude() }; repeat = -1; } else if (effect instanceof VibrationEffect.Waveform) { VibrationEffect.Waveform waveform = (VibrationEffect.Waveform) effect; pattern = waveform.getTimings(); amplitudes = waveform.getAmplitudes(); repeat = waveform.getRepeatIndex(); } else { // TODO: Add support for prebaked effects Loading @@ -1314,7 +1317,7 @@ public final class InputManager { } try { mIm.vibrate(mDeviceId, pattern, repeat, mToken); mIm.vibrate(mDeviceId, pattern, amplitudes, repeat, mToken); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } Loading services/core/java/com/android/server/input/InputManagerService.java +3 −3 Original line number Diff line number Diff line Loading @@ -236,7 +236,7 @@ public class InputManagerService extends IInputManager.Stub private static native void nativeSetInteractive(long ptr, boolean interactive); private static native void nativeReloadCalibration(long ptr); private static native void nativeVibrate(long ptr, int deviceId, long[] pattern, int repeat, int token); int[] amplitudes, int repeat, int token); private static native void nativeCancelVibrate(long ptr, int deviceId, int token); private static native void nativeReloadKeyboardLayouts(long ptr); private static native void nativeReloadDeviceAliases(long ptr); Loading Loading @@ -1716,7 +1716,7 @@ public class InputManagerService extends IInputManager.Stub // Binder call @Override public void vibrate(int deviceId, long[] pattern, int repeat, IBinder token) { public void vibrate(int deviceId, long[] pattern, int[] amplitudes, int repeat, IBinder token) { if (repeat >= pattern.length) { throw new ArrayIndexOutOfBoundsException(); } Loading @@ -1738,7 +1738,7 @@ public class InputManagerService extends IInputManager.Stub synchronized (v) { v.mVibrating = true; nativeVibrate(mPtr, deviceId, pattern, repeat, v.mTokenValue); nativeVibrate(mPtr, deviceId, pattern, amplitudes, repeat, v.mTokenValue); } } Loading services/core/jni/com_android_server_input_InputManagerService.cpp +12 −8 Original line number Diff line number Diff line Loading @@ -1615,9 +1615,8 @@ static void nativeReloadCalibration(JNIEnv* env, jclass clazz, jlong ptr) { im->reloadCalibration(); } static void nativeVibrate(JNIEnv* env, jclass /* clazz */, jlong ptr, jint deviceId, jlongArray patternObj, jint repeat, jint token) { static void nativeVibrate(JNIEnv* env, jclass /* clazz */, jlong ptr, jint deviceId, jlongArray patternObj, jintArray amplitudesObj, jint repeat, jint token) { NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); size_t patternSize = env->GetArrayLength(patternObj); Loading @@ -1630,14 +1629,19 @@ static void nativeVibrate(JNIEnv* env, jlong* patternMillis = static_cast<jlong*>(env->GetPrimitiveArrayCritical( patternObj, nullptr)); nsecs_t pattern[patternSize]; jint* amplitudes = static_cast<jint*>(env->GetPrimitiveArrayCritical(amplitudesObj, nullptr)); std::vector<VibrationElement> pattern(patternSize); for (size_t i = 0; i < patternSize; i++) { pattern[i] = max(jlong(0), min(patternMillis[i], (jlong)(MAX_VIBRATE_PATTERN_DELAY_NSECS / 1000000LL))) * 1000000LL; jlong duration = max(min(patternMillis[i], (jlong)MAX_VIBRATE_PATTERN_DELAY_MSECS), (jlong)0); pattern[i].duration = std::chrono::milliseconds(duration); pattern[i].channels = {amplitudes[i]}; } env->ReleasePrimitiveArrayCritical(patternObj, patternMillis, JNI_ABORT); env->ReleasePrimitiveArrayCritical(amplitudesObj, amplitudes, JNI_ABORT); im->getInputManager()->getReader()->vibrate(deviceId, pattern, patternSize, repeat, token); im->getInputManager()->getReader()->vibrate(deviceId, pattern, repeat, token); } static void nativeCancelVibrate(JNIEnv* /* env */, Loading Loading @@ -1789,7 +1793,7 @@ static const JNINativeMethod gInputManagerMethods[] = { {"nativeSetShowTouches", "(JZ)V", (void*)nativeSetShowTouches}, {"nativeSetInteractive", "(JZ)V", (void*)nativeSetInteractive}, {"nativeReloadCalibration", "(J)V", (void*)nativeReloadCalibration}, {"nativeVibrate", "(JI[JII)V", (void*)nativeVibrate}, {"nativeVibrate", "(JI[J[III)V", (void*)nativeVibrate}, {"nativeCancelVibrate", "(JII)V", (void*)nativeCancelVibrate}, {"nativeReloadKeyboardLayouts", "(J)V", (void*)nativeReloadKeyboardLayouts}, {"nativeReloadDeviceAliases", "(J)V", (void*)nativeReloadDeviceAliases}, Loading Loading
core/java/android/hardware/input/IInputManager.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -83,7 +83,7 @@ interface IInputManager { int isMicMuted(); // Input device vibrator control. void vibrate(int deviceId, in long[] pattern, int repeat, IBinder token); void vibrate(int deviceId, in long[] pattern, in int[] amplitudes, int repeat, IBinder token); void cancelVibrate(int deviceId, IBinder token); void setPointerIconType(int typeId); Loading
core/java/android/hardware/input/InputManager.java +5 −2 Original line number Diff line number Diff line Loading @@ -54,8 +54,8 @@ import com.android.internal.os.SomeArgs; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.concurrent.Executor; import java.util.List; import java.util.concurrent.Executor; /** * Provides information about input devices and available key layouts. Loading Loading @@ -1298,14 +1298,17 @@ public final class InputManager { public void vibrate(int uid, String opPkg, VibrationEffect effect, String reason, AudioAttributes attributes) { long[] pattern; int[] amplitudes; int repeat; if (effect instanceof VibrationEffect.OneShot) { VibrationEffect.OneShot oneShot = (VibrationEffect.OneShot) effect; pattern = new long[] { 0, oneShot.getDuration() }; amplitudes = new int[] { 0, oneShot.getAmplitude() }; repeat = -1; } else if (effect instanceof VibrationEffect.Waveform) { VibrationEffect.Waveform waveform = (VibrationEffect.Waveform) effect; pattern = waveform.getTimings(); amplitudes = waveform.getAmplitudes(); repeat = waveform.getRepeatIndex(); } else { // TODO: Add support for prebaked effects Loading @@ -1314,7 +1317,7 @@ public final class InputManager { } try { mIm.vibrate(mDeviceId, pattern, repeat, mToken); mIm.vibrate(mDeviceId, pattern, amplitudes, repeat, mToken); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } Loading
services/core/java/com/android/server/input/InputManagerService.java +3 −3 Original line number Diff line number Diff line Loading @@ -236,7 +236,7 @@ public class InputManagerService extends IInputManager.Stub private static native void nativeSetInteractive(long ptr, boolean interactive); private static native void nativeReloadCalibration(long ptr); private static native void nativeVibrate(long ptr, int deviceId, long[] pattern, int repeat, int token); int[] amplitudes, int repeat, int token); private static native void nativeCancelVibrate(long ptr, int deviceId, int token); private static native void nativeReloadKeyboardLayouts(long ptr); private static native void nativeReloadDeviceAliases(long ptr); Loading Loading @@ -1716,7 +1716,7 @@ public class InputManagerService extends IInputManager.Stub // Binder call @Override public void vibrate(int deviceId, long[] pattern, int repeat, IBinder token) { public void vibrate(int deviceId, long[] pattern, int[] amplitudes, int repeat, IBinder token) { if (repeat >= pattern.length) { throw new ArrayIndexOutOfBoundsException(); } Loading @@ -1738,7 +1738,7 @@ public class InputManagerService extends IInputManager.Stub synchronized (v) { v.mVibrating = true; nativeVibrate(mPtr, deviceId, pattern, repeat, v.mTokenValue); nativeVibrate(mPtr, deviceId, pattern, amplitudes, repeat, v.mTokenValue); } } Loading
services/core/jni/com_android_server_input_InputManagerService.cpp +12 −8 Original line number Diff line number Diff line Loading @@ -1615,9 +1615,8 @@ static void nativeReloadCalibration(JNIEnv* env, jclass clazz, jlong ptr) { im->reloadCalibration(); } static void nativeVibrate(JNIEnv* env, jclass /* clazz */, jlong ptr, jint deviceId, jlongArray patternObj, jint repeat, jint token) { static void nativeVibrate(JNIEnv* env, jclass /* clazz */, jlong ptr, jint deviceId, jlongArray patternObj, jintArray amplitudesObj, jint repeat, jint token) { NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); size_t patternSize = env->GetArrayLength(patternObj); Loading @@ -1630,14 +1629,19 @@ static void nativeVibrate(JNIEnv* env, jlong* patternMillis = static_cast<jlong*>(env->GetPrimitiveArrayCritical( patternObj, nullptr)); nsecs_t pattern[patternSize]; jint* amplitudes = static_cast<jint*>(env->GetPrimitiveArrayCritical(amplitudesObj, nullptr)); std::vector<VibrationElement> pattern(patternSize); for (size_t i = 0; i < patternSize; i++) { pattern[i] = max(jlong(0), min(patternMillis[i], (jlong)(MAX_VIBRATE_PATTERN_DELAY_NSECS / 1000000LL))) * 1000000LL; jlong duration = max(min(patternMillis[i], (jlong)MAX_VIBRATE_PATTERN_DELAY_MSECS), (jlong)0); pattern[i].duration = std::chrono::milliseconds(duration); pattern[i].channels = {amplitudes[i]}; } env->ReleasePrimitiveArrayCritical(patternObj, patternMillis, JNI_ABORT); env->ReleasePrimitiveArrayCritical(amplitudesObj, amplitudes, JNI_ABORT); im->getInputManager()->getReader()->vibrate(deviceId, pattern, patternSize, repeat, token); im->getInputManager()->getReader()->vibrate(deviceId, pattern, repeat, token); } static void nativeCancelVibrate(JNIEnv* /* env */, Loading Loading @@ -1789,7 +1793,7 @@ static const JNINativeMethod gInputManagerMethods[] = { {"nativeSetShowTouches", "(JZ)V", (void*)nativeSetShowTouches}, {"nativeSetInteractive", "(JZ)V", (void*)nativeSetInteractive}, {"nativeReloadCalibration", "(J)V", (void*)nativeReloadCalibration}, {"nativeVibrate", "(JI[JII)V", (void*)nativeVibrate}, {"nativeVibrate", "(JI[J[III)V", (void*)nativeVibrate}, {"nativeCancelVibrate", "(JII)V", (void*)nativeCancelVibrate}, {"nativeReloadKeyboardLayouts", "(J)V", (void*)nativeReloadKeyboardLayouts}, {"nativeReloadDeviceAliases", "(J)V", (void*)nativeReloadDeviceAliases}, Loading