Merge "Fix bug 7338736. Only starting FUL if the screen is on" into jb-mr1-dev
diff --git a/cmds/pm/src/com/android/commands/pm/Pm.java b/cmds/pm/src/com/android/commands/pm/Pm.java
index 463a18c..16d4ad6 100644
--- a/cmds/pm/src/com/android/commands/pm/Pm.java
+++ b/cmds/pm/src/com/android/commands/pm/Pm.java
@@ -43,6 +43,7 @@
 import android.os.RemoteException;
 import android.os.ServiceManager;
 import android.os.UserHandle;
+import android.os.UserManager;
 
 import java.io.File;
 import java.lang.reflect.Field;
@@ -174,6 +175,11 @@
             return;
         }
 
+        if ("get-max-users".equals(op)) {
+            runGetMaxUsers();
+            return;
+        }
+
         try {
             if (args.length == 1) {
                 if (args[0].equalsIgnoreCase("-l")) {
@@ -1017,8 +1023,10 @@
             return;
         }
         try {
-            if (!mUm.removeUser(userId)) {
-                System.err.println("Error: couldn't remove user #" + userId + ".");
+            if (mUm.removeUser(userId)) {
+                System.out.println("Success: removed user");
+            } else {
+                System.err.println("Error: couldn't remove user id " + userId);
             }
         } catch (RemoteException e) {
             System.err.println(e.toString());
@@ -1042,6 +1050,11 @@
             System.err.println(PM_NOT_RUNNING_ERR);
         }
     }
+
+    public void runGetMaxUsers() {
+        System.out.println("Maximum supported users: " + UserManager.getMaxSupportedUsers());
+    }
+
     class PackageDeleteObserver extends IPackageDeleteObserver.Stub {
         boolean finished;
         boolean result;
@@ -1451,6 +1464,7 @@
         System.err.println("       pm trim-caches DESIRED_FREE_SPACE");
         System.err.println("       pm create-user USER_NAME");
         System.err.println("       pm remove-user USER_ID");
+        System.err.println("       pm get-max-users");
         System.err.println("");
         System.err.println("pm list packages: prints all packages, optionally only");
         System.err.println("  those whose package name contains the text in FILTER.  Options:");
diff --git a/core/java/android/app/FragmentBreadCrumbs.java b/core/java/android/app/FragmentBreadCrumbs.java
index df64035..b810b89 100644
--- a/core/java/android/app/FragmentBreadCrumbs.java
+++ b/core/java/android/app/FragmentBreadCrumbs.java
@@ -19,7 +19,9 @@
 import android.animation.LayoutTransition;
 import android.app.FragmentManager.BackStackEntry;
 import android.content.Context;
+import android.content.res.TypedArray;
 import android.util.AttributeSet;
+import android.view.Gravity;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -51,7 +53,11 @@
     private OnClickListener mParentClickListener;
 
     private OnBreadCrumbClickListener mOnBreadCrumbClickListener;
-    
+
+    private int mGravity;
+
+    private static final int DEFAULT_GRAVITY = Gravity.START | Gravity.CENTER_VERTICAL;
+
     /**
      * Interface to intercept clicks on the bread crumbs.
      */
@@ -80,6 +86,14 @@
 
     public FragmentBreadCrumbs(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
+
+        TypedArray a = context.obtainStyledAttributes(attrs,
+                com.android.internal.R.styleable.FragmentBreadCrumbs, defStyle, 0);
+
+        mGravity = a.getInt(com.android.internal.R.styleable.FragmentBreadCrumbs_gravity,
+                DEFAULT_GRAVITY);
+
+        a.recycle();
     }
 
     /**
@@ -159,16 +173,50 @@
 
     @Override
     protected void onLayout(boolean changed, int l, int t, int r, int b) {
-        // Eventually we should implement our own layout of the views,
-        // rather than relying on a linear layout.
+        // Eventually we should implement our own layout of the views, rather than relying on
+        // a single linear layout.
         final int childCount = getChildCount();
-        for (int i = 0; i < childCount; i++) {
-            final View child = getChildAt(i);
-
-            int childRight = mPaddingLeft + child.getMeasuredWidth() - mPaddingRight;
-            int childBottom = mPaddingTop + child.getMeasuredHeight() - mPaddingBottom;
-            child.layout(mPaddingLeft, mPaddingTop, childRight, childBottom);
+        if (childCount == 0) {
+            return;
         }
+
+        final View child = getChildAt(0);
+
+        final int childTop = mPaddingTop;
+        final int childBottom = mPaddingTop + child.getMeasuredHeight() - mPaddingBottom;
+
+        int childLeft;
+        int childRight;
+
+        final int layoutDirection = getLayoutDirection();
+        final int horizontalGravity = mGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK;
+        switch (Gravity.getAbsoluteGravity(horizontalGravity, layoutDirection)) {
+            case Gravity.RIGHT:
+                childRight = mRight - mLeft - mPaddingRight;
+                childLeft = childRight - child.getMeasuredWidth();
+                break;
+
+            case Gravity.CENTER_HORIZONTAL:
+                childLeft = mPaddingLeft + (mRight - mLeft - child.getMeasuredWidth()) / 2;
+                childRight = childLeft + child.getMeasuredWidth();
+                break;
+
+            case Gravity.LEFT:
+            default:
+                childLeft = mPaddingLeft;
+                childRight = childLeft + child.getMeasuredWidth();
+                break;
+        }
+
+        if (childLeft < mPaddingLeft) {
+            childLeft = mPaddingLeft;
+        }
+
+        if (childRight > mRight - mLeft - mPaddingRight) {
+            childRight = mRight - mLeft - mPaddingRight;
+        }
+
+        child.layout(childLeft, childTop, childRight, childBottom);
     }
 
     @Override
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 384f1ab..3550df9 100755
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -5781,4 +5781,10 @@
         <attr name="leftToRight" format="boolean" />
     </declare-styleable>
 
+    <!-- Attributes that can be used with <code>&lt;FragmentBreadCrumbs&gt;</code>
+    tags. -->
+    <declare-styleable name="FragmentBreadCrumbs">
+        <attr name="gravity" />
+    </declare-styleable>
+
 </resources>