Rename native_driver to android_{driver_extensions|engine_test} (#161263)

Towards https://github.com/flutter/flutter/issues/161261 (before I add
more tests).

This is a 1:1 move, with massaging of
`run_flutter_driver_android_tests.dart` to be more automated as tests
are added.

/cc @reidbaker
This commit is contained in:
Matan Lurey
2025-01-08 12:28:38 -08:00
committed by GitHub
parent 04a60d6b27
commit 132e298335
74 changed files with 62 additions and 1051 deletions

View File

@@ -0,0 +1,11 @@
<!-- Copyright 2014 The Flutter Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- The INTERNET permission is required for development. Specifically,
the Flutter tool needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>

View File

@@ -0,0 +1,49 @@
<!-- Copyright 2014 The Flutter Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:label="android_engine_test"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:taskAffinity=""
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
<!-- Required to query activities that can process text, see:
https://developer.android.com/training/package-visibility and
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.
In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
<queries>
<intent>
<action android:name="android.intent.action.PROCESS_TEXT"/>
<data android:mimeType="text/plain"/>
</intent>
</queries>
</manifest>

View File

@@ -0,0 +1,49 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@file:Suppress("PackageName")
package com.example.android_engine_test
import android.os.Bundle
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import com.example.android_engine_test.extensions.NativeDriverSupportPlugin
import com.example.android_engine_test.fixtures.BlueOrangeGradientPlatformViewFactory
import com.example.android_engine_test.fixtures.ChangingColorButtonPlatformViewFactory
import com.example.android_engine_test.fixtures.SmileyFaceTexturePlugin
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
class MainActivity : FlutterActivity() {
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
// Intentionally do not use GeneratedPluginRegistrant.
flutterEngine
.plugins
.apply {
add(SmileyFaceTexturePlugin())
add(NativeDriverSupportPlugin())
}
flutterEngine
.platformViewsController
.registry
.apply {
registerViewFactory("blue_orange_gradient_platform_view", BlueOrangeGradientPlatformViewFactory())
registerViewFactory("changing_color_button_platform_view", ChangingColorButtonPlatformViewFactory())
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// https://developer.android.com/training/system-ui
val windowInsetsController = WindowCompat.getInsetsController(window, window.decorView)
windowInsetsController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
actionBar?.hide()
}
}

View File

@@ -0,0 +1,109 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@file:Suppress("PackageName")
package com.example.android_engine_test.extensions
import android.app.Activity
import android.os.SystemClock
import android.view.MotionEvent
import io.flutter.Log
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.embedding.engine.plugins.activity.ActivityAware
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
class NativeDriverSupportPlugin :
ActivityAware,
FlutterPlugin,
MethodCallHandler {
private val tag = "NativeDriverSupportPlugin"
private lateinit var channel: MethodChannel
private var activity: Activity? = null
override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) {
channel = MethodChannel(binding.binaryMessenger, "native_driver")
channel.setMethodCallHandler(this)
}
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
channel.setMethodCallHandler(null)
}
override fun onMethodCall(
call: MethodCall,
result: MethodChannel.Result
) {
val activity = this.activity
if (activity == null) {
Log.w(tag, "Received method channel, but no current activity")
return
}
when (call.method) {
"ping" -> {
result.success(null)
}
"tap_view" -> {
// Decode the selector.
val kind = call.argument<String>("kind")
lateinit var selector: NativeSelector
when (kind) {
"byNativeAccessibilityLabel" -> {
selector = NativeSelector.ByContentDescription(call.argument("label")!!)
}
"byNativeIntegerId" -> {
selector = NativeSelector.ByViewId(call.argument("id")!!)
}
else -> {
result.error("INVALID_SELECTOR", "Not supported", kind)
return
}
}
// Fail if not found.
val found = selector.find(activity.window.decorView.rootView)
if (found == null) {
result.error("VIEW_NOT_FOUND", "No view was found", call.arguments())
return
}
// Send tap event.
val x = found.x + found.width / 2
val y = found.y + found.height / 2
val downTime = SystemClock.uptimeMillis()
val pressDown = MotionEvent.obtain(downTime, downTime, MotionEvent.ACTION_DOWN, x, y, 0)
found.dispatchTouchEvent(pressDown)
pressDown.recycle()
val pressUp = MotionEvent.obtain(downTime, downTime, MotionEvent.ACTION_UP, x, y, 0)
found.dispatchTouchEvent(pressUp)
pressUp.recycle()
result.success(null)
}
else -> {
result.notImplemented()
}
}
}
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
activity = binding.activity
}
override fun onDetachedFromActivityForConfigChanges() {
activity = null
}
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
activity = binding.activity
}
override fun onDetachedFromActivity() {
activity = null
}
}

View File

@@ -0,0 +1,57 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@file:Suppress("PackageName")
package com.example.android_engine_test.extensions
import android.view.View
import android.view.ViewGroup
import androidx.core.view.children
// / Finds a native view using serialized data provided by a driver script.
sealed class NativeSelector {
// / Finds a native view by a {@code contentDescription} attribute.
data class ByContentDescription(
val contentDescription: String
) : NativeSelector() {
override fun find(root: View): View? {
val found = ArrayList<View>()
findRecursive(root, found)
if (found.isEmpty()) {
return null
}
if (found.size > 1) {
throw IllegalStateException("Expected a single matching view, got ${found.size}")
}
return found[0]
}
private fun findRecursive(
parent: View,
found: ArrayList<View>
) {
if (contentDescription == parent.contentDescription) {
found.add(parent)
}
if (parent is ViewGroup) {
for (child in parent.children) {
findRecursive(child, found)
}
}
}
}
// / Finds a native view by a {@code id} attribute.
data class ByViewId(
val id: Int
) : NativeSelector() {
override fun find(root: View): View? = root.findViewById(id)
}
// / Given a root view, returns the only view that matches this selector.
// /
// / If no view is found, returns null.
abstract fun find(root: View): View?
}

View File

@@ -0,0 +1,72 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@file:Suppress("PackageName")
package com.example.android_engine_test.fixtures
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.LinearGradient
import android.graphics.Paint
import android.graphics.Shader
import android.view.View
import android.view.ViewGroup
import io.flutter.plugin.platform.PlatformView
import io.flutter.plugin.platform.PlatformViewFactory
class BlueOrangeGradientPlatformViewFactory : PlatformViewFactory(null) {
override fun create(
context: Context,
viewId: Int,
args: Any?
): PlatformView = GradientPlatformView(context)
}
private class GradientPlatformView(
context: Context
) : View(context),
PlatformView {
val paint = Paint()
init {
layoutParams =
ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
}
override fun getView(): View = this
override fun dispose() {}
override fun onDraw(canvas: Canvas) {
canvas.drawRect(0f, 0f, width.toFloat(), height.toFloat(), paint)
super.onDraw(canvas)
}
override fun onSizeChanged(
w: Int,
h: Int,
oldw: Int,
oldh: Int
) {
paint.shader =
LinearGradient(
0f,
0f,
w.toFloat(),
h.toFloat(),
intArrayOf(
Color.rgb(0x41, 0x69, 0xE1),
Color.rgb(0xFF, 0xA5, 0x00)
),
null,
Shader.TileMode.CLAMP
)
super.onSizeChanged(w, h, oldw, oldh)
}
}

View File

@@ -0,0 +1,68 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@file:Suppress("PackageName")
package com.example.android_engine_test.fixtures
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.view.View
import android.view.ViewGroup
import io.flutter.plugin.platform.PlatformView
import io.flutter.plugin.platform.PlatformViewFactory
class ChangingColorButtonPlatformViewFactory : PlatformViewFactory(null) {
override fun create(
context: Context,
viewId: Int,
args: Any?
): PlatformView = ChangingColorButtonPlatformView(context)
}
private class ChangingColorButtonPlatformView(
context: Context
) : View(context),
PlatformView {
private val paintRed =
Paint().apply {
color = Color.RED
style = Paint.Style.FILL
}
private val paintBlue =
Paint().apply {
color = Color.BLUE
style = Paint.Style.FILL
}
private var isBlue = false
init {
layoutParams =
ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
contentDescription = "Change color"
setOnClickListener {
run {
isBlue = !isBlue
invalidate() // Force a redraw
}
}
}
override fun getView(): View = this
override fun dispose() {}
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
canvas.drawRect(0f, 0f, width.toFloat(), height.toFloat(), if (isBlue) paintBlue else paintRed)
}
}

View File

@@ -0,0 +1,105 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@file:Suppress("PackageName")
package com.example.android_engine_test.fixtures
import android.graphics.Color
import android.graphics.Paint
import android.os.Build
import android.view.Surface
import io.flutter.Log
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.embedding.engine.plugins.FlutterPlugin.FlutterPluginBinding
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.view.TextureRegistry.SurfaceProducer
class SmileyFaceTexturePlugin :
FlutterPlugin,
MethodCallHandler,
SurfaceProducer.Callback {
private val tag = "SmileyFaceTexturePlugin"
private lateinit var channel: MethodChannel
private lateinit var binding: FlutterPluginBinding
private lateinit var producer: SurfaceProducer
private var surface: Surface? = null
override fun onAttachedToEngine(binding: FlutterPluginBinding) {
this.binding = binding
channel = MethodChannel(binding.binaryMessenger, "smiley_face_texture")
channel.setMethodCallHandler(this)
producer = binding.textureRegistry.createSurfaceProducer()
producer.setCallback(this)
}
override fun onDetachedFromEngine(binding: FlutterPluginBinding) {
channel.setMethodCallHandler(null)
producer.release()
}
override fun onMethodCall(
call: MethodCall,
result: MethodChannel.Result
) {
if (call.method == "initTexture") {
val height = call.argument<Int>("height") ?: 1
val width = call.argument<Int>("width") ?: 1
producer.setSize(width, height)
result.success(updateTexture())
} else {
result.notImplemented()
}
}
private fun updateTexture(): Long {
var surface = this.surface
if (surface == null) {
surface = producer.surface
this.surface = surface
}
drawOnSurface(producer.surface)
return producer.id()
}
private fun drawOnSurface(surface: Surface) {
val canvas =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
surface.lockHardwareCanvas()
} else {
surface.lockCanvas(null)
}
// Yellow background
canvas.drawRGB(255, 230, 15)
val paint = Paint()
paint.style = Paint.Style.FILL
// Black eyes
paint.color = Color.BLACK
canvas.drawRect(200f, 200f, 250f, 250f, paint) // Left eye
canvas.drawRect(400f, 200f, 450f, 250f, paint) // Right eye
// Black mouth
paint.color = Color.BLACK
canvas.drawRect(250f, 400f, 400f, 420f, paint) // Simple mouth
surface.unlockCanvasAndPost(canvas)
}
override fun onSurfaceCreated() {
Log.i(tag, "onSurfaceCreated()")
updateTexture()
}
override fun onSurfaceDestroyed() {
Log.i(tag, "onSurfaceDestroyed()")
surface?.release()
surface = null
}
}

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2014 The Flutter Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="?android:colorBackground" />
</layer-list>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2014 The Flutter Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/white" />
</layer-list>

Binary file not shown.

After

Width:  |  Height:  |  Size: 544 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 442 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 721 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2014 The Flutter Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
the Flutter engine draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2014 The Flutter Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
the Flutter engine draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>

View File

@@ -0,0 +1,11 @@
<!-- Copyright 2014 The Flutter Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- The INTERNET permission is required for development. Specifically,
the Flutter tool needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>