Remove unnecessary targetSdk check in View
Fixes: 321162709
Android no longer accepts applications with targetSdk < 23.
Removed targetSdk API checks that target any version
earlier than 23(M) for View and ViewGroup.
Test: ran CtsViewTestCases
Change-Id: Ibed01c5c97249cc58512964dea475aa84e93f7d6
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 1cb2765..800fe41 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -204,7 +204,6 @@
import android.view.translation.ViewTranslationRequest;
import android.view.translation.ViewTranslationResponse;
import android.widget.Checkable;
-import android.widget.FrameLayout;
import android.widget.ScrollBarDrawable;
import android.window.OnBackInvokedDispatcher;
@@ -962,21 +961,6 @@
public HapticScrollFeedbackProvider mScrollFeedbackProvider = null;
/**
- * Use the old (broken) way of building MeasureSpecs.
- */
- private static boolean sUseBrokenMakeMeasureSpec = false;
-
- /**
- * Always return a size of 0 for MeasureSpec values with a mode of UNSPECIFIED
- */
- static boolean sUseZeroUnspecifiedMeasureSpec = false;
-
- /**
- * Ignore any optimizations using the measure cache.
- */
- private static boolean sIgnoreMeasureCache = false;
-
- /**
* Ignore an optimization that skips unnecessary EXACTLY layout passes.
*/
private static boolean sAlwaysRemeasureExactly = false;
@@ -5825,20 +5809,6 @@
if (!sCompatibilityDone && context != null) {
final int targetSdkVersion = context.getApplicationInfo().targetSdkVersion;
- // Older apps may need this compatibility hack for measurement.
- sUseBrokenMakeMeasureSpec = targetSdkVersion <= Build.VERSION_CODES.JELLY_BEAN_MR1;
-
- // Older apps expect onMeasure() to always be called on a layout pass, regardless
- // of whether a layout was requested on that View.
- sIgnoreMeasureCache = targetSdkVersion < Build.VERSION_CODES.KITKAT;
-
- // In M and newer, our widgets can pass a "hint" value in the size
- // for UNSPECIFIED MeasureSpecs. This lets child views of scrolling containers
- // know what the expected parent size is going to be, so e.g. list items can size
- // themselves at 1/3 the size of their container. It breaks older apps though,
- // specifically apps that use some popular open source libraries.
- sUseZeroUnspecifiedMeasureSpec = targetSdkVersion < Build.VERSION_CODES.M;
-
// Old versions of the platform would give different results from
// LinearLayout measurement passes using EXACTLY and non-EXACTLY
// modes, so we always need to run an additional EXACTLY pass.
@@ -6015,8 +5985,6 @@
boolean leftPaddingDefined = false;
boolean rightPaddingDefined = false;
- final int targetSdkVersion = context.getApplicationInfo().targetSdkVersion;
-
// Set default values.
viewFlagValues |= FOCUSABLE_AUTO;
viewFlagMasks |= FOCUSABLE_AUTO;
@@ -6237,11 +6205,7 @@
break;
//noinspection deprecation
case R.styleable.View_fadingEdge:
- if (targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
- // Ignore the attribute starting with ICS
- break;
- }
- // With builds < ICS, fall through and apply fading edges
+ break;
case R.styleable.View_requiresFadingEdge:
final int fadingEdge = a.getInt(attr, FADING_EDGE_NONE);
if (fadingEdge != FADING_EDGE_NONE) {
@@ -6379,35 +6343,25 @@
PROVIDER_BACKGROUND));
break;
case R.styleable.View_foreground:
- if (targetSdkVersion >= Build.VERSION_CODES.M || this instanceof FrameLayout) {
- setForeground(a.getDrawable(attr));
- }
+ setForeground(a.getDrawable(attr));
break;
case R.styleable.View_foregroundGravity:
- if (targetSdkVersion >= Build.VERSION_CODES.M || this instanceof FrameLayout) {
- setForegroundGravity(a.getInt(attr, Gravity.NO_GRAVITY));
- }
+ setForegroundGravity(a.getInt(attr, Gravity.NO_GRAVITY));
break;
case R.styleable.View_foregroundTintMode:
- if (targetSdkVersion >= Build.VERSION_CODES.M || this instanceof FrameLayout) {
- setForegroundTintBlendMode(
- Drawable.parseBlendMode(a.getInt(attr, -1),
- null));
- }
+ setForegroundTintBlendMode(
+ Drawable.parseBlendMode(a.getInt(attr, -1),
+ null));
break;
case R.styleable.View_foregroundTint:
- if (targetSdkVersion >= Build.VERSION_CODES.M || this instanceof FrameLayout) {
- setForegroundTintList(a.getColorStateList(attr));
- }
+ setForegroundTintList(a.getColorStateList(attr));
break;
case R.styleable.View_foregroundInsidePadding:
- if (targetSdkVersion >= Build.VERSION_CODES.M || this instanceof FrameLayout) {
- if (mForegroundInfo == null) {
- mForegroundInfo = new ForegroundInfo();
- }
- mForegroundInfo.mInsidePadding = a.getBoolean(attr,
- mForegroundInfo.mInsidePadding);
+ if (mForegroundInfo == null) {
+ mForegroundInfo = new ForegroundInfo();
}
+ mForegroundInfo.mInsidePadding = a.getBoolean(attr,
+ mForegroundInfo.mInsidePadding);
break;
case R.styleable.View_scrollIndicators:
final int scrollIndicators =
@@ -13882,11 +13836,6 @@
})
@ResolvedLayoutDir
public int getLayoutDirection() {
- final int targetSdkVersion = getContext().getApplicationInfo().targetSdkVersion;
- if (targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR1) {
- mPrivateFlags2 |= PFLAG2_LAYOUT_DIRECTION_RESOLVED;
- return LAYOUT_DIRECTION_RESOLVED_DEFAULT;
- }
return ((mPrivateFlags2 & PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL) ==
PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL) ? LAYOUT_DIRECTION_RTL : LAYOUT_DIRECTION_LTR;
}
@@ -22457,8 +22406,7 @@
* RTL not supported)
*/
private boolean isRtlCompatibilityMode() {
- final int targetSdkVersion = getContext().getApplicationInfo().targetSdkVersion;
- return targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR1 || !hasRtlSupport();
+ return !hasRtlSupport();
}
/**
@@ -28126,7 +28074,7 @@
cacheIndex = forceLayout ? -1 : mMeasureCache.indexOfKey(key);
}
- if (cacheIndex < 0 || sIgnoreMeasureCache) {
+ if (cacheIndex < 0) {
if (isTraversalTracingEnabled()) {
Trace.beginSection(mTracingStrings.onMeasure);
}
@@ -31112,11 +31060,7 @@
*/
public static int makeMeasureSpec(@IntRange(from = 0, to = (1 << MeasureSpec.MODE_SHIFT) - 1) int size,
@MeasureSpecMode int mode) {
- if (sUseBrokenMakeMeasureSpec) {
- return size + mode;
- } else {
- return (size & ~MODE_MASK) | (mode & MODE_MASK);
- }
+ return (size & ~MODE_MASK) | (mode & MODE_MASK);
}
/**
@@ -31127,9 +31071,6 @@
*/
@UnsupportedAppUsage
public static int makeSafeMeasureSpec(int size, int mode) {
- if (sUseZeroUnspecifiedMeasureSpec && mode == UNSPECIFIED) {
- return 0;
- }
return makeMeasureSpec(size, mode);
}
diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java
index ab529e6..b2c39b1 100644
--- a/core/java/android/view/ViewGroup.java
+++ b/core/java/android/view/ViewGroup.java
@@ -16,7 +16,6 @@
package android.view;
-import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1;
import static android.view.WindowInsetsAnimation.Callback.DISPATCH_MODE_CONTINUE_ON_SUBTREE;
import static android.view.WindowInsetsAnimation.Callback.DISPATCH_MODE_STOP;
@@ -55,7 +54,6 @@
import android.util.Pools;
import android.util.Pools.SynchronizedPool;
import android.util.SparseArray;
-import android.util.SparseBooleanArray;
import android.view.WindowInsetsAnimation.Bounds;
import android.view.WindowInsetsAnimation.Callback.DispatchMode;
import android.view.accessibility.AccessibilityEvent;
@@ -718,10 +716,7 @@
mGroupFlags |= FLAG_ANIMATION_DONE;
mGroupFlags |= FLAG_ANIMATION_CACHE;
mGroupFlags |= FLAG_ALWAYS_DRAWN_WITH_CACHE;
-
- if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.HONEYCOMB) {
- mGroupFlags |= FLAG_SPLIT_MOTION_EVENTS;
- }
+ mGroupFlags |= FLAG_SPLIT_MOTION_EVENTS;
setDescendantFocusability(FOCUS_BEFORE_DESCENDANTS);
@@ -3599,48 +3594,7 @@
childIndex = getAndVerifyPreorderedIndex(childrenCount, i, customOrder);
} catch (IndexOutOfBoundsException e) {
childIndex = i;
- if (mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.M) {
- Log.w(TAG, "Bad getChildDrawingOrder while collecting assist @ "
- + i + " of " + childrenCount, e);
- // At least one app is failing when we call getChildDrawingOrder
- // at this point, so deal semi-gracefully with it by falling back
- // on the basic order.
- customOrder = false;
- if (i > 0) {
- // If we failed at the first index, there really isn't
- // anything to do -- we will just proceed with the simple
- // sequence order.
- // Otherwise, we failed in the middle, so need to come up
- // with an order for the remaining indices and use that.
- // Failed at the first one, easy peasy.
- int[] permutation = new int[childrenCount];
- SparseBooleanArray usedIndices = new SparseBooleanArray();
- // Go back and collected the indices we have done so far.
- for (int j = 0; j < i; j++) {
- permutation[j] = getChildDrawingOrder(childrenCount, j);
- usedIndices.put(permutation[j], true);
- }
- // Fill in the remaining indices with indices that have not
- // yet been used.
- int nextIndex = 0;
- for (int j = i; j < childrenCount; j++) {
- while (usedIndices.get(nextIndex, false)) {
- nextIndex++;
- }
- permutation[j] = nextIndex;
- nextIndex++;
- }
- // Build the final view list.
- preorderedList = new ArrayList<>(childrenCount);
- for (int j = 0; j < childrenCount; j++) {
- final int index = permutation[j];
- final View child = mChildren[index];
- preorderedList.add(child);
- }
- }
- } else {
- throw e;
- }
+ throw e;
}
final View child = getAndVerifyPreorderedView(preorderedList, mChildren,
childIndex);
@@ -7109,12 +7063,12 @@
} else if (childDimension == LayoutParams.MATCH_PARENT) {
// Child wants to be our size... find out how big it should
// be
- resultSize = View.sUseZeroUnspecifiedMeasureSpec ? 0 : size;
+ resultSize = size;
resultMode = MeasureSpec.UNSPECIFIED;
} else if (childDimension == LayoutParams.WRAP_CONTENT) {
// Child wants to determine its own size.... find out how
// big it should be
- resultSize = View.sUseZeroUnspecifiedMeasureSpec ? 0 : size;
+ resultSize = size;
resultMode = MeasureSpec.UNSPECIFIED;
}
break;
@@ -8662,8 +8616,7 @@
}
final boolean hasRtlSupport = c.getApplicationInfo().hasRtlSupport();
- final int targetSdkVersion = c.getApplicationInfo().targetSdkVersion;
- if (targetSdkVersion < JELLY_BEAN_MR1 || !hasRtlSupport) {
+ if (!hasRtlSupport) {
mMarginFlags |= RTL_COMPATIBILITY_MODE_MASK;
}