forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Android] Add Android Matter Device App for automation testing (proje…
- Loading branch information
Showing
171 changed files
with
22,857 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/.idea |
98 changes: 98 additions & 0 deletions
98
examples/virtual-device-app/android/App/app/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
21
examples/virtual-device-app/android/App/app/proguard-rules.pro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
22 changes: 22 additions & 0 deletions
22
...oid/App/app/src/androidTest/java/com/matter/virtual/device/app/ExampleInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
examples/virtual-device-app/android/App/app/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Binary file added
BIN
+40.3 KB
examples/virtual-device-app/android/App/app/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions
14
...les/virtual-device-app/android/App/app/src/main/java/com/matter/virtual/device/app/App.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...al-device-app/android/App/app/src/main/java/com/matter/virtual/device/app/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...device-app/android/App/app/src/main/java/com/matter/virtual/device/app/TimberDebugTree.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" | ||
} | ||
} | ||
} |
Oops, something went wrong.