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

View File

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

View File

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

View File

@@ -56,7 +56,9 @@ public class Settings extends PreferenceActivity {
String intentClass = intent.getComponent().getClassName(); String intentClass = intent.getComponent().getClassName();
if (intentClass.equals(getClass().getName())) return null; 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. // Old name of manage apps.
intentClass = com.android.settings.applications.ManageApplications.class.getName(); 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.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.os.RemoteException; import android.os.RemoteException;
import android.preference.PreferenceActivity;
import android.text.format.Formatter; import android.text.format.Formatter;
import android.util.Log; import android.util.Log;
@@ -222,6 +224,10 @@ public class InstalledAppDetails extends Fragment
} }
private void initMoveButton() { private void initMoveButton() {
if (Environment.isExternalStorageEmulated()) {
mMoveAppButton.setVisibility(View.INVISIBLE);
return;
}
boolean dataOnly = false; boolean dataOnly = false;
dataOnly = (mPackageInfo == null) && (mAppEntry != null); dataOnly = (mPackageInfo == null) && (mAppEntry != null);
boolean moveDisable = true; boolean moveDisable = true;
@@ -470,13 +476,8 @@ public class InstalledAppDetails extends Fragment
if(localLOGV) Log.i(TAG, "appChanged="+appChanged); if(localLOGV) Log.i(TAG, "appChanged="+appChanged);
Intent intent = new Intent(); Intent intent = new Intent();
intent.putExtra(ManageApplications.APP_CHG, appChanged); intent.putExtra(ManageApplications.APP_CHG, appChanged);
Fragment target = getTargetFragment(); PreferenceActivity pa = (PreferenceActivity)getActivity();
if (target != null) { pa.finishPreferencePanel(this, Activity.RESULT_OK, intent);
target.onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, intent);
}
if (finish) {
getActivity().onBackPressed();
}
} }
private void refreshSizeInfo() { private void refreshSizeInfo() {

View File

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

View File

@@ -20,16 +20,16 @@ import com.android.settings.R;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.Dialog; import android.app.Dialog;
import android.app.Fragment;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Bundle; import android.os.Bundle;
import android.os.SystemClock; import android.os.SystemClock;
import android.os.SystemProperties; import android.os.SystemProperties;
import android.preference.PreferenceActivity;
import android.text.format.DateUtils; import android.text.format.DateUtils;
import android.text.format.Formatter; import android.text.format.Formatter;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@@ -61,6 +61,8 @@ public class RunningProcessesView extends FrameLayout
RunningState mState; RunningState mState;
Fragment mOwner;
Runnable mDataAvail; Runnable mDataAvail;
StringBuilder mBuilder = new StringBuilder(128); StringBuilder mBuilder = new StringBuilder(128);
@@ -417,12 +419,20 @@ public class RunningProcessesView extends FrameLayout
ListView l = (ListView)parent; ListView l = (ListView)parent;
RunningState.MergedItem mi = (RunningState.MergedItem)l.getAdapter().getItem(position); RunningState.MergedItem mi = (RunningState.MergedItem)l.getAdapter().getItem(position);
mCurSelected = mi; mCurSelected = mi;
Intent intent = new Intent(); startServiceDetailsActivity(mi);
intent.putExtra(RunningServiceDetails.KEY_UID, mi.mProcess.mUid); }
intent.putExtra(RunningServiceDetails.KEY_PROCESS, mi.mProcess.mProcessName);
intent.putExtra(RunningServiceDetails.KEY_BACKGROUND, mAdapter.mShowBackground); // utility method used to start sub activity
intent.setClass(getContext(), RunningServiceDetails.class); private void startServiceDetailsActivity(RunningState.MergedItem mi) {
getContext().startActivity(intent); // 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) { public void onMovedToScrapHeap(View view) {
@@ -472,9 +482,11 @@ public class RunningProcessesView extends FrameLayout
public void doPause() { public void doPause() {
mState.pause(); mState.pause();
mDataAvail = null; mDataAvail = null;
mOwner = null;
} }
public boolean doResume(Runnable dataAvail) { public boolean doResume(Fragment owner, Runnable dataAvail) {
mOwner = owner;
mState.resume(this); mState.resume(this);
if (mState.hasData()) { if (mState.hasData()) {
// If the state already has its data, then let's populate our // 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 com.android.settings.R;
import android.app.Activity;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.ApplicationErrorReport; import android.app.ApplicationErrorReport;
import android.app.Dialog; import android.app.Dialog;
import android.app.DialogFragment;
import android.app.Fragment;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.ComponentName; import android.content.ComponentName;
@@ -37,7 +38,7 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
public class RunningServiceDetails extends Activity public class RunningServiceDetails extends Fragment
implements RunningState.OnRefreshUiListener { implements RunningState.OnRefreshUiListener {
static final String TAG = "RunningServicesDetails"; static final String TAG = "RunningServicesDetails";
@@ -59,6 +60,7 @@ public class RunningServiceDetails extends Activity
RunningState.MergedItem mMergedItem; RunningState.MergedItem mMergedItem;
View mRootView;
ViewGroup mAllDetails; ViewGroup mAllDetails;
ViewGroup mSnippet; ViewGroup mSnippet;
RunningProcessesView.ActiveItem mSnippetActiveItem; RunningProcessesView.ActiveItem mSnippetActiveItem;
@@ -84,14 +86,11 @@ public class RunningServiceDetails extends Activity
RunningState.ServiceItem si = mServiceItem; RunningState.ServiceItem si = mServiceItem;
if (!confirmed) { if (!confirmed) {
if ((si.mServiceInfo.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) != 0) { if ((si.mServiceInfo.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) != 0) {
Bundle args = new Bundle(); showConfirmStopDialog(si.mRunningService.service);
args.putParcelable("comp", si.mRunningService.service);
removeDialog(DIALOG_CONFIRM_STOP);
showDialog(DIALOG_CONFIRM_STOP, args);
return; return;
} }
} }
stopService(new Intent().setComponent(si.mRunningService.service)); getActivity().stopService(new Intent().setComponent(si.mRunningService.service));
if (mMergedItem == null) { if (mMergedItem == null) {
// If this is gone, we are gone. // If this is gone, we are gone.
mState.updateNow(); mState.updateNow();
@@ -125,7 +124,7 @@ public class RunningServiceDetails extends Activity
} }
ComponentName comp = new ComponentName(mServiceItem.mServiceInfo.packageName, ComponentName comp = new ComponentName(mServiceItem.mServiceInfo.packageName,
mServiceItem.mServiceInfo.name); mServiceItem.mServiceInfo.name);
File filename = getFileStreamPath("service_dump.txt"); File filename = getActivity().getFileStreamPath("service_dump.txt");
FileOutputStream output = null; FileOutputStream output = null;
try { try {
output = new FileOutputStream(filename); output = new FileOutputStream(filename);
@@ -160,7 +159,7 @@ public class RunningServiceDetails extends Activity
if (mManageIntent != null) { if (mManageIntent != null) {
try { try {
startIntentSender(mManageIntent.getIntentSender(), null, getActivity().startIntentSender(mManageIntent.getIntentSender(), null,
Intent.FLAG_ACTIVITY_NEW_TASK Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET, | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET,
Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET, 0); 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); TextView description = (TextView)root.findViewById(R.id.comp_description);
if (si != null && si.mServiceInfo.descriptionRes != 0) { if (si != null && si.mServiceInfo.descriptionRes != 0) {
description.setText(getPackageManager().getText( description.setText(getActivity().getPackageManager().getText(
si.mServiceInfo.packageName, si.mServiceInfo.descriptionRes, si.mServiceInfo.packageName, si.mServiceInfo.descriptionRes,
si.mServiceInfo.applicationInfo)); si.mServiceInfo.applicationInfo));
} else { } else {
@@ -244,15 +243,15 @@ public class RunningServiceDetails extends Activity
description.setText(R.string.background_process_stop_description); description.setText(R.string.background_process_stop_description);
} else if (detail.mManageIntent != null) { } else if (detail.mManageIntent != null) {
try { try {
Resources clientr = getPackageManager().getResourcesForApplication( Resources clientr = getActivity().getPackageManager().getResourcesForApplication(
si.mRunningService.clientPackage); si.mRunningService.clientPackage);
String label = clientr.getString(si.mRunningService.clientLabel); 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)); label));
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
} }
} else { } else {
description.setText(getText(si != null description.setText(getActivity().getText(si != null
? R.string.service_stop_description ? R.string.service_stop_description
: R.string.heavy_weight_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 = (Button)root.findViewById(R.id.left_button);
detail.mStopButton.setOnClickListener(detail); 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)); ? R.string.service_manage : R.string.service_stop));
detail.mReportButton = (Button)root.findViewById(R.id.right_button); detail.mReportButton = (Button)root.findViewById(R.id.right_button);
detail.mReportButton.setOnClickListener(detail); detail.mReportButton.setOnClickListener(detail);
detail.mReportButton.setText(com.android.internal.R.string.report); detail.mReportButton.setText(com.android.internal.R.string.report);
// check if error reporting is enabled in secure settings // 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); Settings.Secure.SEND_ACTION_APP_ERROR, 0);
if (enabled != 0 && si != null) { if (enabled != 0 && si != null) {
detail.mInstaller = ApplicationErrorReport.getErrorReportReceiver( 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); detail.mReportButton.setEnabled(detail.mInstaller != null);
} else { } else {
detail.mReportButton.setEnabled(false); detail.mReportButton.setEnabled(false);
@@ -312,9 +312,9 @@ public class RunningServiceDetails extends Activity
textid = R.string.process_provider_in_use_description; textid = R.string.process_provider_in_use_description;
if (rpi.importanceReasonComponent != null) { if (rpi.importanceReasonComponent != null) {
try { try {
ProviderInfo prov = getPackageManager().getProviderInfo( ProviderInfo prov = getActivity().getPackageManager().getProviderInfo(
rpi.importanceReasonComponent, 0); rpi.importanceReasonComponent, 0);
label = RunningState.makeLabel(getPackageManager(), label = RunningState.makeLabel(getActivity().getPackageManager(),
prov.name, prov); prov.name, prov);
} catch (NameNotFoundException e) { } catch (NameNotFoundException e) {
} }
@@ -324,9 +324,9 @@ public class RunningServiceDetails extends Activity
textid = R.string.process_service_in_use_description; textid = R.string.process_service_in_use_description;
if (rpi.importanceReasonComponent != null) { if (rpi.importanceReasonComponent != null) {
try { try {
ServiceInfo serv = getPackageManager().getServiceInfo( ServiceInfo serv = getActivity().getPackageManager().getServiceInfo(
rpi.importanceReasonComponent, 0); rpi.importanceReasonComponent, 0);
label = RunningState.makeLabel(getPackageManager(), label = RunningState.makeLabel(getActivity().getPackageManager(),
serv.name, serv); serv.name, serv);
} catch (NameNotFoundException e) { } catch (NameNotFoundException e) {
} }
@@ -334,7 +334,7 @@ public class RunningServiceDetails extends Activity
break; break;
} }
if (textid != 0 && label != null) { 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 @Override
protected void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
mUid = getIntent().getIntExtra(KEY_UID, 0); mUid = getArguments().getInt(KEY_UID, 0);
mProcessName = getIntent().getStringExtra(KEY_PROCESS); mProcessName = getArguments().getString(KEY_PROCESS);
mShowBackground = getIntent().getBooleanExtra(KEY_BACKGROUND, false); mShowBackground = getArguments().getBoolean(KEY_BACKGROUND, false);
mAm = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE); mAm = (ActivityManager)getActivity().getSystemService(Context.ACTIVITY_SERVICE);
mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); mInflater = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mState = RunningState.getInstance(this); mState = RunningState.getInstance(getActivity());
}
setContentView(R.layout.running_service_details); @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = mRootView = inflater.inflate(R.layout.running_service_details, null);
mAllDetails = (ViewGroup)findViewById(R.id.all_details); mAllDetails = (ViewGroup)view.findViewById(R.id.all_details);
mSnippet = (ViewGroup)findViewById(R.id.snippet); mSnippet = (ViewGroup)view.findViewById(R.id.snippet);
mSnippet.setBackgroundResource(com.android.internal.R.drawable.title_bar_medium); mSnippet.setBackgroundResource(com.android.internal.R.drawable.title_bar_medium);
mSnippet.setPadding(0, mSnippet.getPaddingTop(), 0, mSnippet.getPaddingBottom()); mSnippet.setPadding(0, mSnippet.getPaddingTop(), 0, mSnippet.getPaddingBottom());
mSnippetViewHolder = new RunningProcessesView.ViewHolder(mSnippet); 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 // We want to retrieve the data right now, so any active managed
// dialog that gets created can find it. // dialog that gets created can find it.
ensureData(); ensureData();
return view;
} }
@Override @Override
protected void onPause() { public void onPause() {
super.onPause(); super.onPause();
mHaveData = false; mHaveData = false;
mState.pause(); mState.pause();
} }
@Override @Override
protected void onResume() { public void onResume() {
super.onResume(); super.onResume();
ensureData(); ensureData();
} }
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
}
ActiveDetail activeDetailForService(ComponentName comp) { ActiveDetail activeDetailForService(ComponentName comp) {
for (int i=0; i<mActiveDetails.size(); i++) { for (int i=0; i<mActiveDetails.size(); i++) {
ActiveDetail ad = mActiveDetails.get(i); ActiveDetail ad = mActiveDetails.get(i);
@@ -460,34 +464,56 @@ public class RunningServiceDetails extends Activity
return null; return null;
} }
@Override private void showConfirmStopDialog(ComponentName comp) {
protected Dialog onCreateDialog(int id, Bundle args) { DialogFragment newFragment = MyAlertDialogFragment.newConfirmStop(
switch (id) { DIALOG_CONFIRM_STOP, comp);
case DIALOG_CONFIRM_STOP: { newFragment.setTargetFragment(this, 0);
final ComponentName comp = (ComponentName)args.getParcelable("comp"); newFragment.show(getFragmentManager(), "confirmstop");
if (activeDetailForService(comp) == null) { }
return null;
}
return new AlertDialog.Builder(this) public static class MyAlertDialogFragment extends DialogFragment {
.setTitle(getString(R.string.runningservicedetails_stop_dlg_title))
.setIcon(android.R.drawable.ic_dialog_alert) public static MyAlertDialogFragment newConfirmStop(int id, ComponentName comp) {
.setMessage(getString(R.string.runningservicedetails_stop_dlg_text)) MyAlertDialogFragment frag = new MyAlertDialogFragment();
.setPositiveButton(R.string.dlg_ok, Bundle args = new Bundle();
new DialogInterface.OnClickListener() { args.putInt("id", id);
public void onClick(DialogInterface dialog, int which) { args.putParcelable("comp", comp);
ActiveDetail ad = activeDetailForService(comp); frag.setArguments(args);
if (ad != null) { return frag;
ad.stopActiveService(true); }
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)
.setNegativeButton(R.string.dlg_cancel, null) .create();
.create(); }
} }
throw new IllegalArgumentException("unknown id " + id);
default:
return super.onCreateDialog(id, args);
} }
} }
@@ -509,11 +535,10 @@ public class RunningServiceDetails extends Activity
void updateTimes() { void updateTimes() {
if (mSnippetActiveItem != null) { if (mSnippetActiveItem != null) {
mSnippetActiveItem.updateTime(RunningServiceDetails.this, mBuilder); mSnippetActiveItem.updateTime(getActivity(), mBuilder);
} }
for (int i=0; i<mActiveDetails.size(); i++) { for (int i=0; i<mActiveDetails.size(); i++) {
mActiveDetails.get(i).mActiveItem.updateTime( mActiveDetails.get(i).mActiveItem.updateTime(getActivity(), mBuilder);
RunningServiceDetails.this, mBuilder);
} }
} }