Loading services/core/java/com/android/server/VibratorService.java +15 −2 Original line number Diff line number Diff line Loading @@ -127,6 +127,7 @@ public class VibratorService extends IVibratorService.Stub private final int mPreviousVibrationsLimit; private final boolean mAllowPriorityVibrationsInLowPowerMode; private final List<Integer> mSupportedEffects; private final List<Integer> mSupportedPrimitives; private final long mCapabilities; private final int mDefaultVibrationAmplitude; private final SparseArray<VibrationEffect> mFallbackEffects; Loading Loading @@ -184,6 +185,8 @@ public class VibratorService extends IVibratorService.Stub static native int[] vibratorGetSupportedEffects(long controllerPtr); static native int[] vibratorGetSupportedPrimitives(long controllerPtr); static native long vibratorPerformEffect( long controllerPtr, long effect, long strength, Vibration vibration); Loading Loading @@ -397,6 +400,7 @@ public class VibratorService extends IVibratorService.Stub mNativeWrapper.vibratorOff(); mSupportedEffects = asList(mNativeWrapper.vibratorGetSupportedEffects()); mSupportedPrimitives = asList(mNativeWrapper.vibratorGetSupportedPrimitives()); mCapabilities = mNativeWrapper.vibratorGetCapabilities(); mContext = context; Loading Loading @@ -647,8 +651,11 @@ public class VibratorService extends IVibratorService.Stub @Override // Binder call public boolean[] arePrimitivesSupported(int[] primitiveIds) { boolean[] supported = new boolean[primitiveIds.length]; if (hasCapability(IVibrator.CAP_COMPOSE_EFFECTS)) { Arrays.fill(supported, true); if (!hasCapability(IVibrator.CAP_COMPOSE_EFFECTS) || mSupportedPrimitives == null) { return supported; } for (int i = 0; i < primitiveIds.length; i++) { supported[i] = mSupportedPrimitives.contains(primitiveIds[i]); } return supported; } Loading Loading @@ -1501,6 +1508,7 @@ public class VibratorService extends IVibratorService.Stub pw.println(" mNotificationIntensity=" + mNotificationIntensity); pw.println(" mRingIntensity=" + mRingIntensity); pw.println(" mSupportedEffects=" + mSupportedEffects); pw.println(" mSupportedPrimitives=" + mSupportedPrimitives); pw.println(); pw.println(" Previous ring vibrations:"); for (VibrationInfo info : mPreviousRingVibrations) { Loading Loading @@ -1759,6 +1767,11 @@ public class VibratorService extends IVibratorService.Stub return VibratorService.vibratorGetSupportedEffects(mNativeControllerPtr); } /** Returns all compose primitives supported by the device vibrator. */ public int[] vibratorGetSupportedPrimitives() { return VibratorService.vibratorGetSupportedPrimitives(mNativeControllerPtr); } /** Turns vibrator on to perform one of the supported effects. */ public long vibratorPerformEffect(long effect, long strength, Vibration vibration) { return VibratorService.vibratorPerformEffect( Loading services/core/jni/com_android_server_VibratorService.cpp +19 −0 Original line number Diff line number Diff line Loading @@ -181,6 +181,24 @@ static jintArray vibratorGetSupportedEffects(JNIEnv* env, jclass /* clazz */, jl return effects; } static jintArray vibratorGetSupportedPrimitives(JNIEnv* env, jclass /* clazz */, jlong controllerPtr) { vibrator::HalController* controller = reinterpret_cast<vibrator::HalController*>(controllerPtr); if (controller == nullptr) { ALOGE("vibratorGetSupportedPrimitives failed because controller was not initialized"); return nullptr; } auto result = controller->getSupportedPrimitives(); if (!result.isOk()) { return nullptr; } std::vector<aidl::CompositePrimitive> supportedPrimitives = result.value(); jintArray primitives = env->NewIntArray(supportedPrimitives.size()); env->SetIntArrayRegion(primitives, 0, supportedPrimitives.size(), reinterpret_cast<jint*>(supportedPrimitives.data())); return primitives; } static jlong vibratorPerformEffect(JNIEnv* env, jclass /* clazz */, jlong controllerPtr, jlong effect, jlong strength, jobject vibration) { vibrator::HalController* controller = reinterpret_cast<vibrator::HalController*>(controllerPtr); Loading Loading @@ -259,6 +277,7 @@ static const JNINativeMethod method_table[] = { "VibratorService$Vibration;)V", (void*)vibratorPerformComposedEffect}, {"vibratorGetSupportedEffects", "(J)[I", (void*)vibratorGetSupportedEffects}, {"vibratorGetSupportedPrimitives", "(J)[I", (void*)vibratorGetSupportedPrimitives}, {"vibratorSetExternalControl", "(JZ)V", (void*)vibratorSetExternalControl}, {"vibratorGetCapabilities", "(J)J", (void*)vibratorGetCapabilities}, {"vibratorAlwaysOnEnable", "(JJJJ)V", (void*)vibratorAlwaysOnEnable}, Loading services/tests/servicestests/src/com/android/server/VibratorServiceTest.java +17 −2 Original line number Diff line number Diff line Loading @@ -223,9 +223,24 @@ public class VibratorServiceTest { } @Test public void arePrimitivesSupported_withComposeCapability_returnsAlwaysTrue() { public void arePrimitivesSupported_withNullResultFromNative_returnsAlwaysFalse() { mockVibratorCapabilities(IVibrator.CAP_COMPOSE_EFFECTS); assertArrayEquals(new boolean[]{true, true}, when(mNativeWrapperMock.vibratorGetSupportedPrimitives()).thenReturn(null); assertArrayEquals(new boolean[]{false, false}, createService().arePrimitivesSupported(new int[]{ VibrationEffect.Composition.PRIMITIVE_CLICK, VibrationEffect.Composition.PRIMITIVE_QUICK_RISE })); } @Test public void arePrimitivesSupported_withSomeSupportedPrimitives_returnsBasedOnNativeResult() { mockVibratorCapabilities(IVibrator.CAP_COMPOSE_EFFECTS); when(mNativeWrapperMock.vibratorGetSupportedPrimitives()) .thenReturn(new int[]{VibrationEffect.Composition.PRIMITIVE_CLICK}); assertArrayEquals(new boolean[]{true, false}, createService().arePrimitivesSupported(new int[]{ VibrationEffect.Composition.PRIMITIVE_CLICK, VibrationEffect.Composition.PRIMITIVE_QUICK_RISE Loading Loading
services/core/java/com/android/server/VibratorService.java +15 −2 Original line number Diff line number Diff line Loading @@ -127,6 +127,7 @@ public class VibratorService extends IVibratorService.Stub private final int mPreviousVibrationsLimit; private final boolean mAllowPriorityVibrationsInLowPowerMode; private final List<Integer> mSupportedEffects; private final List<Integer> mSupportedPrimitives; private final long mCapabilities; private final int mDefaultVibrationAmplitude; private final SparseArray<VibrationEffect> mFallbackEffects; Loading Loading @@ -184,6 +185,8 @@ public class VibratorService extends IVibratorService.Stub static native int[] vibratorGetSupportedEffects(long controllerPtr); static native int[] vibratorGetSupportedPrimitives(long controllerPtr); static native long vibratorPerformEffect( long controllerPtr, long effect, long strength, Vibration vibration); Loading Loading @@ -397,6 +400,7 @@ public class VibratorService extends IVibratorService.Stub mNativeWrapper.vibratorOff(); mSupportedEffects = asList(mNativeWrapper.vibratorGetSupportedEffects()); mSupportedPrimitives = asList(mNativeWrapper.vibratorGetSupportedPrimitives()); mCapabilities = mNativeWrapper.vibratorGetCapabilities(); mContext = context; Loading Loading @@ -647,8 +651,11 @@ public class VibratorService extends IVibratorService.Stub @Override // Binder call public boolean[] arePrimitivesSupported(int[] primitiveIds) { boolean[] supported = new boolean[primitiveIds.length]; if (hasCapability(IVibrator.CAP_COMPOSE_EFFECTS)) { Arrays.fill(supported, true); if (!hasCapability(IVibrator.CAP_COMPOSE_EFFECTS) || mSupportedPrimitives == null) { return supported; } for (int i = 0; i < primitiveIds.length; i++) { supported[i] = mSupportedPrimitives.contains(primitiveIds[i]); } return supported; } Loading Loading @@ -1501,6 +1508,7 @@ public class VibratorService extends IVibratorService.Stub pw.println(" mNotificationIntensity=" + mNotificationIntensity); pw.println(" mRingIntensity=" + mRingIntensity); pw.println(" mSupportedEffects=" + mSupportedEffects); pw.println(" mSupportedPrimitives=" + mSupportedPrimitives); pw.println(); pw.println(" Previous ring vibrations:"); for (VibrationInfo info : mPreviousRingVibrations) { Loading Loading @@ -1759,6 +1767,11 @@ public class VibratorService extends IVibratorService.Stub return VibratorService.vibratorGetSupportedEffects(mNativeControllerPtr); } /** Returns all compose primitives supported by the device vibrator. */ public int[] vibratorGetSupportedPrimitives() { return VibratorService.vibratorGetSupportedPrimitives(mNativeControllerPtr); } /** Turns vibrator on to perform one of the supported effects. */ public long vibratorPerformEffect(long effect, long strength, Vibration vibration) { return VibratorService.vibratorPerformEffect( Loading
services/core/jni/com_android_server_VibratorService.cpp +19 −0 Original line number Diff line number Diff line Loading @@ -181,6 +181,24 @@ static jintArray vibratorGetSupportedEffects(JNIEnv* env, jclass /* clazz */, jl return effects; } static jintArray vibratorGetSupportedPrimitives(JNIEnv* env, jclass /* clazz */, jlong controllerPtr) { vibrator::HalController* controller = reinterpret_cast<vibrator::HalController*>(controllerPtr); if (controller == nullptr) { ALOGE("vibratorGetSupportedPrimitives failed because controller was not initialized"); return nullptr; } auto result = controller->getSupportedPrimitives(); if (!result.isOk()) { return nullptr; } std::vector<aidl::CompositePrimitive> supportedPrimitives = result.value(); jintArray primitives = env->NewIntArray(supportedPrimitives.size()); env->SetIntArrayRegion(primitives, 0, supportedPrimitives.size(), reinterpret_cast<jint*>(supportedPrimitives.data())); return primitives; } static jlong vibratorPerformEffect(JNIEnv* env, jclass /* clazz */, jlong controllerPtr, jlong effect, jlong strength, jobject vibration) { vibrator::HalController* controller = reinterpret_cast<vibrator::HalController*>(controllerPtr); Loading Loading @@ -259,6 +277,7 @@ static const JNINativeMethod method_table[] = { "VibratorService$Vibration;)V", (void*)vibratorPerformComposedEffect}, {"vibratorGetSupportedEffects", "(J)[I", (void*)vibratorGetSupportedEffects}, {"vibratorGetSupportedPrimitives", "(J)[I", (void*)vibratorGetSupportedPrimitives}, {"vibratorSetExternalControl", "(JZ)V", (void*)vibratorSetExternalControl}, {"vibratorGetCapabilities", "(J)J", (void*)vibratorGetCapabilities}, {"vibratorAlwaysOnEnable", "(JJJJ)V", (void*)vibratorAlwaysOnEnable}, Loading
services/tests/servicestests/src/com/android/server/VibratorServiceTest.java +17 −2 Original line number Diff line number Diff line Loading @@ -223,9 +223,24 @@ public class VibratorServiceTest { } @Test public void arePrimitivesSupported_withComposeCapability_returnsAlwaysTrue() { public void arePrimitivesSupported_withNullResultFromNative_returnsAlwaysFalse() { mockVibratorCapabilities(IVibrator.CAP_COMPOSE_EFFECTS); assertArrayEquals(new boolean[]{true, true}, when(mNativeWrapperMock.vibratorGetSupportedPrimitives()).thenReturn(null); assertArrayEquals(new boolean[]{false, false}, createService().arePrimitivesSupported(new int[]{ VibrationEffect.Composition.PRIMITIVE_CLICK, VibrationEffect.Composition.PRIMITIVE_QUICK_RISE })); } @Test public void arePrimitivesSupported_withSomeSupportedPrimitives_returnsBasedOnNativeResult() { mockVibratorCapabilities(IVibrator.CAP_COMPOSE_EFFECTS); when(mNativeWrapperMock.vibratorGetSupportedPrimitives()) .thenReturn(new int[]{VibrationEffect.Composition.PRIMITIVE_CLICK}); assertArrayEquals(new boolean[]{true, false}, createService().arePrimitivesSupported(new int[]{ VibrationEffect.Composition.PRIMITIVE_CLICK, VibrationEffect.Composition.PRIMITIVE_QUICK_RISE Loading