Always unbind/delete incremental instances when remove packages.
Bug: 160635296 Test: atest PackageManagerShellCommandTest PackageManagerShellCommandIncrementalTest IncrementalServiceTest PackageManagerServiceTest ChecksumsTest Change-Id: Ie0aea11d906dccad892d6962b71afa62b44c6378
This commit is contained in:
@@ -25,6 +25,7 @@ import android.content.pm.DataLoaderParams;
|
||||
import android.content.pm.IPackageLoadingProgressCallback;
|
||||
import android.os.RemoteCallbackList;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Slog;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
@@ -285,7 +286,7 @@ public final class IncrementalManager {
|
||||
* Unbinds the target dir and deletes the corresponding storage instance.
|
||||
* Deletes the package name and associated storage id from maps.
|
||||
*/
|
||||
public void onPackageRemoved(@NonNull File codeFile) {
|
||||
public void rmPackageDir(@NonNull File codeFile) {
|
||||
try {
|
||||
final String codePath = codeFile.getAbsolutePath();
|
||||
final IncrementalStorage storage = openStorage(codePath);
|
||||
@@ -294,11 +295,9 @@ public final class IncrementalManager {
|
||||
}
|
||||
mLoadingProgressCallbacks.cleanUpCallbacks(storage);
|
||||
unregisterHealthListener(codePath);
|
||||
|
||||
// Parent since we bind-mount a folder one level above.
|
||||
mService.deleteBindMount(storage.getId(), codeFile.getParent());
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
storage.unBind(codePath);
|
||||
} catch (IOException e) {
|
||||
Slog.w(TAG, "Failed to remove code path", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4132,6 +4132,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
|
||||
}
|
||||
|
||||
private void destroyInternal() {
|
||||
final IncrementalFileStorages incrementalFileStorages;
|
||||
synchronized (mLock) {
|
||||
mSealed = true;
|
||||
if (!params.isStaged) {
|
||||
@@ -4144,16 +4145,17 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
|
||||
for (FileBridge bridge : mBridges) {
|
||||
bridge.forceClose();
|
||||
}
|
||||
if (mIncrementalFileStorages != null) {
|
||||
mIncrementalFileStorages.cleanUp();
|
||||
mIncrementalFileStorages = null;
|
||||
}
|
||||
incrementalFileStorages = mIncrementalFileStorages;
|
||||
mIncrementalFileStorages = null;
|
||||
}
|
||||
// For staged sessions, we don't delete the directory where the packages have been copied,
|
||||
// since these packages are supposed to be read on reboot.
|
||||
// Those dirs are deleted when the staged session has reached a final state.
|
||||
if (stageDir != null && !params.isStaged) {
|
||||
try {
|
||||
if (incrementalFileStorages != null) {
|
||||
incrementalFileStorages.cleanUp();
|
||||
}
|
||||
mPm.mInstaller.rmPackageDir(stageDir.getAbsolutePath());
|
||||
} catch (InstallerException ignored) {
|
||||
}
|
||||
@@ -4171,13 +4173,15 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
|
||||
}
|
||||
|
||||
private void cleanStageDir() {
|
||||
final IncrementalFileStorages incrementalFileStorages;
|
||||
synchronized (mLock) {
|
||||
if (mIncrementalFileStorages != null) {
|
||||
mIncrementalFileStorages.cleanUp();
|
||||
mIncrementalFileStorages = null;
|
||||
}
|
||||
incrementalFileStorages = mIncrementalFileStorages;
|
||||
mIncrementalFileStorages = null;
|
||||
}
|
||||
try {
|
||||
if (incrementalFileStorages != null) {
|
||||
incrementalFileStorages.cleanUp();
|
||||
}
|
||||
mPm.mInstaller.rmPackageDir(stageDir.getAbsolutePath());
|
||||
} catch (InstallerException ignored) {
|
||||
}
|
||||
|
||||
@@ -12580,10 +12580,21 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
@GuardedBy("mInstallLock")
|
||||
void removeCodePathLI(File codePath) {
|
||||
if (codePath.isDirectory()) {
|
||||
File codePathParent = codePath.getParentFile();
|
||||
final File codePathParent = codePath.getParentFile();
|
||||
final boolean needRemoveParent = codePathParent.getName().startsWith(RANDOM_DIR_PREFIX);
|
||||
try {
|
||||
final boolean isIncremental = (mIncrementalManager != null && isIncrementalPath(
|
||||
codePath.getAbsolutePath()));
|
||||
if (isIncremental) {
|
||||
if (needRemoveParent) {
|
||||
mIncrementalManager.rmPackageDir(codePathParent);
|
||||
} else {
|
||||
mIncrementalManager.rmPackageDir(codePath);
|
||||
}
|
||||
}
|
||||
|
||||
mInstaller.rmPackageDir(codePath.getAbsolutePath());
|
||||
if (codePathParent.getName().startsWith(RANDOM_DIR_PREFIX)) {
|
||||
if (needRemoveParent) {
|
||||
mInstaller.rmPackageDir(codePathParent.getAbsolutePath());
|
||||
removeCachedResult(codePathParent);
|
||||
}
|
||||
@@ -18126,16 +18137,7 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
if (codeFile == null || !codeFile.exists()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final boolean isIncremental = (mIncrementalManager != null && isIncrementalPath(
|
||||
codeFile.getAbsolutePath()));
|
||||
|
||||
removeCodePathLI(codeFile);
|
||||
|
||||
if (isIncremental) {
|
||||
mIncrementalManager.onPackageRemoved(codeFile);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -24776,7 +24778,7 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
final int fileToDeleteCount = filesToDelete.size();
|
||||
for (int i = 0; i < fileToDeleteCount; i++) {
|
||||
File fileToDelete = filesToDelete.get(i);
|
||||
logCriticalInfo(Log.WARN, "Destroying orphaned" + fileToDelete);
|
||||
logCriticalInfo(Log.WARN, "Destroying orphaned at " + fileToDelete);
|
||||
synchronized (mInstallLock) {
|
||||
removeCodePathLI(fileToDelete);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user