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

Commit 552e3c4d authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Android (Google) Code Review
Browse files

Merge "Consistent "low storage" behavior." into oc-dev

parents 53553368 77fe8c1e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -131,7 +131,7 @@ public class StorageDashboardFragment extends DashboardFragment
            }
        }

        mPreferenceController.onLoadFinished(mAppsResult.get(UserHandle.myUserId()));
        mPreferenceController.onLoadFinished(mAppsResult, UserHandle.myUserId());
        updateSecondaryUserControllers(mSecondaryUsers, mAppsResult);

        // setLoading always causes a flicker, so let's avoid doing it.
+2 −1
Original line number Diff line number Diff line
@@ -120,7 +120,8 @@ public class StorageProfileFragment extends DashboardFragment
    @Override
    public void onLoadFinished(Loader<SparseArray<AppsStorageResult>> loader,
            SparseArray<AppsStorageResult> result) {
        mPreferenceController.onLoadFinished(scrubAppsFromResult(result.get(mUserId)));
        scrubAppsFromResult(result.get(mUserId));
        mPreferenceController.onLoadFinished(result, mUserId);
    }

    @Override
+16 −19
Original line number Diff line number Diff line
@@ -22,8 +22,8 @@ import static android.content.pm.ApplicationInfo.CATEGORY_VIDEO;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.UserInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.UserInfo;
import android.os.UserHandle;
import android.util.Log;
import android.util.SparseArray;
@@ -87,45 +87,43 @@ public class StorageAsyncLoader
                stats = mStatsManager.getStatsForPackage(mUuid, app.packageName, myUser);
            } catch (NameNotFoundException | IOException e) {
                // This may happen if the package was removed during our calculation.
                Log.w("App unexpectedly not found", e);
                Log.w(TAG, "App unexpectedly not found", e);
                continue;
            }

            long attributedAppSizeInBytes = stats.getDataBytes();
            // This matches how the package manager calculates sizes -- by zeroing out code sizes of
            // system apps which are not updated. My initial tests suggest that this results in the
            // original code size being counted for updated system apps when they shouldn't, but
            // I am not sure how to avoid this problem without specifically going in to find that
            // code size.
            if (!app.isSystemApp() || app.isUpdatedSystemApp()) {
                attributedAppSizeInBytes += stats.getCodeBytes();
            } else {
                result.systemSize += stats.getCodeBytes();
            long blamedSize = stats.getDataBytes() - stats.getCacheBytes();

            // Only count app code against the current user; we don't want
            // double-counting on multi-user devices.
            if (userId == UserHandle.myUserId()) {
                blamedSize += stats.getCodeBytes();
            }

            switch (app.category) {
                case CATEGORY_GAME:
                    result.gamesSize += attributedAppSizeInBytes;
                    result.gamesSize += blamedSize;
                    break;
                case CATEGORY_AUDIO:
                    result.musicAppsSize += attributedAppSizeInBytes;
                    result.musicAppsSize += blamedSize;
                    break;
                case CATEGORY_VIDEO:
                    result.videoAppsSize += attributedAppSizeInBytes;
                    result.videoAppsSize += blamedSize;
                    break;
                default:
                    // The deprecated game flag does not set the category.
                    if ((app.flags & ApplicationInfo.FLAG_IS_GAME) != 0) {
                        result.gamesSize += attributedAppSizeInBytes;
                        result.gamesSize += blamedSize;
                        break;
                    }
                    result.otherAppsSize += attributedAppSizeInBytes;
                    result.otherAppsSize += blamedSize;
                    break;
            }
        }

        Log.d(TAG, "Loading external stats");
        try {
            result.externalStats = mStatsManager.getExternalStorageStats(mUuid, UserHandle.of(userId));
            result.externalStats = mStatsManager.getExternalStorageStats(mUuid,
                    UserHandle.of(userId));
        } catch (IOException e) {
            Log.w(TAG, e);
        }
@@ -142,7 +140,6 @@ public class StorageAsyncLoader
        public long musicAppsSize;
        public long videoAppsSize;
        public long otherAppsSize;
        public long systemSize;
        public StorageStatsSource.ExternalStorageStats externalStats;
    }

+25 −13
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.net.TrafficStats;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.storage.VolumeInfo;
@@ -30,6 +31,7 @@ import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.util.Log;
import android.util.SparseArray;

import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
@@ -237,7 +239,10 @@ public class StorageItemPreferenceController extends PreferenceController {
        setFilesPreferenceVisibility();
    }

    public void onLoadFinished(StorageAsyncLoader.AppsStorageResult data) {
    public void onLoadFinished(SparseArray<StorageAsyncLoader.AppsStorageResult> result,
            int userId) {
        final StorageAsyncLoader.AppsStorageResult data = result.get(userId);

        // TODO(b/35927909): Figure out how to split out apps which are only installed for work
        //       profiles in order to attribute those app's code bytes only to that profile.
        mPhotoPreference.setStorageSize(
@@ -248,23 +253,30 @@ public class StorageItemPreferenceController extends PreferenceController {
        mMoviesPreference.setStorageSize(data.videoAppsSize, mTotalSize);
        mAppPreference.setStorageSize(data.otherAppsSize, mTotalSize);

        long unattributedExternalBytes =
        long otherExternalBytes =
                data.externalStats.totalBytes
                        - data.externalStats.audioBytes
                        - data.externalStats.videoBytes
                        - data.externalStats.imageBytes;
        mFilePreference.setStorageSize(unattributedExternalBytes, mTotalSize);
                        - data.externalStats.imageBytes
                        - data.externalStats.appBytes;
        mFilePreference.setStorageSize(otherExternalBytes, mTotalSize);

        // We define the system size as everything we can't classify.
        if (mSystemPreference != null) {
            mSystemPreference.setStorageSize(
                    mUsedBytes
                            - data.externalStats.totalBytes
                            - data.musicAppsSize
                            - data.gamesSize
                            - data.videoAppsSize
                            - data.otherAppsSize,
                    mTotalSize);
            // Everything else that hasn't already been attributed is tracked as
            // belonging to system.
            long attributedSize = 0;
            for (int i = 0; i < result.size(); i++) {
                final StorageAsyncLoader.AppsStorageResult otherData = result.valueAt(i);
                attributedSize += otherData.gamesSize
                        + otherData.musicAppsSize
                        + otherData.videoAppsSize
                        + otherData.otherAppsSize;
                attributedSize += otherData.externalStats.totalBytes
                        - otherData.externalStats.appBytes;
            }

            final long systemSize = Math.max(TrafficStats.GB_IN_BYTES, mUsedBytes - attributedSize);
            mSystemPreference.setStorageSize(systemSize, mTotalSize);
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -83,7 +83,7 @@ public class MusicViewHolderControllerTest {
    @Test
    public void storageShouldRepresentStorageStatsQuery() throws Exception {
        when(mSource.getExternalStorageStats(any(String.class), any(UserHandle.class))).thenReturn(
                new StorageStatsSource.ExternalStorageStats(1, 1, 0, 0));
                new StorageStatsSource.ExternalStorageStats(1, 1, 0, 0, 0));

        mController.queryStats();
        mController.setupView(mHolder);
Loading