From b12ff142a88b0794a8e1bfdd625ca889f32e06ee Mon Sep 17 00:00:00 2001 From: Himanshu Gupta Date: Fri, 2 Feb 2024 10:56:31 +0000 Subject: [PATCH] Making Settings Cog open PS Settings page. Settings Cog action should direct to PS Settings page instead of PS entry point page in Privacy&Security Center Bug: 322484516 Flag: ACONFIG com.android.launcher3.Flags.enable_private_space TRUNKFOOD Flag: ACONFIG com.google.android.apps.nexuslauncher.Flags.enable_inject_private_space_tile TRUNKFOOD Test: Launcher3 test. Change-Id: I2bc7a95d591ccedb343909c159c3cbda2814e6bf --- .../allapps/PrivateProfileManager.java | 35 ++++++++++--------- .../allapps/PrivateProfileManagerTest.java | 10 ++---- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/com/android/launcher3/allapps/PrivateProfileManager.java b/src/com/android/launcher3/allapps/PrivateProfileManager.java index 6422943b07..1ebd49e9dd 100644 --- a/src/com/android/launcher3/allapps/PrivateProfileManager.java +++ b/src/com/android/launcher3/allapps/PrivateProfileManager.java @@ -60,9 +60,10 @@ import java.util.function.Predicate; */ public class PrivateProfileManager extends UserProfileManager { - private static final String SAFETY_CENTER_INTENT = Intent.ACTION_SAFETY_CENTER; - private static final String PS_SETTINGS_FRAGMENT_KEY = ":settings:fragment_args_key"; - private static final String PS_SETTINGS_FRAGMENT_VALUE = "AndroidPrivateSpace_personal"; + // TODO (b/324573634): Fix the intent string. + public static final Intent PRIVATE_SPACE_INTENT = new + Intent("com.android.settings.action.PRIVATE_SPACE_SETUP_FLOW"); + private final ActivityAllAppsContainerView mAllApps; private final Predicate mPrivateProfileMatcher; private Set mPreInstalledSystemPackages = new HashSet<>(); @@ -158,18 +159,23 @@ public class PrivateProfileManager extends UserProfileManager { } } - /** Opens the Private Space Settings Entry Point. */ + /** Opens the Private Space Settings Page. */ public void openPrivateSpaceSettings() { - Intent psSettingsIntent = new Intent(SAFETY_CENTER_INTENT); - psSettingsIntent.putExtra(PS_SETTINGS_FRAGMENT_KEY, PS_SETTINGS_FRAGMENT_VALUE); - mAllApps.getContext().startActivity(psSettingsIntent); + if (mPrivateSpaceSettingsAvailable) { + mAllApps.getContext().startActivity(PRIVATE_SPACE_INTENT); + } } - /** Whether Private Space Settings Entry Point is available on the device. */ + /** Returns whether or not Private Space Settings Page is available. */ public boolean isPrivateSpaceSettingsAvailable() { return mPrivateSpaceSettingsAvailable; } + /** Sets whether Private Space Settings Page is available. */ + public boolean setPrivateSpaceSettingsAvailable(boolean value) { + return mPrivateSpaceSettingsAvailable = value; + } + /** Initializes binder call based properties in non-main thread. *

* This can cause the Private Space container items to not load/respond correctly sometimes, @@ -183,19 +189,14 @@ public class PrivateProfileManager extends UserProfileManager { Preconditions.assertNonUiThread(); setPreInstalledSystemPackages(); setAppInstallerIntent(); - setPrivateSpaceSettingsAvailable(); + initializePrivateSpaceSettingsState(); } - private void setPrivateSpaceSettingsAvailable() { - if (mPrivateSpaceSettingsAvailable) { - return; - } + private void initializePrivateSpaceSettingsState() { Preconditions.assertNonUiThread(); - Intent psSettingsIntent = new Intent(SAFETY_CENTER_INTENT); - psSettingsIntent.putExtra(PS_SETTINGS_FRAGMENT_KEY, PS_SETTINGS_FRAGMENT_VALUE); ResolveInfo resolveInfo = mAllApps.getContext().getPackageManager() - .resolveActivity(psSettingsIntent, PackageManager.MATCH_SYSTEM_ONLY); - mPrivateSpaceSettingsAvailable = resolveInfo != null; + .resolveActivity(PRIVATE_SPACE_INTENT, PackageManager.MATCH_SYSTEM_ONLY); + setPrivateSpaceSettingsAvailable(resolveInfo != null); } private void setPreInstalledSystemPackages() { diff --git a/tests/src/com/android/launcher3/allapps/PrivateProfileManagerTest.java b/tests/src/com/android/launcher3/allapps/PrivateProfileManagerTest.java index ea7feb5efd..0907f8fe81 100644 --- a/tests/src/com/android/launcher3/allapps/PrivateProfileManagerTest.java +++ b/tests/src/com/android/launcher3/allapps/PrivateProfileManagerTest.java @@ -76,9 +76,6 @@ public class PrivateProfileManagerTest { new UserIconInfo(MAIN_HANDLE, UserIconInfo.TYPE_MAIN); private static final UserIconInfo PRIVATE_ICON_INFO = new UserIconInfo(PRIVATE_HANDLE, UserIconInfo.TYPE_PRIVATE); - private static final String SAFETY_CENTER_INTENT = Intent.ACTION_SAFETY_CENTER; - private static final String PS_SETTINGS_FRAGMENT_KEY = ":settings:fragment_args_key"; - private static final String PS_SETTINGS_FRAGMENT_VALUE = "AndroidPrivateSpace_personal"; private PrivateProfileManager mPrivateProfileManager; @Mock @@ -180,9 +177,9 @@ public class PrivateProfileManagerTest { @Test public void openPrivateSpaceSettings_triggersSecurityAndPrivacyIntent() { - Intent expectedIntent = new Intent(SAFETY_CENTER_INTENT); - expectedIntent.putExtra(PS_SETTINGS_FRAGMENT_KEY, PS_SETTINGS_FRAGMENT_VALUE); + Intent expectedIntent = PrivateProfileManager.PRIVATE_SPACE_INTENT; ArgumentCaptor acIntent = ArgumentCaptor.forClass(Intent.class); + mPrivateProfileManager.setPrivateSpaceSettingsAvailable(true); mPrivateProfileManager.openPrivateSpaceSettings(); @@ -190,9 +187,6 @@ public class PrivateProfileManagerTest { Intent actualIntent = acIntent.getValue(); assertEquals("Intent Action is different", expectedIntent.getAction(), actualIntent.getAction()); - assertEquals("Settings Fragment is incorrect in Intent", - expectedIntent.getStringExtra(PS_SETTINGS_FRAGMENT_KEY), - actualIntent.getStringExtra(PS_SETTINGS_FRAGMENT_KEY)); } private static void awaitTasksCompleted() throws Exception {