Merge "Fail upgrades that change storage devices." into nyc-dev am: 1fdeb5bdf7

am: bd92d3c267

* commit 'bd92d3c26722e4a435e1c46364cddb27a222df7d':
  Fail upgrades that change storage devices.

Change-Id: Id9e9becd2a18bdeff760fd1b940465388f906d1c
This commit is contained in:
Jeff Sharkey
2016-05-11 01:10:07 +00:00
committed by android-build-merger

View File

@@ -37,7 +37,6 @@ import android.os.storage.VolumeInfo;
import android.provider.Settings; import android.provider.Settings;
import android.util.ArraySet; import android.util.ArraySet;
import android.util.Log; import android.util.Log;
import android.util.Slog;
import libcore.io.IoUtils; import libcore.io.IoUtils;
@@ -46,6 +45,7 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Collections; import java.util.Collections;
import java.util.Objects;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
@@ -383,23 +383,31 @@ public class PackageHelper {
installLocation = PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY; installLocation = PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY;
} }
// If app expresses strong desire for internal space, honor it // If app expresses strong desire for internal storage, honor it
if (!forceAllowOnExternal if (!forceAllowOnExternal
&& installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY) { && installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY) {
if (existingInfo != null && !Objects.equals(existingInfo.volumeUuid,
StorageManager.UUID_PRIVATE_INTERNAL)) {
throw new IOException("Cannot automatically move " + packageName + " from "
+ existingInfo.volumeUuid + " to internal storage");
}
if (fitsOnInternal) { if (fitsOnInternal) {
return null; return StorageManager.UUID_PRIVATE_INTERNAL;
} else { } else {
throw new IOException("Requested internal only, but not enough space"); throw new IOException("Requested internal only, but not enough space");
} }
} }
// If app already exists somewhere, prefer to stay on that volume // If app already exists somewhere, we must stay on that volume
if (existingInfo != null) { if (existingInfo != null) {
if (existingInfo.volumeUuid == null && fitsOnInternal) { if (Objects.equals(existingInfo.volumeUuid, StorageManager.UUID_PRIVATE_INTERNAL)
return null; && fitsOnInternal) {
} return StorageManager.UUID_PRIVATE_INTERNAL;
if (allCandidates.contains(existingInfo.volumeUuid)) { } else if (allCandidates.contains(existingInfo.volumeUuid)) {
return existingInfo.volumeUuid; return existingInfo.volumeUuid;
} else {
throw new IOException("Not enough space on existing volume "
+ existingInfo.volumeUuid + " for " + packageName + " upgrade");
} }
} }
@@ -408,7 +416,7 @@ public class PackageHelper {
if (bestCandidate != null) { if (bestCandidate != null) {
return bestCandidate.fsUuid; return bestCandidate.fsUuid;
} else if (fitsOnInternal) { } else if (fitsOnInternal) {
return null; return StorageManager.UUID_PRIVATE_INTERNAL;
} else { } else {
throw new IOException("No special requests, but no room anywhere"); throw new IOException("No special requests, but no room anywhere");
} }