summaryrefslogtreecommitdiffstats
path: root/src/com/android/packageinstaller/InstallAppProgress.java
diff options
context:
space:
mode:
authorSuchi Amalapurapu <asuchitra@google.com>2009-11-12 13:45:18 -0800
committerSuchi Amalapurapu <asuchitra@google.com>2009-11-12 14:50:19 -0800
commitf80cb7b8632fb2cab44838ee741b3e8fa4aa90b1 (patch)
treee531702cc70d5c197034cacaf83ca192f96a9e9a /src/com/android/packageinstaller/InstallAppProgress.java
parentf075068817434dbb5e861d00f5ed23d6405ab4d9 (diff)
downloadandroid_packages_apps_PackageInstaller-f80cb7b8632fb2cab44838ee741b3e8fa4aa90b1.tar.gz
android_packages_apps_PackageInstaller-f80cb7b8632fb2cab44838ee741b3e8fa4aa90b1.tar.bz2
android_packages_apps_PackageInstaller-f80cb7b8632fb2cab44838ee741b3e8fa4aa90b1.zip
move creating temp file to InstallAppProgress
and deal with cleanly deleting the file
Diffstat (limited to 'src/com/android/packageinstaller/InstallAppProgress.java')
-rwxr-xr-xsrc/com/android/packageinstaller/InstallAppProgress.java62
1 files changed, 61 insertions, 1 deletions
diff --git a/src/com/android/packageinstaller/InstallAppProgress.java b/src/com/android/packageinstaller/InstallAppProgress.java
index 0bd38023..43de6ded 100755
--- a/src/com/android/packageinstaller/InstallAppProgress.java
+++ b/src/com/android/packageinstaller/InstallAppProgress.java
@@ -29,6 +29,7 @@ import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
+import android.os.FileUtils;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
@@ -38,6 +39,11 @@ import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
/**
* This activity corresponds to a download progress screen that is displayed
* when the user tries
@@ -60,6 +66,9 @@ public class InstallAppProgress extends Activity implements View.OnClickListener
final static int FAILED = 0;
private final int INSTALL_COMPLETE = 1;
private Intent mLaunchIntent;
+ private File mTmpFile;
+ private final String TMP_FILE_NAME="tmpCopy.apk";
+
private Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
@@ -152,6 +161,15 @@ public class InstallAppProgress extends Activity implements View.OnClickListener
mLaunchButton = (Button)findViewById(R.id.launch_button);
mOkPanel.setVisibility(View.INVISIBLE);
+ // Create temp file before invoking install api
+ mTmpFile = createTempPackageFile(mPackageURI.getPath());
+ if (mTmpFile == null) {
+ Message msg = mHandler.obtainMessage(INSTALL_COMPLETE);
+ msg.arg1 = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
+ mHandler.sendMessage(msg);
+ return;
+ }
+ mPackageURI = Uri.parse("file://" + mTmpFile.getPath());
String installerPackageName = getIntent().getStringExtra(
Intent.EXTRA_INSTALLER_PACKAGE_NAME);
@@ -159,13 +177,55 @@ public class InstallAppProgress extends Activity implements View.OnClickListener
pm.installPackage(mPackageURI, observer, installFlags, installerPackageName);
}
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ if (mTmpFile != null && mTmpFile.exists()) {
+ mTmpFile.delete();
+ }
+ }
+
public void onClick(View v) {
if(v == mDoneButton) {
- Log.i(TAG, "Finished installing "+mAppInfo);
+ if (mAppInfo.packageName != null) {
+ Log.i(TAG, "Finished installing "+mAppInfo.packageName);
+ }
finish();
} else if(v == mLaunchButton) {
startActivity(mLaunchIntent);
finish();
}
}
+
+ private File createTempPackageFile(String filePath) {
+ File tmpPackageFile = getFileStreamPath(TMP_FILE_NAME);
+ if (tmpPackageFile == null) {
+ Log.w(TAG, "Failed to create temp file");
+ return null;
+ }
+ if (tmpPackageFile.exists()) {
+ tmpPackageFile.delete();
+ }
+ // Open file to make it world readable
+ FileOutputStream fos;
+ try {
+ fos = openFileOutput(TMP_FILE_NAME, MODE_WORLD_READABLE);
+ } catch (FileNotFoundException e1) {
+ Log.e(TAG, "Error opening file " + TMP_FILE_NAME);
+ return null;
+ }
+ try {
+ fos.close();
+ } catch (IOException e) {
+ Log.e(TAG, "Error opening file " + TMP_FILE_NAME);
+ return null;
+ }
+
+ File srcPackageFile = new File(filePath);
+ if (!FileUtils.copyFile(srcPackageFile, tmpPackageFile)) {
+ Log.w(TAG, "Failed to make copy of file: " + srcPackageFile);
+ return null;
+ }
+ return tmpPackageFile;
+ }
}