From 616a1b828d03b0700f2cb395d37e1dfc3be485ea Mon Sep 17 00:00:00 2001 From: Himanshu Gupta Date: Thu, 7 Mar 2024 13:50:15 +0000 Subject: [PATCH] Using LauncherApps API for PS Settings and Setup Flow. Bug: 310027945 Test: Launcher3 tests Flag: ACONFIG com.android.launcher3.enable_private_space TRUNKFOOD Change-Id: I6e04a4b0c33d4526d83b51e512e1e4372ce1cca4 --- .../launcher3/uioverrides/ApiWrapper.java | 23 +++++++++++++++++++ .../allapps/PrivateProfileManager.java | 14 ++++------- .../launcher3/uioverrides/ApiWrapper.java | 7 ++++++ .../allapps/PrivateProfileManagerTest.java | 9 ++++---- 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/quickstep/src/com/android/launcher3/uioverrides/ApiWrapper.java b/quickstep/src/com/android/launcher3/uioverrides/ApiWrapper.java index dcc3b052c9..873dea80e3 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/ApiWrapper.java +++ b/quickstep/src/com/android/launcher3/uioverrides/ApiWrapper.java @@ -21,6 +21,7 @@ import android.app.PendingIntent; import android.app.Person; import android.content.Context; import android.content.Intent; +import android.content.IntentSender; import android.content.pm.ActivityInfo; import android.content.pm.LauncherActivityInfo; import android.content.pm.LauncherApps; @@ -157,6 +158,28 @@ public class ApiWrapper { } } + /** + * Returns an intent which can be used to open Private Space Settings. + */ + public static Intent getPrivateSpaceSettingsIntent(Context context) { + if (android.os.Flags.allowPrivateProfile() && Flags.enablePrivateSpace()) { + LauncherApps launcherApps = context.getSystemService(LauncherApps.class); + IntentSender intentSender = launcherApps.getPrivateSpaceSettingsIntent(); + if (intentSender == null) { + return null; + } + StartActivityParams params = new StartActivityParams((PendingIntent) null, 0); + params.intentSender = intentSender; + ActivityOptions options = ActivityOptions.makeBasic() + .setPendingIntentBackgroundActivityStartMode(ActivityOptions + .MODE_BACKGROUND_ACTIVITY_START_ALLOWED); + params.options = options.toBundle(); + params.requireActivityResult = false; + return ProxyActivityStarter.getLaunchIntent(context, params); + } + return null; + } + /** * Checks if an activity is flagged as non-resizeable. */ diff --git a/src/com/android/launcher3/allapps/PrivateProfileManager.java b/src/com/android/launcher3/allapps/PrivateProfileManager.java index 1ebd49e9dd..a73fb70c5d 100644 --- a/src/com/android/launcher3/allapps/PrivateProfileManager.java +++ b/src/com/android/launcher3/allapps/PrivateProfileManager.java @@ -30,8 +30,6 @@ import static com.android.launcher3.util.SettingsCache.PRIVATE_SPACE_HIDE_WHEN_L import android.content.Context; import android.content.Intent; -import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; import android.os.UserHandle; import android.os.UserManager; @@ -60,10 +58,6 @@ import java.util.function.Predicate; */ public class PrivateProfileManager extends UserProfileManager { - // 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<>(); @@ -162,7 +156,8 @@ public class PrivateProfileManager extends UserProfileManager { /** Opens the Private Space Settings Page. */ public void openPrivateSpaceSettings() { if (mPrivateSpaceSettingsAvailable) { - mAllApps.getContext().startActivity(PRIVATE_SPACE_INTENT); + mAllApps.getContext() + .startActivity(ApiWrapper.getPrivateSpaceSettingsIntent(mAllApps.getContext())); } } @@ -194,9 +189,8 @@ public class PrivateProfileManager extends UserProfileManager { private void initializePrivateSpaceSettingsState() { Preconditions.assertNonUiThread(); - ResolveInfo resolveInfo = mAllApps.getContext().getPackageManager() - .resolveActivity(PRIVATE_SPACE_INTENT, PackageManager.MATCH_SYSTEM_ONLY); - setPrivateSpaceSettingsAvailable(resolveInfo != null); + Intent psSettingsIntent = ApiWrapper.getPrivateSpaceSettingsIntent(mAllApps.getContext()); + setPrivateSpaceSettingsAvailable(psSettingsIntent != null); } private void setPreInstalledSystemPackages() { diff --git a/src_ui_overrides/com/android/launcher3/uioverrides/ApiWrapper.java b/src_ui_overrides/com/android/launcher3/uioverrides/ApiWrapper.java index efde7d863a..90271c1cae 100644 --- a/src_ui_overrides/com/android/launcher3/uioverrides/ApiWrapper.java +++ b/src_ui_overrides/com/android/launcher3/uioverrides/ApiWrapper.java @@ -107,6 +107,13 @@ public class ApiWrapper { .authority(context.getPackageName()).build()); } + /** + * Returns an intent which can be used to open Private Space Settings. + */ + public static Intent getPrivateSpaceSettingsIntent(Context context) { + return null; + } + /** * Checks if an activity is flagged as non-resizeable. */ diff --git a/tests/src/com/android/launcher3/allapps/PrivateProfileManagerTest.java b/tests/src/com/android/launcher3/allapps/PrivateProfileManagerTest.java index 0907f8fe81..eea4fe5f0c 100644 --- a/tests/src/com/android/launcher3/allapps/PrivateProfileManagerTest.java +++ b/tests/src/com/android/launcher3/allapps/PrivateProfileManagerTest.java @@ -47,6 +47,7 @@ import androidx.test.runner.AndroidJUnit4; import com.android.launcher3.logging.StatsLogManager; import com.android.launcher3.pm.UserCache; +import com.android.launcher3.uioverrides.ApiWrapper; import com.android.launcher3.util.ActivityContextWrapper; import com.android.launcher3.util.UserIconInfo; import com.android.launcher3.util.rule.TestStabilityRule; @@ -176,17 +177,15 @@ public class PrivateProfileManagerTest { } @Test - public void openPrivateSpaceSettings_triggersSecurityAndPrivacyIntent() { - Intent expectedIntent = PrivateProfileManager.PRIVATE_SPACE_INTENT; + public void openPrivateSpaceSettings_triggersCorrectIntent() { + Intent expectedIntent = ApiWrapper.getPrivateSpaceSettingsIntent(mContext); ArgumentCaptor acIntent = ArgumentCaptor.forClass(Intent.class); mPrivateProfileManager.setPrivateSpaceSettingsAvailable(true); mPrivateProfileManager.openPrivateSpaceSettings(); Mockito.verify(mContext).startActivity(acIntent.capture()); - Intent actualIntent = acIntent.getValue(); - assertEquals("Intent Action is different", expectedIntent.getAction(), - actualIntent.getAction()); + assertEquals("Intent Action is different", expectedIntent, acIntent.getValue()); } private static void awaitTasksCompleted() throws Exception {