Improve Settings launch performance

From traces analysis, we found getFreeBytes
was taking a long time to return.

getFreeBytes was used when storage controller
tried to get storage information.

In order to prevent this case, we put the action
which takes too much time in background thread.

Test: I can't reproduce it locally. From code view,
this is a reasonable root cause.
Fixes: 136268875

Change-Id: I78e42cde88553c003f198cffb5747b352055f59a
(cherry picked from commit 0c37f019f61f37b67e2297e99d96e8396d962f40)
diff --git a/src/com/android/settings/deviceinfo/TopLevelStoragePreferenceController.java b/src/com/android/settings/deviceinfo/TopLevelStoragePreferenceController.java
index c6fc23b..fdc5feb 100644
--- a/src/com/android/settings/deviceinfo/TopLevelStoragePreferenceController.java
+++ b/src/com/android/settings/deviceinfo/TopLevelStoragePreferenceController.java
@@ -20,10 +20,13 @@
 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 @@
     }
 
     @Override
-    public CharSequence getSummary() {
-        // TODO: Register listener.
-        final NumberFormat percentageFormat = NumberFormat.getPercentInstance();
-        final PrivateStorageInfo info = PrivateStorageInfo.getPrivateStorageInfo(
-                mStorageManagerVolumeProvider);
-        double privateUsedBytes = info.totalBytes - info.freeBytes;
-        return mContext.getString(R.string.storage_summary,
-                percentageFormat.format(privateUsedBytes / info.totalBytes),
-                Formatter.formatFileSize(mContext, info.freeBytes));
+    protected void refreshSummary(Preference preference) {
+        if (preference == null) {
+            return;
+        }
+
+        ThreadUtils.postOnBackgroundThread(() -> {
+            final NumberFormat percentageFormat = NumberFormat.getPercentInstance();
+            final PrivateStorageInfo info = PrivateStorageInfo.getPrivateStorageInfo(
+                    mStorageManagerVolumeProvider);
+            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)));
+            });
+        });
     }
 }