Start fragmentizing Manage Applications.

Change-Id: I0c3d6a358d0236893aba7257537ec32bfad4170d
This commit is contained in:
Dianne Hackborn
2010-10-29 16:53:04 -07:00
parent 58524fc53d
commit f4eb85bc3c
8 changed files with 332 additions and 226 deletions

View File

@@ -16,7 +16,6 @@
package com.android.settings.applications;
import com.android.internal.content.PackageHelper;
import com.android.settings.R;
import com.android.settings.applications.ApplicationsState.AppEntry;
@@ -24,6 +23,8 @@ import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.Fragment;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
@@ -31,7 +32,6 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageDataObserver;
import android.content.pm.IPackageManager;
import android.content.pm.IPackageMoveObserver;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
@@ -43,7 +43,6 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.text.format.Formatter;
import android.util.Log;
@@ -51,7 +50,9 @@ import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import android.content.ComponentName;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AppSecurityPermissions;
import android.widget.Button;
import android.widget.ImageView;
@@ -67,17 +68,20 @@ import android.widget.TextView;
* For non-system applications, there is no option to clear data. Instead there is an option to
* uninstall the application.
*/
public class InstalledAppDetails extends Activity
public class InstalledAppDetails extends Fragment
implements View.OnClickListener, ApplicationsState.Callbacks {
private static final String TAG="InstalledAppDetails";
static final boolean SUPPORT_DISABLE_APPS = false;
private static final boolean localLOGV = false;
public static final String ARG_PACKAGE_NAME = "package";
private PackageManager mPm;
private ApplicationsState mState;
private ApplicationsState.AppEntry mAppEntry;
private PackageInfo mPackageInfo;
private CanBeOnSdCardChecker mCanBeOnSdCardChecker;
private View mRootView;
private Button mUninstallButton;
private boolean mMoveInProgress = false;
private boolean mUpdatedSysApp = false;
@@ -95,7 +99,6 @@ public class InstalledAppDetails extends Activity
private Button mForceStopButton;
private Button mClearDataButton;
private Button mMoveAppButton;
private int mMoveErrorCode;
private PackageMoveObserver mPackageMoveObserver;
@@ -131,8 +134,8 @@ public class InstalledAppDetails extends Activity
private Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
// If the activity is gone, don't process any more messages.
if (isFinishing()) {
// If the fragment is gone, don't process any more messages.
if (getView() == null) {
return;
}
switch (msg.what) {
@@ -180,7 +183,7 @@ public class InstalledAppDetails extends Activity
if (size == SIZE_INVALID) {
return mInvalidSizeStr.toString();
}
return Formatter.formatFileSize(this, size);
return Formatter.formatFileSize(getActivity(), size);
}
private void initDataButtons() {
@@ -203,15 +206,15 @@ public class InstalledAppDetails extends Activity
private CharSequence getMoveErrMsg(int errCode) {
switch (errCode) {
case PackageManager.MOVE_FAILED_INSUFFICIENT_STORAGE:
return getString(R.string.insufficient_storage);
return getActivity().getString(R.string.insufficient_storage);
case PackageManager.MOVE_FAILED_DOESNT_EXIST:
return getString(R.string.does_not_exist);
return getActivity().getString(R.string.does_not_exist);
case PackageManager.MOVE_FAILED_FORWARD_LOCKED:
return getString(R.string.app_forward_locked);
return getActivity().getString(R.string.app_forward_locked);
case PackageManager.MOVE_FAILED_INVALID_LOCATION:
return getString(R.string.invalid_location);
return getActivity().getString(R.string.invalid_location);
case PackageManager.MOVE_FAILED_SYSTEM_PACKAGE:
return getString(R.string.system_package);
return getActivity().getString(R.string.system_package);
case PackageManager.MOVE_FAILED_INTERNAL_ERROR:
return "";
}
@@ -289,45 +292,50 @@ public class InstalledAppDetails extends Activity
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle icicle) {
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
mState = ApplicationsState.getInstance(getApplication());
mPm = getPackageManager();
mState = ApplicationsState.getInstance(getActivity().getApplication());
mPm = getActivity().getPackageManager();
mCanBeOnSdCardChecker = new CanBeOnSdCardChecker();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = mRootView = inflater.inflate(R.layout.installed_app_details, null);
setContentView(R.layout.installed_app_details);
mComputingStr = getText(R.string.computing_size);
mComputingStr = getActivity().getText(R.string.computing_size);
// Set default values on sizes
mTotalSize = (TextView)findViewById(R.id.total_size_text);
mAppSize = (TextView)findViewById(R.id.application_size_text);
mDataSize = (TextView)findViewById(R.id.data_size_text);
mTotalSize = (TextView)view.findViewById(R.id.total_size_text);
mAppSize = (TextView)view.findViewById(R.id.application_size_text);
mDataSize = (TextView)view.findViewById(R.id.data_size_text);
// Get Control button panel
View btnPanel = findViewById(R.id.control_buttons_panel);
View btnPanel = view.findViewById(R.id.control_buttons_panel);
mForceStopButton = (Button) btnPanel.findViewById(R.id.left_button);
mForceStopButton.setText(R.string.force_stop);
mUninstallButton = (Button)btnPanel.findViewById(R.id.right_button);
mForceStopButton.setEnabled(false);
// Initialize clear data and move install location buttons
View data_buttons_panel = findViewById(R.id.data_buttons_panel);
View data_buttons_panel = view.findViewById(R.id.data_buttons_panel);
mClearDataButton = (Button) data_buttons_panel.findViewById(R.id.left_button);
mMoveAppButton = (Button) data_buttons_panel.findViewById(R.id.right_button);
// Cache section
mCacheSize = (TextView) findViewById(R.id.cache_size_text);
mClearCacheButton = (Button) findViewById(R.id.clear_cache_button);
mCacheSize = (TextView) view.findViewById(R.id.cache_size_text);
mClearCacheButton = (Button) view.findViewById(R.id.clear_cache_button);
mActivitiesButton = (Button)view.findViewById(R.id.clear_activities_button);
mActivitiesButton = (Button)findViewById(R.id.clear_activities_button);
return view;
}
// Utility method to set applicaiton label and icon.
private void setAppLabelAndIcon(PackageInfo pkgInfo) {
View appSnippet = findViewById(R.id.app_snippet);
View appSnippet = mRootView.findViewById(R.id.app_snippet);
ImageView icon = (ImageView) appSnippet.findViewById(R.id.app_icon);
mState.ensureIcon(mAppEntry);
icon.setImageDrawable(mAppEntry.icon);
@@ -339,7 +347,7 @@ public class InstalledAppDetails extends Activity
if (pkgInfo != null && pkgInfo.versionName != null) {
mAppVersion.setVisibility(View.VISIBLE);
mAppVersion.setText(getString(R.string.version_text,
mAppVersion.setText(getActivity().getString(R.string.version_text,
String.valueOf(pkgInfo.versionName)));
} else {
mAppVersion.setVisibility(View.INVISIBLE);
@@ -395,8 +403,13 @@ public class InstalledAppDetails extends Activity
return true;
}
Intent intent = getIntent();
final String packageName = intent.getData().getSchemeSpecificPart();
String packageName = getArguments().getString(ARG_PACKAGE_NAME);
if (packageName == null) {
Intent intent = (Intent)getArguments().getParcelable("intent");
if (intent != null) {
packageName = intent.getData().getSchemeSpecificPart();
}
}
mAppEntry = mState.getEntry(packageName);
if (mAppEntry == null) {
@@ -421,7 +434,7 @@ public class InstalledAppDetails extends Activity
List<IntentFilter> intentList = new ArrayList<IntentFilter>();
mPm.getPreferredActivities(intentList, prefActList, packageName);
if(localLOGV) Log.i(TAG, "Have "+prefActList.size()+" number of activities in prefered list");
TextView autoLaunchView = (TextView)findViewById(R.id.auto_launch);
TextView autoLaunchView = (TextView)mRootView.findViewById(R.id.auto_launch);
if (prefActList.size() <= 0) {
// Disable clear activities button
autoLaunchView.setText(R.string.auto_launch_disable_text);
@@ -433,8 +446,8 @@ public class InstalledAppDetails extends Activity
}
// Security permissions section
LinearLayout permsView = (LinearLayout) findViewById(R.id.permissions_section);
AppSecurityPermissions asp = new AppSecurityPermissions(this, packageName);
LinearLayout permsView = (LinearLayout) mRootView.findViewById(R.id.permissions_section);
AppSecurityPermissions asp = new AppSecurityPermissions(getActivity(), packageName);
if (asp.getPermissionCount() > 0) {
permsView.setVisibility(View.VISIBLE);
// Make the security sections header visible
@@ -457,9 +470,12 @@ public class InstalledAppDetails extends Activity
if(localLOGV) Log.i(TAG, "appChanged="+appChanged);
Intent intent = new Intent();
intent.putExtra(ManageApplications.APP_CHG, appChanged);
setResult(ManageApplications.RESULT_OK, intent);
if(finish) {
finish();
Fragment target = getTargetFragment();
if (target != null) {
target.onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, intent);
}
if (finish) {
getActivity().onBackPressed();
}
}
@@ -549,8 +565,7 @@ public class InstalledAppDetails extends Activity
// Refresh size information again.
mState.requestSize(mAppEntry.info.packageName);
} else {
mMoveErrorCode = result;
showDialogInner(DLG_MOVE_FAILED);
showDialogInner(DLG_MOVE_FAILED, result);
}
refreshUi();
}
@@ -567,105 +582,125 @@ public class InstalledAppDetails extends Activity
if (mClearDataObserver == null) {
mClearDataObserver = new ClearUserDataObserver();
}
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager am = (ActivityManager)
getActivity().getSystemService(Context.ACTIVITY_SERVICE);
boolean res = am.clearApplicationUserData(packageName, mClearDataObserver);
if (!res) {
// Clearing data failed for some obscure reason. Just log error for now
Log.i(TAG, "Couldnt clear application user data for package:"+packageName);
showDialogInner(DLG_CANNOT_CLEAR_DATA);
showDialogInner(DLG_CANNOT_CLEAR_DATA, 0);
} else {
mClearDataButton.setText(R.string.recompute_size);
}
}
private void showDialogInner(int id) {
//removeDialog(id);
showDialog(id);
private void showDialogInner(int id, int moveErrorCode) {
DialogFragment newFragment = MyAlertDialogFragment.newInstance(id, moveErrorCode);
newFragment.setTargetFragment(this, 0);
newFragment.show(getFragmentManager(), "dialog " + id);
}
@Override
public Dialog onCreateDialog(int id, Bundle args) {
switch (id) {
case DLG_CLEAR_DATA:
return new AlertDialog.Builder(this)
.setTitle(getString(R.string.clear_data_dlg_title))
.setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(getString(R.string.clear_data_dlg_text))
.setPositiveButton(R.string.dlg_ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Clear user data here
initiateClearUserData();
}
})
.setNegativeButton(R.string.dlg_cancel, null)
.create();
case DLG_FACTORY_RESET:
return new AlertDialog.Builder(this)
.setTitle(getString(R.string.app_factory_reset_dlg_title))
.setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(getString(R.string.app_factory_reset_dlg_text))
.setPositiveButton(R.string.dlg_ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Clear user data here
uninstallPkg(mAppEntry.info.packageName);
}
})
.setNegativeButton(R.string.dlg_cancel, null)
.create();
case DLG_APP_NOT_FOUND:
return new AlertDialog.Builder(this)
.setTitle(getString(R.string.app_not_found_dlg_title))
.setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(getString(R.string.app_not_found_dlg_title))
.setNeutralButton(getString(R.string.dlg_ok),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//force to recompute changed value
setIntentAndFinish(true, true);
}
})
.create();
case DLG_CANNOT_CLEAR_DATA:
return new AlertDialog.Builder(this)
.setTitle(getString(R.string.clear_failed_dlg_title))
.setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(getString(R.string.clear_failed_dlg_text))
.setNeutralButton(R.string.dlg_ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
mClearDataButton.setEnabled(false);
//force to recompute changed value
setIntentAndFinish(false, false);
}
})
.create();
case DLG_FORCE_STOP:
return new AlertDialog.Builder(this)
.setTitle(getString(R.string.force_stop_dlg_title))
.setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(getString(R.string.force_stop_dlg_text))
.setPositiveButton(R.string.dlg_ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Force stop
forceStopPackage(mAppEntry.info.packageName);
}
})
.setNegativeButton(R.string.dlg_cancel, null)
.create();
case DLG_MOVE_FAILED:
CharSequence msg = getString(R.string.move_app_failed_dlg_text,
getMoveErrMsg(mMoveErrorCode));
return new AlertDialog.Builder(this)
.setTitle(getString(R.string.move_app_failed_dlg_title))
.setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(msg)
.setNeutralButton(R.string.dlg_ok, null)
.create();
public static class MyAlertDialogFragment extends DialogFragment {
public static MyAlertDialogFragment newInstance(int id, int moveErrorCode) {
MyAlertDialogFragment frag = new MyAlertDialogFragment();
Bundle args = new Bundle();
args.putInt("id", id);
args.putInt("moveError", moveErrorCode);
frag.setArguments(args);
return frag;
}
InstalledAppDetails getOwner() {
return (InstalledAppDetails)getTargetFragment();
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
int id = getArguments().getInt("id");
int moveErrorCode = getArguments().getInt("moveError");
switch (id) {
case DLG_CLEAR_DATA:
return new AlertDialog.Builder(getActivity())
.setTitle(getActivity().getText(R.string.clear_data_dlg_title))
.setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(getActivity().getText(R.string.clear_data_dlg_text))
.setPositiveButton(R.string.dlg_ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Clear user data here
getOwner().initiateClearUserData();
}
})
.setNegativeButton(R.string.dlg_cancel, null)
.create();
case DLG_FACTORY_RESET:
return new AlertDialog.Builder(getActivity())
.setTitle(getActivity().getText(R.string.app_factory_reset_dlg_title))
.setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(getActivity().getText(R.string.app_factory_reset_dlg_text))
.setPositiveButton(R.string.dlg_ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Clear user data here
getOwner().uninstallPkg(getOwner().mAppEntry.info.packageName);
}
})
.setNegativeButton(R.string.dlg_cancel, null)
.create();
case DLG_APP_NOT_FOUND:
return new AlertDialog.Builder(getActivity())
.setTitle(getActivity().getText(R.string.app_not_found_dlg_title))
.setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(getActivity().getText(R.string.app_not_found_dlg_title))
.setNeutralButton(getActivity().getText(R.string.dlg_ok),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//force to recompute changed value
getOwner().setIntentAndFinish(true, true);
}
})
.create();
case DLG_CANNOT_CLEAR_DATA:
return new AlertDialog.Builder(getActivity())
.setTitle(getActivity().getText(R.string.clear_failed_dlg_title))
.setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(getActivity().getText(R.string.clear_failed_dlg_text))
.setNeutralButton(R.string.dlg_ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
getOwner().mClearDataButton.setEnabled(false);
//force to recompute changed value
getOwner().setIntentAndFinish(false, false);
}
})
.create();
case DLG_FORCE_STOP:
return new AlertDialog.Builder(getActivity())
.setTitle(getActivity().getText(R.string.force_stop_dlg_title))
.setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(getActivity().getText(R.string.force_stop_dlg_text))
.setPositiveButton(R.string.dlg_ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Force stop
getOwner().forceStopPackage(getOwner().mAppEntry.info.packageName);
}
})
.setNegativeButton(R.string.dlg_cancel, null)
.create();
case DLG_MOVE_FAILED:
CharSequence msg = getActivity().getString(R.string.move_app_failed_dlg_text,
getOwner().getMoveErrMsg(moveErrorCode));
return new AlertDialog.Builder(getActivity())
.setTitle(getActivity().getText(R.string.move_app_failed_dlg_title))
.setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(msg)
.setNeutralButton(R.string.dlg_ok, null)
.create();
}
throw new IllegalArgumentException("unknown id " + id);
}
return null;
}
private void uninstallPkg(String packageName) {
@@ -677,7 +712,7 @@ public class InstalledAppDetails extends Activity
}
private void forceStopPackage(String pkgName) {
ActivityManager am = (ActivityManager)getSystemService(
ActivityManager am = (ActivityManager)getActivity().getSystemService(
Context.ACTIVITY_SERVICE);
am.forceStopPackage(pkgName);
checkForceStop();
@@ -686,7 +721,7 @@ public class InstalledAppDetails extends Activity
private final BroadcastReceiver mCheckKillProcessesReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
mForceStopButton.setEnabled(getResultCode() != RESULT_CANCELED);
mForceStopButton.setEnabled(getResultCode() != Activity.RESULT_CANCELED);
mForceStopButton.setOnClickListener(InstalledAppDetails.this);
}
};
@@ -696,7 +731,7 @@ public class InstalledAppDetails extends Activity
Uri.fromParts("package", mAppEntry.info.packageName, null));
intent.putExtra(Intent.EXTRA_PACKAGES, new String[] { mAppEntry.info.packageName });
intent.putExtra(Intent.EXTRA_UID, mAppEntry.info.uid);
sendOrderedBroadcast(intent, null, mCheckKillProcessesReceiver, null,
getActivity().sendOrderedBroadcast(intent, null, mCheckKillProcessesReceiver, null,
Activity.RESULT_CANCELED, null, null);
}
@@ -728,7 +763,7 @@ public class InstalledAppDetails extends Activity
String packageName = mAppEntry.info.packageName;
if(v == mUninstallButton) {
if (mUpdatedSysApp) {
showDialogInner(DLG_FACTORY_RESET);
showDialogInner(DLG_FACTORY_RESET, 0);
} else {
if ((mAppEntry.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
new DisableChanger(this, mAppEntry.info, mAppEntry.info.enabled ?
@@ -748,7 +783,7 @@ public class InstalledAppDetails extends Activity
mAppEntry.info.manageSpaceActivityName);
startActivityForResult(intent, -1);
} else {
showDialogInner(DLG_CLEAR_DATA);
showDialogInner(DLG_CLEAR_DATA, 0);
}
} else if (v == mClearCacheButton) {
// Lazy initialization of observer
@@ -757,7 +792,7 @@ public class InstalledAppDetails extends Activity
}
mPm.deleteApplicationCacheFiles(packageName, mClearCacheObserver);
} else if (v == mForceStopButton) {
showDialogInner(DLG_FORCE_STOP);
showDialogInner(DLG_FORCE_STOP, 0);
//forceStopPackage(mAppInfo.packageName);
} else if (v == mMoveAppButton) {
if (mPackageMoveObserver == null) {