Merge "Canceling expand animations as well when starting QS expansion" into mnc-dev
diff --git a/api/current.txt b/api/current.txt
index 7c22e4e..90e44e7 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -5852,7 +5852,6 @@
     field public static final java.lang.String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED = "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
     field public static final java.lang.String EXTRA_PROVISIONING_LOCALE = "android.app.extra.PROVISIONING_LOCALE";
     field public static final java.lang.String EXTRA_PROVISIONING_LOCAL_TIME = "android.app.extra.PROVISIONING_LOCAL_TIME";
-    field public static final java.lang.String EXTRA_PROVISIONING_RESET_PROTECTION_PARAMETERS = "android.app.extra.PROVISIONING_RESET_PROTECTION_PARAMETERS";
     field public static final java.lang.String EXTRA_PROVISIONING_SKIP_ENCRYPTION = "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
     field public static final java.lang.String EXTRA_PROVISIONING_TIME_ZONE = "android.app.extra.PROVISIONING_TIME_ZONE";
     field public static final java.lang.String EXTRA_PROVISIONING_WIFI_HIDDEN = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
@@ -36818,6 +36817,8 @@
     method public boolean onRequestSendAccessibilityEvent(android.view.View, android.view.accessibility.AccessibilityEvent);
     method public boolean onStartNestedScroll(android.view.View, android.view.View, int);
     method public void onStopNestedScroll(android.view.View);
+    method public void onViewAdded(android.view.View);
+    method public void onViewRemoved(android.view.View);
     method public void recomputeViewAttributes(android.view.View);
     method public void removeAllViews();
     method public void removeAllViewsInLayout();
diff --git a/api/system-current.txt b/api/system-current.txt
index 67d3635..8a99eaf 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -5969,7 +5969,6 @@
     field public static final java.lang.String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED = "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
     field public static final java.lang.String EXTRA_PROVISIONING_LOCALE = "android.app.extra.PROVISIONING_LOCALE";
     field public static final java.lang.String EXTRA_PROVISIONING_LOCAL_TIME = "android.app.extra.PROVISIONING_LOCAL_TIME";
-    field public static final java.lang.String EXTRA_PROVISIONING_RESET_PROTECTION_PARAMETERS = "android.app.extra.PROVISIONING_RESET_PROTECTION_PARAMETERS";
     field public static final java.lang.String EXTRA_PROVISIONING_SKIP_ENCRYPTION = "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
     field public static final java.lang.String EXTRA_PROVISIONING_TIME_ZONE = "android.app.extra.PROVISIONING_TIME_ZONE";
     field public static final java.lang.String EXTRA_PROVISIONING_WIFI_HIDDEN = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
@@ -30918,7 +30917,6 @@
     method public abstract byte[] read() throws android.os.RemoteException;
     method public abstract void setOemUnlockEnabled(boolean) throws android.os.RemoteException;
     method public abstract void wipe() throws android.os.RemoteException;
-    method public abstract void wipeIfAllowed(android.os.Bundle, android.app.PendingIntent) throws android.os.RemoteException;
     method public abstract int write(byte[]) throws android.os.RemoteException;
   }
 
@@ -30930,14 +30928,7 @@
     method public byte[] read();
     method public void setOemUnlockEnabled(boolean);
     method public void wipe();
-    method public void wipeIfAllowed(android.os.Bundle, android.app.PendingIntent);
     method public int write(byte[]);
-    field public static final java.lang.String ACTION_WIPE_IF_ALLOWED = "android.service.persistentdata.action.WIPE_IF_ALLOWED";
-    field public static final java.lang.String EXTRA_WIPE_IF_ALLOWED_CALLBACK = "android.service.persistentdata.extra.WIPE_IF_ALLOWED_CALLBACK";
-    field public static final int STATUS_ERROR_NETWORK_ERROR = 2; // 0x2
-    field public static final int STATUS_ERROR_NOT_COMPLIANT = 3; // 0x3
-    field public static final int STATUS_ERROR_REMOTE_EXCEPTION = 1; // 0x1
-    field public static final int STATUS_SUCCESS = 0; // 0x0
   }
 
 }
@@ -39106,6 +39097,8 @@
     method public boolean onRequestSendAccessibilityEvent(android.view.View, android.view.accessibility.AccessibilityEvent);
     method public boolean onStartNestedScroll(android.view.View, android.view.View, int);
     method public void onStopNestedScroll(android.view.View);
+    method public void onViewAdded(android.view.View);
+    method public void onViewRemoved(android.view.View);
     method public void recomputeViewAttributes(android.view.View);
     method public void removeAllViews();
     method public void removeAllViewsInLayout();
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index ed20086..b9862ca 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -552,19 +552,6 @@
         = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_SIGNATURE_CHECKSUM";
 
     /**
-     * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
-     * holds data needed by the system to wipe factory reset protection. The data needed to wipe
-     * the device depend on the installed factory reset protection implementation. For example,
-     * if an account is needed to unlock a device, this extra may contain data used to
-     * authenticate that account.
-     *
-     * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
-     * provisioning via an NFC bump.
-     */
-    public static final String EXTRA_PROVISIONING_RESET_PROTECTION_PARAMETERS
-            = "android.app.extra.PROVISIONING_RESET_PROTECTION_PARAMETERS";
-
-    /**
      * This MIME type is used for starting the Device Owner provisioning that does not require
      * provisioning features introduced in Android API level
      * {@link android.os.Build.VERSION_CODES#MNC} or later levels.
diff --git a/core/java/android/service/persistentdata/IPersistentDataBlockService.aidl b/core/java/android/service/persistentdata/IPersistentDataBlockService.aidl
index 0071a33..52db223 100644
--- a/core/java/android/service/persistentdata/IPersistentDataBlockService.aidl
+++ b/core/java/android/service/persistentdata/IPersistentDataBlockService.aidl
@@ -16,8 +16,6 @@
 
 package android.service.persistentdata;
 
-import android.app.PendingIntent;
-import android.os.Bundle;
 import android.os.ParcelFileDescriptor;
 
 /**
@@ -32,7 +30,6 @@
     int write(in byte[] data);
     byte[] read();
     void wipe();
-    void wipeIfAllowed(in Bundle bundle, in PendingIntent pi);
     int getDataBlockSize();
     long getMaximumDataBlockSize();
 
diff --git a/core/java/android/service/persistentdata/PersistentDataBlockManager.java b/core/java/android/service/persistentdata/PersistentDataBlockManager.java
index 31570c6..0ffdf68 100644
--- a/core/java/android/service/persistentdata/PersistentDataBlockManager.java
+++ b/core/java/android/service/persistentdata/PersistentDataBlockManager.java
@@ -17,8 +17,6 @@
 package android.service.persistentdata;
 
 import android.annotation.SystemApi;
-import android.app.PendingIntent;
-import android.os.Bundle;
 import android.os.RemoteException;
 import android.util.Slog;
 
@@ -43,56 +41,6 @@
 @SystemApi
 public class PersistentDataBlockManager {
     private static final String TAG = PersistentDataBlockManager.class.getSimpleName();
-
-    /**
-     * Broadcast action that will be called when the {@link #wipeIfAllowed(Bundle,PendingIntent)}
-     * method is called.  A broadcast with this action will be sent to the package allowed to write
-     * to the persistent data block. Packages receiving this broadcasts should respond by using the
-     * {@link android.app.PendingIntent} sent in the {@link #EXTRA_WIPE_IF_ALLOWED_CALLBACK} extra.
-     */
-    public static final String ACTION_WIPE_IF_ALLOWED
-            = "android.service.persistentdata.action.WIPE_IF_ALLOWED";
-
-    /**
-     * A {@link android.os.Parcelable} extra of type {@link android.app.PendingIntent} used to
-     * response to {@link #wipeIfAllowed(Bundle,PendingIntent)}. This extra will set in broadcasts
-     * with an action of {@link #ACTION_WIPE_IF_ALLOWED}.
-     */
-    public static final String EXTRA_WIPE_IF_ALLOWED_CALLBACK
-            = "android.service.persistentdata.extra.WIPE_IF_ALLOWED_CALLBACK";
-
-    /**
-     * Result code indicating that the data block was wiped.
-     *
-     * <p>This value is set as result code of the {@link android.app.PendingIntent} argument to
-     * {@link #wipeIfAllowed(Bundle,PendingIntent)}
-     */
-    public static final int STATUS_SUCCESS = 0;
-
-    /**
-     * Result code indicating that a remote exception was received while processing the request.
-     *
-     * <p>This value is set as result code of the {@link android.app.PendingIntent} argument to
-     * {@link #wipeIfAllowed(Bundle,PendingIntent)}
-     */
-    public static final int STATUS_ERROR_REMOTE_EXCEPTION = 1;
-
-    /**
-     * Result code indicating that a network error occurred while processing the request.
-     *
-     * <p>This value is set as result code of the {@link android.app.PendingIntent} argument to
-     * {@link #wipeIfAllowed(Bundle,PendingIntent)}
-     */
-    public static final int STATUS_ERROR_NETWORK_ERROR = 2;
-
-    /**
-     * Result code indicating that the data block could not be cleared with the provided data.
-     *
-     * <p>This value is set as result code of the {@link android.app.PendingIntent} argument to
-     * {@link #wipeIfAllowed(Bundle,PendingIntent)}
-     */
-    public static final int STATUS_ERROR_NOT_COMPLIANT = 3;
-
     private IPersistentDataBlockService sService;
 
     public PersistentDataBlockManager(IPersistentDataBlockService service) {
@@ -170,28 +118,6 @@
     }
 
     /**
-     * Attempt to wipe the data block by sending a broadcast to the package allowed to modify the
-     * datablock. The allowed package can refuse to wipe the data block based on the contents of
-     * the specified bundle. This bundle may contain data used by the allowed package to wipe the
-     * partition such as account credentials or an authorization token.
-     * @param bundle data used to wipe the data block. The contents of this bundle depend on the
-     *    allowed package receiving the data.
-     * @param pi intent called when attempt finished. The result code of this intent will be set
-     *    to one of {@link #STATUS_SUCCESS}, {@link #STATUS_ERROR_REMOTE_EXCEPTION},
-     *    {@link #STATUS_ERROR_NETWORK_ERROR}, or {@link #STATUS_ERROR_NOT_COMPLIANT}.
-     */
-    public void wipeIfAllowed(Bundle bundle, PendingIntent pi) {
-        if (pi == null) {
-            throw new NullPointerException();
-        }
-        try {
-            sService.wipeIfAllowed(bundle, pi);
-        } catch (RemoteException e) {
-            onError("wiping persistent partition");
-        }
-    }
-
-    /**
      * Writes a byte enabling or disabling the ability to "OEM unlock" the device.
      */
     public void setOemUnlockEnabled(boolean enabled) {
diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java
index 73cfd8c..2e2ba88 100644
--- a/core/java/android/view/ViewGroup.java
+++ b/core/java/android/view/ViewGroup.java
@@ -4148,24 +4148,38 @@
         mOnHierarchyChangeListener = listener;
     }
 
-    /**
-     * @hide
-     */
-    protected void onViewAdded(View child) {
+    void dispatchViewAdded(View child) {
+        onViewAdded(child);
         if (mOnHierarchyChangeListener != null) {
             mOnHierarchyChangeListener.onChildViewAdded(this, child);
         }
     }
 
     /**
-     * @hide
+     * Called when a new child is added to this ViewGroup. Overrides should always
+     * call super.onViewAdded.
+     *
+     * @param child the added child view
      */
-    protected void onViewRemoved(View child) {
+    public void onViewAdded(View child) {
+    }
+
+    void dispatchViewRemoved(View child) {
+        onViewRemoved(child);
         if (mOnHierarchyChangeListener != null) {
             mOnHierarchyChangeListener.onChildViewRemoved(this, child);
         }
     }
 
+    /**
+     * Called when a child view is removed from this ViewGroup. Overrides should always
+     * call super.onViewRemoved.
+     *
+     * @param child the removed child view
+     */
+    public void onViewRemoved(View child) {
+    }
+
     private void clearCachedLayoutMode() {
         if (!hasBooleanFlag(FLAG_LAYOUT_MODE_WAS_EXPLICITLY_SET)) {
            mLayoutMode = LAYOUT_MODE_UNDEFINED;
@@ -4292,7 +4306,7 @@
             child.resetRtlProperties();
         }
 
-        onViewAdded(child);
+        dispatchViewAdded(child);
 
         if ((child.mViewFlags & DUPLICATE_PARENT_STATE) == DUPLICATE_PARENT_STATE) {
             mGroupFlags |= FLAG_NOTIFY_CHILDREN_ON_DRAWABLE_STATE_CHANGE;
@@ -4554,7 +4568,7 @@
             }
         }
 
-        onViewRemoved(view);
+        dispatchViewRemoved(view);
 
         if (view.getVisibility() != View.GONE) {
             notifySubtreeAccessibilityStateChangedIfNeeded();
@@ -4646,7 +4660,7 @@
 
             needGlobalAttributesUpdate(false);
 
-            onViewRemoved(view);
+            dispatchViewRemoved(view);
         }
 
         removeFromArray(start, count);
@@ -4729,7 +4743,7 @@
                 childHasTransientStateChanged(view, false);
             }
 
-            onViewRemoved(view);
+            dispatchViewRemoved(view);
 
             view.mParent = null;
             children[i] = null;
@@ -4788,7 +4802,7 @@
             childHasTransientStateChanged(child, false);
         }
 
-        onViewRemoved(child);
+        dispatchViewRemoved(child);
     }
 
     /**
diff --git a/core/java/android/view/accessibility/AccessibilityInteractionClient.java b/core/java/android/view/accessibility/AccessibilityInteractionClient.java
index db78ec5..b49cbc6 100644
--- a/core/java/android/view/accessibility/AccessibilityInteractionClient.java
+++ b/core/java/android/view/accessibility/AccessibilityInteractionClient.java
@@ -186,7 +186,9 @@
                 if (DEBUG) {
                     Log.i(LOG_TAG, "Window cache miss");
                 }
+                final long identityToken = Binder.clearCallingIdentity();
                 window = connection.getWindow(accessibilityWindowId);
+                Binder.restoreCallingIdentity(identityToken);
                 if (window != null) {
                     sAccessibilityCache.addWindow(window);
                     return window;
@@ -222,7 +224,9 @@
                 if (DEBUG) {
                     Log.i(LOG_TAG, "Windows cache miss");
                 }
+                final long identityToken = Binder.clearCallingIdentity();
                 windows = connection.getWindows();
+                Binder.restoreCallingIdentity(identityToken);
                 if (windows != null) {
                     final int windowCount = windows.size();
                     for (int i = 0; i < windowCount; i++) {
@@ -282,9 +286,11 @@
                     }
                 }
                 final int interactionId = mInteractionIdCounter.getAndIncrement();
+                final long identityToken = Binder.clearCallingIdentity();
                 final boolean success = connection.findAccessibilityNodeInfoByAccessibilityId(
                         accessibilityWindowId, accessibilityNodeId, interactionId, this,
                         prefetchFlags, Thread.currentThread().getId());
+                Binder.restoreCallingIdentity(identityToken);
                 // If the scale is zero the call has failed.
                 if (success) {
                     List<AccessibilityNodeInfo> infos = getFindAccessibilityNodeInfosResultAndClear(
@@ -328,9 +334,11 @@
             IAccessibilityServiceConnection connection = getConnection(connectionId);
             if (connection != null) {
                 final int interactionId = mInteractionIdCounter.getAndIncrement();
+                final long identityToken = Binder.clearCallingIdentity();
                 final boolean success = connection.findAccessibilityNodeInfosByViewId(
                         accessibilityWindowId, accessibilityNodeId, viewId, interactionId, this,
                         Thread.currentThread().getId());
+                Binder.restoreCallingIdentity(identityToken);
                 if (success) {
                     List<AccessibilityNodeInfo> infos = getFindAccessibilityNodeInfosResultAndClear(
                             interactionId);
@@ -374,9 +382,11 @@
             IAccessibilityServiceConnection connection = getConnection(connectionId);
             if (connection != null) {
                 final int interactionId = mInteractionIdCounter.getAndIncrement();
+                final long identityToken = Binder.clearCallingIdentity();
                 final boolean success = connection.findAccessibilityNodeInfosByText(
                         accessibilityWindowId, accessibilityNodeId, text, interactionId, this,
                         Thread.currentThread().getId());
+                Binder.restoreCallingIdentity(identityToken);
                 if (success) {
                     List<AccessibilityNodeInfo> infos = getFindAccessibilityNodeInfosResultAndClear(
                             interactionId);
@@ -419,9 +429,11 @@
             IAccessibilityServiceConnection connection = getConnection(connectionId);
             if (connection != null) {
                 final int interactionId = mInteractionIdCounter.getAndIncrement();
+                final long identityToken = Binder.clearCallingIdentity();
                 final boolean success = connection.findFocus(accessibilityWindowId,
                         accessibilityNodeId, focusType, interactionId, this,
                         Thread.currentThread().getId());
+                Binder.restoreCallingIdentity(identityToken);
                 if (success) {
                     AccessibilityNodeInfo info = getFindAccessibilityNodeInfoResultAndClear(
                             interactionId);
@@ -461,9 +473,11 @@
             IAccessibilityServiceConnection connection = getConnection(connectionId);
             if (connection != null) {
                 final int interactionId = mInteractionIdCounter.getAndIncrement();
+                final long identityToken = Binder.clearCallingIdentity();
                 final boolean success = connection.focusSearch(accessibilityWindowId,
                         accessibilityNodeId, direction, interactionId, this,
                         Thread.currentThread().getId());
+                Binder.restoreCallingIdentity(identityToken);
                 if (success) {
                     AccessibilityNodeInfo info = getFindAccessibilityNodeInfoResultAndClear(
                             interactionId);
@@ -502,9 +516,11 @@
             IAccessibilityServiceConnection connection = getConnection(connectionId);
             if (connection != null) {
                 final int interactionId = mInteractionIdCounter.getAndIncrement();
+                final long identityToken = Binder.clearCallingIdentity();
                 final boolean success = connection.performAccessibilityAction(
                         accessibilityWindowId, accessibilityNodeId, action, arguments,
                         interactionId, this, Thread.currentThread().getId());
+                Binder.restoreCallingIdentity(identityToken);
                 if (success) {
                     return getPerformAccessibilityActionResultAndClear(interactionId);
                 }
diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java
index 6454b57..a96bf71 100644
--- a/core/java/android/widget/AbsListView.java
+++ b/core/java/android/widget/AbsListView.java
@@ -3113,9 +3113,7 @@
     }
 
     private boolean performStylusButtonPressAction(MotionEvent ev) {
-        if (ev.getToolType(0) == MotionEvent.TOOL_TYPE_STYLUS
-                && ev.isButtonPressed(MotionEvent.BUTTON_SECONDARY)
-                && mChoiceMode == CHOICE_MODE_MULTIPLE_MODAL && mChoiceActionMode == null) {
+        if (mChoiceMode == CHOICE_MODE_MULTIPLE_MODAL && mChoiceActionMode == null) {
             final View child = getChildAt(mMotionPosition - mFirstPosition);
             if (child != null) {
                 final int longPressPosition = mMotionPosition;
@@ -3785,7 +3783,7 @@
         }
 
         if (mTouchMode == TOUCH_MODE_DOWN && mMotionPosition != INVALID_POSITION
-                && (performButtonActionOnTouchDown(ev) || performStylusButtonPressAction(ev))) {
+                && performButtonActionOnTouchDown(ev)) {
                 removeCallbacks(mPendingCheckForTap);
         }
     }
@@ -3828,11 +3826,6 @@
                     mTouchMode = TOUCH_MODE_DONE_WAITING;
                     updateSelectorState();
                 } else if (motionView != null) {
-                    if (performStylusButtonPressAction(ev)) {
-                        removeCallbacks(mPendingCheckForTap);
-                        removeCallbacks(mPendingCheckForLongPress);
-                    }
-
                     // Still within bounds, update the hotspot.
                     final float[] point = mTmpPoint;
                     point[0] = x;
@@ -4072,7 +4065,7 @@
     public boolean onGenericMotionEvent(MotionEvent event) {
         if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
             switch (event.getAction()) {
-                case MotionEvent.ACTION_SCROLL: {
+                case MotionEvent.ACTION_SCROLL:
                     if (mTouchMode == TOUCH_MODE_REST) {
                         final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                         if (vscroll != 0) {
@@ -4082,9 +4075,22 @@
                             }
                         }
                     }
-                }
+                    break;
+
+                case MotionEvent.ACTION_BUTTON_PRESS:
+                    int actionButton = event.getActionButton();
+                    if ((actionButton == MotionEvent.BUTTON_STYLUS_PRIMARY
+                            || actionButton == MotionEvent.BUTTON_SECONDARY)
+                            && (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP)) {
+                        if (performStylusButtonPressAction(event)) {
+                            removeCallbacks(mPendingCheckForLongPress);
+                            removeCallbacks(mPendingCheckForTap);
+                        }
+                    }
+                    break;
             }
         }
+
         return super.onGenericMotionEvent(event);
     }
 
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java
index 238d6c4..9ca59f1 100644
--- a/core/java/android/widget/Editor.java
+++ b/core/java/android/widget/Editor.java
@@ -4157,6 +4157,11 @@
                         offset = adjustedOffset;
                     }
                     positionCursor = true;
+                } else if (adjustedOffset < mPreviousOffset) {
+                    // Handle has jumped to the start of the word, and the user is moving
+                    // their finger towards the handle, the delta should be updated.
+                    mTouchWordDelta = mTextView.convertToLocalHorizontalCoordinate(x)
+                            - layout.getPrimaryHorizontal(mPreviousOffset);
                 }
             }
 
@@ -4291,6 +4296,11 @@
                         offset = adjustedOffset;
                     }
                     positionCursor = true;
+                } else if (adjustedOffset > mPreviousOffset) {
+                    // Handle has jumped to the end of the word, and the user is moving
+                    // their finger towards the handle, the delta should be updated.
+                    mTouchWordDelta = layout.getPrimaryHorizontal(mPreviousOffset)
+                            - mTextView.convertToLocalHorizontalCoordinate(x);
                 }
             }
 
diff --git a/core/java/android/widget/GridLayout.java b/core/java/android/widget/GridLayout.java
index 6cc4bda..258424a 100644
--- a/core/java/android/widget/GridLayout.java
+++ b/core/java/android/widget/GridLayout.java
@@ -935,22 +935,14 @@
         super.onDebugDraw(canvas);
     }
 
-    // Add/remove
-
-    /**
-     * @hide
-     */
     @Override
-    protected void onViewAdded(View child) {
+    public void onViewAdded(View child) {
         super.onViewAdded(child);
         invalidateStructure();
     }
 
-    /**
-     * @hide
-     */
     @Override
-    protected void onViewRemoved(View child) {
+    public void onViewRemoved(View child) {
         super.onViewRemoved(child);
         invalidateStructure();
     }
diff --git a/core/java/com/android/internal/widget/FloatingToolbar.java b/core/java/com/android/internal/widget/FloatingToolbar.java
index 53ebc23..65f2f53f 100644
--- a/core/java/com/android/internal/widget/FloatingToolbar.java
+++ b/core/java/com/android/internal/widget/FloatingToolbar.java
@@ -20,7 +20,9 @@
 import android.animation.AnimatorListenerAdapter;
 import android.animation.AnimatorSet;
 import android.animation.ObjectAnimator;
+import android.content.ComponentCallbacks;
 import android.content.Context;
+import android.content.res.Configuration;
 import android.graphics.Color;
 import android.graphics.Point;
 import android.graphics.Rect;
@@ -89,6 +91,19 @@
     private int mSuggestedWidth;
     private boolean mWidthChanged = true;
 
+    private final ComponentCallbacks mOrientationChangeHandler = new ComponentCallbacks() {
+        @Override
+        public void onConfigurationChanged(Configuration newConfig) {
+            if (mPopup.isShowing() && mPopup.viewPortHasChanged()) {
+                mWidthChanged = true;
+                updateLayout();
+            }
+        }
+
+        @Override
+        public void onLowMemory() {}
+    };
+
     /**
      * Initializes a floating toolbar.
      */
@@ -151,6 +166,8 @@
      * Shows this floating toolbar.
      */
     public FloatingToolbar show() {
+        mContext.unregisterComponentCallbacks(mOrientationChangeHandler);
+        mContext.registerComponentCallbacks(mOrientationChangeHandler);
         List<MenuItem> menuItems = getVisibleAndEnabledMenuItems(mMenu);
         if (!isCurrentlyShowing(menuItems) || mWidthChanged) {
             mPopup.dismiss();
@@ -181,6 +198,7 @@
      * Dismisses this floating toolbar.
      */
     public void dismiss() {
+        mContext.unregisterComponentCallbacks(mOrientationChangeHandler);
         mPopup.dismiss();
     }
 
@@ -329,6 +347,7 @@
 
         private final Rect mViewPort = new Rect();
         private final Point mCoords = new Point();
+        private final Rect mTmpRect = new Rect();
 
         private final Region mTouchableRegion = new Region();
         private final ViewTreeObserver.OnComputeInternalInsetsListener mInsetsComputer =
@@ -873,6 +892,11 @@
             mParent.getWindowVisibleDisplayFrame(mViewPort);
         }
 
+        private boolean viewPortHasChanged() {
+            mParent.getWindowVisibleDisplayFrame(mTmpRect);
+            return !mTmpRect.equals(mViewPort);
+        }
+
         private int getToolbarWidth(int suggestedWidth) {
             int width = suggestedWidth;
             refreshViewPort();
diff --git a/core/jni/android/graphics/Region.cpp b/core/jni/android/graphics/Region.cpp
index 3bab2df..e99bdfc 100644
--- a/core/jni/android/graphics/Region.cpp
+++ b/core/jni/android/graphics/Region.cpp
@@ -231,15 +231,24 @@
 static jboolean Region_writeToParcel(JNIEnv* env, jobject clazz, jlong regionHandle, jobject parcel)
 {
     const SkRegion* region = reinterpret_cast<SkRegion*>(regionHandle);
-    if (parcel == NULL) {
+    if (parcel == nullptr) {
         return JNI_FALSE;
     }
 
     android::Parcel* p = android::parcelForJavaObject(env, parcel);
 
-    size_t size = region->writeToMemory(NULL);
+    const size_t size = region->writeToMemory(nullptr);
     p->writeInt32(size);
-    region->writeToMemory(p->writeInplace(size));
+    void* dst = p->writeInplace(size);
+    if (dst == nullptr) {
+        ALOGE("Region.writeToParcel could not write %zi bytes", size);
+        return JNI_FALSE;
+    }
+    const size_t sizeWritten = region->writeToMemory(dst);
+    if (sizeWritten != size) {
+        ALOGE("SkRegion::writeToMemory should have written %zi bytes but wrote %zi",
+                size, sizeWritten);
+    }
 
     return JNI_TRUE;
 }
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 65c064b..f197597 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -316,8 +316,6 @@
     <protected-broadcast android:name="android.intent.action.ACTION_SET_RADIO_CAPABILITY_FAILED" />
 
     <protected-broadcast android:name="android.internal.policy.action.BURN_IN_PROTECTION" />
-    <protected-broadcast android:name="android.service.persistentdata.action.WIPE_IF_ALLOWED" />
-
     <protected-broadcast android:name="android.app.action.SYSTEM_UPDATE_POLICY_CHANGED" />
     <!-- ====================================================================== -->
     <!--                          RUNTIME PERMISSIONS                           -->
diff --git a/keystore/java/android/security/keystore/AndroidKeyStoreBCWorkaroundProvider.java b/keystore/java/android/security/keystore/AndroidKeyStoreBCWorkaroundProvider.java
index 06b76fa..156f45f6 100644
--- a/keystore/java/android/security/keystore/AndroidKeyStoreBCWorkaroundProvider.java
+++ b/keystore/java/android/security/keystore/AndroidKeyStoreBCWorkaroundProvider.java
@@ -132,52 +132,52 @@
 
         putSignatureImpl("MD5withRSA",
                 PACKAGE_NAME + ".AndroidKeyStoreRSASignatureSpi$MD5WithPKCS1Padding");
-        put("Alg.Alias.Signature.MD5WithRSAEncryption", "MD5WithRSA");
-        put("Alg.Alias.Signature.MD5/RSA", "MD5WithRSA");
-        put("Alg.Alias.Signature.1.2.840.113549.1.1.4", "MD5WithRSA");
-        put("Alg.Alias.Signature.1.2.840.113549.2.5with1.2.840.113549.1.1.1", "MD5WithRSA");
+        put("Alg.Alias.Signature.MD5WithRSAEncryption", "MD5withRSA");
+        put("Alg.Alias.Signature.MD5/RSA", "MD5withRSA");
+        put("Alg.Alias.Signature.1.2.840.113549.1.1.4", "MD5withRSA");
+        put("Alg.Alias.Signature.1.2.840.113549.2.5with1.2.840.113549.1.1.1", "MD5withRSA");
 
         putSignatureImpl("SHA1withRSA",
                 PACKAGE_NAME + ".AndroidKeyStoreRSASignatureSpi$SHA1WithPKCS1Padding");
-        put("Alg.Alias.Signature.SHA1WithRSAEncryption", "SHA1WithRSA");
-        put("Alg.Alias.Signature.SHA1/RSA", "SHA1WithRSA");
-        put("Alg.Alias.Signature.SHA-1/RSA", "SHA1WithRSA");
-        put("Alg.Alias.Signature.1.2.840.113549.1.1.5", "SHA1WithRSA");
-        put("Alg.Alias.Signature.1.3.14.3.2.26with1.2.840.113549.1.1.1", "SHA1WithRSA");
-        put("Alg.Alias.Signature.1.3.14.3.2.26with1.2.840.113549.1.1.5", "SHA1WithRSA");
-        put("Alg.Alias.Signature.1.3.14.3.2.29", "SHA1WithRSA");
+        put("Alg.Alias.Signature.SHA1WithRSAEncryption", "SHA1withRSA");
+        put("Alg.Alias.Signature.SHA1/RSA", "SHA1withRSA");
+        put("Alg.Alias.Signature.SHA-1/RSA", "SHA1withRSA");
+        put("Alg.Alias.Signature.1.2.840.113549.1.1.5", "SHA1withRSA");
+        put("Alg.Alias.Signature.1.3.14.3.2.26with1.2.840.113549.1.1.1", "SHA1withRSA");
+        put("Alg.Alias.Signature.1.3.14.3.2.26with1.2.840.113549.1.1.5", "SHA1withRSA");
+        put("Alg.Alias.Signature.1.3.14.3.2.29", "SHA1withRSA");
 
         putSignatureImpl("SHA224withRSA",
                 PACKAGE_NAME + ".AndroidKeyStoreRSASignatureSpi$SHA224WithPKCS1Padding");
-        put("Alg.Alias.Signature.SHA224WithRSAEncryption", "SHA224WithRSA");
-        put("Alg.Alias.Signature.1.2.840.113549.1.1.11", "SHA224WithRSA");
+        put("Alg.Alias.Signature.SHA224WithRSAEncryption", "SHA224withRSA");
+        put("Alg.Alias.Signature.1.2.840.113549.1.1.11", "SHA224withRSA");
         put("Alg.Alias.Signature.2.16.840.1.101.3.4.2.4with1.2.840.113549.1.1.1",
-                "SHA224WithRSA");
+                "SHA224withRSA");
         put("Alg.Alias.Signature.2.16.840.1.101.3.4.2.4with1.2.840.113549.1.1.11",
-                "SHA224WithRSA");
+                "SHA224withRSA");
 
         putSignatureImpl("SHA256withRSA",
                 PACKAGE_NAME + ".AndroidKeyStoreRSASignatureSpi$SHA256WithPKCS1Padding");
-        put("Alg.Alias.Signature.SHA256WithRSAEncryption", "SHA256WithRSA");
-        put("Alg.Alias.Signature.1.2.840.113549.1.1.11", "SHA256WithRSA");
+        put("Alg.Alias.Signature.SHA256WithRSAEncryption", "SHA256withRSA");
+        put("Alg.Alias.Signature.1.2.840.113549.1.1.11", "SHA256withRSA");
         put("Alg.Alias.Signature.2.16.840.1.101.3.4.2.1with1.2.840.113549.1.1.1",
-                "SHA256WithRSA");
+                "SHA256withRSA");
         put("Alg.Alias.Signature.2.16.840.1.101.3.4.2.1with1.2.840.113549.1.1.11",
-                "SHA256WithRSA");
+                "SHA256withRSA");
 
         putSignatureImpl("SHA384withRSA",
                 PACKAGE_NAME + ".AndroidKeyStoreRSASignatureSpi$SHA384WithPKCS1Padding");
-        put("Alg.Alias.Signature.SHA384WithRSAEncryption", "SHA384WithRSA");
-        put("Alg.Alias.Signature.1.2.840.113549.1.1.12", "SHA384WithRSA");
+        put("Alg.Alias.Signature.SHA384WithRSAEncryption", "SHA384withRSA");
+        put("Alg.Alias.Signature.1.2.840.113549.1.1.12", "SHA384withRSA");
         put("Alg.Alias.Signature.2.16.840.1.101.3.4.2.2with1.2.840.113549.1.1.1",
-                "SHA384WithRSA");
+                "SHA384withRSA");
 
         putSignatureImpl("SHA512withRSA",
                 PACKAGE_NAME + ".AndroidKeyStoreRSASignatureSpi$SHA512WithPKCS1Padding");
-        put("Alg.Alias.Signature.SHA512WithRSAEncryption", "SHA512WithRSA");
-        put("Alg.Alias.Signature.1.2.840.113549.1.1.13", "SHA512WithRSA");
+        put("Alg.Alias.Signature.SHA512WithRSAEncryption", "SHA512withRSA");
+        put("Alg.Alias.Signature.1.2.840.113549.1.1.13", "SHA512withRSA");
         put("Alg.Alias.Signature.2.16.840.1.101.3.4.2.3with1.2.840.113549.1.1.1",
-                "SHA512WithRSA");
+                "SHA512withRSA");
 
         putSignatureImpl("SHA1withRSA/PSS",
                 PACKAGE_NAME + ".AndroidKeyStoreRSASignatureSpi$SHA1WithPSSPadding");
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java
index 24ac507..5700732 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java
@@ -1609,7 +1609,7 @@
     }
 
     @Override
-    protected void onViewRemoved(View child) {
+    public void onViewRemoved(View child) {
         super.onViewRemoved(child);
         // we only call our internal methods if this is actually a removal and not just a
         // notification which becomes a child notification
@@ -1757,7 +1757,7 @@
     }
 
     @Override
-    protected void onViewAdded(View child) {
+    public void onViewAdded(View child) {
         super.onViewAdded(child);
         onViewAddedInternal(child);
     }
diff --git a/services/core/java/com/android/server/PersistentDataBlockService.java b/services/core/java/com/android/server/PersistentDataBlockService.java
index 56f9942..94316fe 100644
--- a/services/core/java/com/android/server/PersistentDataBlockService.java
+++ b/services/core/java/com/android/server/PersistentDataBlockService.java
@@ -18,18 +18,14 @@
 
 import android.Manifest;
 import android.app.ActivityManager;
-import android.app.PendingIntent;
 import android.content.Context;
-import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.os.Binder;
-import android.os.Bundle;
 import android.os.IBinder;
 import android.os.RemoteException;
 import android.os.SystemProperties;
 import android.os.UserHandle;
 import android.service.persistentdata.IPersistentDataBlockService;
-import android.service.persistentdata.PersistentDataBlockManager;
 import android.util.Slog;
 
 import com.android.internal.R;
@@ -432,29 +428,6 @@
         }
 
         @Override
-        public void wipeIfAllowed(Bundle bundle, PendingIntent pi) {
-            // Should only be called by owner
-            if (UserHandle.getCallingUserId() != UserHandle.USER_OWNER) {
-                throw new SecurityException("Only the Owner is allowed to wipe");
-            }
-            // Caller must be able to query the the state of the PersistentDataBlock
-            enforcePersistentDataBlockAccess();
-            String allowedPackage = mContext.getResources()
-                    .getString(R.string.config_persistentDataPackageName);
-            Intent intent = new Intent();
-            intent.setPackage(allowedPackage);
-            intent.setAction(PersistentDataBlockManager.ACTION_WIPE_IF_ALLOWED);
-            intent.putExtras(bundle);
-            intent.putExtra(PersistentDataBlockManager.EXTRA_WIPE_IF_ALLOWED_CALLBACK, pi);
-            long id = Binder.clearCallingIdentity();
-            try {
-                mContext.sendBroadcastAsUser(intent, UserHandle.OWNER);
-            } finally {
-                restoreCallingIdentity(id);
-            }
-        }
-
-        @Override
         public void setOemUnlockEnabled(boolean enabled) {
             // do not allow monkey to flip the flag
             if (ActivityManager.isUserAMonkey()) {
diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java
index eb5af9e5..0714d36 100644
--- a/services/core/java/com/android/server/am/ActivityStack.java
+++ b/services/core/java/com/android/server/am/ActivityStack.java
@@ -1326,7 +1326,12 @@
                         if (r != starting) {
                             mStackSupervisor.startSpecificActivityLocked(
                                     r, noStackActivityResumed, false);
-                            noStackActivityResumed = false;
+                            if (activityNdx >= activities.size()) {
+                                // Record may be removed if its process needs to restart.
+                                activityNdx = activities.size() - 1;
+                            } else {
+                                noStackActivityResumed = false;
+                            }
                         }
 
                     } else if (r.visible) {
diff --git a/tests/VectorDrawableTest/res/drawable/vector_drawable04.xml b/tests/VectorDrawableTest/res/drawable/vector_drawable04.xml
index d282fc9..0f3fb95 100644
--- a/tests/VectorDrawableTest/res/drawable/vector_drawable04.xml
+++ b/tests/VectorDrawableTest/res/drawable/vector_drawable04.xml
@@ -13,37 +13,41 @@
      limitations under the License.
 -->
 <vector xmlns:android="http://schemas.android.com/apk/res/android"
-            android:width="64dp"
-            android:height="64dp"
-            android:viewportWidth="7.30625"
-            android:viewportHeight="12.25"
-            android:autoMirrored="true">
+    android:autoMirrored="true"
+    android:height="64dp"
+    android:viewportHeight="12.25"
+    android:viewportWidth="7.30625"
+    android:width="64dp" >
 
     <group>
         <clip-path
-                android:name="clip1"
-                android:pathData="
+            android:name="clip1"
+            android:pathData="
                 M 3.65, 6.125
                 m-.001, 0
                 a .001,.001 0 1,0 .002,0
-                a .001,.001 0 1,0-.002,0z"/>
-        <path
-                android:name="one"
-                android:pathData="M 1.215625,9.5l 1.9375,0.0 0.0-6.671875-2.109375,0.421875 0.0-1.078125
-                l 2.09375-0.421875 1.1874998,0.0 0.0,7.75 1.9375,0.0 0.0,1.0
-                l-5.046875,0.0 0.0-1.0Z"
-                android:fillColor="#ff88ff"/>
+                a .001,.001 0 1,0-.002,0z" />
 
+        <path
+            android:name="one"
+            android:fillColor="#ff88ff"
+            android:pathData="M 1.215625,9.5l 1.9375,0.0 0.0-6.671875-2.109375,0.421875 0.0-1.078125
+                l 2.09375-0.421875 1.1874998,0.0 0.0,7.75 1.9375,0.0 0.0,1.0
+                l-5.046875,0.0 0.0-1.0Z" />
+    </group>
+    <group>
         <clip-path
-                android:name="clip2"
-                android:pathData="
+            android:name="clip2"
+            android:pathData="
                 M 3.65, 6.125
                 m-6, 0
                 a 6,6 0 1,0 12,0
-                a 6,6 0 1,0-12,0z"/>
+                a 6,6 0 1,0-12,0z" />
+
         <path
-                android:name="two"
-                android:pathData="M 2.534375,9.6875l 4.140625,0.0 0.0,1.0-5.5625,0.0 0.0-1.0q 0.671875-0.6875 1.828125-1.859375
+            android:name="two"
+            android:fillColor="#ff88ff"
+            android:pathData="M 2.534375,9.6875l 4.140625,0.0 0.0,1.0-5.5625,0.0 0.0-1.0q 0.671875-0.6875 1.828125-1.859375
                         q 1.1718752-1.1875 1.4687502-1.53125 0.578125-0.625 0.796875-1.0625
                         q 0.234375-0.453125 0.234375-0.875 0.0-0.703125-0.5-1.140625
                         q-0.484375-0.4375-1.2656252-0.4375-0.5625,0.0-1.1875,0.1875
@@ -51,7 +55,7 @@
                         q 0.625-0.15625 1.140625-0.15625 1.3593752,0.0 2.1718752,0.6875
                         q 0.8125,0.671875 0.8125,1.8125 0.0,0.53125-0.203125,1.015625
                         q-0.203125,0.484375-0.734375,1.140625-0.15625,0.171875-0.9375,0.984375
-                        q-0.78125024,0.8125-2.2187502,2.265625Z"
-                android:fillColor="#ff88ff"/>
+                        q-0.78125024,0.8125-2.2187502,2.265625Z" />
     </group>
-</vector>
+
+</vector>
\ No newline at end of file
diff --git a/tools/aapt2/BinaryResourceParser.cpp b/tools/aapt2/BinaryResourceParser.cpp
index 3559f43..4f1947a 100644
--- a/tools/aapt2/BinaryResourceParser.cpp
+++ b/tools/aapt2/BinaryResourceParser.cpp
@@ -116,9 +116,11 @@
 BinaryResourceParser::BinaryResourceParser(const std::shared_ptr<ResourceTable>& table,
                                            const std::shared_ptr<IResolver>& resolver,
                                            const Source& source,
+                                           const std::u16string& defaultPackage,
                                            const void* data,
                                            size_t len) :
-        mTable(table), mResolver(resolver), mSource(source), mData(data), mDataLen(len) {
+        mTable(table), mResolver(resolver), mSource(source), mDefaultPackage(defaultPackage),
+        mData(data), mDataLen(len) {
 }
 
 bool BinaryResourceParser::parse() {
@@ -177,6 +179,9 @@
             if (!type) {
                 return false;
             }
+            if (outSymbol->package.empty()) {
+                outSymbol->package = mTable->getPackage();
+            }
             outSymbol->type = *type;
 
             // Since we scan the symbol table in order, we can start looking for the
@@ -350,7 +355,22 @@
 
     size_t len = strnlen16(reinterpret_cast<const char16_t*>(packageHeader->name),
             sizeof(packageHeader->name) / sizeof(packageHeader->name[0]));
-    mTable->setPackage(StringPiece16(reinterpret_cast<const char16_t*>(packageHeader->name), len));
+    if (mTable->getPackage().empty() && len == 0) {
+        mTable->setPackage(mDefaultPackage);
+    } else if (len > 0) {
+        StringPiece16 thisPackage(reinterpret_cast<const char16_t*>(packageHeader->name), len);
+        if (mTable->getPackage().empty()) {
+            mTable->setPackage(thisPackage);
+        } else if (thisPackage != mTable->getPackage()) {
+            Logger::error(mSource)
+                    << "incompatible packages: "
+                    << mTable->getPackage()
+                    << " vs. "
+                    << thisPackage
+                    << std::endl;
+            return false;
+        }
+    }
 
     ResChunkPullParser parser(getChunkData(packageHeader->header),
                               getChunkDataLen(packageHeader->header));
diff --git a/tools/aapt2/BinaryResourceParser.h b/tools/aapt2/BinaryResourceParser.h
index 32876cd..3aab301 100644
--- a/tools/aapt2/BinaryResourceParser.h
+++ b/tools/aapt2/BinaryResourceParser.h
@@ -45,6 +45,7 @@
     BinaryResourceParser(const std::shared_ptr<ResourceTable>& table,
                          const std::shared_ptr<IResolver>& resolver,
                          const Source& source,
+                         const std::u16string& defaultPackage,
                          const void* data, size_t len);
 
     BinaryResourceParser(const BinaryResourceParser&) = delete; // No copy.
@@ -97,12 +98,12 @@
 
     const Source mSource;
 
+    // The package name of the resource table.
+    std::u16string mDefaultPackage;
+
     const void* mData;
     const size_t mDataLen;
 
-    // The package name of the resource table.
-    std::u16string mPackage;
-
     // The array of symbol entries. Each element points to an offset
     // in the table and an index into the symbol table string pool.
     const SymbolTable_entry* mSymbolEntries = nullptr;
diff --git a/tools/aapt2/Linker.cpp b/tools/aapt2/Linker.cpp
index f3f04a5..c37cc93 100644
--- a/tools/aapt2/Linker.cpp
+++ b/tools/aapt2/Linker.cpp
@@ -160,7 +160,7 @@
 void Linker::visit(Reference& reference, ValueVisitorArgs& a) {
     Args& args = static_cast<Args&>(a);
 
-    if (!reference.name.isValid()) {
+    if (reference.name.entry.empty()) {
         // We can't have a completely bad reference.
         if (!reference.id.isValid()) {
             Logger::error() << "srsly? " << args.referrer << std::endl;
diff --git a/tools/aapt2/Main.cpp b/tools/aapt2/Main.cpp
index 41c229d..54a7329 100644
--- a/tools/aapt2/Main.cpp
+++ b/tools/aapt2/Main.cpp
@@ -756,8 +756,8 @@
                 zipFile->uncompress(entry));
         assert(uncompressedData);
 
-        BinaryResourceParser parser(table, resolver, source, uncompressedData.get(),
-                                    entry->getUncompressedLen());
+        BinaryResourceParser parser(table, resolver, source, options.appInfo.package, 
+                                    uncompressedData.get(), entry->getUncompressedLen());
         if (!parser.parse()) {
             return false;
         }
@@ -1085,50 +1085,47 @@
     }
 
     bool isStaticLib = false;
+    if (options.phase == AaptOptions::Phase::Link) {
+        flag::requiredFlag("--manifest", "AndroidManifest.xml of your app",
+                [&options](const StringPiece& arg) {
+                    options.manifest = Source{ arg.toString() };
+                });
+
+        flag::optionalFlag("-I", "add an Android APK to link against",
+                [&options](const StringPiece& arg) {
+                    options.libraries.push_back(Source{ arg.toString() });
+                });
+
+        flag::optionalFlag("--java", "directory in which to generate R.java",
+                [&options](const StringPiece& arg) {
+                    options.generateJavaClass = Source{ arg.toString() };
+                });
+
+        flag::optionalFlag("--proguard", "file in which to output proguard rules",
+                [&options](const StringPiece& arg) {
+                    options.generateProguardRules = Source{ arg.toString() };
+                });
+
+        flag::optionalSwitch("--static-lib", "generate a static Android library", true,
+                             &isStaticLib);
+
+        flag::optionalFlag("--binding", "Output directory for binding XML files",
+                [&options](const StringPiece& arg) {
+                    options.bindingOutput = Source{ arg.toString() };
+                });
+        flag::optionalSwitch("--no-version", "Disables automatic style and layout versioning",
+                             false, &options.versionStylesAndLayouts);
+    }
+
     if (options.phase == AaptOptions::Phase::Compile ||
             options.phase == AaptOptions::Phase::Link) {
-        if (options.phase == AaptOptions::Phase::Compile) {
-            flag::requiredFlag("--package", "Android package name",
-                    [&options](const StringPiece& arg) {
-                        options.appInfo.package = util::utf8ToUtf16(arg);
-                    });
-        } else if (options.phase == AaptOptions::Phase::Link) {
-            flag::requiredFlag("--manifest", "AndroidManifest.xml of your app",
-                    [&options](const StringPiece& arg) {
-                        options.manifest = Source{ arg.toString() };
-                    });
-
-            flag::optionalFlag("-I", "add an Android APK to link against",
-                    [&options](const StringPiece& arg) {
-                        options.libraries.push_back(Source{ arg.toString() });
-                    });
-
-            flag::optionalFlag("--java", "directory in which to generate R.java",
-                    [&options](const StringPiece& arg) {
-                        options.generateJavaClass = Source{ arg.toString() };
-                    });
-
-            flag::optionalFlag("--proguard", "file in which to output proguard rules",
-                    [&options](const StringPiece& arg) {
-                        options.generateProguardRules = Source{ arg.toString() };
-                    });
-
-            flag::optionalSwitch("--static-lib", "generate a static Android library", true,
-                                 &isStaticLib);
-
-            flag::optionalFlag("--binding", "Output directory for binding XML files",
-                    [&options](const StringPiece& arg) {
-                        options.bindingOutput = Source{ arg.toString() };
-                    });
-            flag::optionalSwitch("--no-version", "Disables automatic style and layout versioning",
-                                 false, &options.versionStylesAndLayouts);
-        }
-
         // Common flags for all steps.
         flag::requiredFlag("-o", "Output path", [&options](const StringPiece& arg) {
             options.output = Source{ arg.toString() };
         });
-    } else if (options.phase == AaptOptions::Phase::DumpStyleGraph) {
+    }
+
+    if (options.phase == AaptOptions::Phase::DumpStyleGraph) {
         flag::requiredFlag("--style", "Name of the style to dump",
                 [&options](const StringPiece& arg, std::string* outError) -> bool {
                     Reference styleReference;
@@ -1191,7 +1188,7 @@
                 zipFile->uncompress(entry));
         assert(uncompressedData);
 
-        BinaryResourceParser parser(table, resolver, source, uncompressedData.get(),
+        BinaryResourceParser parser(table, resolver, source, {}, uncompressedData.get(),
                                     entry->getUncompressedLen());
         if (!parser.parse()) {
             return false;
@@ -1223,16 +1220,17 @@
         if (!loadAppInfo(options.manifest, &options.appInfo)) {
             return false;
         }
-    }
 
-    // Verify we have some common options set.
-    if (options.appInfo.package.empty()) {
-        Logger::error() << "no package name specified." << std::endl;
-        return false;
+        if (options.appInfo.package.empty()) {
+            Logger::error() << "no package name specified." << std::endl;
+            return false;
+        }
     }
 
     // Every phase needs a resource table.
     std::shared_ptr<ResourceTable> table = std::make_shared<ResourceTable>();
+
+    // The package name is empty when in the compile phase.
     table->setPackage(options.appInfo.package);
     if (options.appInfo.package == u"android") {
         table->setPackageId(0x01);
diff --git a/tools/aapt2/TableFlattener.cpp b/tools/aapt2/TableFlattener.cpp
index 539c48f..b7c04f0 100644
--- a/tools/aapt2/TableFlattener.cpp
+++ b/tools/aapt2/TableFlattener.cpp
@@ -79,7 +79,7 @@
 
         // Write the key.
         if (!Res_INTERNALID(key.id.id) && !key.id.isValid()) {
-            assert(key.name.isValid());
+            assert(!key.name.entry.empty());
             mSymbols->push_back(std::make_pair(ResourceNameRef(key.name),
                     mOut->size() - sizeof(*outMapEntry)));
         }
@@ -284,13 +284,6 @@
 bool TableFlattener::flatten(BigBuffer* out, const ResourceTable& table) {
     const size_t beginning = out->size();
 
-    if (table.getPackage().size() == 0) {
-        Logger::error()
-                << "ResourceTable has no package name."
-                << std::endl;
-        return false;
-    }
-
     if (table.getPackageId() == ResourceTable::kUnsetPackageId) {
         Logger::error()
                 << "ResourceTable has no package ID set."
diff --git a/tools/aapt2/data/Makefile b/tools/aapt2/data/Makefile
index 3387135..91ff5fe 100644
--- a/tools/aapt2/data/Makefile
+++ b/tools/aapt2/data/Makefile
@@ -50,7 +50,7 @@
 # returns: out/values-v4.apk: res/values-v4/styles.xml res/values-v4/colors.xml
 define make-collect-rule
 $(LOCAL_OUT)/$1.apk: $(filter $(LOCAL_RESOURCE_DIR)/$1/%,$(PRIVATE_RESOURCES))
-	$(AAPT) compile --package $(LOCAL_PACKAGE) -o $$@ $$^
+	$(AAPT) compile -o $$@ $$^
 endef
 
 # Collect: out/values-v4.apk <- res/values-v4/styles.xml res/values-v4/colors.xml
diff --git a/tools/aapt2/data/lib/Makefile b/tools/aapt2/data/lib/Makefile
index 372c225..741be9a 100644
--- a/tools/aapt2/data/lib/Makefile
+++ b/tools/aapt2/data/lib/Makefile
@@ -48,7 +48,7 @@
 # returns: out/values-v4.apk: res/values-v4/styles.xml res/values-v4/colors.xml
 define make-collect-rule
 $(LOCAL_OUT)/$1.apk: $(filter $(LOCAL_RESOURCE_DIR)/$1/%,$(PRIVATE_RESOURCES))
-	$(AAPT) compile --package $(LOCAL_PACKAGE) -o $$@ $$^
+	$(AAPT) compile -o $$@ $$^
 endef
 
 # Collect: out/values-v4.apk <- res/values-v4/styles.xml res/values-v4/colors.xml