Skip to content

Commit

Permalink
Change <vibration> to <vibration-effect>
Browse files Browse the repository at this point in the history
<vibration> 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
<vibration> to <vibration-effect>.

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
  • Loading branch information
Yeabkal Wubshit committed Nov 29, 2023
1 parent 2bea0e4 commit 8969182
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 93 deletions.
36 changes: 18 additions & 18 deletions core/java/android/os/vibrator/persistence/VibrationXmlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@
*
* <pre>
* {@code
* <vibration>
* <vibration-effect>
* <predefined-effect name="click" />
* </vibration>
* </vibration-effect>
* }
* </pre>
*
* * Waveform vibration effects
*
* <pre>
* {@code
* <vibration>
* <vibration-effect>
* <waveform-effect>
* <waveform-entry amplitude="default" durationMs="10" />
* <waveform-entry amplitude="0" durationMs="10" />
Expand All @@ -77,39 +77,39 @@
* <waveform-entry amplitude="255" durationMs="20" />
* </repeating>
* </waveform-effect>
* </vibration>
* </vibration-effect>
* }
* </pre>
*
* * Primitive composition effects
*
* <pre>
* {@code
* <vibration>
* <vibration-effect>
* <primitive-effect name="click" />
* <primitive-effect name="slow_rise" scale="0.8" />
* <primitive-effect name="quick_fall" delayMs="50" />
* <primitive-effect name="tick" scale="0.5" delayMs="100" />
* </vibration>
* </vibration-effect>
* }
* </pre>
*
* <p>When the root element represents a selection list of vibration effects, the root tag should be
* a <vibration-select> tag. The root element should contain a list of vibration serializations.
* Each vibration within the root-element should follow the format discussed for the <vibration> tag
* above. See example below:
* Each vibration within the root-element should follow the format discussed for the
* <vibration-effect> tag above. See example below:
*
* <pre>
* {@code
* <vibration-select>
* <vibration>
* <vibration-effect>
* <predefined-effect name="click" />
* </vibration>
* <vibration>
* </vibration-effect>
* <vibration-effect>
* <waveform-effect>
* <waveform-entry amplitude="default" durationMs="10" />
* </waveform-effect>
* </vibration>
* </vibration-effect>
* </vibration-select>
* }
* </pre>
Expand Down Expand Up @@ -262,12 +262,12 @@ public static ParsedVibration parseDocument(@NonNull Reader reader, @Flags int f
* {@link ParsedVibration}.
*
* <p>Same as {@link #parseDocument(Reader, int)}, but, instead of parsing the full XML content,
* it takes a parser that points to either a <vibration> or a <vibration-select> start tag. No
* other parser position, including start of document, is considered valid.
* it takes a parser that points to either a <vibration-effect> or a <vibration-select> start
* tag. No other parser position, including start of document, is considered valid.
*
* <p>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.
* <p>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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -44,17 +44,17 @@
*
* <pre>
* {@code
* <vibration>
* <vibration-effect>
* <predefined-effect name="click" />
* </vibration>
* </vibration-effect>
* }
* </pre>
*
* * Waveform vibration effects
*
* <pre>
* {@code
* <vibration>
* <vibration-effect>
* <waveform-effect>
* <waveform-entry amplitude="default" durationMs="10" />
* <waveform-entry amplitude="0" durationMs="10" />
Expand All @@ -65,18 +65,18 @@
* <waveform-entry amplitude="255" durationMs="20" />
* </repeating>
* </waveform-effect>
* </vibration>
* </vibration-effect>
* }
* </pre>
*
* * Primitive composition effects
*
* <pre>
* {@code
* <vibration>
* <vibration-effect>
* <primitive-effect name="click" />
* <primitive-effect name="tick" scale="0.5" delayMs="100" />
* </vibration>
* </vibration-effect>
* }
* </pre>
*
Expand All @@ -94,7 +94,7 @@ public class VibrationEffectXmlParser {
public static XmlSerializedVibration<VibrationEffect> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public interface XmlSerializedVibration<T> {
*
* <p>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 <vibration>}, {@code <parallel-vibration>} or {@code <vibration vibratorId="0">}).
* {@code <vibration-effect>}, {@code <parallel-vibration-effect>}
* or {@code <vibration-effect vibratorId="0">}).
*
* @param serializer The output XML serializer where the vibration will be written
*/
Expand Down
4 changes: 2 additions & 2 deletions core/res/res/raw/default_ringtone_vibration_effect.ahv
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
-->

<vibration>
<vibration-effect>
<waveform-effect>
<waveform-entry amplitude="0" durationMs="0" />
<waveform-entry amplitude="255" durationMs="12" />
Expand All @@ -44,4 +44,4 @@
<waveform-entry amplitude="0" durationMs="1000" />
</repeating>
</waveform-effect>
</vibration>
</vibration-effect>
Loading

0 comments on commit 8969182

Please sign in to comment.