Merge "parse named anonymous memory for dumpsys meminfo" into klp-dev
diff --git a/api/current.txt b/api/current.txt
index d79a8c0..b9d51fdf 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -20716,6 +20716,7 @@
     field public static final java.lang.String ACTION_MEMORY_CARD_SETTINGS = "android.settings.MEMORY_CARD_SETTINGS";
     field public static final java.lang.String ACTION_NETWORK_OPERATOR_SETTINGS = "android.settings.NETWORK_OPERATOR_SETTINGS";
     field public static final java.lang.String ACTION_NFCSHARING_SETTINGS = "android.settings.NFCSHARING_SETTINGS";
+    field public static final java.lang.String ACTION_NFC_PAYMENT_SETTINGS = "android.settings.NFC_PAYMENT_SETTINGS";
     field public static final java.lang.String ACTION_NFC_SETTINGS = "android.settings.NFC_SETTINGS";
     field public static final java.lang.String ACTION_PRIVACY_SETTINGS = "android.settings.PRIVACY_SETTINGS";
     field public static final java.lang.String ACTION_QUICK_LAUNCH_SETTINGS = "android.settings.QUICK_LAUNCH_SETTINGS";
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index 17e8dd9..be831d7 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -1527,9 +1527,26 @@
      */
     public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
             IllegalStateException {
+        return setDeviceOwner(packageName, null);
+    }
+
+    /**
+     * @hide
+     * Sets the given package as the device owner. The package must already be installed and there
+     * shouldn't be an existing device owner registered, for this call to succeed. Also, this
+     * method must be called before the device is provisioned.
+     * @param packageName the package name of the application to be registered as the device owner.
+     * @param ownerName the human readable name of the institution that owns this device.
+     * @return whether the package was successfully registered as the device owner.
+     * @throws IllegalArgumentException if the package name is null or invalid
+     * @throws IllegalStateException if a device owner is already registered or the device has
+     *         already been provisioned.
+     */
+    public boolean setDeviceOwner(String packageName, String ownerName)
+            throws IllegalArgumentException, IllegalStateException {
         if (mService != null) {
             try {
-                return mService.setDeviceOwner(packageName);
+                return mService.setDeviceOwner(packageName, ownerName);
             } catch (RemoteException re) {
                 Log.w(TAG, "Failed to set device owner");
             }
@@ -1581,4 +1598,16 @@
         }
         return null;
     }
+
+    /** @hide */
+    public String getDeviceOwnerName() {
+        if (mService != null) {
+            try {
+                return mService.getDeviceOwnerName();
+            } catch (RemoteException re) {
+                Log.w(TAG, "Failed to get device owner");
+            }
+        }
+        return null;
+    }
 }
diff --git a/core/java/android/app/admin/IDevicePolicyManager.aidl b/core/java/android/app/admin/IDevicePolicyManager.aidl
index b2a65bf..9659a91 100644
--- a/core/java/android/app/admin/IDevicePolicyManager.aidl
+++ b/core/java/android/app/admin/IDevicePolicyManager.aidl
@@ -98,7 +98,8 @@
     void reportFailedPasswordAttempt(int userHandle);
     void reportSuccessfulPasswordAttempt(int userHandle);
 
-    boolean setDeviceOwner(String packageName);
+    boolean setDeviceOwner(String packageName, String ownerName);
     boolean isDeviceOwner(String packageName);
     String getDeviceOwner();
+    String getDeviceOwnerName();
 }
diff --git a/core/java/android/nfc/cardemulation/ApduServiceInfo.java b/core/java/android/nfc/cardemulation/ApduServiceInfo.java
index ffa7d7e..3f7e3ef 100644
--- a/core/java/android/nfc/cardemulation/ApduServiceInfo.java
+++ b/core/java/android/nfc/cardemulation/ApduServiceInfo.java
@@ -188,7 +188,8 @@
                         currentGroup != null) {
                     final TypedArray a = res.obtainAttributes(attrs,
                             com.android.internal.R.styleable.AidFilter);
-                    String aid = a.getString(com.android.internal.R.styleable.AidFilter_name);
+                    String aid = a.getString(com.android.internal.R.styleable.AidFilter_name).
+                            toUpperCase();
                     if (isValidAid(aid) && !currentGroup.aids.contains(aid)) {
                         currentGroup.aids.add(aid);
                         mAids.add(aid);
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 4865fd0..585115a 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -644,6 +644,23 @@
         "android.settings.NFCSHARING_SETTINGS";
 
     /**
+     * Activity Action: Show NFC Tap & Pay settings
+     * <p>
+     * This shows UI that allows the user to configure Tap&Pay
+     * settings.
+     * <p>
+     * In some cases, a matching Activity may not exist, so ensure you
+     * safeguard against this.
+     * <p>
+     * Input: Nothing.
+     * <p>
+     * Output: Nothing
+     */
+    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
+    public static final String ACTION_NFC_PAYMENT_SETTINGS =
+        "android.settings.NFC_PAYMENT_SETTINGS";
+
+    /**
      * Activity Action: Show Daydream settings.
      * <p>
      * In some cases, a matching Activity may not exist, so ensure you
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 20938f51..3dff1b0 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -12062,7 +12062,8 @@
     }
 
     /**
-     * Resolve padding depending on layout direction.
+     * Resolves padding depending on layout direction, if applicable, and
+     * recomputes internal padding values to adjust for scroll bars.
      *
      * @hide
      */
@@ -12102,11 +12103,11 @@
 
             mUserPaddingBottom = (mUserPaddingBottom >= 0) ? mUserPaddingBottom : mPaddingBottom;
 
-            internalSetPadding(mUserPaddingLeft, mPaddingTop, mUserPaddingRight,
-                    mUserPaddingBottom);
             onRtlPropertiesChanged(resolvedLayoutDirection);
         }
 
+        internalSetPadding(mUserPaddingLeft, mPaddingTop, mUserPaddingRight, mUserPaddingBottom);
+
         mPrivateFlags2 |= PFLAG2_PADDING_RESOLVED;
     }
 
@@ -14659,13 +14660,26 @@
      * @hide
      */
     protected void resolveDrawables() {
-        if (canResolveLayoutDirection()) {
-            if (mBackground != null) {
-                mBackground.setLayoutDirection(getLayoutDirection());
-            }
-            mPrivateFlags2 |= PFLAG2_DRAWABLE_RESOLVED;
-            onResolveDrawables(getLayoutDirection());
+        // Drawables resolution may need to happen before resolving the layout direction (which is
+        // done only during the measure() call).
+        // If the layout direction is not resolved yet, we cannot resolve the Drawables except in
+        // one case: when the raw layout direction has not been defined as LAYOUT_DIRECTION_INHERIT.
+        // So, if the raw layout direction is LAYOUT_DIRECTION_LTR or LAYOUT_DIRECTION_RTL or
+        // LAYOUT_DIRECTION_LOCALE, we can "cheat" and we don't need to wait for the layout
+        // direction to be resolved as its resolved value will be the same as its raw value.
+        if (!isLayoutDirectionResolved() &&
+                getRawLayoutDirection() == View.LAYOUT_DIRECTION_INHERIT) {
+            return;
         }
+
+        final int layoutDirection = isLayoutDirectionResolved() ?
+                getLayoutDirection() : getRawLayoutDirection();
+
+        if (mBackground != null) {
+            mBackground.setLayoutDirection(layoutDirection);
+        }
+        mPrivateFlags2 |= PFLAG2_DRAWABLE_RESOLVED;
+        onResolveDrawables(layoutDirection);
     }
 
     /**
diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java
index 3f391ad..0ed846b 100644
--- a/core/java/android/widget/AbsListView.java
+++ b/core/java/android/widget/AbsListView.java
@@ -1243,6 +1243,12 @@
             mFastScroller = new FastScroller(this);
             mFastScroller.setEnabled(true);
         }
+
+        recomputePadding();
+
+        if (mFastScroller != null) {
+            mFastScroller.updateLayout();
+        }
     }
 
     /**
@@ -1303,7 +1309,7 @@
 
     @Override
     public int getVerticalScrollbarWidth() {
-        if (isFastScrollAlwaysVisible() && mFastScroller != null) {
+        if (mFastScroller != null && mFastScroller.isEnabled()) {
             return Math.max(super.getVerticalScrollbarWidth(), mFastScroller.getWidth());
         }
         return super.getVerticalScrollbarWidth();
@@ -1327,6 +1333,14 @@
         }
     }
 
+    @Override
+    public void setScrollBarStyle(int style) {
+        super.setScrollBarStyle(style);
+        if (mFastScroller != null) {
+            mFastScroller.setScrollBarStyle(style);
+        }
+    }
+
     /**
      * If fast scroll is enabled, then don't draw the vertical scrollbar.
      * @hide
@@ -2787,7 +2801,6 @@
     @Override
     public void onRtlPropertiesChanged(int layoutDirection) {
         super.onRtlPropertiesChanged(layoutDirection);
-
         if (mFastScroller != null) {
            mFastScroller.setScrollbarPosition(getVerticalScrollbarPosition());
         }
diff --git a/core/java/android/widget/FastScroller.java b/core/java/android/widget/FastScroller.java
index 393720f..c48955f 100644
--- a/core/java/android/widget/FastScroller.java
+++ b/core/java/android/widget/FastScroller.java
@@ -131,6 +131,9 @@
     /** Whether there is a track image to display. */
     private final boolean mHasTrackImage;
 
+    /** Total width of decorations. */
+    private final int mWidth;
+
     /** Set containing decoration transition animations. */
     private AnimatorSet mDecorAnimation;
 
@@ -155,6 +158,9 @@
     /** The index of the current section. */
     private int mCurrentSection = -1;
 
+    /** The current scrollbar position. */
+    private int mScrollbarPosition = -1;
+
     /** Whether the list is long enough to need a fast scroller. */
     private boolean mLongList;
 
@@ -194,6 +200,9 @@
      */
     private int mOverlayPosition;
 
+    /** Current scrollbar style, including inset and overlay properties. */
+    private int mScrollBarStyle;
+
     /** Whether to precisely match the thumb position to the list. */
     private boolean mMatchDragPosition;
 
@@ -245,34 +254,44 @@
         final Resources res = context.getResources();
         final TypedArray ta = context.getTheme().obtainStyledAttributes(ATTRS);
 
-        mTrackImage = new ImageView(context);
+        final ImageView trackImage = new ImageView(context);
+        mTrackImage = trackImage;
+
+        int width = 0;
 
         // Add track to overlay if it has an image.
-        final int trackResId = ta.getResourceId(TRACK_DRAWABLE, 0);
-        if (trackResId != 0) {
+        final Drawable trackDrawable = ta.getDrawable(TRACK_DRAWABLE);
+        if (trackDrawable != null) {
             mHasTrackImage = true;
-            mTrackImage.setBackgroundResource(trackResId);
-            mOverlay.add(mTrackImage);
+            trackImage.setBackground(trackDrawable);
+            mOverlay.add(trackImage);
+            width = Math.max(width, trackDrawable.getIntrinsicWidth());
         } else {
             mHasTrackImage = false;
         }
 
-        mThumbImage = new ImageView(context);
+        final ImageView thumbImage = new ImageView(context);
+        mThumbImage = thumbImage;
 
         // Add thumb to overlay if it has an image.
         final Drawable thumbDrawable = ta.getDrawable(THUMB_DRAWABLE);
         if (thumbDrawable != null) {
-            mThumbImage.setImageDrawable(thumbDrawable);
-            mOverlay.add(mThumbImage);
+            thumbImage.setImageDrawable(thumbDrawable);
+            mOverlay.add(thumbImage);
+            width = Math.max(width, thumbDrawable.getIntrinsicWidth());
         }
 
         // If necessary, apply minimum thumb width and height.
         if (thumbDrawable.getIntrinsicWidth() <= 0 || thumbDrawable.getIntrinsicHeight() <= 0) {
-            mThumbImage.setMinimumWidth(res.getDimensionPixelSize(R.dimen.fastscroll_thumb_width));
-            mThumbImage.setMinimumHeight(
+            final int minWidth = res.getDimensionPixelSize(R.dimen.fastscroll_thumb_width);
+            thumbImage.setMinimumWidth(minWidth);
+            thumbImage.setMinimumHeight(
                     res.getDimensionPixelSize(R.dimen.fastscroll_thumb_height));
+            width = Math.max(width, minWidth);
         }
 
+        mWidth = width;
+
         final int previewSize = res.getDimensionPixelSize(R.dimen.fastscroll_overlay_size);
         mPreviewImage = new ImageView(context);
         mPreviewImage.setMinimumWidth(previewSize);
@@ -297,10 +316,11 @@
         mOverlayPosition = ta.getInt(OVERLAY_POSITION, OVERLAY_FLOATING);
         ta.recycle();
 
+        mScrollBarStyle = listView.getScrollBarStyle();
         mScrollCompleted = true;
         mState = STATE_VISIBLE;
-        mMatchDragPosition =
-                context.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.HONEYCOMB;
+        mMatchDragPosition = context.getApplicationInfo().targetSdkVersion
+                >= Build.VERSION_CODES.HONEYCOMB;
 
         getSectionsFromIndexer();
         refreshDrawablePressedState();
@@ -362,6 +382,14 @@
         return mAlwaysShow;
     }
 
+    public void setScrollBarStyle(int style) {
+        if (mScrollBarStyle != style) {
+            mScrollBarStyle = style;
+
+            updateLayout();
+        }
+    }
+
     /**
      * Immediately transitions the fast scroller decorations to a hidden state.
      */
@@ -375,25 +403,29 @@
                     View.SCROLLBAR_POSITION_LEFT : View.SCROLLBAR_POSITION_RIGHT;
         }
 
-        mLayoutFromRight = position != View.SCROLLBAR_POSITION_LEFT;
+        if (mScrollbarPosition != position) {
+            mScrollbarPosition = position;
+            mLayoutFromRight = position != View.SCROLLBAR_POSITION_LEFT;
 
-        final int previewResId = mPreviewResId[mLayoutFromRight ? PREVIEW_RIGHT : PREVIEW_LEFT];
-        mPreviewImage.setBackgroundResource(previewResId);
+            final int previewResId = mPreviewResId[mLayoutFromRight ? PREVIEW_RIGHT : PREVIEW_LEFT];
+            mPreviewImage.setBackgroundResource(previewResId);
 
-        // Add extra padding for text.
-        final Drawable background = mPreviewImage.getBackground();
-        if (background != null) {
-            final Rect padding = mTempBounds;
-            background.getPadding(padding);
-            padding.offset(mPreviewPadding, mPreviewPadding);
-            mPreviewImage.setPadding(padding.left, padding.top, padding.right, padding.bottom);
+            // Add extra padding for text.
+            final Drawable background = mPreviewImage.getBackground();
+            if (background != null) {
+                final Rect padding = mTempBounds;
+                background.getPadding(padding);
+                padding.offset(mPreviewPadding, mPreviewPadding);
+                mPreviewImage.setPadding(padding.left, padding.top, padding.right, padding.bottom);
+            }
+
+            // Requires re-layout.
+            updateLayout();
         }
-
-        updateLayout();
     }
 
     public int getWidth() {
-        return mThumbImage.getWidth();
+        return mWidth;
     }
 
     public void onSizeChanged(int w, int h, int oldw, int oldh) {
@@ -437,7 +469,7 @@
     /**
      * Measures and layouts the scrollbar and decorations.
      */
-    private void updateLayout() {
+    public void updateLayout() {
         // Prevent re-entry when RTL properties change as a side-effect of
         // resolving padding.
         if (mUpdatingLayout) {
@@ -594,21 +626,36 @@
         out.set(left, top, right, bottom);
     }
 
+    /**
+     * Updates the container rectangle used for layout.
+     */
     private void updateContainerRect() {
         final AbsListView list = mList;
+        list.resolvePadding();
+
         final Rect container = mContainerRect;
         container.left = 0;
         container.top = 0;
         container.right = list.getWidth();
         container.bottom = list.getHeight();
 
-        final int scrollbarStyle = list.getScrollBarStyle();
+        final int scrollbarStyle = mScrollBarStyle;
         if (scrollbarStyle == View.SCROLLBARS_INSIDE_INSET
                 || scrollbarStyle == View.SCROLLBARS_INSIDE_OVERLAY) {
             container.left += list.getPaddingLeft();
             container.top += list.getPaddingTop();
             container.right -= list.getPaddingRight();
             container.bottom -= list.getPaddingBottom();
+
+            // In inset mode, we need to adjust for padded scrollbar width.
+            if (scrollbarStyle == View.SCROLLBARS_INSIDE_INSET) {
+                final int width = getWidth();
+                if (mScrollbarPosition == View.SCROLLBAR_POSITION_RIGHT) {
+                    container.right += width;
+                } else {
+                    container.left -= width;
+                }
+            }
         }
     }
 
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 3181164..9c21f0d 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -1378,6 +1378,8 @@
             } else {
                 dr.mDrawableSizeEnd = dr.mDrawableHeightEnd = 0;
             }
+            resetResolvedDrawables();
+            resolveDrawables();
         }
     }
 
diff --git a/services/java/com/android/server/DevicePolicyManagerService.java b/services/java/com/android/server/DevicePolicyManagerService.java
index 4c81006..43f95c3 100644
--- a/services/java/com/android/server/DevicePolicyManagerService.java
+++ b/services/java/com/android/server/DevicePolicyManagerService.java
@@ -2378,7 +2378,7 @@
     }
 
     @Override
-    public boolean setDeviceOwner(String packageName) {
+    public boolean setDeviceOwner(String packageName, String ownerName) {
         if (packageName == null
                 || !DeviceOwner.isInstalled(packageName, mContext.getPackageManager())) {
             throw new IllegalArgumentException("Invalid package name " + packageName
@@ -2386,7 +2386,7 @@
         }
         synchronized (this) {
             if (mDeviceOwner == null && !isDeviceProvisioned()) {
-                mDeviceOwner = new DeviceOwner(packageName);
+                mDeviceOwner = new DeviceOwner(packageName, ownerName);
                 mDeviceOwner.writeOwnerFile();
                 return true;
             } else {
@@ -2415,6 +2415,17 @@
         return null;
     }
 
+    @Override
+    public String getDeviceOwnerName() {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USERS, null);
+        synchronized (this) {
+            if (mDeviceOwner != null) {
+                return mDeviceOwner.getName();
+            }
+        }
+        return null;
+    }
+
     private boolean isDeviceProvisioned() {
         return Settings.Global.getInt(mContext.getContentResolver(),
                 Settings.Global.DEVICE_PROVISIONED, 0) > 0;
@@ -2488,15 +2499,18 @@
     static class DeviceOwner {
         private static final String DEVICE_OWNER_XML = "device_owner.xml";
         private static final String TAG_DEVICE_OWNER = "device-owner";
+        private static final String ATTR_NAME = "name";
         private static final String ATTR_PACKAGE = "package";
         private String mPackageName;
+        private String mOwnerName;
 
         DeviceOwner() {
             readOwnerFile();
         }
 
-        DeviceOwner(String packageName) {
+        DeviceOwner(String packageName, String ownerName) {
             this.mPackageName = packageName;
+            this.mOwnerName = ownerName;
         }
 
         static boolean isRegistered() {
@@ -2508,6 +2522,10 @@
             return mPackageName;
         }
 
+        String getName() {
+            return mOwnerName;
+        }
+
         static boolean isInstalled(String packageName, PackageManager pm) {
             try {
                 PackageInfo pi;
@@ -2539,6 +2557,7 @@
                             "Device Owner file does not start with device-owner tag: found " + tag);
                 }
                 mPackageName = parser.getAttributeValue(null, ATTR_PACKAGE);
+                mOwnerName = parser.getAttributeValue(null, ATTR_NAME);
                 input.close();
             } catch (XmlPullParserException xppe) {
                 Slog.e(TAG, "Error parsing device-owner file\n" + xppe);
@@ -2563,6 +2582,9 @@
                 out.startDocument(null, true);
                 out.startTag(null, TAG_DEVICE_OWNER);
                 out.attribute(null, ATTR_PACKAGE, mPackageName);
+                if (mOwnerName != null) {
+                    out.attribute(null, ATTR_NAME, mOwnerName);
+                }
                 out.endTag(null, TAG_DEVICE_OWNER);
                 out.endDocument();
                 out.flush();