Merge "Match parent width for user spinner to fix tint" into lmp-dev
diff --git a/src/com/android/settings/UserSpinnerAdapter.java b/src/com/android/settings/UserSpinnerAdapter.java
index b44caac..001dfc4 100644
--- a/src/com/android/settings/UserSpinnerAdapter.java
+++ b/src/com/android/settings/UserSpinnerAdapter.java
@@ -20,7 +20,7 @@
 import android.content.pm.UserInfo;
 import android.content.res.Resources;
 import android.database.DataSetObserver;
-import android.graphics.Bitmap;
+import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.Drawable;
 import android.os.UserHandle;
 import android.os.UserManager;
@@ -32,8 +32,6 @@
 import android.widget.TextView;
 
 import com.android.internal.util.UserIcons;
-import com.android.settings.drawable.CircleFramedDrawable;
-import com.android.settings.R;
 
 import java.util.ArrayList;
 
@@ -54,14 +52,14 @@
             if (userInfo.isManagedProfile()) {
                 name = context.getString(R.string.managed_user_title);
                 icon = Resources.getSystem().getDrawable(
-                        com.android.internal.R.drawable.ic_corp_icon);
+                    com.android.internal.R.drawable.ic_corp_icon);
             } else {
                 name = userInfo.name;
-                Bitmap bitmap = um.getUserIcon(userHandle.getIdentifier());
-                if (bitmap != null) {
-                    icon = CircleFramedDrawable.getInstance(context, bitmap);
+                final int userId = userInfo.id;
+                if (um.getUserIcon(userId) != null) {
+                    icon = new BitmapDrawable(context.getResources(), um.getUserIcon(userId));
                 } else {
-                    icon = UserIcons.getDefaultUserIcon(userInfo.id, /* light= */ false);
+                    icon = UserIcons.getDefaultUserIcon(userId, /* light= */ false);
                 }
             }
         }
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index de9fac7..08cfc58 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -613,6 +613,8 @@
             int titleResId, CharSequence title, boolean isShortcut, UserHandle userHandle) {
         Intent intent = onBuildStartFragmentIntent(context, fragmentName, args, titleResId,
                 title, isShortcut);
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
         context.startActivityAsUser(intent, userHandle);
     }
 
diff --git a/src/com/android/settings/fuelgauge/PowerUsageDetail.java b/src/com/android/settings/fuelgauge/PowerUsageDetail.java
index 36a2444..9dca029 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageDetail.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageDetail.java
@@ -259,8 +259,14 @@
         args.putIntArray(PowerUsageDetail.EXTRA_DETAIL_TYPES, types);
         args.putDoubleArray(PowerUsageDetail.EXTRA_DETAIL_VALUES, values);
 
-        caller.startPreferencePanelAsUser(PowerUsageDetail.class.getName(), args,
-                R.string.details_title, null, new UserHandle(userId));
+        // This is a workaround, see b/17523189
+        if (userId == UserHandle.myUserId()) {
+            caller.startPreferencePanel(PowerUsageDetail.class.getName(), args,
+                    R.string.details_title, null, null, 0);
+        } else {
+            caller.startPreferencePanelAsUser(PowerUsageDetail.class.getName(), args,
+                    R.string.details_title, null, new UserHandle(userId));
+        }
     }
 
     public static final int ACTION_DISPLAY_SETTINGS = 1;
@@ -644,8 +650,9 @@
         if (mPackages == null) return;
         ActivityManager am = (ActivityManager)getActivity().getSystemService(
                 Context.ACTIVITY_SERVICE);
+        final int userId = UserHandle.getUserId(mUid);
         for (int i = 0; i < mPackages.length; i++) {
-            am.forceStopPackage(mPackages[i]);
+            am.forceStopPackageAsUser(mPackages[i], userId);
         }
         checkForceStop();
     }
diff --git a/src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java b/src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java
index f0f7307..bae9dbc 100644
--- a/src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java
+++ b/src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java
@@ -147,9 +147,10 @@
         mGameControllerCategory = (PreferenceCategory)findPreference(
                 "game_controller_settings_category");
 
+        final Intent startingIntent = activity.getIntent();
         // Filter out irrelevant features if invoked from IME settings button.
         mShowsOnlyFullImeAndKeyboardList = Settings.ACTION_INPUT_METHOD_SETTINGS.equals(
-                activity.getIntent().getAction());
+                startingIntent.getAction());
         if (mShowsOnlyFullImeAndKeyboardList) {
             getPreferenceScreen().removeAll();
             getPreferenceScreen().addPreference(mHardKeyboardCategory);
@@ -182,6 +183,14 @@
         mSettingsObserver = new SettingsObserver(mHandler, activity);
         mDpm = (DevicePolicyManager) (getActivity().
                 getSystemService(Context.DEVICE_POLICY_SERVICE));
+
+        // If we've launched from the keyboard layout notification, go ahead and just show the
+        // keyboard layout dialog.
+        final InputDeviceIdentifier identifier =
+                startingIntent.getParcelableExtra(Settings.EXTRA_INPUT_DEVICE_IDENTIFIER);
+        if (mShowsOnlyFullImeAndKeyboardList && identifier != null) {
+            showKeyboardLayoutDialog(identifier);
+        }
     }
 
     private void updateInputMethodSelectorSummary(int value) {
diff --git a/src/com/android/settings/wifi/AdvancedWifiSettings.java b/src/com/android/settings/wifi/AdvancedWifiSettings.java
index f86cc45..bda13ff 100644
--- a/src/com/android/settings/wifi/AdvancedWifiSettings.java
+++ b/src/com/android/settings/wifi/AdvancedWifiSettings.java
@@ -16,6 +16,8 @@
 
 package com.android.settings.wifi;
 
+import android.app.Dialog;
+import android.app.DialogFragment;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
@@ -151,8 +153,8 @@
         Preference wpsPushPref = findPreference(KEY_WPS_PUSH);
         wpsPushPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                 public boolean onPreferenceClick(Preference arg0) {
-                    WpsDialog wpsDialog = new WpsDialog(context, WpsInfo.PBC);
-                    wpsDialog.show();
+                    WpsFragment wpsFragment = new WpsFragment(WpsInfo.PBC);
+                    wpsFragment.show(getFragmentManager(), KEY_WPS_PUSH);
                     return true;
                 }
         });
@@ -161,8 +163,8 @@
         Preference wpsPinPref = findPreference(KEY_WPS_PIN);
         wpsPinPref.setOnPreferenceClickListener(new OnPreferenceClickListener(){
                 public boolean onPreferenceClick(Preference arg0) {
-                    WpsDialog wpsDialog = new WpsDialog(context, WpsInfo.DISPLAY);
-                    wpsDialog.show();
+                    WpsFragment wpsFragment = new WpsFragment(WpsInfo.DISPLAY);
+                    wpsFragment.show(getFragmentManager(), KEY_WPS_PIN);
                     return true;
                 }
         });
@@ -315,4 +317,24 @@
         wifiIpAddressPref.setSelectable(false);
     }
 
+    /* Wrapper class for the WPS dialog to properly handle life cycle events like rotation. */
+    public static class WpsFragment extends DialogFragment {
+        private static int mWpsSetup;
+
+        // Public default constructor is required for rotation.
+        public WpsFragment() {
+            super();
+        }
+
+        public WpsFragment(int wpsSetup) {
+            super();
+            mWpsSetup = wpsSetup;
+        }
+
+        @Override
+        public Dialog onCreateDialog(Bundle savedInstanceState) {
+            return new WpsDialog(getActivity(), mWpsSetup);
+        }
+    }
+
 }