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

Commit 6ed24847 authored by tmfang's avatar tmfang Committed by android-build-merger
Browse files

Improve Settings launch performance am: 496d3f6f

am: 49d575b9

Change-Id: I544556c17a56dd1e36efded7ae565fa7d97fa8ba
parents c8334b20 49d575b9
Loading
Loading
Loading
Loading
+20 −9
Original line number Diff line number Diff line
@@ -20,10 +20,13 @@ import android.content.Context;
import android.os.storage.StorageManager;
import android.text.format.Formatter;

import androidx.preference.Preference;

import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.deviceinfo.PrivateStorageInfo;
import com.android.settingslib.deviceinfo.StorageManagerVolumeProvider;
import com.android.settingslib.utils.ThreadUtils;

import java.text.NumberFormat;

@@ -44,14 +47,22 @@ public class TopLevelStoragePreferenceController extends BasePreferenceControlle
    }

    @Override
    public CharSequence getSummary() {
        // TODO: Register listener.
    protected void refreshSummary(Preference preference) {
        if (preference == null) {
            return;
        }

        ThreadUtils.postOnBackgroundThread(() -> {
            final NumberFormat percentageFormat = NumberFormat.getPercentInstance();
            final PrivateStorageInfo info = PrivateStorageInfo.getPrivateStorageInfo(
                    mStorageManagerVolumeProvider);
        double privateUsedBytes = info.totalBytes - info.freeBytes;
        return mContext.getString(R.string.storage_summary,
            final double privateUsedBytes = info.totalBytes - info.freeBytes;

            ThreadUtils.postOnMainThread(() -> {
                preference.setSummary(mContext.getString(R.string.storage_summary,
                        percentageFormat.format(privateUsedBytes / info.totalBytes),
                Formatter.formatFileSize(mContext, info.freeBytes));
                        Formatter.formatFileSize(mContext, info.freeBytes)));
            });
        });
    }
}