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 android.health.connect.accesslog;
18 
19 import android.annotation.NonNull;
20 import android.health.connect.internal.ParcelUtils;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.Objects;
27 
28 /** @hide */
29 public final class AccessLogsResponseParcel implements Parcelable {
30     @NonNull
31     public static final Creator<AccessLogsResponseParcel> CREATOR =
32             new Creator<>() {
33                 @Override
34                 public AccessLogsResponseParcel createFromParcel(Parcel in) {
35                     return new AccessLogsResponseParcel(in);
36                 }
37 
38                 @Override
39                 public AccessLogsResponseParcel[] newArray(int size) {
40                     return new AccessLogsResponseParcel[size];
41                 }
42             };
43 
44     private final List<AccessLog> mAccessLogsList;
45 
AccessLogsResponseParcel(@onNull Parcel in)46     private AccessLogsResponseParcel(@NonNull Parcel in) {
47         in = ParcelUtils.getParcelForSharedMemoryIfRequired(in);
48         mAccessLogsList = new ArrayList<>();
49         in.readParcelableList(mAccessLogsList, AccessLog.class.getClassLoader(), AccessLog.class);
50     }
51 
AccessLogsResponseParcel(@onNull List<AccessLog> accessLogs)52     public AccessLogsResponseParcel(@NonNull List<AccessLog> accessLogs) {
53         Objects.requireNonNull(accessLogs);
54 
55         mAccessLogsList = accessLogs;
56     }
57 
58     @Override
describeContents()59     public int describeContents() {
60         return 0;
61     }
62 
63     @Override
writeToParcel(@onNull Parcel dest, int flags)64     public void writeToParcel(@NonNull Parcel dest, int flags) {
65         ParcelUtils.putToRequiredMemory(dest, flags, this::writeToAccessLogParcel);
66     }
67 
writeToAccessLogParcel(@onNull Parcel dest)68     private void writeToAccessLogParcel(@NonNull Parcel dest) {
69         dest.writeParcelableList(mAccessLogsList, 0);
70     }
71 
72     @NonNull
getAccessLogs()73     public List<AccessLog> getAccessLogs() {
74         return mAccessLogsList;
75     }
76 }
77