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.
setSpaEnvironment();
if (FeatureFlagUtils.isEnabled(this, FeatureFlagUtils.SETTINGS_SUPPORT_LARGE_SCREEN)
&& ActivityEmbeddingUtils.isSettingsSplitEnabled(this)) {
if (ActivityEmbeddingUtils.isSettingsSplitEnabled(this)
&& FeatureFlagUtils.isEnabled(this,
FeatureFlagUtils.SETTINGS_SUPPORT_LARGE_SCREEN)) {
if (WizardManagerHelper.isUserSetupComplete(this)) {
new ActivityEmbeddingRulesController(this).initRules();
} else {

View File

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

View File

@@ -57,7 +57,6 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.window.embedding.ActivityEmbeddingController;
import androidx.window.embedding.SplitRule;
import com.android.settings.R;
@@ -108,7 +107,6 @@ public class SettingsHomepageActivity extends FragmentActivity implements
private View mTwoPaneSuggestionView;
private CategoryMixin mCategoryMixin;
private Set<HomepageLoadedListener> mLoadedListeners;
private ActivityEmbeddingController mActivityEmbeddingController;
private boolean mIsEmbeddingActivityEnabled;
private boolean mIsTwoPane;
// A regular layout shows icons on homepage, whereas a simplified layout doesn't.
@@ -200,8 +198,7 @@ public class SettingsHomepageActivity extends FragmentActivity implements
setupEdgeToEdge();
setContentView(R.layout.settings_homepage_container);
mActivityEmbeddingController = ActivityEmbeddingController.getInstance(this);
mIsTwoPane = mActivityEmbeddingController.isActivityEmbedded(this);
mIsTwoPane = ActivityEmbeddingUtils.isAlreadyEmbedded(this);
updateAppBarMinHeight();
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
// 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) {
initSplitPairRules();
}
@@ -284,7 +281,7 @@ public class SettingsHomepageActivity extends FragmentActivity implements
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
final boolean newTwoPaneState = mActivityEmbeddingController.isActivityEmbedded(this);
final boolean newTwoPaneState = ActivityEmbeddingUtils.isAlreadyEmbedded(this);
if (mIsTwoPane != newTwoPaneState) {
mIsTwoPane = newTwoPaneState;
updateHomepageAppBar();
@@ -427,8 +424,9 @@ public class SettingsHomepageActivity extends FragmentActivity implements
}
private boolean shouldLaunchDeepLinkIntentToRight() {
if (!FeatureFlagUtils.isEnabled(this, FeatureFlagUtils.SETTINGS_SUPPORT_LARGE_SCREEN)
|| !ActivityEmbeddingUtils.isSettingsSplitEnabled(this)) {
if (!ActivityEmbeddingUtils.isSettingsSplitEnabled(this)
|| !FeatureFlagUtils.isEnabled(this,
FeatureFlagUtils.SETTINGS_SUPPORT_LARGE_SCREEN)) {
return false;
}