Skip to content

Commit

Permalink
Fix Android linting using old minSdkVersion (facebook#36587)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#36587

Right now an arc focus'd Android Studio (and presumably Android studio in OSS) will warn on any call incompatible with API 20 and later, but we only target API 21+ (Lollipop). See D24380233 for where we removed Lollipop and earlier code in October 2020.

https://pxl.cl/2xMGG

From searching, these warnings are controlled by the closest parent `AndroidManifest.xml`. We don't use this to control the actual SDK version, but we can add one for correct lint warning.

This change does that, then removes any extraneous version checks that were added since then.

Changelog:
[Internal]

Reviewed By: cortinico

Differential Revision: D44305441

fbshipit-source-id: f7b9b8889f4b0523a1e7b1a14808b0f587012a90
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Apr 19, 2023
1 parent 537c28a commit 5f0c3a3
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 40 deletions.
15 changes: 15 additions & 0 deletions packages/react-native/ReactAndroid/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
>

<!-- This is necessary to inform the linter about our min API version. The linter walk the tree
up from the file to lint until it find an AndroidManifest with a minSdkVersion. This is then used
as the min SDK to lint the file.-->
<uses-sdk
android:minSdkVersion="21"
android:targetSdkVersion="33"
/>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

package com.facebook.react.modules.network;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
Expand Down Expand Up @@ -76,7 +74,6 @@ public void clearCookies(final Callback callback) {
clearCookiesAsync(callback);
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void clearCookiesAsync(final Callback callback) {
CookieManager cookieManager = getCookieManager();
if (cookieManager != null) {
Expand Down Expand Up @@ -104,7 +101,6 @@ public void addCookies(final String url, final List<String> cookies) {
mCookieSaver.onCookiesModified();
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void addCookieAsync(String url, String cookie) {
CookieManager cookieManager = getCookieManager();
if (cookieManager != null) {
Expand Down Expand Up @@ -199,7 +195,6 @@ public void run() {
});
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void flush() {
CookieManager cookieManager = getCookieManager();
if (cookieManager != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public void setColor(final double colorDouble, final boolean animated) {

UiThreadUtil.runOnUiThread(
new GuardedRunnable(getReactApplicationContext()) {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void runGuarded() {
activity
Expand Down Expand Up @@ -118,7 +117,6 @@ public void setTranslucent(final boolean translucent) {

UiThreadUtil.runOnUiThread(
new GuardedRunnable(getReactApplicationContext()) {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void runGuarded() {
// If the status bar is translucent hook into the window insets calculations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@

package com.facebook.react.views.switchview;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.PorterDuff;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.RippleDrawable;
import android.os.Build;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.SwitchCompat;

Expand Down Expand Up @@ -51,7 +49,6 @@ public void setChecked(boolean checked) {
}

@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void setBackgroundColor(int color) {
setBackground(
new RippleDrawable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

package com.facebook.react.views.text;

import android.annotation.TargetApi;
import android.os.Build;
import android.text.TextPaint;
import android.text.style.MetricAffectingSpan;

Expand All @@ -18,7 +16,6 @@
* <p>The letter spacing is specified in pixels, which are converted to ems at paint time; this span
* must therefore be applied after any spans affecting font size.
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public class CustomLetterSpacingSpan extends MetricAffectingSpan implements ReactSpan {

private final float mLetterSpacing;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -706,12 +706,10 @@ private void stripStyleEquivalentSpans(SpannableStringBuilder sb) {
stripSpansOfKind(
sb, ReactUnderlineSpan.class, (span) -> (getPaintFlags() & Paint.UNDERLINE_TEXT_FLAG) != 0);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
stripSpansOfKind(
sb,
CustomLetterSpacingSpan.class,
(span) -> span.getSpacing() == mTextAttributes.getEffectiveLetterSpacing());
}
stripSpansOfKind(
sb,
CustomLetterSpacingSpan.class,
(span) -> span.getSpacing() == mTextAttributes.getEffectiveLetterSpacing());

stripSpansOfKind(
sb,
Expand Down Expand Up @@ -769,15 +767,10 @@ private void addSpansFromStyleAttributes(SpannableStringBuilder workingText) {
workingText.setSpan(new ReactUnderlineSpan(), 0, workingText.length(), spanFlags);
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
float effectiveLetterSpacing = mTextAttributes.getEffectiveLetterSpacing();
if (!Float.isNaN(effectiveLetterSpacing)) {
workingText.setSpan(
new CustomLetterSpacingSpan(effectiveLetterSpacing),
0,
workingText.length(),
spanFlags);
}
float effectiveLetterSpacing = mTextAttributes.getEffectiveLetterSpacing();
if (!Float.isNaN(effectiveLetterSpacing)) {
workingText.setSpan(
new CustomLetterSpacingSpan(effectiveLetterSpacing), 0, workingText.length(), spanFlags);
}

if (mFontStyle != UNSET
Expand Down Expand Up @@ -1087,9 +1080,7 @@ protected void applyTextAttributes() {

float effectiveLetterSpacing = mTextAttributes.getEffectiveLetterSpacing();
if (!Float.isNaN(effectiveLetterSpacing)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setLetterSpacing(effectiveLetterSpacing);
}
setLetterSpacing(effectiveLetterSpacing);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

package com.facebook.react.views.view;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color;
Expand All @@ -31,7 +30,6 @@ public class ReactDrawableHelper {

private static final TypedValue sResolveOutValue = new TypedValue();

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static Drawable createDrawableFromJSDescription(
Context context, ReadableMap drawableDescriptionDict) {
String type = drawableDescriptionDict.getString("type");
Expand All @@ -52,7 +50,6 @@ public static Drawable createDrawableFromJSDescription(
}
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static int getAttrId(Context context, String attr) {
SoftAssertions.assertNotNull(attr);
if ("selectableItemBackground".equals(attr)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

package com.facebook.react.views.view;

import static android.os.Build.VERSION_CODES.LOLLIPOP;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
Expand Down Expand Up @@ -1396,7 +1393,6 @@ public int getBorderColor(int position) {
return ReactViewBackgroundDrawable.colorFromAlphaAndRGBComponents(alpha, rgb);
}

@TargetApi(LOLLIPOP)
public RectF getDirectionAwareBorderInsets() {
final float borderWidth = getBorderWidthOrDefaultTo(0, Spacing.ALL);
final float borderTopWidth = getBorderWidthOrDefaultTo(borderWidth, Spacing.TOP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Build;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -58,7 +57,6 @@
* Backing for a React View. Has support for borders, but since borders aren't common, lazy
* initializes most of the storage needed for them.
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public class ReactViewGroup extends ViewGroup
implements ReactInterceptingViewGroup,
ReactClippingViewGroup,
Expand Down

0 comments on commit 5f0c3a3

Please sign in to comment.