Improve launch time for app & notification screen

- We won't query recent apps in getAvailabilityStatus().
And then we do that in background thread.
So, we can launch app & notificatins screen as soon as possible.

- Create a RecentAppStatsMixin class which is responsible
for maintaining the recent apps data.

- Controllers and fragment update their UI after they got
onReloadDataCompleted callback from RecentAppStatsMixin.

Test: manual, robotest
Fixes: 128849426
Fixes: 126453868
Change-Id: I636d5878cb5d53496978fe613c625382d8d382bc
This commit is contained in:
tmfang
2019-03-19 13:44:01 +08:00
parent 6010c3a9a8
commit e9f11d6efc
7 changed files with 629 additions and 431 deletions

View File

@@ -19,39 +19,54 @@ package com.android.settings.applications;
import android.app.usage.UsageStats;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import java.util.List;
public class AllAppsInfoPreferenceController extends BasePreferenceController {
public class AllAppsInfoPreferenceController extends BasePreferenceController
implements RecentAppStatsMixin.RecentAppStatsListener {
private List<UsageStats> mRecentApps;
@VisibleForTesting
Preference mPreference;
public AllAppsInfoPreferenceController(Context context, String key) {
super(context, key);
}
public void setRecentApps(List<UsageStats> recentApps) {
mRecentApps = recentApps;
}
@Override
public int getAvailabilityStatus() {
return mRecentApps == null || mRecentApps.isEmpty() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
return AVAILABLE;
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = screen.findPreference(getPreferenceKey());
// In most cases, device has recently opened apps. So, we hide it by default.
mPreference.setVisible(false);
}
@Override
public void onReloadDataCompleted(@NonNull List<UsageStats> recentApps) {
// If device has recently opened apps, we don't show all apps preference.
if (!recentApps.isEmpty()) {
mPreference.setVisible(false);
return;
}
mPreference.setVisible(true);
// Show total number of installed apps as See all's summary.
new InstalledAppCounter(mContext, InstalledAppCounter.IGNORE_INSTALL_REASON,
mContext.getPackageManager()) {
@Override
protected void onCountComplete(int num) {
preference.setSummary(mContext.getString(R.string.apps_summary, num));
mPreference.setSummary(mContext.getString(R.string.apps_summary, num));
}
}.execute();
}