Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4124284b authored by Yanting Yang's avatar Yanting Yang
Browse files

Improve the latency of first entering Apps page

Root cause:
AppsPreferenceController will query the recent app usages twice on
the main thread.

Solution:
Set flag to ensure only triggering refreshUi() once when entering
the Apps page.

Also correct the preference key of apps.xml since we don’t have
duplicated preferences now.

Fixes: 183176038
Test: robotests & visual
Change-Id: Ia41ee1e4a1946b8122deca63e318d3915afcc426
parent 54c1ff84
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@
        settings:searchable="false"/>

    <Preference
        android:key="default_apps_v2"
        android:key="default_apps"
        android:title="@string/app_default_dashboard_title"
        android:order="-996"
        settings:controller="com.android.settings.applications.DefaultAppsPreferenceController">
@@ -85,7 +85,7 @@
    </Preference>

    <Preference
        android:key="special_access_v2"
        android:key="special_access"
        android:fragment="com.android.settings.applications.specialaccess.SpecialAccessSettings"
        android:title="@string/special_access"
        android:order="20"
+1 −0
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ public class AppDashboardFragment extends DashboardFragment {
        use(SpecialAppAccessPreferenceController.class).setSession(getSettingsLifecycle());
        mAppsPreferenceController = use(AppsPreferenceController.class);
        mAppsPreferenceController.setFragment(this /* fragment */);
        getSettingsLifecycle().addObserver(mAppsPreferenceController);

        final HibernatedAppsPreferenceController hibernatedAppsPreferenceController =
                use(HibernatedAppsPreferenceController.class);
+22 −2
Original line number Diff line number Diff line
@@ -26,6 +26,9 @@ import android.util.ArrayMap;

import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
@@ -45,7 +48,8 @@ import java.util.Map;
 * This controller displays up to four recently used apps.
 * If there is no recently used app, we only show up an "App Info" preference.
 */
public class AppsPreferenceController extends BasePreferenceController {
public class AppsPreferenceController extends BasePreferenceController implements
        LifecycleObserver {

    public static final int SHOW_RECENT_APP_COUNT = 4;

@@ -73,6 +77,7 @@ public class AppsPreferenceController extends BasePreferenceController {
    Preference mSeeAllPref;

    private Fragment mHost;
    private boolean mInitialLaunch = false;

    public AppsPreferenceController(Context context) {
        super(context, KEY_RECENT_APPS_CATEGORY);
@@ -95,13 +100,24 @@ public class AppsPreferenceController extends BasePreferenceController {
        super.displayPreference(screen);
        initPreferences(screen);
        refreshUi();
        mInitialLaunch = true;
    }

    @Override
    public void updateState(Preference preference) {
        super.updateState(preference);
        if (!mInitialLaunch) {
            refreshUi();
        }
    }

    /**
     * Called when the apps page pauses.
     */
    @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
    public void onPause() {
        mInitialLaunch = false;
    }

    @VisibleForTesting
    void refreshUi() {
@@ -109,11 +125,15 @@ public class AppsPreferenceController extends BasePreferenceController {
        mRecentApps = loadRecentApps();
        if (!mRecentApps.isEmpty()) {
            displayRecentApps();
            mAllAppsInfoPref.setVisible(false);
            mRecentAppsCategory.setVisible(true);
            mGeneralCategory.setVisible(true);
            mSeeAllPref.setVisible(true);
        } else {
            mAllAppsInfoPref.setVisible(true);
            mRecentAppsCategory.setVisible(false);
            mGeneralCategory.setVisible(false);
            mSeeAllPref.setVisible(false);
        }
    }