Merge "Speed up dev options"
This commit is contained in:
committed by
Android (Google) Code Review
commit
e50254dce0
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user