From feb20850c87c4cc0c72182b43b4378ec846fe122 Mon Sep 17 00:00:00 2001 From: Oli Thompson Date: Thu, 30 Mar 2023 11:03:23 +0000 Subject: [PATCH] Change strings in MiniResolver to use dynamo Test: manually tested Bug: 268470040 Change-Id: I30aaee51358f1acb32a73fb31e30c7b553f68687 --- .../app/admin/DevicePolicyResources.java | 11 ++++++ .../internal/app/IntentForwarderActivity.java | 12 +++++-- .../internal/app/ResolverActivity.java | 36 ++++++++++++++----- 3 files changed, 48 insertions(+), 11 deletions(-) diff --git a/core/java/android/app/admin/DevicePolicyResources.java b/core/java/android/app/admin/DevicePolicyResources.java index a49891356ccd2..593f73635617f 100644 --- a/core/java/android/app/admin/DevicePolicyResources.java +++ b/core/java/android/app/admin/DevicePolicyResources.java @@ -1857,6 +1857,17 @@ public final class DevicePolicyResources { public static final String WORK_PROFILE_TELEPHONY_PAUSED_TURN_ON_BUTTON = PREFIX + "TURN_ON_WORK_PROFILE_BUTTON_TEXT"; + public static final String MINIRESOLVER_OPEN_IN_WORK = + PREFIX + "MINIRESOLVER_OPEN_IN_WORK"; + + public static final String MINIRESOLVER_OPEN_IN_PERSONAL = + PREFIX + "MINIRESOLVER_OPEN_IN_PERSONAL"; + + public static final String MINIRESOLVER_USE_WORK_BROWSER = + PREFIX + "MINIRESOLVER_OPEN_IN_PERSONAL"; + + public static final String MINIRESOLVER_USE_PERSONAL_BROWSER = + PREFIX + "MINIRESOLVER_OPEN_IN_PERSONAL"; } /** diff --git a/core/java/com/android/internal/app/IntentForwarderActivity.java b/core/java/com/android/internal/app/IntentForwarderActivity.java index ae192a4effc74..4196474e7016c 100644 --- a/core/java/com/android/internal/app/IntentForwarderActivity.java +++ b/core/java/com/android/internal/app/IntentForwarderActivity.java @@ -18,6 +18,7 @@ package com.android.internal.app; import static android.app.admin.DevicePolicyResources.Strings.Core.FORWARD_INTENT_TO_PERSONAL; import static android.app.admin.DevicePolicyResources.Strings.Core.FORWARD_INTENT_TO_WORK; +import static android.app.admin.DevicePolicyResources.Strings.Core.MINIRESOLVER_OPEN_IN_WORK; import static android.content.pm.PackageManager.MATCH_DEFAULT_ONLY; import static com.android.internal.app.ResolverActivity.EXTRA_CALLING_USER; @@ -196,9 +197,7 @@ public class IntentForwarderActivity extends Activity { buttonContainer.setPadding(0, 0, 0, buttonContainer.getPaddingBottom()); ((TextView) findViewById(R.id.open_cross_profile)).setText( - getResources().getString( - R.string.miniresolver_open_in_work, - target.loadLabel(packageManagerForTargetUser))); + getOpenInWorkMessage(target.loadLabel(packageManagerForTargetUser))); // The mini-resolver's negative button is reused in this flow to cancel the intent ((Button) findViewById(R.id.use_same_profile_browser)).setText(R.string.cancel); @@ -210,6 +209,13 @@ public class IntentForwarderActivity extends Activity { }); } + private String getOpenInWorkMessage(CharSequence targetLabel) { + return getSystemService(DevicePolicyManager.class).getResources().getString( + MINIRESOLVER_OPEN_IN_WORK, + () -> getString(R.string.miniresolver_open_in_work, targetLabel), + targetLabel); + } + private String getForwardToPersonalMessage() { return getSystemService(DevicePolicyManager.class).getResources().getString( FORWARD_INTENT_TO_PERSONAL, diff --git a/core/java/com/android/internal/app/ResolverActivity.java b/core/java/com/android/internal/app/ResolverActivity.java index 73c5207e62389..499d38c31b591 100644 --- a/core/java/com/android/internal/app/ResolverActivity.java +++ b/core/java/com/android/internal/app/ResolverActivity.java @@ -19,6 +19,10 @@ package com.android.internal.app; import static android.Manifest.permission.INTERACT_ACROSS_PROFILES; import static android.app.admin.DevicePolicyResources.Strings.Core.FORWARD_INTENT_TO_PERSONAL; import static android.app.admin.DevicePolicyResources.Strings.Core.FORWARD_INTENT_TO_WORK; +import static android.app.admin.DevicePolicyResources.Strings.Core.MINIRESOLVER_OPEN_IN_PERSONAL; +import static android.app.admin.DevicePolicyResources.Strings.Core.MINIRESOLVER_OPEN_IN_WORK; +import static android.app.admin.DevicePolicyResources.Strings.Core.MINIRESOLVER_USE_PERSONAL_BROWSER; +import static android.app.admin.DevicePolicyResources.Strings.Core.MINIRESOLVER_USE_WORK_BROWSER; import static android.app.admin.DevicePolicyResources.Strings.Core.RESOLVER_CANT_ACCESS_PERSONAL; import static android.app.admin.DevicePolicyResources.Strings.Core.RESOLVER_CANT_ACCESS_WORK; import static android.app.admin.DevicePolicyResources.Strings.Core.RESOLVER_CROSS_PROFILE_BLOCKED_TITLE; @@ -46,6 +50,7 @@ import android.app.VoiceInteractor.PickOptionRequest.Option; import android.app.VoiceInteractor.Prompt; import android.app.admin.DevicePolicyEventLogger; import android.app.admin.DevicePolicyManager; +import android.app.admin.DevicePolicyResourcesManager; import android.compat.annotation.UnsupportedAppUsage; import android.content.BroadcastReceiver; import android.content.ComponentName; @@ -1713,14 +1718,29 @@ public class ResolverActivity extends Activity implements } }.execute(); - ((TextView) findViewById(R.id.open_cross_profile)).setText( - getResources().getString( - inWorkProfile ? R.string.miniresolver_open_in_personal - : R.string.miniresolver_open_in_work, - otherProfileResolveInfo.getDisplayLabel())); - ((Button) findViewById(R.id.use_same_profile_browser)).setText( - inWorkProfile ? R.string.miniresolver_use_work_browser - : R.string.miniresolver_use_personal_browser); + CharSequence targetDisplayLabel = otherProfileResolveInfo.getDisplayLabel(); + + DevicePolicyResourcesManager devicePolicyResourcesManager = getSystemService( + DevicePolicyManager.class).getResources(); + + if (inWorkProfile) { + ((TextView) findViewById(R.id.open_cross_profile)).setText( + devicePolicyResourcesManager.getString(MINIRESOLVER_OPEN_IN_WORK, + () -> getString(R.string.miniresolver_open_in_work, targetDisplayLabel), + targetDisplayLabel)); + ((Button) findViewById(R.id.use_same_profile_browser)).setText( + devicePolicyResourcesManager.getString(MINIRESOLVER_USE_WORK_BROWSER, + () -> getString(R.string.miniresolver_use_work_browser))); + } else { + ((TextView) findViewById(R.id.open_cross_profile)).setText( + devicePolicyResourcesManager.getString(MINIRESOLVER_OPEN_IN_PERSONAL, + () -> getString(R.string.miniresolver_open_in_personal, + targetDisplayLabel), + targetDisplayLabel)); + ((Button) findViewById(R.id.use_same_profile_browser)).setText( + devicePolicyResourcesManager.getString(MINIRESOLVER_USE_PERSONAL_BROWSER, + () -> getString(R.string.miniresolver_use_personal_browser))); + } findViewById(R.id.use_same_profile_browser).setOnClickListener( v -> {