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

Commit e79dace

Browse files
committed
add min sdk annotations
1 parent 50db548 commit e79dace

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.INITIAL_ROUTE_META_DATA_KEY;
2222
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.NORMAL_THEME_META_DATA_KEY;
2323

24+
import android.annotation.TargetApi;
2425
import android.app.Activity;
2526
import android.content.Context;
2627
import android.content.Intent;
@@ -40,6 +41,7 @@
4041
import android.window.OnBackInvokedDispatcher;
4142
import androidx.annotation.NonNull;
4243
import androidx.annotation.Nullable;
44+
import androidx.annotation.RequiresApi;
4345
import androidx.annotation.VisibleForTesting;
4446
import androidx.lifecycle.Lifecycle;
4547
import androidx.lifecycle.LifecycleOwner;
@@ -657,7 +659,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
657659
*/
658660
@VisibleForTesting
659661
public void registerOnBackInvokedCallback() {
660-
if (onBackInvokedCallback != null) {
662+
if (Build.VERSION.SDK_INT >= 33 && onBackInvokedCallback != null) {
661663
getOnBackInvokedDispatcher()
662664
.registerOnBackInvokedCallback(
663665
OnBackInvokedDispatcher.PRIORITY_DEFAULT, onBackInvokedCallback);
@@ -673,7 +675,7 @@ public void registerOnBackInvokedCallback() {
673675
*/
674676
@VisibleForTesting
675677
public void unregisterOnBackInvokedCallback() {
676-
if (onBackInvokedCallback != null) {
678+
if (Build.VERSION.SDK_INT >= 33 && onBackInvokedCallback != null) {
677679
getOnBackInvokedDispatcher().unregisterOnBackInvokedCallback(onBackInvokedCallback);
678680
hasRegisteredBackCallback = false;
679681
}
@@ -921,18 +923,24 @@ public void onBackPressed() {
921923
}
922924
}
923925

926+
@TargetApi(34)
927+
@RequiresApi(34)
924928
public void startBackGesture(@NonNull BackEvent backEvent) {
925929
if (stillAttachedForEvent("startBackGesture")) {
926930
delegate.startBackGesture(backEvent);
927931
}
928932
}
929933

934+
@TargetApi(34)
935+
@RequiresApi(34)
930936
public void updateBackGestureProgress(@NonNull BackEvent backEvent) {
931937
if (stillAttachedForEvent("updateBackGestureProgress")) {
932938
delegate.updateBackGestureProgress(backEvent);
933939
}
934940
}
935941

942+
@TargetApi(34)
943+
@RequiresApi(34)
936944
public void cancelBackGesture() {
937945
if (stillAttachedForEvent("cancelBackGesture")) {
938946
delegate.cancelBackGesture();

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import static android.content.ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW;
88
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.DEFAULT_INITIAL_ROUTE;
99

10+
import android.annotation.TargetApi;
1011
import android.app.Activity;
1112
import android.content.Context;
1213
import android.content.Intent;
@@ -20,6 +21,7 @@
2021
import android.window.OnBackAnimationCallback;
2122
import androidx.annotation.NonNull;
2223
import androidx.annotation.Nullable;
24+
import androidx.annotation.RequiresApi;
2325
import androidx.annotation.VisibleForTesting;
2426
import androidx.lifecycle.Lifecycle;
2527
import io.flutter.FlutterInjector;
@@ -792,6 +794,8 @@ void onBackPressed() {
792794
* @param backEvent The BackEvent object containing information about the touch or button press.
793795
* This value cannot be null.
794796
*/
797+
@TargetApi(34)
798+
@RequiresApi(34)
795799
void startBackGesture(@NonNull BackEvent backEvent) {
796800
ensureAlive();
797801
if (flutterEngine != null) {
@@ -812,6 +816,8 @@ void startBackGesture(@NonNull BackEvent backEvent) {
812816
*
813817
* @param backEvent An BackEvent object describing the progress event. This value cannot be null.
814818
*/
819+
@TargetApi(34)
820+
@RequiresApi(34)
815821
void updateBackGestureProgress(@NonNull BackEvent backEvent) {
816822
ensureAlive();
817823
if (flutterEngine != null) {
@@ -832,6 +838,8 @@ void updateBackGestureProgress(@NonNull BackEvent backEvent) {
832838
* rollback of any changes or animations that were initiated in response to the back gesture. This
833839
* includes resetting UI elements or state to their original form before the gesture started.
834840
*/
841+
@TargetApi(34)
842+
@RequiresApi(34)
835843
void cancelBackGesture() {
836844
ensureAlive();
837845
if (flutterEngine != null) {

shell/platform/android/io/flutter/embedding/engine/systemchannels/NavigationChannel.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55
package io.flutter.embedding.engine.systemchannels;
66

7+
import android.annotation.TargetApi;
78
import android.window.BackEvent;
89
import androidx.annotation.NonNull;
910
import androidx.annotation.Nullable;
11+
import androidx.annotation.RequiresApi;
1012
import io.flutter.Log;
1113
import io.flutter.embedding.engine.dart.DartExecutor;
1214
import io.flutter.plugin.common.JSONMethodCodec;
@@ -58,16 +60,22 @@ public void popRoute() {
5860
channel.invokeMethod("popRoute", null);
5961
}
6062

63+
@TargetApi(34)
64+
@RequiresApi(34)
6165
public void startBackGesture(@NonNull BackEvent backEvent) {
6266
Log.v(TAG, "Sending message to start back gesture");
6367
channel.invokeMethod("startBackGesture", backEventToJsonMap(backEvent));
6468
}
6569

70+
@TargetApi(34)
71+
@RequiresApi(34)
6672
public void updateBackGestureProgress(@NonNull BackEvent backEvent) {
6773
Log.v(TAG, "Sending message to update back gesture progress");
6874
channel.invokeMethod("updateBackGestureProgress", backEventToJsonMap(backEvent));
6975
}
7076

77+
@TargetApi(34)
78+
@RequiresApi(34)
7179
public void cancelBackGesture() {
7280
Log.v(TAG, "Sending message to cancel back gesture");
7381
channel.invokeMethod("cancelBackGesture", null);
@@ -77,6 +85,8 @@ public void setMethodCallHandler(@Nullable MethodChannel.MethodCallHandler handl
7785
channel.setMethodCallHandler(handler);
7886
}
7987

88+
@TargetApi(34)
89+
@RequiresApi(34)
8090
private Map<String, Object> backEventToJsonMap(@NonNull BackEvent backEvent) {
8191
Map<String, Object> message = new HashMap<>(4);
8292
message.put("touchX", backEvent.getTouchX());

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,14 +369,20 @@ public void popRoute() {
369369
navigationChannel.popRoute();
370370
}
371371

372+
@TargetApi(34)
373+
@RequiresApi(34)
372374
public void startBackGesture(@NonNull BackEvent backEvent) {
373375
navigationChannel.startBackGesture(backEvent);
374376
}
375377

378+
@TargetApi(34)
379+
@RequiresApi(34)
376380
public void updateBackGestureProgress(@NonNull BackEvent backEvent) {
377381
navigationChannel.updateBackGestureProgress(backEvent);
378382
}
379383

384+
@TargetApi(34)
385+
@RequiresApi(34)
380386
public void cancelBackGesture() {
381387
navigationChannel.cancelBackGesture();
382388
}

0 commit comments

Comments
 (0)