Skip to content
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

[Android] Add Android Matter Device App for automation testing #27799

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ceeba48
st-device-app: Add st-device-app for automation test with Android device
Jaehoon-You Jul 7, 2023
bf03bba
st-device-app: Add gradle-wrapper.jar file
Jaehoon-You Jul 7, 2023
e6bc84e
st-device-app: Remove brand icon after reviewing
Jaehoon-You Jul 10, 2023
bbb0777
Update examples/st-device-app/android/.gn
chulspro Jul 11, 2023
f35a75d
Update examples/st-device-app/android/java/src/com/samsung/matter/std…
chulspro Jul 11, 2023
cf9cca7
Update examples/st-device-app/android/java/src/com/samsung/matter/std…
chulspro Jul 11, 2023
3cbafd2
Update examples/st-device-app/st-device-common/include/CHIPProjectApp…
chulspro Jul 11, 2023
07aad11
Update examples/st-device-app/st-device-common/BUILD.gn
chulspro Jul 11, 2023
3714147
Update examples/st-device-app/android/java/src/com/samsung/matter/std…
chulspro Jul 11, 2023
fc5254b
Update examples/st-device-app/android/java/src/com/samsung/matter/std…
chulspro Jul 11, 2023
e79841e
Update examples/st-device-app/android/java/src/com/samsung/matter/std…
chulspro Jul 11, 2023
5b4999f
st-device-app: Change the hexadecimal format in string xml
Jaehoon-You Jul 13, 2023
a8aaced
st-device-app: Update .zap/.matter for supporting required attributes
Jaehoon-You Jul 13, 2023
8705f51
st-device-app: Resolve spelling check issue
Jaehoon-You Jul 13, 2023
95fb360
scripts: fix merge conflicts
chulspro Jul 19, 2023
adb6cd3
docs: add virtual-device-app and fix merge conflicts
chulspro Jul 19, 2023
041fd9b
Restyled by whitespace
restyled-commits Jul 14, 2023
e21944a
Restyled by google-java-format
restyled-commits Jul 14, 2023
1928edb
Restyled by clang-format
restyled-commits Jul 14, 2023
b847dc8
Restyled by gn
restyled-commits Jul 14, 2023
81a4da4
Restyled by prettier-markdown
restyled-commits Jul 14, 2023
3590097
Restyled by shellharden
restyled-commits Jul 14, 2023
531c25d
Restyled by shfmt
restyled-commits Jul 14, 2023
9e276ac
Restyled by shellharden
restyled-commits Jul 14, 2023
1be6845
st-device-app: Format kotlin files
Jaehoon-You Jul 14, 2023
bc4727e
scritps: fix merge conflicts
chulspro Jul 20, 2023
e977d82
virtual-device-app: chmod for gradle
Jaehoon-You Jul 17, 2023
f6da08a
virtual-device-app: apply common build script
Jaehoon-You Jul 17, 2023
918fcfc
virtual-device-app: Use out_dir from build script
Jaehoon-You Jul 17, 2023
2647e1b
virtual-device-app: Remove unused chip args
Jaehoon-You Jul 17, 2023
1a19a06
virtual-device-app: Update device config
Jaehoon-You Jul 17, 2023
9ea68f3
Restyled by google-java-format
restyled-commits Jul 17, 2023
7aca097
Restyled by clang-format
restyled-commits Jul 17, 2023
0197ed6
Restyled by gn
restyled-commits Jul 17, 2023
9279568
Restyled by prettier-markdown
restyled-commits Jul 17, 2023
92b3176
virtual-device-app: Change OnOff revision to 5
Jaehoon-You Jul 19, 2023
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
9 changes: 9 additions & 0 deletions docs/examples/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ darwin-framework-tool/README
java-matter-controller/README
```

## Virtual Device App example

```{toctree}
:glob:
:maxdepth: 1

virtual-device-app/**/README
```

## Lighting example

```{toctree}
Expand Down
25 changes: 25 additions & 0 deletions examples/virtual-device-app/android/.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) 2023 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build_overrides/build.gni")

# The location of the build configuration file.
buildconfig = "${build_root}/config/BUILDCONFIG.gn"

# CHIP uses angle bracket includes.
check_system_includes = true

default_args = {
import("//args.gni")
}
26 changes: 26 additions & 0 deletions examples/virtual-device-app/android/App/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
*.iml
.gradle
/local.properties
/.idea/misc.xml
/.idea/gradle.xml
/.idea/compiler.xml
/.idea/.name
/.idea/jarRepositories.xml
/.idea/vcs.xml
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.idea/**
.DS_Store
/captures
.externalNativeBuild
.cxx
local.properties

# Shared libs & JAR libs (those libs are copied into source tree for easy Android build).
*.so
*.jar
*.map
1 change: 1 addition & 0 deletions examples/virtual-device-app/android/App/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.idea
98 changes: 98 additions & 0 deletions examples/virtual-device-app/android/App/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import com.matter.buildsrc.Deps
import com.matter.buildsrc.Versions

plugins {
id("com.android.application")
id("kotlin-android")
id("dagger.hilt.android.plugin")
id("androidx.navigation.safeargs.kotlin")
kotlin("kapt")
}

android {
namespace = "com.matter.virtual.device.app"
compileSdk = Versions.compileSdkVersion
buildToolsVersion = Versions.buildToolsVersion

defaultConfig {
applicationId = "com.matter.virtual.device.app"
minSdk = Versions.minSdkVersion
targetSdk = Versions.targetSdkVersion
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
targets += listOf("default")
}
}
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}

debug {
packagingOptions {
jniLibs.keepDebugSymbols.add("**/*.so")
}
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
viewBinding = true
dataBinding = true
}
kapt {
correctErrorTypes = true
}
sourceSets {
getByName("main") {
jniLibs.setSrcDirs(listOf("libs/jniLibs"))
}
}
packagingOptions {
jniLibs.pickFirsts.add("**/*.so")
jniLibs.useLegacyPackaging = true
}
}

dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))

implementation(project(":core:common"))
implementation(project(":core:data"))
implementation(project(":core:domain"))
implementation(project(":core:model"))
implementation(project(":feature:main"))
implementation(project(":feature:qrcode"))
implementation(project(":feature:setup"))

implementation(Deps.AndroidX.core)
implementation(Deps.AndroidX.appcompat)
implementation(Deps.material)

implementation(Deps.Navigation.fragment)
implementation(Deps.Navigation.ui)

implementation(Deps.Dagger.hiltAndroid)
kapt(Deps.Dagger.hiltAndroidCompiler)

implementation(Deps.timber)

testImplementation(Deps.Test.junit)
androidTestImplementation(Deps.Test.junitExt)
androidTestImplementation(Deps.Test.espresso)
}
21 changes: 21 additions & 0 deletions examples/virtual-device-app/android/App/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.matter.virtual.device.app

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.*
import org.junit.Test
import org.junit.runner.RunWith

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.matter.virtual.device.app", appContext.packageName)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<application
android:name=".App"
android:allowBackup="false"
android:extractNativeLibs="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.App">

<activity
android:name=".MainActivity"
android:exported="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.matter.virtual.device.app

import android.app.Application
import dagger.hilt.android.HiltAndroidApp
import timber.log.Timber

@HiltAndroidApp
class App : Application() {

override fun onCreate() {
super.onCreate()
Timber.plant(TimberDebugTree())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.matter.virtual.device.app

import android.Manifest
import android.content.pm.PackageManager
import android.os.Bundle
import android.view.MenuItem
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.matter.virtual.device.app.databinding.ActivityMainBinding
import dagger.hilt.android.AndroidEntryPoint
import timber.log.Timber

@AndroidEntryPoint
class MainActivity : AppCompatActivity() {

private lateinit var binding: ActivityMainBinding

private val permissions = arrayOf(Manifest.permission.ACCESS_FINE_LOCATION)

private val requestMultiplePermissions =
registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { permissions ->
permissions.entries.forEach { Timber.d("${it.key}:${it.value}") }
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Timber.d("onCreate()")

val isPermissionsGranted =
permissions.all {
ContextCompat.checkSelfPermission(this, it) == PackageManager.PERMISSION_GRANTED
}

if (!isPermissionsGranted) {
requestMultiplePermissions.launch(permissions)
}

binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
}

override fun onDestroy() {
super.onDestroy()
Timber.d("onDestroy()")
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
android.R.id.home -> {
onBackPressed()
return true
}
}

return super.onOptionsItemSelected(item)
}

override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
Timber.d("RequestCode:$requestCode")
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.matter.virtual.device.app

import timber.log.Timber

class TimberDebugTree : Timber.DebugTree() {
override fun createStackElementTag(element: StackTraceElement): String {
return if (BuildConfig.DEBUG) {
"[STD]:${element.fileName}:${element.lineNumber}#${element.methodName}"
} else {
"[STD]:${element.className}#${element.methodName}"
}
}
}
Loading