From b3db40a02bb8c42d7f603060921d9a11de2eb0aa Mon Sep 17 00:00:00 2001 From: Tsung-Mao Fang Date: Wed, 3 Nov 2021 16:27:30 +0800 Subject: [PATCH] Register rule for wallpaper entry We should keep consistent split rule for wallpaper and other home menu item. So, we create this cl to register the split rule for wallpaper. Also, I do some minor refactoring in this cl for reusing existing method and better code quality. Test: Go to wallpaper, and click back key. App can close. Fix: 204406425 Fix: 204364572 Change-Id: Ia7de9483b351d1121cc26c4af1cb8a89ad0a16bc --- .../ActivityEmbeddingRulesController.java | 42 ++++++++++++++++--- .../DashboardFeatureProviderImpl.java | 10 ++--- ...TopLevelWallpaperPreferenceController.java | 6 +++ .../settings/homepage/TopLevelSettings.java | 2 +- .../search/SearchResultTrampoline.java | 2 +- 5 files changed, 47 insertions(+), 15 deletions(-) diff --git a/src/com/android/settings/activityembedding/ActivityEmbeddingRulesController.java b/src/com/android/settings/activityembedding/ActivityEmbeddingRulesController.java index 974ec2cbe2a..53e80203d35 100644 --- a/src/com/android/settings/activityembedding/ActivityEmbeddingRulesController.java +++ b/src/com/android/settings/activityembedding/ActivityEmbeddingRulesController.java @@ -73,6 +73,9 @@ public class ActivityEmbeddingRulesController { boolean finishPrimaryWithSecondary, boolean finishSecondaryWithPrimary, boolean clearTop) { + if (!ActivityEmbeddingUtils.isEmbeddingActivityEnabled(context)) { + return; + } final Set filters = new HashSet<>(); filters.add(new SplitPairFilter(primaryComponent, secondaryComponent, secondaryIntentAction)); @@ -87,18 +90,45 @@ public class ActivityEmbeddingRulesController { LayoutDirection.LOCALE)); } + /** + * Register a new SplitPairRule for Settings home. Because homepage is able to be opened by + * {@link Settings} or {@link SettingsHomepageActivity}, we register split rule twice for + * two cases. + */ + public static void registerTwoPanePairRuleForSettingsHome(Context context, + ComponentName secondaryComponent, + String secondaryIntentAction, + boolean clearTop) { + + registerTwoPanePairRule( + context, + getComponentName(context, Settings.class), + secondaryComponent, + secondaryIntentAction, + true /* finishPrimaryWithSecondary */, + true /* finishSecondaryWithPrimary */, + clearTop); + + registerTwoPanePairRule( + context, + getComponentName(context, SettingsHomepageActivity.class), + secondaryComponent, + secondaryIntentAction, + true /* finishPrimaryWithSecondary */, + true /* finishSecondaryWithPrimary */, + clearTop); + } + /** Register a SplitPairRule for SubSettings if the device supports 2-pane. */ - public static void registerSubSettingsPairRuleIfNeeded(Context context, boolean clearTop) { + public static void registerSubSettingsPairRule(Context context, boolean clearTop) { if (!ActivityEmbeddingUtils.isEmbeddingActivityEnabled(context)) { return; } - registerTwoPanePairRule(context, - getComponentName(context, Settings.class), + registerTwoPanePairRuleForSettingsHome( + context, getComponentName(context, SubSettings.class), null /* secondaryIntentAction */, - true /* finishPrimaryWithSecondary */, - true /* finishSecondaryWithPrimary */, clearTop); } @@ -140,7 +170,7 @@ public class ActivityEmbeddingRulesController { @NonNull private static ComponentName getComponentName(Context context, - Class activityClass) { + Class activityClass) { return new ComponentName(context.getPackageName(), activityClass.getName()); } } diff --git a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java index 951eb3c1b40..3d1381d6867 100644 --- a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java +++ b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java @@ -175,14 +175,10 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider { if (fragment instanceof TopLevelSettings && ActivityEmbeddingUtils.isEmbeddingActivityEnabled(mContext)) { // Register the rule for injected apps. - ActivityEmbeddingRulesController.registerTwoPanePairRule(mContext, - new ComponentName(activity.getPackageName(), - com.android.settings.Settings.class.getName()), - new ComponentName(tile.getPackageName(), - tile.getComponentName()), + ActivityEmbeddingRulesController.registerTwoPanePairRuleForSettingsHome( + mContext, + new ComponentName(tile.getPackageName(), tile.getComponentName()), null /* secondaryIntentAction */, - true /* finishPrimaryWithSecondary */, - true /* finishSecondaryWithPrimary */, true /* clearTop */); // Highlight preference ui. diff --git a/src/com/android/settings/display/TopLevelWallpaperPreferenceController.java b/src/com/android/settings/display/TopLevelWallpaperPreferenceController.java index 2e59725cdc1..7640d08716f 100644 --- a/src/com/android/settings/display/TopLevelWallpaperPreferenceController.java +++ b/src/com/android/settings/display/TopLevelWallpaperPreferenceController.java @@ -31,6 +31,7 @@ import androidx.preference.Preference; import androidx.preference.PreferenceScreen; import com.android.settings.R; +import com.android.settings.activityembedding.ActivityEmbeddingRulesController; import com.android.settings.activityembedding.ActivityEmbeddingUtils; import com.android.settings.core.BasePreferenceController; import com.android.settingslib.RestrictedLockUtilsInternal; @@ -102,6 +103,11 @@ public class TopLevelWallpaperPreferenceController extends BasePreferenceControl mContext)) { intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); } + ActivityEmbeddingRulesController.registerTwoPanePairRuleForSettingsHome( + mContext, + intent.getComponent(), + null /* secondaryIntentAction */, + true /* clearTop */); preference.getContext().startActivity(intent); return true; } diff --git a/src/com/android/settings/homepage/TopLevelSettings.java b/src/com/android/settings/homepage/TopLevelSettings.java index e9c7ef89668..2b0f7888730 100644 --- a/src/com/android/settings/homepage/TopLevelSettings.java +++ b/src/com/android/settings/homepage/TopLevelSettings.java @@ -100,7 +100,7 @@ public class TopLevelSettings extends DashboardFragment implements @Override public boolean onPreferenceTreeClick(Preference preference) { // Register SplitPairRule for SubSettings. - ActivityEmbeddingRulesController.registerSubSettingsPairRuleIfNeeded(getContext(), + ActivityEmbeddingRulesController.registerSubSettingsPairRule(getContext(), true /* clearTop */); setHighlightPreferenceKey(preference.getKey()); diff --git a/src/com/android/settings/search/SearchResultTrampoline.java b/src/com/android/settings/search/SearchResultTrampoline.java index d20a2ea860d..8805d198da8 100644 --- a/src/com/android/settings/search/SearchResultTrampoline.java +++ b/src/com/android/settings/search/SearchResultTrampoline.java @@ -97,7 +97,7 @@ public class SearchResultTrampoline extends Activity { } else if (isFromSettingsIntelligence(callingActivity)) { // Register SplitPairRule for SubSettings, set clearTop false to prevent unexpected back // navigation behavior. - ActivityEmbeddingRulesController.registerSubSettingsPairRuleIfNeeded(this, + ActivityEmbeddingRulesController.registerSubSettingsPairRule(this, false /* clearTop */); // TODO: pass menu key to homepage intent.setFlags(intent.getFlags() & ~Intent.FLAG_ACTIVITY_NEW_TASK);