Merge "Don't clip task windows in some workspaces"
diff --git a/Android.mk b/Android.mk
index b1ca0bc..769a555 100644
--- a/Android.mk
+++ b/Android.mk
@@ -752,6 +752,7 @@
     -since $(SRC_API_DIR)/20.txt 20 \
     -since $(SRC_API_DIR)/21.txt 21 \
     -since $(SRC_API_DIR)/22.txt 22 \
+    -since $(SRC_API_DIR)/23.txt 23 \
 		-werror -hide 111 -hide 113 \
 		-overview $(LOCAL_PATH)/core/java/overview.html
 
@@ -790,7 +791,7 @@
 
 ## SDK version identifiers used in the published docs
   # major[.minor] version for current SDK. (full releases only)
-framework_docs_SDK_VERSION:=5.1
+framework_docs_SDK_VERSION:=6.0
   # release version (ie "Release x")  (full releases only)
 framework_docs_SDK_REL_ID:=1
 
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index a2f2e73..fe79629 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -4316,6 +4316,11 @@
 
             configDiff = mConfiguration.updateFrom(config);
             config = applyCompatConfiguration(mCurDefaultDisplayDpi);
+
+            final Theme systemTheme = getSystemContext().getTheme();
+            if ((systemTheme.getChangingConfigurations() & configDiff) != 0) {
+                systemTheme.rebase();
+            }
         }
 
         ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(false, config);
diff --git a/core/java/android/app/Instrumentation.java b/core/java/android/app/Instrumentation.java
index 69b8b95..dee8d21 100644
--- a/core/java/android/app/Instrumentation.java
+++ b/core/java/android/app/Instrumentation.java
@@ -1809,21 +1809,12 @@
             case ActivityManager.START_NOT_VOICE_COMPATIBLE:
                 throw new SecurityException(
                         "Starting under voice control not allowed for: " + intent);
-            case ActivityManager.START_NOT_CURRENT_USER_ACTIVITY:
-                // Fail silently for this case so we don't break current apps.
-                // TODO(b/22929608): Instead of failing silently or throwing an exception,
-                // we should properly position the activity in the stack (i.e. behind all current
-                // user activity/task) and not change the positioning of stacks.
-                Log.e(TAG,
-                        "Not allowed to start background user activity that shouldn't be displayed"
-                        + " for all users. Failing silently...");
-                break;
             default:
                 throw new AndroidRuntimeException("Unknown error code "
                         + res + " when starting " + intent);
         }
     }
-    
+
     private final void validateNotAppThread() {
         if (Looper.myLooper() == Looper.getMainLooper()) {
             throw new RuntimeException(
diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java
index 5abc645e3..ae92108 100644
--- a/core/java/android/content/res/Resources.java
+++ b/core/java/android/content/res/Resources.java
@@ -1426,10 +1426,12 @@
          *              if not already defined in the theme.
          */
         public void applyStyle(int resId, boolean force) {
-            AssetManager.applyThemeStyle(mTheme, resId, force);
+            synchronized (mKey) {
+                AssetManager.applyThemeStyle(mTheme, resId, force);
 
-            mThemeResId = resId;
-            mKey.append(resId, force);
+                mThemeResId = resId;
+                mKey.append(resId, force);
+            }
         }
 
         /**
@@ -1442,10 +1444,14 @@
          * @param other The existing Theme to copy from.
          */
         public void setTo(Theme other) {
-            AssetManager.copyTheme(mTheme, other.mTheme);
+            synchronized (mKey) {
+                synchronized (other.mKey) {
+                    AssetManager.copyTheme(mTheme, other.mTheme);
 
-            mThemeResId = other.mThemeResId;
-            mKey.setTo(other.getKey());
+                    mThemeResId = other.mThemeResId;
+                    mKey.setTo(other.getKey());
+                }
+            }
         }
 
         /**
@@ -1468,11 +1474,13 @@
          * @see #obtainStyledAttributes(AttributeSet, int[], int, int)
          */
         public TypedArray obtainStyledAttributes(@StyleableRes int[] attrs) {
-            final int len = attrs.length;
-            final TypedArray array = TypedArray.obtain(Resources.this, len);
-            array.mTheme = this;
-            AssetManager.applyStyle(mTheme, 0, 0, 0, attrs, array.mData, array.mIndices);
-            return array;
+            synchronized (mKey) {
+                final int len = attrs.length;
+                final TypedArray array = TypedArray.obtain(Resources.this, len);
+                array.mTheme = this;
+                AssetManager.applyStyle(mTheme, 0, 0, 0, attrs, array.mData, array.mIndices);
+                return array;
+            }
         }
 
         /**
@@ -1482,7 +1490,7 @@
          * <p>Be sure to call {@link TypedArray#recycle() TypedArray.recycle()} when you are done
          * with the array.
          * 
-         * @param resid The desired style resource.
+         * @param resId The desired style resource.
          * @param attrs The desired attributes in the style.
          * 
          * @throws NotFoundException Throws NotFoundException if the given ID does not exist.
@@ -1495,39 +1503,15 @@
          * @see #obtainStyledAttributes(int[])
          * @see #obtainStyledAttributes(AttributeSet, int[], int, int)
          */
-        public TypedArray obtainStyledAttributes(@StyleRes int resid, @StyleableRes int[] attrs)
+        public TypedArray obtainStyledAttributes(@StyleRes int resId, @StyleableRes int[] attrs)
                 throws NotFoundException {
-            final int len = attrs.length;
-            final TypedArray array = TypedArray.obtain(Resources.this, len);
-            array.mTheme = this;
-            if (false) {
-                int[] data = array.mData;
-                
-                System.out.println("**********************************************************");
-                System.out.println("**********************************************************");
-                System.out.println("**********************************************************");
-                System.out.println("Attributes:");
-                String s = "  Attrs:";
-                int i;
-                for (i=0; i<attrs.length; i++) {
-                    s = s + " 0x" + Integer.toHexString(attrs[i]);
-                }
-                System.out.println(s);
-                s = "  Found:";
-                TypedValue value = new TypedValue();
-                for (i=0; i<attrs.length; i++) {
-                    int d = i*AssetManager.STYLE_NUM_ENTRIES;
-                    value.type = data[d+AssetManager.STYLE_TYPE];
-                    value.data = data[d+AssetManager.STYLE_DATA];
-                    value.assetCookie = data[d+AssetManager.STYLE_ASSET_COOKIE];
-                    value.resourceId = data[d+AssetManager.STYLE_RESOURCE_ID];
-                    s = s + " 0x" + Integer.toHexString(attrs[i])
-                        + "=" + value;
-                }
-                System.out.println(s);
+            synchronized (mKey) {
+                final int len = attrs.length;
+                final TypedArray array = TypedArray.obtain(Resources.this, len);
+                array.mTheme = this;
+                AssetManager.applyStyle(mTheme, 0, resId, 0, attrs, array.mData, array.mIndices);
+                return array;
             }
-            AssetManager.applyStyle(mTheme, 0, resid, 0, attrs, array.mData, array.mIndices);
-            return array;
         }
 
         /**
@@ -1580,50 +1564,23 @@
          */
         public TypedArray obtainStyledAttributes(AttributeSet set,
                 @StyleableRes int[] attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
-            final int len = attrs.length;
-            final TypedArray array = TypedArray.obtain(Resources.this, len);
+            synchronized (mKey) {
+                final int len = attrs.length;
+                final TypedArray array = TypedArray.obtain(Resources.this, len);
 
-            // XXX note that for now we only work with compiled XML files.
-            // To support generic XML files we will need to manually parse
-            // out the attributes from the XML file (applying type information
-            // contained in the resources and such).
-            final XmlBlock.Parser parser = (XmlBlock.Parser)set;
-            AssetManager.applyStyle(mTheme, defStyleAttr, defStyleRes,
-                    parser != null ? parser.mParseState : 0, attrs, array.mData, array.mIndices);
+                // XXX note that for now we only work with compiled XML files.
+                // To support generic XML files we will need to manually parse
+                // out the attributes from the XML file (applying type information
+                // contained in the resources and such).
+                final XmlBlock.Parser parser = (XmlBlock.Parser) set;
+                AssetManager.applyStyle(mTheme, defStyleAttr, defStyleRes,
+                        parser != null ? parser.mParseState : 0,
+                        attrs, array.mData, array.mIndices);
+                array.mTheme = this;
+                array.mXml = parser;
 
-            array.mTheme = this;
-            array.mXml = parser;
-
-            if (false) {
-                int[] data = array.mData;
-                
-                System.out.println("Attributes:");
-                String s = "  Attrs:";
-                int i;
-                for (i=0; i<set.getAttributeCount(); i++) {
-                    s = s + " " + set.getAttributeName(i);
-                    int id = set.getAttributeNameResource(i);
-                    if (id != 0) {
-                        s = s + "(0x" + Integer.toHexString(id) + ")";
-                    }
-                    s = s + "=" + set.getAttributeValue(i);
-                }
-                System.out.println(s);
-                s = "  Found:";
-                TypedValue value = new TypedValue();
-                for (i=0; i<attrs.length; i++) {
-                    int d = i*AssetManager.STYLE_NUM_ENTRIES;
-                    value.type = data[d+AssetManager.STYLE_TYPE];
-                    value.data = data[d+AssetManager.STYLE_DATA];
-                    value.assetCookie = data[d+AssetManager.STYLE_ASSET_COOKIE];
-                    value.resourceId = data[d+AssetManager.STYLE_RESOURCE_ID];
-                    s = s + " 0x" + Integer.toHexString(attrs[i])
-                        + "=" + value;
-                }
-                System.out.println(s);
+                return array;
             }
-
-            return array;
         }
 
         /**
@@ -1642,18 +1599,20 @@
          */
         @NonNull
         public TypedArray resolveAttributes(@NonNull int[] values, @NonNull int[] attrs) {
-            final int len = attrs.length;
-            if (values == null || len != values.length) {
-                throw new IllegalArgumentException(
-                        "Base attribute values must the same length as attrs");
+            synchronized (mKey) {
+                final int len = attrs.length;
+                if (values == null || len != values.length) {
+                    throw new IllegalArgumentException(
+                            "Base attribute values must the same length as attrs");
+                }
+
+                final TypedArray array = TypedArray.obtain(Resources.this, len);
+                AssetManager.resolveAttrs(mTheme, 0, 0, values, attrs, array.mData, array.mIndices);
+                array.mTheme = this;
+                array.mXml = null;
+
+                return array;
             }
-
-            final TypedArray array = TypedArray.obtain(Resources.this, len);
-            AssetManager.resolveAttrs(mTheme, 0, 0, values, attrs, array.mData, array.mIndices);
-            array.mTheme = this;
-            array.mXml = null;
-
-            return array;
         }
 
         /**
@@ -1674,14 +1633,9 @@
          *         <var>outValue</var> is valid, else false.
          */
         public boolean resolveAttribute(int resid, TypedValue outValue, boolean resolveRefs) {
-            boolean got = mAssets.getThemeValue(mTheme, resid, outValue, resolveRefs);
-            if (false) {
-                System.out.println(
-                    "resolveAttribute #" + Integer.toHexString(resid)
-                    + " got=" + got + ", type=0x" + Integer.toHexString(outValue.type)
-                    + ", data=0x" + Integer.toHexString(outValue.data));
+            synchronized (mKey) {
+                return mAssets.getThemeValue(mTheme, resid, outValue, resolveRefs);
             }
-            return got;
         }
 
         /**
@@ -1727,8 +1681,11 @@
          * @see ActivityInfo
          */
         public int getChangingConfigurations() {
-            final int nativeChangingConfig = AssetManager.getThemeChangingConfigurations(mTheme);
-            return ActivityInfo.activityInfoConfigNativeToJava(nativeChangingConfig);
+            synchronized (mKey) {
+                final int nativeChangingConfig =
+                        AssetManager.getThemeChangingConfigurations(mTheme);
+                return ActivityInfo.activityInfoConfigNativeToJava(nativeChangingConfig);
+            }
         }
 
         /**
@@ -1739,7 +1696,9 @@
          * @param prefix Text to prefix each line printed.
          */
         public void dump(int priority, String tag, String prefix) {
-            AssetManager.dumpTheme(mTheme, priority, tag, prefix);
+            synchronized (mKey) {
+                AssetManager.dumpTheme(mTheme, priority, tag, prefix);
+            }
         }
 
         @Override
@@ -1789,19 +1748,21 @@
          */
         @ViewDebug.ExportedProperty(category = "theme", hasAdjacentMapping = true)
         public String[] getTheme() {
-            final int N = mKey.mCount;
-            final String[] themes = new String[N * 2];
-            for (int i = 0, j = N - 1; i < themes.length; i += 2, --j) {
-                final int resId = mKey.mResId[j];
-                final boolean forced = mKey.mForce[j];
-                try {
-                    themes[i] = getResourceName(resId);
-                } catch (NotFoundException e) {
-                    themes[i] = Integer.toHexString(i);
+            synchronized (mKey) {
+                final int N = mKey.mCount;
+                final String[] themes = new String[N * 2];
+                for (int i = 0, j = N - 1; i < themes.length; i += 2, --j) {
+                    final int resId = mKey.mResId[j];
+                    final boolean forced = mKey.mForce[j];
+                    try {
+                        themes[i] = getResourceName(resId);
+                    } catch (NotFoundException e) {
+                        themes[i] = Integer.toHexString(i);
+                    }
+                    themes[i + 1] = forced ? "forced" : "not forced";
                 }
-                themes[i + 1] = forced ? "forced" : "not forced";
+                return themes;
             }
-            return themes;
         }
 
         /** @hide */
@@ -1822,13 +1783,15 @@
          * @hide
          */
         public void rebase() {
-            AssetManager.clearTheme(mTheme);
+            synchronized (mKey) {
+                AssetManager.clearTheme(mTheme);
 
-            // Reapply the same styles in the same order.
-            for (int i = 0; i < mKey.mCount; i++) {
-                final int resId = mKey.mResId[i];
-                final boolean force = mKey.mForce[i];
-                AssetManager.applyThemeStyle(mTheme, resId, force);
+                // Reapply the same styles in the same order.
+                for (int i = 0; i < mKey.mCount; i++) {
+                    final int resId = mKey.mResId[i];
+                    final boolean force = mKey.mForce[i];
+                    AssetManager.applyThemeStyle(mTheme, resId, force);
+                }
             }
         }
     }
diff --git a/core/java/com/android/internal/widget/ExploreByTouchHelper.java b/core/java/com/android/internal/widget/ExploreByTouchHelper.java
index 4a23df8..f5637dd 100644
--- a/core/java/com/android/internal/widget/ExploreByTouchHelper.java
+++ b/core/java/com/android/internal/widget/ExploreByTouchHelper.java
@@ -306,7 +306,7 @@
      */
     private AccessibilityEvent createEventForHost(int eventType) {
         final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
-        onInitializeAccessibilityEvent(mView, event);
+        mView.onInitializeAccessibilityEvent(event);
         return event;
     }
 
@@ -368,7 +368,7 @@
      */
     private AccessibilityNodeInfo createNodeForHost() {
         final AccessibilityNodeInfo node = AccessibilityNodeInfo.obtain(mView);
-        onInitializeAccessibilityNodeInfo(mView, node);
+        mView.onInitializeAccessibilityNodeInfo(node);
 
         // Add the virtual descendants.
         if (mTempArray == null) {
@@ -500,7 +500,7 @@
     }
 
     private boolean performActionForHost(int action, Bundle arguments) {
-        return performAccessibilityAction(mView, action, arguments);
+        return mView.performAccessibilityAction(action, arguments);
     }
 
     private boolean performActionForChild(int virtualViewId, int action, Bundle arguments) {
diff --git a/core/java/com/android/internal/widget/NonClientDecorView.java b/core/java/com/android/internal/widget/NonClientDecorView.java
index dd5c5d7..05711b5 100644
--- a/core/java/com/android/internal/widget/NonClientDecorView.java
+++ b/core/java/com/android/internal/widget/NonClientDecorView.java
@@ -21,6 +21,7 @@
 import android.os.RemoteException;
 import android.util.AttributeSet;
 import android.view.View;
+import android.widget.LinearLayout;
 import android.view.ViewGroup;
 import android.view.ViewOutlineProvider;
 import android.view.Window;
@@ -56,7 +57,7 @@
  * </ul>
  * This will be mitigated once b/22527834 will be addressed.
  */
-public class NonClientDecorView extends ViewGroup implements View.OnClickListener {
+public class NonClientDecorView extends LinearLayout implements View.OnClickListener {
     private final static String TAG = "NonClientDecorView";
     // The height of a window which has focus in DIP.
     private final int DECOR_SHADOW_FOCUSED_HEIGHT_IN_DIP = 20;
@@ -91,6 +92,7 @@
         mOwner = owner;
         mWindowHasShadow = windowHasShadow;
         mShowDecor = showDecor;
+        updateCaptionVisibility();
         if (mWindowHasShadow) {
             initializeElevation();
         }
@@ -108,6 +110,7 @@
      **/
     public void phoneWindowUpdated(boolean showDecor, boolean windowHasShadow) {
         mShowDecor = showDecor;
+        updateCaptionVisibility();
         if (windowHasShadow != mWindowHasShadow) {
             mWindowHasShadow = windowHasShadow;
             initializeElevation();
@@ -131,48 +134,17 @@
     }
 
     @Override
-    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
-        measureChildren(widthMeasureSpec, heightMeasureSpec);
-        final int width = MeasureSpec.getSize(widthMeasureSpec);
-        final int height = MeasureSpec.getSize(heightMeasureSpec);
-        setMeasuredDimension(width, height);
-    }
-
-    @Override
     protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
-        // The system inset needs only to be applied to the caption. The client area of
-        // the window will automatically be adjusted by the the DecorView.
-        WindowInsets insets = getRootWindowInsets();
-        int systemMargin = insets.getSystemWindowInsetTop();
-
-        final int leftPos = getPaddingLeft();
-        final int rightPos = right - left - getPaddingRight();
-        final int topPos = getPaddingTop();
-        final int bottomPos = bottom - top - getPaddingBottom();
-
-        // On top we have the caption which has to fill left to right with a fixed height.
-        final int width = rightPos - leftPos;
-        final View caption = getChildAt(0);
-
         // If the application changed its SystemUI metrics, we might also have to adapt
         // our shadow elevation.
         updateElevation();
         mAllowUpdateElevation = true;
 
-        // Don't show the decor if the window has e.g. entered full screen.
-        final int captionHeight =
-                (isFillingScreen() || !mShowDecor) ? 0 : caption.getMeasuredHeight();
-        caption.layout(leftPos, topPos + systemMargin, leftPos + width,
-                topPos + systemMargin + captionHeight);
-
-        // Note: We should never have more then 1 additional item in here.
-        if (getChildCount() > 1) {
-            getChildAt(1).layout(leftPos, topPos + captionHeight, leftPos + width, bottomPos);
-        }
+        super.onLayout(changed, left, top, right, bottom);
     }
 
     @Override
-    public void addView(View child, int index, LayoutParams params) {
+    public void addView(View child, int index, ViewGroup.LayoutParams params) {
         // Make sure that we never get more then one client area in our view.
         if (index >= 2 || getChildCount() >= 2) {
             throw new IllegalStateException("NonClientDecorView can only handle 1 client view");
@@ -191,6 +163,16 @@
     }
 
     /**
+     * Updates the visibility of the caption.
+     **/
+    private void updateCaptionVisibility() {
+        // Don't show the decor if the window has e.g. entered full screen.
+        boolean invisible = isFillingScreen() || !mShowDecor;
+        View caption = getChildAt(0);
+        caption.setVisibility(invisible ? GONE : VISIBLE);
+    }
+
+    /**
      * The elevation gets set for the first time and the framework needs to be informed that
      * the surface layer gets created with the shadow size in mind.
      **/
diff --git a/core/res/res/layout/non_client_decor_dark.xml b/core/res/res/layout/non_client_decor_dark.xml
index 00b4255..d1e2974 100644
--- a/core/res/res/layout/non_client_decor_dark.xml
+++ b/core/res/res/layout/non_client_decor_dark.xml
@@ -20,8 +20,7 @@
 <com.android.internal.widget.NonClientDecorView xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical"
     android:layout_width="match_parent"
-    android:layout_height="wrap_content"
-    android:layout_gravity="top|start"
+    android:layout_height="match_parent"
     android:descendantFocusability="beforeDescendants" >
     <LinearLayout
         android:layout_width="match_parent"
diff --git a/core/res/res/layout/non_client_decor_light.xml b/core/res/res/layout/non_client_decor_light.xml
index 0ce8fa7..f7c3fcd 100644
--- a/core/res/res/layout/non_client_decor_light.xml
+++ b/core/res/res/layout/non_client_decor_light.xml
@@ -20,8 +20,7 @@
 <com.android.internal.widget.NonClientDecorView xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical"
     android:layout_width="match_parent"
-    android:layout_height="wrap_content"
-    android:layout_gravity="top|start"
+    android:layout_height="match_parent"
     android:descendantFocusability="beforeDescendants" >
     <LinearLayout
         android:layout_width="match_parent"
diff --git a/core/tests/inputmethodtests/src/android/os/CursorAnchorInfoTest.java b/core/tests/coretests/src/android/view/inputmethod/CursorAnchorInfoTest.java
similarity index 99%
rename from core/tests/inputmethodtests/src/android/os/CursorAnchorInfoTest.java
rename to core/tests/coretests/src/android/view/inputmethod/CursorAnchorInfoTest.java
index d4244ba..e0664d9 100644
--- a/core/tests/inputmethodtests/src/android/os/CursorAnchorInfoTest.java
+++ b/core/tests/coretests/src/android/view/inputmethod/CursorAnchorInfoTest.java
@@ -14,14 +14,14 @@
  * limitations under the License.
  */
 
-package android.os;
+package android.view.inputmethod;
 
 import android.graphics.Matrix;
 import android.graphics.RectF;
+import android.os.Parcel;
 import android.test.InstrumentationTestCase;
 import android.test.suitebuilder.annotation.SmallTest;
 import android.text.TextUtils;
-import android.view.inputmethod.CursorAnchorInfo;
 import android.view.inputmethod.CursorAnchorInfo.Builder;
 
 import java.util.Objects;
diff --git a/core/tests/inputmethodtests/src/android/os/InputMethodSubtypeArrayTest.java b/core/tests/coretests/src/android/view/inputmethod/InputMethodSubtypeArrayTest.java
similarity index 95%
rename from core/tests/inputmethodtests/src/android/os/InputMethodSubtypeArrayTest.java
rename to core/tests/coretests/src/android/view/inputmethod/InputMethodSubtypeArrayTest.java
index 1e0a919..a339f61 100644
--- a/core/tests/inputmethodtests/src/android/os/InputMethodSubtypeArrayTest.java
+++ b/core/tests/coretests/src/android/view/inputmethod/InputMethodSubtypeArrayTest.java
@@ -14,12 +14,11 @@
  * limitations under the License.
  */
 
-package android.os;
+package android.view.inputmethod;
 
+import android.os.Parcel;
 import android.test.InstrumentationTestCase;
 import android.test.suitebuilder.annotation.SmallTest;
-import android.view.inputmethod.InputMethodSubtype;
-import android.view.inputmethod.InputMethodSubtypeArray;
 import android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder;
 
 import java.util.ArrayList;
diff --git a/core/tests/inputmethodtests/src/android/os/InputMethodSubtypeTest.java b/core/tests/coretests/src/android/view/inputmethod/InputMethodSubtypeTest.java
similarity index 97%
rename from core/tests/inputmethodtests/src/android/os/InputMethodSubtypeTest.java
rename to core/tests/coretests/src/android/view/inputmethod/InputMethodSubtypeTest.java
index 8feac9b..0adac4c 100644
--- a/core/tests/inputmethodtests/src/android/os/InputMethodSubtypeTest.java
+++ b/core/tests/coretests/src/android/view/inputmethod/InputMethodSubtypeTest.java
@@ -14,11 +14,11 @@
  * limitations under the License.
  */
 
-package android.os;
+package android.view.inputmethod;
 
+import android.os.Parcel;
 import android.test.InstrumentationTestCase;
 import android.test.suitebuilder.annotation.SmallTest;
-import android.view.inputmethod.InputMethodSubtype;
 import android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder;
 
 import java.util.Objects;
diff --git a/core/tests/inputmethodtests/src/android/os/SparseRectFArrayTest.java b/core/tests/coretests/src/android/view/inputmethod/SparseRectFArrayTest.java
similarity index 99%
rename from core/tests/inputmethodtests/src/android/os/SparseRectFArrayTest.java
rename to core/tests/coretests/src/android/view/inputmethod/SparseRectFArrayTest.java
index 47b0d2a..f9fa017 100644
--- a/core/tests/inputmethodtests/src/android/os/SparseRectFArrayTest.java
+++ b/core/tests/coretests/src/android/view/inputmethod/SparseRectFArrayTest.java
@@ -14,12 +14,12 @@
  * limitations under the License.
  */
 
-package android.os;
+package android.view.inputmethod;
 
 import android.graphics.RectF;
+import android.os.Parcel;
 import android.test.InstrumentationTestCase;
 import android.test.suitebuilder.annotation.SmallTest;
-import android.view.inputmethod.SparseRectFArray;
 import android.view.inputmethod.SparseRectFArray.SparseRectFArrayBuilder;
 
 import java.util.Objects;
diff --git a/core/tests/inputmethodtests/src/android/os/InputMethodSubtypeSwitchingControllerTest.java b/core/tests/coretests/src/com/android/internal/inputmethod/InputMethodSubtypeSwitchingControllerTest.java
similarity index 99%
rename from core/tests/inputmethodtests/src/android/os/InputMethodSubtypeSwitchingControllerTest.java
rename to core/tests/coretests/src/com/android/internal/inputmethod/InputMethodSubtypeSwitchingControllerTest.java
index 3a598f2..ec5220f 100644
--- a/core/tests/inputmethodtests/src/android/os/InputMethodSubtypeSwitchingControllerTest.java
+++ b/core/tests/coretests/src/com/android/internal/inputmethod/InputMethodSubtypeSwitchingControllerTest.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package android.os;
+package com.android.internal.inputmethod;
 
 import android.content.pm.ApplicationInfo;
 import android.content.pm.ResolveInfo;
diff --git a/core/tests/inputmethodtests/src/android/os/InputMethodTest.java b/core/tests/coretests/src/com/android/internal/inputmethod/InputMethodUtilsTest.java
similarity index 98%
rename from core/tests/inputmethodtests/src/android/os/InputMethodTest.java
rename to core/tests/coretests/src/com/android/internal/inputmethod/InputMethodUtilsTest.java
index 31a4703..67f87a3 100644
--- a/core/tests/inputmethodtests/src/android/os/InputMethodTest.java
+++ b/core/tests/coretests/src/com/android/internal/inputmethod/InputMethodUtilsTest.java
@@ -14,26 +14,25 @@
  * limitations under the License.
  */
 
-package android.os;
+package com.android.internal.inputmethod;
 
 import android.content.Context;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.ResolveInfo;
 import android.content.pm.ServiceInfo;
+import android.os.Parcel;
 import android.test.InstrumentationTestCase;
 import android.test.suitebuilder.annotation.SmallTest;
 import android.view.inputmethod.InputMethodInfo;
 import android.view.inputmethod.InputMethodSubtype;
 import android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder;
 
-import com.android.internal.inputmethod.InputMethodUtils;
-
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
 import java.util.Objects;
 
-public class InputMethodTest extends InstrumentationTestCase {
+public class InputMethodUtilsTest extends InstrumentationTestCase {
     private static final boolean IS_AUX = true;
     private static final boolean IS_DEFAULT = true;
     private static final boolean IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE = true;
diff --git a/core/tests/inputmethodtests/Android.mk b/core/tests/inputmethodtests/Android.mk
deleted file mode 100644
index 4631e65..0000000
--- a/core/tests/inputmethodtests/Android.mk
+++ /dev/null
@@ -1,18 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-# We only want this apk build for tests.
-LOCAL_MODULE_TAGS := tests
-
-# Include all test java files.
-LOCAL_SRC_FILES := \
-	$(call all-java-files-under, src)
-
-LOCAL_DX_FLAGS := --core-library
-LOCAL_STATIC_JAVA_LIBRARIES := core-tests android-common frameworks-core-util-lib
-LOCAL_JAVA_LIBRARIES := android.test.runner
-LOCAL_PACKAGE_NAME := FrameworksCoreInputMethodTests
-
-LOCAL_CERTIFICATE := platform
-
-include $(BUILD_PACKAGE)
diff --git a/core/tests/inputmethodtests/AndroidManifest.xml b/core/tests/inputmethodtests/AndroidManifest.xml
deleted file mode 100644
index 7f0b1aa..0000000
--- a/core/tests/inputmethodtests/AndroidManifest.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2013 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
-          android:installLocation="internalOnly"
-          package="com.android.frameworks.coretests.inputmethod"
-          android:sharedUserId="android.uid.system">
-
-    <application>
-        <uses-library android:name="android.test.runner" />
-    </application>
-
-    <instrumentation android:name="android.test.InstrumentationTestRunner"
-            android:targetPackage="com.android.frameworks.coretests.inputmethod"
-            android:label="Frameworks InputMethod Core Tests" />
-
-</manifest>
diff --git a/core/tests/inputmethodtests/run_core_inputmethod_test.sh b/core/tests/inputmethodtests/run_core_inputmethod_test.sh
deleted file mode 100755
index a11e49b..0000000
--- a/core/tests/inputmethodtests/run_core_inputmethod_test.sh
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/bin/bash
-
-while [[ $# -gt 0 ]]; do
-  case "$1" in
-  --rebuild ) echo Rebuild && rebuild=true;;
-  * ) com_opts+=($1);;
-  esac
-  shift
-done
-
-if [[ -z $ANDROID_PRODUCT_OUT && $rebuilld == true ]]; then
-  echo You must lunch before running this test.
-  exit 0
-fi
-
-if [[ $rebuild == true ]]; then
-  make -j4 FrameworksCoreInputMethodTests
-  TESTAPP=${ANDROID_PRODUCT_OUT}/data/app/FrameworksCoreInputMethodTests/FrameworksCoreInputMethodTests.apk
-  COMMAND="adb install -r $TESTAPP"
-  echo $COMMAND
-  $COMMAND
-fi
-
-adb shell am instrument -w -e class android.os.InputMethodTest,android.os.InputMethodSubtypeTest,android.os.InputMethodSubtypeArrayTest,android.os.InputMethodSubtypeSwitchingControllerTest,android.os.CursorAnchorInfoTest,android.os.SparseRectFArrayTest com.android.frameworks.coretests.inputmethod/android.test.InstrumentationTestRunner
diff --git a/docs/html/guide/topics/manifest/uses-sdk-element.jd b/docs/html/guide/topics/manifest/uses-sdk-element.jd
index 3ac87ef..642b820 100644
--- a/docs/html/guide/topics/manifest/uses-sdk-element.jd
+++ b/docs/html/guide/topics/manifest/uses-sdk-element.jd
@@ -19,7 +19,6 @@
       <li><a href="#testing">Testing against higher API Levels</a></li>
     </ol>
   </li>
-  <li><a href="#provisional">Using a Provisional API Level</a></li>
   <li><a href="#filtering">Filtering the Reference Documentation by API Level</a></li>
 </ol>
 </div>
@@ -227,6 +226,11 @@
 <table>
   <tr><th>Platform Version</th><th>API Level</th><th>VERSION_CODE</th><th>Notes</th></tr>
 
+    <tr><td>Android 6.0</td>
+    <td><a href="{@docRoot}sdk/api_diff/23/changes.html" title="Diff Report">23</a></td>
+    <td>{@link android.os.Build.VERSION_CODES#M}</td>
+    <td><a href="{@docRoot}preview/api-overview.html">API Changes</a></td></tr>
+
     <tr><td><a href="{@docRoot}about/versions/android-5.1.html">Android 5.1</a></td>
     <td><a href="{@docRoot}sdk/api_diff/22/changes.html" title="Diff Report">22</a></td>
     <td>{@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}</td>
@@ -552,29 +556,6 @@
 of the Android platform it runs. See the table at the top of this document for
 a list of platform versions and their API Levels. </p>
 
-<h2 id="provisional">Using a Provisional API Level</h2>
-
-<p>In some cases, an "Early Look" Android SDK platform may be available. To let
-you begin developing on the platform although the APIs may not be final, the
-platform's API Level integer will not be specified. You must instead use the
-platform's <em>provisional API Level</em> in your application manifest, in order
-to build applications against the platform. A provisional API Level is not an
-integer, but a string matching the codename of the unreleased platform version.
-The provisional API Level will be specified in the release notes for the Early
-Look SDK release notes and is case-sensitive.</p>
-
-<p>The use of a provisional API Level is designed to protect developers and
-device users from inadvertently publishing or installing applications based on
-the Early Look framework API, which may not run properly on actual devices
-running the final system image.</p>
-
-<p>The provisional API Level will only be valid while using the Early Look SDK
-and can only be used to run applications in the emulator. An application using
-the provisional API Level can never be installed on an Android device. At the
-final release of the platform, you must replace any instances of the provisional
-API Level in your application manifest with the final platform's actual API
-Level integer.</p>
-
 
 <h2 id="filtering">Filtering the Reference Documentation by API Level</h2>
 
diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java
index 0c6c067..18a0a36 100644
--- a/services/core/java/com/android/server/am/ActivityStack.java
+++ b/services/core/java/com/android/server/am/ActivityStack.java
@@ -363,8 +363,7 @@
     }
 
     boolean okToShowLocked(ActivityRecord r) {
-        return mStackSupervisor.isCurrentProfileLocked(r.userId)
-                || (r.info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0;
+        return mStackSupervisor.okToShowLocked(r);
     }
 
     final ActivityRecord topRunningActivityLocked(ActivityRecord notTop) {
@@ -690,6 +689,13 @@
                 "Launch completed; removing icicle of " + r.icicle);
     }
 
+    private void addRecentActivityLocked(ActivityRecord r) {
+        if (r != null) {
+            mRecentTasks.addLocked(r.task);
+            r.task.touchActiveTime();
+        }
+    }
+
     private void startLaunchTraces(String packageName) {
         if (mFullyDrawnStartTime != 0)  {
             Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0);
@@ -2285,6 +2291,8 @@
 
         if (doResume) {
             mStackSupervisor.resumeTopActivitiesLocked(this, r, options);
+        } else {
+            addRecentActivityLocked(r);
         }
     }
 
@@ -3730,6 +3738,14 @@
         // of the stack, keeping them in the same internal order.
         insertTaskAtTop(tr, null);
 
+        // Don't refocus if invisible to current user
+        ActivityRecord top = tr.getTopActivity();
+        if (!okToShowLocked(top)) {
+            addRecentActivityLocked(top);
+            ActivityOptions.abort(options);
+            return;
+        }
+
         // Set focus to the top running activity of this stack.
         ActivityRecord r = topRunningActivityLocked(null);
         mService.setFocusedActivityLocked(r, reason);
diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
index 2e9272c..a449baf 100644
--- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java
+++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
@@ -1499,13 +1499,6 @@
             err = ActivityManager.START_CLASS_NOT_FOUND;
         }
 
-        if (err == ActivityManager.START_SUCCESS
-                && !isCurrentProfileLocked(userId)
-                && (aInfo.flags & FLAG_SHOW_FOR_ALL_USERS) == 0) {
-            // Trying to launch a background activity that doesn't show for all users.
-            err = ActivityManager.START_NOT_CURRENT_USER_ACTIVITY;
-        }
-
         if (err == ActivityManager.START_SUCCESS && sourceRecord != null
                 && sourceRecord.task.voiceSession != null) {
             // If this activity is being launched as part of a voice session, we need
@@ -1922,8 +1915,9 @@
         // If the caller has asked not to resume at this point, we make note
         // of this in the record so that we can skip it when trying to find
         // the top running activity.
-        if (!doResume) {
+        if (!doResume || !okToShowLocked(r)) {
             r.delayedResume = true;
+            doResume = false;
         }
 
         ActivityRecord notTop =
@@ -2128,7 +2122,7 @@
                             options = null;
                         }
                     }
-                    if (!movedToFront) {
+                    if (!movedToFront && doResume) {
                         if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Bring to front target: " + targetStack
                                 + " from " + intentActivity);
                         targetStack.moveToFront("intentActivityFound");
@@ -2155,6 +2149,7 @@
                         } else {
                             ActivityOptions.abort(options);
                         }
+                        updateUserStackLocked(r.userId, targetStack);
                         return ActivityManager.START_RETURN_INTENT_TO_CALLER;
                     }
                     if ((launchFlags & (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK))
@@ -2257,6 +2252,7 @@
                         } else {
                             ActivityOptions.abort(options);
                         }
+                        updateUserStackLocked(r.userId, targetStack);
                         return ActivityManager.START_TASK_TO_FRONT;
                     }
                 }
@@ -2322,7 +2318,9 @@
                 && (launchFlags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
             newTask = true;
             targetStack = computeStackFocus(r, newTask);
-            targetStack.moveToFront("startingNewTask");
+            if (doResume) {
+                targetStack.moveToFront("startingNewTask");
+            }
 
             if (reuseTask == null) {
                 r.setTask(targetStack.createTaskRecord(getNextTaskId(),
@@ -2355,7 +2353,9 @@
                 return ActivityManager.START_RETURN_LOCK_TASK_MODE_VIOLATION;
             }
             targetStack = sourceTask.stack;
-            targetStack.moveToFront("sourceStackToFront");
+            if (doResume) {
+                targetStack.moveToFront("sourceStackToFront");
+            }
             final TaskRecord topTask = targetStack.topTask();
             if (topTask != sourceTask) {
                 targetStack.moveTaskToFrontLocked(sourceTask, noAnimation, options,
@@ -2450,7 +2450,9 @@
             // of a new task...  just put it in the top task, though these days
             // this case should never happen.
             targetStack = computeStackFocus(r, newTask);
-            targetStack.moveToFront("addingToTopTask");
+            if (doResume) {
+                targetStack.moveToFront("addingToTopTask");
+            }
             ActivityRecord prev = targetStack.topActivity();
             r.setTask(prev != null ? prev.task : targetStack.createTaskRecord(getNextTaskId(),
                             r.info, intent, null, null, true), null);
@@ -2471,10 +2473,10 @@
         ActivityStack.logStartActivity(EventLogTags.AM_CREATE_ACTIVITY, r, r.task);
         targetStack.mLastPausedActivity = null;
         targetStack.startActivityLocked(r, newTask, doResume, keepCurTransition, options);
-        if (!launchTaskBehind) {
-            // Don't set focus on an activity that's going to the back.
+        if (!launchTaskBehind && doResume) {
             mService.setFocusedActivityLocked(r, "startedActivity");
         }
+        updateUserStackLocked(r.userId, targetStack);
         return ActivityManager.START_SUCCESS;
     }
 
@@ -2676,6 +2678,16 @@
     }
 
     /**
+     * Update the last used stack id for non-current user (current user's last
+     * used stack is the focused stack)
+     */
+    void updateUserStackLocked(int userId, ActivityStack stack) {
+        if (userId != mCurrentUser) {
+            mUserStackInFront.put(userId, stack != null ? stack.getStackId() : HOME_STACK_ID);
+        }
+    }
+
+    /**
      * @return true if some activity was finished (or would have finished if doit were true).
      */
     boolean finishDisabledPackageActivitiesLocked(String packageName, Set<String> filterByClasses,
@@ -3511,6 +3523,12 @@
         return false;
     }
 
+    /** Checks whether the activity should be shown for current user. */
+    boolean okToShowLocked(ActivityRecord r) {
+        return r != null && (isCurrentProfileLocked(r.userId)
+                || (r.info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0);
+    }
+
     final ArrayList<ActivityRecord> processStoppingActivitiesLocked(boolean remove) {
         ArrayList<ActivityRecord> stops = null;
 
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index 6b35f6a..ed32c76 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -1040,6 +1040,12 @@
         w.getDefaultDisplay().getMetrics(metrics);
         context.getResources().updateConfiguration(config, metrics);
 
+        // The system context's theme may be configuration-dependent.
+        final Theme systemTheme = context.getTheme();
+        if (systemTheme.getChangingConfigurations() != 0) {
+            systemTheme.rebase();
+        }
+
         try {
             // TODO: use boot phase
             mPowerManagerService.systemReady(mActivityManagerService.getAppOpsService());