mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-11-21 20:00:49 +01:00
fix(android): avoid Sony snapshot crash when locking screen
This commit is contained in:
1 parent
d789c08630
commit
030d44bbd0
7 files changed
+184
-8
No files matched your search
@@ -58,7 +58,9 @@ internal fun hasKnownImpellerRasterCrash(sdk: Int, manufacturer: String, model:
|
||||
(sdk == 35 && manufacturer.equals("xiaomi", ignoreCase = true) &&
|
||||
model.equals("25053PC47I", ignoreCase = true)) ||
|
||||
(sdk == 36 && manufacturer.equals("samsung", ignoreCase = true) &&
|
||||
model.equals("SM-S711B", ignoreCase = true))
|
||||
model.equals("SM-S711B", ignoreCase = true)) ||
|
||||
(sdk == 33 && manufacturer.equals("sony", ignoreCase = true) &&
|
||||
model.equals("SOG04", ignoreCase = true))
|
||||
|
||||
internal fun flutterRendererShellArgs(): Array<String> =
|
||||
if (shouldDisableImpeller()) arrayOf("--enable-impeller=false") else emptyArray()
|
||||
@@ -70,7 +72,7 @@ internal fun shouldDisableImpeller(): Boolean {
|
||||
val device = Build.DEVICE.lowercase(Locale.ROOT)
|
||||
val manufacturer = Build.MANUFACTURER.lowercase(Locale.ROOT)
|
||||
|
||||
// Reported crashes in Impeller SaveLayer and Samsung's Vulkan QueueSubmit.
|
||||
// Reported Impeller crashes in SaveLayer, Vulkan submission and GLES snapshots.
|
||||
// Keep these workarounds scoped to the reported device and Android version.
|
||||
if (hasKnownImpellerRasterCrash(Build.VERSION.SDK_INT, manufacturer, model)) {
|
||||
android.util.Log.i("Mornye", "Using Skia for a known Impeller raster crash on $model")
|
||||
|
||||
@@ -17,6 +17,20 @@ class ImpellerCompatibilityTest {
|
||||
assertTrue(hasKnownImpellerRasterCrash(36, "SAMSUNG", "sm-s711b"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun sonySnapshotCrashUsesFallbackOnTheReportedDeviceAndAndroidVersion() {
|
||||
assertTrue(hasKnownImpellerRasterCrash(33, "Sony", "SOG04"))
|
||||
assertTrue(hasKnownImpellerRasterCrash(33, "SONY", "sog04"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun sonyFallbackDoesNotIncludeOtherDevicesOrAndroidVersions() {
|
||||
assertFalse(hasKnownImpellerRasterCrash(32, "Sony", "SOG04"))
|
||||
assertFalse(hasKnownImpellerRasterCrash(34, "Sony", "SOG04"))
|
||||
assertFalse(hasKnownImpellerRasterCrash(33, "Sony", "SOG05"))
|
||||
assertFalse(hasKnownImpellerRasterCrash(33, "Other", "SOG04"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun samsungFallbackDoesNotIncludeOtherDevicesOrAndroidVersions() {
|
||||
assertFalse(hasKnownImpellerRasterCrash(35, "samsung", "SM-S711B"))
|
||||
|
||||
@@ -79,7 +79,8 @@ class _BlurSnapshot extends SingleChildRenderObjectWidget {
|
||||
/// Paints its child blurred by [sigma], from a cached image once the child
|
||||
/// has not changed for a frame. With a zero [sigma] it is a plain repaint
|
||||
/// boundary.
|
||||
class RenderLyricBlurSnapshot extends RenderProxyBox {
|
||||
class RenderLyricBlurSnapshot extends RenderProxyBox
|
||||
with WidgetsBindingObserver {
|
||||
RenderLyricBlurSnapshot(this._sigma, this._devicePixelRatio, this._source);
|
||||
|
||||
double _sigma;
|
||||
@@ -114,6 +115,9 @@ class RenderLyricBlurSnapshot extends RenderProxyBox {
|
||||
@visibleForTesting
|
||||
ui.Image? get debugSnapshot => _snapshot;
|
||||
|
||||
bool get _canSnapshot =>
|
||||
WidgetsBinding.instance.lifecycleState == AppLifecycleState.resumed;
|
||||
|
||||
// Keeps the line on its own layer, like the boundary a live blur needs.
|
||||
@override
|
||||
bool get isRepaintBoundary => true;
|
||||
@@ -141,7 +145,7 @@ class RenderLyricBlurSnapshot extends RenderProxyBox {
|
||||
(_sigma * 3 * _devicePixelRatio).ceil() / _devicePixelRatio,
|
||||
);
|
||||
final live = _live.layer;
|
||||
if (_snapshot == null && _unchanged && live != null) {
|
||||
if (_canSnapshot && _snapshot == null && _unchanged && live != null) {
|
||||
// The previous frame's live layer still holds the same, unchanged line.
|
||||
_snapshot = live.toImageSync(bounds, pixelRatio: _devicePixelRatio);
|
||||
_live.layer = null;
|
||||
@@ -158,9 +162,12 @@ class RenderLyricBlurSnapshot extends RenderProxyBox {
|
||||
final layer = _live.layer ??= ImageFilterLayer();
|
||||
layer.imageFilter = ui.ImageFilter.blur(sigmaX: _sigma, sigmaY: _sigma);
|
||||
context.pushLayer(layer, super.paint, offset);
|
||||
if (!_canSnapshot) return;
|
||||
_unchanged = true;
|
||||
SchedulerBinding.instance.addPostFrameCallback((_) {
|
||||
if (!attached || !_unchanged || _snapshot != null) return;
|
||||
if (!attached || !_canSnapshot || !_unchanged || _snapshot != null) {
|
||||
return;
|
||||
}
|
||||
_repaintingForSnapshot = true;
|
||||
markNeedsPaint();
|
||||
_repaintingForSnapshot = false;
|
||||
@@ -172,8 +179,23 @@ class RenderLyricBlurSnapshot extends RenderProxyBox {
|
||||
_snapshot = null;
|
||||
}
|
||||
|
||||
@override
|
||||
void attach(PipelineOwner owner) {
|
||||
super.attach(owner);
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
markNeedsPaint();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
// A hidden surface may lose its GPU context. Rebuild its cache on resume.
|
||||
_live.layer = null;
|
||||
markNeedsPaint();
|
||||
}
|
||||
|
||||
@override
|
||||
void detach() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
_unchanged = false;
|
||||
_live.layer = null;
|
||||
_disposeSnapshot();
|
||||
|
||||
@@ -60,7 +60,7 @@ class SettledBlur extends SingleChildRenderObjectWidget {
|
||||
/// Paints its child blurred by [sigma]: live while the child changes, then
|
||||
/// from one image with [pixelRatio] image pixels per logical pixel. With a
|
||||
/// zero [sigma] it is a plain repaint boundary.
|
||||
class RenderSettledBlur extends RenderProxyBox {
|
||||
class RenderSettledBlur extends RenderProxyBox with WidgetsBindingObserver {
|
||||
RenderSettledBlur({
|
||||
required double sigma,
|
||||
required double pixelRatio,
|
||||
@@ -103,6 +103,9 @@ class RenderSettledBlur extends RenderProxyBox {
|
||||
@visibleForTesting
|
||||
ui.Image? get debugImage => _image;
|
||||
|
||||
bool get _canSnapshot =>
|
||||
WidgetsBinding.instance.lifecycleState == AppLifecycleState.resumed;
|
||||
|
||||
// Keeps the blur on its own layer, so moving it reuses that layer.
|
||||
@override
|
||||
bool get isRepaintBoundary => true;
|
||||
@@ -142,7 +145,7 @@ class RenderSettledBlur extends RenderProxyBox {
|
||||
}
|
||||
|
||||
void _scheduleCheck() {
|
||||
if (_checkScheduled) return;
|
||||
if (_checkScheduled || !_canSnapshot) return;
|
||||
_checkScheduled = true;
|
||||
SchedulerBinding.instance.addPostFrameCallback(_check);
|
||||
}
|
||||
@@ -153,7 +156,7 @@ class RenderSettledBlur extends RenderProxyBox {
|
||||
void _check(Duration _) {
|
||||
_checkScheduled = false;
|
||||
final live = _live.layer;
|
||||
if (!attached || live == null || _image != null) return;
|
||||
if (!attached || !_canSnapshot || live == null || _image != null) return;
|
||||
if (!live.attached) {
|
||||
// Off screen: it paints live again, and settles, once it is back.
|
||||
markNeedsPaint();
|
||||
@@ -202,12 +205,21 @@ class RenderSettledBlur extends RenderProxyBox {
|
||||
@override
|
||||
void attach(PipelineOwner owner) {
|
||||
super.attach(owner);
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
// Moved boxes repaint, as their old layer may hold an unchecked live blur.
|
||||
markNeedsPaint();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
// A hidden surface may lose its GPU context. Rebuild its cache on resume.
|
||||
_live.layer = null;
|
||||
markNeedsPaint();
|
||||
}
|
||||
|
||||
@override
|
||||
void detach() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
_live.layer = null;
|
||||
_disposeImage();
|
||||
super.detach();
|
||||
|
||||
@@ -137,6 +137,71 @@ Future<List<int>> _pixels(WidgetTester tester) async {
|
||||
}
|
||||
|
||||
void main() {
|
||||
final binding = TestWidgetsFlutterBinding.ensureInitialized();
|
||||
setUp(() {
|
||||
binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
|
||||
});
|
||||
|
||||
for (final state in AppLifecycleState.values) {
|
||||
if (state == AppLifecycleState.resumed) continue;
|
||||
testWidgets('releases the snapshot while $state and rebuilds on resume', (
|
||||
tester,
|
||||
) async {
|
||||
addTearDown(
|
||||
() => tester.binding.handleAppLifecycleStateChanged(
|
||||
AppLifecycleState.resumed,
|
||||
),
|
||||
);
|
||||
final before = await _settle(tester, const _Line().build());
|
||||
|
||||
tester.binding.handleAppLifecycleStateChanged(state);
|
||||
expect(before.debugDisposed, isTrue);
|
||||
for (var frame = 0; frame < 3; frame++) {
|
||||
tester.binding.scheduleForcedFrame();
|
||||
await tester.pump();
|
||||
expect(_snapshot(tester), isNull);
|
||||
}
|
||||
expect(tester.binding.hasScheduledFrame, isFalse);
|
||||
|
||||
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
|
||||
await tester.pump();
|
||||
expect(_snapshot(tester), isNull);
|
||||
expect(_hasLiveBlur(tester), isTrue);
|
||||
await tester.pump();
|
||||
final after = _snapshot(tester)!;
|
||||
expect(after, isNot(same(before)));
|
||||
expect(after.debugDisposed, isFalse);
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('a pending snapshot repaint stops when focus is lost mid-frame', (
|
||||
tester,
|
||||
) async {
|
||||
addTearDown(
|
||||
() => tester.binding.handleAppLifecycleStateChanged(
|
||||
AppLifecycleState.resumed,
|
||||
),
|
||||
);
|
||||
tester.binding.addPostFrameCallback((_) {
|
||||
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.inactive);
|
||||
});
|
||||
await tester.pumpWidget(const _Line().build());
|
||||
for (var frame = 0; frame < 3; frame++) {
|
||||
tester.binding.scheduleFrame();
|
||||
await tester.pump();
|
||||
expect(_snapshot(tester), isNull);
|
||||
}
|
||||
expect(tester.binding.hasScheduledFrame, isFalse);
|
||||
|
||||
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(_snapshot(tester), isNotNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.inactive);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('a line blurs live until its blur settles', (tester) async {
|
||||
await tester.pumpWidget(const _Line(sigma: 2, settled: false).build());
|
||||
await tester.pump();
|
||||
|
||||
@@ -2364,6 +2364,7 @@ void main() {
|
||||
testWidgets(
|
||||
'Mornye lyrics keep the active line sharp with bold leading-aligned text',
|
||||
(tester) async {
|
||||
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
|
||||
await pumpNowPlaying(
|
||||
tester,
|
||||
theme: MornyeTheme.build(Brightness.light),
|
||||
|
||||
@@ -225,6 +225,66 @@ double _meanDifference(Uint8List a, Uint8List b) {
|
||||
}
|
||||
|
||||
void main() {
|
||||
final binding = TestWidgetsFlutterBinding.ensureInitialized();
|
||||
setUp(() {
|
||||
binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
|
||||
});
|
||||
|
||||
for (final state in AppLifecycleState.values) {
|
||||
if (state == AppLifecycleState.resumed) continue;
|
||||
testWidgets('releases the snapshot while $state and rebuilds on resume', (
|
||||
tester,
|
||||
) async {
|
||||
addTearDown(
|
||||
() => tester.binding.handleAppLifecycleStateChanged(
|
||||
AppLifecycleState.resumed,
|
||||
),
|
||||
);
|
||||
final before = await _settle(tester, _scene(const _Pattern()));
|
||||
|
||||
tester.binding.handleAppLifecycleStateChanged(state);
|
||||
expect(before.debugDisposed, isTrue);
|
||||
for (var frame = 0; frame < 3; frame++) {
|
||||
tester.binding.scheduleForcedFrame();
|
||||
await tester.pump();
|
||||
expect(_image(tester), isNull);
|
||||
}
|
||||
expect(tester.binding.hasScheduledFrame, isFalse);
|
||||
|
||||
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
|
||||
await tester.pump();
|
||||
final after = await _settleFrames(tester);
|
||||
expect(after, isNot(same(before)));
|
||||
expect(after.debugDisposed, isFalse);
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('a pending snapshot check stops when focus is lost mid-frame', (
|
||||
tester,
|
||||
) async {
|
||||
addTearDown(
|
||||
() => tester.binding.handleAppLifecycleStateChanged(
|
||||
AppLifecycleState.resumed,
|
||||
),
|
||||
);
|
||||
tester.binding.addPostFrameCallback((_) {
|
||||
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.inactive);
|
||||
});
|
||||
await tester.pumpWidget(_scene(const _Pattern()));
|
||||
for (var frame = 0; frame < 3; frame++) {
|
||||
await _frame(tester);
|
||||
expect(_image(tester), isNull);
|
||||
}
|
||||
expect(tester.binding.hasScheduledFrame, isFalse);
|
||||
|
||||
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
|
||||
await tester.pump();
|
||||
await _settleFrames(tester);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.inactive);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('blurs live, then draws one image once a frame shows it '
|
||||
'unchanged', (tester) async {
|
||||
final image = await _settle(tester, _scene(const _Pattern()));
|
||||
|
||||
Reference in new issue
Block a user