From 3d07f28761d467664ea97a7be7cbedf92762f14c Mon Sep 17 00:00:00 2001 From: Suchi Amalapurapu Date: Fri, 19 Feb 2010 10:59:21 -0800 Subject: Nuke parser references. Modify free storage logic. --- .../packageinstaller/PackageInstallerActivity.java | 45 +++++++++++++++------- src/com/android/packageinstaller/PackageUtil.java | 6 ++- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/com/android/packageinstaller/PackageInstallerActivity.java b/src/com/android/packageinstaller/PackageInstallerActivity.java index a945a548..483feb90 100644 --- a/src/com/android/packageinstaller/PackageInstallerActivity.java +++ b/src/com/android/packageinstaller/PackageInstallerActivity.java @@ -30,13 +30,16 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.DialogInterface.OnCancelListener; import android.content.pm.ApplicationInfo; +import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageParser; import android.content.pm.PackageManager.NameNotFoundException; import android.net.Uri; import android.os.Bundle; +import android.os.Environment; import android.os.Handler; import android.os.Message; +import android.os.StatFs; import android.provider.Settings; import android.util.Log; import android.view.View; @@ -95,7 +98,7 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen unregisterReceiver(mClearCacheReceiver); } if(msg.arg1 == SUCCEEDED) { - makeTempCopyAndInstall(); + initiateInstall(); } else { showDialogInner(DLG_OUT_OF_SPACE); } @@ -234,22 +237,38 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen "com.android.packageinstaller.CLEAR_CACHE"; @Override public void onReceive(Context context, Intent intent) { - Message msg = mHandler.obtainMessage(FREE_SPACE); - msg.arg1 = (getResultCode() ==1) ? SUCCEEDED : FAILED; - mHandler.sendMessage(msg); + sendFreeSpaceMessage(getResultCode()); } } + + private void sendFreeSpaceMessage(int resultCode) { + Message msg = mHandler.obtainMessage(FREE_SPACE); + msg.arg1 = (resultCode == 1) ? SUCCEEDED : FAILED; + mHandler.sendMessage(msg); + } private void checkOutOfSpace(long size) { - if(localLOGV) Log.i(TAG, "Checking for "+size+" number of bytes"); - if (mClearCacheReceiver == null) { - mClearCacheReceiver = new ClearCacheReceiver(); + if (mPkgInfo.installLocation != PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL) { + if(localLOGV) Log.i(TAG, "Checking for "+size+" number of bytes"); + if (mClearCacheReceiver == null) { + mClearCacheReceiver = new ClearCacheReceiver(); + } + registerReceiver(mClearCacheReceiver, + new IntentFilter(ClearCacheReceiver.INTENT_CLEAR_CACHE)); + PendingIntent pi = PendingIntent.getBroadcast(this, + 0, new Intent(ClearCacheReceiver.INTENT_CLEAR_CACHE), 0); + mPm.freeStorage(size, pi.getIntentSender()); + } else { + StatFs sdcardStats = new StatFs(Environment.getExternalStorageDirectory().getPath()); + long availSDSize = (long)sdcardStats.getAvailableBlocks() * + (long)sdcardStats.getBlockSize(); + int resultCode = 1; + if (size >= availSDSize) { + resultCode = 0; + } + // Send message right away. TODO do statfs on sdcard + sendFreeSpaceMessage(resultCode); } - registerReceiver(mClearCacheReceiver, - new IntentFilter(ClearCacheReceiver.INTENT_CLEAR_CACHE)); - PendingIntent pi = PendingIntent.getBroadcast(this, - 0, new Intent(ClearCacheReceiver.INTENT_CLEAR_CACHE), 0); - mPm.freeStorage(size, pi.getIntentSender()); } private void launchSettingsAppAndFinish() { @@ -264,7 +283,7 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen Settings.Secure.INSTALL_NON_MARKET_APPS, 0) > 0; } - private void makeTempCopyAndInstall() { + private void initiateInstall() { // Check if package is already installed. display confirmation dialog if replacing pkg try { mAppInfo = mPm.getApplicationInfo(mPkgInfo.packageName, diff --git a/src/com/android/packageinstaller/PackageUtil.java b/src/com/android/packageinstaller/PackageUtil.java index 5b31062c..3d40f7de 100644 --- a/src/com/android/packageinstaller/PackageUtil.java +++ b/src/com/android/packageinstaller/PackageUtil.java @@ -76,7 +76,11 @@ public class PackageUtil { File sourceFile = new File(archiveFilePath); DisplayMetrics metrics = new DisplayMetrics(); metrics.setToDefaults(); - return packageParser.parsePackage(sourceFile, archiveFilePath, metrics, 0); + PackageParser.Package pkg = packageParser.parsePackage(sourceFile, + archiveFilePath, metrics, 0); + // Nuke the parser reference. + packageParser = null; + return pkg; } /* -- cgit v1.2.3