summaryrefslogtreecommitdiffstats
path: root/src/com/android/packageinstaller
diff options
context:
space:
mode:
authorSuchi Amalapurapu <asuchitra@google.com>2010-03-11 10:54:44 -0800
committerSuchi Amalapurapu <asuchitra@google.com>2010-03-11 14:29:54 -0800
commit9ab50f3655afed4f9266402a03d3235d94220397 (patch)
treea0755e70e683d841fee32be90d94636cfc9b038c /src/com/android/packageinstaller
parentdc7d3d29d2d058e795ab7650a611027d981e4a71 (diff)
downloadandroid_packages_apps_PackageInstaller-9ab50f3655afed4f9266402a03d3235d94220397.tar.gz
android_packages_apps_PackageInstaller-9ab50f3655afed4f9266402a03d3235d94220397.tar.bz2
android_packages_apps_PackageInstaller-9ab50f3655afed4f9266402a03d3235d94220397.zip
Remove memory checks in side loading ui
Move dialog for insufficient storage as a post-install error handle dialog Change-Id: I419b1dc233e01fc91e29d1274bae17d5bd63a60d
Diffstat (limited to 'src/com/android/packageinstaller')
-rwxr-xr-xsrc/com/android/packageinstaller/InstallAppProgress.java65
-rw-r--r--src/com/android/packageinstaller/PackageInstallerActivity.java91
-rw-r--r--src/com/android/packageinstaller/PackageUtil.java57
3 files changed, 97 insertions, 116 deletions
diff --git a/src/com/android/packageinstaller/InstallAppProgress.java b/src/com/android/packageinstaller/InstallAppProgress.java
index 3fe69321..859ccfac 100755
--- a/src/com/android/packageinstaller/InstallAppProgress.java
+++ b/src/com/android/packageinstaller/InstallAppProgress.java
@@ -19,7 +19,11 @@ package com.android.packageinstaller;
import com.android.packageinstaller.R;
import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.DialogInterface;
import android.content.Intent;
+import android.content.DialogInterface.OnCancelListener;
import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageInstallObserver;
import android.content.pm.PackageInfo;
@@ -39,10 +43,6 @@ 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;
import java.util.List;
/**
@@ -53,7 +53,7 @@ import java.util.List;
* codes defined in PackageManager. If the package being installed already exists,
* the existing package is replaced with the new one.
*/
-public class InstallAppProgress extends Activity implements View.OnClickListener {
+public class InstallAppProgress extends Activity implements View.OnClickListener, OnCancelListener {
private final String TAG="InstallAppProgress";
private boolean localLOGV = false;
private ApplicationInfo mAppInfo;
@@ -63,10 +63,10 @@ public class InstallAppProgress extends Activity implements View.OnClickListener
private TextView mStatusTextView;
private Button mDoneButton;
private Button mLaunchButton;
- final static int SUCCEEDED = 1;
- final static int FAILED = 0;
private final int INSTALL_COMPLETE = 1;
private Intent mLaunchIntent;
+ private static final int DLG_OUT_OF_SPACE = 1;
+ private CharSequence mLabel;
private Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
@@ -77,7 +77,7 @@ public class InstallAppProgress extends Activity implements View.OnClickListener
// Show the ok button
int centerTextLabel;
Drawable centerTextDrawable = null;
- if(msg.arg1 == SUCCEEDED) {
+ if(msg.arg1 == PackageManager.INSTALL_SUCCEEDED) {
mLaunchButton.setVisibility(View.VISIBLE);
centerTextDrawable = getResources().getDrawable(R.drawable.button_indicator_finish);
centerTextLabel = R.string.install_done;
@@ -97,7 +97,11 @@ public class InstallAppProgress extends Activity implements View.OnClickListener
} else {
mLaunchButton.setEnabled(false);
}
+ } else if (msg.arg1 == PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE){
+ showDialogInner(DLG_OUT_OF_SPACE);
+ return;
} else {
+ // Generic error handling for all other error codes.
centerTextDrawable = Resources.getSystem().getDrawable(
com.android.internal.R.drawable.ic_bullet_key_permission);
centerTextLabel = R.string.install_failed;
@@ -127,7 +131,40 @@ public class InstallAppProgress extends Activity implements View.OnClickListener
mPackageURI = intent.getData();
initView();
}
-
+
+ @Override
+ public Dialog onCreateDialog(int id, Bundle bundle) {
+ switch (id) {
+ case DLG_OUT_OF_SPACE:
+ String dlgText = getString(R.string.out_of_space_dlg_text, mLabel);
+ return new AlertDialog.Builder(this)
+ .setTitle(R.string.out_of_space_dlg_title)
+ .setMessage(dlgText)
+ .setPositiveButton(R.string.manage_applications, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ //launch manage applications
+ Intent intent = new Intent("android.intent.action.MANAGE_PACKAGE_STORAGE");
+ startActivity(intent);
+ finish();
+ }
+ })
+ .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ Log.i(TAG, "Canceling installation");
+ finish();
+ }
+ })
+ .setOnCancelListener(this)
+ .create();
+ }
+ return null;
+ }
+
+ private void showDialogInner(int id) {
+ removeDialog(id);
+ showDialog(id);
+ }
+
class PackageInstallObserver extends IPackageInstallObserver.Stub {
public void packageInstalled(String packageName, int returnCode) {
Message msg = mHandler.obtainMessage(INSTALL_COMPLETE);
@@ -152,8 +189,10 @@ public class InstallAppProgress extends Activity implements View.OnClickListener
if((installFlags & PackageManager.INSTALL_REPLACE_EXISTING )!= 0) {
Log.w(TAG, "Replacing package:" + mAppInfo.packageName);
}
- PackageUtil.initSnippetForNewApp(this, mAppInfo,
- R.id.app_snippet, mPackageURI);
+ PackageUtil.AppSnippet as = PackageUtil.getAppSnippet(this, mAppInfo,
+ mPackageURI);
+ mLabel = as.label;
+ PackageUtil.initSnippetForNewApp(this, as, R.id.app_snippet);
mStatusTextView = (TextView)findViewById(R.id.center_text);
mStatusTextView.setText(R.string.installing);
mProgressBar = (ProgressBar) findViewById(R.id.progress_bar);
@@ -186,4 +225,8 @@ public class InstallAppProgress extends Activity implements View.OnClickListener
finish();
}
}
+
+ public void onCancel(DialogInterface dialog) {
+ finish();
+ }
}
diff --git a/src/com/android/packageinstaller/PackageInstallerActivity.java b/src/com/android/packageinstaller/PackageInstallerActivity.java
index 483feb90..96c1b160 100644
--- a/src/com/android/packageinstaller/PackageInstallerActivity.java
+++ b/src/com/android/packageinstaller/PackageInstallerActivity.java
@@ -18,28 +18,18 @@ package com.android.packageinstaller;
import com.android.packageinstaller.R;
-import java.io.File;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
-import android.app.PendingIntent;
-import android.content.BroadcastReceiver;
-import android.content.Context;
import android.content.DialogInterface;
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;
@@ -64,14 +54,7 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen
private Uri mPackageURI;
private boolean localLOGV = false;
PackageManager mPm;
- private boolean mReplacing = false;
private PackageParser.Package mPkgInfo;
- private static final int SUCCEEDED = 1;
- private static final int FAILED = 0;
- // Broadcast receiver for clearing cache
- ClearCacheReceiver mClearCacheReceiver = null;
- private static final int HANDLER_BASE_MSG_IDX = 0;
- private static final int FREE_SPACE = HANDLER_BASE_MSG_IDX + 1;
// ApplicationInfo object primarily used for already existing applications
private ApplicationInfo mAppInfo = null;
@@ -90,25 +73,6 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen
private static final int DLG_OUT_OF_SPACE = DLG_BASE + 4;
private static final int DLG_INSTALL_ERROR = DLG_BASE + 5;
- private Handler mHandler = new Handler() {
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case FREE_SPACE:
- if (mClearCacheReceiver != null) {
- unregisterReceiver(mClearCacheReceiver);
- }
- if(msg.arg1 == SUCCEEDED) {
- initiateInstall();
- } else {
- showDialogInner(DLG_OUT_OF_SPACE);
- }
- break;
- default:
- break;
- }
- }
- };
-
private void startInstallConfirm() {
LinearLayout permsSection = (LinearLayout) mInstallConfirm.findViewById(R.id.permissions_section);
LinearLayout securityList = (LinearLayout) permsSection.findViewById(
@@ -138,7 +102,7 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen
}
@Override
- public Dialog onCreateDialog(int id) {
+ public Dialog onCreateDialog(int id, Bundle bundle) {
switch (id) {
case DLG_REPLACE_APP:
int msgId = R.string.dlg_app_replacement_statement;
@@ -151,7 +115,6 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
startInstallConfirm();
- mReplacing = true;
}})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
@@ -232,45 +195,6 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen
return null;
}
- private class ClearCacheReceiver extends BroadcastReceiver {
- public static final String INTENT_CLEAR_CACHE =
- "com.android.packageinstaller.CLEAR_CACHE";
- @Override
- public void onReceive(Context context, Intent intent) {
- 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 (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);
- }
- }
-
private void launchSettingsAppAndFinish() {
//Create an intent to launch SettingsTwo activity
Intent launchSettingsIntent = new Intent(Settings.ACTION_APPLICATION_SETTINGS);
@@ -321,21 +245,16 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen
setContentView(R.layout.install_start);
mInstallConfirm = findViewById(R.id.install_confirm_panel);
mInstallConfirm.setVisibility(View.INVISIBLE);
- PackageUtil.initSnippetForNewApp(this, mPkgInfo.applicationInfo,
- R.id.app_snippet, mPackageURI);
+ PackageUtil.AppSnippet as = PackageUtil.getAppSnippet(this,
+ mPkgInfo.applicationInfo, mPackageURI);
+ PackageUtil.initSnippetForNewApp(this, as, R.id.app_snippet);
//check setting
if(!isInstallingUnknownAppsAllowed()) {
//ask user to enable setting first
showDialogInner(DLG_UNKNOWN_APPS);
return;
}
- //compute the size of the application. just an estimate
- long size;
- String apkPath = mPackageURI.getPath();
- File apkFile = new File(apkPath);
- //TODO? DEVISE BETTER HEAURISTIC
- size = 1*apkFile.length();
- checkOutOfSpace(size);
+ initiateInstall();
}
// Generic handling when pressing back key
diff --git a/src/com/android/packageinstaller/PackageUtil.java b/src/com/android/packageinstaller/PackageUtil.java
index 3d40f7de..45c42890 100644
--- a/src/com/android/packageinstaller/PackageUtil.java
+++ b/src/com/android/packageinstaller/PackageUtil.java
@@ -115,9 +115,44 @@ public class PackageUtil {
* @param appInfo ApplicationInfo object of package whose resources are to be loaded
* @param snippetId view id of app snippet view
*/
- public static View initSnippetForNewApp(Activity pContext, ApplicationInfo appInfo,
- int snippetId, Uri packageURI) {
+ public static View initSnippetForNewApp(Activity pContext, AppSnippet as,
+ int snippetId) {
View appSnippet = pContext.findViewById(snippetId);
+ ((ImageView)appSnippet.findViewById(R.id.app_icon)).setImageDrawable(as.icon);
+ ((TextView)appSnippet.findViewById(R.id.app_name)).setText(as.label);
+ return appSnippet;
+ }
+
+ public static boolean isPackageAlreadyInstalled(Activity context, String pkgName) {
+ List<PackageInfo> installedList = context.getPackageManager().getInstalledPackages(
+ PackageManager.GET_UNINSTALLED_PACKAGES);
+ int installedListSize = installedList.size();
+ for(int i = 0; i < installedListSize; i++) {
+ PackageInfo tmp = installedList.get(i);
+ if(pkgName.equalsIgnoreCase(tmp.packageName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ static public class AppSnippet {
+ CharSequence label;
+ Drawable icon;
+ public AppSnippet(CharSequence label, Drawable icon) {
+ this.label = label;
+ this.icon = icon;
+ }
+ }
+ /*
+ * Utility method to load application label
+ *
+ * @param pContext context of package that can load the resources
+ * @param appInfo ApplicationInfo object of package whose resources are to be loaded
+ * @param snippetId view id of app snippet view
+ */
+ public static AppSnippet getAppSnippet(Activity pContext, ApplicationInfo appInfo,
+ Uri packageURI) {
final String archiveFilePath = packageURI.getPath();
Resources pRes = pContext.getResources();
AssetManager assmgr = new AssetManager();
@@ -148,22 +183,6 @@ public class PackageUtil {
if (icon == null) {
icon = pContext.getPackageManager().getDefaultActivityIcon();
}
- ((ImageView)appSnippet.findViewById(R.id.app_icon)).setImageDrawable(icon);
- ((TextView)appSnippet.findViewById(R.id.app_name)).setText(label);
- return appSnippet;
- }
-
- public static boolean isPackageAlreadyInstalled(Activity context, String pkgName) {
- List<PackageInfo> installedList = context.getPackageManager().getInstalledPackages(
- PackageManager.GET_UNINSTALLED_PACKAGES);
- int installedListSize = installedList.size();
- for(int i = 0; i < installedListSize; i++) {
- PackageInfo tmp = installedList.get(i);
- if(pkgName.equalsIgnoreCase(tmp.packageName)) {
- return true;
- }
-
- }
- return false;
+ return new PackageUtil.AppSnippet(label, icon);
}
}