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
This commit is contained in:
@@ -55,7 +55,7 @@
|
|||||||
settings:searchable="false"/>
|
settings:searchable="false"/>
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="default_apps_v2"
|
android:key="default_apps"
|
||||||
android:title="@string/app_default_dashboard_title"
|
android:title="@string/app_default_dashboard_title"
|
||||||
android:order="-996"
|
android:order="-996"
|
||||||
settings:controller="com.android.settings.applications.DefaultAppsPreferenceController">
|
settings:controller="com.android.settings.applications.DefaultAppsPreferenceController">
|
||||||
@@ -85,7 +85,7 @@
|
|||||||
</Preference>
|
</Preference>
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="special_access_v2"
|
android:key="special_access"
|
||||||
android:fragment="com.android.settings.applications.specialaccess.SpecialAccessSettings"
|
android:fragment="com.android.settings.applications.specialaccess.SpecialAccessSettings"
|
||||||
android:title="@string/special_access"
|
android:title="@string/special_access"
|
||||||
android:order="20"
|
android:order="20"
|
||||||
|
@@ -69,6 +69,7 @@ public class AppDashboardFragment extends DashboardFragment {
|
|||||||
use(SpecialAppAccessPreferenceController.class).setSession(getSettingsLifecycle());
|
use(SpecialAppAccessPreferenceController.class).setSession(getSettingsLifecycle());
|
||||||
mAppsPreferenceController = use(AppsPreferenceController.class);
|
mAppsPreferenceController = use(AppsPreferenceController.class);
|
||||||
mAppsPreferenceController.setFragment(this /* fragment */);
|
mAppsPreferenceController.setFragment(this /* fragment */);
|
||||||
|
getSettingsLifecycle().addObserver(mAppsPreferenceController);
|
||||||
|
|
||||||
final HibernatedAppsPreferenceController hibernatedAppsPreferenceController =
|
final HibernatedAppsPreferenceController hibernatedAppsPreferenceController =
|
||||||
use(HibernatedAppsPreferenceController.class);
|
use(HibernatedAppsPreferenceController.class);
|
||||||
|
@@ -26,6 +26,9 @@ import android.util.ArrayMap;
|
|||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.lifecycle.LifecycleObserver;
|
||||||
|
import androidx.lifecycle.OnLifecycleEvent;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceCategory;
|
import androidx.preference.PreferenceCategory;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
@@ -45,7 +48,8 @@ import java.util.Map;
|
|||||||
* This controller displays up to four recently used apps.
|
* This controller displays up to four recently used apps.
|
||||||
* If there is no recently used app, we only show up an "App Info" preference.
|
* 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;
|
public static final int SHOW_RECENT_APP_COUNT = 4;
|
||||||
|
|
||||||
@@ -73,6 +77,7 @@ public class AppsPreferenceController extends BasePreferenceController {
|
|||||||
Preference mSeeAllPref;
|
Preference mSeeAllPref;
|
||||||
|
|
||||||
private Fragment mHost;
|
private Fragment mHost;
|
||||||
|
private boolean mInitialLaunch = false;
|
||||||
|
|
||||||
public AppsPreferenceController(Context context) {
|
public AppsPreferenceController(Context context) {
|
||||||
super(context, KEY_RECENT_APPS_CATEGORY);
|
super(context, KEY_RECENT_APPS_CATEGORY);
|
||||||
@@ -95,12 +100,23 @@ public class AppsPreferenceController extends BasePreferenceController {
|
|||||||
super.displayPreference(screen);
|
super.displayPreference(screen);
|
||||||
initPreferences(screen);
|
initPreferences(screen);
|
||||||
refreshUi();
|
refreshUi();
|
||||||
|
mInitialLaunch = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
super.updateState(preference);
|
super.updateState(preference);
|
||||||
refreshUi();
|
if (!mInitialLaunch) {
|
||||||
|
refreshUi();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the apps page pauses.
|
||||||
|
*/
|
||||||
|
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
||||||
|
public void onPause() {
|
||||||
|
mInitialLaunch = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -109,11 +125,15 @@ public class AppsPreferenceController extends BasePreferenceController {
|
|||||||
mRecentApps = loadRecentApps();
|
mRecentApps = loadRecentApps();
|
||||||
if (!mRecentApps.isEmpty()) {
|
if (!mRecentApps.isEmpty()) {
|
||||||
displayRecentApps();
|
displayRecentApps();
|
||||||
|
mAllAppsInfoPref.setVisible(false);
|
||||||
mRecentAppsCategory.setVisible(true);
|
mRecentAppsCategory.setVisible(true);
|
||||||
mGeneralCategory.setVisible(true);
|
mGeneralCategory.setVisible(true);
|
||||||
mSeeAllPref.setVisible(true);
|
mSeeAllPref.setVisible(true);
|
||||||
} else {
|
} else {
|
||||||
mAllAppsInfoPref.setVisible(true);
|
mAllAppsInfoPref.setVisible(true);
|
||||||
|
mRecentAppsCategory.setVisible(false);
|
||||||
|
mGeneralCategory.setVisible(false);
|
||||||
|
mSeeAllPref.setVisible(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user