Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
518fbd16
E
engine
项目概览
sxychenjing
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
518fbd16
编写于
7月 14, 2020
作者:
M
Michael Goderbauer
提交者:
GitHub
7月 14, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add flag to indicate whether the platform supports state restoration (#19717)
上级
72d0c364
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
27 addition
and
7 deletion
+27
-7
shell/platform/android/io/flutter/embedding/engine/systemchannels/RestorationChannel.java
...r/embedding/engine/systemchannels/RestorationChannel.java
+12
-3
shell/platform/android/test/io/flutter/embedding/engine/systemchannels/RestorationChannelTest.java
...bedding/engine/systemchannels/RestorationChannelTest.java
+15
-4
未找到文件。
shell/platform/android/io/flutter/embedding/engine/systemchannels/RestorationChannel.java
浏览文件 @
518fbd16
...
...
@@ -10,6 +10,8 @@ import io.flutter.embedding.engine.dart.DartExecutor;
import
io.flutter.plugin.common.MethodCall
;
import
io.flutter.plugin.common.MethodChannel
;
import
io.flutter.plugin.common.StandardMethodCodec
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* System channel to exchange restoration data between framework and engine.
...
...
@@ -79,7 +81,7 @@ public class RestorationChannel {
engineHasProvidedData
=
true
;
if
(
pendingFrameworkRestorationChannelRequest
!=
null
)
{
// If their is a pending request from the framework, answer it.
pendingFrameworkRestorationChannelRequest
.
success
(
data
);
pendingFrameworkRestorationChannelRequest
.
success
(
packageData
(
data
)
);
pendingFrameworkRestorationChannelRequest
=
null
;
restorationData
=
data
;
}
else
if
(
frameworkHasRequestedData
)
{
...
...
@@ -90,7 +92,7 @@ public class RestorationChannel {
// e.g. when the engine is attached to a new activity.
channel
.
invokeMethod
(
"push"
,
data
,
packageData
(
data
)
,
new
MethodChannel
.
Result
()
{
@Override
public
void
success
(
Object
result
)
{
...
...
@@ -142,7 +144,7 @@ public class RestorationChannel {
case
"get"
:
frameworkHasRequestedData
=
true
;
if
(
engineHasProvidedData
||
!
waitForRestorationData
)
{
result
.
success
(
restorationData
);
result
.
success
(
packageData
(
restorationData
)
);
// Do not delete the restoration data on the engine side after sending it to the
// framework. We may need to hand this data back to the operating system if the
// framework never modifies the data (and thus doesn't send us any
...
...
@@ -157,4 +159,11 @@ public class RestorationChannel {
}
}
};
private
Map
<
String
,
Object
>
packageData
(
byte
[]
data
)
{
final
Map
<
String
,
Object
>
packaged
=
new
HashMap
<
String
,
Object
>();
packaged
.
put
(
"enabled"
,
true
);
// Android supports state restoration.
packaged
.
put
(
"data"
,
data
);
return
packaged
;
}
}
shell/platform/android/test/io/flutter/embedding/engine/systemchannels/RestorationChannelTest.java
浏览文件 @
518fbd16
...
...
@@ -11,6 +11,8 @@ import static org.mockito.Mockito.verifyZeroInteractions;
import
android.annotation.TargetApi
;
import
io.flutter.plugin.common.MethodCall
;
import
io.flutter.plugin.common.MethodChannel
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.json.JSONException
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
...
...
@@ -51,12 +53,15 @@ public class RestorationChannelTest {
restorationChannel
.
setRestorationData
(
data
);
verify
(
rawChannel
,
times
(
0
)).
invokeMethod
(
any
(),
any
());
verify
(
result
).
success
(
data
);
Map
<
String
,
Object
>
expected
=
new
HashMap
<>();
expected
.
put
(
"enabled"
,
true
);
expected
.
put
(
"data"
,
data
);
verify
(
result
).
success
(
expected
);
// Next get request is answered right away.
MethodChannel
.
Result
result2
=
mock
(
MethodChannel
.
Result
.
class
);
argumentCaptor
.
getValue
().
onMethodCall
(
new
MethodCall
(
"get"
,
null
),
result2
);
verify
(
result2
).
success
(
data
);
verify
(
result2
).
success
(
expected
);
}
@Test
...
...
@@ -72,14 +77,20 @@ public class RestorationChannelTest {
MethodChannel
.
Result
result
=
mock
(
MethodChannel
.
Result
.
class
);
argumentCaptor
.
getValue
().
onMethodCall
(
new
MethodCall
(
"get"
,
null
),
result
);
verify
(
result
).
success
(
null
);
Map
<
String
,
Object
>
expected
=
new
HashMap
<>();
expected
.
put
(
"enabled"
,
true
);
expected
.
put
(
"data"
,
null
);
verify
(
result
).
success
(
expected
);
restorationChannel
.
setRestorationData
(
data
);
assertEquals
(
restorationChannel
.
getRestorationData
(),
null
);
ArgumentCaptor
<
MethodChannel
.
Result
>
resultCapture
=
ArgumentCaptor
.
forClass
(
MethodChannel
.
Result
.
class
);
verify
(
rawChannel
).
invokeMethod
(
eq
(
"push"
),
eq
(
data
),
resultCapture
.
capture
());
Map
<
String
,
Object
>
expected2
=
new
HashMap
<>();
expected2
.
put
(
"enabled"
,
true
);
expected2
.
put
(
"data"
,
data
);
verify
(
rawChannel
).
invokeMethod
(
eq
(
"push"
),
eq
(
expected2
),
resultCapture
.
capture
());
resultCapture
.
getValue
().
success
(
null
);
assertEquals
(
restorationChannel
.
getRestorationData
(),
data
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录