|
Name |
|
Date |
Size |
#Lines |
LOC |
| .. | | - | - |
| accesslog/ | | 25-Apr-2025 | - | 345 | 216 |
| aidl/ | | 25-Apr-2025 | - | 3,360 | 1,994 |
| backuprestore/ | | 25-Apr-2025 | - | 421 | 263 |
| changelog/ | | 25-Apr-2025 | - | 623 | 369 |
| datatypes/ | | 25-Apr-2025 | - | 20,578 | 12,420 |
| exportimport/ | | 25-Apr-2025 | - | 831 | 439 |
| internal/ | | 25-Apr-2025 | - | 9,933 | 6,956 |
| migration/ | | 25-Apr-2025 | - | 1,302 | 732 |
| ratelimiter/ | | 25-Apr-2025 | - | 599 | 459 |
| restore/ | | 25-Apr-2025 | - | 291 | 170 |
| AggregateRecordsGroupedByDurationResponse.java | D | 25-Apr-2025 | 3.9 KiB | 111 | 56 |
| AggregateRecordsGroupedByPeriodResponse.java | D | 25-Apr-2025 | 4.2 KiB | 123 | 64 |
| AggregateRecordsRequest.java | D | 25-Apr-2025 | 4.6 KiB | 131 | 64 |
| AggregateRecordsResponse.java | D | 25-Apr-2025 | 5.5 KiB | 160 | 90 |
| AggregateResult.java | D | 25-Apr-2025 | 2.7 KiB | 91 | 48 |
| ApplicationInfoResponse.java | D | 25-Apr-2025 | 1.4 KiB | 47 | 18 |
| Constants.java | D | 25-Apr-2025 | 1.5 KiB | 43 | 18 |
| CreateMedicalDataSourceRequest.aidl | D | 25-Apr-2025 | 88 | 4 | 2 |
| CreateMedicalDataSourceRequest.java | D | 25-Apr-2025 | 11.1 KiB | 305 | 185 |
| DeleteMedicalResourcesRequest.aidl | D | 25-Apr-2025 | 87 | 4 | 2 |
| DeleteMedicalResourcesRequest.java | D | 25-Apr-2025 | 9.2 KiB | 240 | 138 |
| DeleteUsingFiltersRequest.java | D | 25-Apr-2025 | 5.2 KiB | 164 | 76 |
| FetchDataOriginsPriorityOrderResponse.java | D | 25-Apr-2025 | 1.5 KiB | 51 | 19 |
| GetMedicalDataSourcesRequest.aidl | D | 25-Apr-2025 | 86 | 4 | 2 |
| GetMedicalDataSourcesRequest.java | D | 25-Apr-2025 | 7.2 KiB | 205 | 115 |
| HealthApiVersion.java | D | 25-Apr-2025 | 903 | 31 | 7 |
| HealthConnectDataState.aidl | D | 25-Apr-2025 | 527 | 12 | 2 |
| HealthConnectDataState.java | D | 25-Apr-2025 | 11.4 KiB | 326 | 92 |
| HealthConnectException.java | D | 25-Apr-2025 | 4.5 KiB | 136 | 46 |
| HealthConnectManager.java | D | 25-Apr-2025 | 123.4 KiB | 2,868 | 1,685 |
| HealthDataCategory.java | D | 25-Apr-2025 | 1.8 KiB | 64 | 33 |
| HealthPermissionCategory.java | D | 25-Apr-2025 | 7.3 KiB | 228 | 110 |
| HealthPermissions.java | D | 25-Apr-2025 | 54.7 KiB | 1,381 | 625 |
| HealthServicesInitializer.java | D | 25-Apr-2025 | 2.9 KiB | 76 | 39 |
| InsertRecordsResponse.java | D | 25-Apr-2025 | 1.2 KiB | 41 | 14 |
| LocalTimeRangeFilter.java | D | 25-Apr-2025 | 4.8 KiB | 139 | 80 |
| MedicalResourceId.aidl | D | 25-Apr-2025 | 75 | 4 | 2 |
| MedicalResourceId.java | D | 25-Apr-2025 | 8.3 KiB | 208 | 120 |
| MedicalResourceTypeInfo.aidl | D | 25-Apr-2025 | 81 | 4 | 2 |
| MedicalResourceTypeInfo.java | D | 25-Apr-2025 | 4.9 KiB | 138 | 88 |
| PageTokenWrapper.java | D | 25-Apr-2025 | 7.8 KiB | 219 | 119 |
| ReadMedicalResourcesInitialRequest.java | D | 25-Apr-2025 | 9.6 KiB | 253 | 127 |
| ReadMedicalResourcesPageRequest.java | D | 25-Apr-2025 | 6.1 KiB | 174 | 83 |
| ReadMedicalResourcesRequest.java | D | 25-Apr-2025 | 2.3 KiB | 65 | 23 |
| ReadMedicalResourcesResponse.aidl | D | 25-Apr-2025 | 86 | 4 | 2 |
| ReadMedicalResourcesResponse.java | D | 25-Apr-2025 | 5.9 KiB | 164 | 106 |
| ReadRecordsRequest.java | D | 25-Apr-2025 | 1.7 KiB | 53 | 20 |
| ReadRecordsRequestUsingFilters.java | D | 25-Apr-2025 | 8.4 KiB | 229 | 119 |
| ReadRecordsRequestUsingIds.java | D | 25-Apr-2025 | 5.4 KiB | 143 | 67 |
| ReadRecordsResponse.java | D | 25-Apr-2025 | 1.7 KiB | 57 | 19 |
| RecordIdFilter.java | D | 25-Apr-2025 | 3.2 KiB | 97 | 43 |
| RecordTypeInfoResponse.java | D | 25-Apr-2025 | 2.4 KiB | 71 | 32 |
| TimeInstantRangeFilter.java | D | 25-Apr-2025 | 4.1 KiB | 130 | 66 |
| TimeRangeFilter.java | D | 25-Apr-2025 | 898 | 25 | 2 |
| TimeRangeFilterHelper.java | D | 25-Apr-2025 | 3.7 KiB | 93 | 49 |
| UpdateDataOriginPriorityOrderRequest.java | D | 25-Apr-2025 | 1.9 KiB | 65 | 26 |
| UpsertMedicalResourceRequest.aidl | D | 25-Apr-2025 | 86 | 4 | 2 |
| UpsertMedicalResourceRequest.java | D | 25-Apr-2025 | 9 KiB | 261 | 157 |
ReadMedicalResourcesInitialRequest.java
1 /*
2 * Copyright (C) 2024 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 package android.health.connect;
17
18 import static android.health.connect.Constants.DEFAULT_PAGE_SIZE;
19 import static android.health.connect.Constants.MAXIMUM_PAGE_SIZE;
20 import static android.health.connect.Constants.MINIMUM_PAGE_SIZE;
21 import static android.health.connect.datatypes.MedicalDataSource.validateMedicalDataSourceIds;
22 import static android.health.connect.datatypes.MedicalResource.MedicalResourceType;
23 import static android.health.connect.datatypes.MedicalResource.validateMedicalResourceType;
24 import static android.health.connect.datatypes.validation.ValidationUtils.requireInRange;
25
26 import static com.android.healthfitness.flags.Flags.FLAG_PERSONAL_HEALTH_RECORD;
27
28 import static java.util.Objects.hash;
29 import static java.util.Objects.requireNonNull;
30
31 import android.annotation.FlaggedApi;
32 import android.annotation.IntRange;
33 import android.annotation.NonNull;
34 import android.health.connect.aidl.ReadMedicalResourcesRequestParcel;
35 import android.health.connect.datatypes.MedicalDataSource;
36 import android.health.connect.datatypes.MedicalResource;
37 import android.util.ArraySet;
38
39 import java.util.HashSet;
40 import java.util.Set;
41
42 /**
43 * An initial read request with specified filters for {@link
44 * HealthConnectManager#readMedicalResources}.
45 *
46 * <p>On receiving the response, if {@link ReadMedicalResourcesResponse#getNextPageToken()} is not
47 * {@code null}, then use the next token with {@link ReadMedicalResourcesPageRequest} to read the
48 * next page.
49 *
50 * <p>Example usage:
51 *
52 * <pre>{@code
53 * ReadMedicalResourcesInitialRequest initialRequest
54 * = new ReadMedicalResourcesInitialRequest.Builder(...).build();
55 * ReadMedicalResourcesResponse response = makeRequest(initialRequest);
56 * String pageToken = response.getNextPageToken();
57 *
58 * while (pageToken != null) {
59 * ReadMedicalResourcesPageRequest pageRequest = new ReadMedicalResourcesPageRequest(pageToken);
60 * response = makeRequest(pageRequest);
61 * pageToken = response.getNextPageToken();
62 * }
63 * }</pre>
64 */
65 @FlaggedApi(FLAG_PERSONAL_HEALTH_RECORD)
66 public final class ReadMedicalResourcesInitialRequest extends ReadMedicalResourcesRequest {
67 @MedicalResourceType private final int mMedicalResourceType;
68 @NonNull private final Set<String> mDataSourceIds;
69
70 /**
71 * Creates a new instance of {@link ReadMedicalResourcesInitialRequest}. Please see {@link
72 * ReadMedicalResourcesInitialRequest.Builder} for more detailed parameters information.
73 */
ReadMedicalResourcesInitialRequest( @edicalResourceType int medicalResourceType, @NonNull Set<String> dataSourceIds, @IntRange(from = MINIMUM_PAGE_SIZE, to = MAXIMUM_PAGE_SIZE) int pageSize)74 private ReadMedicalResourcesInitialRequest(
75 @MedicalResourceType int medicalResourceType,
76 @NonNull Set<String> dataSourceIds,
77 @IntRange(from = MINIMUM_PAGE_SIZE, to = MAXIMUM_PAGE_SIZE) int pageSize) {
78 super(pageSize);
79 validateMedicalResourceType(medicalResourceType);
80 requireNonNull(dataSourceIds);
81 validateMedicalDataSourceIds(dataSourceIds);
82
83 mMedicalResourceType = medicalResourceType;
84 mDataSourceIds = dataSourceIds;
85 }
86
87 /** Returns the medical resource type. */
88 @MedicalResourceType
getMedicalResourceType()89 public int getMedicalResourceType() {
90 return mMedicalResourceType;
91 }
92
93 /**
94 * Returns the set of IDs of the {@link MedicalDataSource} filter to read from, or an empty set
95 * for no filter.
96 */
97 @NonNull
getDataSourceIds()98 public Set<String> getDataSourceIds() {
99 return new ArraySet<>(mDataSourceIds);
100 }
101
102 @Override
equals(Object o)103 public boolean equals(Object o) {
104 if (this == o) return true;
105 if (!(o instanceof ReadMedicalResourcesInitialRequest that)) return false;
106
107 return getMedicalResourceType() == that.getMedicalResourceType()
108 && getDataSourceIds().equals(that.getDataSourceIds())
109 && getPageSize() == that.getPageSize();
110 }
111
112 @Override
hashCode()113 public int hashCode() {
114 return hash(getMedicalResourceType(), getDataSourceIds(), getPageSize());
115 }
116
117 @Override
toString()118 public String toString() {
119 return this.getClass().getSimpleName()
120 + "{"
121 + "medicalResourceType="
122 + getMedicalResourceType()
123 + ",dataSourceIds="
124 + getDataSourceIds()
125 + ",pageSize="
126 + getPageSize()
127 + "}";
128 }
129
130 /**
131 * Returns an instance of {@link ReadMedicalResourcesRequestParcel} to carry the request.
132 *
133 * @hide
134 */
toParcel()135 public ReadMedicalResourcesRequestParcel toParcel() {
136 return new ReadMedicalResourcesRequestParcel(this);
137 }
138
139 /** Builder class for {@link ReadMedicalResourcesInitialRequest}. */
140 public static final class Builder {
141 @MedicalResourceType private int mMedicalResourceType;
142 @NonNull private Set<String> mDataSourceIds = new HashSet<>();
143 private int mPageSize = DEFAULT_PAGE_SIZE;
144
145 /**
146 * Constructs a new {@link ReadMedicalResourcesInitialRequest.Builder} instance.
147 *
148 * @param medicalResourceType The medical resource type.
149 * @throws IllegalArgumentException if the provided {@code medicalResourceType} is not a
150 * supported type.
151 */
Builder(@edicalResourceType int medicalResourceType)152 public Builder(@MedicalResourceType int medicalResourceType) {
153 validateMedicalResourceType(medicalResourceType);
154 mMedicalResourceType = medicalResourceType;
155 }
156
157 /** Constructs a clone of the other {@link ReadMedicalResourcesInitialRequest.Builder}. */
Builder(@onNull Builder other)158 public Builder(@NonNull Builder other) {
159 mMedicalResourceType = other.mMedicalResourceType;
160 mDataSourceIds.addAll(other.mDataSourceIds);
161 mPageSize = other.mPageSize;
162 }
163
164 /** Constructs a clone of the other {@link ReadMedicalResourcesInitialRequest} instance. */
Builder(@onNull ReadMedicalResourcesInitialRequest other)165 public Builder(@NonNull ReadMedicalResourcesInitialRequest other) {
166 mMedicalResourceType = other.getMedicalResourceType();
167 mDataSourceIds.addAll(other.getDataSourceIds());
168 mPageSize = other.getPageSize();
169 }
170
171 /**
172 * Sets the medical resource type.
173 *
174 * @throws IllegalArgumentException if the provided {@code medicalResourceType} is not a
175 * supported type.
176 */
177 @NonNull
setMedicalResourceType(@edicalResourceType int medicalResourceType)178 public Builder setMedicalResourceType(@MedicalResourceType int medicalResourceType) {
179 validateMedicalResourceType(medicalResourceType);
180 mMedicalResourceType = medicalResourceType;
181 return this;
182 }
183
184 /**
185 * Adds the data source ID based on which the read operation is to be performed. This should
186 * be an ID of the existing {@link MedicalDataSource}.
187 *
188 * <p>If no {@link MedicalDataSource} ID is added, then {@link MedicalResource}s from all
189 * {@link MedicalDataSource}s will be read.
190 *
191 * @throws IllegalArgumentException if the provided {@code dataSourceId} is not a valid ID.
192 */
193 @NonNull
addDataSourceId(@onNull String dataSourceId)194 public Builder addDataSourceId(@NonNull String dataSourceId) {
195 requireNonNull(dataSourceId);
196 validateMedicalDataSourceIds(Set.of(dataSourceId));
197 mDataSourceIds.add(dataSourceId);
198 return this;
199 }
200
201 /**
202 * Adds all data source IDs based on which the read operation is to be performed. This
203 * should all be IDs of existing {@link MedicalDataSource}s.
204 *
205 * <p>If no {@link MedicalDataSource} IDs are added, then {@link MedicalResource}s from all
206 * {@link MedicalDataSource}s will be read.
207 *
208 * @throws IllegalArgumentException if the provided {@code dataSourceIds} is null, or any ID
209 * in it is not valid.
210 */
211 @NonNull
addDataSourceIds(@onNull Set<String> dataSourceIds)212 public Builder addDataSourceIds(@NonNull Set<String> dataSourceIds) {
213 requireNonNull(dataSourceIds);
214 validateMedicalDataSourceIds(dataSourceIds);
215 mDataSourceIds.addAll(dataSourceIds);
216 return this;
217 }
218
219 /** Clears all the {@link MedicalDataSource} filters for this builder. */
220 @NonNull
clearDataSourceIds()221 public Builder clearDataSourceIds() {
222 mDataSourceIds.clear();
223 return this;
224 }
225
226 /**
227 * Sets the maximum number of {@code MedicalResource}s to be returned by the read operation.
228 *
229 * <p>If not set, default to 1000.
230 *
231 * @throws IllegalArgumentException if the provided {@code pageSize} is less than 1 or more
232 * than 5000.
233 */
234 @NonNull
setPageSize( @ntRangefrom = MINIMUM_PAGE_SIZE, to = MAXIMUM_PAGE_SIZE) int pageSize)235 public Builder setPageSize(
236 @IntRange(from = MINIMUM_PAGE_SIZE, to = MAXIMUM_PAGE_SIZE) int pageSize) {
237 requireInRange(pageSize, MINIMUM_PAGE_SIZE, MAXIMUM_PAGE_SIZE, "pageSize");
238 mPageSize = pageSize;
239 return this;
240 }
241
242 /**
243 * Returns a new instance of {@link ReadMedicalResourcesInitialRequest} with the specified
244 * parameters.
245 */
246 @NonNull
build()247 public ReadMedicalResourcesInitialRequest build() {
248 return new ReadMedicalResourcesInitialRequest(
249 mMedicalResourceType, mDataSourceIds, mPageSize);
250 }
251 }
252 }
253
ReadMedicalResourcesPageRequest.java
1 /*
2 * Copyright (C) 2024 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 package android.health.connect;
17
18 import static android.health.connect.Constants.DEFAULT_PAGE_SIZE;
19 import static android.health.connect.Constants.MAXIMUM_PAGE_SIZE;
20 import static android.health.connect.Constants.MINIMUM_PAGE_SIZE;
21 import static android.health.connect.datatypes.validation.ValidationUtils.requireInRange;
22
23 import static com.android.healthfitness.flags.Flags.FLAG_PERSONAL_HEALTH_RECORD;
24
25 import static java.util.Objects.hash;
26 import static java.util.Objects.requireNonNull;
27
28 import android.annotation.FlaggedApi;
29 import android.annotation.IntRange;
30 import android.annotation.NonNull;
31 import android.health.connect.aidl.ReadMedicalResourcesRequestParcel;
32
33 /**
34 * A page read request with specified {@code pageToken} for {@link
35 * HealthConnectManager#readMedicalResources}.
36 *
37 * <p>When making a new initial request with new filters, use {@link
38 * ReadMedicalResourcesInitialRequest}.
39 *
40 * <p>Example usage:
41 *
42 * <pre>{@code
43 * ReadMedicalResourcesInitialRequest initialRequest
44 * = new ReadMedicalResourcesInitialRequest.Builder(...).build();
45 * ReadMedicalResourcesResponse response = makeRequest(initialRequest);
46 * String pageToken = response.getNextPageToken();
47 *
48 * while (pageToken != null) {
49 * ReadMedicalResourcesPageRequest pageRequest = new ReadMedicalResourcesPageRequest(pageToken);
50 * response = makeRequest(pageRequest);
51 * pageToken = response.getNextPageToken();
52 * }
53 * }</pre>
54 */
55 @FlaggedApi(FLAG_PERSONAL_HEALTH_RECORD)
56 public final class ReadMedicalResourcesPageRequest extends ReadMedicalResourcesRequest {
57 @NonNull private final String mPageToken;
58
59 /**
60 * Creates a new instance of {@link ReadMedicalResourcesPageRequest}. Please see {@link
61 * ReadMedicalResourcesPageRequest.Builder} for more detailed parameters information.
62 */
ReadMedicalResourcesPageRequest( @onNull String pageToken, @IntRange(from = MINIMUM_PAGE_SIZE, to = MAXIMUM_PAGE_SIZE) int pageSize)63 private ReadMedicalResourcesPageRequest(
64 @NonNull String pageToken,
65 @IntRange(from = MINIMUM_PAGE_SIZE, to = MAXIMUM_PAGE_SIZE) int pageSize) {
66 super(pageSize);
67 requireNonNull(pageToken);
68 mPageToken = pageToken;
69 }
70
71 /** Returns the page token to read the requested page. */
72 @NonNull
getPageToken()73 public String getPageToken() {
74 return mPageToken;
75 }
76
77 @Override
equals(Object o)78 public boolean equals(Object o) {
79 if (this == o) return true;
80 if (!(o instanceof ReadMedicalResourcesPageRequest that)) return false;
81 return getPageToken().equals(that.getPageToken()) && getPageSize() == that.getPageSize();
82 }
83
84 @Override
hashCode()85 public int hashCode() {
86 return hash(getPageToken(), getPageSize());
87 }
88
89 @Override
toString()90 public String toString() {
91 return this.getClass().getSimpleName()
92 + "{"
93 + "pageToken="
94 + getPageToken()
95 + ",pageSize="
96 + getPageSize()
97 + "}";
98 }
99
100 /**
101 * Returns an instance of {@link ReadMedicalResourcesRequestParcel} to carry the request.
102 *
103 * @hide
104 */
toParcel()105 public ReadMedicalResourcesRequestParcel toParcel() {
106 return new ReadMedicalResourcesRequestParcel(this);
107 }
108
109 /** Builder class for {@link ReadMedicalResourcesPageRequest}. */
110 public static final class Builder {
111 @NonNull private String mPageToken;
112 private int mPageSize = DEFAULT_PAGE_SIZE;
113
114 /**
115 * Constructs a new {@link ReadMedicalResourcesPageRequest} instance.
116 *
117 * @param pageToken The page token to read the requested page of the result, from the
118 * previous {@link ReadMedicalResourcesResponse#getNextPageToken()}.
119 */
Builder(@onNull String pageToken)120 public Builder(@NonNull String pageToken) {
121 requireNonNull(pageToken);
122 mPageToken = pageToken;
123 }
124
125 /** Constructs a clone of the other {@link ReadMedicalResourcesPageRequest.Builder}. */
Builder(@onNull Builder other)126 public Builder(@NonNull Builder other) {
127 mPageToken = other.mPageToken;
128 mPageSize = other.mPageSize;
129 }
130
131 /** Constructs a clone of the other {@link ReadMedicalResourcesPageRequest} instance. */
Builder(@onNull ReadMedicalResourcesPageRequest other)132 public Builder(@NonNull ReadMedicalResourcesPageRequest other) {
133 mPageToken = other.getPageToken();
134 mPageSize = other.getPageSize();
135 }
136
137 /**
138 * Sets page token to read the requested page of the result, from the previous {@link
139 * ReadMedicalResourcesResponse#getNextPageToken()}.
140 */
141 @NonNull
setPageToken(@onNull String pageToken)142 public Builder setPageToken(@NonNull String pageToken) {
143 requireNonNull(pageToken);
144 mPageToken = pageToken;
145 return this;
146 }
147
148 /**
149 * Sets the maximum number of {@code MedicalResource}s to be returned by the read operation.
150 *
151 * <p>If not set, default to 1000.
152 *
153 * @throws IllegalArgumentException if the provided {@code pageSize} is less than 1 or more
154 * than 5000.
155 */
156 @NonNull
setPageSize( @ntRangefrom = MINIMUM_PAGE_SIZE, to = MAXIMUM_PAGE_SIZE) int pageSize)157 public Builder setPageSize(
158 @IntRange(from = MINIMUM_PAGE_SIZE, to = MAXIMUM_PAGE_SIZE) int pageSize) {
159 requireInRange(pageSize, MINIMUM_PAGE_SIZE, MAXIMUM_PAGE_SIZE, "pageSize");
160 mPageSize = pageSize;
161 return this;
162 }
163
164 /**
165 * Returns a new instance of {@link ReadMedicalResourcesPageRequest} with the specified
166 * parameters.
167 */
168 @NonNull
build()169 public ReadMedicalResourcesPageRequest build() {
170 return new ReadMedicalResourcesPageRequest(mPageToken, mPageSize);
171 }
172 }
173 }
174
ReadMedicalResourcesRequest.java
1 /*
2 * Copyright (C) 2024 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;
18
19 import static android.health.connect.Constants.MAXIMUM_PAGE_SIZE;
20 import static android.health.connect.Constants.MINIMUM_PAGE_SIZE;
21 import static android.health.connect.datatypes.validation.ValidationUtils.requireInRange;
22
23 import static com.android.healthfitness.flags.Flags.FLAG_PERSONAL_HEALTH_RECORD;
24
25 import android.annotation.FlaggedApi;
26 import android.annotation.IntRange;
27 import android.health.connect.aidl.ReadMedicalResourcesRequestParcel;
28
29 /**
30 * A base class to represent a read request for {@link HealthConnectManager#readMedicalResources}.
31 */
32 @FlaggedApi(FLAG_PERSONAL_HEALTH_RECORD)
33 public abstract class ReadMedicalResourcesRequest {
34 private final int mPageSize;
35
36 /**
37 * @param pageSize The maximum number of {@code MedicalResource}s to be returned by the read
38 * operation.
39 * @throws IllegalArgumentException if {@code pageSize} is less than 1 or more than 5000.
40 * @hide
41 */
ReadMedicalResourcesRequest( @ntRangefrom = MINIMUM_PAGE_SIZE, to = MAXIMUM_PAGE_SIZE) int pageSize)42 protected ReadMedicalResourcesRequest(
43 @IntRange(from = MINIMUM_PAGE_SIZE, to = MAXIMUM_PAGE_SIZE) int pageSize) {
44 requireInRange(pageSize, MINIMUM_PAGE_SIZE, MAXIMUM_PAGE_SIZE, "pageSize");
45 mPageSize = pageSize;
46 }
47
48 /**
49 * Returns maximum number of {@code MedicalResource}s to be returned by the read operation if
50 * set, 1000 otherwise.
51 */
52 @IntRange(from = MINIMUM_PAGE_SIZE, to = MAXIMUM_PAGE_SIZE)
getPageSize()53 public int getPageSize() {
54 return mPageSize;
55 }
56
57 /**
58 * Returns an instance of {@link ReadMedicalResourcesRequestParcel} to carry the request.
59 *
60 * @hide
61 */
62 @SuppressWarnings("HiddenAbstractMethod")
toParcel()63 abstract ReadMedicalResourcesRequestParcel toParcel();
64 }
65
ReadMedicalResourcesResponse.aidl
ReadMedicalResourcesResponse.java
1 /*
2 * Copyright (C) 2024 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;
18
19 import static com.android.healthfitness.flags.Flags.FLAG_PERSONAL_HEALTH_RECORD;
20
21 import static java.util.Objects.hash;
22 import static java.util.Objects.requireNonNull;
23
24 import android.annotation.FlaggedApi;
25 import android.annotation.NonNull;
26 import android.annotation.Nullable;
27 import android.health.connect.datatypes.MedicalResource;
28 import android.health.connect.internal.ParcelUtils;
29 import android.os.Parcel;
30 import android.os.Parcelable;
31
32 import java.util.ArrayList;
33 import java.util.List;
34 import java.util.Objects;
35
36 /** A read response for {@link HealthConnectManager#readMedicalResources}. */
37 @FlaggedApi(FLAG_PERSONAL_HEALTH_RECORD)
38 public final class ReadMedicalResourcesResponse implements Parcelable {
39 @NonNull private final List<MedicalResource> mMedicalResources;
40 @Nullable private final String mNextPageToken;
41 private final int mRemainingCount;
42
43 /**
44 * Constructs a new {@link ReadMedicalResourcesResponse} instance.
45 *
46 * @param medicalResources List of {@link MedicalResource}s.
47 * @param nextPageToken The token value of the read result which can be used as input token for
48 * next read request. {@code null} if there are no more pages available.
49 * @param remainingCount the total number of medical resources remaining, excluding the ones in
50 * this response
51 */
ReadMedicalResourcesResponse( @onNull List<MedicalResource> medicalResources, @Nullable String nextPageToken, int remainingCount)52 public ReadMedicalResourcesResponse(
53 @NonNull List<MedicalResource> medicalResources,
54 @Nullable String nextPageToken,
55 int remainingCount) {
56 requireNonNull(medicalResources);
57 if (nextPageToken == null && remainingCount > 0) {
58 throw new IllegalArgumentException(
59 String.format(
60 "Remaining count must be 0 to have a null next page token, but was %d",
61 remainingCount));
62 }
63 if (nextPageToken != null && remainingCount == 0) {
64 throw new IllegalArgumentException("Next page token provided with no remaining data");
65 }
66 mMedicalResources = medicalResources;
67 mNextPageToken = nextPageToken;
68 mRemainingCount = remainingCount;
69 }
70
ReadMedicalResourcesResponse(@onNull Parcel in)71 private ReadMedicalResourcesResponse(@NonNull Parcel in) {
72 requireNonNull(in);
73 in = ParcelUtils.getParcelForSharedMemoryIfRequired(in);
74 mMedicalResources = new ArrayList<>();
75 in.readParcelableList(
76 mMedicalResources, MedicalResource.class.getClassLoader(), MedicalResource.class);
77 mNextPageToken = in.readString();
78 mRemainingCount = in.readInt();
79 }
80
81 @NonNull
82 public static final Creator<ReadMedicalResourcesResponse> CREATOR =
83 new Creator<>() {
84 @Override
85 public ReadMedicalResourcesResponse createFromParcel(Parcel in) {
86 return new ReadMedicalResourcesResponse(in);
87 }
88
89 @Override
90 public ReadMedicalResourcesResponse[] newArray(int size) {
91 return new ReadMedicalResourcesResponse[size];
92 }
93 };
94
95 /** Returns list of {@link MedicalResource}s. */
96 @NonNull
getMedicalResources()97 public List<MedicalResource> getMedicalResources() {
98 return mMedicalResources;
99 }
100
101 /**
102 * Returns a page token to read the next page of the result. {@code null} if there are no more
103 * pages available.
104 */
105 @Nullable
getNextPageToken()106 public String getNextPageToken() {
107 return mNextPageToken;
108 }
109
110 /**
111 * Returns the count of medical resources still remaining which were not returned due to
112 * pagination.
113 *
114 * <p>For a response with a null next page token, this will be 0. This result is accurate at the
115 * time the request was made, and with the permissions when the request was made. However, the
116 * actual results may change if permissions change or resources are inserted or deleted.
117 */
getRemainingCount()118 public int getRemainingCount() {
119 return mRemainingCount;
120 }
121
122 @Override
describeContents()123 public int describeContents() {
124 return 0;
125 }
126
127 @Override
writeToParcel(@onNull Parcel dest, int flags)128 public void writeToParcel(@NonNull Parcel dest, int flags) {
129 requireNonNull(dest);
130 ParcelUtils.putToRequiredMemory(dest, flags, this::writeToParcelInternal);
131 }
132
writeToParcelInternal(@onNull Parcel dest)133 private void writeToParcelInternal(@NonNull Parcel dest) {
134 requireNonNull(dest);
135 dest.writeParcelableList(mMedicalResources, 0);
136 dest.writeString(mNextPageToken);
137 dest.writeInt(mRemainingCount);
138 }
139
140 @Override
equals(Object o)141 public boolean equals(Object o) {
142 if (this == o) return true;
143 if (!(o instanceof ReadMedicalResourcesResponse that)) return false;
144 return getMedicalResources().equals(that.getMedicalResources())
145 && Objects.equals(getNextPageToken(), that.getNextPageToken())
146 && mRemainingCount == that.getRemainingCount();
147 }
148
149 @Override
hashCode()150 public int hashCode() {
151 return hash(getMedicalResources(), getNextPageToken(), mRemainingCount);
152 }
153
154 @Override
toString()155 public String toString() {
156 StringBuilder sb = new StringBuilder();
157 sb.append(this.getClass().getSimpleName()).append("{");
158 sb.append("medicalResources=").append(getMedicalResources());
159 sb.append(",nextPageToken=").append(getNextPageToken());
160 sb.append("}");
161 return sb.toString();
162 }
163 }
164