Skip to content

Commit

Permalink
Added Android platform (#9884)
Browse files Browse the repository at this point in the history
* added android platform impl and CHIPTest to run ul-test on it

* add clangd index file and compile_commands.json to .gitignore

* use platform/android in src/controller instead of impl themselves

* basic run and debug with new control

* use inject driver mode as old controller as Andrei Litvin suggestion

* fix ci build

* fix ci build

* fixed restyled-io

* fixed restyled-io

* fixed Doxygen ci

* fixed review code style issues

* move AndroidChipPlatform singleton down to the app layer

* move dependencies in the constructor for AndroidChipPlatform

* using val than var

* update gradle version in CHIPTest and fix runtime errors

* fixed restyled-io

* remove commented out code

* fixed restyled-io

* update license to 2021

* fixed review code style issues

* fix ci build

* rename load to loadJni and add a comment describing the purpose.

* fixed review code style issues

* separate ble callback and Connection

* Recovery PR #9097

* fix merge issue

* fix merge issue

* fixed restyled-io

* fixed restyled-io
  • Loading branch information
xylophone21 authored and pull[bot] committed Nov 5, 2021
1 parent 6c25956 commit 5466904
Show file tree
Hide file tree
Showing 125 changed files with 5,190 additions and 1,259 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,9 @@ docs/html

# VSCode java extensions
.project

# clangd index files
.cache

# compilation database for VSCode and other Ides
compile_commands.json
1 change: 1 addition & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") {
if (current_os == "android") {
deps += [
"${chip_root}/src/controller/java",
"${chip_root}/src/platform/android:java",
"${chip_root}/src/setup_payload/java",
]
}
Expand Down
7 changes: 6 additions & 1 deletion scripts/build/builders/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ def _build(self):

jars = {
'CHIPController.jar': 'src/controller/java/CHIPController.jar',
'SetupPayloadParser.jar': 'src/setup_payload/java/SetupPayloadParser.jar'
'SetupPayloadParser.jar': 'src/setup_payload/java/SetupPayloadParser.jar',
'AndroidPlatform.jar': 'src/platform/android/AndroidPlatform.jar'

}
for jarName in jars.keys():
self._Execute(['cp', os.path.join(
Expand All @@ -174,6 +176,9 @@ def build_outputs(self):
'CHIPController.jar':
os.path.join(self.output_dir, 'lib',
'src/controller/java/CHIPController.jar'),
'AndroidPlatform.jar':
os.path.join(self.output_dir, 'lib',
'src/platform/android/AndroidPlatform.jar'),
'SetupPayloadParser.jar':
os.path.join(self.output_dir, 'lib',
'src/setup_payload/java/SetupPayloadParser.jar'),
Expand Down
8 changes: 8 additions & 0 deletions scripts/build/expected_all_platform_commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ cp {out}/android-arm-chip_tool/lib/src/controller/java/CHIPController.jar {root}

cp {out}/android-arm-chip_tool/lib/src/setup_payload/java/SetupPayloadParser.jar {root}/src/android/CHIPTool/app/libs/SetupPayloadParser.jar

cp {out}/android-arm-chip_tool/lib/src/platform/android/AndroidPlatform.jar {root}/src/android/CHIPTool/app/libs/AndroidPlatform.jar

# Building APP android-arm-chip_tool
{root}/src/android/CHIPTool/gradlew -p {root}/src/android/CHIPTool -PbuildDir={out}/android-arm-chip_tool assembleDebug

Expand All @@ -296,6 +298,8 @@ cp {out}/android-arm64-chip_tool/lib/src/controller/java/CHIPController.jar {roo

cp {out}/android-arm64-chip_tool/lib/src/setup_payload/java/SetupPayloadParser.jar {root}/src/android/CHIPTool/app/libs/SetupPayloadParser.jar

cp {out}/android-arm64-chip_tool/lib/src/platform/android/AndroidPlatform.jar {root}/src/android/CHIPTool/app/libs/AndroidPlatform.jar

# Building APP android-arm64-chip_tool
{root}/src/android/CHIPTool/gradlew -p {root}/src/android/CHIPTool -PbuildDir={out}/android-arm64-chip_tool assembleDebug

Expand All @@ -315,6 +319,8 @@ cp {out}/android-x64-chip_tool/lib/src/controller/java/CHIPController.jar {root}

cp {out}/android-x64-chip_tool/lib/src/setup_payload/java/SetupPayloadParser.jar {root}/src/android/CHIPTool/app/libs/SetupPayloadParser.jar

cp {out}/android-x64-chip_tool/lib/src/platform/android/AndroidPlatform.jar {root}/src/android/CHIPTool/app/libs/AndroidPlatform.jar

# Building APP android-x64-chip_tool
{root}/src/android/CHIPTool/gradlew -p {root}/src/android/CHIPTool -PbuildDir={out}/android-x64-chip_tool assembleDebug

Expand All @@ -334,6 +340,8 @@ cp {out}/android-x86-chip_tool/lib/src/controller/java/CHIPController.jar {root}

cp {out}/android-x86-chip_tool/lib/src/setup_payload/java/SetupPayloadParser.jar {root}/src/android/CHIPTool/app/libs/SetupPayloadParser.jar

cp {out}/android-x86-chip_tool/lib/src/platform/android/AndroidPlatform.jar {root}/src/android/CHIPTool/app/libs/AndroidPlatform.jar

# Building APP android-x86-chip_tool
{root}/src/android/CHIPTool/gradlew -p {root}/src/android/CHIPTool -PbuildDir={out}/android-x86-chip_tool assembleDebug

Expand Down
20 changes: 20 additions & 0 deletions src/android/CHIPTest/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
*.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

# Shared libs & JAR libs (those libs are copied into source tree for easy Android build).
*.so
*.jar
*.map
3 changes: 3 additions & 0 deletions src/android/CHIPTest/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/android/CHIPTest/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/android/CHIPTest/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions src/android/CHIPTest/.idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/android/CHIPTest/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/android/CHIPTest/.idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/android/CHIPTest/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/android/CHIPTest/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
75 changes: 75 additions & 0 deletions src/android/CHIPTest/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.3"

defaultConfig {
applicationId "com.tcl.chip.chiptest"
minSdkVersion 26
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

ndk {abiFilters 'arm64-v8a'}

externalNativeBuild {
cmake {
arguments "-DMATTER_SDK_SOURCE_BUILD="+rootProject.ext.matterSdkSourceBuild \
, "-DMATTER_SDK_BUILD_ROOT="+rootProject.ext.matterSdkBuildRoot \
, "-DMATTER_SDK_UTEST_LIB="+rootProject.ext.matterSdkUtestLib
}
}
}

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

debug {
packagingOptions {
doNotStrip '**/*.so'
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}

externalNativeBuild {
cmake {
path file('src/main/cpp/CMakeLists.txt')
version '3.10.2'
}
}

buildFeatures {
viewBinding true
}
}

dependencies {
if(!rootProject.ext.matterSdkSourceBuild) {
implementation fileTree(dir: "libs", include: ["*.jar"])
}

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
2 changes: 2 additions & 0 deletions src/android/CHIPTest/app/libs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This directory will contain any .jar files required by the CHIPTool demo app for
Android.
3 changes: 3 additions & 0 deletions src/android/CHIPTest/app/libs/jniLibs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This directory will contain .so files required by CHIPTool demo app for Android.
The .so files must be organized into folders by the name of the corresponding
Android architecture for which they are built, eg. arm64-v8a, x86, x86_64, etc.
21 changes: 21 additions & 0 deletions src/android/CHIPTest/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,24 @@
package com.tcl.chip.chiptest

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.tcl.chip.chiptest", appContext.packageName)
}
}
30 changes: 30 additions & 0 deletions src/android/CHIPTest/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tcl.chip.chiptest">

<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.NFC" />

<application
android:allowBackup="true"
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.CHIPTest">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Loading

0 comments on commit 5466904

Please sign in to comment.