Improve Settings launch performance for normal phones

1. Initialize ActivitEmbedding component only if necessary
2. Early return to avoid executing long execution time operations
  ex: initialize ActivityEmbedding component, feature flag operations

Test: manual - launch settings and profile
Test: run
v2/android-crystalball-eng/health/microbench/startup/firstparty/open-settings
on affacted devices
Test: atest SettingsHomepageActivityTest TopLevelWallpaperPreferenceControllerTest DashboardFeatureProviderImplTest TopLevelSettingsTest TopLevelWallpaperPreferenceControllerTest SearchResultTrampolineTest
Test: atest CtsSettingsTestCases
Fixes: 281505190

Change-Id: I0c1a1dc50f26c4ded02de82190dd7aad59c20c01
This commit is contained in:
Charles Chen
2023-05-10 17:07:15 +08:00
parent 90b344e760
commit 8524048094
3 changed files with 29 additions and 23 deletions

View File

@@ -51,8 +51,9 @@ public class SettingsApplication extends Application {
// Set Spa environment. // Set Spa environment.
setSpaEnvironment(); setSpaEnvironment();
if (FeatureFlagUtils.isEnabled(this, FeatureFlagUtils.SETTINGS_SUPPORT_LARGE_SCREEN) if (ActivityEmbeddingUtils.isSettingsSplitEnabled(this)
&& ActivityEmbeddingUtils.isSettingsSplitEnabled(this)) { && FeatureFlagUtils.isEnabled(this,
FeatureFlagUtils.SETTINGS_SUPPORT_LARGE_SCREEN)) {
if (WizardManagerHelper.isUserSetupComplete(this)) { if (WizardManagerHelper.isUserSetupComplete(this)) {
new ActivityEmbeddingRulesController(this).initRules(); new ActivityEmbeddingRulesController(this).initRules();
} else { } else {

View File

@@ -97,16 +97,24 @@ public class ActivityEmbeddingUtils {
* </ul> * </ul>
*/ */
public static boolean isEmbeddingActivityEnabled(Context context) { public static boolean isEmbeddingActivityEnabled(Context context) {
boolean isFlagEnabled = FeatureFlagUtils.isEnabled(context, // Activity Embedding feature is not enabled if Settings doesn't enable large screen
FeatureFlagUtils.SETTINGS_SUPPORT_LARGE_SCREEN); // optimization or the device is not supported.
boolean isSettingsSplitSupported = isSettingsSplitEnabled(context); if (!isSettingsSplitEnabled(context)) {
boolean isUserSetupComplete = WizardManagerHelper.isUserSetupComplete(context); Log.d(TAG, "isSettingsSplitSupported = false");
return false;
Log.d(TAG, "isFlagEnabled = " + isFlagEnabled); }
Log.d(TAG, "isSettingsSplitSupported = " + isSettingsSplitSupported); // Activity Embedding feature is not enabled if a user chooses to disable the feature.
Log.d(TAG, "isUserSetupComplete = " + isUserSetupComplete); if (!FeatureFlagUtils.isEnabled(context, FeatureFlagUtils.SETTINGS_SUPPORT_LARGE_SCREEN)) {
Log.d(TAG, "isFlagEnabled = false");
return isFlagEnabled && isSettingsSplitSupported && isUserSetupComplete; return false;
}
// Don't enable Activity embedding for setup wizard.
if (!WizardManagerHelper.isUserSetupComplete(context)) {
Log.d(TAG, "isUserSetupComplete = false");
return false;
}
Log.d(TAG, "isEmbeddingActivityEnabled = true");
return true;
} }
/** Whether to show the regular or simplified homepage layout. */ /** Whether to show the regular or simplified homepage layout. */
@@ -120,8 +128,7 @@ public class ActivityEmbeddingUtils {
* Check if activity is already embedded * Check if activity is already embedded
*/ */
public static boolean isAlreadyEmbedded(Activity activity) { public static boolean isAlreadyEmbedded(Activity activity) {
return ActivityEmbeddingController return isEmbeddingActivityEnabled(activity) && ActivityEmbeddingController.getInstance(
.getInstance(activity) activity).isActivityEmbedded(activity);
.isActivityEmbedded(activity);
} }
} }

View File

@@ -57,7 +57,6 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import androidx.window.embedding.ActivityEmbeddingController;
import androidx.window.embedding.SplitRule; import androidx.window.embedding.SplitRule;
import com.android.settings.R; import com.android.settings.R;
@@ -108,7 +107,6 @@ public class SettingsHomepageActivity extends FragmentActivity implements
private View mTwoPaneSuggestionView; private View mTwoPaneSuggestionView;
private CategoryMixin mCategoryMixin; private CategoryMixin mCategoryMixin;
private Set<HomepageLoadedListener> mLoadedListeners; private Set<HomepageLoadedListener> mLoadedListeners;
private ActivityEmbeddingController mActivityEmbeddingController;
private boolean mIsEmbeddingActivityEnabled; private boolean mIsEmbeddingActivityEnabled;
private boolean mIsTwoPane; private boolean mIsTwoPane;
// A regular layout shows icons on homepage, whereas a simplified layout doesn't. // A regular layout shows icons on homepage, whereas a simplified layout doesn't.
@@ -200,8 +198,7 @@ public class SettingsHomepageActivity extends FragmentActivity implements
setupEdgeToEdge(); setupEdgeToEdge();
setContentView(R.layout.settings_homepage_container); setContentView(R.layout.settings_homepage_container);
mActivityEmbeddingController = ActivityEmbeddingController.getInstance(this); mIsTwoPane = ActivityEmbeddingUtils.isAlreadyEmbedded(this);
mIsTwoPane = mActivityEmbeddingController.isActivityEmbedded(this);
updateAppBarMinHeight(); updateAppBarMinHeight();
initHomepageContainer(); initHomepageContainer();
@@ -242,7 +239,7 @@ public class SettingsHomepageActivity extends FragmentActivity implements
// Settings app may be launched on an existing task. Reset SplitPairRule of SubSettings here // Settings app may be launched on an existing task. Reset SplitPairRule of SubSettings here
// to prevent SplitPairRule of an existing task applied on a new started Settings app. // to prevent SplitPairRule of an existing task applied on a new started Settings app.
if (ActivityEmbeddingUtils.isEmbeddingActivityEnabled(this) if (mIsEmbeddingActivityEnabled
&& (getIntent().getFlags() & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) { && (getIntent().getFlags() & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) {
initSplitPairRules(); initSplitPairRules();
} }
@@ -284,7 +281,7 @@ public class SettingsHomepageActivity extends FragmentActivity implements
@Override @Override
public void onConfigurationChanged(Configuration newConfig) { public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig); super.onConfigurationChanged(newConfig);
final boolean newTwoPaneState = mActivityEmbeddingController.isActivityEmbedded(this); final boolean newTwoPaneState = ActivityEmbeddingUtils.isAlreadyEmbedded(this);
if (mIsTwoPane != newTwoPaneState) { if (mIsTwoPane != newTwoPaneState) {
mIsTwoPane = newTwoPaneState; mIsTwoPane = newTwoPaneState;
updateHomepageAppBar(); updateHomepageAppBar();
@@ -427,8 +424,9 @@ public class SettingsHomepageActivity extends FragmentActivity implements
} }
private boolean shouldLaunchDeepLinkIntentToRight() { private boolean shouldLaunchDeepLinkIntentToRight() {
if (!FeatureFlagUtils.isEnabled(this, FeatureFlagUtils.SETTINGS_SUPPORT_LARGE_SCREEN) if (!ActivityEmbeddingUtils.isSettingsSplitEnabled(this)
|| !ActivityEmbeddingUtils.isSettingsSplitEnabled(this)) { || !FeatureFlagUtils.isEnabled(this,
FeatureFlagUtils.SETTINGS_SUPPORT_LARGE_SCREEN)) {
return false; return false;
} }