diff options
author | 2022-03-14 14:00:40 +0000 | |
---|---|---|
committer | 2022-03-25 14:40:14 +0000 | |
commit | 64e55a5b49805010a2826812818f26629efe7816 (patch) | |
tree | d15ee2a855a320bc9907a0e00210906464a0bdc2 | |
parent | 8037081fee5ef130560f85ded4fbf77e3dd0e372 (diff) |
RESTRICT AUTOMERGE Refactor device policy resource APIs to a separate class
Also moved constant definitions from DPM to DocsUI
Bug: 217388602
Bug: 218875965
Test: atest EnterpriseResourcesTests
Test: manual
Change-Id: I08c2087fd320b0aa3761699136377969df75f598
(cherry picked from commit eacf94a437a3bfc64f6bcc24164d2436b6d120df)
Merged-In: I08c2087fd320b0aa3761699136377969df75f598
10 files changed, 248 insertions, 52 deletions
diff --git a/src/com/android/documentsui/DevicePolicyResources.java b/src/com/android/documentsui/DevicePolicyResources.java new file mode 100644 index 000000000..651441db4 --- /dev/null +++ b/src/com/android/documentsui/DevicePolicyResources.java @@ -0,0 +1,194 @@ +/* + * 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.documentsui; + +import android.app.admin.DevicePolicyManager; + +/** + * Class containing the required identifiers to update device management resources. + * + * <p>See {@link DevicePolicyManager#getDrawable} and {@link DevicePolicyManager#getString}. + */ +public class DevicePolicyResources { + + /** + * Class containing the identifiers used to update device management-related system strings. + */ + public static final class Strings { + private static final String PREFIX = "DocumentsUi."; + + /** + * An ID for any string that can't be updated. + */ + public static final String UNDEFINED = "UNDEFINED"; + + /** + * Title for error message shown when work profile is turned off. + */ + public static final String WORK_PROFILE_OFF_ERROR_TITLE = + PREFIX + "WORK_PROFILE_OFF_ERROR_TITLE"; + + /** + * Button text shown when work profile is turned off. + */ + public static final String WORK_PROFILE_OFF_ENABLE_BUTTON = + PREFIX + "WORK_PROFILE_OFF_ENABLE_BUTTON"; + + /** + * Title for error message shown when a user's IT admin does not allow the user to + * select work files from a personal app. + */ + public static final String CANT_SELECT_WORK_FILES_TITLE = + PREFIX + "CANT_SELECT_WORK_FILES_TITLE"; + + /** + * Message shown when a user's IT admin does not allow the user to select work files + * from a personal app. + */ + public static final String CANT_SELECT_WORK_FILES_MESSAGE = + PREFIX + "CANT_SELECT_WORK_FILES_MESSAGE"; + + /** + * Title for error message shown when a user's IT admin does not allow the user to + * select personal files from a work app. + */ + public static final String CANT_SELECT_PERSONAL_FILES_TITLE = + PREFIX + "CANT_SELECT_PERSONAL_FILES_TITLE"; + + /** + * Message shown when a user's IT admin does not allow the user to select personal files + * from a work app. + */ + public static final String CANT_SELECT_PERSONAL_FILES_MESSAGE = + PREFIX + "CANT_SELECT_PERSONAL_FILES_MESSAGE"; + + /** + * Title for error message shown when a user's IT admin does not allow the user to save + * files from their personal profile to their work profile. + */ + public static final String CANT_SAVE_TO_WORK_TITLE = + PREFIX + "CANT_SAVE_TO_WORK_TITLE"; + + /** + * Message shown when a user's IT admin does not allow the user to save files from their + * personal profile to their work profile. + */ + public static final String CANT_SAVE_TO_WORK_MESSAGE = + PREFIX + "CANT_SAVE_TO_WORK_MESSAGE"; + + /** + * Title for error message shown when a user's IT admin does not allow the user to save + * files from their work profile to their personal profile. + */ + public static final String CANT_SAVE_TO_PERSONAL_TITLE = + PREFIX + "CANT_SAVE_TO_PERSONAL_TITLE"; + + /** + * Message shown when a user's IT admin does not allow the user to save files from their + * work profile to their personal profile. + */ + public static final String CANT_SAVE_TO_PERSONAL_MESSAGE = + PREFIX + "CANT_SAVE_TO_PERSONAL_MESSAGE"; + + /** + * Title for error message shown when a user tries to do something on their work + * device, but that action isn't allowed by their IT admin. + */ + public static final String CROSS_PROFILE_NOT_ALLOWED_TITLE = + PREFIX + "CROSS_PROFILE_NOT_ALLOWED_TITLE"; + + /** + * Message shown when a user tries to do something on their work device, but that action + * isn't allowed by their IT admin. + */ + public static final String CROSS_PROFILE_NOT_ALLOWED_MESSAGE = + PREFIX + "CROSS_PROFILE_NOT_ALLOWED_MESSAGE"; + + /** + * Content description text that's spoken by a screen reader for previewing a work file + * before opening it. Accepts file name as a param. + */ + public static final String PREVIEW_WORK_FILE_ACCESSIBILITY = + PREFIX + "PREVIEW_WORK_FILE_ACCESSIBILITY"; + + /** + * Label for tab and sidebar to indicate personal content. + */ + public static final String PERSONAL_TAB = PREFIX + "PERSONAL_TAB"; + + /** + * Label for tab and sidebar tab to indicate work content + */ + public static final String WORK_TAB = PREFIX + "WORK_TAB"; + + } + + /** + * Class containing the identifiers used to update device management-related system drawable. + */ + public static final class Drawables { + /** + * Specifically used to badge work profile app icons. + */ + public static final String WORK_PROFILE_ICON_BADGE = "WORK_PROFILE_ICON_BADGE"; + + /** + * General purpose work profile icon (i.e. generic icon badging). For badging app icons + * specifically, see {@link #WORK_PROFILE_ICON_BADGE}. + */ + public static final String WORK_PROFILE_ICON = "WORK_PROFILE_ICON"; + + /** + * General purpose icon representing the work profile off state. + */ + public static final String WORK_PROFILE_OFF_ICON = "WORK_PROFILE_OFF_ICON"; + + /** + * General purpose icon for the work profile user avatar. + */ + public static final String WORK_PROFILE_USER_ICON = "WORK_PROFILE_USER_ICON"; + + /** + * Class containing the style identifiers used to update device management-related system + * drawable. + */ + public static final class Style { + + /** + * A style identifier indicating that the updatable drawable should use the default + * style. + */ + public static final String DEFAULT = "DEFAULT"; + + /** + * A style identifier indicating that the updatable drawable has a solid color fill. + */ + public static final String SOLID_COLORED = "SOLID_COLORED"; + + /** + * A style identifier indicating that the updatable drawable has a solid non-colored + * fill. + */ + public static final String SOLID_NOT_COLORED = "SOLID_NOT_COLORED"; + + /** + * A style identifier indicating that the updatable drawable is an outline. + */ + public static final String OUTLINE = "OUTLINE"; + } + } +} diff --git a/src/com/android/documentsui/ProfileTabs.java b/src/com/android/documentsui/ProfileTabs.java index e2cec1a6b..a3dac4c0a 100644 --- a/src/com/android/documentsui/ProfileTabs.java +++ b/src/com/android/documentsui/ProfileTabs.java @@ -16,11 +16,11 @@ package com.android.documentsui; -import static android.app.admin.DevicePolicyResources.Strings.DocumentsUi.PERSONAL_TAB; -import static android.app.admin.DevicePolicyResources.Strings.DocumentsUi.WORK_TAB; - import static androidx.core.util.Preconditions.checkNotNull; +import static com.android.documentsui.DevicePolicyResources.Strings.PERSONAL_TAB; +import static com.android.documentsui.DevicePolicyResources.Strings.WORK_TAB; + import android.app.admin.DevicePolicyManager; import android.os.Build; import android.view.View; @@ -176,7 +176,7 @@ public class ProfileTabs implements ProfileTabsAddons { private String getUpdatableEnterpriseString(String updatableStringId, int defaultStringId) { DevicePolicyManager dpm = mTabsContainer.getContext().getSystemService( DevicePolicyManager.class); - return dpm.getString( + return dpm.getResources().getString( updatableStringId, () -> mTabsContainer.getContext().getString(defaultStringId)); } diff --git a/src/com/android/documentsui/dirlist/DocumentHolder.java b/src/com/android/documentsui/dirlist/DocumentHolder.java index 678dee295..afa75602a 100644 --- a/src/com/android/documentsui/dirlist/DocumentHolder.java +++ b/src/com/android/documentsui/dirlist/DocumentHolder.java @@ -16,8 +16,8 @@ package com.android.documentsui.dirlist; -import static android.app.admin.DevicePolicyResources.Strings.DocumentsUi.PREVIEW_WORK_FILE_ACCESSIBILITY; -import static android.app.admin.DevicePolicyResources.Strings.UNDEFINED; +import static com.android.documentsui.DevicePolicyResources.Strings.PREVIEW_WORK_FILE_ACCESSIBILITY; +import static com.android.documentsui.DevicePolicyResources.Strings.UNDEFINED; import android.app.admin.DevicePolicyManager; import android.content.Context; @@ -196,7 +196,7 @@ public abstract class DocumentHolder String updatableStringId = isWorkProfile ? PREVIEW_WORK_FILE_ACCESSIBILITY : UNDEFINED; int defaultStringId = isWorkProfile ? R.string.preview_work_file : R.string.preview_file; - return dpm.getString( + return dpm.getResources().getString( updatableStringId, () -> itemView.getResources().getString(defaultStringId, fileName), /* formatArgs= */ fileName); diff --git a/src/com/android/documentsui/dirlist/GridDirectoryHolder.java b/src/com/android/documentsui/dirlist/GridDirectoryHolder.java index 8998b20c3..9bc2ce952 100644 --- a/src/com/android/documentsui/dirlist/GridDirectoryHolder.java +++ b/src/com/android/documentsui/dirlist/GridDirectoryHolder.java @@ -16,9 +16,8 @@ package com.android.documentsui.dirlist; -import static android.app.admin.DevicePolicyResources.Drawables.Style.SOLID_COLORED; -import static android.app.admin.DevicePolicyResources.Drawables.WORK_PROFILE_ICON; - +import static com.android.documentsui.DevicePolicyResources.Drawables.Style.SOLID_COLORED; +import static com.android.documentsui.DevicePolicyResources.Drawables.WORK_PROFILE_ICON; import static com.android.documentsui.base.DocumentInfo.getCursorString; import android.app.admin.DevicePolicyManager; @@ -70,7 +69,7 @@ final class GridDirectoryHolder extends DocumentHolder { @RequiresApi(Build.VERSION_CODES.TIRAMISU) private void setUpdatableWorkProfileIcon(Context context) { DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class); - Drawable drawable = dpm.getDrawable(WORK_PROFILE_ICON, SOLID_COLORED, () -> + Drawable drawable = dpm.getResources().getDrawable(WORK_PROFILE_ICON, SOLID_COLORED, () -> context.getDrawable(R.drawable.ic_briefcase)); mIconBriefcase.setImageDrawable(drawable); } diff --git a/src/com/android/documentsui/dirlist/GridDocumentHolder.java b/src/com/android/documentsui/dirlist/GridDocumentHolder.java index 16983ed09..535ae954b 100644 --- a/src/com/android/documentsui/dirlist/GridDocumentHolder.java +++ b/src/com/android/documentsui/dirlist/GridDocumentHolder.java @@ -16,9 +16,8 @@ package com.android.documentsui.dirlist; -import static android.app.admin.DevicePolicyResources.Drawables.Style.SOLID_COLORED; -import static android.app.admin.DevicePolicyResources.Drawables.WORK_PROFILE_ICON; - +import static com.android.documentsui.DevicePolicyResources.Drawables.Style.SOLID_COLORED; +import static com.android.documentsui.DevicePolicyResources.Drawables.WORK_PROFILE_ICON; import static com.android.documentsui.base.DocumentInfo.getCursorInt; import static com.android.documentsui.base.DocumentInfo.getCursorLong; import static com.android.documentsui.base.DocumentInfo.getCursorString; @@ -89,7 +88,7 @@ final class GridDocumentHolder extends DocumentHolder { @RequiresApi(Build.VERSION_CODES.TIRAMISU) private void setUpdatableWorkProfileIcon(Context context) { DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class); - Drawable drawable = dpm.getDrawable(WORK_PROFILE_ICON, SOLID_COLORED, () -> + Drawable drawable = dpm.getResources().getDrawable(WORK_PROFILE_ICON, SOLID_COLORED, () -> context.getDrawable(R.drawable.ic_briefcase)); mIconBriefcase.setImageDrawable(drawable); } diff --git a/src/com/android/documentsui/dirlist/GridPhotoHolder.java b/src/com/android/documentsui/dirlist/GridPhotoHolder.java index a9b790bcc..dac6a318a 100644 --- a/src/com/android/documentsui/dirlist/GridPhotoHolder.java +++ b/src/com/android/documentsui/dirlist/GridPhotoHolder.java @@ -16,9 +16,8 @@ package com.android.documentsui.dirlist; -import static android.app.admin.DevicePolicyResources.Drawables.Style.SOLID_NOT_COLORED; -import static android.app.admin.DevicePolicyResources.Drawables.WORK_PROFILE_ICON; - +import static com.android.documentsui.DevicePolicyResources.Drawables.Style.SOLID_NOT_COLORED; +import static com.android.documentsui.DevicePolicyResources.Drawables.WORK_PROFILE_ICON; import static com.android.documentsui.base.DocumentInfo.getCursorInt; import static com.android.documentsui.base.DocumentInfo.getCursorLong; import static com.android.documentsui.base.DocumentInfo.getCursorString; @@ -78,8 +77,9 @@ final class GridPhotoHolder extends DocumentHolder { @RequiresApi(Build.VERSION_CODES.TIRAMISU) private void setUpdatableWorkProfileIcon(Context context) { DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class); - Drawable drawable = dpm.getDrawable(WORK_PROFILE_ICON, SOLID_NOT_COLORED, () -> - context.getDrawable(R.drawable.ic_briefcase)); + Drawable drawable = dpm.getResources().getDrawable( + WORK_PROFILE_ICON, SOLID_NOT_COLORED, () -> + context.getDrawable(R.drawable.ic_briefcase)); ImageView icon = (ImageView) mIconBriefcase.findViewById(R.id.icon_id); icon.setImageDrawable(drawable); diff --git a/src/com/android/documentsui/dirlist/ListDocumentHolder.java b/src/com/android/documentsui/dirlist/ListDocumentHolder.java index 7fe48eecb..ad8eac72e 100644 --- a/src/com/android/documentsui/dirlist/ListDocumentHolder.java +++ b/src/com/android/documentsui/dirlist/ListDocumentHolder.java @@ -16,9 +16,8 @@ package com.android.documentsui.dirlist; -import static android.app.admin.DevicePolicyResources.Drawables.Style.SOLID_COLORED; -import static android.app.admin.DevicePolicyResources.Drawables.WORK_PROFILE_ICON; - +import static com.android.documentsui.DevicePolicyResources.Drawables.Style.SOLID_COLORED; +import static com.android.documentsui.DevicePolicyResources.Drawables.WORK_PROFILE_ICON; import static com.android.documentsui.base.DocumentInfo.getCursorInt; import static com.android.documentsui.base.DocumentInfo.getCursorString; @@ -107,7 +106,7 @@ final class ListDocumentHolder extends DocumentHolder { @RequiresApi(Build.VERSION_CODES.TIRAMISU) private void setUpdatableWorkProfileIcon(Context context) { DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class); - Drawable drawable = dpm.getDrawable(WORK_PROFILE_ICON, SOLID_COLORED, () -> + Drawable drawable = dpm.getResources().getDrawable(WORK_PROFILE_ICON, SOLID_COLORED, () -> context.getDrawable(R.drawable.ic_briefcase)); mIconBriefcase.setImageDrawable(drawable); } diff --git a/src/com/android/documentsui/dirlist/Message.java b/src/com/android/documentsui/dirlist/Message.java index 5546ad94d..6ba5ea388 100644 --- a/src/com/android/documentsui/dirlist/Message.java +++ b/src/com/android/documentsui/dirlist/Message.java @@ -16,20 +16,20 @@ package com.android.documentsui.dirlist; -import static android.app.admin.DevicePolicyResources.Drawables.Style.OUTLINE; -import static android.app.admin.DevicePolicyResources.Drawables.WORK_PROFILE_OFF_ICON; -import static android.app.admin.DevicePolicyResources.Strings.DocumentsUi.CANT_SAVE_TO_PERSONAL_MESSAGE; -import static android.app.admin.DevicePolicyResources.Strings.DocumentsUi.CANT_SAVE_TO_PERSONAL_TITLE; -import static android.app.admin.DevicePolicyResources.Strings.DocumentsUi.CANT_SAVE_TO_WORK_MESSAGE; -import static android.app.admin.DevicePolicyResources.Strings.DocumentsUi.CANT_SAVE_TO_WORK_TITLE; -import static android.app.admin.DevicePolicyResources.Strings.DocumentsUi.CANT_SELECT_PERSONAL_FILES_MESSAGE; -import static android.app.admin.DevicePolicyResources.Strings.DocumentsUi.CANT_SELECT_PERSONAL_FILES_TITLE; -import static android.app.admin.DevicePolicyResources.Strings.DocumentsUi.CANT_SELECT_WORK_FILES_MESSAGE; -import static android.app.admin.DevicePolicyResources.Strings.DocumentsUi.CANT_SELECT_WORK_FILES_TITLE; -import static android.app.admin.DevicePolicyResources.Strings.DocumentsUi.CROSS_PROFILE_NOT_ALLOWED_MESSAGE; -import static android.app.admin.DevicePolicyResources.Strings.DocumentsUi.CROSS_PROFILE_NOT_ALLOWED_TITLE; -import static android.app.admin.DevicePolicyResources.Strings.DocumentsUi.WORK_PROFILE_OFF_ENABLE_BUTTON; -import static android.app.admin.DevicePolicyResources.Strings.DocumentsUi.WORK_PROFILE_OFF_ERROR_TITLE; +import static com.android.documentsui.DevicePolicyResources.Drawables.Style.OUTLINE; +import static com.android.documentsui.DevicePolicyResources.Drawables.WORK_PROFILE_OFF_ICON; +import static com.android.documentsui.DevicePolicyResources.Strings.CANT_SAVE_TO_PERSONAL_MESSAGE; +import static com.android.documentsui.DevicePolicyResources.Strings.CANT_SAVE_TO_PERSONAL_TITLE; +import static com.android.documentsui.DevicePolicyResources.Strings.CANT_SAVE_TO_WORK_MESSAGE; +import static com.android.documentsui.DevicePolicyResources.Strings.CANT_SAVE_TO_WORK_TITLE; +import static com.android.documentsui.DevicePolicyResources.Strings.CANT_SELECT_PERSONAL_FILES_MESSAGE; +import static com.android.documentsui.DevicePolicyResources.Strings.CANT_SELECT_PERSONAL_FILES_TITLE; +import static com.android.documentsui.DevicePolicyResources.Strings.CANT_SELECT_WORK_FILES_MESSAGE; +import static com.android.documentsui.DevicePolicyResources.Strings.CANT_SELECT_WORK_FILES_TITLE; +import static com.android.documentsui.DevicePolicyResources.Strings.CROSS_PROFILE_NOT_ALLOWED_MESSAGE; +import static com.android.documentsui.DevicePolicyResources.Strings.CROSS_PROFILE_NOT_ALLOWED_TITLE; +import static com.android.documentsui.DevicePolicyResources.Strings.WORK_PROFILE_OFF_ENABLE_BUTTON; +import static com.android.documentsui.DevicePolicyResources.Strings.WORK_PROFILE_OFF_ERROR_TITLE; import android.Manifest; import android.app.AuthenticationRequiredException; @@ -344,7 +344,7 @@ abstract class Message { private String getUpdatableEnterpriseString(String updatableStringId, int defaultStringId) { DevicePolicyManager dpm = mEnv.getContext().getSystemService( DevicePolicyManager.class); - return dpm.getString( + return dpm.getResources().getString( updatableStringId, () -> mEnv.getContext().getString(defaultStringId)); } @@ -360,7 +360,7 @@ abstract class Message { private Drawable getUpdatableWorkProfileIcon() { DevicePolicyManager dpm = mEnv.getContext().getSystemService( DevicePolicyManager.class); - return dpm.getDrawable( + return dpm.getResources().getDrawable( WORK_PROFILE_OFF_ICON, OUTLINE, () -> mEnv.getContext().getDrawable(R.drawable.work_off)); } diff --git a/src/com/android/documentsui/sidebar/UserItemsCombiner.java b/src/com/android/documentsui/sidebar/UserItemsCombiner.java index a797eae81..d8c0dc767 100644 --- a/src/com/android/documentsui/sidebar/UserItemsCombiner.java +++ b/src/com/android/documentsui/sidebar/UserItemsCombiner.java @@ -16,12 +16,12 @@ package com.android.documentsui.sidebar; -import static android.app.admin.DevicePolicyResources.Strings.DocumentsUi.PERSONAL_TAB; -import static android.app.admin.DevicePolicyResources.Strings.DocumentsUi.WORK_TAB; - import static androidx.core.util.Preconditions.checkArgument; import static androidx.core.util.Preconditions.checkNotNull; +import static com.android.documentsui.DevicePolicyResources.Strings.PERSONAL_TAB; +import static com.android.documentsui.DevicePolicyResources.Strings.WORK_TAB; + import android.app.admin.DevicePolicyManager; import android.content.res.Resources; import android.os.Build; @@ -119,6 +119,7 @@ class UserItemsCombiner { @RequiresApi(Build.VERSION_CODES.TIRAMISU) private String getUpdatableEnterpriseString(String updatableStringId, int defaultStringId) { - return mDpm.getString(updatableStringId, () -> mResources.getString(defaultStringId)); + return mDpm.getResources().getString( + updatableStringId, () -> mResources.getString(defaultStringId)); } } diff --git a/tests/unit/com/android/documentsui/dirlist/MessageTest.java b/tests/unit/com/android/documentsui/dirlist/MessageTest.java index e755d853b..c8bd01e55 100644 --- a/tests/unit/com/android/documentsui/dirlist/MessageTest.java +++ b/tests/unit/com/android/documentsui/dirlist/MessageTest.java @@ -16,10 +16,10 @@ package com.android.documentsui.dirlist; -import static android.app.admin.DevicePolicyResources.Strings.DocumentsUi.CANT_SELECT_WORK_FILES_MESSAGE; -import static android.app.admin.DevicePolicyResources.Strings.DocumentsUi.CANT_SELECT_WORK_FILES_TITLE; -import static android.app.admin.DevicePolicyResources.Strings.DocumentsUi.WORK_PROFILE_OFF_ENABLE_BUTTON; -import static android.app.admin.DevicePolicyResources.Strings.DocumentsUi.WORK_PROFILE_OFF_ERROR_TITLE; +import static com.android.documentsui.DevicePolicyResources.Strings.CANT_SELECT_WORK_FILES_MESSAGE; +import static com.android.documentsui.DevicePolicyResources.Strings.CANT_SELECT_WORK_FILES_TITLE; +import static com.android.documentsui.DevicePolicyResources.Strings.WORK_PROFILE_OFF_ENABLE_BUTTON; +import static com.android.documentsui.DevicePolicyResources.Strings.WORK_PROFILE_OFF_ERROR_TITLE; import static com.google.common.truth.Truth.assertThat; @@ -29,6 +29,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import android.app.admin.DevicePolicyManager; +import android.app.admin.DevicePolicyResourcesManager; import android.content.Context; import android.os.UserManager; @@ -59,6 +60,7 @@ public final class MessageTest { }; private UserManager mUserManager; private DevicePolicyManager mDevicePolicyManager; + private DevicePolicyResourcesManager mDevicePolicyResourcesManager; private TestActionHandler mTestActionHandler; @Before @@ -67,11 +69,13 @@ public final class MessageTest { mUserManager = UserManagers.create(); mTestActionHandler = new TestActionHandler(); mDevicePolicyManager = mock(DevicePolicyManager.class); + mDevicePolicyResourcesManager = mock(DevicePolicyResourcesManager.class); when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager); when(mContext.getSystemServiceName(DevicePolicyManager.class)) .thenReturn(Context.DEVICE_POLICY_SERVICE); when(mContext.getSystemService(Context.DEVICE_POLICY_SERVICE)) .thenReturn(mDevicePolicyManager); + when(mDevicePolicyManager.getResources()).thenReturn(mDevicePolicyResourcesManager); when(mContext.getResources()).thenReturn( InstrumentationRegistry.getInstrumentation().getTargetContext().getResources()); DocumentsAdapter.Environment env = @@ -89,9 +93,9 @@ public final class MessageTest { /* isRemoteActionsEnabled= */ true); String title = mContext.getString(R.string.cant_select_work_files_error_title); String message = mContext.getString(R.string.cant_select_work_files_error_message); - when(mDevicePolicyManager.getString(eq(CANT_SELECT_WORK_FILES_TITLE), any())) + when(mDevicePolicyResourcesManager.getString(eq(CANT_SELECT_WORK_FILES_TITLE), any())) .thenReturn(title); - when(mDevicePolicyManager.getString(eq(CANT_SELECT_WORK_FILES_MESSAGE), any())) + when(mDevicePolicyResourcesManager.getString(eq(CANT_SELECT_WORK_FILES_MESSAGE), any())) .thenReturn(message); mInflateMessage.update(error); @@ -113,9 +117,9 @@ public final class MessageTest { /* isRemoteActionsEnabled= */ true); String title = mContext.getString(R.string.quiet_mode_error_title); String text = mContext.getString(R.string.quiet_mode_button); - when(mDevicePolicyManager.getString(eq(WORK_PROFILE_OFF_ERROR_TITLE), any())) + when(mDevicePolicyResourcesManager.getString(eq(WORK_PROFILE_OFF_ERROR_TITLE), any())) .thenReturn(title); - when(mDevicePolicyManager.getString(eq(WORK_PROFILE_OFF_ENABLE_BUTTON), any())) + when(mDevicePolicyResourcesManager.getString(eq(WORK_PROFILE_OFF_ENABLE_BUTTON), any())) .thenReturn(text); mInflateMessage.update(error); |