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.aidl;
18 
19 import android.annotation.NonNull;
20 import android.health.connect.FetchDataOriginsPriorityOrderResponse;
21 import android.health.connect.datatypes.DataOrigin;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 
25 import java.util.List;
26 import java.util.stream.Collectors;
27 
28 /** @hide */
29 public final class GetPriorityResponseParcel implements Parcelable {
30     public static final Creator<GetPriorityResponseParcel> CREATOR =
31             new Creator<GetPriorityResponseParcel>() {
32                 @Override
33                 public GetPriorityResponseParcel createFromParcel(Parcel in) {
34                     return new GetPriorityResponseParcel(in);
35                 }
36 
37                 @Override
38                 public GetPriorityResponseParcel[] newArray(int size) {
39                     return new GetPriorityResponseParcel[size];
40                 }
41             };
42     private final List<String> mPackagesInPriorityOrder;
43 
GetPriorityResponseParcel(Parcel in)44     private GetPriorityResponseParcel(Parcel in) {
45         mPackagesInPriorityOrder = in.createStringArrayList();
46     }
47 
GetPriorityResponseParcel( @onNull FetchDataOriginsPriorityOrderResponse fetchDataOriginsPriorityOrderResponse)48     public GetPriorityResponseParcel(
49             @NonNull FetchDataOriginsPriorityOrderResponse fetchDataOriginsPriorityOrderResponse) {
50         mPackagesInPriorityOrder =
51                 fetchDataOriginsPriorityOrderResponse.getDataOriginsPriorityOrder().stream()
52                         .map(DataOrigin::getPackageName)
53                         .collect(Collectors.toList());
54     }
55 
getPriorityResponse()56     public FetchDataOriginsPriorityOrderResponse getPriorityResponse() {
57         return new FetchDataOriginsPriorityOrderResponse(
58                 mPackagesInPriorityOrder.stream()
59                         .map(
60                                 packageName ->
61                                         new DataOrigin.Builder()
62                                                 .setPackageName(packageName)
63                                                 .build())
64                         .collect(Collectors.toList()));
65     }
66 
67     @Override
describeContents()68     public int describeContents() {
69         return 0;
70     }
71 
72     @Override
writeToParcel(@onNull Parcel dest, int flags)73     public void writeToParcel(@NonNull Parcel dest, int flags) {
74         dest.writeStringList(mPackagesInPriorityOrder);
75     }
76 }
77