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

Commit cea37434 authored by Kenny Root's avatar Kenny Root
Browse files

Try to free cache before giving up on install

Try to get installd to free up cache before giving up when there is too
little space free.

Bug: 7232123
Change-Id: Ie3c8ca8dfc190abbb9a29a7baee31f32e9de7d69
parent a3e90798
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -36,4 +36,5 @@ interface IMediaContainerService {
    /** Return file system stats: [0] is total bytes, [1] is available bytes */
    long[] getFileSystemStats(in String path);
    void clearDirectory(in String directory);
    long calculateInstalledSize(in String packagePath, boolean isForwardLocked);
}
+15 −0
Original line number Diff line number Diff line
@@ -259,6 +259,21 @@ public class DefaultContainerService extends IntentService {
                eraseFiles(directory);
            }
        }

        @Override
        public long calculateInstalledSize(String packagePath, boolean isForwardLocked)
                throws RemoteException {
            final File packageFile = new File(packagePath);
            try {
                return calculateContainerSize(packageFile, isForwardLocked) * 1024 * 1024;
            } catch (IOException e) {
                /*
                 * Okay, something failed, so let's just estimate it to be 2x
                 * the file size. Note this will be 0 if the file doesn't exist.
                 */
                return packageFile.length() * 2;
            }
        }
    };

    public DefaultContainerService() {
+17 −2
Original line number Diff line number Diff line
@@ -6330,8 +6330,23 @@ public class PackageManagerService extends IPackageManager.Stub {

                    if (packageFile != null) {
                        // Remote call to find out default install location
                        pkgLite = mContainerService.getMinimalPackageInfo(
                                packageFile.getAbsolutePath(), flags, lowThreshold);
                        final String packageFilePath = packageFile.getAbsolutePath();
                        pkgLite = mContainerService.getMinimalPackageInfo(packageFilePath, flags,
                                lowThreshold);

                        /*
                         * If we have too little free space, try to free cache
                         * before giving up.
                         */
                        if (pkgLite.recommendedInstallLocation
                                == PackageHelper.RECOMMEND_FAILED_INSUFFICIENT_STORAGE) {
                            final long size = mContainerService.calculateInstalledSize(
                                    packageFilePath, isForwardLocked());
                            if (mInstaller.freeCache(size + lowThreshold) >= 0) {
                                pkgLite = mContainerService.getMinimalPackageInfo(packageFilePath,
                                        flags, lowThreshold);
                            }
                        }
                    }
                } finally {
                    mContext.revokeUriPermission(mPackageURI,