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

Commit a5e0fedb authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Revert "Adds a section for unaccounted data."" into nyc-mr1-dev

parents 03f206a2 952a0d9f
Loading
Loading
Loading
Loading
+29 −58
Original line number Original line Diff line number Diff line
@@ -79,7 +79,6 @@ public class StorageMeasurement {
    public static class MeasurementDetails {
    public static class MeasurementDetails {
        public long totalSize;
        public long totalSize;
        public long availSize;
        public long availSize;
        private long accountedSize;


        /**
        /**
         * Total apps disk usage per profiles of the current user.
         * Total apps disk usage per profiles of the current user.
@@ -127,17 +126,6 @@ public class StorageMeasurement {
         * internal storage. Key is {@link UserHandle}.
         * internal storage. Key is {@link UserHandle}.
         */
         */
        public SparseLongArray usersSize = new SparseLongArray();
        public SparseLongArray usersSize = new SparseLongArray();

        /**
         * Gets the total disk usage that is not accounted for.
         *
         * <p>
         * Typically used by device-specific processes that the Framework has no control over.
         */
        public long getUnaccountedSize() {
            final long usedSize = totalSize - availSize;
            return usedSize - accountedSize;
        }
    }
    }


    public interface MeasurementReceiver {
    public interface MeasurementReceiver {
@@ -231,9 +219,6 @@ public class StorageMeasurement {
        }
        }


        private void addStatsLocked(PackageStats stats) {
        private void addStatsLocked(PackageStats stats) {
            synchronized (mDetails) {
                long accountedAppSize = 0;
                long accountedCacheSize = 0;
            if (mIsPrivate) {
            if (mIsPrivate) {
                long codeSize = stats.codeSize;
                long codeSize = stats.codeSize;
                long dataSize = stats.dataSize;
                long dataSize = stats.dataSize;
@@ -245,29 +230,23 @@ public class StorageMeasurement {
                    dataSize += stats.externalDataSize + stats.externalMediaSize;
                    dataSize += stats.externalDataSize + stats.externalMediaSize;
                    cacheSize += stats.externalCacheSize;
                    cacheSize += stats.externalCacheSize;
                }
                }
                    accountedAppSize += dataSize;

                // Count code and data for current user's profiles (keys prepared in constructor)
                // Count code and data for current user's profiles (keys prepared in constructor)
                    if (addValueIfKeyExists(mDetails.appsSize, stats.userHandle,
                addValueIfKeyExists(mDetails.appsSize, stats.userHandle, codeSize + dataSize);
                            codeSize + dataSize)) {

                        // Code is only counted once for the current user
                        accountedAppSize += codeSize;
                    }
                // User summary only includes data (code is only counted once
                // User summary only includes data (code is only counted once
                // for the current user)
                // for the current user)
                addValue(mDetails.usersSize, stats.userHandle, dataSize);
                addValue(mDetails.usersSize, stats.userHandle, dataSize);


                // Include cache for all users
                // Include cache for all users
                    accountedCacheSize = cacheSize;
                mDetails.cacheSize += cacheSize;


            } else {
            } else {
                // Physical storage; only count external sizes
                // Physical storage; only count external sizes
                addValue(mDetails.appsSize, mCurrentUser,
                addValue(mDetails.appsSize, mCurrentUser,
                        stats.externalCodeSize + stats.externalDataSize
                        stats.externalCodeSize + stats.externalDataSize
                        + stats.externalMediaSize + stats.externalObbSize);
                        + stats.externalMediaSize + stats.externalObbSize);
                    accountedCacheSize = stats.externalCacheSize;
                mDetails.cacheSize += stats.externalCacheSize;
                }
                mDetails.cacheSize += accountedCacheSize;
                mDetails.accountedSize += accountedAppSize + accountedCacheSize;
            }
            }
        }
        }
    }
    }
@@ -396,14 +375,11 @@ public class StorageMeasurement {
                for (String type : sMeasureMediaTypes) {
                for (String type : sMeasureMediaTypes) {
                    final File path = new File(basePath, type);
                    final File path = new File(basePath, type);
                    final long size = getDirectorySize(imcs, path);
                    final long size = getDirectorySize(imcs, path);
                    details.accountedSize += size;
                    mediaMap.put(type, size);
                    mediaMap.put(type, size);
                }
                }


                // Measure misc files not counted under media
                // Measure misc files not counted under media
                final long miscSize = measureMisc(imcs, basePath);
                addValue(details.miscSize, userId, measureMisc(imcs, basePath));
                details.accountedSize += miscSize;
                addValue(details.miscSize, userId, miscSize);
            }
            }


            if (mSharedVolume.getType() == VolumeInfo.TYPE_EMULATED) {
            if (mSharedVolume.getType() == VolumeInfo.TYPE_EMULATED) {
@@ -412,9 +388,6 @@ public class StorageMeasurement {
                for (UserInfo user : users) {
                for (UserInfo user : users) {
                    final File userPath = mSharedVolume.getPathForUser(user.id);
                    final File userPath = mSharedVolume.getPathForUser(user.id);
                    final long size = getDirectorySize(imcs, userPath);
                    final long size = getDirectorySize(imcs, userPath);
                    if (user.id != UserHandle.USER_SYSTEM) {
                        details.accountedSize += size;
                    }
                    addValue(details.usersSize, user.id, size);
                    addValue(details.usersSize, user.id, size);
                }
                }
            }
            }
@@ -495,12 +468,10 @@ public class StorageMeasurement {
        array.put(key, array.get(key) + value);
        array.put(key, array.get(key) + value);
    }
    }


    private static boolean addValueIfKeyExists(SparseLongArray array, int key, long value) {
    private static void addValueIfKeyExists(SparseLongArray array, int key, long value) {
        final int index = array.indexOfKey(key);
        final int index = array.indexOfKey(key);
        if (index >= 0) {
        if (index >= 0) {
            array.put(key, array.valueAt(index) + value);
            array.put(key, array.valueAt(index) + value);
            return true;
        }
        }
        return false;
    }
    }
}
}