Compatibility measurement hacks when targetSdkVersion <= JB-MR1

All three of these are interrelated!

* Allow broken MeasureSpec values. The long-standing implementation
  of MeasureSpec.makeMeasureSpec has been to add both values rather
  than masking/or-ing the values together. Some old code relied on
  this, such as if it mixed up size/mode params.

* Disable ImageView adjustViewBounds allowing the view to grow beyond
  its initial size. A bug in RelativeLayout in the presence of the
  above MeasureSpec fix causes this not to work properly in apps.

* Allow RelativeLayout to send overflowed/bogus MeasureSpec values
  when measured with MeasureSpec.UNSPECIFIED mode. Some apps have
  custom child views that do not properly handle UNSPECIFIED
  measurements, but the exact overflow semantics caused this to
  generate AT_MOST $REALLYBIG MeasureSpecs for those views instead if
  they were placed inside a RelativeLayout in a scrolling container.

Change-Id: I977a5f1ba5637f0cba3d26a70139e2bcd021fc9c
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 63019bd..40eaa7a 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -40,6 +40,7 @@
 import android.graphics.drawable.ColorDrawable;
 import android.graphics.drawable.Drawable;
 import android.hardware.display.DisplayManagerGlobal;
+import android.os.Build;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.IBinder;
@@ -688,6 +689,8 @@
      */
     public static final int NO_ID = -1;
 
+    private static boolean sUseBrokenMakeMeasureSpec = false;
+
     /**
      * This view does not want keystrokes. Use with TAKES_FOCUS_MASK when
      * calling setFlags.
@@ -3234,6 +3237,12 @@
         setOverScrollMode(OVER_SCROLL_IF_CONTENT_SCROLLS);
         mUserPaddingStart = UNDEFINED_PADDING;
         mUserPaddingEnd = UNDEFINED_PADDING;
+
+        if (!sUseBrokenMakeMeasureSpec && context.getApplicationInfo().targetSdkVersion <=
+                Build.VERSION_CODES.JELLY_BEAN_MR1 ) {
+            // Older apps may need this compatibility hack for measurement.
+            sUseBrokenMakeMeasureSpec = true;
+        }
     }
 
     /**
@@ -17327,7 +17336,11 @@
          * @return the measure specification based on size and mode
          */
         public static int makeMeasureSpec(int size, int mode) {
-            return (size & ~MODE_MASK) | (mode & MODE_MASK);
+            if (sUseBrokenMakeMeasureSpec) {
+                return size + mode;
+            } else {
+                return (size & ~MODE_MASK) | (mode & MODE_MASK);
+            }
         }
 
         /**