Unverified Commit 8f1a4305 authored by Gary Qian's avatar Gary Qian Committed by GitHub

Initialize the lifecycle state with initial state in window. Roll engine (19 commits) (#28688)

git log --oneline --no-merges f4951df193a7966f9ed4da43d555eee0913d84d1..a48cd16e077778a7aa5908e4faa4da07714260f2
a48cd16e0 Update a11y word forward/back enum names (https://github.com/flutter/engine/pull/8073)
b5f59ed89 Delay the vsync callback till the frame start time specified by embedder. (https://github.com/flutter/engine/pull/8072)
7426305f5 Mark const extern (https://github.com/flutter/engine/pull/8077)
d3f6d7a21 only partial rule revert (https://github.com/flutter/engine/pull/8078)
d71bfe58d Only build a full Dart SDK when building for the host system (https://github.com/flutter/engine/pull/8071)
de90dbff7 Refactor web configuration/ Add dartdevc (https://github.com/flutter/engine/pull/7978)
ff46dd38f Roll src/third_party/skia 4c1ea43a79b5..88b8d1124b72 (8 commits) (https://github.com/flutter/engine/pull/8070)
80c6dd286 Roll src/third_party/skia 692122e3ef23..4c1ea43a79b5 (3 commits) (https://github.com/flutter/engine/pull/8069)
68ed654ea Roll src/third_party/skia 3c957d575c58..692122e3ef23 (6 commits) (https://github.com/flutter/engine/pull/8067)
ca0bac4fb Revert "add signal to pointer kinds" (https://github.com/flutter/engine/pull/8066)
3fb627f2c add signal to pointer kinds (https://github.com/flutter/engine/pull/8065)
5a06afa2a Roll src/third_party/skia 801a9c16d81e..3c957d575c58 (19 commits) (https://github.com/flutter/engine/pull/8063)
a93d99db9 A11y callback (https://github.com/flutter/engine/pull/8005)
3661d5e43 Re-land "Buffer lifecycle in WindowData" (https://github.com/flutter/engine/pull/8032)
471a2c89a Send scroll events from the macOS shell (https://github.com/flutter/engine/pull/8056)
2fe9c9b5f Roll src/third_party/skia 72542816cadb..801a9c16d81e (46 commits) (https://github.com/flutter/engine/pull/8060)
3335764ae Skip skp files in license check (https://github.com/flutter/engine/pull/8050)
7f16789b2 Remove redundant thread checker in FML. (https://github.com/flutter/engine/pull/8053)
840c5233a Correct URL for Cirrus CI build status badge (https://github.com/flutter/engine/pull/8054)
57c120a29 remove extra source files (https://github.com/flutter/engine/pull/8052)
4773375c6 Used named conditionals for platform specific dependencies and suppress Android and Windows hooks on Mac. (https://github.com/flutter/engine/pull/8051)
70a18b515 Add clang static analysis support to gn wrapper (https://github.com/flutter/engine/pull/8047)
b30f9897b Improve elevation bounds for physical shape layers (https://github.com/flutter/engine/pull/8044)
e37bd27b4 Fix weak pointer use violations in shell and platform view. (https://github.com/flutter/engine/pull/8046)
dd80fc9ff Add engine support for scrollwheel events (https://github.com/flutter/engine/pull/7494)
parent a3b484d0
f4951df193a7966f9ed4da43d555eee0913d84d1 a48cd16e077778a7aa5908e4faa4da07714260f2
...@@ -193,6 +193,7 @@ mixin SchedulerBinding on BindingBase, ServicesBinding { ...@@ -193,6 +193,7 @@ mixin SchedulerBinding on BindingBase, ServicesBinding {
window.onBeginFrame = _handleBeginFrame; window.onBeginFrame = _handleBeginFrame;
window.onDrawFrame = _handleDrawFrame; window.onDrawFrame = _handleDrawFrame;
SystemChannels.lifecycle.setMessageHandler(_handleLifecycleMessage); SystemChannels.lifecycle.setMessageHandler(_handleLifecycleMessage);
readInitialLifecycleStateFromNativeWindow();
} }
/// The current [SchedulerBinding], if one has been created. /// The current [SchedulerBinding], if one has been created.
...@@ -225,6 +226,23 @@ mixin SchedulerBinding on BindingBase, ServicesBinding { ...@@ -225,6 +226,23 @@ mixin SchedulerBinding on BindingBase, ServicesBinding {
AppLifecycleState get lifecycleState => _lifecycleState; AppLifecycleState get lifecycleState => _lifecycleState;
AppLifecycleState _lifecycleState; AppLifecycleState _lifecycleState;
/// Initializes the [lifecycleState] with the [initialLifecycleState] from the
/// window.
///
/// Once the [lifecycleState] is populated through any means (including this
/// method), this method will do nothing. This is because the
/// [initialLifecycleState] may already be stale and it no longer makes sense
/// to use the initial state at dart vm startup as the current state anymore.
///
/// The latest state should be obtained by subscribing to
/// [WidgetsBindingObserver.didChangeAppLifecycleState].
@protected
void readInitialLifecycleStateFromNativeWindow() {
if (_lifecycleState == null && _parseAppLifecycleMessage(window.initialLifecycleState) != null) {
_handleLifecycleMessage(window.initialLifecycleState);
}
}
/// Called when the application lifecycle state changes. /// Called when the application lifecycle state changes.
/// ///
/// Notifies all the observers using /// Notifies all the observers using
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/scheduler.dart';
void main() {
testWidgets('initialLifecycleState is used to init state paused', (WidgetTester tester) async {
// The lifecycleState is null initially in tests as there is no
// initialLifecycleState.
expect(SchedulerBinding.instance.lifecycleState, equals(null));
// Mock the Window to provide paused as the AppLifecycleState
final TestWidgetsFlutterBinding binding = tester.binding;
// Use paused as the initial state.
binding.window.initialLifecycleStateTestValue = 'AppLifecycleState.paused';
binding.readTestInitialLifecycleStateFromNativeWindow(); // Re-attempt the initializaiton.
// The lifecycleState should now be the state we passed above,
// even though no lifecycle event was fired from the platform.
expect(SchedulerBinding.instance.lifecycleState.toString(), equals('AppLifecycleState.paused'));
});
}
...@@ -257,6 +257,12 @@ abstract class TestWidgetsFlutterBinding extends BindingBase ...@@ -257,6 +257,12 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
}); });
} }
/// Re-attempts the initialization of the lifecycle state after providing
/// test values in [TestWindow.initialLifecycleStateTestValue].
void readTestInitialLifecycleStateFromNativeWindow() {
readInitialLifecycleStateFromNativeWindow();
}
Size _surfaceSize; Size _surfaceSize;
/// Artificially changes the surface size to `size` on the Widget binding, /// Artificially changes the surface size to `size` on the Widget binding,
......
...@@ -151,6 +151,14 @@ class TestWindow implements Window { ...@@ -151,6 +151,14 @@ class TestWindow implements Window {
_window.onLocaleChanged = callback; _window.onLocaleChanged = callback;
} }
@override
String get initialLifecycleState => _initialLifecycleStateTestValue;
String _initialLifecycleStateTestValue;
/// Sets a faked initialLifecycleState for testing.
set initialLifecycleStateTestValue(String state) {
_initialLifecycleStateTestValue = state;
}
@override @override
double get textScaleFactor => _textScaleFactorTestValue ?? _window.textScaleFactor; double get textScaleFactor => _textScaleFactorTestValue ?? _window.textScaleFactor;
double _textScaleFactorTestValue; double _textScaleFactorTestValue;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment