Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
niottt committed Feb 13, 2025
0 parents commit 5b46509
Show file tree
Hide file tree
Showing 82 changed files with 9,126 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/build-apk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Release
run-name: ${{ github.actor }} is building Release 🚀
on:
push:
tags:
- 'v*'
permissions:
contents: write
jobs:
deploy:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Checkout main repository
uses: actions/checkout@v3
with:
ref: main
- name: Build APK
run: |
chmod +x ./gradlew
./gradlew build
./gradlew packageDebugAndroidTest
mkdir -p app/build/apk
mv app/build/outputs/apk/debug/app-debug.apk app/build/apk/com.github.tikmatrix.apk
mv app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk app/build/apk/com.github.tikmatrix.test.apk
- name: Upload APK
uses: ryand56/[email protected]
with:
r2-account-id: ${{ secrets.R2_ACCOUNT_ID }}
r2-access-key-id: ${{ secrets.R2_ACCESS_KEY_ID }}
r2-secret-access-key: ${{ secrets.R2_SECRET_ACCESS_KEY }}
r2-bucket: tikmatrix
source-dir: app/build/apk/
destination-dir: ./
- name: Update Version
run: |
TAG_NAME="${GITHUB_REF#refs/tags/}"
curl -X PUT https://pro.api.tikmatrix.com/ci/update_core_version \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${{ secrets.API_KEY }}" \
-d '{
"apk_version": "'"${TAG_NAME}"'",
"test_apk_version": "'"${TAG_NAME}"'"
}'
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.gradle
local.properties
.DS_Store
build
captures
.idea
app/app.iml
tikmatrix-android.iml
*.iml
24 changes: 24 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "android",
"request": "launch",
"name": "Android launch",
"appSrcRoot": "${workspaceRoot}/app/src/main",
"apkFile": "${workspaceRoot}/app/build/outputs/apk/debug/app-debug.apk",
"adbPort": 5037
},
{
"type": "android",
"request": "attach",
"name": "Android attach",
"appSrcRoot": "${workspaceRoot}/app/src/main",
"adbPort": 5037,
"processId": "${command:PickAndroidProcess}"
}
]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "automatic"
}
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2015 [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.
171 changes: 171 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
# Purpose

Support Android 5.0+
[UIAutomator](http://developer.android.com/tools/testing/testing_ui.html) is a
great tool to perform Android UI testing, but to do it, you have to write java
code, compile it, install the jar, and run. It's a complex steps for all
testers...

This project is to build a light weight jsonrpc server in Android device, so
that we can just write PC side script to write UIAutomator tests.

# Github Actions

## R2_ACCOUNT_ID

Your Cloudflare account ID.

## R2_ACCESS_KEY_ID

Your Cloudflare R2 bucket access key ID.

## R2_SECRET_ACCESS_KEY

Your Cloudflare R2 bucket secret access key.

# Build

- Run command:

```bash
./gradlew build
./gradlew packageDebugAndroidTest
mv app/build/outputs/apk/debug/app-debug.apk app/build/outputs/apk/com.github.tikmatrix.apk
mv app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk app/build/outputs/apk/com.github.tikmatrix.test.apk
```

- Run the jsonrpc server on Android device

```bash
./gradlew cC
adb forward tcp:9008 tcp:9008 # tcp forward
```

If debug apk already installed, There is no need to use gradle.

simply run the following command

```
adb forward tcp:9008 tcp:9008
adb shell am instrument -w -r -e debug false -e class com.github.tikmatrix.stub.Stub com.github.tikmatrix.test/androidx.test.runner.AndroidJUnitRunner
adb shell am startservice com.github.tikmatrix/.Service
```

# Run

```bash
$ curl -X POST -d '{"jsonrpc": "2.0", "id": "1f0f2655716023254ed2b57ba4198815", "method": "deviceInfo", "params": {}}' 'http://127.0.0.1:9008/jsonrpc/0'
{'currentPackageName': 'com.smartisanos.launcher',
'displayHeight': 1920,
'displayRotation': 0,
'displaySizeDpX': 360,
'displaySizeDpY': 640,
'displayWidth': 1080,
'productName': 'surabaya',
'screenOn': True,
'sdkInt': 23,
'naturalOrientation': True}
```

# The buildin input method

**Fast input method**

Encode the text into UTF-8 and then Base64

For example:

"Hello 你好" -> (UTF-8 && Base64) = SGVsbG8g5L2g5aW9

Send to FastInputIME with broadcast

```bash
# Append text to input field
$ adb shell am broadcast -a ADB_INPUT_TEXT --es text SGVsbG8g5L2g5aW9

# Clear text
$ adb shell am broadcast -a ADB_CLEAR_TEXT

# Clear text before append text
$ adb shell am broadcast -a ADB_SET_TEXT --es text SGVsbG8g5L2g5aW9

# Send keycode, eg: ENTER
$ adb shell am broadcast -a ADB_INPUT_KEYCODE --ei code 66

# Send Editor code
$ adb shell am broadcast -a ADB_EDITOR_CODE --ei code 2 # IME_ACTION_GO

# Get clipboard (without data)
$ adb shell am broadcast -a ADB_GET_CLIPBOARD
Broadcasting: Intent { act=ADB_GET_CLIPBOARD flg=0x400000 }
Broadcast completed: result=0

# Get clipboard (with data, base64 encoded)
$ adb shell am broadcast -a ADB_GET_CLIPBOARD
Broadcasting: Intent { act=ADB_GET_CLIPBOARD flg=0x400000 }
Broadcast completed: result=-1, data="5LqG6Kej5Lyg57uf5paH5YyW"
```
- [Editor Code](https://developer.android.com/reference/android/view/inputmethod/EditorInfo)
- [Key Event](https://developer.android.com/reference/android/view/KeyEvent)
# Change GPS mock location
You can change mock location from terminal using adb in order to test GPS on real devices.
```
adb [-s <specific device>] shell am broadcast -a send.mock [-e lat <latitude>] [-e lon <longitude>]
[-e alt <altitude>] [-e accurate <accurate>]
```
For example:
```
adb shell am broadcast -a send.mock -e lat 15.3 -e lon 99
```
## Show toast
```
adb shell am start -n com.github.tikmatrix/.ToastActivity -e message hello
```
## Float window
```
adb shell am start -n com.github.tikmatrix/.ToastActivity -e showFloatWindow true # show
adb shell am start -n com.github.tikmatrix/.ToastActivity -e showFloatWindow false # hide
```
## Change language and timezone
```
adb shell am start -n com.github.tikmatrix/.ToastActivity --es language en --es timezone Europe/London
```
# How to generate changelog
[conventional-changelog](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-cli)
```bash
npm install -g conventional-changelog-cli
conventional-changelog -p grunt -i CHANGELOG.md -s -r 0
```
# Dependencies
- [nanohttpd](https://github.com/NanoHttpd/nanohttpd)
- [jsonrpc4j](https://github.com/briandilley/jsonrpc4j)
- [jackson](https://github.com/FasterXML/jackson)
- [androidx.test.uiautomator](https://mvnrepository.com/artifact/androidx.test.uiautomator/uiautomator-v18)
# Added features
- [x] support unicode input
# Resources
- [Google UiAutomator Tutorial](https://developer.android.com/training/testing/ui-testing/uiautomator-testing?hl=zh-cn)
- [Google UiAutomator API](https://developer.android.com/reference/android/support/test/uiautomator/package-summary?hl=zh-cn)
- [Maven repository of uiautomator-v18](https://mvnrepository.com/artifact/androidx.test.uiautomator/uiautomator-v18)
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
96 changes: 96 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@

buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.8.0' // Ensure this is 3.0.0 or higher
}
}

apply plugin: 'com.android.application'

android {
compileSdk 34
// version code history
// 1: original version
// 2: update all dependencies to latest
// 6: input method, battery,rotation monitor
namespace 'com.github.tikmatrix'
defaultConfig {
applicationId "com.github.tikmatrix"
minSdkVersion 21
targetSdkVersion 34
versionName "0.0.1"
versionCode 2025001
}

signingConfigs {
release {
storeFile file("../release.keystore")
storePassword "uiautomator-release-2015"
keyAlias "uiautomator"
keyPassword "uiautomator"
}
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}

android {
lintOptions {
abortOnError false
}
}
packagingOptions {
resources {
excludes += ['LICENSE.txt', 'META-INF/LICENSE', 'META-INF/NOTICE']
}
}

defaultConfig {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

}


// fix try-with-resource warning
// ref: https://stackoverflow.com/questions/40408628/try-with-resources-requires-api-level-19-okhttp
compileOptions {
sourceCompatibility agp_version
targetCompatibility agp_version
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

// server
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'org.nanohttpd:nanohttpd:2.3.1'
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
implementation 'commons-cli:commons-cli:1.3.1'

// test

androidTestImplementation 'androidx.test:runner:1.5.2'
androidTestImplementation 'androidx.test:rules:1.5.0'
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.3.0'
androidTestImplementation 'com.github.briandilley.jsonrpc4j:jsonrpc4j:1.5.0'
androidTestImplementation 'com.fasterxml.jackson.core:jackson-core:2.5.3'
androidTestImplementation 'com.fasterxml.jackson.core:jackson-annotations:2.5.3'
androidTestImplementation 'com.fasterxml.jackson.core:jackson-databind:2.5.3'

}


repositories {
google()
mavenCentral()
}
17 changes: 17 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/xiaocong/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# 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 *;
#}
Loading

0 comments on commit 5b46509

Please sign in to comment.