summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSuchi Amalapurapu <asuchitra@google.com>2010-02-19 10:59:21 -0800
committerSuchi Amalapurapu <asuchitra@google.com>2010-02-19 11:02:44 -0800
commit3d07f28761d467664ea97a7be7cbedf92762f14c (patch)
treefaa95289bf52de0c27590fec897b6d2d57c9e2de
parent7cdf9b3362df82fbfea24d559329109b8ed0b46f (diff)
downloadandroid_packages_apps_PackageInstaller-3d07f28761d467664ea97a7be7cbedf92762f14c.zip
android_packages_apps_PackageInstaller-3d07f28761d467664ea97a7be7cbedf92762f14c.tar.gz
android_packages_apps_PackageInstaller-3d07f28761d467664ea97a7be7cbedf92762f14c.tar.bz2
Nuke parser references.
Modify free storage logic.
-rw-r--r--src/com/android/packageinstaller/PackageInstallerActivity.java45
-rw-r--r--src/com/android/packageinstaller/PackageUtil.java6
2 files changed, 37 insertions, 14 deletions
diff --git a/src/com/android/packageinstaller/PackageInstallerActivity.java b/src/com/android/packageinstaller/PackageInstallerActivity.java
index a945a54..483feb9 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 5b31062..3d40f7d 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;
}
/*