Skip to content

Upgrade macrobenchmark sample to UiAutomator 2.4-alpha05 #327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions MacrobenchmarkSample/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ plugins {
}

android {
compileSdk = 35
compileSdk = 36
namespace = "com.example.macrobenchmark.target"

defaultConfig {
applicationId = "com.example.macrobenchmark.target"
versionCode = 1
versionName = "1.0"
minSdk = 24
targetSdk = 35
targetSdk = 36
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down
2 changes: 1 addition & 1 deletion MacrobenchmarkSample/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
android:theme="@style/Theme.Macrobenchmarktarget">
<profileable
android:shell="true"
tools:targetApi="29,q" />
tools:targetApi="29" />
<!-- [END macrobenchmark_setup_profileable] -->
<!--
Activities need to be exported so the Macrobenchmarks can discover them
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.ReportDrawnWhen
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.Text
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -37,20 +40,25 @@ class FullyDrawnStartupActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
var isLoaded by remember { mutableStateOf(false) }
ReportDrawnWhen { isLoaded }
MaterialTheme {
Box {
var isLoaded by remember { mutableStateOf(false) }
ReportDrawnWhen { isLoaded }

LaunchedEffect(Unit) {
isLoaded = sampleViewModel.data.isReady()
}
LaunchedEffect(Unit) {
isLoaded = sampleViewModel.data.isReady()
}

Column {
Text("Compose Macrobenchmark Target")
if (!isLoaded) {
CircularProgressIndicator()
} else {
Text("Fully Drawn")
Column {
Text("Compose Macrobenchmark Target")
if (!isLoaded) {
CircularProgressIndicator()
} else {
Text("Fully Drawn")
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.material.TextButton
import androidx.compose.material.TopAppBar
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.semantics
Expand All @@ -57,7 +57,7 @@ private const val TAG = "MainActivity"

class MainActivity : ComponentActivity() {

@OptIn(ExperimentalComposeUiApi::class)
@OptIn(ExperimentalMaterial3Api::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Expand Down Expand Up @@ -132,7 +132,7 @@ class MainActivity : ComponentActivity() {
.padding(8.dp)
.testTag(testTag),
onClick = onClick,
border = BorderStroke(1.dp, MaterialTheme.colors.primary)
border = BorderStroke(1.dp, MaterialTheme.colorScheme.primary)
) {
Text(name)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.appcompat.app.AlertDialog
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
Expand All @@ -30,11 +29,13 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.Card
import androidx.compose.material.Checkbox
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.material.TextField
import androidx.compose.material3.Card
import androidx.compose.material3.Checkbox
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -43,16 +44,12 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.tracing.trace
import com.example.macrobenchmark.target.recyclerview.Entry
import com.example.macrobenchmark.target.util.ClickTrace

@OptIn(ExperimentalComposeUiApi::class)
class ComposeActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -68,49 +65,35 @@ class ComposeActivity : ComponentActivity() {
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun BenchmarkComposeList(data: List<Entry>) {
MaterialTheme {
Box(
modifier = Modifier.semantics {
// Allows to use testTag() for UiAutomator's resource-id.
// It can be enabled high in the compose hierarchy,
// so that it's enabled for the whole subtree
testTagsAsResourceId = true
}
) {
// Thanks to [SemanticsPropertyReceiver.testTagsAsResourceId],
// [Modifier.testTag]s will be propagated to resource-id
// and can be accessed from benchmarks.
var value by remember { mutableStateOf("Enter text here") }
Column(modifier = Modifier.fillMaxWidth()) {
TextField(
modifier = Modifier
.fillMaxWidth()
.testTag("input"),
value = value,
onValueChange = { value = it },
placeholder = { Text("Enter text here") }
)
var value by remember { mutableStateOf("Enter text here") }
Column(modifier = Modifier.fillMaxWidth()) {
TopAppBar(title = { Text("Compose Sample") })
TextField(
modifier = Modifier
.fillMaxWidth(),
value = value,
onValueChange = { value = it },
placeholder = { Text("Enter text here") }
)

LazyColumn(
modifier = Modifier
.testTag("myLazyColumn")
) {
items(data, key = { it.contents }) { item ->
EntryRow(
entry = item,
modifier = Modifier
.padding(8.dp)
.clickable {
ClickTrace.onClickPerformed()
AlertDialog
.Builder(this@ComposeActivity)
.setMessage("Item clicked")
.show()
}
)
}
LazyColumn {
items(data, key = { it.contents }) { item ->
EntryRow(
entry = item,
modifier = Modifier
.padding(8.dp)
.clickable {
ClickTrace.onClickPerformed()
AlertDialog
.Builder(this@ComposeActivity)
.setMessage("Item clicked")
.show()
}
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import android.widget.BaseAdapter
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updatePadding
import com.example.macrobenchmark.target.databinding.ActivityListViewBinding
import com.example.macrobenchmark.target.recyclerview.Entry
import com.example.macrobenchmark.target.util.ClickTrace
Expand Down Expand Up @@ -73,5 +76,19 @@ class ListViewActivity : AppCompatActivity() {
.show()
}

ViewCompat.setOnApplyWindowInsetsListener(binding.listview) { v, insets ->
val bars = insets.getInsets(
WindowInsetsCompat.Type.systemBars()
or WindowInsetsCompat.Type.displayCutout()
)
v.updatePadding(
left = bars.left,
top = bars.top,
right = bars.right,
bottom = bars.bottom,
)
WindowInsetsCompat.CONSUMED
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ package com.example.macrobenchmark.target.activity.clicklatency
import android.os.Bundle
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updatePadding
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
Expand Down Expand Up @@ -55,6 +58,20 @@ class NestedRecyclerActivity : AppCompatActivity() {
}
}
}

ViewCompat.setOnApplyWindowInsetsListener(binding.recycler) { v, insets ->
val bars = insets.getInsets(
WindowInsetsCompat.Type.systemBars()
or WindowInsetsCompat.Type.displayCutout()
)
v.updatePadding(
left = bars.left,
top = bars.top,
right = bars.right,
bottom = bars.bottom,
)
WindowInsetsCompat.CONSUMED
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ package com.example.macrobenchmark.target.activity.clicklatency

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updatePadding
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.macrobenchmark.target.databinding.ActivityRecyclerViewBinding
import com.example.macrobenchmark.target.recyclerview.Entry
Expand All @@ -30,6 +33,20 @@ open class RecyclerViewActivity : AppCompatActivity() {
val binding = ActivityRecyclerViewBinding.inflate(layoutInflater)
setContentView(binding.root)

ViewCompat.setOnApplyWindowInsetsListener(binding.recycler) { v, insets ->
val bars = insets.getInsets(
WindowInsetsCompat.Type.systemBars()
or WindowInsetsCompat.Type.displayCutout()
)
v.updatePadding(
left = bars.left,
top = bars.top,
right = bars.right,
bottom = bars.bottom,
)
WindowInsetsCompat.CONSUMED
}

// This argument allows the Macrobenchmark tests control the content being tested.
// In your app, you could use this approach to navigate to a consistent UI.
// e.g. Here the UI is being populated with a well known number of list items.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import android.view.LayoutInflater
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updatePadding
import com.example.macrobenchmark.target.R
import com.example.macrobenchmark.target.databinding.ActivityScrollViewBinding
import com.example.macrobenchmark.target.recyclerview.Entry
Expand All @@ -36,6 +39,21 @@ class ScrollViewActivity : AppCompatActivity() {
title = "ScrollView Sample"
val binding = ActivityScrollViewBinding.inflate(layoutInflater)
setContentView(binding.root)

ViewCompat.setOnApplyWindowInsetsListener(binding.scrollcontent) { v, insets ->
val bars = insets.getInsets(
WindowInsetsCompat.Type.systemBars()
or WindowInsetsCompat.Type.displayCutout()
)
v.updatePadding(
left = bars.left,
top = bars.top,
right = bars.right,
bottom = bars.bottom,
)
WindowInsetsCompat.CONSUMED
}

val itemCount = intent.getIntExtra(RecyclerViewActivity.EXTRA_ITEM_COUNT, 1000)

val items = List(itemCount) {
Expand Down
Loading
Loading