1 /* 2 * Copyright (C) 2022 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 com.android.launcher3.model; 18 19 import android.annotation.SuppressLint; 20 import android.app.admin.DevicePolicyManager; 21 import android.content.Context; 22 import android.os.Build; 23 24 import androidx.annotation.RequiresApi; 25 26 import com.android.launcher3.R; 27 import com.android.launcher3.Utilities; 28 29 /** 30 * 31 * Cache for the device policy strings used in Launcher. 32 */ 33 public class StringCache { 34 35 private static final String PREFIX = "Launcher."; 36 37 /** 38 * Work folder name. 39 */ 40 public static final String WORK_FOLDER_NAME = PREFIX + "WORK_FOLDER_NAME"; 41 42 /** 43 * User on-boarding title for work profile apps. 44 */ 45 private static final String WORK_PROFILE_EDU = PREFIX + "WORK_PROFILE_EDU"; 46 47 /** 48 * Action label to finish work profile edu. 49 */ 50 private static final String WORK_PROFILE_EDU_ACCEPT = PREFIX + "WORK_PROFILE_EDU_ACCEPT"; 51 52 /** 53 * Title shown when user opens work apps tab while work profile is paused. 54 */ 55 private static final String WORK_PROFILE_PAUSED_TITLE = 56 PREFIX + "WORK_PROFILE_PAUSED_TITLE"; 57 58 /** 59 * Description shown when user opens work apps tab while work profile is paused. 60 */ 61 private static final String WORK_PROFILE_PAUSED_DESCRIPTION = 62 PREFIX + "WORK_PROFILE_PAUSED_DESCRIPTION"; 63 64 /** 65 * Shown on the button to pause work profile. 66 */ 67 private static final String WORK_PROFILE_PAUSE_BUTTON = 68 PREFIX + "WORK_PROFILE_PAUSE_BUTTON"; 69 70 /** 71 * Shown on the button to enable work profile. 72 */ 73 private static final String WORK_PROFILE_ENABLE_BUTTON = 74 PREFIX + "WORK_PROFILE_ENABLE_BUTTON"; 75 76 /** 77 * Label on launcher tab to indicate work apps. 78 */ 79 private static final String ALL_APPS_WORK_TAB = PREFIX + "ALL_APPS_WORK_TAB"; 80 81 /** 82 * Label on launcher tab to indicate personal apps. 83 */ 84 private static final String ALL_APPS_PERSONAL_TAB = PREFIX + "ALL_APPS_PERSONAL_TAB"; 85 86 /** 87 * Accessibility description for launcher tab to indicate work apps. 88 */ 89 private static final String ALL_APPS_WORK_TAB_ACCESSIBILITY = 90 PREFIX + "ALL_APPS_WORK_TAB_ACCESSIBILITY"; 91 92 /** 93 * Accessibility description for launcher tab to indicate personal apps. 94 */ 95 private static final String ALL_APPS_PERSONAL_TAB_ACCESSIBILITY = 96 PREFIX + "ALL_APPS_PERSONAL_TAB_ACCESSIBILITY"; 97 98 /** 99 * Label on widget tab to indicate work app widgets. 100 */ 101 private static final String WIDGETS_WORK_TAB = PREFIX + "WIDGETS_WORK_TAB"; 102 103 /** 104 * Label on widget tab to indicate personal app widgets. 105 */ 106 private static final String WIDGETS_PERSONAL_TAB = PREFIX + "WIDGETS_PERSONAL_TAB"; 107 108 /** 109 * Message shown when a feature is disabled by the admin (e.g. changing wallpaper). 110 */ 111 private static final String DISABLED_BY_ADMIN_MESSAGE = 112 PREFIX + "DISABLED_BY_ADMIN_MESSAGE"; 113 114 /** 115 * User on-boarding title for work profile apps. 116 */ 117 public String workProfileEdu; 118 119 /** 120 * Action label to finish work profile edu. 121 */ 122 public String workProfileEduAccept; 123 124 /** 125 * Title shown when user opens work apps tab while work profile is paused. 126 */ 127 public String workProfilePausedTitle; 128 129 /** 130 * Description shown when user opens work apps tab while work profile is paused. 131 */ 132 public String workProfilePausedDescription; 133 134 /** 135 * Shown on the button to pause work profile. 136 */ 137 public String workProfilePauseButton; 138 139 /** 140 * Shown on the button to enable work profile. 141 */ 142 public String workProfileEnableButton; 143 144 /** 145 * Label on launcher tab to indicate work apps. 146 */ 147 public String allAppsWorkTab; 148 149 /** 150 * Label on launcher tab to indicate personal apps. 151 */ 152 public String allAppsPersonalTab; 153 154 /** 155 * Accessibility description for launcher tab to indicate work apps. 156 */ 157 public String allAppsWorkTabAccessibility; 158 159 /** 160 * Accessibility description for launcher tab to indicate personal apps. 161 */ 162 public String allAppsPersonalTabAccessibility; 163 164 /** 165 * Work folder name. 166 */ 167 public String workFolderName; 168 169 /** 170 * Label on widget tab to indicate work app widgets. 171 */ 172 public String widgetsWorkTab; 173 174 /** 175 * Label on widget tab to indicate personal app widgets. 176 */ 177 public String widgetsPersonalTab; 178 179 /** 180 * Message shown when a feature is disabled by the admin (e.g. changing wallpaper). 181 */ 182 public String disabledByAdminMessage; 183 184 /** 185 * Sets the default values for the strings. 186 */ loadStrings(Context context)187 public void loadStrings(Context context) { 188 workProfileEdu = getEnterpriseString( 189 context, WORK_PROFILE_EDU, R.string.work_profile_edu_work_apps); 190 workProfileEduAccept = getEnterpriseString( 191 context, WORK_PROFILE_EDU_ACCEPT, R.string.work_profile_edu_accept); 192 workProfilePausedTitle = getEnterpriseString( 193 context, WORK_PROFILE_PAUSED_TITLE, R.string.work_apps_paused_title); 194 workProfilePausedDescription = getEnterpriseString( 195 context, WORK_PROFILE_PAUSED_DESCRIPTION, R.string.work_apps_paused_body); 196 workProfilePauseButton = getEnterpriseString( 197 context, WORK_PROFILE_PAUSE_BUTTON, R.string.work_apps_pause_btn_text); 198 workProfileEnableButton = getEnterpriseString( 199 context, WORK_PROFILE_ENABLE_BUTTON, R.string.work_apps_enable_btn_text); 200 allAppsWorkTab = getEnterpriseString( 201 context, ALL_APPS_WORK_TAB, R.string.all_apps_work_tab); 202 allAppsPersonalTab = getEnterpriseString( 203 context, ALL_APPS_PERSONAL_TAB, R.string.all_apps_personal_tab); 204 allAppsWorkTabAccessibility = getEnterpriseString( 205 context, ALL_APPS_WORK_TAB_ACCESSIBILITY, R.string.all_apps_button_work_label); 206 allAppsPersonalTabAccessibility = getEnterpriseString( 207 context, ALL_APPS_PERSONAL_TAB_ACCESSIBILITY, 208 R.string.all_apps_button_personal_label); 209 workFolderName = getEnterpriseString( 210 context, WORK_FOLDER_NAME, R.string.work_folder_name); 211 widgetsWorkTab = getEnterpriseString( 212 context, WIDGETS_WORK_TAB, R.string.widgets_full_sheet_work_tab); 213 widgetsPersonalTab = getEnterpriseString( 214 context, WIDGETS_PERSONAL_TAB, R.string.widgets_full_sheet_personal_tab); 215 disabledByAdminMessage = getEnterpriseString( 216 context, DISABLED_BY_ADMIN_MESSAGE, R.string.msg_disabled_by_admin); 217 } 218 219 @SuppressLint("NewApi") getEnterpriseString( Context context, String updatableStringId, int defaultStringId)220 private String getEnterpriseString( 221 Context context, String updatableStringId, int defaultStringId) { 222 return Utilities.ATLEAST_T 223 ? getUpdatableEnterpriseSting(context, updatableStringId, defaultStringId) 224 : context.getString(defaultStringId); 225 } 226 227 @RequiresApi(Build.VERSION_CODES.TIRAMISU) getUpdatableEnterpriseSting( Context context, String updatableStringId, int defaultStringId)228 private String getUpdatableEnterpriseSting( 229 Context context, String updatableStringId, int defaultStringId) { 230 DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class); 231 return dpm.getResources().getString( 232 updatableStringId, () -> context.getString(defaultStringId)); 233 } 234 235 @Override clone()236 public StringCache clone() { 237 StringCache clone = new StringCache(); 238 clone.workProfileEdu = this.workProfileEdu; 239 clone.workProfileEduAccept = this.workProfileEduAccept; 240 clone.workProfilePausedTitle = this.workProfilePausedTitle; 241 clone.workProfilePausedDescription = this.workProfilePausedDescription; 242 clone.workProfilePauseButton = this.workProfilePauseButton; 243 clone.workProfileEnableButton = this.workProfileEnableButton; 244 clone.allAppsWorkTab = this.allAppsWorkTab; 245 clone.allAppsPersonalTab = this.allAppsPersonalTab; 246 clone.allAppsWorkTabAccessibility = this.allAppsWorkTabAccessibility; 247 clone.allAppsPersonalTabAccessibility = this.allAppsPersonalTabAccessibility; 248 clone.workFolderName = this.workFolderName; 249 clone.widgetsWorkTab = this.widgetsWorkTab; 250 clone.widgetsPersonalTab = this.widgetsPersonalTab; 251 clone.disabledByAdminMessage = this.disabledByAdminMessage; 252 return clone; 253 } 254 } 255