Merge "Save and update enabled Subtypes in InputMethodAndSubtypeEnabler"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 66c9bfd..4729785 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -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>
 
 
 
diff --git a/res/values/strings.xml b/res/values/strings.xml
index d510018..2d1a599 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -999,14 +999,6 @@
     <!-- Wi-Fi Advanced Settings --> <skip />
     <!-- Wi-Fi settings screen, advanced, settings section.  This is a header shown above advanced wifi settings. -->
     <string name="wifi_advanced_titlebar">Advanced</string>
-    <!-- Wi-Fi settings screen, setting title for choosing the number of channels to be used -->
-    <string name="wifi_setting_num_channels_title">Regulatory domain</string>
-    <!-- Wi-Fi settings screen, setting summary for choosing the number of channels to be used -->
-    <string name="wifi_setting_num_channels_summary">Set the number of channels to use</string>
-    <!-- Wi-Fi settings screen, generic error message when the regulatory domain could not be set. -->
-    <string name="wifi_setting_num_channels_error">There was a problem setting the regulatory domain.</string>
-    <!-- Wi-Fi settings screen, label to be appended to the count in displaying the list of valid channel counts -->
-    <string name="wifi_setting_num_channels_channel_phrase"><xliff:g id="num_channels">%1$d</xliff:g> channels</string>
     <!-- Wi-Fi settings screen, setting title for setting the wifi sleep policy -->
     <string name="wifi_setting_sleep_policy_title">Wi-Fi sleep policy</string>
     <!-- Wi-Fi settings screen, setting summary for setting the wifi sleep policy -->
diff --git a/res/xml/application_settings.xml b/res/xml/application_settings.xml
index 6cd0b62..76fa0bc 100644
--- a/res/xml/application_settings.xml
+++ b/res/xml/application_settings.xml
@@ -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
diff --git a/res/xml/wifi_advanced_settings.xml b/res/xml/wifi_advanced_settings.xml
index 8496428..7ccd588 100644
--- a/res/xml/wifi_advanced_settings.xml
+++ b/res/xml/wifi_advanced_settings.xml
@@ -18,13 +18,6 @@
         android:title="@string/wifi_advanced_titlebar">
 
     <ListPreference
-            android:key="num_channels"
-            android:title="@string/wifi_setting_num_channels_title"
-            android:summary="@string/wifi_setting_num_channels_summary"
-            android:persistent="false"
-            />
-    
-    <ListPreference
             android:key="sleep_policy"
             android:title="@string/wifi_setting_sleep_policy_title"
             android:summary="@string/wifi_setting_sleep_policy_summary"
diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java
index b0e5c07..c9c9263 100644
--- a/src/com/android/settings/DevelopmentSettings.java
+++ b/src/com/android/settings/DevelopmentSettings.java
@@ -18,21 +18,20 @@
 
 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 @@
     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 @@
     }
 
     @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 @@
             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 @@
                         .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 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);
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index b428928..3a6e6d8 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -56,7 +56,9 @@
         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();
         }
diff --git a/src/com/android/settings/applications/InstalledAppDetails.java b/src/com/android/settings/applications/InstalledAppDetails.java
index cb5fbed..1d46ed0 100644
--- a/src/com/android/settings/applications/InstalledAppDetails.java
+++ b/src/com/android/settings/applications/InstalledAppDetails.java
@@ -40,9 +40,11 @@
 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 @@
     }
 
     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 @@
         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() {
diff --git a/src/com/android/settings/applications/ManageApplications.java b/src/com/android/settings/applications/ManageApplications.java
index 217e333..20cf2f9 100644
--- a/src/com/android/settings/applications/ManageApplications.java
+++ b/src/com/android/settings/applications/ManageApplications.java
@@ -21,14 +21,11 @@
 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.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.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 @@
     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 @@
         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 @@
         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 @@
                 .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 @@
         super.onResume();
         mActivityResumed = true;
         showCurrentTab();
+        updateOptionsMenu();
     }
 
     @Override
@@ -620,8 +624,8 @@
         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 @@
     
     // 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 @@
         } else if (menuId == SHOW_BACKGROUND_PROCESSES) {
             mRunningProcessesView.mAdapter.setShowBackground(true);
         }
+        updateOptionsMenu();
         return true;
     }
     
@@ -822,7 +838,7 @@
             }
             boolean haveData = true;
             if (mActivityResumed && !mResumedRunning) {
-                haveData = mRunningProcessesView.doResume(mRunningProcessesAvail);
+                haveData = mRunningProcessesView.doResume(this, mRunningProcessesAvail);
                 mResumedRunning = true;
             }
             mApplicationsAdapter.pause();
@@ -850,7 +866,7 @@
     }
 
     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 @@
         mFilterApps = newOption;
         selectView(VIEW_LIST);
         updateStorageUsage();
+        updateOptionsMenu();
     }
 
     public void onTabChanged(String tabId) {
diff --git a/src/com/android/settings/applications/RunningProcessesView.java b/src/com/android/settings/applications/RunningProcessesView.java
index 7794365..958adbd 100644
--- a/src/com/android/settings/applications/RunningProcessesView.java
+++ b/src/com/android/settings/applications/RunningProcessesView.java
@@ -20,16 +20,16 @@
 
 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 @@
     
     RunningState mState;
     
+    Fragment mOwner;
+    
     Runnable mDataAvail;
 
     StringBuilder mBuilder = new StringBuilder(128);
@@ -417,14 +419,22 @@
         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 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
diff --git a/src/com/android/settings/applications/RunningServiceDetails.java b/src/com/android/settings/applications/RunningServiceDetails.java
index aa89baf..eccff93 100644
--- a/src/com/android/settings/applications/RunningServiceDetails.java
+++ b/src/com/android/settings/applications/RunningServiceDetails.java
@@ -2,11 +2,12 @@
 
 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.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 @@
     
     RunningState.MergedItem mMergedItem;
     
+    View mRootView;
     ViewGroup mAllDetails;
     ViewGroup mSnippet;
     RunningProcessesView.ActiveItem mSnippetActiveItem;
@@ -84,14 +86,11 @@
             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 @@
                 }
                 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 @@
 
             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 @@
         
         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 @@
                 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 @@
         
         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 @@
                     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 @@
                     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 @@
                     break;
             }
             if (textid != 0 && label != null) {
-                description.setText(getString(textid, label));
+                description.setText(getActivity().getString(textid, label));
             }
         }
         
@@ -405,23 +405,30 @@
         }
     }
     
+    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 @@
         // 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 @@
         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 @@
     
     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);
         }
     }
 
diff --git a/src/com/android/settings/wifi/AdvancedSettings.java b/src/com/android/settings/wifi/AdvancedSettings.java
index c88073d..0d33a10 100644
--- a/src/com/android/settings/wifi/AdvancedSettings.java
+++ b/src/com/android/settings/wifi/AdvancedSettings.java
@@ -35,12 +35,8 @@
 
     private static final String KEY_MAC_ADDRESS = "mac_address";
     private static final String KEY_CURRENT_IP_ADDRESS = "current_ip_address";
-    private static final String KEY_NUM_CHANNELS = "num_channels";
     private static final String KEY_SLEEP_POLICY = "sleep_policy";
 
-    //Tracks ro.debuggable (1 on userdebug builds)
-    private static int DEBUGGABLE;
-
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -50,77 +46,16 @@
     @Override
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
-
-        DEBUGGABLE = SystemProperties.getInt("ro.debuggable", 0);
-
-        /**
-         * Remove user control of regulatory domain
-         * channel count settings in non userdebug builds
-         */
-        if (DEBUGGABLE == 1) {
-            /*
-             * Fix the Run-time IllegalStateException that ListPreference requires an entries
-             * array and an entryValues array, this exception occurs when user open/close the
-             * slider in the Regulatory domain dialog.
-             */
-            initNumChannelsPreference();
-        } else {
-            Preference chanPref = findPreference(KEY_NUM_CHANNELS);
-            if (chanPref != null) {
-              getPreferenceScreen().removePreference(chanPref);
-            }
-        }
     }
-    
+
     @Override
     public void onResume() {
         super.onResume();
 
-        /**
-         * Remove user control of regulatory domain
-         * channel count settings in non userdebug builds
-         */
-        if (DEBUGGABLE == 1) {
-            initNumChannelsPreference();
-        }
         initSleepPolicyPreference();
         refreshWifiInfo();
     }
 
-    private void initNumChannelsPreference() {
-        ListPreference pref = (ListPreference) findPreference(KEY_NUM_CHANNELS);
-        pref.setOnPreferenceChangeListener(this);
-
-        WifiManager wifiManager = (WifiManager) getSystemService(Activity.WIFI_SERVICE);
-        /*
-         * Generate the list of valid channel counts to show in the ListPreference.
-         * The values are numerical, so the only text to be localized is the
-         * "channel_word" resource.
-         */
-        int[] validChannelCounts = wifiManager.getValidChannelCounts();
-        if (validChannelCounts == null) {
-            Toast.makeText(getActivity(), R.string.wifi_setting_num_channels_error,
-                           Toast.LENGTH_SHORT).show();
-            pref.setEnabled(false);
-            return;
-        }
-        String[] entries = new String[validChannelCounts.length];
-        String[] entryValues = new String[validChannelCounts.length];
-
-        for (int i = 0; i < validChannelCounts.length; i++) {
-            entryValues[i] = String.valueOf(validChannelCounts[i]);
-            entries[i] = getActivity().getString(R.string.wifi_setting_num_channels_channel_phrase,
-                    validChannelCounts[i]);
-        }
-        pref.setEntries(entries);
-        pref.setEntryValues(entryValues);
-        pref.setEnabled(true);
-        int numChannels = wifiManager.getNumAllowedChannels();
-        if (numChannels >= 0) {
-            pref.setValue(String.valueOf(numChannels));
-        }
-    }
-    
     private void initSleepPolicyPreference() {
         ListPreference pref = (ListPreference) findPreference(KEY_SLEEP_POLICY);
         pref.setOnPreferenceChangeListener(this);
@@ -133,21 +68,7 @@
         String key = preference.getKey();
         if (key == null) return true;
 
-        if (key.equals(KEY_NUM_CHANNELS)) {
-            try {
-                int numChannels = Integer.parseInt((String) newValue);
-                WifiManager wifiManager = (WifiManager) getSystemService(Activity.WIFI_SERVICE);
-                if (!wifiManager.setNumAllowedChannels(numChannels, true)) {
-                    Toast.makeText(getActivity(), R.string.wifi_setting_num_channels_error,
-                            Toast.LENGTH_SHORT).show();
-                }
-            } catch (NumberFormatException e) {
-                Toast.makeText(getActivity(), R.string.wifi_setting_num_channels_error,
-                        Toast.LENGTH_SHORT).show();
-                return false;
-            }
-            
-        } else if (key.equals(KEY_SLEEP_POLICY)) {
+        if (key.equals(KEY_SLEEP_POLICY)) {
             try {
                 Settings.System.putInt(getContentResolver(),
                         Settings.System.WIFI_SLEEP_POLICY, Integer.parseInt(((String) newValue)));
@@ -157,7 +78,7 @@
                 return false;
             }
         }
-        
+
         return true;
     }
 
@@ -167,7 +88,7 @@
 
         Preference wifiMacAddressPref = findPreference(KEY_MAC_ADDRESS);
         String macAddress = wifiInfo == null ? null : wifiInfo.getMacAddress();
-        wifiMacAddressPref.setSummary(!TextUtils.isEmpty(macAddress) ? macAddress 
+        wifiMacAddressPref.setSummary(!TextUtils.isEmpty(macAddress) ? macAddress
                 : getActivity().getString(R.string.status_unavailable));
 
         Preference wifiIpAddressPref = findPreference(KEY_CURRENT_IP_ADDRESS);