Work on settings startup speed
- Cut down on amount stored in conditions xml - Remove extra work from dashboard startup - Move summary to min priority Change-Id: I51ca3828e4446632d6faa60dcfbab3446d19d335 Fixes: 28134360
This commit is contained in:
@@ -85,6 +85,10 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
setShowingAll(true);
|
||||
}
|
||||
|
||||
public List<Tile> getSuggestions() {
|
||||
return mSuggestions;
|
||||
}
|
||||
|
||||
public void setSuggestions(SuggestionParser suggestionParser) {
|
||||
mSuggestionParser = suggestionParser;
|
||||
mSuggestions = suggestionParser.getSuggestions();
|
||||
|
@@ -77,19 +77,19 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
List<DashboardCategory> categories =
|
||||
((SettingsActivity) getActivity()).getDashboardCategories();
|
||||
mSummaryLoader = new SummaryLoader(getActivity(), categories);
|
||||
setHasOptionsMenu(true);
|
||||
if (DEBUG_TIMING) Log.d(TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
|
||||
+ " ms");
|
||||
Context context = getContext();
|
||||
mConditionManager = ConditionManager.get(context);
|
||||
mSuggestionParser = new SuggestionParser(context,
|
||||
context.getSharedPreferences(SUGGESTIONS, 0), R.xml.suggestion_ordering);
|
||||
if (DEBUG_TIMING) Log.d(TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
|
||||
+ " ms");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -108,17 +108,22 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
long startTime = System.currentTimeMillis();
|
||||
super.onResume();
|
||||
|
||||
((SettingsDrawerActivity) getActivity()).addCategoryListener(this);
|
||||
mSummaryLoader.setListening(true);
|
||||
for (Condition c : mConditionManager.getVisibleConditions()) {
|
||||
MetricsLogger.visible(getContext(), c.getMetricsConstant());
|
||||
for (Condition c : mConditionManager.getConditions()) {
|
||||
if (c.shouldShow()) {
|
||||
MetricsLogger.visible(getContext(), c.getMetricsConstant());
|
||||
}
|
||||
}
|
||||
for (Tile suggestion : mSuggestionParser.getSuggestions()) {
|
||||
for (Tile suggestion : mAdapter.getSuggestions()) {
|
||||
MetricsLogger.action(getContext(), MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
|
||||
DashboardAdapter.getSuggestionIdentifier(getContext(), suggestion));
|
||||
}
|
||||
if (DEBUG_TIMING) Log.d(TAG, "onResume took " + (System.currentTimeMillis() - startTime)
|
||||
+ " ms");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -127,10 +132,12 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
|
||||
((SettingsDrawerActivity) getActivity()).remCategoryListener(this);
|
||||
mSummaryLoader.setListening(false);
|
||||
for (Condition c : mConditionManager.getVisibleConditions()) {
|
||||
MetricsLogger.hidden(getContext(), c.getMetricsConstant());
|
||||
for (Condition c : mConditionManager.getConditions()) {
|
||||
if (c.shouldShow()) {
|
||||
MetricsLogger.hidden(getContext(), c.getMetricsConstant());
|
||||
}
|
||||
}
|
||||
for (Tile suggestion : mSuggestionParser.getSuggestions()) {
|
||||
for (Tile suggestion : mAdapter.getSuggestions()) {
|
||||
MetricsLogger.action(getContext(), MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION,
|
||||
DashboardAdapter.getSuggestionIdentifier(getContext(), suggestion));
|
||||
}
|
||||
@@ -138,12 +145,15 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasWindowFocus) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
if (hasWindowFocus) {
|
||||
mConditionManager.addListener(this);
|
||||
mConditionManager.refreshAll();
|
||||
} else {
|
||||
mConditionManager.remListener(this);
|
||||
}
|
||||
if (DEBUG_TIMING) Log.d(TAG, "onWindowFocusChanged took "
|
||||
+ (System.currentTimeMillis() - startTime) + " ms");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -161,6 +171,7 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle bundle) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
mDashboard = (FocusRecyclerView) view.findViewById(R.id.dashboard_container);
|
||||
mLayoutManager = new LinearLayoutManager(getContext());
|
||||
mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
||||
@@ -174,10 +185,11 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
mDashboard.addItemDecoration(new DashboardDecorator(getContext()));
|
||||
mAdapter = new DashboardAdapter(getContext());
|
||||
mAdapter.setConditions(mConditionManager.getConditions());
|
||||
mAdapter.setSuggestions(mSuggestionParser);
|
||||
mDashboard.setAdapter(mAdapter);
|
||||
mSummaryLoader.setAdapter(mAdapter);
|
||||
ConditionAdapterUtils.addDismiss(mDashboard);
|
||||
if (DEBUG_TIMING) Log.d(TAG, "onViewCreated took "
|
||||
+ (System.currentTimeMillis() - startTime) + " ms");
|
||||
|
||||
rebuildUI();
|
||||
}
|
||||
|
@@ -17,11 +17,8 @@ package com.android.settings.dashboard;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.*;
|
||||
import android.os.Process;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.Log;
|
||||
import com.android.settings.SettingsActivity;
|
||||
@@ -51,7 +48,7 @@ public class SummaryLoader {
|
||||
|
||||
public SummaryLoader(Activity activity, List<DashboardCategory> categories) {
|
||||
mHandler = new Handler();
|
||||
mWorkerThread = new HandlerThread("SummaryLoader");
|
||||
mWorkerThread = new HandlerThread("SummaryLoader", Process.THREAD_PRIORITY_BACKGROUND);
|
||||
mWorkerThread.start();
|
||||
mWorker = new Worker(mWorkerThread.getLooper());
|
||||
mActivity = activity;
|
||||
|
@@ -35,7 +35,8 @@ public abstract class Condition {
|
||||
private boolean mIsActive;
|
||||
private long mLastStateChange;
|
||||
|
||||
public Condition(ConditionManager manager) {
|
||||
// All conditions must live in this package.
|
||||
Condition(ConditionManager manager) {
|
||||
mManager = manager;
|
||||
}
|
||||
|
||||
@@ -45,10 +46,15 @@ public abstract class Condition {
|
||||
mLastStateChange = bundle.getLong(KEY_LAST_STATE);
|
||||
}
|
||||
|
||||
void saveState(PersistableBundle bundle) {
|
||||
bundle.putBoolean(KEY_SILENCE, mIsSilenced);
|
||||
bundle.putBoolean(KEY_ACTIVE, mIsActive);
|
||||
bundle.putLong(KEY_LAST_STATE, mLastStateChange);
|
||||
boolean saveState(PersistableBundle bundle) {
|
||||
if (mIsSilenced) {
|
||||
bundle.putBoolean(KEY_SILENCE, mIsSilenced);
|
||||
}
|
||||
if (mIsActive) {
|
||||
bundle.putBoolean(KEY_ACTIVE, mIsActive);
|
||||
bundle.putLong(KEY_LAST_STATE, mLastStateChange);
|
||||
}
|
||||
return mIsSilenced || mIsActive;
|
||||
}
|
||||
|
||||
protected void notifyChanged() {
|
||||
|
@@ -38,10 +38,12 @@ public class ConditionManager {
|
||||
|
||||
private static final boolean DEBUG = true;
|
||||
|
||||
private static final String PKG = "com.android.settings.dashboard.conditional.";
|
||||
|
||||
private static final String FILE_NAME = "condition_state.xml";
|
||||
private static final String TAG_CONDITIONS = "conditions";
|
||||
private static final String TAG_CONDITION = "condition";
|
||||
private static final String ATTR_CLASS = "class";
|
||||
private static final String TAG_CONDITIONS = "cs";
|
||||
private static final String TAG_CONDITION = "c";
|
||||
private static final String ATTR_CLASS = "cls";
|
||||
|
||||
private static ConditionManager sInstance;
|
||||
|
||||
@@ -80,6 +82,9 @@ public class ConditionManager {
|
||||
if (TAG_CONDITION.equals(parser.getName())) {
|
||||
int depth = parser.getDepth();
|
||||
String clz = parser.getAttributeValue("", ATTR_CLASS);
|
||||
if (!clz.startsWith(PKG)) {
|
||||
clz = PKG + clz;
|
||||
}
|
||||
Condition condition = createCondition(Class.forName(clz));
|
||||
PersistableBundle bundle = PersistableBundle.restoreFromXml(parser);
|
||||
if (DEBUG) Log.d(TAG, "Reading " + clz + " -- " + bundle);
|
||||
@@ -109,12 +114,14 @@ public class ConditionManager {
|
||||
|
||||
final int N = mConditions.size();
|
||||
for (int i = 0; i < N; i++) {
|
||||
serializer.startTag("", TAG_CONDITION);
|
||||
serializer.attribute("", ATTR_CLASS, mConditions.get(i).getClass().getName());
|
||||
PersistableBundle bundle = new PersistableBundle();
|
||||
mConditions.get(i).saveState(bundle);
|
||||
bundle.saveToXml(serializer);
|
||||
serializer.endTag("", TAG_CONDITION);
|
||||
if (mConditions.get(i).saveState(bundle)) {
|
||||
serializer.startTag("", TAG_CONDITION);
|
||||
final String clz = mConditions.get(i).getClass().getSimpleName();
|
||||
serializer.attribute("", ATTR_CLASS, clz);
|
||||
bundle.saveToXml(serializer);
|
||||
serializer.endTag("", TAG_CONDITION);
|
||||
}
|
||||
}
|
||||
|
||||
serializer.endTag("", TAG_CONDITIONS);
|
||||
@@ -133,6 +140,7 @@ public class ConditionManager {
|
||||
addIfMissing(CellularDataCondition.class);
|
||||
addIfMissing(BackgroundDataCondition.class);
|
||||
addIfMissing(WorkModeCondition.class);
|
||||
Collections.sort(mConditions, CONDITION_COMPARATOR);
|
||||
}
|
||||
|
||||
private void addIfMissing(Class<? extends Condition> clz) {
|
||||
@@ -187,12 +195,12 @@ public class ConditionManager {
|
||||
conditions.add(mConditions.get(i));
|
||||
}
|
||||
}
|
||||
Collections.sort(conditions, CONDITION_COMPARATOR);
|
||||
return conditions;
|
||||
}
|
||||
|
||||
public void notifyChanged(Condition condition) {
|
||||
saveToXml();
|
||||
Collections.sort(mConditions, CONDITION_COMPARATOR);
|
||||
final int N = mListeners.size();
|
||||
for (int i = 0; i < N; i++) {
|
||||
mListeners.get(i).onConditionsChanged();
|
||||
@@ -209,7 +217,7 @@ public class ConditionManager {
|
||||
|
||||
public static ConditionManager get(Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new ConditionManager(context);
|
||||
sInstance = new ConditionManager(context.getApplicationContext());
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
Reference in New Issue
Block a user