summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--services/core/java/com/android/server/VibratorService.java17
-rw-r--r--services/core/jni/com_android_server_VibratorService.cpp19
-rw-r--r--services/tests/servicestests/src/com/android/server/VibratorServiceTest.java19
3 files changed, 51 insertions, 4 deletions
diff --git a/services/core/java/com/android/server/VibratorService.java b/services/core/java/com/android/server/VibratorService.java
index 32d02fb17983..96d973ec5272 100644
--- a/services/core/java/com/android/server/VibratorService.java
+++ b/services/core/java/com/android/server/VibratorService.java
@@ -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;
@@ -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);
@@ -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;
@@ -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;
}
@@ -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) {
@@ -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(
diff --git a/services/core/jni/com_android_server_VibratorService.cpp b/services/core/jni/com_android_server_VibratorService.cpp
index 529fb8838aa1..b3f3a5e1ff72 100644
--- a/services/core/jni/com_android_server_VibratorService.cpp
+++ b/services/core/jni/com_android_server_VibratorService.cpp
@@ -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);
@@ -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},
diff --git a/services/tests/servicestests/src/com/android/server/VibratorServiceTest.java b/services/tests/servicestests/src/com/android/server/VibratorServiceTest.java
index 02d10e3b6ce1..b7a36f2eaed2 100644
--- a/services/tests/servicestests/src/com/android/server/VibratorServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/VibratorServiceTest.java
@@ -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