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 com.android.healthconnect.controller.permissions.data
17 
18 import android.health.connect.HealthPermissions
19 import androidx.annotation.StringRes
20 import com.android.healthconnect.controller.R
21 import com.google.common.collect.ImmutableMap
22 
23 /** Represents the display strings used for Additional Permissions. */
24 data class AdditionalPermissionStrings(
25     @StringRes val permissionTitle: Int,
26     @StringRes val permissionDescription: Int,
27     @StringRes val requestTitle: Int,
28     @StringRes val requestDescription: Int,
29     @StringRes val permissionDescriptionFallback: Int = 0,
30     @StringRes val requestDescriptionFallback: Int = 0
31 ) {
32 
33     companion object {
fromAdditionalPermissionnull34         fun fromAdditionalPermission(
35             additionalPermission: HealthPermission.AdditionalPermission
36         ): AdditionalPermissionStrings {
37             return ADDITIONAL_PERMISSION_STRINGS[additionalPermission.additionalPermission]
38                 ?: throw IllegalArgumentException(
39                     "No strings for additional permission $additionalPermission")
40         }
41     }
42 }
43 
44 private val ADDITIONAL_PERMISSION_STRINGS: ImmutableMap<String, AdditionalPermissionStrings> =
45     ImmutableMap.Builder<String, AdditionalPermissionStrings>()
46         .put(
47             HealthPermissions.READ_HEALTH_DATA_IN_BACKGROUND,
48             AdditionalPermissionStrings(
49                 R.string.background_read_title,
50                 R.string.background_read_description,
51                 R.string.background_read_request_title,
52                 R.string.background_read_request_description))
53         .put(
54             HealthPermissions.READ_HEALTH_DATA_HISTORY,
55             AdditionalPermissionStrings(
56                 R.string.historic_access_title,
57                 R.string.historic_access_description,
58                 R.string.historic_access_request_title,
59                 R.string.historic_access_request_description,
60                 R.string.historic_access_description_fallback,
61                 R.string.historic_access_request_description_fallback))
62         .buildOrThrow()
63