Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_34031325
engine
提交
7b9ac278
E
engine
项目概览
qq_34031325
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,发现更多精彩内容 >>
未验证
提交
7b9ac278
编写于
8月 17, 2020
作者:
G
gaaclarke
提交者:
GitHub
8月 17, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revert "Create PlatformView instance right after method channel call from Dart (#20500)" (#20564)
This reverts commit
9333b7c1
.
上级
41971f48
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
65 addition
and
100 deletion
+65
-100
shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java
...d/io/flutter/plugin/platform/PlatformViewsController.java
+48
-38
shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java
.../flutter/plugin/platform/PlatformViewsControllerTest.java
+17
-62
未找到文件。
shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java
浏览文件 @
7b9ac278
...
...
@@ -79,6 +79,7 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
// it is associated with(e.g if a platform view creates other views in the same virtual display.
private
final
HashMap
<
Context
,
View
>
contextToPlatformView
;
private
final
SparseArray
<
PlatformViewsChannel
.
PlatformViewCreationRequest
>
platformViewRequests
;
private
final
SparseArray
<
View
>
platformViews
;
private
final
SparseArray
<
FlutterMutatorView
>
mutatorViews
;
...
...
@@ -106,45 +107,18 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
@Override
public
void
createAndroidViewForPlatformView
(
@NonNull
PlatformViewsChannel
.
PlatformViewCreationRequest
request
)
{
// API level 19 is required for
`android.graphics.ImageReader`
.
// API level 19 is required for
android.graphics.ImageReader
.
ensureValidAndroidVersion
(
Build
.
VERSION_CODES
.
KITKAT
);
if
(!
validateDirection
(
request
.
direction
))
{
throw
new
IllegalStateException
(
"Trying to create a view with unknown direction value: "
+
request
.
direction
+
"(view id: "
+
request
.
viewId
+
")"
);
}
final
PlatformViewFactory
factory
=
registry
.
getFactory
(
request
.
viewType
);
if
(
factory
==
null
)
{
throw
new
IllegalStateException
(
"Trying to create a platform view of unregistered type: "
+
request
.
viewType
);
}
Object
createParams
=
null
;
if
(
request
.
params
!=
null
)
{
createParams
=
factory
.
getCreateArgsCodec
().
decodeMessage
(
request
.
params
);
}
final
PlatformView
platformView
=
factory
.
create
(
context
,
request
.
viewId
,
createParams
);
final
View
view
=
platformView
.
getView
();
if
(
view
==
null
)
{
throw
new
IllegalStateException
(
"PlatformView#getView() returned null, but an Android view reference was expected."
);
}
if
(
view
.
getParent
()
!=
null
)
{
throw
new
IllegalStateException
(
"The Android view returned from PlatformView#getView() was already added to a parent view."
);
}
platformViews
.
put
(
request
.
viewId
,
view
);
platformViewRequests
.
put
(
request
.
viewId
,
request
);
}
@Override
public
void
disposeAndroidViewForPlatformView
(
int
viewId
)
{
// Hybrid view.
if
(
platformViewRequests
.
get
(
viewId
)
!=
null
)
{
platformViewRequests
.
remove
(
viewId
);
}
final
View
platformView
=
platformViews
.
get
(
viewId
);
if
(
platformView
!=
null
)
{
final
FlutterMutatorView
mutatorView
=
mutatorViews
.
get
(
viewId
);
...
...
@@ -404,6 +378,7 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
currentFrameUsedOverlayLayerIds
=
new
HashSet
<>();
currentFrameUsedPlatformViewIds
=
new
HashSet
<>();
platformViewRequests
=
new
SparseArray
<>();
platformViews
=
new
SparseArray
<>();
mutatorViews
=
new
SparseArray
<>();
...
...
@@ -676,15 +651,50 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
@VisibleForTesting
void
initializePlatformViewIfNeeded
(
int
viewId
)
{
final
View
view
=
platformViews
.
get
(
viewId
);
if
(
view
==
null
)
{
if
(
platformViews
.
get
(
viewId
)
!=
null
)
{
return
;
}
PlatformViewsChannel
.
PlatformViewCreationRequest
request
=
platformViewRequests
.
get
(
viewId
);
if
(
request
==
null
)
{
throw
new
IllegalStateException
(
"Platform view hasn't been initialized from the platform view channel."
);
}
if
(
mutatorViews
.
get
(
viewId
)
!=
null
)
{
return
;
if
(!
validateDirection
(
request
.
direction
))
{
throw
new
IllegalStateException
(
"Trying to create a view with unknown direction value: "
+
request
.
direction
+
"(view id: "
+
viewId
+
")"
);
}
PlatformViewFactory
factory
=
registry
.
getFactory
(
request
.
viewType
);
if
(
factory
==
null
)
{
throw
new
IllegalStateException
(
"Trying to create a platform view of unregistered type: "
+
request
.
viewType
);
}
Object
createParams
=
null
;
if
(
request
.
params
!=
null
)
{
createParams
=
factory
.
getCreateArgsCodec
().
decodeMessage
(
request
.
params
);
}
final
FlutterMutatorView
mutatorView
=
PlatformView
platformView
=
factory
.
create
(
context
,
viewId
,
createParams
);
View
view
=
platformView
.
getView
();
if
(
view
==
null
)
{
throw
new
IllegalStateException
(
"PlatformView#getView() returned null, but an Android view reference was expected."
);
}
if
(
view
.
getParent
()
!=
null
)
{
throw
new
IllegalStateException
(
"The Android view returned from PlatformView#getView() was already added to a parent view."
);
}
platformViews
.
put
(
viewId
,
view
);
FlutterMutatorView
mutatorView
=
new
FlutterMutatorView
(
context
,
context
.
getResources
().
getDisplayMetrics
().
density
,
androidTouchProcessor
);
mutatorViews
.
put
(
viewId
,
mutatorView
);
...
...
shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java
浏览文件 @
7b9ac278
...
...
@@ -7,7 +7,6 @@ import static org.mockito.Mockito.*;
import
android.content.Context
;
import
android.content.res.AssetManager
;
import
android.util.SparseArray
;
import
android.view.MotionEvent
;
import
android.view.Surface
;
import
android.view.SurfaceHolder
;
...
...
@@ -29,9 +28,7 @@ import io.flutter.embedding.engine.systemchannels.KeyEventChannel;
import
io.flutter.embedding.engine.systemchannels.MouseCursorChannel
;
import
io.flutter.embedding.engine.systemchannels.SettingsChannel
;
import
io.flutter.embedding.engine.systemchannels.TextInputChannel
;
import
io.flutter.plugin.common.FlutterException
;
import
io.flutter.plugin.common.MethodCall
;
import
io.flutter.plugin.common.StandardMessageCodec
;
import
io.flutter.plugin.common.StandardMethodCodec
;
import
io.flutter.plugin.localization.LocalizationPlugin
;
import
java.nio.ByteBuffer
;
...
...
@@ -245,29 +242,7 @@ public class PlatformViewsControllerTest {
@Test
@Config
(
shadows
=
{
ShadowFlutterJNI
.
class
})
public
void
createPlatformViewMessage__initializesAndroidView
()
{
PlatformViewsController
platformViewsController
=
new
PlatformViewsController
();
int
platformViewId
=
0
;
assertNull
(
platformViewsController
.
getPlatformViewById
(
platformViewId
));
PlatformViewFactory
viewFactory
=
mock
(
PlatformViewFactory
.
class
);
PlatformView
platformView
=
mock
(
PlatformView
.
class
);
when
(
platformView
.
getView
()).
thenReturn
(
mock
(
View
.
class
));
when
(
viewFactory
.
create
(
any
(),
eq
(
platformViewId
),
any
())).
thenReturn
(
platformView
);
platformViewsController
.
getRegistry
().
registerViewFactory
(
"testType"
,
viewFactory
);
FlutterJNI
jni
=
new
FlutterJNI
();
attach
(
jni
,
platformViewsController
);
// Simulate create call from the framework.
createPlatformView
(
jni
,
platformViewsController
,
platformViewId
,
"testType"
);
verify
(
platformView
,
times
(
1
)).
getView
();
}
@Test
@Config
(
shadows
=
{
ShadowFlutterJNI
.
class
})
public
void
createPlatformViewMessage__throwsIfViewIsNull
()
{
public
void
initializePlatformViewIfNeeded__throwsIfViewIsNull
()
{
PlatformViewsController
platformViewsController
=
new
PlatformViewsController
();
int
platformViewId
=
0
;
...
...
@@ -284,28 +259,22 @@ public class PlatformViewsControllerTest {
// Simulate create call from the framework.
createPlatformView
(
jni
,
platformViewsController
,
platformViewId
,
"testType"
);
assertEquals
(
ShadowFlutterJNI
.
getResponses
().
size
(),
1
);
final
ByteBuffer
responseBuffer
=
ShadowFlutterJNI
.
getResponses
().
get
(
0
);
responseBuffer
.
rewind
();
StandardMethodCodec
methodCodec
=
new
StandardMethodCodec
(
new
StandardMessageCodec
());
try
{
methodCodec
.
decodeEnvelope
(
responseBuffer
);
}
catch
(
FlutterException
exception
)
{
assertTrue
(
exception
.
getMessage
()
.
contains
(
"PlatformView#getView() returned null, but an Android view reference was expected."
));
platformViewsController
.
initializePlatformViewIfNeeded
(
platformViewId
);
}
catch
(
Exception
exception
)
{
assertTrue
(
exception
instanceof
IllegalStateException
);
assertEquals
(
exception
.
getMessage
(),
"PlatformView#getView() returned null, but an Android view reference was expected."
);
return
;
}
assert
False
(
tru
e
);
assert
True
(
fals
e
);
}
@Test
@Config
(
shadows
=
{
ShadowFlutterJNI
.
class
})
public
void
createPlatformViewMessage
__throwsIfViewHasParent
()
{
public
void
initializePlatformViewIfNeeded
__throwsIfViewHasParent
()
{
PlatformViewsController
platformViewsController
=
new
PlatformViewsController
();
int
platformViewId
=
0
;
...
...
@@ -324,23 +293,16 @@ public class PlatformViewsControllerTest {
// Simulate create call from the framework.
createPlatformView
(
jni
,
platformViewsController
,
platformViewId
,
"testType"
);
assertEquals
(
ShadowFlutterJNI
.
getResponses
().
size
(),
1
);
final
ByteBuffer
responseBuffer
=
ShadowFlutterJNI
.
getResponses
().
get
(
0
);
responseBuffer
.
rewind
();
StandardMethodCodec
methodCodec
=
new
StandardMethodCodec
(
new
StandardMessageCodec
());
try
{
methodCodec
.
decodeEnvelope
(
responseBuffer
);
}
catch
(
FlutterException
exception
)
{
assertTrue
(
exception
.
getMessage
()
.
contains
(
"The Android view returned from PlatformView#getView() was already added to a parent view."
));
platformViewsController
.
initializePlatformViewIfNeeded
(
platformViewId
);
}
catch
(
Exception
exception
)
{
assertTrue
(
exception
instanceof
IllegalStateException
);
assertEquals
(
exception
.
getMessage
(),
"The Android view returned from PlatformView#getView() was already added to a parent view."
);
return
;
}
assert
False
(
tru
e
);
assert
True
(
fals
e
);
}
@Test
...
...
@@ -519,7 +481,6 @@ public class PlatformViewsControllerTest {
@Implements
(
FlutterJNI
.
class
)
public
static
class
ShadowFlutterJNI
{
private
static
SparseArray
<
ByteBuffer
>
replies
=
new
SparseArray
<>();
public
ShadowFlutterJNI
()
{}
...
...
@@ -566,13 +527,7 @@ public class PlatformViewsControllerTest {
@Implementation
public
void
invokePlatformMessageResponseCallback
(
int
responseId
,
ByteBuffer
message
,
int
position
)
{
replies
.
put
(
responseId
,
message
);
}
public
static
SparseArray
<
ByteBuffer
>
getResponses
()
{
return
replies
;
}
int
responseId
,
ByteBuffer
message
,
int
position
)
{}
}
@Implements
(
SurfaceView
.
class
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录