2021-12-20 16:47:38 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2022 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package com.android.launcher3.model;
|
|
|
|
|
|
2022-04-14 21:26:57 +00:00
|
|
|
import android.annotation.SuppressLint;
|
2022-03-14 13:58:51 +00:00
|
|
|
import android.app.admin.DevicePolicyManager;
|
2021-12-20 16:47:38 +00:00
|
|
|
import android.content.Context;
|
2022-03-21 10:19:24 +00:00
|
|
|
import android.os.Build;
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.RequiresApi;
|
2021-12-20 16:47:38 +00:00
|
|
|
|
|
|
|
|
import com.android.launcher3.R;
|
2022-03-14 13:58:51 +00:00
|
|
|
import com.android.launcher3.Utilities;
|
2021-12-20 16:47:38 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
2022-03-14 13:58:51 +00:00
|
|
|
* Cache for the device policy strings used in Launcher.
|
2021-12-20 16:47:38 +00:00
|
|
|
*/
|
|
|
|
|
public class StringCache {
|
|
|
|
|
|
2022-03-14 13:58:51 +00:00
|
|
|
private static final String PREFIX = "Launcher.";
|
|
|
|
|
|
2022-04-28 15:55:40 +01:00
|
|
|
/**
|
|
|
|
|
* Work folder name.
|
|
|
|
|
*/
|
|
|
|
|
public static final String WORK_FOLDER_NAME = PREFIX + "WORK_FOLDER_NAME";
|
|
|
|
|
|
2022-03-14 13:58:51 +00:00
|
|
|
/**
|
|
|
|
|
* User on-boarding title for work profile apps.
|
|
|
|
|
*/
|
|
|
|
|
private static final String WORK_PROFILE_EDU = PREFIX + "WORK_PROFILE_EDU";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Action label to finish work profile edu.
|
|
|
|
|
*/
|
|
|
|
|
private static final String WORK_PROFILE_EDU_ACCEPT = PREFIX + "WORK_PROFILE_EDU_ACCEPT";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Title shown when user opens work apps tab while work profile is paused.
|
|
|
|
|
*/
|
|
|
|
|
private static final String WORK_PROFILE_PAUSED_TITLE =
|
|
|
|
|
PREFIX + "WORK_PROFILE_PAUSED_TITLE";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Description shown when user opens work apps tab while work profile is paused.
|
|
|
|
|
*/
|
|
|
|
|
private static final String WORK_PROFILE_PAUSED_DESCRIPTION =
|
|
|
|
|
PREFIX + "WORK_PROFILE_PAUSED_DESCRIPTION";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Shown on the button to pause work profile.
|
|
|
|
|
*/
|
|
|
|
|
private static final String WORK_PROFILE_PAUSE_BUTTON =
|
|
|
|
|
PREFIX + "WORK_PROFILE_PAUSE_BUTTON";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Shown on the button to enable work profile.
|
|
|
|
|
*/
|
|
|
|
|
private static final String WORK_PROFILE_ENABLE_BUTTON =
|
|
|
|
|
PREFIX + "WORK_PROFILE_ENABLE_BUTTON";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Label on launcher tab to indicate work apps.
|
|
|
|
|
*/
|
|
|
|
|
private static final String ALL_APPS_WORK_TAB = PREFIX + "ALL_APPS_WORK_TAB";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Label on launcher tab to indicate personal apps.
|
|
|
|
|
*/
|
|
|
|
|
private static final String ALL_APPS_PERSONAL_TAB = PREFIX + "ALL_APPS_PERSONAL_TAB";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Accessibility description for launcher tab to indicate work apps.
|
|
|
|
|
*/
|
|
|
|
|
private static final String ALL_APPS_WORK_TAB_ACCESSIBILITY =
|
|
|
|
|
PREFIX + "ALL_APPS_WORK_TAB_ACCESSIBILITY";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Accessibility description for launcher tab to indicate personal apps.
|
|
|
|
|
*/
|
|
|
|
|
private static final String ALL_APPS_PERSONAL_TAB_ACCESSIBILITY =
|
|
|
|
|
PREFIX + "ALL_APPS_PERSONAL_TAB_ACCESSIBILITY";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Label on widget tab to indicate work app widgets.
|
|
|
|
|
*/
|
|
|
|
|
private static final String WIDGETS_WORK_TAB = PREFIX + "WIDGETS_WORK_TAB";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Label on widget tab to indicate personal app widgets.
|
|
|
|
|
*/
|
|
|
|
|
private static final String WIDGETS_PERSONAL_TAB = PREFIX + "WIDGETS_PERSONAL_TAB";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Message shown when a feature is disabled by the admin (e.g. changing wallpaper).
|
|
|
|
|
*/
|
|
|
|
|
private static final String DISABLED_BY_ADMIN_MESSAGE =
|
|
|
|
|
PREFIX + "DISABLED_BY_ADMIN_MESSAGE";
|
|
|
|
|
|
2021-12-20 16:47:38 +00:00
|
|
|
/**
|
|
|
|
|
* User on-boarding title for work profile apps.
|
|
|
|
|
*/
|
|
|
|
|
public String workProfileEdu;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Action label to finish work profile edu.
|
|
|
|
|
*/
|
|
|
|
|
public String workProfileEduAccept;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Title shown when user opens work apps tab while work profile is paused.
|
|
|
|
|
*/
|
|
|
|
|
public String workProfilePausedTitle;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Description shown when user opens work apps tab while work profile is paused.
|
|
|
|
|
*/
|
|
|
|
|
public String workProfilePausedDescription;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Shown on the button to pause work profile.
|
|
|
|
|
*/
|
|
|
|
|
public String workProfilePauseButton;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Shown on the button to enable work profile.
|
|
|
|
|
*/
|
|
|
|
|
public String workProfileEnableButton;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Label on launcher tab to indicate work apps.
|
|
|
|
|
*/
|
|
|
|
|
public String allAppsWorkTab;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Label on launcher tab to indicate personal apps.
|
|
|
|
|
*/
|
|
|
|
|
public String allAppsPersonalTab;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Accessibility description for launcher tab to indicate work apps.
|
|
|
|
|
*/
|
|
|
|
|
public String allAppsWorkTabAccessibility;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Accessibility description for launcher tab to indicate personal apps.
|
|
|
|
|
*/
|
|
|
|
|
public String allAppsPersonalTabAccessibility;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Work folder name.
|
|
|
|
|
*/
|
|
|
|
|
public String workFolderName;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Label on widget tab to indicate work app widgets.
|
|
|
|
|
*/
|
|
|
|
|
public String widgetsWorkTab;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Label on widget tab to indicate personal app widgets.
|
|
|
|
|
*/
|
|
|
|
|
public String widgetsPersonalTab;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Message shown when a feature is disabled by the admin (e.g. changing wallpaper).
|
|
|
|
|
*/
|
|
|
|
|
public String disabledByAdminMessage;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the default values for the strings.
|
|
|
|
|
*/
|
2022-03-14 13:58:51 +00:00
|
|
|
public void loadStrings(Context context) {
|
|
|
|
|
workProfileEdu = getEnterpriseString(
|
|
|
|
|
context, WORK_PROFILE_EDU, R.string.work_profile_edu_work_apps);
|
|
|
|
|
workProfileEduAccept = getEnterpriseString(
|
|
|
|
|
context, WORK_PROFILE_EDU_ACCEPT, R.string.work_profile_edu_accept);
|
|
|
|
|
workProfilePausedTitle = getEnterpriseString(
|
|
|
|
|
context, WORK_PROFILE_PAUSED_TITLE, R.string.work_apps_paused_title);
|
|
|
|
|
workProfilePausedDescription = getEnterpriseString(
|
|
|
|
|
context, WORK_PROFILE_PAUSED_DESCRIPTION, R.string.work_apps_paused_body);
|
|
|
|
|
workProfilePauseButton = getEnterpriseString(
|
|
|
|
|
context, WORK_PROFILE_PAUSE_BUTTON, R.string.work_apps_pause_btn_text);
|
|
|
|
|
workProfileEnableButton = getEnterpriseString(
|
|
|
|
|
context, WORK_PROFILE_ENABLE_BUTTON, R.string.work_apps_enable_btn_text);
|
|
|
|
|
allAppsWorkTab = getEnterpriseString(
|
|
|
|
|
context, ALL_APPS_WORK_TAB, R.string.all_apps_work_tab);
|
|
|
|
|
allAppsPersonalTab = getEnterpriseString(
|
|
|
|
|
context, ALL_APPS_PERSONAL_TAB, R.string.all_apps_personal_tab);
|
|
|
|
|
allAppsWorkTabAccessibility = getEnterpriseString(
|
|
|
|
|
context, ALL_APPS_WORK_TAB_ACCESSIBILITY, R.string.all_apps_button_work_label);
|
|
|
|
|
allAppsPersonalTabAccessibility = getEnterpriseString(
|
|
|
|
|
context, ALL_APPS_PERSONAL_TAB_ACCESSIBILITY,
|
2021-12-20 16:47:38 +00:00
|
|
|
R.string.all_apps_button_personal_label);
|
2022-03-14 13:58:51 +00:00
|
|
|
workFolderName = getEnterpriseString(
|
|
|
|
|
context, WORK_FOLDER_NAME, R.string.work_folder_name);
|
|
|
|
|
widgetsWorkTab = getEnterpriseString(
|
|
|
|
|
context, WIDGETS_WORK_TAB, R.string.widgets_full_sheet_work_tab);
|
|
|
|
|
widgetsPersonalTab = getEnterpriseString(
|
|
|
|
|
context, WIDGETS_PERSONAL_TAB, R.string.widgets_full_sheet_personal_tab);
|
|
|
|
|
disabledByAdminMessage = getEnterpriseString(
|
|
|
|
|
context, DISABLED_BY_ADMIN_MESSAGE, R.string.msg_disabled_by_admin);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-14 21:26:57 +00:00
|
|
|
@SuppressLint("NewApi")
|
2022-03-14 13:58:51 +00:00
|
|
|
private String getEnterpriseString(
|
|
|
|
|
Context context, String updatableStringId, int defaultStringId) {
|
|
|
|
|
return Utilities.ATLEAST_T
|
2022-03-21 10:19:24 +00:00
|
|
|
? getUpdatableEnterpriseSting(context, updatableStringId, defaultStringId)
|
2022-03-14 13:58:51 +00:00
|
|
|
: context.getString(defaultStringId);
|
2021-12-20 16:47:38 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-21 10:19:24 +00:00
|
|
|
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
|
|
|
|
|
private String getUpdatableEnterpriseSting(
|
|
|
|
|
Context context, String updatableStringId, int defaultStringId) {
|
|
|
|
|
DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class);
|
|
|
|
|
return dpm.getResources().getString(
|
|
|
|
|
updatableStringId, () -> context.getString(defaultStringId));
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-20 16:47:38 +00:00
|
|
|
@Override
|
|
|
|
|
public StringCache clone() {
|
|
|
|
|
StringCache clone = new StringCache();
|
|
|
|
|
clone.workProfileEdu = this.workProfileEdu;
|
|
|
|
|
clone.workProfileEduAccept = this.workProfileEduAccept;
|
|
|
|
|
clone.workProfilePausedTitle = this.workProfilePausedTitle;
|
|
|
|
|
clone.workProfilePausedDescription = this.workProfilePausedDescription;
|
|
|
|
|
clone.workProfilePauseButton = this.workProfilePauseButton;
|
|
|
|
|
clone.workProfileEnableButton = this.workProfileEnableButton;
|
|
|
|
|
clone.allAppsWorkTab = this.allAppsWorkTab;
|
|
|
|
|
clone.allAppsPersonalTab = this.allAppsPersonalTab;
|
|
|
|
|
clone.allAppsWorkTabAccessibility = this.allAppsWorkTabAccessibility;
|
|
|
|
|
clone.allAppsPersonalTabAccessibility = this.allAppsPersonalTabAccessibility;
|
|
|
|
|
clone.workFolderName = this.workFolderName;
|
|
|
|
|
clone.widgetsWorkTab = this.widgetsWorkTab;
|
|
|
|
|
clone.widgetsPersonalTab = this.widgetsPersonalTab;
|
|
|
|
|
clone.disabledByAdminMessage = this.disabledByAdminMessage;
|
|
|
|
|
return clone;
|
|
|
|
|
}
|
|
|
|
|
}
|