[G1 Android Development] Effdee:
think I know why

http://github.com/AndDiSa/GB-framew...oid/defcontainer/DefaultContainerService.java

I've added the bold

I haven't tried to compile it, so not 100% it will work

private int recommendAppInstallLocation(int installLocation,
String archiveFilePath, int flags) {
boolean checkInt = false;
boolean checkExt = false;
boolean checkSDExt = false;
boolean checkAll = false;
check_inner : {
// Check flags.
if ((flags & PackageManager.INSTALL_FORWARD_LOCK) != 0) {
// Check for forward locked app
checkInt = true;
checkSDExt = true;
break check_inner;
} else if ((flags & PackageManager.INSTALL_INTERNAL) != 0) {
// Explicit flag to install internally.
// Check internal storage and return
checkInt = true;
break check_inner;
} else if ((flags & PackageManager.INSTALL_EXTERNAL) != 0) {
// Explicit flag to install externally.
// Check external storage and return
checkExt = true;
break check_inner;
}
// Check for manifest option
[b]
int installPreference = Settings.System.getInt(getApplicationContext()
.getContentResolver(),
Settings.Secure.DEFAULT_INSTALL_LOCATION,
PackageHelper.APP_INSTALL_AUTO);
if ((installPreference == PackageHelper.APP_INSTALL_SDEXT) {
checkSDExt = true;
}
[/b]
if (installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY) {
checkInt = true;
break check_inner;
} else if (installLocation == PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL) {
checkExt = true;
checkAll = true;
break check_inner;
} else if (installLocation == PackageInfo.INSTALL_LOCATION_AUTO) {
checkInt = true;
checkAll = true;
break check_inner;
}
// Pick user preference
[b]// don't need this as we moved it higher up[/b]
[strike] int installPreference = Settings.System.getInt(getApplicationContext()
.getContentResolver(),
Settings.Secure.DEFAULT_INSTALL_LOCATION,
PackageHelper.APP_INSTALL_AUTO);[/strike]
if ((installPreference == PackageHelper.APP_INSTALL_SDEXT) &&
(android.os.Environment.IsSdExtMounted())) {
checkSDExt = true;
break check_inner;
} else if (installPreference == PackageHelper.APP_INSTALL_INTERNAL) {
checkInt = true;
break check_inner;
} else if (installPreference == PackageHelper.APP_INSTALL_EXTERNAL) {
checkExt = true;
break check_inner;
}
// Fall back to default policy if nothing else is specified.
checkInt = true;
}

// Package size = code size + cache size + data size
// If code size > 1 MB, install on SD card.
// Else install on internal NAND flash, unless space on NAND is less than 10%
String status = Environment.getExternalStorageState();
long availSDSize = -1;
boolean mediaAvailable = false;
if (status.equals(Environment.MEDIA_MOUNTED)) {
StatFs sdStats = new StatFs(
Environment.getExternalStorageDirectory().getPath());
availSDSize = (long)sdStats.getAvailableBlocks() *
(long)sdStats.getBlockSize();
mediaAvailable = true;
}
StatFs internalStats = new StatFs(Environment.getDataDirectory().getPath());
long totalInternalSize = (long)internalStats.getBlockCount() *
(long)internalStats.getBlockSize();
long availInternalSize = (long)internalStats.getAvailableBlocks() *
(long)internalStats.getBlockSize();

double pctNandFree = (double)availInternalSize / (double)totalInternalSize;

long availsdextSize = -1;
if (android.os.Environment.IsSdExtMounted()) {
StatFs sdextStats = new StatFs(Environment.getSdExtDirectory().getPath());
long totalsdextSize = (long)sdextStats.getBlockCount() *
(long)sdextStats.getBlockSize();
availsdextSize = (long)sdextStats.getAvailableBlocks() *
(long)sdextStats.getBlockSize();
}

File apkFile = new File(archiveFilePath);
long pkgLen = apkFile.length();

// To make final copy
long reqInstallSize = pkgLen;
// For dex files. Just ignore and fail when extracting. Max limit of 2Gig for now.
long reqInternalSize = 0;
boolean intThresholdOk = (pctNandFree >= LOW_NAND_FLASH_TRESHOLD);
boolean intAvailOk = ((reqInstallSize + reqInternalSize) < availInternalSize);
boolean fitsOnSDExt = ((reqInstallSize + reqInternalSize) < availsdextSize);
boolean fitsOnSd = false;
if (mediaAvailable && (reqInstallSize < availSDSize)) {
// If we do not have an internal size requirement
// don't do a threshold check.
if (reqInternalSize == 0) {
fitsOnSd = true;
} else if ((reqInternalSize < availInternalSize) && intThresholdOk) {
fitsOnSd = true;
}
}
boolean fitsOnInt = intThresholdOk && intAvailOk;
if (checkSDExt) {
if (fitsOnSDExt) {
return PackageHelper.RECOMMEND_INSTALL_SDEXT;
}
} else if (checkInt) {
// Check for internal memory availability
if (fitsOnInt) {
return PackageHelper.RECOMMEND_INSTALL_INTERNAL;
}
} else if (checkExt) {
if (fitsOnSd) {
return PackageHelper.RECOMMEND_INSTALL_EXTERNAL;
}
}
if (checkAll) {
// Check for internal first
if (fitsOnInt) {
return PackageHelper.RECOMMEND_INSTALL_INTERNAL;
}
// Check for sd-ext next
if (fitsOnSDExt) {
return PackageHelper.RECOMMEND_INSTALL_SDEXT;
}
// Check for external next
if (fitsOnSd) {
return PackageHelper.RECOMMEND_INSTALL_EXTERNAL;
}
}
if ((checkExt || checkAll || checkSDExt) && !mediaAvailable) {
return PackageHelper.RECOMMEND_MEDIA_UNAVAILABLE;
}
return PackageHelper.RECOMMEND_FAILED_INSUFFICIENT_STORAGE;
}

make DefaultContainerService

results in a tiny apk

just need to test it against apps which have the prefer int and auto flags set

amended as per hrk's sugestion

I also remove the mount check as this check is done when working out if sdext has space

availsdextSize will remain at -1 if sd-ext is not mounted

so fitsOnSDExt will be false

might be able to clean up a few more of those checks

BUT I think the mount check should stay if you are about to break out of check_inner