Skip to content

Commit

Permalink
add android dummy stub for java matter controller application
Browse files Browse the repository at this point in the history
  • Loading branch information
yunhanw-google committed Oct 28, 2022
1 parent bd2c96a commit dd3ec53
Show file tree
Hide file tree
Showing 16 changed files with 433 additions and 11 deletions.
1 change: 1 addition & 0 deletions examples/build_overrides/build.gni
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
declare_args() {
# Root directory for build files.
build_root = "//third_party/connectedhomeip/build"
build_java_matter_controller = false
}
3 changes: 2 additions & 1 deletion examples/java-matter-controller/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import("${build_root}/config/android_abi.gni")
import("${chip_root}/build/chip/java/rules.gni")
import("${chip_root}/build/chip/tools.gni")

build_java_matter_controller = true

android_binary("java-matter-controller") {
output_name = "java-matter-controller"

deps = [
"${chip_root}/src/controller/java",
"${chip_root}/src/setup_payload/java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,17 @@
*/
package com.matter.controller;

import chip.devicecontroller.ChipDeviceController;
import chip.devicecontroller.ControllerParams;

public class Main {
public static void main(String[] args) {
ChipDeviceController controller =
new ChipDeviceController(
ControllerParams.newBuilder()
.setUdpListenPort(0)
.setControllerVendorId(0xFFF1)
.build());
System.out.println("Hello Matter Controller!");

for (String s : args) {
Expand Down
28 changes: 22 additions & 6 deletions src/controller/java/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ import("//build_overrides/chip.gni")
import("${build_root}/config/android_abi.gni")
import("${chip_root}/build/chip/java/rules.gni")

if (defined(build_java_matter_controller)) {
build_java_matter_controller = build_java_matter_controller
} else {
build_java_matter_controller = false
}

shared_library("jni") {
output_name = "libCHIPController"

Expand Down Expand Up @@ -67,10 +73,7 @@ shared_library("jni") {
android_library("java") {
output_name = "CHIPController.jar"

deps = [
":android",
"${chip_root}/third_party/java_deps:annotation",
]
deps = [ "${chip_root}/third_party/java_deps:annotation" ]

data_deps = [
":jni",
Expand Down Expand Up @@ -122,12 +125,25 @@ android_library("java") {
"zap-generated/chip/devicecontroller/ClusterWriteMapping.java",
]

if (build_java_matter_controller) {
deps += [
"${chip_root}/third_party/java_deps/stub_src",
"${chip_root}/third_party/java_deps:json",
]
} else {
deps += [ ":android" ]

data_deps += [ "${chip_root}/build/chip/java:shared_cpplib" ]
}

javac_flags = [ "-Xlint:deprecation" ]

# TODO: add classpath support (we likely need to add something like
# ..../platforms/android-21/android.jar to access BLE items)
}

java_prebuilt("android") {
jar_path = "${android_sdk_root}/platforms/android-21/android.jar"
if (!build_java_matter_controller) {
java_prebuilt("android") {
jar_path = "${android_sdk_root}/platforms/android-21/android.jar"
}
}
15 changes: 11 additions & 4 deletions src/setup_payload/java/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ import("//build_overrides/chip.gni")
import("${build_root}/config/android_abi.gni")
import("${chip_root}/build/chip/java/rules.gni")

if (defined(build_java_matter_controller)) {
build_java_matter_controller = build_java_matter_controller
} else {
build_java_matter_controller = false
}

shared_library("jni") {
output_name = "libSetupPayloadParser"

Expand All @@ -34,10 +40,11 @@ shared_library("jni") {
android_library("java") {
output_name = "SetupPayloadParser.jar"

data_deps = [
":jni",
"${chip_root}/build/chip/java:shared_cpplib",
]
data_deps = [ ":jni" ]

if (!build_java_matter_controller) {
data_deps += [ "${chip_root}/build/chip/java:shared_cpplib" ]
}

sources = [
"src/chip/setuppayload/DiscoveryCapability.java",
Expand Down
4 changes: 4 additions & 0 deletions third_party/java_deps/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ import("${chip_root}/build/chip/java/rules.gni")
java_prebuilt("annotation") {
jar_path = "artifacts/jsr305-3.0.2.jar"
}

java_prebuilt("json") {
jar_path = "artifacts/json-20220924.jar"
}
1 change: 1 addition & 0 deletions third_party/java_deps/set_up_java_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@

mkdir third_party/java_deps/artifacts
curl --fail --location --silent --show-error https://repo1.maven.org/maven2/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar -o third_party/java_deps/artifacts/jsr305-3.0.2.jar
curl --fail --location --silent --show-error https://repo1.maven.org/maven2/org/json/json/20220924/json-20220924.jar -o third_party/java_deps/artifacts/json-20220924.jar
38 changes: 38 additions & 0 deletions third_party/java_deps/stub_src/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright (c) 2020-2021 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.

#TODO: Decouple Android Bluetooth stuff from ChipDeviceController.Java, remove dummy implemenation here.
#TODO: Decouple Android Logging from from ChipDeviceController.Java, remove dummy implemenation here.

import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")
import("${build_root}/config/android_abi.gni")
import("${chip_root}/build/chip/java/rules.gni")

android_library("stub_src") {
output_name = "Android.jar"

sources = [
"android/bluetooth/BluetoothGatt.java",
"android/bluetooth/BluetoothGattCallback.java",
"android/bluetooth/BluetoothGattCharacteristic.java",
"android/bluetooth/BluetoothGattDescriptor.java",
"android/bluetooth/BluetoothGattService.java",
"android/bluetooth/BluetoothProfile.java",
"android/os/Build.java",
"android/util/Log.java",
]

javac_flags = [ "-Xlint:deprecation" ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* Copyright (c) 2015-2017 Nest Labs, Inc.
* All rights reserved.
*
* 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.
*/

/** BluetoothGatt.java Stub file to allow compiling standalone, without Android SDK. */
package android.bluetooth;

import java.util.List;
import java.util.UUID;

// Stub class to allow standalone compilation without Android
public final class BluetoothGatt {

public static final int GATT_SUCCESS = 0;

public void close() {}

public BluetoothGattService getService(UUID uuid) {
return null;
}

public List<BluetoothGattService> getServices() {
return null;
}

public boolean setCharacteristicNotification(
BluetoothGattCharacteristic characteristic, boolean enable) {
return false;
}

public boolean writeCharacteristic(BluetoothGattCharacteristic characteristic) {
return false;
}

public boolean writeDescriptor(BluetoothGattDescriptor descriptor) {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* Copyright (c) 2015-2017 Nest Labs, Inc.
* All rights reserved.
*
* 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.
*/

/** BluetoothGattCallback.java Stub file to allow compiling standalone, without Android SDK. */
package android.bluetooth;

// Stub class to allow standalone compilation without Android
public abstract class BluetoothGattCallback {
public void onCharacteristicChanged(
BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {}

public void onCharacteristicRead(
BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {}

public void onCharacteristicWrite(
BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {}

public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {}

public void onDescriptorRead(
BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {}

public void onDescriptorWrite(
BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {}

public void onServicesDiscovered(BluetoothGatt gatt, int status) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* Copyright (c) 2015-2017 Nest Labs, Inc.
* All rights reserved.
*
* 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.
*/

/**
* BluetoothGattCharacteristic.java Stub file to allow compiling standalone, without Android SDK.
*/
package android.bluetooth;

import java.util.UUID;

// Stub class to allow standalone compilation without Android
public class BluetoothGattCharacteristic {
protected UUID mUuid;

public BluetoothGattDescriptor getDescriptor(UUID uuid) {
return null;
}

public BluetoothGattService getService() {
return null;
}

public UUID getUuid() {
return mUuid;
}

public byte[] getValue() {
return null;
}

public boolean setValue(byte[] value) {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* Copyright (c) 2015-2017 Nest Labs, Inc.
* All rights reserved.
*
* 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.
*/

/** BluetoothGattDescriptor.java Stub file to allow compiling standalone, without Android SDK. */
package android.bluetooth;

import java.util.UUID;

// Stub class to allow standalone compilation without Android
public class BluetoothGattDescriptor {
public static final byte[] ENABLE_NOTIFICATION_VALUE = {0x01, 0x00};

public static final byte[] ENABLE_INDICATION_VALUE = {0x02, 0x00};

public static final byte[] DISABLE_NOTIFICATION_VALUE = {0x00, 0x00};

protected UUID mUuid;

public BluetoothGattCharacteristic getCharacteristic() {
return null;
}

public UUID getUuid() {
return mUuid;
}

public byte[] getValue() {
return null;
}

public boolean setValue(byte[] value) {
return true;
}
}
Loading

0 comments on commit dd3ec53

Please sign in to comment.