Skip to content

Commit

Permalink
[Android] Add Android Matter Device App for automation testing (proje…
Browse files Browse the repository at this point in the history
  • Loading branch information
chulspro authored and erwinpan1 committed Jul 21, 2023
1 parent 491318a commit 80accab
Show file tree
Hide file tree
Showing 171 changed files with 22,857 additions and 1 deletion.
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

0 comments on commit 80accab

Please sign in to comment.