Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 383e228

Browse files
authored
Bump everything to Android 21 (#51032)
Followed the linter, got rid of a bunch of version check/guards we don't need anymore.
1 parent aebac40 commit 383e228

File tree

45 files changed

+196
-670
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+196
-670
lines changed

shell/platform/android/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
-->
66
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="io.flutter.app" android:versionCode="1" android:versionName="0.0.1">
77

8-
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="34" />
8+
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="34" />
99
<uses-permission android:name="android.permission.INTERNET" />
1010
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
1111
<uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true" />

shell/platform/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ android {
2323
compileSdkVersion 34
2424

2525
defaultConfig {
26-
minSdkVersion 19
26+
minSdkVersion 21
2727
}
2828

2929
sourceSets {

shell/platform/android/io/flutter/app/FlutterActivityDelegate.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import android.content.res.Configuration;
1818
import android.content.res.Resources.NotFoundException;
1919
import android.graphics.drawable.Drawable;
20-
import android.os.Build;
2120
import android.os.Bundle;
2221
import android.util.TypedValue;
2322
import android.view.View;
@@ -137,12 +136,10 @@ public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
137136

138137
@Override
139138
public void onCreate(Bundle savedInstanceState) {
140-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
141-
Window window = activity.getWindow();
142-
window.addFlags(LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
143-
window.setStatusBarColor(0x40000000);
144-
window.getDecorView().setSystemUiVisibility(PlatformPlugin.DEFAULT_SYSTEM_UI);
145-
}
139+
Window window = activity.getWindow();
140+
window.addFlags(LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
141+
window.setStatusBarColor(0x40000000);
142+
window.getDecorView().setSystemUiVisibility(PlatformPlugin.DEFAULT_SYSTEM_UI);
146143

147144
String[] args = getArgsFromIntent(activity.getIntent());
148145
FlutterMain.ensureInitializationComplete(activity.getApplicationContext(), args);

shell/platform/android/io/flutter/embedding/android/AndroidTouchProcessor.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,7 @@ public boolean onTouchEvent(@NonNull MotionEvent event, @NonNull Matrix transfor
204204
public boolean onGenericMotionEvent(@NonNull MotionEvent event, @NonNull Context context) {
205205
// Method isFromSource is only available in API 18+ (Jelly Bean MR2)
206206
// Mouse hover support is not implemented for API < 18.
207-
boolean isPointerEvent =
208-
Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2
209-
&& event.isFromSource(InputDevice.SOURCE_CLASS_POINTER);
207+
boolean isPointerEvent = event.isFromSource(InputDevice.SOURCE_CLASS_POINTER);
210208
boolean isMovementEvent =
211209
(event.getActionMasked() == MotionEvent.ACTION_HOVER_MOVE
212210
|| event.getActionMasked() == MotionEvent.ACTION_SCROLL);

shell/platform/android/io/flutter/embedding/android/FlutterActivity.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import io.flutter.embedding.engine.plugins.activity.ActivityControlSurface;
5050
import io.flutter.embedding.engine.plugins.util.GeneratedPluginRegister;
5151
import io.flutter.plugin.platform.PlatformPlugin;
52-
import io.flutter.util.ViewUtils;
5352
import java.util.ArrayList;
5453
import java.util.List;
5554

@@ -216,7 +215,7 @@ public class FlutterActivity extends Activity
216215
* <p>This ID can be used to lookup {@code FlutterView} in the Android view hierarchy. For more,
217216
* see {@link android.view.View#findViewById}.
218217
*/
219-
public static final int FLUTTER_VIEW_ID = ViewUtils.generateViewId(0xF1F2);
218+
public static final int FLUTTER_VIEW_ID = View.generateViewId();
220219

221220
/**
222221
* Creates an {@link Intent} that launches a {@code FlutterActivity}, which creates a {@link
@@ -773,12 +772,10 @@ private View createFlutterView() {
773772
}
774773

775774
private void configureStatusBarForFullscreenFlutterExperience() {
776-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
777-
Window window = getWindow();
778-
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
779-
window.setStatusBarColor(0x40000000);
780-
window.getDecorView().setSystemUiVisibility(PlatformPlugin.DEFAULT_SYSTEM_UI);
781-
}
775+
Window window = getWindow();
776+
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
777+
window.setStatusBarColor(0x40000000);
778+
window.getDecorView().setSystemUiVisibility(PlatformPlugin.DEFAULT_SYSTEM_UI);
782779
}
783780

784781
@Override

shell/platform/android/io/flutter/embedding/android/FlutterFragment.java

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import android.content.ComponentCallbacks2;
99
import android.content.Context;
1010
import android.content.Intent;
11-
import android.os.Build;
1211
import android.os.Bundle;
1312
import android.view.LayoutInflater;
1413
import android.view.View;
@@ -17,7 +16,6 @@
1716
import androidx.activity.OnBackPressedCallback;
1817
import androidx.annotation.NonNull;
1918
import androidx.annotation.Nullable;
20-
import androidx.annotation.RequiresApi;
2119
import androidx.annotation.VisibleForTesting;
2220
import androidx.fragment.app.Fragment;
2321
import androidx.fragment.app.FragmentActivity;
@@ -27,7 +25,6 @@
2725
import io.flutter.embedding.engine.FlutterShellArgs;
2826
import io.flutter.embedding.engine.renderer.FlutterUiDisplayListener;
2927
import io.flutter.plugin.platform.PlatformPlugin;
30-
import io.flutter.util.ViewUtils;
3128
import java.util.ArrayList;
3229
import java.util.List;
3330

@@ -107,7 +104,7 @@ public class FlutterFragment extends Fragment
107104
* <p>This ID can be used to lookup {@code FlutterView} in the Android view hierarchy. For more,
108105
* see {@link android.view.View#findViewById}.
109106
*/
110-
public static final int FLUTTER_VIEW_ID = ViewUtils.generateViewId(0xF1F2);
107+
public static final int FLUTTER_VIEW_ID = View.generateViewId();
111108

112109
private static final String TAG = "FlutterFragment";
113110

@@ -170,18 +167,15 @@ public class FlutterFragment extends Fragment
170167
protected static final String ARG_SHOULD_AUTOMATICALLY_HANDLE_ON_BACK_PRESSED =
171168
"should_automatically_handle_on_back_pressed";
172169

173-
@RequiresApi(18)
174170
private final OnWindowFocusChangeListener onWindowFocusChangeListener =
175-
Build.VERSION.SDK_INT >= 18
176-
? new OnWindowFocusChangeListener() {
177-
@Override
178-
public void onWindowFocusChanged(boolean hasFocus) {
179-
if (stillAttachedForEvent("onWindowFocusChanged")) {
180-
delegate.onWindowFocusChanged(hasFocus);
181-
}
182-
}
171+
new OnWindowFocusChangeListener() {
172+
@Override
173+
public void onWindowFocusChanged(boolean hasFocus) {
174+
if (stillAttachedForEvent("onWindowFocusChanged")) {
175+
delegate.onWindowFocusChanged(hasFocus);
183176
}
184-
: null;
177+
}
178+
};
185179

186180
/**
187181
* Creates a {@code FlutterFragment} with a default configuration.
@@ -1128,20 +1122,15 @@ public void onStop() {
11281122
@Override
11291123
public void onViewCreated(View view, Bundle savedInstanceState) {
11301124
super.onViewCreated(view, savedInstanceState);
1131-
if (Build.VERSION.SDK_INT >= 18) {
1132-
view.getViewTreeObserver().addOnWindowFocusChangeListener(onWindowFocusChangeListener);
1133-
}
1125+
view.getViewTreeObserver().addOnWindowFocusChangeListener(onWindowFocusChangeListener);
11341126
}
11351127

11361128
@Override
11371129
public void onDestroyView() {
11381130
super.onDestroyView();
1139-
if (Build.VERSION.SDK_INT >= 18) {
1140-
// onWindowFocusChangeListener is API 18+ only.
1141-
requireView()
1142-
.getViewTreeObserver()
1143-
.removeOnWindowFocusChangeListener(onWindowFocusChangeListener);
1144-
}
1131+
requireView()
1132+
.getViewTreeObserver()
1133+
.removeOnWindowFocusChangeListener(onWindowFocusChangeListener);
11451134
if (stillAttachedForEvent("onDestroyView")) {
11461135
delegate.onDestroyView();
11471136
}

shell/platform/android/io/flutter/embedding/android/FlutterFragmentActivity.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import android.content.pm.PackageManager;
2828
import android.graphics.Color;
2929
import android.graphics.drawable.ColorDrawable;
30-
import android.os.Build;
3130
import android.os.Bundle;
3231
import android.view.View;
3332
import android.view.ViewGroup;
@@ -45,7 +44,6 @@
4544
import io.flutter.embedding.engine.FlutterShellArgs;
4645
import io.flutter.embedding.engine.plugins.util.GeneratedPluginRegister;
4746
import io.flutter.plugin.platform.PlatformPlugin;
48-
import io.flutter.util.ViewUtils;
4947
import java.util.ArrayList;
5048
import java.util.List;
5149

@@ -67,8 +65,7 @@ public class FlutterFragmentActivity extends FragmentActivity
6765
// FlutterFragment management.
6866
private static final String TAG_FLUTTER_FRAGMENT = "flutter_fragment";
6967
// TODO(mattcarroll): replace ID with R.id when build system supports R.java
70-
public static final int FRAGMENT_CONTAINER_ID =
71-
ViewUtils.generateViewId(609893468); // random number
68+
public static final int FRAGMENT_CONTAINER_ID = View.generateViewId();
7269

7370
/**
7471
* Creates an {@link Intent} that launches a {@code FlutterFragmentActivity}, which executes a
@@ -600,12 +597,10 @@ protected FlutterFragment createFlutterFragment() {
600597
}
601598

602599
private void configureStatusBarForFullscreenFlutterExperience() {
603-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
604-
Window window = getWindow();
605-
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
606-
window.setStatusBarColor(0x40000000);
607-
window.getDecorView().setSystemUiVisibility(PlatformPlugin.DEFAULT_SYSTEM_UI);
608-
}
600+
Window window = getWindow();
601+
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
602+
window.setStatusBarColor(0x40000000);
603+
window.getDecorView().setSystemUiVisibility(PlatformPlugin.DEFAULT_SYSTEM_UI);
609604
}
610605

611606
@Override

shell/platform/android/io/flutter/embedding/android/FlutterImageView.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
* an {@link android.media.Image} and renders it to the {@link android.graphics.Canvas} in {@code
4040
* onDraw}.
4141
*/
42-
@TargetApi(19)
4342
public class FlutterImageView extends View implements RenderSurface {
4443
private static final String TAG = "FlutterImageView";
4544

@@ -99,7 +98,6 @@ private static void logW(String format, Object... args) {
9998
Log.w(TAG, String.format(Locale.US, format, args));
10099
}
101100

102-
@TargetApi(19)
103101
@SuppressLint("WrongConstant") // RGBA_8888 is a valid constant.
104102
@NonNull
105103
private static ImageReader createImageReader(int width, int height) {
@@ -187,7 +185,6 @@ public void resume() {
187185
* Acquires the next image to be drawn to the {@link android.graphics.Canvas}. Returns true if
188186
* there's an image available in the queue.
189187
*/
190-
@TargetApi(19)
191188
public boolean acquireLatestImage() {
192189
if (!isAttachedToFlutterRenderer) {
193190
return false;

shell/platform/android/io/flutter/embedding/android/FlutterView.java

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ public FlutterView(@NonNull Context context, @NonNull FlutterTextureView flutter
290290
* <p>{@code FlutterView} requires an {@code Activity} instead of a generic {@code Context} to be
291291
* compatible with {@link PlatformViewsController}.
292292
*/
293-
@TargetApi(19)
294293
public FlutterView(@NonNull Context context, @NonNull FlutterImageView flutterImageView) {
295294
this(context, null, flutterImageView);
296295
}
@@ -357,7 +356,6 @@ private FlutterView(
357356
init();
358357
}
359358

360-
@TargetApi(19)
361359
private FlutterView(
362360
@NonNull Context context,
363361
@Nullable AttributeSet attrs,
@@ -643,8 +641,7 @@ else if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) {
643641
//
644642
// This method is replaced by Android API 30 (R/11) getInsets() method which can take the
645643
// android.view.WindowInsets.Type.ime() flag to find the keyboard inset.
646-
@TargetApi(20)
647-
@RequiresApi(20)
644+
648645
private int guessBottomKeyboardInset(WindowInsets insets) {
649646
int screenHeight = getRootView().getHeight();
650647
// Magic number due to this being a heuristic. This should be replaced, but we have not
@@ -670,8 +667,7 @@ private int guessBottomKeyboardInset(WindowInsets insets) {
670667
* wider than expected padding when the status and navigation bars are hidden.
671668
*/
672669
@Override
673-
@TargetApi(20)
674-
@RequiresApi(20)
670+
675671
// The annotations to suppress "InlinedApi" and "NewApi" lints prevent lint warnings
676672
// caused by usage of Android Q APIs. These calls are safe because they are
677673
// guarded.
@@ -802,53 +798,6 @@ navigationBarVisible && guessBottomKeyboardInset(insets) == 0
802798
sendViewportMetricsToFlutter();
803799
return newInsets;
804800
}
805-
806-
/**
807-
* Invoked when Android's desired window insets change, i.e., padding.
808-
*
809-
* <p>{@code fitSystemWindows} is an earlier version of {@link
810-
* #onApplyWindowInsets(WindowInsets)}. See that method for more details about how window insets
811-
* relate to Flutter.
812-
*/
813-
@Override
814-
@SuppressWarnings("deprecation")
815-
protected boolean fitSystemWindows(@NonNull Rect insets) {
816-
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
817-
// Status bar, left/right system insets partially obscure content (padding).
818-
viewportMetrics.viewPaddingTop = insets.top;
819-
viewportMetrics.viewPaddingRight = insets.right;
820-
viewportMetrics.viewPaddingBottom = 0;
821-
viewportMetrics.viewPaddingLeft = insets.left;
822-
823-
// Bottom system inset (keyboard) should adjust scrollable bottom edge (inset).
824-
viewportMetrics.viewInsetTop = 0;
825-
viewportMetrics.viewInsetRight = 0;
826-
viewportMetrics.viewInsetBottom = insets.bottom;
827-
viewportMetrics.viewInsetLeft = 0;
828-
829-
Log.v(
830-
TAG,
831-
"Updating window insets (fitSystemWindows()):\n"
832-
+ "Status bar insets: Top: "
833-
+ viewportMetrics.viewPaddingTop
834-
+ ", Left: "
835-
+ viewportMetrics.viewPaddingLeft
836-
+ ", Right: "
837-
+ viewportMetrics.viewPaddingRight
838-
+ "\n"
839-
+ "Keyboard insets: Bottom: "
840-
+ viewportMetrics.viewInsetBottom
841-
+ ", Left: "
842-
+ viewportMetrics.viewInsetLeft
843-
+ ", Right: "
844-
+ viewportMetrics.viewInsetRight);
845-
846-
sendViewportMetricsToFlutter();
847-
return true;
848-
} else {
849-
return super.fitSystemWindows(insets);
850-
}
851-
}
852801
// ------- End: Process View configuration that Flutter cares about. --------
853802

854803
// -------- Start: Process UI I/O that Flutter cares about. -------
@@ -930,14 +879,7 @@ public boolean onTouchEvent(@NonNull MotionEvent event) {
930879
return super.onTouchEvent(event);
931880
}
932881

933-
// TODO(abarth): This version check might not be effective in some
934-
// versions of Android that statically compile code and will be upset
935-
// at the lack of |requestUnbufferedDispatch|. Instead, we should factor
936-
// version-dependent code into separate classes for each supported
937-
// version and dispatch dynamically.
938-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
939-
requestUnbufferedDispatch(event);
940-
}
882+
requestUnbufferedDispatch(event);
941883

942884
return androidTouchProcessor.onTouchEvent(event);
943885
}

shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,22 +1297,17 @@ public String[] computePlatformResolvedLocale(@NonNull String[] strings) {
12971297
String countryCode = strings[i + 1];
12981298
String scriptCode = strings[i + 2];
12991299
// Convert to Locales via LocaleBuilder if available (API 21+) to include scriptCode.
1300-
if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
1301-
Locale.Builder localeBuilder = new Locale.Builder();
1302-
if (!languageCode.isEmpty()) {
1303-
localeBuilder.setLanguage(languageCode);
1304-
}
1305-
if (!countryCode.isEmpty()) {
1306-
localeBuilder.setRegion(countryCode);
1307-
}
1308-
if (!scriptCode.isEmpty()) {
1309-
localeBuilder.setScript(scriptCode);
1310-
}
1311-
supportedLocales.add(localeBuilder.build());
1312-
} else {
1313-
// Pre-API 21, we fall back on scriptCode-less locales.
1314-
supportedLocales.add(new Locale(languageCode, countryCode));
1300+
Locale.Builder localeBuilder = new Locale.Builder();
1301+
if (!languageCode.isEmpty()) {
1302+
localeBuilder.setLanguage(languageCode);
1303+
}
1304+
if (!countryCode.isEmpty()) {
1305+
localeBuilder.setRegion(countryCode);
1306+
}
1307+
if (!scriptCode.isEmpty()) {
1308+
localeBuilder.setScript(scriptCode);
13151309
}
1310+
supportedLocales.add(localeBuilder.build());
13161311
}
13171312

13181313
Locale result = localizationPlugin.resolveNativeLocale(supportedLocales);
@@ -1323,11 +1318,7 @@ public String[] computePlatformResolvedLocale(@NonNull String[] strings) {
13231318
String[] output = new String[localeDataLength];
13241319
output[0] = result.getLanguage();
13251320
output[1] = result.getCountry();
1326-
if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
1327-
output[2] = result.getScript();
1328-
} else {
1329-
output[2] = "";
1330-
}
1321+
output[2] = result.getScript();
13311322
return output;
13321323
}
13331324

0 commit comments

Comments
 (0)