Merge "Fix VFY issues in appcompat-resources" into androidx-main
diff --git a/appcompat/appcompat-resources/lint-baseline.xml b/appcompat/appcompat-resources/lint-baseline.xml
index 4982402..4826d47 100644
--- a/appcompat/appcompat-resources/lint-baseline.xml
+++ b/appcompat/appcompat-resources/lint-baseline.xml
@@ -112,94 +112,6 @@
     </issue>
 
     <issue
-        id="ClassVerificationFailure"
-        message="This call references a method added in API level 18; however, the containing class androidx.appcompat.graphics.drawable.AnimatedStateListDrawableCompat.AnimationDrawableTransition is reachable from earlier API levels and will fail run-time class verification."
-        errorLine1="                anim.setAutoCancel(true);"
-        errorLine2="                     ~~~~~~~~~~~~~">
-        <location
-            file="src/main/java/androidx/appcompat/graphics/drawable/AnimatedStateListDrawableCompat.java"
-            line="401"
-            column="22"/>
-    </issue>
-
-    <issue
-        id="ClassVerificationFailure"
-        message="This call references a method added in API level 21; however, the containing class androidx.appcompat.graphics.drawable.AnimatedStateListDrawableCompat is reachable from earlier API levels and will fail run-time class verification."
-        errorLine1="            state.mChangingConfigurations |= a.getChangingConfigurations();"
-        errorLine2="                                               ~~~~~~~~~~~~~~~~~~~~~~~~~">
-        <location
-            file="src/main/java/androidx/appcompat/graphics/drawable/AnimatedStateListDrawableCompat.java"
-            line="452"
-            column="48"/>
-    </issue>
-
-    <issue
-        id="ClassVerificationFailure"
-        message="This call references a method added in API level 21; however, the containing class androidx.appcompat.graphics.drawable.AnimatedStateListDrawableCompat is reachable from earlier API levels and will fail run-time class verification."
-        errorLine1="                dr = Drawable.createFromXmlInner(resources, parser, attrs, theme);"
-        errorLine2="                              ~~~~~~~~~~~~~~~~~~">
-        <location
-            file="src/main/java/androidx/appcompat/graphics/drawable/AnimatedStateListDrawableCompat.java"
-            line="541"
-            column="31"/>
-    </issue>
-
-    <issue
-        id="ClassVerificationFailure"
-        message="This call references a method added in API level 21; however, the containing class androidx.appcompat.graphics.drawable.AnimatedStateListDrawableCompat is reachable from earlier API levels and will fail run-time class verification."
-        errorLine1="                dr = Drawable.createFromXmlInner(resources, parser, attrs, theme);"
-        errorLine2="                              ~~~~~~~~~~~~~~~~~~">
-        <location
-            file="src/main/java/androidx/appcompat/graphics/drawable/AnimatedStateListDrawableCompat.java"
-            line="591"
-            column="31"/>
-    </issue>
-
-    <issue
-        id="ClassVerificationFailure"
-        message="This call references a method added in API level 21; however, the containing class androidx.appcompat.widget.ResourceManagerInternal.DrawableDelegate is reachable from earlier API levels and will fail run-time class verification."
-        errorLine1="                        drawable.inflate(context.getResources(), parser, attrs, theme);"
-        errorLine2="                                 ~~~~~~~">
-        <location
-            file="src/main/java/androidx/appcompat/widget/ResourceManagerInternal.java"
-            line="565"
-            column="34"/>
-    </issue>
-
-    <issue
-        id="ClassVerificationFailure"
-        message="This call references a method added in API level 15; however, the containing class androidx.appcompat.widget.ResourcesWrapper is reachable from earlier API levels and will fail run-time class verification."
-        errorLine1="        mResources.getValueForDensity(id, density, outValue, resolveRefs);"
-        errorLine2="                   ~~~~~~~~~~~~~~~~~~">
-        <location
-            file="src/main/java/androidx/appcompat/widget/ResourcesWrapper.java"
-            line="241"
-            column="20"/>
-    </issue>
-
-    <issue
-        id="ClassVerificationFailure"
-        message="This call references a method added in API level 21; however, the containing class androidx.appcompat.graphics.drawable.StateListDrawable is reachable from earlier API levels and will fail run-time class verification."
-        errorLine1="            state.mChangingConfigurations |= a.getChangingConfigurations();"
-        errorLine2="                                               ~~~~~~~~~~~~~~~~~~~~~~~~~">
-        <location
-            file="src/main/java/androidx/appcompat/graphics/drawable/StateListDrawable.java"
-            line="159"
-            column="48"/>
-    </issue>
-
-    <issue
-        id="ClassVerificationFailure"
-        message="This call references a method added in API level 21; however, the containing class androidx.appcompat.graphics.drawable.StateListDrawable is reachable from earlier API levels and will fail run-time class verification."
-        errorLine1="                    dr = Drawable.createFromXmlInner(r, parser, attrs, theme);"
-        errorLine2="                                  ~~~~~~~~~~~~~~~~~~">
-        <location
-            file="src/main/java/androidx/appcompat/graphics/drawable/StateListDrawable.java"
-            line="218"
-            column="35"/>
-    </issue>
-
-    <issue
         id="KotlinPropertyAccess"
         message="The getter return type (`Theme`) and setter parameter type (`int`) getter and setter methods for property `theme` should have exactly the same type to allow be accessed as a property from Kotlin; see https://android.github.io/kotlin-guides/interop.html#property-prefixes"
         errorLine1="    public Resources.Theme getTheme() {"
diff --git a/appcompat/appcompat-resources/src/main/java/androidx/appcompat/graphics/drawable/AnimatedStateListDrawableCompat.java b/appcompat/appcompat-resources/src/main/java/androidx/appcompat/graphics/drawable/AnimatedStateListDrawableCompat.java
index f57aace..67c4235 100644
--- a/appcompat/appcompat-resources/src/main/java/androidx/appcompat/graphics/drawable/AnimatedStateListDrawableCompat.java
+++ b/appcompat/appcompat-resources/src/main/java/androidx/appcompat/graphics/drawable/AnimatedStateListDrawableCompat.java
@@ -39,6 +39,7 @@
 import androidx.annotation.DrawableRes;
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
+import androidx.appcompat.resources.Compatibility;
 import androidx.appcompat.resources.R;
 import androidx.appcompat.widget.ResourceManagerInternal;
 import androidx.collection.LongSparseArray;
@@ -398,7 +399,7 @@
             final ObjectAnimator anim =
                     ObjectAnimator.ofInt(ad, "currentIndex", fromFrame, toFrame);
             if (SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
-                anim.setAutoCancel(true);
+                Compatibility.Api18Impl.setAutoCancel(anim, true);
             }
             anim.setDuration(interp.getTotalDuration());
             anim.setInterpolator(interp);
@@ -449,7 +450,7 @@
         final AnimatedStateListState state = mState;
         // Account for any configuration changes.
         if (SDK_INT >= LOLLIPOP) {
-            state.mChangingConfigurations |= a.getChangingConfigurations();
+            state.mChangingConfigurations |= Compatibility.Api21Impl.getChangingConfigurations(a);
         }
         // Extract the theme attributes, if any.
         state.setVariablePadding(
@@ -538,7 +539,7 @@
                 dr = AnimatedVectorDrawableCompat.createFromXmlInner(context, resources, parser,
                         attrs, theme);
             } else if (SDK_INT >= LOLLIPOP) {
-                dr = Drawable.createFromXmlInner(resources, parser, attrs, theme);
+                dr = Compatibility.Api21Impl.createFromXmlInner(resources, parser, attrs, theme);
             } else {
                 dr = Drawable.createFromXmlInner(resources, parser, attrs);
             }
@@ -588,7 +589,7 @@
             if (parser.getName().equals("vector")) {
                 dr = VectorDrawableCompat.createFromXmlInner(resources, parser, attrs, theme);
             } else if (SDK_INT >= LOLLIPOP) {
-                dr = Drawable.createFromXmlInner(resources, parser, attrs, theme);
+                dr = Compatibility.Api21Impl.createFromXmlInner(resources, parser, attrs, theme);
             } else {
                 dr = Drawable.createFromXmlInner(resources, parser, attrs);
             }
diff --git a/appcompat/appcompat-resources/src/main/java/androidx/appcompat/graphics/drawable/StateListDrawable.java b/appcompat/appcompat-resources/src/main/java/androidx/appcompat/graphics/drawable/StateListDrawable.java
index e501460..ceabac7 100644
--- a/appcompat/appcompat-resources/src/main/java/androidx/appcompat/graphics/drawable/StateListDrawable.java
+++ b/appcompat/appcompat-resources/src/main/java/androidx/appcompat/graphics/drawable/StateListDrawable.java
@@ -35,6 +35,7 @@
 import androidx.annotation.Nullable;
 import androidx.annotation.RequiresApi;
 import androidx.annotation.RestrictTo;
+import androidx.appcompat.resources.Compatibility;
 import androidx.appcompat.resources.R;
 import androidx.appcompat.widget.ResourceManagerInternal;
 
@@ -156,7 +157,7 @@
         final StateListState state = mStateListState;
         // Account for any configuration changes.
         if (SDK_INT >= LOLLIPOP) {
-            state.mChangingConfigurations |= a.getChangingConfigurations();
+            state.mChangingConfigurations |= Compatibility.Api21Impl.getChangingConfigurations(a);
         }
         state.mVariablePadding = a.getBoolean(
                 R.styleable.StateListDrawable_android_variablePadding, state.mVariablePadding);
@@ -215,7 +216,7 @@
                                     + "child tag defining a drawable");
                 }
                 if (SDK_INT >= LOLLIPOP) {
-                    dr = Drawable.createFromXmlInner(r, parser, attrs, theme);
+                    dr = Compatibility.Api21Impl.createFromXmlInner(r, parser, attrs, theme);
                 } else {
                     dr = Drawable.createFromXmlInner(r, parser, attrs);
                 }
diff --git a/appcompat/appcompat-resources/src/main/java/androidx/appcompat/resources/Compatibility.java b/appcompat/appcompat-resources/src/main/java/androidx/appcompat/resources/Compatibility.java
new file mode 100644
index 0000000..189b793
--- /dev/null
+++ b/appcompat/appcompat-resources/src/main/java/androidx/appcompat/resources/Compatibility.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package androidx.appcompat.resources;
+
+import android.animation.ObjectAnimator;
+import android.content.res.Resources;
+import android.content.res.TypedArray;
+import android.graphics.drawable.Drawable;
+import android.util.AttributeSet;
+import android.util.TypedValue;
+
+import androidx.annotation.DoNotInline;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.annotation.RequiresApi;
+import androidx.annotation.RestrictTo;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+import java.io.IOException;
+
+/**
+ * Unified ApiXXImpls for appcompat-resources.
+ *
+ * @hide
+ */
+@RestrictTo(RestrictTo.Scope.LIBRARY)
+public final class Compatibility {
+    private Compatibility() {
+        // This class is not instantiable.
+    }
+
+    @RequiresApi(21)
+    public static class Api21Impl {
+        private Api21Impl() {
+            // This class is not instantiable.
+        }
+
+        @DoNotInline
+        public static void inflate(@NonNull Drawable drawable, @NonNull Resources r,
+                @NonNull XmlPullParser parser, @NonNull AttributeSet attrs,
+                @Nullable Resources.Theme theme) throws IOException, XmlPullParserException {
+            drawable.inflate(r, parser, attrs, theme);
+        }
+
+        @DoNotInline
+        public static int getChangingConfigurations(@NonNull TypedArray typedArray) {
+            return typedArray.getChangingConfigurations();
+        }
+
+        @NonNull
+        @DoNotInline
+        public static Drawable createFromXmlInner(@NonNull Resources r,
+                @NonNull XmlPullParser parser, @NonNull AttributeSet attrs,
+                @Nullable Resources.Theme theme) throws IOException, XmlPullParserException {
+            return Drawable.createFromXmlInner(r, parser, attrs, theme);
+        }
+    }
+
+    @RequiresApi(18)
+    public static class Api18Impl {
+        private Api18Impl() {
+            // This class is not instantiable.
+        }
+
+        @DoNotInline
+        public static void setAutoCancel(@NonNull ObjectAnimator objectAnimator, boolean cancel) {
+            objectAnimator.setAutoCancel(cancel);
+        }
+    }
+
+    @RequiresApi(15)
+    public static class Api15Impl {
+        private Api15Impl() {
+            // This class is not instantiable.
+        }
+
+        @DoNotInline
+        public static void getValueForDensity(@NonNull Resources resources, int id, int density,
+                @NonNull TypedValue outValue, boolean resolveRefs) {
+            resources.getValueForDensity(id, density, outValue, resolveRefs);
+        }
+    }
+}
diff --git a/appcompat/appcompat-resources/src/main/java/androidx/appcompat/widget/ResourceManagerInternal.java b/appcompat/appcompat-resources/src/main/java/androidx/appcompat/widget/ResourceManagerInternal.java
index dfb0754..a269912 100644
--- a/appcompat/appcompat-resources/src/main/java/androidx/appcompat/widget/ResourceManagerInternal.java
+++ b/appcompat/appcompat-resources/src/main/java/androidx/appcompat/widget/ResourceManagerInternal.java
@@ -38,6 +38,7 @@
 import androidx.annotation.Nullable;
 import androidx.annotation.RestrictTo;
 import androidx.appcompat.graphics.drawable.AnimatedStateListDrawableCompat;
+import androidx.appcompat.resources.Compatibility;
 import androidx.appcompat.resources.R;
 import androidx.collection.LongSparseArray;
 import androidx.collection.LruCache;
@@ -562,7 +563,8 @@
                                     .asSubclass(Drawable.class);
                     Drawable drawable = drawableClass.getDeclaredConstructor().newInstance();
                     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
-                        drawable.inflate(context.getResources(), parser, attrs, theme);
+                        Compatibility.Api21Impl.inflate(drawable, context.getResources(), parser,
+                                attrs, theme);
                     } else {
                         drawable.inflate(context.getResources(), parser, attrs);
                     }
diff --git a/appcompat/appcompat-resources/src/main/java/androidx/appcompat/widget/ResourcesWrapper.java b/appcompat/appcompat-resources/src/main/java/androidx/appcompat/widget/ResourcesWrapper.java
index d81cfe7..b854a9e 100644
--- a/appcompat/appcompat-resources/src/main/java/androidx/appcompat/widget/ResourcesWrapper.java
+++ b/appcompat/appcompat-resources/src/main/java/androidx/appcompat/widget/ResourcesWrapper.java
@@ -29,6 +29,7 @@
 import android.util.TypedValue;
 
 import androidx.annotation.RequiresApi;
+import androidx.appcompat.resources.Compatibility;
 import androidx.core.content.res.ResourcesCompat;
 
 import org.xmlpull.v1.XmlPullParserException;
@@ -238,7 +239,7 @@
     @Override
     public void getValueForDensity(int id, int density, TypedValue outValue, boolean resolveRefs)
             throws NotFoundException {
-        mResources.getValueForDensity(id, density, outValue, resolveRefs);
+        Compatibility.Api15Impl.getValueForDensity(mResources, id, density, outValue, resolveRefs);
     }
 
     @Override