From d5a4d60483e1a81597c1d273f3ad795d1d1e6c33 Mon Sep 17 00:00:00 2001 From: kholoud mohamed Date: Thu, 28 Apr 2022 15:55:40 +0100 Subject: [PATCH] update enterprise strings on ACTION_DEVICE_POLICY_RESOURCE_UPDATED Also updated work folder name provider to retrieve it from dpm Bug: 218322904 Test: manual Change-Id: Id80a9e90806f3a07f132b5cc1e9871bb35df42b0 --- .../android/launcher3/LauncherAppState.java | 5 ++- src/com/android/launcher3/LauncherModel.java | 5 +++ .../launcher3/folder/FolderNameProvider.java | 21 +++++++++- .../model/ReloadStringCacheTask.java | 39 +++++++++++++++++++ .../android/launcher3/model/StringCache.java | 10 ++--- 5 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 src/com/android/launcher3/model/ReloadStringCacheTask.java diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java index 45011590e3..597bc8da3a 100644 --- a/src/com/android/launcher3/LauncherAppState.java +++ b/src/com/android/launcher3/LauncherAppState.java @@ -16,6 +16,8 @@ package com.android.launcher3; +import static android.app.admin.DevicePolicyManager.ACTION_DEVICE_POLICY_RESOURCE_UPDATED; + import static com.android.launcher3.Utilities.getDevicePrefs; import static com.android.launcher3.config.FeatureFlags.ENABLE_THEMED_ICONS; import static com.android.launcher3.util.Executors.MODEL_EXECUTOR; @@ -97,7 +99,8 @@ public class LauncherAppState implements SafeCloseable { modelChangeReceiver.register(mContext, Intent.ACTION_LOCALE_CHANGED, Intent.ACTION_MANAGED_PROFILE_AVAILABLE, Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE, - Intent.ACTION_MANAGED_PROFILE_UNLOCKED); + Intent.ACTION_MANAGED_PROFILE_UNLOCKED, + ACTION_DEVICE_POLICY_RESOURCE_UPDATED); if (FeatureFlags.IS_STUDIO_BUILD) { modelChangeReceiver.register(mContext, Context.RECEIVER_EXPORTED, ACTION_FORCE_ROLOAD); } diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index ee6f51ed05..5c5c101355 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -16,6 +16,8 @@ package com.android.launcher3; +import static android.app.admin.DevicePolicyManager.ACTION_DEVICE_POLICY_RESOURCE_UPDATED; + import static com.android.launcher3.LauncherAppState.ACTION_FORCE_ROLOAD; import static com.android.launcher3.config.FeatureFlags.IS_STUDIO_BUILD; import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; @@ -51,6 +53,7 @@ import com.android.launcher3.model.ModelWriter; import com.android.launcher3.model.PackageIncrementalDownloadUpdatedTask; import com.android.launcher3.model.PackageInstallStateChangedTask; import com.android.launcher3.model.PackageUpdatedTask; +import com.android.launcher3.model.ReloadStringCacheTask; import com.android.launcher3.model.ShortcutsChangedTask; import com.android.launcher3.model.UserLockStateChangedTask; import com.android.launcher3.model.data.AppInfo; @@ -278,6 +281,8 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi user, Intent.ACTION_MANAGED_PROFILE_UNLOCKED.equals(action))); } } + } else if (ACTION_DEVICE_POLICY_RESOURCE_UPDATED.equals(action)) { + enqueueModelUpdateTask(new ReloadStringCacheTask(mModelDelegate)); } else if (IS_STUDIO_BUILD && ACTION_FORCE_ROLOAD.equals(action)) { for (Callbacks cb : getCallbacks()) { if (cb instanceof Launcher) { diff --git a/src/com/android/launcher3/folder/FolderNameProvider.java b/src/com/android/launcher3/folder/FolderNameProvider.java index 2b621bd58b..502164473f 100644 --- a/src/com/android/launcher3/folder/FolderNameProvider.java +++ b/src/com/android/launcher3/folder/FolderNameProvider.java @@ -15,6 +15,8 @@ */ package com.android.launcher3.folder; +import android.annotation.SuppressLint; +import android.app.admin.DevicePolicyManager; import android.content.ComponentName; import android.content.Context; import android.os.Process; @@ -22,11 +24,15 @@ import android.os.UserHandle; import android.text.TextUtils; import android.util.Log; +import androidx.annotation.WorkerThread; + import com.android.launcher3.LauncherAppState; import com.android.launcher3.R; +import com.android.launcher3.Utilities; import com.android.launcher3.model.AllAppsList; import com.android.launcher3.model.BaseModelUpdateTask; import com.android.launcher3.model.BgDataModel; +import com.android.launcher3.model.StringCache; import com.android.launcher3.model.data.AppInfo; import com.android.launcher3.model.data.FolderInfo; import com.android.launcher3.model.data.WorkspaceItemInfo; @@ -94,6 +100,7 @@ public class FolderNameProvider implements ResourceBasedOverride { /** * Generate and rank the suggested Folder names. */ + @WorkerThread public void getSuggestedFolderName(Context context, ArrayList workspaceItemInfos, FolderNameInfos nameInfos) { @@ -107,8 +114,7 @@ public class FolderNameProvider implements ResourceBasedOverride { Set users = workspaceItemInfos.stream().map(w -> w.user) .collect(Collectors.toSet()); if (users.size() == 1 && !users.contains(Process.myUserHandle())) { - String workFolderName = context.getString(R.string.work_folder_name); - setAsLastSuggestion(nameInfos, workFolderName); + setAsLastSuggestion(nameInfos, getWorkFolderName(context)); } // If all the icons are from same package (e.g., main icon, shortcut, shortcut) @@ -130,6 +136,17 @@ public class FolderNameProvider implements ResourceBasedOverride { } } + @WorkerThread + @SuppressLint("NewApi") + private String getWorkFolderName(Context context) { + if (!Utilities.ATLEAST_T) { + return context.getString(R.string.work_folder_name); + } + return context.getSystemService(DevicePolicyManager.class).getResources() + .getString(StringCache.WORK_FOLDER_NAME, () -> + context.getString(R.string.work_folder_name)); + } + private Optional getAppInfoByPackageName(String packageName) { if (mAppInfos == null || mAppInfos.isEmpty()) { return Optional.empty(); diff --git a/src/com/android/launcher3/model/ReloadStringCacheTask.java b/src/com/android/launcher3/model/ReloadStringCacheTask.java new file mode 100644 index 0000000000..f4d42988bf --- /dev/null +++ b/src/com/android/launcher3/model/ReloadStringCacheTask.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2016 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; + +import com.android.launcher3.LauncherAppState; + +/** + * Handles updates due to changes in Device Policy Management resources triggered by + * {@link android.app.admin.DevicePolicyManager#ACTION_DEVICE_POLICY_RESOURCE_UPDATED}. + */ +public class ReloadStringCacheTask extends BaseModelUpdateTask { + private ModelDelegate mModelDelegate; + + public ReloadStringCacheTask(ModelDelegate modelDelegate) { + mModelDelegate = modelDelegate; + } + + @Override + public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList appsList) { + synchronized (dataModel) { + mModelDelegate.loadStringCache(dataModel.stringCache); + StringCache cloneSC = dataModel.stringCache.clone(); + scheduleCallbackTask(c -> c.bindStringCache(cloneSC)); + } + } +} diff --git a/src/com/android/launcher3/model/StringCache.java b/src/com/android/launcher3/model/StringCache.java index 663a46327f..9859ddca28 100644 --- a/src/com/android/launcher3/model/StringCache.java +++ b/src/com/android/launcher3/model/StringCache.java @@ -34,6 +34,11 @@ public class StringCache { private static final String PREFIX = "Launcher."; + /** + * Work folder name. + */ + public static final String WORK_FOLDER_NAME = PREFIX + "WORK_FOLDER_NAME"; + /** * User on-boarding title for work profile apps. */ @@ -90,11 +95,6 @@ public class StringCache { private static final String ALL_APPS_PERSONAL_TAB_ACCESSIBILITY = PREFIX + "ALL_APPS_PERSONAL_TAB_ACCESSIBILITY"; - /** - * Work folder name. - */ - private static final String WORK_FOLDER_NAME = PREFIX + "WORK_FOLDER_NAME"; - /** * Label on widget tab to indicate work app widgets. */