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

Commit 529f030

Browse files
XilaiZhangCasey Hillers
andauthored
Revert "Support basic back navigation in Android 13/API 33" (#36001) (#36063)
Co-authored-by: Casey Hillers <[email protected]>
1 parent 5e0f577 commit 529f030

File tree

3 files changed

+4
-90
lines changed

3 files changed

+4
-90
lines changed

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

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
import android.view.View;
3636
import android.view.Window;
3737
import android.view.WindowManager;
38-
import android.window.OnBackInvokedCallback;
39-
import android.window.OnBackInvokedDispatcher;
4038
import androidx.annotation.NonNull;
4139
import androidx.annotation.Nullable;
4240
import androidx.annotation.VisibleForTesting;
@@ -497,57 +495,13 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
497495

498496
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
499497

500-
registerOnBackInvokedCallback();
501-
502498
configureWindowForTransparency();
503499

504500
setContentView(createFlutterView());
505501

506502
configureStatusBarForFullscreenFlutterExperience();
507503
}
508504

509-
/**
510-
* Registers the callback with OnBackInvokedDispatcher to capture back navigation gestures and
511-
* pass them to the framework.
512-
*
513-
* <p>This replaces the deprecated onBackPressed method override in order to support API 33's
514-
* predictive back navigation feature.
515-
*
516-
* <p>The callback must be unregistered in order to prevent unpredictable behavior once outside
517-
* the Flutter app.
518-
*/
519-
@VisibleForTesting
520-
public void registerOnBackInvokedCallback() {
521-
if (Build.VERSION.SDK_INT >= 33) {
522-
getOnBackInvokedDispatcher()
523-
.registerOnBackInvokedCallback(
524-
OnBackInvokedDispatcher.PRIORITY_DEFAULT, onBackInvokedCallback);
525-
}
526-
}
527-
528-
/**
529-
* Unregisters the callback from OnBackInvokedDispatcher.
530-
*
531-
* <p>This should be called when the activity is no longer in use to prevent unpredictable
532-
* behavior such as being stuck and unable to press back.
533-
*/
534-
@VisibleForTesting
535-
public void unregisterOnBackInvokedCallback() {
536-
if (Build.VERSION.SDK_INT >= 33) {
537-
getOnBackInvokedDispatcher().unregisterOnBackInvokedCallback(onBackInvokedCallback);
538-
}
539-
}
540-
541-
private final OnBackInvokedCallback onBackInvokedCallback =
542-
Build.VERSION.SDK_INT >= 33
543-
? new OnBackInvokedCallback() {
544-
@Override
545-
public void onBackInvoked() {
546-
onBackPressed();
547-
}
548-
}
549-
: null;
550-
551505
/**
552506
* Switches themes for this {@code Activity} from the theme used to launch this {@code Activity}
553507
* to a "normal theme" that is intended for regular {@code Activity} operation.
@@ -726,9 +680,7 @@ protected void onSaveInstanceState(Bundle outState) {
726680
*
727681
* <p>After calling, this activity should be disposed immediately and not be re-used.
728682
*/
729-
@VisibleForTesting
730-
public void release() {
731-
unregisterOnBackInvokedCallback();
683+
private void release() {
732684
if (delegate != null) {
733685
delegate.release();
734686
delegate = null;

shell/platform/android/test/io/flutter/embedding/android/FlutterActivityTest.java

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -88,36 +88,6 @@ public void flutterViewHasId() {
8888
assertTrue(activity.findViewById(FlutterActivity.FLUTTER_VIEW_ID) instanceof FlutterView);
8989
}
9090

91-
// TODO(garyq): Robolectric does not yet support android api 33 yet. Switch to a robolectric
92-
// test that directly exercises the OnBackInvoked APIs when API 33 is supported.
93-
@Test
94-
@TargetApi(33)
95-
public void itRegistersOnBackInvokedCallbackOnCreate() {
96-
Intent intent = FlutterActivityWithReportFullyDrawn.createDefaultIntent(ctx);
97-
ActivityController<FlutterActivityWithReportFullyDrawn> activityController =
98-
Robolectric.buildActivity(FlutterActivityWithReportFullyDrawn.class, intent);
99-
FlutterActivityWithReportFullyDrawn activity = spy(activityController.get());
100-
101-
activity.onCreate(null);
102-
103-
verify(activity, times(1)).registerOnBackInvokedCallback();
104-
}
105-
106-
// TODO(garyq): Robolectric does not yet support android api 33 yet. Switch to a robolectric
107-
// test that directly exercises the OnBackInvoked APIs when API 33 is supported.
108-
@Test
109-
@TargetApi(33)
110-
public void itUnregistersOnBackInvokedCallbackOnRelease() {
111-
Intent intent = FlutterActivityWithReportFullyDrawn.createDefaultIntent(ctx);
112-
ActivityController<FlutterActivityWithReportFullyDrawn> activityController =
113-
Robolectric.buildActivity(FlutterActivityWithReportFullyDrawn.class, intent);
114-
FlutterActivityWithReportFullyDrawn activity = spy(activityController.get());
115-
116-
activity.release();
117-
118-
verify(activity, times(1)).unregisterOnBackInvokedCallback();
119-
}
120-
12191
@Test
12292
public void itCreatesDefaultIntentWithExpectedDefaults() {
12393
Intent intent = FlutterActivity.createDefaultIntent(ctx);
@@ -626,14 +596,6 @@ public void resetFullyDrawn() {
626596
}
627597
}
628598

629-
private class FlutterActivityWithMockBackInvokedHandling extends FlutterActivity {
630-
@Override
631-
public void registerOnBackInvokedCallback() {}
632-
633-
@Override
634-
public void unregisterOnBackInvokedCallback() {}
635-
}
636-
637599
private static final class FakeFlutterPlugin
638600
implements FlutterPlugin,
639601
ActivityAware,

shell/platform/android/test_runner/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ android {
7171
testImplementation "com.google.android.play:core:1.8.0"
7272
testImplementation "com.ibm.icu:icu4j:69.1"
7373
testImplementation "org.robolectric:robolectric:4.7.3"
74-
testImplementation "junit:junit:4.13.2"
75-
testImplementation "androidx.test.ext:junit:1.1.4-alpha07"
74+
testImplementation "junit:junit:4.13"
75+
testImplementation "androidx.test.ext:junit:1.1.3"
7676

77-
def mockitoVersion = "4.7.0"
77+
def mockitoVersion = "4.1.0"
7878
testImplementation "org.mockito:mockito-core:$mockitoVersion"
7979
testImplementation "org.mockito:mockito-inline:$mockitoVersion"
8080
testImplementation "org.mockito:mockito-android:$mockitoVersion"

0 commit comments

Comments
 (0)