Skip to content

Commit

Permalink
feat: init project
Browse files Browse the repository at this point in the history
Signed-off-by: DazeCake <[email protected]>
  • Loading branch information
DazeCake committed Mar 14, 2024
0 parents commit a331174
Show file tree
Hide file tree
Showing 20 changed files with 673 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.iml
.gradle
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
/.idea/
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# AutoDroidX

Modern Android application automation testing toolset.

> ⚠️Warning! This project is in fast moving, and any disruptive API changes will not be notified in advance.
---

## Base

> We call it `adx` as abbreviation
adx is designed as a low-intrusive, multi-capability modern Android application automation testing toolkit. It consists of multiple modules, ultimately providing users with powerful automation testing capabilities. The design of its core module, `agent`, is inspired by [scrcpy](https://github.com/Genymobile/scrcpy) (in fact, it is a Kotlin implementation of scrcpy-server).

Here is a picture to briefly explain how it works.

![structure](docs/pic/structure.png)

## Module

### 🚧 agent

The core of adx, all operations are ultimately sent to the agent and are finally represented by it to Android devices as events.

### 🗒 server

Start and manage agent. Also instance Management Center allows you to centrally manage multiple Android device.
1 change: 1 addition & 0 deletions agent/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
55 changes: 55 additions & 0 deletions agent/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import com.android.build.gradle.internal.tasks.factory.dependsOn

plugins {
alias(libs.plugins.androidApplication)
alias(libs.plugins.jetbrainsKotlinAndroid)
}

android {
namespace = "com.dazecake.autodroidx"
compileSdk = 34

defaultConfig {
applicationId = "com.dazecake.autodroidx"
minSdk = 21
targetSdk = 34
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"
}
}

dependencies {

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.material)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
}

tasks.register<Copy>("makeJar") {
// from("build/intermediates/packaged-classes/debug/classes.jar")
from("build/tmp/kotlin-classes/debug/com/dazecake/autodroidx/MainKt.class")
into("build/libs")
rename { "autodroidx-agent.jar" }
}.dependsOn("build")
21 changes: 21 additions & 0 deletions agent/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,24 @@
package com.dazecake.autodroidx

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* 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.dazecake.autodroidx", appContext.packageName)
}
}
2 changes: 2 additions & 0 deletions agent/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!-- not a real Android application, it is run by app_process manually -->
<manifest />
43 changes: 43 additions & 0 deletions agent/src/main/java/com/dazecake/autodroidx/Main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.dazecake.autodroidx

import android.os.Build
import com.dazecake.autodroidx.utils.Log
import com.dazecake.autodroidx.utils.Options
import kotlin.system.exitProcess

object Main {
/**
* Main entry point for the agent.
*/
@JvmStatic
fun main(args: Array<String>) {
var status = 0
try {
init(args)
} catch (e: Exception) {
e.message?.let { Log.e(it, e) }
status = 1
} finally {
exitProcess(status)
}
}

private fun init(args: Array<String>) {
Thread.setDefaultUncaughtExceptionHandler { t: Thread, e: Throwable? ->
e?.let {
Log.e(
"Exception on thread $t",
it
)
}
}

val options = Options().paras(args)

Log.disableSystemStreams()
Log.setLevel(options.logLevel)

Log.i("Device: [" + Build.MANUFACTURER + "] " + Build.BRAND + " " + Build.MODEL + " (Android " + Build.VERSION.RELEASE + ")")
}
}

104 changes: 104 additions & 0 deletions agent/src/main/java/com/dazecake/autodroidx/utils/Log.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.dazecake.autodroidx.utils

import android.util.Log
import java.io.FileDescriptor
import java.io.FileOutputStream
import java.io.OutputStream
import java.io.PrintStream


enum class Level {
VERBOSE,
DEBUG,
INFO,
WARN,
ERROR
}


internal class NullOutputStream : OutputStream() {
override fun write(b: ByteArray) {
// ignore
}

override fun write(b: ByteArray, off: Int, len: Int) {
// ignore
}

override fun write(b: Int) {
// ignore
}
}


object Log {

private var threshold: Level = Level.INFO

private const val TAG = "AutoDroidX"
private const val PREFIX = "[adx]: "

private val CONSOLE_OUT = PrintStream(FileOutputStream(FileDescriptor.out))
private val CONSOLE_ERR = PrintStream(FileOutputStream(FileDescriptor.err))

private fun isEnabled(level: Level): Boolean {
return level.ordinal >= threshold.ordinal
}

fun disableSystemStreams() {
val nullStream = PrintStream(NullOutputStream())
System.setOut(nullStream)
System.setErr(nullStream)
}

fun v(message: String) {
if (isEnabled(Level.VERBOSE)) {
Log.v(TAG, message)
CONSOLE_OUT.print(PREFIX + "VERBOSE: " + message + '\n')
}
}

fun d(message: String) {
if (isEnabled(Level.DEBUG)) {
Log.d(TAG, message)
CONSOLE_OUT.print(PREFIX + "DEBUG: " + message + '\n')
}
}

fun i(message: String) {
if (isEnabled(Level.INFO)) {
Log.i(TAG, message)
CONSOLE_OUT.print(PREFIX + "INFO: " + message + '\n')
}
}

fun w(message: String) {
if (isEnabled(Level.WARN)) {
Log.w(TAG, message)
CONSOLE_ERR.print(PREFIX + "WARN: " + message + '\n')
}
}

fun e(message: String) {
if (isEnabled(Level.ERROR)) {
Log.e(TAG, message)
CONSOLE_ERR.print(PREFIX + "ERROR: " + message + '\n')
}
}

fun e(message: String, e: Throwable) {
if (isEnabled(Level.ERROR)) {
Log.e(TAG, message, e)
CONSOLE_ERR.print(PREFIX + "ERROR: " + message + '\n')
e.printStackTrace(CONSOLE_ERR)
}
}

fun setLevel(level: Level) {
Log.i(TAG, "Setting log level to $level")
threshold = level
}



}
15 changes: 15 additions & 0 deletions agent/src/main/java/com/dazecake/autodroidx/utils/Options.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.dazecake.autodroidx.utils

data class Options(
var logLevel: Level = Level.DEBUG,
) {
fun paras(args: Array<String>): Options {
val options = Options()
for (i in args.indices) {
if (args[i] == "-v") {
options.logLevel = Level.VERBOSE
}
}
return options
}
}
17 changes: 17 additions & 0 deletions agent/src/test/java/com/dazecake/autodroidx/ExampleUnitTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.dazecake.autodroidx

import org.junit.Test

import org.junit.Assert.*

/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}
6 changes: 6 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.jetbrainsKotlinAndroid) apply false
alias(libs.plugins.androidLibrary) apply false
}
Binary file added docs/pic/structure.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. For more details, visit
# https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
23 changes: 23 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[versions]
agp = "8.3.0"
kotlin = "1.9.0"
coreKtx = "1.10.1"
junit = "4.13.2"
junitVersion = "1.1.5"
espressoCore = "3.5.1"
appcompat = "1.6.1"
material = "1.10.0"

[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
material = { group = "com.google.android.material", name = "material", version.ref = "material" }

[plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" }
jetbrainsKotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
androidLibrary = { id = "com.android.library", version.ref = "agp" }

Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Loading

0 comments on commit a331174

Please sign in to comment.