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:key="memory"
|
||||||
android:icon="@drawable/ic_settings_memory"
|
android:icon="@drawable/ic_settings_memory"
|
||||||
android:title="@string/memory_settings_title"
|
android:title="@string/memory_settings_title"
|
||||||
android:summary="@string/summary_empty"
|
android:summary="@string/summary_placeholder"
|
||||||
android:fragment="com.android.settings.applications.ProcessStatsSummary" />
|
android:fragment="com.android.settings.applications.ProcessStatsSummary" />
|
||||||
|
|
||||||
<com.android.settings.BugreportPreference
|
<com.android.settings.BugreportPreference
|
||||||
|
@@ -87,9 +87,11 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
|||||||
// Set ComparisonCallback so we get better animation when list changes.
|
// Set ComparisonCallback so we get better animation when list changes.
|
||||||
getPreferenceManager().setPreferenceComparisonCallback(
|
getPreferenceManager().setPreferenceComparisonCallback(
|
||||||
new PreferenceManager.SimplePreferenceComparisonCallback());
|
new PreferenceManager.SimplePreferenceComparisonCallback());
|
||||||
// Upon rotation configuration change we need to update preference states before any
|
if (icicle != null) {
|
||||||
// editing dialog is recreated (that would happen before onResume is called).
|
// Upon rotation configuration change we need to update preference states before any
|
||||||
updatePreferenceStates();
|
// editing dialog is recreated (that would happen before onResume is called).
|
||||||
|
updatePreferenceStates();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -27,6 +27,7 @@ import com.android.settings.applications.ProcStatsData;
|
|||||||
import com.android.settings.applications.ProcessStatsBase;
|
import com.android.settings.applications.ProcessStatsBase;
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
|
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
|
||||||
|
import com.android.settingslib.utils.ThreadUtils;
|
||||||
|
|
||||||
public class MemoryUsagePreferenceController extends DeveloperOptionsPreferenceController implements
|
public class MemoryUsagePreferenceController extends DeveloperOptionsPreferenceController implements
|
||||||
PreferenceControllerMixin {
|
PreferenceControllerMixin {
|
||||||
@@ -56,14 +57,19 @@ public class MemoryUsagePreferenceController extends DeveloperOptionsPreferenceC
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
mProcStatsData.refreshStats(true);
|
// This is posted on the background thread to speed up fragment launch time for dev options
|
||||||
final ProcStatsData.MemInfo memInfo = mProcStatsData.getMemInfo();
|
// mProcStasData.refreshStats(true) takes ~20ms to run.
|
||||||
final String usedResult = Formatter.formatShortFileSize(mContext,
|
ThreadUtils.postOnBackgroundThread(() -> {
|
||||||
(long) memInfo.realUsedRam);
|
mProcStatsData.refreshStats(true);
|
||||||
final String totalResult = Formatter.formatShortFileSize(mContext,
|
final ProcStatsData.MemInfo memInfo = mProcStatsData.getMemInfo();
|
||||||
(long) memInfo.realTotalRam);
|
final String usedResult = Formatter.formatShortFileSize(mContext,
|
||||||
mPreference.setSummary(mContext.getString(R.string.memory_summary,
|
(long) memInfo.realUsedRam);
|
||||||
usedResult, totalResult));
|
final String totalResult = Formatter.formatShortFileSize(mContext,
|
||||||
|
(long) memInfo.realTotalRam);
|
||||||
|
ThreadUtils.postOnMainThread(
|
||||||
|
() -> mPreference.setSummary(mContext.getString(R.string.memory_summary,
|
||||||
|
usedResult, totalResult)));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
@@ -30,6 +30,7 @@ import android.support.v7.preference.PreferenceScreen;
|
|||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.applications.ProcStatsData;
|
import com.android.settings.applications.ProcStatsData;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
import com.android.settings.testutils.shadow.ShadowThreadUtils;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -68,6 +69,9 @@ public class MemoryUsagePreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Config(shadows = {
|
||||||
|
ShadowThreadUtils.class
|
||||||
|
})
|
||||||
public void updateState_shouldUpdatePreferenceSummary() {
|
public void updateState_shouldUpdatePreferenceSummary() {
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user