1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  * ```
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * ```
10  *
11  * Unless required by applicable law or agreed to in writing, software distributed under the License
12  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13  * or implied. See the License for the specific language governing permissions and limitations under
14  * the License.
15  */
16 package com.android.healthconnect.controller.permissions.data
17 
18 import androidx.annotation.StringRes
19 import com.android.healthconnect.controller.R
20 import com.google.common.collect.ImmutableMap
21 
22 data class FitnessPermissionStrings(
23     @StringRes val uppercaseLabel: Int,
24     @StringRes val lowercaseLabel: Int,
25     @StringRes val readContentDescription: Int,
26     @StringRes val writeContentDescription: Int
27 ) {
28     companion object {
fromPermissionTypenull29         fun fromPermissionType(
30             healthPermissionType: HealthPermissionType
31         ): FitnessPermissionStrings {
32             return PERMISSION_TYPE_STRINGS[healthPermissionType]
33                 ?: throw IllegalArgumentException(
34                     "No strings for permission group " + healthPermissionType.name)
35         }
36     }
37 }
38 
39 private val PERMISSION_TYPE_STRINGS: ImmutableMap<HealthPermissionType, FitnessPermissionStrings> =
40     ImmutableMap.Builder<HealthPermissionType, FitnessPermissionStrings>()
41         .put(
42             HealthPermissionType.ACTIVE_CALORIES_BURNED,
43             FitnessPermissionStrings(
44                 R.string.active_calories_burned_uppercase_label,
45                 R.string.active_calories_burned_lowercase_label,
46                 R.string.active_calories_burned_read_content_description,
47                 R.string.active_calories_burned_write_content_description))
48         .put(
49             HealthPermissionType.DISTANCE,
50             FitnessPermissionStrings(
51                 R.string.distance_uppercase_label,
52                 R.string.distance_lowercase_label,
53                 R.string.distance_read_content_description,
54                 R.string.distance_write_content_description))
55         .put(
56             HealthPermissionType.ELEVATION_GAINED,
57             FitnessPermissionStrings(
58                 R.string.elevation_gained_uppercase_label,
59                 R.string.elevation_gained_lowercase_label,
60                 R.string.elevation_gained_read_content_description,
61                 R.string.elevation_gained_write_content_description))
62         .put(
63             HealthPermissionType.EXERCISE,
64             FitnessPermissionStrings(
65                 R.string.exercise_uppercase_label,
66                 R.string.exercise_lowercase_label,
67                 R.string.exercise_read_content_description,
68                 R.string.exercise_write_content_description))
69         .put(
70             HealthPermissionType.SPEED,
71             FitnessPermissionStrings(
72                 R.string.speed_uppercase_label,
73                 R.string.speed_lowercase_label,
74                 R.string.speed_read_content_description,
75                 R.string.speed_write_content_description))
76         .put(
77             HealthPermissionType.POWER,
78             FitnessPermissionStrings(
79                 R.string.power_uppercase_label,
80                 R.string.power_lowercase_label,
81                 R.string.power_read_content_description,
82                 R.string.power_write_content_description))
83         .put(
84             HealthPermissionType.FLOORS_CLIMBED,
85             FitnessPermissionStrings(
86                 R.string.floors_climbed_uppercase_label,
87                 R.string.floors_climbed_lowercase_label,
88                 R.string.floors_climbed_read_content_description,
89                 R.string.floors_climbed_write_content_description))
90         .put(
91             HealthPermissionType.INTERMENSTRUAL_BLEEDING,
92             FitnessPermissionStrings(
93                 R.string.spotting_uppercase_label,
94                 R.string.spotting_lowercase_label,
95                 R.string.spotting_read_content_description,
96                 R.string.spotting_write_content_description))
97         .put(
98             HealthPermissionType.STEPS,
99             FitnessPermissionStrings(
100                 R.string.steps_uppercase_label,
101                 R.string.steps_lowercase_label,
102                 R.string.steps_read_content_description,
103                 R.string.steps_write_content_description))
104         .put(
105             HealthPermissionType.TOTAL_CALORIES_BURNED,
106             FitnessPermissionStrings(
107                 R.string.total_calories_burned_uppercase_label,
108                 R.string.total_calories_burned_lowercase_label,
109                 R.string.total_calories_burned_read_content_description,
110                 R.string.total_calories_burned_write_content_description))
111         .put(
112             HealthPermissionType.VO2_MAX,
113             FitnessPermissionStrings(
114                 R.string.vo2_max_uppercase_label,
115                 R.string.vo2_max_lowercase_label,
116                 R.string.vo2_max_read_content_description,
117                 R.string.vo2_max_write_content_description))
118         .put(
119             HealthPermissionType.WHEELCHAIR_PUSHES,
120             FitnessPermissionStrings(
121                 R.string.wheelchair_pushes_uppercase_label,
122                 R.string.wheelchair_pushes_lowercase_label,
123                 R.string.wheelchair_pushes_read_content_description,
124                 R.string.wheelchair_pushes_write_content_description))
125         .put(
126             HealthPermissionType.BASAL_METABOLIC_RATE,
127             FitnessPermissionStrings(
128                 R.string.basal_metabolic_rate_uppercase_label,
129                 R.string.basal_metabolic_rate_lowercase_label,
130                 R.string.basal_metabolic_rate_read_content_description,
131                 R.string.basal_metabolic_rate_write_content_description))
132         .put(
133             HealthPermissionType.BODY_FAT,
134             FitnessPermissionStrings(
135                 R.string.body_fat_uppercase_label,
136                 R.string.body_fat_lowercase_label,
137                 R.string.body_fat_read_content_description,
138                 R.string.body_fat_write_content_description))
139         .put(
140             HealthPermissionType.BODY_WATER_MASS,
141             FitnessPermissionStrings(
142                 R.string.body_water_mass_uppercase_label,
143                 R.string.body_water_mass_lowercase_label,
144                 R.string.body_water_mass_read_content_description,
145                 R.string.body_water_mass_write_content_description))
146         .put(
147             HealthPermissionType.BONE_MASS,
148             FitnessPermissionStrings(
149                 R.string.bone_mass_uppercase_label,
150                 R.string.bone_mass_lowercase_label,
151                 R.string.bone_mass_read_content_description,
152                 R.string.bone_mass_write_content_description))
153         .put(
154             HealthPermissionType.HEIGHT,
155             FitnessPermissionStrings(
156                 R.string.height_uppercase_label,
157                 R.string.height_lowercase_label,
158                 R.string.height_read_content_description,
159                 R.string.height_write_content_description))
160         .put(
161             HealthPermissionType.LEAN_BODY_MASS,
162             FitnessPermissionStrings(
163                 R.string.lean_body_mass_uppercase_label,
164                 R.string.lean_body_mass_lowercase_label,
165                 R.string.lean_body_mass_read_content_description,
166                 R.string.lean_body_mass_write_content_description))
167         .put(
168             HealthPermissionType.WEIGHT,
169             FitnessPermissionStrings(
170                 R.string.weight_uppercase_label,
171                 R.string.weight_lowercase_label,
172                 R.string.weight_read_content_description,
173                 R.string.weight_write_content_description))
174         .put(
175             HealthPermissionType.CERVICAL_MUCUS,
176             FitnessPermissionStrings(
177                 R.string.cervical_mucus_uppercase_label,
178                 R.string.cervical_mucus_lowercase_label,
179                 R.string.cervical_mucus_read_content_description,
180                 R.string.cervical_mucus_write_content_description))
181         .put(
182             HealthPermissionType.MENSTRUATION,
183             FitnessPermissionStrings(
184                 R.string.menstruation_uppercase_label,
185                 R.string.menstruation_lowercase_label,
186                 R.string.menstruation_read_content_description,
187                 R.string.menstruation_write_content_description))
188         .put(
189             HealthPermissionType.OVULATION_TEST,
190             FitnessPermissionStrings(
191                 R.string.ovulation_test_uppercase_label,
192                 R.string.ovulation_test_lowercase_label,
193                 R.string.ovulation_test_read_content_description,
194                 R.string.ovulation_test_write_content_description))
195         .put(
196             HealthPermissionType.SEXUAL_ACTIVITY,
197             FitnessPermissionStrings(
198                 R.string.sexual_activity_uppercase_label,
199                 R.string.sexual_activity_lowercase_label,
200                 R.string.sexual_activity_read_content_description,
201                 R.string.sexual_activity_write_content_description))
202         .put(
203             HealthPermissionType.HYDRATION,
204             FitnessPermissionStrings(
205                 R.string.hydration_uppercase_label,
206                 R.string.hydration_lowercase_label,
207                 R.string.hydration_read_content_description,
208                 R.string.hydration_write_content_description))
209         .put(
210             HealthPermissionType.NUTRITION,
211             FitnessPermissionStrings(
212                 R.string.nutrition_uppercase_label,
213                 R.string.nutrition_lowercase_label,
214                 R.string.nutrition_read_content_description,
215                 R.string.nutrition_write_content_description))
216         .put(
217             HealthPermissionType.SLEEP,
218             FitnessPermissionStrings(
219                 R.string.sleep_uppercase_label,
220                 R.string.sleep_lowercase_label,
221                 R.string.sleep_read_content_description,
222                 R.string.sleep_write_content_description))
223         .put(
224             HealthPermissionType.BASAL_BODY_TEMPERATURE,
225             FitnessPermissionStrings(
226                 R.string.basal_body_temperature_uppercase_label,
227                 R.string.basal_body_temperature_lowercase_label,
228                 R.string.basal_body_temperature_read_content_description,
229                 R.string.basal_body_temperature_write_content_description))
230         .put(
231             HealthPermissionType.BLOOD_GLUCOSE,
232             FitnessPermissionStrings(
233                 R.string.blood_glucose_uppercase_label,
234                 R.string.blood_glucose_lowercase_label,
235                 R.string.blood_glucose_read_content_description,
236                 R.string.blood_glucose_write_content_description))
237         .put(
238             HealthPermissionType.BLOOD_PRESSURE,
239             FitnessPermissionStrings(
240                 R.string.blood_pressure_uppercase_label,
241                 R.string.blood_pressure_lowercase_label,
242                 R.string.blood_pressure_read_content_description,
243                 R.string.blood_pressure_write_content_description))
244         .put(
245             HealthPermissionType.BODY_TEMPERATURE,
246             FitnessPermissionStrings(
247                 R.string.body_temperature_uppercase_label,
248                 R.string.body_temperature_lowercase_label,
249                 R.string.body_temperature_read_content_description,
250                 R.string.body_temperature_write_content_description))
251         .put(
252             HealthPermissionType.HEART_RATE,
253             FitnessPermissionStrings(
254                 R.string.heart_rate_uppercase_label,
255                 R.string.heart_rate_lowercase_label,
256                 R.string.heart_rate_read_content_description,
257                 R.string.heart_rate_write_content_description))
258         .put(
259             HealthPermissionType.HEART_RATE_VARIABILITY,
260             FitnessPermissionStrings(
261                 R.string.heart_rate_variability_uppercase_label,
262                 R.string.heart_rate_variability_lowercase_label,
263                 R.string.heart_rate_variability_read_content_description,
264                 R.string.heart_rate_variability_write_content_description))
265         .put(
266             HealthPermissionType.OXYGEN_SATURATION,
267             FitnessPermissionStrings(
268                 R.string.oxygen_saturation_uppercase_label,
269                 R.string.oxygen_saturation_lowercase_label,
270                 R.string.oxygen_saturation_read_content_description,
271                 R.string.oxygen_saturation_write_content_description))
272         .put(
273             HealthPermissionType.RESPIRATORY_RATE,
274             FitnessPermissionStrings(
275                 R.string.respiratory_rate_uppercase_label,
276                 R.string.respiratory_rate_lowercase_label,
277                 R.string.respiratory_rate_read_content_description,
278                 R.string.respiratory_rate_write_content_description))
279         .put(
280             HealthPermissionType.RESTING_HEART_RATE,
281             FitnessPermissionStrings(
282                 R.string.resting_heart_rate_uppercase_label,
283                 R.string.resting_heart_rate_lowercase_label,
284                 R.string.resting_heart_rate_read_content_description,
285                 R.string.resting_heart_rate_write_content_description))
286         .put(
287             HealthPermissionType.SKIN_TEMPERATURE,
288             FitnessPermissionStrings(
289                 R.string.skin_temperature_uppercase_label,
290                 R.string.skin_temperature_lowercase_label,
291                 R.string.skin_temperature_read_content_description,
292                 R.string.skin_temperature_write_content_description))
293         .put(
294             HealthPermissionType.EXERCISE_ROUTE,
295             FitnessPermissionStrings(
296                 R.string.exercise_route_uppercase_label,
297                 R.string.exercise_route_lowercase_label,
298                 R.string.exercise_route_read_content_description,
299                 R.string.exercise_route_write_content_description,
300             ))
301         .put(
302             HealthPermissionType.PLANNED_EXERCISE,
303             FitnessPermissionStrings(
304                 R.string.planned_exercise_uppercase_label,
305                 R.string.planned_exercise_lowercase_label,
306                 R.string.planned_exercise_read_content_description,
307                 R.string.planned_exercise_write_content_description,
308             ))
309         .buildOrThrow()
310