Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bf234afb authored by jeffreyhuang's avatar jeffreyhuang
Browse files

Speed up dev options

 - Put memory updates on background thread
 - Prevent update state from being called twice

Bug: 69000975
Test: Manual
Change-Id: I186bc25f6b74a5098b1737891efee3a6855dc996
parent e91f6ea3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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
+5 −3
Original line number Diff line number Diff line
@@ -87,10 +87,12 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
        // Set ComparisonCallback so we get better animation when list changes.
        getPreferenceManager().setPreferenceComparisonCallback(
                new PreferenceManager.SimplePreferenceComparisonCallback());
        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
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+14 −8
Original line number Diff line number Diff line
@@ -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) {
        // 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);
        mPreference.setSummary(mContext.getString(R.string.memory_summary,
                usedResult, totalResult));
            ThreadUtils.postOnMainThread(
                    () -> mPreference.setSummary(mContext.getString(R.string.memory_summary,
                            usedResult, totalResult)));
        });
    }

    @VisibleForTesting
+4 −0
Original line number Diff line number Diff line
@@ -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);