Merge "Speed up dev options"

This commit is contained in:
Jeffrey Huang
2017-11-15 18:01:07 +00:00
committed by Android (Google) Code Review
4 changed files with 24 additions and 12 deletions

View File

@@ -23,7 +23,7 @@
android:key="memory"
android:icon="@drawable/ic_settings_memory"
android:title="@string/memory_settings_title"
android:summary="@string/summary_empty"
android:summary="@string/summary_placeholder"
android:fragment="com.android.settings.applications.ProcessStatsSummary" />
<com.android.settings.BugreportPreference

View File

@@ -87,9 +87,11 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
// Set ComparisonCallback so we get better animation when list changes.
getPreferenceManager().setPreferenceComparisonCallback(
new PreferenceManager.SimplePreferenceComparisonCallback());
// Upon rotation configuration change we need to update preference states before any
// editing dialog is recreated (that would happen before onResume is called).
updatePreferenceStates();
if (icicle != null) {
// Upon rotation configuration change we need to update preference states before any
// editing dialog is recreated (that would happen before onResume is called).
updatePreferenceStates();
}
}
@Override

View File

@@ -27,6 +27,7 @@ import com.android.settings.applications.ProcStatsData;
import com.android.settings.applications.ProcessStatsBase;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
import com.android.settingslib.utils.ThreadUtils;
public class MemoryUsagePreferenceController extends DeveloperOptionsPreferenceController implements
PreferenceControllerMixin {
@@ -56,14 +57,19 @@ public class MemoryUsagePreferenceController extends DeveloperOptionsPreferenceC
@Override
public void updateState(Preference preference) {
mProcStatsData.refreshStats(true);
final ProcStatsData.MemInfo memInfo = mProcStatsData.getMemInfo();
final String usedResult = Formatter.formatShortFileSize(mContext,
(long) memInfo.realUsedRam);
final String totalResult = Formatter.formatShortFileSize(mContext,
(long) memInfo.realTotalRam);
mPreference.setSummary(mContext.getString(R.string.memory_summary,
usedResult, totalResult));
// This is posted on the background thread to speed up fragment launch time for dev options
// mProcStasData.refreshStats(true) takes ~20ms to run.
ThreadUtils.postOnBackgroundThread(() -> {
mProcStatsData.refreshStats(true);
final ProcStatsData.MemInfo memInfo = mProcStatsData.getMemInfo();
final String usedResult = Formatter.formatShortFileSize(mContext,
(long) memInfo.realUsedRam);
final String totalResult = Formatter.formatShortFileSize(mContext,
(long) memInfo.realTotalRam);
ThreadUtils.postOnMainThread(
() -> mPreference.setSummary(mContext.getString(R.string.memory_summary,
usedResult, totalResult)));
});
}
@VisibleForTesting

View File

@@ -30,6 +30,7 @@ import android.support.v7.preference.PreferenceScreen;
import com.android.settings.TestConfig;
import com.android.settings.applications.ProcStatsData;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowThreadUtils;
import org.junit.Before;
import org.junit.Test;
@@ -68,6 +69,9 @@ public class MemoryUsagePreferenceControllerTest {
}
@Test
@Config(shadows = {
ShadowThreadUtils.class
})
public void updateState_shouldUpdatePreferenceSummary() {
mController.updateState(mPreference);