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 package com.android.intentresolver.data.repository 17 18 import android.app.admin.DevicePolicyManager 19 import android.app.admin.DevicePolicyResources.Strings.Core.FORWARD_INTENT_TO_PERSONAL 20 import android.app.admin.DevicePolicyResources.Strings.Core.FORWARD_INTENT_TO_WORK 21 import android.app.admin.DevicePolicyResources.Strings.Core.RESOLVER_CANT_ACCESS_PERSONAL 22 import android.app.admin.DevicePolicyResources.Strings.Core.RESOLVER_CANT_ACCESS_WORK 23 import android.app.admin.DevicePolicyResources.Strings.Core.RESOLVER_CANT_SHARE_WITH_PERSONAL 24 import android.app.admin.DevicePolicyResources.Strings.Core.RESOLVER_CANT_SHARE_WITH_WORK 25 import android.app.admin.DevicePolicyResources.Strings.Core.RESOLVER_CROSS_PROFILE_BLOCKED_TITLE 26 import android.app.admin.DevicePolicyResources.Strings.Core.RESOLVER_NO_PERSONAL_APPS 27 import android.app.admin.DevicePolicyResources.Strings.Core.RESOLVER_NO_WORK_APPS 28 import android.app.admin.DevicePolicyResources.Strings.Core.RESOLVER_PERSONAL_TAB 29 import android.app.admin.DevicePolicyResources.Strings.Core.RESOLVER_PERSONAL_TAB_ACCESSIBILITY 30 import android.app.admin.DevicePolicyResources.Strings.Core.RESOLVER_WORK_PROFILE_NOT_SUPPORTED 31 import android.app.admin.DevicePolicyResources.Strings.Core.RESOLVER_WORK_TAB 32 import android.app.admin.DevicePolicyResources.Strings.Core.RESOLVER_WORK_TAB_ACCESSIBILITY 33 import android.content.res.Resources 34 import androidx.annotation.OpenForTesting 35 import com.android.intentresolver.R 36 import com.android.intentresolver.inject.ApplicationOwned 37 import javax.inject.Inject 38 import javax.inject.Singleton 39 40 @OpenForTesting 41 @Singleton 42 open class DevicePolicyResources 43 @Inject 44 constructor( 45 @ApplicationOwned private val resources: Resources, 46 devicePolicyManager: DevicePolicyManager, 47 ) { 48 private val policyResources = devicePolicyManager.resources 49 <lambda>null50 val personalTabLabel by lazy { 51 requireNotNull( 52 policyResources.getString(RESOLVER_PERSONAL_TAB) { 53 resources.getString(R.string.resolver_personal_tab) 54 } 55 ) 56 } 57 <lambda>null58 val workTabLabel by lazy { 59 requireNotNull( 60 policyResources.getString(RESOLVER_WORK_TAB) { 61 resources.getString(R.string.resolver_work_tab) 62 } 63 ) 64 } 65 <lambda>null66 val personalTabAccessibilityLabel by lazy { 67 requireNotNull( 68 policyResources.getString(RESOLVER_PERSONAL_TAB_ACCESSIBILITY) { 69 resources.getString(R.string.resolver_personal_tab_accessibility) 70 } 71 ) 72 } 73 <lambda>null74 val workTabAccessibilityLabel by lazy { 75 requireNotNull( 76 policyResources.getString(RESOLVER_WORK_TAB_ACCESSIBILITY) { 77 resources.getString(R.string.resolver_work_tab_accessibility) 78 } 79 ) 80 } 81 82 val forwardToPersonalMessage: String? = <lambda>null83 devicePolicyManager.resources.getString(FORWARD_INTENT_TO_PERSONAL) { 84 resources.getString(R.string.forward_intent_to_owner) 85 } 86 <lambda>null87 val forwardToWorkMessage by lazy { 88 requireNotNull( 89 policyResources.getString(FORWARD_INTENT_TO_WORK) { 90 resources.getString(R.string.forward_intent_to_work) 91 } 92 ) 93 } 94 <lambda>null95 val noPersonalApps by lazy { 96 requireNotNull( 97 policyResources.getString(RESOLVER_NO_PERSONAL_APPS) { 98 resources.getString(R.string.resolver_no_personal_apps_available) 99 } 100 ) 101 } 102 <lambda>null103 val noWorkApps by lazy { 104 requireNotNull( 105 policyResources.getString(RESOLVER_NO_WORK_APPS) { 106 resources.getString(R.string.resolver_no_work_apps_available) 107 } 108 ) 109 } 110 <lambda>null111 open val crossProfileBlocked by lazy { 112 requireNotNull( 113 policyResources.getString(RESOLVER_CROSS_PROFILE_BLOCKED_TITLE) { 114 resources.getString(R.string.resolver_cross_profile_blocked) 115 } 116 ) 117 } 118 toPersonalBlockedByPolicyMessagenull119 open fun toPersonalBlockedByPolicyMessage(share: Boolean): String { 120 return requireNotNull(if (share) { 121 policyResources.getString(RESOLVER_CANT_SHARE_WITH_PERSONAL) { 122 resources.getString(R.string.resolver_cant_share_with_personal_apps_explanation) 123 } 124 } else { 125 policyResources.getString(RESOLVER_CANT_ACCESS_PERSONAL) { 126 resources.getString(R.string.resolver_cant_access_personal_apps_explanation) 127 } 128 }) 129 } 130 toWorkBlockedByPolicyMessagenull131 open fun toWorkBlockedByPolicyMessage(share: Boolean): String { 132 return requireNotNull(if (share) { 133 policyResources.getString(RESOLVER_CANT_SHARE_WITH_WORK) { 134 resources.getString(R.string.resolver_cant_share_with_work_apps_explanation) 135 } 136 } else { 137 policyResources.getString(RESOLVER_CANT_ACCESS_WORK) { 138 resources.getString(R.string.resolver_cant_access_work_apps_explanation) 139 } 140 }) 141 } 142 toPrivateBlockedByPolicyMessagenull143 open fun toPrivateBlockedByPolicyMessage(share: Boolean): String { 144 return if (share) { 145 resources.getString(R.string.resolver_cant_share_with_private_apps_explanation) 146 } else { 147 resources.getString(R.string.resolver_cant_access_private_apps_explanation) 148 } 149 } 150 getWorkProfileNotSupportedMessagenull151 fun getWorkProfileNotSupportedMessage(launcherName: String): String { 152 return requireNotNull( 153 policyResources.getString( 154 RESOLVER_WORK_PROFILE_NOT_SUPPORTED, 155 { 156 resources.getString( 157 R.string.activity_resolver_work_profiles_support, 158 launcherName 159 ) 160 }, 161 launcherName 162 ) 163 ) 164 } 165 } 166