Skip to content

Commit 0dab6f5

Browse files
authored
Replace onSurfaceCreated with onSurfaceAvailable. (#8384)
Closes flutter/flutter#155131. This replaces overrides of `SurfaceProducer.onSurfaceCreated` with `SurfaceProducer.onSurfaceAvailable`. Both packages that use the API have their minimum SDKs bumped to use the API, and an automatic release pending.
1 parent 3fc6b7a commit 0dab6f5

File tree

8 files changed

+31
-42
lines changed

8 files changed

+31
-42
lines changed

packages/camera/camera_android_camerax/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.6.11
2+
3+
* Replaces deprecated Android embedder APIs (`onSurfaceCreated` -> `onSurfaceAvailable`).
4+
* Updates minimum supported SDK version to Flutter 3.22/Dart 3.4.
5+
16
## 0.6.10+3
27

38
* Bumps com.google.guava:guava from 33.3.1-android to 33.4.0-android.

packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/PreviewHostApiImpl.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,7 @@ public void onSurfaceRequested(@NonNull SurfaceRequest request) {
8383
surfaceProducer.setCallback(
8484
new TextureRegistry.SurfaceProducer.Callback() {
8585
@Override
86-
// TODO(matanlurey): Replace with onSurfaceAvailable once available on stable;
87-
// https://github.com/flutter/flutter/issues/155131.
88-
@SuppressWarnings({"deprecation", "removal"})
89-
public void onSurfaceCreated() {
86+
public void onSurfaceAvailable() {
9087
// Do nothing. The Preview.SurfaceProvider will handle this whenever a new
9188
// Surface is needed.
9289
}

packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/PreviewTest.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ public void createSurfaceProducer_setsExpectedSurfaceProducerCallback() {
133133

134134
reset(mockSurfaceRequest);
135135

136-
// Verify callback's onSurfaceCreated does not interact with the SurfaceRequest.
137-
simulateSurfaceCreation(callback);
136+
// Verify callback's onSurfaceAvailable does not interact with the SurfaceRequest.
137+
callback.onSurfaceAvailable();
138138
verifyNoMoreInteractions(mockSurfaceRequest);
139139
}
140140

@@ -262,12 +262,4 @@ public void setTargetRotation_makesCallToSetTargetRotation() {
262262

263263
verify(mockPreview).setTargetRotation(targetRotation);
264264
}
265-
266-
// TODO(matanlurey): Replace with inline calls to onSurfaceAvailable once
267-
// available on stable; see https://github.com/flutter/flutter/issues/155131.
268-
// This seperate method only exists to scope the suppression.
269-
@SuppressWarnings({"deprecation", "removal"})
270-
void simulateSurfaceCreation(TextureRegistry.SurfaceProducer.Callback producerLifecycle) {
271-
producerLifecycle.onSurfaceCreated();
272-
}
273265
}

packages/camera/camera_android_camerax/pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ name: camera_android_camerax
22
description: Android implementation of the camera plugin using the CameraX library.
33
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android_camerax
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
5-
version: 0.6.10+3
5+
version: 0.6.11
66

77
environment:
8-
sdk: ^3.5.0
9-
flutter: ">=3.24.0"
8+
sdk: ^3.6.0
9+
flutter: ">=3.27.0"
1010

1111
flutter:
1212
plugin:

packages/video_player/video_player_android/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.7.17
2+
3+
* Replaces deprecated Android embedder APIs (`onSurfaceCreated` -> `onSurfaceAvailable`).
4+
* Updates minimum supported SDK version to Flutter 3.22/Dart 3.4.
5+
16
## 2.7.16
27

38
* Updates internal Pigeon API to use newer features.

packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayer.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ interface ExoPlayerProvider {
8585
}
8686

8787
@RestrictTo(RestrictTo.Scope.LIBRARY)
88-
// TODO(matanlurey): https://github.com/flutter/flutter/issues/155131.
89-
@SuppressWarnings({"deprecation", "removal"})
90-
public void onSurfaceCreated() {
88+
public void onSurfaceAvailable() {
9189
if (savedStateDuring != null) {
9290
exoPlayer = createVideoPlayer();
9391
savedStateDuring.restore(exoPlayer);

packages/video_player/video_player_android/android/src/test/java/io/flutter/plugins/videoplayer/VideoPlayerTest.java

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public void seekAndGetPosition() {
172172
}
173173

174174
@Test
175-
public void onSurfaceProducerDestroyedAndRecreatedReleasesAndThenRecreatesAndResumesPlayer() {
175+
public void onSurfaceProducerDestroyedAndAvailableReleasesAndThenRecreatesAndResumesPlayer() {
176176
VideoPlayer videoPlayer = createVideoPlayer();
177177

178178
verify(mockProducer).setCallback(callbackCaptor.capture());
@@ -190,7 +190,7 @@ public void onSurfaceProducerDestroyedAndRecreatedReleasesAndThenRecreatesAndRes
190190

191191
// Create a new mock exo player so that we get a new instance.
192192
mockExoPlayer = mock(ExoPlayer.class);
193-
simulateSurfaceCreation(producerLifecycle);
193+
producerLifecycle.onSurfaceAvailable();
194194

195195
verify(mockExoPlayer).seekTo(10L);
196196
verify(mockExoPlayer).setRepeatMode(Player.REPEAT_MODE_ALL);
@@ -226,7 +226,7 @@ public void onDisposeSurfaceProducerCallbackIsDisconnected() {
226226
}
227227

228228
@Test
229-
public void onInitializedCalledWhenVideoPlayerInitiallyCreated() {
229+
public void onInitializedCalledWhenVideoPlayerInitiallyAvailable() {
230230
VideoPlayer videoPlayer = createVideoPlayer();
231231

232232
// Pretend we have a video, and capture the registered event listener.
@@ -242,7 +242,7 @@ public void onInitializedCalledWhenVideoPlayerInitiallyCreated() {
242242
}
243243

244244
@Test
245-
public void onSurfaceCreatedDoesNotSendInitializeEventAgain() {
245+
public void onSurfaceAvailableDoesNotSendInitializeEventAgain() {
246246
// The VideoPlayer contract assumes that the event "initialized" is sent exactly once
247247
// (duplicate events cause an error to be thrown at the shared Dart layer). This test verifies
248248
// that the onInitialized event is sent exactly once per player.
@@ -251,13 +251,13 @@ public void onSurfaceCreatedDoesNotSendInitializeEventAgain() {
251251
VideoPlayer videoPlayer = createVideoPlayer();
252252
when(mockExoPlayer.getVideoSize()).thenReturn(new VideoSize(300, 200));
253253

254-
// Capture the lifecycle events so we can simulate onSurfaceCreated/Destroyed.
254+
// Capture the lifecycle events so we can simulate onSurfaceAvailableDestroyed.
255255
verify(mockProducer).setCallback(callbackCaptor.capture());
256256
TextureRegistry.SurfaceProducer.Callback producerLifecycle = callbackCaptor.getValue();
257257

258-
// Trigger destroyed/created.
258+
// Trigger destroyed/available.
259259
producerLifecycle.onSurfaceDestroyed();
260-
simulateSurfaceCreation(producerLifecycle);
260+
producerLifecycle.onSurfaceAvailable();
261261

262262
// Initial listener, and the new one from the resume.
263263
verify(mockExoPlayer, times(2)).addListener(listenerCaptor.capture());
@@ -273,17 +273,17 @@ public void onSurfaceCreatedDoesNotSendInitializeEventAgain() {
273273
}
274274

275275
@Test
276-
public void onSurfaceCreatedWithoutDestroyDoesNotRecreate() {
276+
public void onSurfaceAvailableWithoutDestroyDoesNotRecreate() {
277277
// Initially create the video player, which creates the initial surface.
278278
VideoPlayer videoPlayer = createVideoPlayer();
279279
verify(mockProducer).getSurface();
280280

281-
// Capture the lifecycle events so we can simulate onSurfaceCreated/Destroyed.
281+
// Capture the lifecycle events so we can simulate onSurfaceAvailable/Destroyed.
282282
verify(mockProducer).setCallback(callbackCaptor.capture());
283283
TextureRegistry.SurfaceProducer.Callback producerLifecycle = callbackCaptor.getValue();
284284

285-
// Calling onSurfaceCreated does not do anything, since the surface was never destroyed.
286-
simulateSurfaceCreation(producerLifecycle);
285+
// Calling onSurfaceAvailable does not do anything, since the surface was never destroyed.
286+
producerLifecycle.onSurfaceAvailable();
287287
verifyNoMoreInteractions(mockProducer);
288288

289289
videoPlayer.dispose();
@@ -301,12 +301,4 @@ public void disposeReleasesExoPlayerBeforeTexture() {
301301
inOrder.verify(mockExoPlayer).release();
302302
inOrder.verify(mockProducer).release();
303303
}
304-
305-
// TODO(matanlurey): Replace with inline calls to onSurfaceAvailable once
306-
// available on stable; see https://github.com/flutter/flutter/issues/155131.
307-
// This separate method only exists to scope the suppression.
308-
@SuppressWarnings({"deprecation", "removal"})
309-
void simulateSurfaceCreation(TextureRegistry.SurfaceProducer.Callback producerLifecycle) {
310-
producerLifecycle.onSurfaceCreated();
311-
}
312304
}

packages/video_player/video_player_android/pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ name: video_player_android
22
description: Android implementation of the video_player plugin.
33
repository: https://github.com/flutter/packages/tree/main/packages/video_player/video_player_android
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
5-
version: 2.7.16
5+
version: 2.7.17
66

77
environment:
8-
sdk: ^3.5.0
9-
flutter: ">=3.24.0"
8+
sdk: ^3.6.0
9+
flutter: ">=3.27.0"
1010

1111
flutter:
1212
plugin:

0 commit comments

Comments
 (0)