1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.internal.vibrator.persistence; 18 19 import android.annotation.NonNull; 20 21 import com.android.modules.utils.TypedXmlSerializer; 22 23 import java.io.IOException; 24 25 /** 26 * Serialized representation of a generic vibration. 27 * 28 * <p>This can be used to represent a {@link android.os.CombinedVibration} or a 29 * {@link android.os.VibrationEffect}. Instances can be created from vibration objects via 30 * {@link XmlSerializer}, or from XML content via {@link XmlParser}. 31 * 32 * <p>The separation of serialization and writing procedures enables configurable rules to define 33 * which vibrations can be successfully serialized before any data is written to the output stream. 34 * Serialization can fail early and prevent writing partial data into the output. 35 * 36 * @param <T> The type of vibration represented by this serialization 37 * @hide 38 */ 39 public interface XmlSerializedVibration<T> { 40 41 /** Reconstructs the vibration using the serialized fields. */ 42 @NonNull deserialize()43 T deserialize(); 44 45 /** 46 * Writes the top level XML tag and the serialized fields into given XML. 47 * 48 * @param serializer The output XML serializer where the vibration will be written 49 */ write(@onNull TypedXmlSerializer serializer)50 void write(@NonNull TypedXmlSerializer serializer) throws IOException; 51 52 /** 53 * Writes the serialized fields into given XML, without the top level XML tag. 54 * 55 * <p>This allows the same serialized representation of a vibration to be used in different 56 * contexts (e.g. a {@link android.os.VibrationEffect} can be written into any of the tags 57 * {@code <vibration-effect>}, {@code <parallel-vibration-effect>} 58 * or {@code <vibration-effect vibratorId="0">}). 59 * 60 * @param serializer The output XML serializer where the vibration will be written 61 */ writeContent(@onNull TypedXmlSerializer serializer)62 void writeContent(@NonNull TypedXmlSerializer serializer) throws IOException; 63 } 64