Skip to content

Commit

Permalink
[android-release/0.0.1] initial Commissioner Android App (openthread#158
Browse files Browse the repository at this point in the history
)

This commit adds the initial OT Commissioner Android App:

- Commission new Joiner Device with Thread 1.1 MeshCoP
  - Scan Thread Network by mDNS
  - Scan Joiner QR code
  - do 1.1 MeshCoP
- setup GitHub Action builds
  - nightly build with testing (only database tests for this initial PR)
  - release build
- prettify Java code

For testing, we didn't include integration tests against OTBR. Because
Android emulator doesn't support multicast (link) and it is also not
feasible to test QR code scanning given the emulator has no camera.
  • Loading branch information
wgtdkp authored Dec 7, 2020
1 parent f6beb7b commit 95917b0
Show file tree
Hide file tree
Showing 79 changed files with 4,619 additions and 6 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/android-app-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#
# Copyright (c) 2020, The OpenThread Commissioner Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

name: Android App Build

on: [push, pull_request]

jobs:
nightly-build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
android-api: [24]
android-abi: [x86, x86_64]
os: [macos-10.15, ubuntu-20.04]
steps:
- uses: actions/checkout@v2
- name: Bootstrap
run: |
script/bootstrap.sh
- name: Build
run: |
cd android
ANDROID_ABI=${{ matrix.android-abi }} ANDROID_NDK_HOME=$ANDROID_HOME/ndk-bundle ./build-commissioner-libs.sh
cd openthread_commissioner
./gradlew build
- name: Tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.android-api }}
arch: ${{ matrix.android-abi }}
script: "cd android/openthread_commissioner && ./gradlew connectedAndroidTest"
85 changes: 85 additions & 0 deletions .github/workflows/android-app-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#
# Copyright (c) 2020, The OpenThread Commissioner Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# This file runs Android App release build and publish
# releases automatically.
#

name: Android App Release

on:
pull_request:
types: [assigned, opened, synchronize, reopened, closed]

jobs:
build-release:
runs-on: ubuntu-20.04
# We run this job only when the PR branch starts with 'android-release/'.
if: startsWith(github.head_ref, 'android-release/')
steps:
- uses: actions/checkout@v2
- name: Check Release Version
id: check_release_version
run: |
# The PR branch should has the format 'android-release/<release-version>'.
# <release-version> should equal to versionName defined in the gradle file.
branch_version="${GITHUB_HEAD_REF##*/}"
gradle_version="$(cd android/openthread_commissioner && ./gradlew -q printVersionName)"
if [ $branch_version != $gradle_version ]; then
echo "branch name should be android-release/${gradle_version}!"
exit 1
fi
echo "::set-output name=release_version::${gradle_version}"
echo "::set-output name=pr_merged::${{ github.event.pull_request.merged }}"
- name: Bootstrap
run: |
script/bootstrap.sh
- name: Build
run: |
cd android
ANDROID_ABI=armeabi-v7a ANDROID_NDK_HOME=$ANDROID_HOME/ndk-bundle ./build-commissioner-libs.sh
ANDROID_ABI=arm64-v8a ANDROID_NDK_HOME=$ANDROID_HOME/ndk-bundle ./build-commissioner-libs.sh
cd openthread_commissioner
./gradlew assembleDebug
cp app/build/outputs/apk/debug/app-debug.apk \
ot-commissioner-app-debug-${{ steps.check_release_version.outputs.release_version }}.apk
- name: Create New Release
# We create the release only when this PR is merged.
# For some reason, github.event.pull_request.merged
# doesn't work at here.
if: ${{ steps.check_release_version.outputs.pr_merged == 'true' }}
uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "${{ steps.check_release_version.outputs.release_version }}"
prerelease: false
title: "OT Commissioner App ${{ steps.check_release_version.outputs.release_version }}"
files: |
./android/openthread_commissioner/ot-commissioner-app-debug-*.apk
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ libtool
Makefile.in

# build
._build
.build*
build
cmake-build-*

Expand All @@ -63,6 +63,3 @@ doc
__pycache__/
venv/
*.py[cod]

# Java (autogenerated)
**/io/openthread/commissioner
24 changes: 24 additions & 0 deletions android/BUILDING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Build OpenThread Commissioner App

This document describes how to build the OT Commissioner Android App.

## Prerequisites

- macOS or Linux computer.
- Install latest Android Studio from [here](https://developer.android.com/studio).

## Build shared library

The Commissioner Android App is built on top of the native OT Commissioner library. Run the `build-commissioner-libs.sh` script in this directory to build the required libraries:

```shell
ANDROID_ABI=arm64-v8a ANDROID_NDK_HOME=$HOME/Library/Android/sdk/ndk/21.3.6528147 ./build-commissioner-libs.sh
```

This script creates a build directory (`.build-${ANDROID_ABI}`) in the current directory and copies generated libraries into target sub-folders in `openthread_commissioner`.

> Note: you need to set env `ANDROID_ABI` to the ABI of your phone. This value can be got with command `adb shell getprop ro.product.cpu.abi` after connecting the phone to your computer.
## Build the App with Android Studio

Connect the phone to your computer and open the `openthread_commissioner` directory with Android Studio. Click the **Gradle Sync** and **Run** buttons to run the Commissioner App on your phone.
7 changes: 7 additions & 0 deletions android/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# OpenThread Commissioner Android App

The OpenThread (OT) Commissioner Android App commissions a new Thread 1.1 Device onto an existing Thread Network.

## Build

See [BUILDING.md](./BUILDING.md).
83 changes: 83 additions & 0 deletions android/build-commissioner-libs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/bash
#
# Copyright (c) 2020, The OpenThread Commissioner Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

readonly CUR_DIR="$(dirname "$(realpath -s "$0")")"

set -e

if [ -z "${ANDROID_ABI}" ]; then
echo "ANDROID_ABI not set! Candidates: armeabi-v7a, arm64-v8a, x86 and x86_64"
exit 1
fi

if [ -z "${ANDROID_NDK_HOME}" ]; then
echo "ANDROID_NDK_HOME not set! Please set it to your Android NDK location!"
exit 1
fi

cd "${CUR_DIR}"

readonly BUILD_DIR=".build-$ANDROID_ABI"

mkdir -p "$BUILD_DIR" && cd "$BUILD_DIR"
cmake -GNinja \
-DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME"/build/cmake/android.toolchain.cmake \
-DANDROID_ABI="$ANDROID_ABI" \
-DANDROID_ARM_NEON=ON \
-DANDROID_NATIVE_API_LEVEL=21 \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_CXX_STANDARD=11 \
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
-DCMAKE_BUILD_TYPE=Release \
-DOT_COMM_ANDROID=ON \
-DOT_COMM_JAVA_BINDING=ON \
-DOT_COMM_APP=OFF \
-DOT_COMM_TEST=OFF \
-DOT_COMM_CCM=OFF \
../..

ninja commissioner-java
cd ../

rm -rf "$BUILD_DIR"/libs && mkdir -p "$BUILD_DIR"/libs

## Create JAR library
javac -source 8 -target 8 "$BUILD_DIR"/src/java/io/openthread/commissioner/*.java

cd "$BUILD_DIR"/src/java
find ./io/openthread/commissioner -name "*.class" | xargs jar cvf ../../libs/libotcommissioner.jar
cd ../../../

## Copy shared native libraries
cp "$BUILD_DIR"/src/java/libcommissioner-java.so "$BUILD_DIR"/libs

mkdir -p openthread_commissioner/service/libs
mkdir -p openthread_commissioner/service/src/main/jniLibs/"${ANDROID_ABI}"
cp "$BUILD_DIR"/libs/libotcommissioner.jar openthread_commissioner/service/libs
cp "$BUILD_DIR"/libs/*.so openthread_commissioner/service/src/main/jniLibs/"${ANDROID_ABI}"
15 changes: 15 additions & 0 deletions android/openthread_commissioner/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
1 change: 1 addition & 0 deletions android/openthread_commissioner/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
88 changes: 88 additions & 0 deletions android/openthread_commissioner/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright (c) 2020, The OpenThread Commissioner Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

plugins {
id 'com.android.application'
}

def getGitHash = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', '--short', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
}

// Print App version.
task printVersionName {
doLast {
println android.defaultConfig.versionName
}
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.1"
ndkVersion "21.3.6528147"

defaultConfig {
applicationId "io.openthread.commissioner.app"
minSdkVersion 24
targetSdkVersion 30
versionCode 1
versionName "0.0.1"

buildConfigField "String", "GIT_HASH", "\"${getGitHash()}\""

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

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

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation project(':service')

implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
testImplementation 'junit:junit:4.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
Loading

0 comments on commit 95917b0

Please sign in to comment.