adjust haptic feedback test for device without vibrator
- performHapticFeedback will always return false when there is no vibrator
Bug: 7334352
Change-Id: I554c6fbb36a72e3b52abda22506eb4f18c30ade5
diff --git a/tests/tests/view/src/android/view/cts/ViewTest.java b/tests/tests/view/src/android/view/cts/ViewTest.java
index d3553a3..888bb73 100644
--- a/tests/tests/view/src/android/view/cts/ViewTest.java
+++ b/tests/tests/view/src/android/view/cts/ViewTest.java
@@ -34,6 +34,7 @@
import android.graphics.drawable.StateListDrawable;
import android.os.Parcelable;
import android.os.SystemClock;
+import android.os.Vibrator;
import android.test.ActivityInstrumentationTestCase2;
import android.test.TouchUtils;
import android.test.UiThreadTest;
@@ -3087,6 +3088,9 @@
}
public void testHapticFeedback() {
+ Vibrator vib = (Vibrator) mActivity.getSystemService(Context.VIBRATOR_SERVICE);
+ boolean hasVibrator = vib.hasVibrator();
+
final MockView view = (MockView) mActivity.findViewById(R.id.mock_view);
final int LONG_PRESS = HapticFeedbackConstants.LONG_PRESS;
final int FLAG_IGNORE_VIEW_SETTING = HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING;
@@ -3097,11 +3101,11 @@
assertFalse(view.isHapticFeedbackEnabled());
assertFalse(view.performHapticFeedback(LONG_PRESS));
assertFalse(view.performHapticFeedback(LONG_PRESS, FLAG_IGNORE_GLOBAL_SETTING));
- assertTrue(view.performHapticFeedback(LONG_PRESS, ALWAYS));
+ assertEquals(hasVibrator, view.performHapticFeedback(LONG_PRESS, ALWAYS));
view.setHapticFeedbackEnabled(true);
assertTrue(view.isHapticFeedbackEnabled());
- assertTrue(view.performHapticFeedback(LONG_PRESS, FLAG_IGNORE_GLOBAL_SETTING));
+ assertEquals(hasVibrator, view.performHapticFeedback(LONG_PRESS, FLAG_IGNORE_GLOBAL_SETTING));
}
public void testInputConnection() throws Throwable {