• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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}.
30  *
31  * <p>The separation of serialization and writing procedures enables configurable rules to define
32  * which vibrations can be successfully serialized before any data is written to the output stream.
33  * Serialization can fail early and prevent writing partial data into the output.
34  *
35  * @param <T> The type of vibration represented by this serialization
36  * @hide
37  */
38 public interface XmlSerializedVibration<T> {
39 
40     /** Reconstructs the vibration using the serialized fields. */
41     @NonNull
deserialize()42     T deserialize();
43 
44     /**
45      * Writes the top level XML tag and the serialized fields into given XML.
46      *
47      * @param serializer The output XML serializer where the vibration will be written
48      */
write(@onNull TypedXmlSerializer serializer)49     void write(@NonNull TypedXmlSerializer serializer) throws IOException;
50 
51     /**
52      * Writes the serialized fields into given XML, without the top level XML tag.
53      *
54      * <p>This allows the same serialized representation of a vibration to be used in different
55      * contexts (e.g. a {@link android.os.VibrationEffect} can be written into any of the tags
56      * {@code <vibration-effect>}, {@code <parallel-vibration-effect>}
57      * or {@code <vibration-effect vibratorId="0">}).
58      *
59      * @param serializer The output XML serializer where the vibration will be written
60      */
writeContent(@onNull TypedXmlSerializer serializer)61     void writeContent(@NonNull TypedXmlSerializer serializer) throws IOException;
62 }
63