Disable uninstall button when move is in progress.

Handle onActivityResult in ManageApplications when a package has been
uninstalled.

Change-Id: I4c4a8a54f9743f89949f47e21c1e143ac08ca2c3
This commit is contained in:
Suchi Amalapurapu
2010-03-22 15:21:34 -07:00
parent 28bcb47ef7
commit de03ac27b7
2 changed files with 61 additions and 42 deletions

View File

@@ -68,6 +68,7 @@ public class InstalledAppDetails extends Activity implements View.OnClickListene
private static final int _UNKNOWN_APP=R.string.unknown; private static final int _UNKNOWN_APP=R.string.unknown;
private ApplicationInfo mAppInfo; private ApplicationInfo mAppInfo;
private Button mUninstallButton; private Button mUninstallButton;
private boolean mMoveInProgress = false;
private boolean mUpdatedSysApp = false; private boolean mUpdatedSysApp = false;
private Button mActivitiesButton; private Button mActivitiesButton;
private boolean localLOGV = false; private boolean localLOGV = false;
@@ -187,7 +188,6 @@ public class InstalledAppDetails extends Activity implements View.OnClickListene
mClearDataButton.setText(R.string.clear_user_data_text); mClearDataButton.setText(R.string.clear_user_data_text);
} }
mClearDataButton.setOnClickListener(this); mClearDataButton.setOnClickListener(this);
initMoveButton();
} }
private CharSequence getMoveErrMsg(int errCode) { private CharSequence getMoveErrMsg(int errCode) {
@@ -244,7 +244,7 @@ public class InstalledAppDetails extends Activity implements View.OnClickListene
} }
} }
private void initControlButtons() { private void initUninstallButtons() {
mUpdatedSysApp = (mAppInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0; mUpdatedSysApp = (mAppInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0;
boolean enabled = true; boolean enabled = true;
if (mUpdatedSysApp) { if (mUpdatedSysApp) {
@@ -262,6 +262,17 @@ public class InstalledAppDetails extends Activity implements View.OnClickListene
} }
} }
private void initAppInfo(String packageName) {
try {
mAppInfo = mPm.getApplicationInfo(packageName,
PackageManager.GET_UNINSTALLED_PACKAGES);
} catch (NameNotFoundException e) {
Log.e(TAG, "Exception when retrieving package: " + packageName, e);
showDialogInner(DLG_APP_NOT_FOUND);
return;
}
}
/** Called when the activity is first created. */ /** Called when the activity is first created. */
@Override @Override
protected void onCreate(Bundle icicle) { protected void onCreate(Bundle icicle) {
@@ -277,14 +288,7 @@ public class InstalledAppDetails extends Activity implements View.OnClickListene
totalSizeStr = appSizeStr = dataSizeStr = mComputingStr; totalSizeStr = appSizeStr = dataSizeStr = mComputingStr;
if(localLOGV) Log.i(TAG, "Have to compute package sizes"); if(localLOGV) Log.i(TAG, "Have to compute package sizes");
mSizeObserver = new PkgSizeObserver(); mSizeObserver = new PkgSizeObserver();
try { initAppInfo(packageName);
mAppInfo = mPm.getApplicationInfo(packageName,
PackageManager.GET_UNINSTALLED_PACKAGES);
} catch (NameNotFoundException e) {
Log.e(TAG, "Exception when retrieving package:"+packageName, e);
showDialogInner(DLG_APP_NOT_FOUND);
return;
}
setContentView(R.layout.installed_app_details); setContentView(R.layout.installed_app_details);
//TODO download str and download url //TODO download str and download url
// Set default values on sizes // Set default values on sizes
@@ -300,7 +304,6 @@ public class InstalledAppDetails extends Activity implements View.OnClickListene
mForceStopButton.setText(R.string.force_stop); mForceStopButton.setText(R.string.force_stop);
mUninstallButton = (Button)btnPanel.findViewById(R.id.right_button); mUninstallButton = (Button)btnPanel.findViewById(R.id.right_button);
mForceStopButton.setEnabled(false); mForceStopButton.setEnabled(false);
initControlButtons();
// Initialize clear data and move install location buttons // Initialize clear data and move install location buttons
View data_buttons_panel = findViewById(R.id.data_buttons_panel); View data_buttons_panel = findViewById(R.id.data_buttons_panel);
mClearDataButton = (Button) data_buttons_panel.findViewById(R.id.left_button); mClearDataButton = (Button) data_buttons_panel.findViewById(R.id.left_button);
@@ -341,16 +344,6 @@ public class InstalledAppDetails extends Activity implements View.OnClickListene
} }
} }
private void refreshAppAttributes(PackageInfo pkgInfo) {
setAppLabelAndIcon(pkgInfo);
initControlButtons();
initDataButtons();
// Refresh size info
if (mAppInfo != null && mAppInfo.packageName != null) {
mPm.getPackageSizeInfo(mAppInfo.packageName, mSizeObserver);
}
}
// Utility method to set applicaiton label and icon. // Utility method to set applicaiton label and icon.
private void setAppLabelAndIcon(PackageInfo pkgInfo) { private void setAppLabelAndIcon(PackageInfo pkgInfo) {
View appSnippet = findViewById(R.id.app_snippet); View appSnippet = findViewById(R.id.app_snippet);
@@ -374,11 +367,10 @@ public class InstalledAppDetails extends Activity implements View.OnClickListene
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
PackageInfo pkgInfo; initAppInfo(mAppInfo.packageName);
PackageInfo pkgInfo = null;
// Get application info again to refresh changed properties of application // Get application info again to refresh changed properties of application
try { try {
mAppInfo = mPm.getApplicationInfo(mAppInfo.packageName,
PackageManager.GET_UNINSTALLED_PACKAGES);
pkgInfo = mPm.getPackageInfo(mAppInfo.packageName, pkgInfo = mPm.getPackageInfo(mAppInfo.packageName,
PackageManager.GET_UNINSTALLED_PACKAGES); PackageManager.GET_UNINSTALLED_PACKAGES);
} catch (NameNotFoundException e) { } catch (NameNotFoundException e) {
@@ -387,7 +379,12 @@ public class InstalledAppDetails extends Activity implements View.OnClickListene
return; return;
} }
checkForceStop(); checkForceStop();
refreshAppAttributes(pkgInfo); setAppLabelAndIcon(pkgInfo);
refreshButtons();
// Refresh size info
if (mAppInfo != null && mAppInfo.packageName != null) {
mPm.getPackageSizeInfo(mAppInfo.packageName, mSizeObserver);
}
} }
private void setIntentAndFinish(boolean finish, boolean appChanged) { private void setIntentAndFinish(boolean finish, boolean appChanged) {
@@ -473,23 +470,31 @@ public class InstalledAppDetails extends Activity implements View.OnClickListene
} }
} }
private void refreshButtons() {
if (!mMoveInProgress) {
// Refresh application information again.
initAppInfo(mAppInfo.packageName);
initUninstallButtons();
initDataButtons();
initMoveButton();
} else {
mMoveAppButton.setText(R.string.moving);
mMoveAppButton.setEnabled(false);
mUninstallButton.setEnabled(false);
}
}
private void processMoveMsg(Message msg) { private void processMoveMsg(Message msg) {
int result = msg.arg1; int result = msg.arg1;
String packageName = mAppInfo.packageName; String packageName = mAppInfo.packageName;
// Refresh the button attributes.
mMoveInProgress = false;
refreshButtons();
if(result == PackageManager.MOVE_SUCCEEDED) { if(result == PackageManager.MOVE_SUCCEEDED) {
Log.i(TAG, "Moved resources for " + packageName); Log.i(TAG, "Moved resources for " + packageName);
try { // Refresh size information again.
// Reset flags
mAppInfo = mPm.getApplicationInfo(packageName,
PackageManager.GET_UNINSTALLED_PACKAGES);
initMoveButton();
// Refresh size info
mPm.getPackageSizeInfo(mAppInfo.packageName, mSizeObserver); mPm.getPackageSizeInfo(mAppInfo.packageName, mSizeObserver);
} catch (NameNotFoundException e) {
// TODO error handling
}
} else { } else {
initMoveButton();
mMoveErrorCode = result; mMoveErrorCode = result;
showDialogInner(DLG_MOVE_FAILED); showDialogInner(DLG_MOVE_FAILED);
} }
@@ -677,8 +682,8 @@ public class InstalledAppDetails extends Activity implements View.OnClickListene
} }
int moveFlags = (mAppInfo.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0 ? int moveFlags = (mAppInfo.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0 ?
PackageManager.MOVE_INTERNAL : PackageManager.MOVE_EXTERNAL_MEDIA; PackageManager.MOVE_INTERNAL : PackageManager.MOVE_EXTERNAL_MEDIA;
mMoveAppButton.setText(R.string.moving); mMoveInProgress = true;
mMoveAppButton.setEnabled(false); refreshButtons();
mPm.movePackage(mAppInfo.packageName, mPackageMoveObserver, moveFlags); mPm.movePackage(mAppInfo.packageName, mPackageMoveObserver, moveFlags);
} }
} }

View File

@@ -19,7 +19,6 @@ package com.android.settings;
import com.android.settings.R; import com.android.settings.R;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.app.TabActivity; import android.app.TabActivity;
@@ -37,7 +36,6 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
@@ -45,7 +43,6 @@ import android.os.Message;
import android.os.SystemClock; import android.os.SystemClock;
import android.text.format.Formatter; import android.text.format.Formatter;
import android.util.Log; import android.util.Log;
import android.util.SparseArray;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@@ -209,7 +206,7 @@ public class ManageApplications extends TabActivity implements
ResourceLoaderThread mResourceThread; ResourceLoaderThread mResourceThread;
private TaskRunner mSizeComputor; private TaskRunner mSizeComputor;
String mCurrentPkgName; private String mCurrentPkgName;
// Cache application attributes // Cache application attributes
private AppInfoCache mCache = new AppInfoCache(); private AppInfoCache mCache = new AppInfoCache();
@@ -2055,4 +2052,21 @@ public class ManageApplications extends TabActivity implements
} }
sendMessageToHandler(REORDER_LIST, newOption); sendMessageToHandler(REORDER_LIST, newOption);
} }
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (requestCode == INSTALLED_APP_DETAILS && mCurrentPkgName != null) {
// Refresh package attributes
try {
ApplicationInfo info = mPm.getApplicationInfo(mCurrentPkgName,
PackageManager.GET_UNINSTALLED_PACKAGES);
} catch (NameNotFoundException e) {
Bundle rData = new Bundle();
rData.putString(ATTR_PKG_NAME, mCurrentPkgName);
sendMessageToHandler(REMOVE_PKG, rData);
mCurrentPkgName = null;
}
}
}
} }