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

Commit 50bac1a9 authored by Christopher R. Palmer's avatar Christopher R. Palmer Committed by Steve Kondik
Browse files

Storage; Fix apps2sd for noemulated secondary storage

A recent commit:

  commit 9d0514d8
  Author: Thomas Wendt <thoemy@gmx.net>
  Date:   Wed Jan 14 16:18:19 2015 +0100

    Storage: Fix moving apps to external storag

changed the supported case from secondary storage that was marked
as noemulated to external storage that was noemulated.

Both are valid use-cases for apps2sd.

This commit restores the secondary storage logic removed in
the previous commit and allows either configuration to work
for apps2sd.

Change-Id: I069571dfe10c6e8e2247b26f3de0d185ba10d5a2
parent f768e862
Loading
Loading
Loading
Loading
+19 −5
Original line number Diff line number Diff line
@@ -377,7 +377,8 @@ public class PackageHelper {
            checkBoth = false;
        }

        final boolean emulated = Environment.isExternalStorageEmulated();
        final boolean externalIsEmulated = Environment.isExternalStorageEmulated();
        final boolean noemulated = Environment.isNoEmulatedStorageExist();
        final StorageManager storage = StorageManager.from(context);

        boolean fitsOnInternal = false;
@@ -387,7 +388,7 @@ public class PackageHelper {
        }

        boolean fitsOnExternal = false;
        if (!emulated && (checkBoth || prefer == RECOMMEND_INSTALL_EXTERNAL)) {
        if (!externalIsEmulated && (checkBoth || prefer == RECOMMEND_INSTALL_EXTERNAL)) {
            final File target = new UserEnvironment(UserHandle.USER_OWNER)
                    .getExternalStorageDirectory();
            // External is only an option when size is known
@@ -396,11 +397,21 @@ public class PackageHelper {
            }
        }

        if (noemulated && (checkBoth || prefer == RECOMMEND_INSTALL_EXTERNAL)) {
            final File target = new UserEnvironment(UserHandle.USER_OWNER)
                     .getSecondaryStorageDirectory();
            // External is only an option when size is known
            if (sizeBytes > 0) {
                fitsOnExternal = fitsOnExternal |
                    (sizeBytes <= storage.getStorageBytesUntilLow(target));
            }
        }

        if (prefer == RECOMMEND_INSTALL_INTERNAL) {
            if (fitsOnInternal) {
                return PackageHelper.RECOMMEND_INSTALL_INTERNAL;
            }
        } else if (!emulated && prefer == RECOMMEND_INSTALL_EXTERNAL) {
        } else if (prefer == RECOMMEND_INSTALL_EXTERNAL) {
            if (fitsOnExternal) {
                return PackageHelper.RECOMMEND_INSTALL_EXTERNAL;
            }
@@ -409,7 +420,7 @@ public class PackageHelper {
        if (checkBoth) {
            if (fitsOnInternal) {
                return PackageHelper.RECOMMEND_INSTALL_INTERNAL;
            } else if (!emulated && fitsOnExternal) {
            } else if (fitsOnExternal) {
                return PackageHelper.RECOMMEND_INSTALL_EXTERNAL;
            }
        }
@@ -419,9 +430,12 @@ public class PackageHelper {
         * the media was unavailable. Otherwise, indicate there was insufficient
         * storage space available.
         */
        if (!emulated && (checkBoth || prefer == RECOMMEND_INSTALL_EXTERNAL)
        if (!externalIsEmulated && (checkBoth || prefer == RECOMMEND_INSTALL_EXTERNAL)
                && !Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
            return PackageHelper.RECOMMEND_MEDIA_UNAVAILABLE;
        } else if (noemulated && (checkBoth || prefer == RECOMMEND_INSTALL_EXTERNAL)
                && !Environment.MEDIA_MOUNTED.equals(Environment.getSecondaryStorageState())) {
            return PackageHelper.RECOMMEND_MEDIA_UNAVAILABLE;
        } else {
            return PackageHelper.RECOMMEND_FAILED_INSUFFICIENT_STORAGE;
        }