1 /*
2  * Copyright (C) 2020 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 android.service.controls.actions;
18 
19 import android.annotation.NonNull;
20 import android.os.Parcel;
21 import android.os.Parcelable;
22 
23 import com.android.internal.util.Preconditions;
24 
25 /**
26  * Wrapper for parceling/unparceling {@link ControlAction}.
27  * @hide
28  */
29 public final class ControlActionWrapper implements Parcelable {
30 
31     private final @NonNull ControlAction mControlAction;
32 
ControlActionWrapper(@onNull ControlAction controlAction)33     public ControlActionWrapper(@NonNull ControlAction controlAction) {
34         Preconditions.checkNotNull(controlAction);
35 
36         mControlAction = controlAction;
37     }
38 
39     @Override
writeToParcel(@onNull Parcel dest, int flags)40     public void writeToParcel(@NonNull Parcel dest, int flags) {
41         dest.writeBundle(mControlAction.getDataBundle());
42     }
43 
44     @NonNull
getWrappedAction()45     public ControlAction getWrappedAction() {
46         return mControlAction;
47     }
48 
49     @Override
describeContents()50     public int describeContents() {
51         return 0;
52     }
53 
54     public static final @NonNull Creator<ControlActionWrapper> CREATOR =
55             new Creator<ControlActionWrapper>() {
56                 @Override
57                 public ControlActionWrapper createFromParcel(@NonNull Parcel in) {
58                     return new ControlActionWrapper(
59                             ControlAction.createActionFromBundle(in.readBundle()));
60                 }
61 
62                 @Override
63                 public ControlActionWrapper[] newArray(int size) {
64                     return new ControlActionWrapper[size];
65                 }
66             };
67 }
68