Skip to content

Commit cea3743

Browse files
committed
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
1 parent a3e9079 commit cea3743

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

core/java/com/android/internal/app/IMediaContainerService.aidl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ interface IMediaContainerService {
3636
/** Return file system stats: [0] is total bytes, [1] is available bytes */
3737
long[] getFileSystemStats(in String path);
3838
void clearDirectory(in String directory);
39+
long calculateInstalledSize(in String packagePath, boolean isForwardLocked);
3940
}

packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,21 @@ public void clearDirectory(String path) throws RemoteException {
259259
eraseFiles(directory);
260260
}
261261
}
262+
263+
@Override
264+
public long calculateInstalledSize(String packagePath, boolean isForwardLocked)
265+
throws RemoteException {
266+
final File packageFile = new File(packagePath);
267+
try {
268+
return calculateContainerSize(packageFile, isForwardLocked) * 1024 * 1024;
269+
} catch (IOException e) {
270+
/*
271+
* Okay, something failed, so let's just estimate it to be 2x
272+
* the file size. Note this will be 0 if the file doesn't exist.
273+
*/
274+
return packageFile.length() * 2;
275+
}
276+
}
262277
};
263278

264279
public DefaultContainerService() {

services/java/com/android/server/pm/PackageManagerService.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6330,8 +6330,23 @@ public void handleStartCopy() throws RemoteException {
63306330

63316331
if (packageFile != null) {
63326332
// Remote call to find out default install location
6333-
pkgLite = mContainerService.getMinimalPackageInfo(
6334-
packageFile.getAbsolutePath(), flags, lowThreshold);
6333+
final String packageFilePath = packageFile.getAbsolutePath();
6334+
pkgLite = mContainerService.getMinimalPackageInfo(packageFilePath, flags,
6335+
lowThreshold);
6336+
6337+
/*
6338+
* If we have too little free space, try to free cache
6339+
* before giving up.
6340+
*/
6341+
if (pkgLite.recommendedInstallLocation
6342+
== PackageHelper.RECOMMEND_FAILED_INSUFFICIENT_STORAGE) {
6343+
final long size = mContainerService.calculateInstalledSize(
6344+
packageFilePath, isForwardLocked());
6345+
if (mInstaller.freeCache(size + lowThreshold) >= 0) {
6346+
pkgLite = mContainerService.getMinimalPackageInfo(packageFilePath,
6347+
flags, lowThreshold);
6348+
}
6349+
}
63356350
}
63366351
} finally {
63376352
mContext.revokeUriPermission(mPackageURI,

0 commit comments

Comments
 (0)