From 8969182e12fe27007a00cd6574ddc9d30888b352 Mon Sep 17 00:00:00 2001 From: Yeabkal Wubshit Date: Fri, 6 Oct 2023 15:30:43 -0700 Subject: [PATCH] Change to could later be used as a generic tag for different representations of vibrations, other than VibrationEffects. Thus, this change changes the tag used to serialize VibrationEffects from to . Contents of change is under the `enable_vibration_serialization_apis` flag, so no new flag is created as this CL is only a simple rename. Bug: 297296718 Test: unit tests, presubmit Change-Id: I8c7fb12ad3602ccc213b59b36db1e733c4e2b396 --- .../persistence/VibrationXmlParser.java | 36 +++++----- .../SerializedVibrationEffect.java | 4 +- .../persistence/VibrationEffectXmlParser.java | 16 ++--- .../vibrator/persistence/XmlConstants.java | 2 +- .../persistence/XmlSerializedVibration.java | 3 +- .../raw/default_ringtone_vibration_effect.ahv | 4 +- .../VibrationEffectXmlSerializationTest.java | 67 ++++++++++--------- core/xsd/Android.bp | 2 +- .../xsd/vibrator/vibration/schema/current.txt | 8 +-- .../vibration/vibration-plus-hidden-apis.xsd | 6 +- core/xsd/vibrator/vibration/vibration.xsd | 6 +- .../ringtone/res/raw/test_haptic_file.ahv | 4 +- .../server/power/ShutdownThreadTest.java | 12 ++-- .../HapticFeedbackCustomizationTest.java | 22 +++--- 14 files changed, 99 insertions(+), 93 deletions(-) diff --git a/core/java/android/os/vibrator/persistence/VibrationXmlParser.java b/core/java/android/os/vibrator/persistence/VibrationXmlParser.java index fed1053e2a12..3d711a7b69d5 100644 --- a/core/java/android/os/vibrator/persistence/VibrationXmlParser.java +++ b/core/java/android/os/vibrator/persistence/VibrationXmlParser.java @@ -56,9 +56,9 @@ * *
  *   {@code
- *     
+ *     
  *       
- *     
+ *     
  *   }
  * 
* @@ -66,7 +66,7 @@ * *
  *   {@code
- *     
+ *     
  *       
  *         
  *         
@@ -77,7 +77,7 @@
  *           
  *         
  *       
- *     
+ *     
  *   }
  * 
* @@ -85,31 +85,31 @@ * *
  *   {@code
- *     
+ *     
  *       
  *       
  *       
  *       
- *     
+ *     
  *   }
  * 
* *

When the root element represents a selection list of vibration effects, the root tag should be * a tag. The root element should contain a list of vibration serializations. - * Each vibration within the root-element should follow the format discussed for the tag - * above. See example below: + * Each vibration within the root-element should follow the format discussed for the + * tag above. See example below: * *

  *   {@code
  *     
- *       
+ *       
  *         
- *       
- *       
+ *       
+ *       
  *         
  *           
  *         
- *       
+ *       
  *     
  *   }
  * 
@@ -262,12 +262,12 @@ public static ParsedVibration parseDocument(@NonNull Reader reader, @Flags int f * {@link ParsedVibration}. * *

Same as {@link #parseDocument(Reader, int)}, but, instead of parsing the full XML content, - * it takes a parser that points to either a or a start tag. No - * other parser position, including start of document, is considered valid. + * it takes a parser that points to either a or a start + * tag. No other parser position, including start of document, is considered valid. * - *

This method parses until an end "vibration" or "vibration-select" tag (depending on the - * start tag found at the start of parsing). After a successful parsing, the parser will point - * to the end tag. + *

This method parses until an end "vibration-effect" or "vibration-select" tag (depending + * on the start tag found at the start of parsing). After a successful parsing, the parser + * will point to the end tag. * * @throws IOException error parsing from given {@link TypedXmlPullParser}. * @throws VibrationXmlParserException if the XML tag cannot be parsed into a @@ -308,7 +308,7 @@ private static ParsedVibration parseElementInternal( String tagName = parser.getName(); switch(tagName) { - case XmlConstants.TAG_VIBRATION: + case XmlConstants.TAG_VIBRATION_EFFECT: return new ParsedVibration(parseVibrationEffectInternal(parser, flags)); case XmlConstants.TAG_VIBRATION_SELECT: return parseVibrationSelectInternal(parser, flags); diff --git a/core/java/com/android/internal/vibrator/persistence/SerializedVibrationEffect.java b/core/java/com/android/internal/vibrator/persistence/SerializedVibrationEffect.java index 84e8647991da..23df3048e69c 100644 --- a/core/java/com/android/internal/vibrator/persistence/SerializedVibrationEffect.java +++ b/core/java/com/android/internal/vibrator/persistence/SerializedVibrationEffect.java @@ -65,9 +65,9 @@ public VibrationEffect deserialize() { @Override public void write(@NonNull TypedXmlSerializer serializer) throws IOException { - serializer.startTag(XmlConstants.NAMESPACE, XmlConstants.TAG_VIBRATION); + serializer.startTag(XmlConstants.NAMESPACE, XmlConstants.TAG_VIBRATION_EFFECT); writeContent(serializer); - serializer.endTag(XmlConstants.NAMESPACE, XmlConstants.TAG_VIBRATION); + serializer.endTag(XmlConstants.NAMESPACE, XmlConstants.TAG_VIBRATION_EFFECT); } @Override diff --git a/core/java/com/android/internal/vibrator/persistence/VibrationEffectXmlParser.java b/core/java/com/android/internal/vibrator/persistence/VibrationEffectXmlParser.java index 3561fe458085..2b8b61d50a6c 100644 --- a/core/java/com/android/internal/vibrator/persistence/VibrationEffectXmlParser.java +++ b/core/java/com/android/internal/vibrator/persistence/VibrationEffectXmlParser.java @@ -18,7 +18,7 @@ import static com.android.internal.vibrator.persistence.XmlConstants.TAG_PREDEFINED_EFFECT; import static com.android.internal.vibrator.persistence.XmlConstants.TAG_PRIMITIVE_EFFECT; -import static com.android.internal.vibrator.persistence.XmlConstants.TAG_VIBRATION; +import static com.android.internal.vibrator.persistence.XmlConstants.TAG_VIBRATION_EFFECT; import static com.android.internal.vibrator.persistence.XmlConstants.TAG_WAVEFORM_EFFECT; import android.annotation.NonNull; @@ -44,9 +44,9 @@ * *

  *   {@code
- *     
+ *     
  *       
- *     
+ *     
  *   }
  * 
* @@ -54,7 +54,7 @@ * *
  *   {@code
- *     
+ *     
  *       
  *         
  *         
@@ -65,7 +65,7 @@
  *           
  *         
  *       
- *     
+ *     
  *   }
  * 
* @@ -73,10 +73,10 @@ * *
  *   {@code
- *     
+ *     
  *       
  *       
- *     
+ *     
  *   }
  * 
* @@ -94,7 +94,7 @@ public class VibrationEffectXmlParser { public static XmlSerializedVibration parseTag( @NonNull TypedXmlPullParser parser, @XmlConstants.Flags int flags) throws XmlParserException, IOException { - XmlValidator.checkStartTag(parser, TAG_VIBRATION); + XmlValidator.checkStartTag(parser, TAG_VIBRATION_EFFECT); XmlValidator.checkTagHasNoUnexpectedAttributes(parser); return parseVibrationContent(parser, flags); diff --git a/core/java/com/android/internal/vibrator/persistence/XmlConstants.java b/core/java/com/android/internal/vibrator/persistence/XmlConstants.java index 6b69a158220c..8b92153b27db 100644 --- a/core/java/com/android/internal/vibrator/persistence/XmlConstants.java +++ b/core/java/com/android/internal/vibrator/persistence/XmlConstants.java @@ -35,7 +35,7 @@ public final class XmlConstants { public static final String NAMESPACE = null; - public static final String TAG_VIBRATION = "vibration"; + public static final String TAG_VIBRATION_EFFECT = "vibration-effect"; public static final String TAG_VIBRATION_SELECT = "vibration-select"; public static final String TAG_PREDEFINED_EFFECT = "predefined-effect"; diff --git a/core/java/com/android/internal/vibrator/persistence/XmlSerializedVibration.java b/core/java/com/android/internal/vibrator/persistence/XmlSerializedVibration.java index f807ab939c3a..3233fa224694 100644 --- a/core/java/com/android/internal/vibrator/persistence/XmlSerializedVibration.java +++ b/core/java/com/android/internal/vibrator/persistence/XmlSerializedVibration.java @@ -54,7 +54,8 @@ public interface XmlSerializedVibration { * *

This allows the same serialized representation of a vibration to be used in different * contexts (e.g. a {@link android.os.VibrationEffect} can be written into any of the tags - * {@code }, {@code } or {@code }). + * {@code }, {@code } + * or {@code }). * * @param serializer The output XML serializer where the vibration will be written */ diff --git a/core/res/res/raw/default_ringtone_vibration_effect.ahv b/core/res/res/raw/default_ringtone_vibration_effect.ahv index c66fc046316b..c4a27a4dc797 100644 --- a/core/res/res/raw/default_ringtone_vibration_effect.ahv +++ b/core/res/res/raw/default_ringtone_vibration_effect.ahv @@ -18,7 +18,7 @@ */ --> - + @@ -44,4 +44,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/core/tests/vibrator/src/android/os/vibrator/persistence/VibrationEffectXmlSerializationTest.java b/core/tests/vibrator/src/android/os/vibrator/persistence/VibrationEffectXmlSerializationTest.java index 2814a5f5366c..7d8c53faaec4 100644 --- a/core/tests/vibrator/src/android/os/vibrator/persistence/VibrationEffectXmlSerializationTest.java +++ b/core/tests/vibrator/src/android/os/vibrator/persistence/VibrationEffectXmlSerializationTest.java @@ -74,18 +74,18 @@ public void testParseElement_fromVibrationTag_succeedAndParserPointsToEndVibrati .addPrimitive(PRIMITIVE_CLICK) .addPrimitive(PRIMITIVE_TICK, 0.2497f) .compose(); - String xml = "" + String xml = "" + "" + "" - + ""; + + ""; VibrationEffect effect2 = VibrationEffect.startComposition() .addPrimitive(PRIMITIVE_LOW_TICK, 1f, 356) .addPrimitive(PRIMITIVE_SPIN, 0.6364f, 7) .compose(); - String xml2 = "" + String xml2 = "" + "" + "" - + ""; + + ""; TypedXmlPullParser parser = createXmlPullParser(xml); assertParseElementSucceeds(parser, effect); @@ -95,7 +95,7 @@ public void testParseElement_fromVibrationTag_succeedAndParserPointsToEndVibrati // Test no-issues when an end-tag follows the vibration XML. // To test this, starting with the corresponding "start-tag" is necessary. parser = createXmlPullParser("" + xml + ""); - // Move the parser once to point to the " tag. + // Move the parser once to point to the " tag. parser.next(); assertParseElementSucceeds(parser, effect); parser.next(); @@ -114,7 +114,7 @@ public void testParseElement_fromVibrationTag_succeedAndParserPointsToEndVibrati assertEndOfDocument(parser); // Check when there is comment before the end tag. - xml = ""; + xml = ""; parser = createXmlPullParser(xml); assertParseElementSucceeds( parser, VibrationEffect.startComposition().addPrimitive(PRIMITIVE_TICK).compose()); @@ -128,18 +128,18 @@ public void testParseElement_fromVibrationTag_succeedAndParserPointsToEndVibrati .addPrimitive(PRIMITIVE_CLICK) .addPrimitive(PRIMITIVE_TICK, 0.2497f) .compose(); - String vibrationXml1 = "" + String vibrationXml1 = "" + "" + "" - + ""; + + ""; VibrationEffect effect2 = VibrationEffect.startComposition() .addPrimitive(PRIMITIVE_LOW_TICK, 1f, 356) .addPrimitive(PRIMITIVE_SPIN, 0.6364f, 7) .compose(); - String vibrationXml2 = "" + String vibrationXml2 = "" + "" + "" - + ""; + + ""; String xml = "" + vibrationXml1 + vibrationXml2 + ""; TypedXmlPullParser parser = createXmlPullParser(xml); @@ -150,7 +150,7 @@ public void testParseElement_fromVibrationTag_succeedAndParserPointsToEndVibrati // Test no-issues when an end-tag follows the vibration XML. // To test this, starting with the corresponding "start-tag" is necessary. parser = createXmlPullParser("" + xml + ""); - // Move the parser once to point to the " tag. + // Move the parser once to point to the " tag. parser.next(); assertParseElementSucceeds(parser, effect1, effect2); parser.next(); @@ -183,7 +183,8 @@ public void testParseElement_fromVibrationTag_succeedAndParserPointsToEndVibrati @Test public void testParseElement_withHiddenApis_onlySucceedsWithFlag() throws Exception { // Check when the root tag is "vibration". - String xml = ""; + String xml = + ""; assertParseElementSucceeds(createXmlPullParser(xml), VibrationXmlSerializer.FLAG_ALLOW_HIDDEN_APIS, VibrationEffect.get(VibrationEffect.EFFECT_TEXTURE_TICK)); @@ -201,29 +202,29 @@ public void testParseElement_withHiddenApis_onlySucceedsWithFlag() throws Except public void testParseElement_badXml_throwsException() throws Exception { // No "vibration-select" tag. assertParseElementFails( - "random text"); - assertParseElementFails(""); - assertParseElementFails(""); - assertParseElementFails(""); + "rand text"); + assertParseElementFails(""); + assertParseElementFails(""); + assertParseElementFails(""); // Incomplete XML. assertParseElementFails(""); assertParseElementFails("" - + "" + + "" + "" - + ""); + + ""); // Bad vibration XML. assertParseElementFails("" + "" - + "" + + "" + ""); // "vibration-select" tag should have no attributes. assertParseElementFails("" - + "" + + "" + "" - + "" + + "" + ""); } @@ -235,12 +236,12 @@ public void testPrimitives_allSucceed() throws IOException { .addPrimitive(PRIMITIVE_LOW_TICK, 1f, 356) .addPrimitive(PRIMITIVE_SPIN, 0.6364f, 7) .compose(); - String xml = "" + String xml = "" + "" + "" + "" + "" - + ""; + + ""; assertPublicApisParserSucceeds(xml, effect); assertPublicApisSerializerSucceeds(effect, "click", "tick", "low_tick", "spin"); @@ -254,8 +255,9 @@ public void testPrimitives_allSucceed() throws IOException { @Test public void testParseDocument_withVibrationSelectTag_withHiddenApis_onlySucceedsWithFlag() throws Exception { - // Check when the root tag is "vibration". - String xml = ""; + // Check when the root tag is "vibration-effect". + String xml = + ""; assertParseDocumentSucceeds(xml, VibrationXmlSerializer.FLAG_ALLOW_HIDDEN_APIS, VibrationEffect.get(VibrationEffect.EFFECT_TEXTURE_TICK)); @@ -273,14 +275,14 @@ public void testParseDocument_withVibrationSelectTag_withHiddenApis_onlySucceeds public void testWaveforms_allSucceed() throws IOException { VibrationEffect effect = VibrationEffect.createWaveform(new long[]{123, 456, 789, 0}, new int[]{254, 1, 255, 0}, /* repeat= */ 0); - String xml = "" + String xml = "" + "" + "" + "" + "" + "" + "" - + ""; + + ""; assertPublicApisParserSucceeds(xml, effect); assertPublicApisSerializerSucceeds(effect, "123", "456", "789", "254", "1", "255", "0"); @@ -297,7 +299,8 @@ public void testPredefinedEffects_publicEffectsWithDefaultFallback_allSucceed() for (Map.Entry entry : createPublicPredefinedEffectsMap().entrySet()) { VibrationEffect effect = VibrationEffect.get(entry.getValue()); String xml = String.format( - "", entry.getKey()); + "", + entry.getKey()); assertPublicApisParserSucceeds(xml, effect); assertPublicApisSerializerSucceeds(effect, entry.getKey()); @@ -314,7 +317,8 @@ public void testPredefinedEffects_hiddenEffects_onlySucceedsWithFlag() throws IO for (Map.Entry entry : createHiddenPredefinedEffectsMap().entrySet()) { VibrationEffect effect = VibrationEffect.get(entry.getValue()); String xml = String.format( - "", entry.getKey()); + "", + entry.getKey()); assertPublicApisParserFails(xml); assertPublicApisSerializerFails(effect); @@ -332,7 +336,8 @@ public void testPredefinedEffects_allEffectsWithNonDefaultFallback_onlySucceedsW boolean nonDefaultFallback = !PrebakedSegment.DEFAULT_SHOULD_FALLBACK; VibrationEffect effect = VibrationEffect.get(entry.getValue(), nonDefaultFallback); String xml = String.format( - "", + "" + + "", entry.getKey(), nonDefaultFallback); assertPublicApisParserFails(xml); @@ -378,7 +383,7 @@ private void assertParseElementSucceeds( private void assertParseElementSucceeds( TypedXmlPullParser parser, int flags, VibrationEffect... effects) throws Exception { String tagName = parser.getName(); - assertThat(Set.of("vibration", "vibration-select")).contains(tagName); + assertThat(Set.of("vibration-effect", "vibration-select")).contains(tagName); assertThat(parseElement(parser, flags).getVibrationEffects()).containsExactly(effects); assertThat(parser.getEventType()).isEqualTo(XmlPullParser.END_TAG); diff --git a/core/xsd/Android.bp b/core/xsd/Android.bp index 4e418d6cc0f0..39b531167155 100644 --- a/core/xsd/Android.bp +++ b/core/xsd/Android.bp @@ -20,7 +20,7 @@ xsd_config { api_dir: "vibrator/vibration/schema", package_name: "com.android.internal.vibrator.persistence", root_elements: [ - "vibration", + "vibration-effect", "vibration-select", ], } diff --git a/core/xsd/vibrator/vibration/schema/current.txt b/core/xsd/vibrator/vibration/schema/current.txt index 176638462397..f0e13c4e8ca3 100644 --- a/core/xsd/vibrator/vibration/schema/current.txt +++ b/core/xsd/vibrator/vibration/schema/current.txt @@ -37,8 +37,8 @@ package com.android.internal.vibrator.persistence { enum_constant public static final com.android.internal.vibrator.persistence.PrimitiveEffectName tick; } - public class Vibration { - ctor public Vibration(); + public class VibrationEffect { + ctor public VibrationEffect(); method public com.android.internal.vibrator.persistence.PredefinedEffect getPredefinedEffect_optional(); method public com.android.internal.vibrator.persistence.PrimitiveEffect getPrimitiveEffect_optional(); method public com.android.internal.vibrator.persistence.WaveformEffect getWaveformEffect_optional(); @@ -49,7 +49,7 @@ package com.android.internal.vibrator.persistence { public class VibrationSelect { ctor public VibrationSelect(); - method public java.util.List getVibration(); + method public java.util.List getVibrationEffect(); } public enum WaveformAmplitudeDefault { @@ -80,7 +80,7 @@ package com.android.internal.vibrator.persistence { public class XmlParser { ctor public XmlParser(); method public static String readText(org.xmlpull.v1.XmlPullParser) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException; - method public static com.android.internal.vibrator.persistence.Vibration readVibration(java.io.InputStream) throws javax.xml.datatype.DatatypeConfigurationException, java.io.IOException, org.xmlpull.v1.XmlPullParserException; + method public static com.android.internal.vibrator.persistence.VibrationEffect readVibrationEffect(java.io.InputStream) throws javax.xml.datatype.DatatypeConfigurationException, java.io.IOException, org.xmlpull.v1.XmlPullParserException; method public static com.android.internal.vibrator.persistence.VibrationSelect readVibrationSelect(java.io.InputStream) throws javax.xml.datatype.DatatypeConfigurationException, java.io.IOException, org.xmlpull.v1.XmlPullParserException; method public static void skip(org.xmlpull.v1.XmlPullParser) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException; } diff --git a/core/xsd/vibrator/vibration/vibration-plus-hidden-apis.xsd b/core/xsd/vibrator/vibration/vibration-plus-hidden-apis.xsd index 679b9fa019ac..fcd250b4fc06 100644 --- a/core/xsd/vibrator/vibration/vibration-plus-hidden-apis.xsd +++ b/core/xsd/vibrator/vibration/vibration-plus-hidden-apis.xsd @@ -25,7 +25,7 @@ - + @@ -33,11 +33,11 @@ - + - + diff --git a/core/xsd/vibrator/vibration/vibration.xsd b/core/xsd/vibrator/vibration/vibration.xsd index 8406562b8579..b9de6914b9dc 100644 --- a/core/xsd/vibrator/vibration/vibration.xsd +++ b/core/xsd/vibrator/vibration/vibration.xsd @@ -23,7 +23,7 @@ - + @@ -31,11 +31,11 @@ - + - + diff --git a/media/tests/ringtone/res/raw/test_haptic_file.ahv b/media/tests/ringtone/res/raw/test_haptic_file.ahv index 18c99c79814f..d6eba1a4d7ba 100644 --- a/media/tests/ringtone/res/raw/test_haptic_file.ahv +++ b/media/tests/ringtone/res/raw/test_haptic_file.ahv @@ -1,4 +1,4 @@ - + @@ -14,4 +14,4 @@ - + diff --git a/services/tests/powerservicetests/src/com/android/server/power/ShutdownThreadTest.java b/services/tests/powerservicetests/src/com/android/server/power/ShutdownThreadTest.java index 2d1b545a9e6d..62075b828a62 100644 --- a/services/tests/powerservicetests/src/com/android/server/power/ShutdownThreadTest.java +++ b/services/tests/powerservicetests/src/com/android/server/power/ShutdownThreadTest.java @@ -51,31 +51,31 @@ public class ShutdownThreadTest { private static final String WAVEFORM_VIB_10MS_SERIALIZATION = """ - + - + """; private static final VibrationEffect WAVEFORM_VIB_10MS = VibrationEffect.createOneShot(10, 100); private static final String REPEATING_VIB_SERIALIZATION = """ - + - + """; private static final String CLICK_VIB_SERIALIZATION = """ - + - + """; private static final VibrationEffect CLILCK_VIB = diff --git a/services/tests/vibrator/src/com/android/server/vibrator/HapticFeedbackCustomizationTest.java b/services/tests/vibrator/src/com/android/server/vibrator/HapticFeedbackCustomizationTest.java index 04158c4d4f93..2b23b1897f59 100644 --- a/services/tests/vibrator/src/com/android/server/vibrator/HapticFeedbackCustomizationTest.java +++ b/services/tests/vibrator/src/com/android/server/vibrator/HapticFeedbackCustomizationTest.java @@ -56,22 +56,22 @@ public class HapticFeedbackCustomizationTest { @Rule public MockitoRule rule = MockitoJUnit.rule(); // Pairs of valid vibration XML along with their equivalent VibrationEffect. - private static final String COMPOSITION_VIBRATION_XML = "" + private static final String COMPOSITION_VIBRATION_XML = "" + "" - + ""; + + ""; private static final VibrationEffect COMPOSITION_VIBRATION = VibrationEffect.startComposition().addPrimitive(PRIMITIVE_TICK, 0.2497f).compose(); private static final String PREDEFINED_VIBRATION_XML = - ""; + ""; private static final VibrationEffect PREDEFINED_VIBRATION = VibrationEffect.createPredefined(EFFECT_CLICK); - private static final String WAVEFORM_VIBRATION_XML = "" + private static final String WAVEFORM_VIBRATION_XML = "" + "" + "" + "" - + ""; + + ""; private static final VibrationEffect WAVEFORM_VIBARTION = VibrationEffect.createWaveform(new long[] {123}, new int[] {254}, -1); @@ -259,13 +259,13 @@ public void testParseCustomizations_disallowedVibrationForHapticFeedback_throwsE assertParseCustomizationsFails( "" + "" - + "" + + "" + "" + "" + "" + "" + "" - + "" + + "" + "" + ""); } @@ -339,14 +339,14 @@ public void testParseCustomizations_badVibrationXml_throwsException() throws Exc assertParseCustomizationsFails( "" + "" - + "" + + "" + "" + ""); assertParseCustomizationsFails( "" + "" - + "" + + "" + "" + ""); @@ -354,14 +354,14 @@ public void testParseCustomizations_badVibrationXml_throwsException() throws Exc "" + "" + "" - + "" + + "" + "" + ""); assertParseCustomizationsFails( "" + "" - + "" + + "" + "" + "" + "");