Further manage apps fragmentization.

All of the UI under manage apps should now be working.  Various
cleanup through new framework APIs.  Fragmentized developer settings.

Change-Id: I2b42a2dd0d015e0fdcde497579ddad3dceea9da2
This commit is contained in:
Dianne Hackborn
2010-11-01 12:32:33 -07:00
parent 0417e40947
commit ee2937941d
8 changed files with 220 additions and 163 deletions

View File

@@ -457,7 +457,7 @@
<!-- Provide direct entry into manage apps showing running services. -->
<activity-alias android:name=".RunningServices"
android:label="@string/runningservices_settings_title"
android:targetActivity=".applications.ManageApplications">
android:targetActivity="Settings">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
@@ -470,7 +470,7 @@
<!-- Provide direct entry into manage apps showing running services. -->
<activity-alias android:name=".applications.StorageUse"
android:label="@string/storageuse_settings_title"
android:targetActivity=".applications.ManageApplications">
android:targetActivity="Settings">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
@@ -480,11 +480,6 @@
</intent-filter>
</activity-alias>
<activity android:name=".applications.RunningServiceDetails"
android:theme="@android:style/Theme.NoTitleBar"
android:label="@string/runningservicedetails_settings_title">
</activity>
<activity-alias android:name="SecuritySettings"
android:label="@string/location_security_settings_title"
android:configChanges="orientation|keyboardHidden"
@@ -686,15 +681,17 @@
</intent-filter>
</activity>
<activity android:name="DevelopmentSettings"
android:label="@string/development_settings_title">
<activity-alias android:name="DevelopmentSettings"
android:label="@string/development_settings_title"
android:targetActivity="Settings"
android:clearTaskOnLaunch="true"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="com.android.settings.APPLICATION_DEVELOPMENT_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</activity-alias>

View File

@@ -44,25 +44,24 @@
</PreferenceScreen>
<PreferenceScreen
android:fragment="com.android.settings.applications.ManageApplications"
android:title="@string/manageapplications_settings_title"
android:summary="@string/manageapplications_settings_summary">
android:fragment="com.android.settings.applications.ManageApplications"
android:title="@string/manageapplications_settings_title"
android:summary="@string/manageapplications_settings_summary">
</PreferenceScreen>
<PreferenceScreen
android:fragment="com.android.settings.applications.ManageApplications"
android:title="@string/runningservices_settings_title"
android:summary="@string/runningservices_settings_summary">
<intent android:action="android.intent.action.MAIN"
android:targetPackage="com.android.settings"
android:targetClass="com.android.settings.RunningServices" />
<extra android:name="classname" android:value="com.android.settings.RunningServices" />
</PreferenceScreen>
<PreferenceScreen
android:fragment="com.android.settings.applications.ManageApplications"
android:title="@string/storageuse_settings_title"
android:summary="@string/storageuse_settings_summary">
<intent android:action="android.intent.action.MAIN"
android:targetPackage="com.android.settings"
android:targetClass="com.android.settings.applications.StorageUse" />
<extra android:name="classname"
android:value="com.android.settings.applications.StorageUse" />
</PreferenceScreen>
<PreferenceScreen

View File

@@ -18,21 +18,20 @@ package com.android.settings;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ContentResolver;
import android.content.DialogInterface;
import android.os.BatteryManager;
import android.os.Bundle;
import android.os.SystemProperties;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
import android.preference.CheckBoxPreference;
import android.provider.Settings;
import android.text.TextUtils;
/*
* Displays preferences for application developers.
*/
public class DevelopmentSettings extends PreferenceActivity
public class DevelopmentSettings extends PreferenceFragment
implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener {
private static final String ENABLE_ADB = "enable_adb";
@@ -49,7 +48,7 @@ public class DevelopmentSettings extends PreferenceActivity
private Dialog mOkDialog;
@Override
protected void onCreate(Bundle icicle) {
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.development_prefs);
@@ -60,14 +59,15 @@ public class DevelopmentSettings extends PreferenceActivity
}
@Override
protected void onResume() {
public void onResume() {
super.onResume();
mEnableAdb.setChecked(Settings.Secure.getInt(getContentResolver(),
final ContentResolver cr = getActivity().getContentResolver();
mEnableAdb.setChecked(Settings.Secure.getInt(cr,
Settings.Secure.ADB_ENABLED, 0) != 0);
mKeepScreenOn.setChecked(Settings.System.getInt(getContentResolver(),
mKeepScreenOn.setChecked(Settings.System.getInt(cr,
Settings.System.STAY_ON_WHILE_PLUGGED_IN, 0) != 0);
mAllowMockLocation.setChecked(Settings.Secure.getInt(getContentResolver(),
mAllowMockLocation.setChecked(Settings.Secure.getInt(cr,
Settings.Secure.ALLOW_MOCK_LOCATION, 0) != 0);
}
@@ -82,8 +82,8 @@ public class DevelopmentSettings extends PreferenceActivity
if (mEnableAdb.isChecked()) {
mOkClicked = false;
if (mOkDialog != null) dismissDialog();
mOkDialog = new AlertDialog.Builder(this).setMessage(
getResources().getString(R.string.adb_warning_message))
mOkDialog = new AlertDialog.Builder(getActivity()).setMessage(
getActivity().getResources().getString(R.string.adb_warning_message))
.setTitle(R.string.adb_warning_title)
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(android.R.string.yes, this)
@@ -91,14 +91,17 @@ public class DevelopmentSettings extends PreferenceActivity
.show();
mOkDialog.setOnDismissListener(this);
} else {
Settings.Secure.putInt(getContentResolver(), Settings.Secure.ADB_ENABLED, 0);
Settings.Secure.putInt(getActivity().getContentResolver(),
Settings.Secure.ADB_ENABLED, 0);
}
} else if (preference == mKeepScreenOn) {
Settings.System.putInt(getContentResolver(), Settings.System.STAY_ON_WHILE_PLUGGED_IN,
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.STAY_ON_WHILE_PLUGGED_IN,
mKeepScreenOn.isChecked() ?
(BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB) : 0);
} else if (preference == mAllowMockLocation) {
Settings.Secure.putInt(getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION,
Settings.Secure.putInt(getActivity().getContentResolver(),
Settings.Secure.ALLOW_MOCK_LOCATION,
mAllowMockLocation.isChecked() ? 1 : 0);
}
@@ -114,7 +117,8 @@ public class DevelopmentSettings extends PreferenceActivity
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_POSITIVE) {
mOkClicked = true;
Settings.Secure.putInt(getContentResolver(), Settings.Secure.ADB_ENABLED, 1);
Settings.Secure.putInt(getActivity().getContentResolver(),
Settings.Secure.ADB_ENABLED, 1);
} else {
// Reset the toggle
mEnableAdb.setChecked(false);

View File

@@ -56,7 +56,9 @@ public class Settings extends PreferenceActivity {
String intentClass = intent.getComponent().getClassName();
if (intentClass.equals(getClass().getName())) return null;
if ("com.android.settings.ManageApplications".equals(intentClass)) {
if ("com.android.settings.ManageApplications".equals(intentClass)
|| "com.android.settings.RunningServices".equals(intentClass)
|| "com.android.settings.applications.StorageUse".equals(intentClass)) {
// Old name of manage apps.
intentClass = com.android.settings.applications.ManageApplications.class.getName();
}

View File

@@ -40,9 +40,11 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.os.RemoteException;
import android.preference.PreferenceActivity;
import android.text.format.Formatter;
import android.util.Log;
@@ -222,6 +224,10 @@ public class InstalledAppDetails extends Fragment
}
private void initMoveButton() {
if (Environment.isExternalStorageEmulated()) {
mMoveAppButton.setVisibility(View.INVISIBLE);
return;
}
boolean dataOnly = false;
dataOnly = (mPackageInfo == null) && (mAppEntry != null);
boolean moveDisable = true;
@@ -470,13 +476,8 @@ public class InstalledAppDetails extends Fragment
if(localLOGV) Log.i(TAG, "appChanged="+appChanged);
Intent intent = new Intent();
intent.putExtra(ManageApplications.APP_CHG, appChanged);
Fragment target = getTargetFragment();
if (target != null) {
target.onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, intent);
}
if (finish) {
getActivity().onBackPressed();
}
PreferenceActivity pa = (PreferenceActivity)getActivity();
pa.finishPreferencePanel(this, Activity.RESULT_OK, intent);
}
private void refreshSizeInfo() {

View File

@@ -21,14 +21,11 @@ import com.android.settings.R;
import com.android.settings.applications.ApplicationsState.AppEntry;
import android.app.Fragment;
import android.app.TabActivity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
import android.content.pm.PackageInfo;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.RemoteException;
@@ -38,14 +35,12 @@ import android.preference.PreferenceActivity;
import android.provider.Settings;
import android.text.format.Formatter;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.animation.AnimationUtils;
import android.view.inputmethod.InputMethodManager;
import android.widget.AbsListView;
@@ -57,7 +52,6 @@ import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
@@ -167,6 +161,8 @@ public class ManageApplications extends Fragment implements
TextView mUsedStorageText;
TextView mFreeStorageText;
private Menu mOptionsMenu;
// These are for keeping track of activity and tab switch state.
private int mCurView;
private boolean mCreatedRunning;
@@ -518,11 +514,14 @@ public class ManageApplications extends Fragment implements
Intent intent = getActivity().getIntent();
String action = intent.getAction();
String defaultTabTag = TAB_DOWNLOADED;
if (intent.getComponent().getClassName().equals(
"com.android.settings.RunningServices")) {
String className = getArguments() != null
? getArguments().getString("classname") : null;
if (className == null) {
className = intent.getComponent().getClassName();
}
if (className.equals("com.android.settings.RunningServices")) {
defaultTabTag = TAB_RUNNING;
} else if (intent.getComponent().getClassName().equals(
"com.android.settings.applications.StorageUse")
} else if (className.equals("com.android.settings.applications.StorageUse")
|| action.equals(Intent.ACTION_MANAGE_PACKAGE_STORAGE)) {
mSortOrder = SORT_ORDER_SIZE;
mFilterApps = FILTER_APPS_ALL;
@@ -577,6 +576,8 @@ public class ManageApplications extends Fragment implements
mRunningProcessesView = (RunningProcessesView)mRootView.findViewById(
R.id.running_processes);
mCreatedRunning = mResumedRunning = false;
View tabRoot = mInflater.inflate(com.android.internal.R.layout.tab_content, null);
mTabHost = (TabHost)tabRoot.findViewById(com.android.internal.R.id.tabhost);
mTabHost.setup();
@@ -589,10 +590,12 @@ public class ManageApplications extends Fragment implements
.setIndicator(getActivity().getString(R.string.filter_apps_all),
getActivity().getResources().getDrawable(R.drawable.ic_tab_all))
.setContent(this));
tabHost.addTab(tabHost.newTabSpec(TAB_SDCARD)
.setIndicator(getActivity().getString(R.string.filter_apps_onsdcard),
getActivity().getResources().getDrawable(R.drawable.ic_tab_sdcard))
.setContent(this));
if (!Environment.isExternalStorageEmulated()) {
tabHost.addTab(tabHost.newTabSpec(TAB_SDCARD)
.setIndicator(getActivity().getString(R.string.filter_apps_onsdcard),
getActivity().getResources().getDrawable(R.drawable.ic_tab_sdcard))
.setContent(this));
}
tabHost.addTab(tabHost.newTabSpec(TAB_RUNNING)
.setIndicator(getActivity().getString(R.string.filter_apps_running),
getActivity().getResources().getDrawable(R.drawable.ic_tab_running))
@@ -613,6 +616,7 @@ public class ManageApplications extends Fragment implements
super.onResume();
mActivityResumed = true;
showCurrentTab();
updateOptionsMenu();
}
@Override
@@ -620,8 +624,8 @@ public class ManageApplications extends Fragment implements
super.onSaveInstanceState(outState);
outState.putInt("sortOrder", mSortOrder);
outState.putInt("filterApps", mFilterApps);
if (mTabHost != null) {
outState.putString("defautTabTag", mTabHost.getCurrentTabTag());
if (mDefaultTab != null) {
outState.putString("defautTabTag", mDefaultTab);
}
}
@@ -645,52 +649,63 @@ public class ManageApplications extends Fragment implements
// utility method used to start sub activity
private void startApplicationDetailsActivity() {
// Create intent to start new activity
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
Uri.fromParts("package", mCurrentPkgName, null));
// start new fragment to display extended information
Bundle args = new Bundle();
args.putString(InstalledAppDetails.ARG_PACKAGE_NAME, mCurrentPkgName);
PreferenceActivity pa = (PreferenceActivity)getActivity();
if (pa.isMultiPane()) {
Fragment frag = new InstalledAppDetails();
frag.setTargetFragment(this, INSTALLED_APP_DETAILS);
frag.setArguments(args);
frag.setTargetFragment(this, INSTALLED_APP_DETAILS);
pa.startPreferenceFragment(frag, true);
} else {
pa.startWithFragment(InstalledAppDetails.class.getName(), args);
}
pa.startPreferencePanel(InstalledAppDetails.class.getName(), args,
R.string.application_info_label, null, this, INSTALLED_APP_DETAILS);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
Log.i(TAG, "onCreateOptionsMenu in " + this + ": " + menu);
mOptionsMenu = menu;
menu.add(0, SORT_ORDER_ALPHA, 1, R.string.sort_order_alpha)
.setIcon(android.R.drawable.ic_menu_sort_alphabetically);
.setIcon(android.R.drawable.ic_menu_sort_alphabetically)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add(0, SORT_ORDER_SIZE, 2, R.string.sort_order_size)
.setIcon(android.R.drawable.ic_menu_sort_by_size);
menu.add(0, SHOW_RUNNING_SERVICES, 3, R.string.show_running_services);
menu.add(0, SHOW_BACKGROUND_PROCESSES, 3, R.string.show_background_processes);
.setIcon(android.R.drawable.ic_menu_sort_by_size)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add(0, SHOW_RUNNING_SERVICES, 3, R.string.show_running_services)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add(0, SHOW_BACKGROUND_PROCESSES, 3, R.string.show_background_processes)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
updateOptionsMenu();
}
@Override
public void onPrepareOptionsMenu(Menu menu) {
updateOptionsMenu();
}
@Override
public void onDestroyOptionsMenu() {
mOptionsMenu = null;
}
void updateOptionsMenu() {
if (mOptionsMenu == null) {
return;
}
/*
* The running processes screen doesn't use the mApplicationsAdapter
* so bringing up this menu in that case doesn't make any sense.
*/
if (mCurView == VIEW_RUNNING) {
boolean showingBackground = mRunningProcessesView.mAdapter.getShowBackground();
menu.findItem(SORT_ORDER_ALPHA).setVisible(false);
menu.findItem(SORT_ORDER_SIZE).setVisible(false);
menu.findItem(SHOW_RUNNING_SERVICES).setVisible(showingBackground);
menu.findItem(SHOW_BACKGROUND_PROCESSES).setVisible(!showingBackground);
boolean showingBackground = mRunningProcessesView != null
? mRunningProcessesView.mAdapter.getShowBackground() : false;
mOptionsMenu.findItem(SORT_ORDER_ALPHA).setVisible(false);
mOptionsMenu.findItem(SORT_ORDER_SIZE).setVisible(false);
mOptionsMenu.findItem(SHOW_RUNNING_SERVICES).setVisible(showingBackground);
mOptionsMenu.findItem(SHOW_BACKGROUND_PROCESSES).setVisible(!showingBackground);
} else {
menu.findItem(SORT_ORDER_ALPHA).setVisible(mSortOrder != SORT_ORDER_ALPHA);
menu.findItem(SORT_ORDER_SIZE).setVisible(mSortOrder != SORT_ORDER_SIZE);
menu.findItem(SHOW_RUNNING_SERVICES).setVisible(false);
menu.findItem(SHOW_BACKGROUND_PROCESSES).setVisible(false);
mOptionsMenu.findItem(SORT_ORDER_ALPHA).setVisible(mSortOrder != SORT_ORDER_ALPHA);
mOptionsMenu.findItem(SORT_ORDER_SIZE).setVisible(mSortOrder != SORT_ORDER_SIZE);
mOptionsMenu.findItem(SHOW_RUNNING_SERVICES).setVisible(false);
mOptionsMenu.findItem(SHOW_BACKGROUND_PROCESSES).setVisible(false);
}
}
@@ -707,6 +722,7 @@ public class ManageApplications extends Fragment implements
} else if (menuId == SHOW_BACKGROUND_PROCESSES) {
mRunningProcessesView.mAdapter.setShowBackground(true);
}
updateOptionsMenu();
return true;
}
@@ -822,7 +838,7 @@ public class ManageApplications extends Fragment implements
}
boolean haveData = true;
if (mActivityResumed && !mResumedRunning) {
haveData = mRunningProcessesView.doResume(mRunningProcessesAvail);
haveData = mRunningProcessesView.doResume(this, mRunningProcessesAvail);
mResumedRunning = true;
}
mApplicationsAdapter.pause();
@@ -850,7 +866,7 @@ public class ManageApplications extends Fragment implements
}
public void showCurrentTab() {
String tabId = mTabHost.getCurrentTabTag();
String tabId = mDefaultTab = mTabHost.getCurrentTabTag();
int newOption;
if (TAB_DOWNLOADED.equalsIgnoreCase(tabId)) {
newOption = FILTER_APPS_THIRD_PARTY;
@@ -872,6 +888,7 @@ public class ManageApplications extends Fragment implements
mFilterApps = newOption;
selectView(VIEW_LIST);
updateStorageUsage();
updateOptionsMenu();
}
public void onTabChanged(String tabId) {

View File

@@ -20,16 +20,16 @@ import com.android.settings.R;
import android.app.ActivityManager;
import android.app.Dialog;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.preference.PreferenceActivity;
import android.text.format.DateUtils;
import android.text.format.Formatter;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -61,6 +61,8 @@ public class RunningProcessesView extends FrameLayout
RunningState mState;
Fragment mOwner;
Runnable mDataAvail;
StringBuilder mBuilder = new StringBuilder(128);
@@ -417,14 +419,22 @@ public class RunningProcessesView extends FrameLayout
ListView l = (ListView)parent;
RunningState.MergedItem mi = (RunningState.MergedItem)l.getAdapter().getItem(position);
mCurSelected = mi;
Intent intent = new Intent();
intent.putExtra(RunningServiceDetails.KEY_UID, mi.mProcess.mUid);
intent.putExtra(RunningServiceDetails.KEY_PROCESS, mi.mProcess.mProcessName);
intent.putExtra(RunningServiceDetails.KEY_BACKGROUND, mAdapter.mShowBackground);
intent.setClass(getContext(), RunningServiceDetails.class);
getContext().startActivity(intent);
startServiceDetailsActivity(mi);
}
// utility method used to start sub activity
private void startServiceDetailsActivity(RunningState.MergedItem mi) {
// start new fragment to display extended information
Bundle args = new Bundle();
args.putInt(RunningServiceDetails.KEY_UID, mi.mProcess.mUid);
args.putString(RunningServiceDetails.KEY_PROCESS, mi.mProcess.mProcessName);
args.putBoolean(RunningServiceDetails.KEY_BACKGROUND, mAdapter.mShowBackground);
PreferenceActivity pa = (PreferenceActivity)mOwner.getActivity();
pa.startPreferencePanel(RunningServiceDetails.class.getName(), args,
R.string.runningservicedetails_settings_title, null, null, 0);
}
public void onMovedToScrapHeap(View view) {
mActiveItems.remove(view);
}
@@ -472,9 +482,11 @@ public class RunningProcessesView extends FrameLayout
public void doPause() {
mState.pause();
mDataAvail = null;
mOwner = null;
}
public boolean doResume(Runnable dataAvail) {
public boolean doResume(Fragment owner, Runnable dataAvail) {
mOwner = owner;
mState.resume(this);
if (mState.hasData()) {
// If the state already has its data, then let's populate our

View File

@@ -2,11 +2,12 @@ package com.android.settings.applications;
import com.android.settings.R;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.app.ApplicationErrorReport;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.Fragment;
import android.app.PendingIntent;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
@@ -37,7 +38,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
public class RunningServiceDetails extends Activity
public class RunningServiceDetails extends Fragment
implements RunningState.OnRefreshUiListener {
static final String TAG = "RunningServicesDetails";
@@ -59,6 +60,7 @@ public class RunningServiceDetails extends Activity
RunningState.MergedItem mMergedItem;
View mRootView;
ViewGroup mAllDetails;
ViewGroup mSnippet;
RunningProcessesView.ActiveItem mSnippetActiveItem;
@@ -84,14 +86,11 @@ public class RunningServiceDetails extends Activity
RunningState.ServiceItem si = mServiceItem;
if (!confirmed) {
if ((si.mServiceInfo.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) != 0) {
Bundle args = new Bundle();
args.putParcelable("comp", si.mRunningService.service);
removeDialog(DIALOG_CONFIRM_STOP);
showDialog(DIALOG_CONFIRM_STOP, args);
showConfirmStopDialog(si.mRunningService.service);
return;
}
}
stopService(new Intent().setComponent(si.mRunningService.service));
getActivity().stopService(new Intent().setComponent(si.mRunningService.service));
if (mMergedItem == null) {
// If this is gone, we are gone.
mState.updateNow();
@@ -125,7 +124,7 @@ public class RunningServiceDetails extends Activity
}
ComponentName comp = new ComponentName(mServiceItem.mServiceInfo.packageName,
mServiceItem.mServiceInfo.name);
File filename = getFileStreamPath("service_dump.txt");
File filename = getActivity().getFileStreamPath("service_dump.txt");
FileOutputStream output = null;
try {
output = new FileOutputStream(filename);
@@ -160,7 +159,7 @@ public class RunningServiceDetails extends Activity
if (mManageIntent != null) {
try {
startIntentSender(mManageIntent.getIntentSender(), null,
getActivity().startIntentSender(mManageIntent.getIntentSender(), null,
Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET,
Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET, 0);
@@ -236,7 +235,7 @@ public class RunningServiceDetails extends Activity
TextView description = (TextView)root.findViewById(R.id.comp_description);
if (si != null && si.mServiceInfo.descriptionRes != 0) {
description.setText(getPackageManager().getText(
description.setText(getActivity().getPackageManager().getText(
si.mServiceInfo.packageName, si.mServiceInfo.descriptionRes,
si.mServiceInfo.applicationInfo));
} else {
@@ -244,15 +243,15 @@ public class RunningServiceDetails extends Activity
description.setText(R.string.background_process_stop_description);
} else if (detail.mManageIntent != null) {
try {
Resources clientr = getPackageManager().getResourcesForApplication(
Resources clientr = getActivity().getPackageManager().getResourcesForApplication(
si.mRunningService.clientPackage);
String label = clientr.getString(si.mRunningService.clientLabel);
description.setText(getString(R.string.service_manage_description,
description.setText(getActivity().getString(R.string.service_manage_description,
label));
} catch (PackageManager.NameNotFoundException e) {
}
} else {
description.setText(getText(si != null
description.setText(getActivity().getText(si != null
? R.string.service_stop_description
: R.string.heavy_weight_stop_description));
}
@@ -260,18 +259,19 @@ public class RunningServiceDetails extends Activity
detail.mStopButton = (Button)root.findViewById(R.id.left_button);
detail.mStopButton.setOnClickListener(detail);
detail.mStopButton.setText(getText(detail.mManageIntent != null
detail.mStopButton.setText(getActivity().getText(detail.mManageIntent != null
? R.string.service_manage : R.string.service_stop));
detail.mReportButton = (Button)root.findViewById(R.id.right_button);
detail.mReportButton.setOnClickListener(detail);
detail.mReportButton.setText(com.android.internal.R.string.report);
// check if error reporting is enabled in secure settings
int enabled = Settings.Secure.getInt(getContentResolver(),
int enabled = Settings.Secure.getInt(getActivity().getContentResolver(),
Settings.Secure.SEND_ACTION_APP_ERROR, 0);
if (enabled != 0 && si != null) {
detail.mInstaller = ApplicationErrorReport.getErrorReportReceiver(
this, si.mServiceInfo.packageName, si.mServiceInfo.applicationInfo.flags);
getActivity(), si.mServiceInfo.packageName,
si.mServiceInfo.applicationInfo.flags);
detail.mReportButton.setEnabled(detail.mInstaller != null);
} else {
detail.mReportButton.setEnabled(false);
@@ -312,9 +312,9 @@ public class RunningServiceDetails extends Activity
textid = R.string.process_provider_in_use_description;
if (rpi.importanceReasonComponent != null) {
try {
ProviderInfo prov = getPackageManager().getProviderInfo(
ProviderInfo prov = getActivity().getPackageManager().getProviderInfo(
rpi.importanceReasonComponent, 0);
label = RunningState.makeLabel(getPackageManager(),
label = RunningState.makeLabel(getActivity().getPackageManager(),
prov.name, prov);
} catch (NameNotFoundException e) {
}
@@ -324,9 +324,9 @@ public class RunningServiceDetails extends Activity
textid = R.string.process_service_in_use_description;
if (rpi.importanceReasonComponent != null) {
try {
ServiceInfo serv = getPackageManager().getServiceInfo(
ServiceInfo serv = getActivity().getPackageManager().getServiceInfo(
rpi.importanceReasonComponent, 0);
label = RunningState.makeLabel(getPackageManager(),
label = RunningState.makeLabel(getActivity().getPackageManager(),
serv.name, serv);
} catch (NameNotFoundException e) {
}
@@ -334,7 +334,7 @@ public class RunningServiceDetails extends Activity
break;
}
if (textid != 0 && label != null) {
description.setText(getString(textid, label));
description.setText(getActivity().getString(textid, label));
}
}
@@ -405,23 +405,30 @@ public class RunningServiceDetails extends Activity
}
}
private void finish() {
getActivity().onBackPressed();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mUid = getIntent().getIntExtra(KEY_UID, 0);
mProcessName = getIntent().getStringExtra(KEY_PROCESS);
mShowBackground = getIntent().getBooleanExtra(KEY_BACKGROUND, false);
mUid = getArguments().getInt(KEY_UID, 0);
mProcessName = getArguments().getString(KEY_PROCESS);
mShowBackground = getArguments().getBoolean(KEY_BACKGROUND, false);
mAm = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mAm = (ActivityManager)getActivity().getSystemService(Context.ACTIVITY_SERVICE);
mInflater = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mState = RunningState.getInstance(this);
mState = RunningState.getInstance(getActivity());
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = mRootView = inflater.inflate(R.layout.running_service_details, null);
setContentView(R.layout.running_service_details);
mAllDetails = (ViewGroup)findViewById(R.id.all_details);
mSnippet = (ViewGroup)findViewById(R.id.snippet);
mAllDetails = (ViewGroup)view.findViewById(R.id.all_details);
mSnippet = (ViewGroup)view.findViewById(R.id.snippet);
mSnippet.setBackgroundResource(com.android.internal.R.drawable.title_bar_medium);
mSnippet.setPadding(0, mSnippet.getPaddingTop(), 0, mSnippet.getPaddingBottom());
mSnippetViewHolder = new RunningProcessesView.ViewHolder(mSnippet);
@@ -429,26 +436,23 @@ public class RunningServiceDetails extends Activity
// We want to retrieve the data right now, so any active managed
// dialog that gets created can find it.
ensureData();
return view;
}
@Override
protected void onPause() {
public void onPause() {
super.onPause();
mHaveData = false;
mState.pause();
}
@Override
protected void onResume() {
public void onResume() {
super.onResume();
ensureData();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
}
ActiveDetail activeDetailForService(ComponentName comp) {
for (int i=0; i<mActiveDetails.size(); i++) {
ActiveDetail ad = mActiveDetails.get(i);
@@ -460,34 +464,56 @@ public class RunningServiceDetails extends Activity
return null;
}
@Override
protected Dialog onCreateDialog(int id, Bundle args) {
switch (id) {
case DIALOG_CONFIRM_STOP: {
final ComponentName comp = (ComponentName)args.getParcelable("comp");
if (activeDetailForService(comp) == null) {
return null;
}
return new AlertDialog.Builder(this)
.setTitle(getString(R.string.runningservicedetails_stop_dlg_title))
.setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(getString(R.string.runningservicedetails_stop_dlg_text))
.setPositiveButton(R.string.dlg_ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
ActiveDetail ad = activeDetailForService(comp);
if (ad != null) {
ad.stopActiveService(true);
private void showConfirmStopDialog(ComponentName comp) {
DialogFragment newFragment = MyAlertDialogFragment.newConfirmStop(
DIALOG_CONFIRM_STOP, comp);
newFragment.setTargetFragment(this, 0);
newFragment.show(getFragmentManager(), "confirmstop");
}
public static class MyAlertDialogFragment extends DialogFragment {
public static MyAlertDialogFragment newConfirmStop(int id, ComponentName comp) {
MyAlertDialogFragment frag = new MyAlertDialogFragment();
Bundle args = new Bundle();
args.putInt("id", id);
args.putParcelable("comp", comp);
frag.setArguments(args);
return frag;
}
RunningServiceDetails getOwner() {
return (RunningServiceDetails)getTargetFragment();
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
int id = getArguments().getInt("id");
switch (id) {
case DIALOG_CONFIRM_STOP: {
final ComponentName comp = (ComponentName)getArguments().getParcelable("comp");
if (getOwner().activeDetailForService(comp) == null) {
return null;
}
return new AlertDialog.Builder(getActivity())
.setTitle(getActivity().getString(R.string.runningservicedetails_stop_dlg_title))
.setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(getActivity().getString(R.string.runningservicedetails_stop_dlg_text))
.setPositiveButton(R.string.dlg_ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
ActiveDetail ad = getOwner().activeDetailForService(comp);
if (ad != null) {
ad.stopActiveService(true);
}
}
}
})
.setNegativeButton(R.string.dlg_cancel, null)
.create();
})
.setNegativeButton(R.string.dlg_cancel, null)
.create();
}
}
default:
return super.onCreateDialog(id, args);
throw new IllegalArgumentException("unknown id " + id);
}
}
@@ -509,11 +535,10 @@ public class RunningServiceDetails extends Activity
void updateTimes() {
if (mSnippetActiveItem != null) {
mSnippetActiveItem.updateTime(RunningServiceDetails.this, mBuilder);
mSnippetActiveItem.updateTime(getActivity(), mBuilder);
}
for (int i=0; i<mActiveDetails.size(); i++) {
mActiveDetails.get(i).mActiveItem.updateTime(
RunningServiceDetails.this, mBuilder);
mActiveDetails.get(i).mActiveItem.updateTime(getActivity(), mBuilder);
}
}