diff --git a/examples/build_overrides/build.gni b/examples/build_overrides/build.gni index 323b150ed3399a..b092dc3c3d7013 100644 --- a/examples/build_overrides/build.gni +++ b/examples/build_overrides/build.gni @@ -15,4 +15,5 @@ declare_args() { # Root directory for build files. build_root = "//third_party/connectedhomeip/build" + build_java_matter_controller = false } diff --git a/examples/java-matter-controller/BUILD.gn b/examples/java-matter-controller/BUILD.gn index 8f0d8a43a3763d..ef80aec3e765c6 100644 --- a/examples/java-matter-controller/BUILD.gn +++ b/examples/java-matter-controller/BUILD.gn @@ -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", diff --git a/examples/java-matter-controller/java/src/com/matter/controller/Main.java b/examples/java-matter-controller/java/src/com/matter/controller/Main.java index 6c2d18189f62d6..02ae2c00485918 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/Main.java +++ b/examples/java-matter-controller/java/src/com/matter/controller/Main.java @@ -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) { diff --git a/src/controller/java/BUILD.gn b/src/controller/java/BUILD.gn index 69137520fad329..76cd24cca0e7f8 100644 --- a/src/controller/java/BUILD.gn +++ b/src/controller/java/BUILD.gn @@ -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" @@ -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", @@ -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:json", + "${chip_root}/third_party/java_deps/stub_src", + ] + } 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" + } } diff --git a/src/setup_payload/java/BUILD.gn b/src/setup_payload/java/BUILD.gn index f2b922a2a34b2d..df632864bb2f88 100644 --- a/src/setup_payload/java/BUILD.gn +++ b/src/setup_payload/java/BUILD.gn @@ -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" @@ -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", diff --git a/third_party/java_deps/BUILD.gn b/third_party/java_deps/BUILD.gn index 330783e23af0a9..ffcd48dfe5fe3c 100644 --- a/third_party/java_deps/BUILD.gn +++ b/third_party/java_deps/BUILD.gn @@ -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" +} diff --git a/third_party/java_deps/set_up_java_deps.sh b/third_party/java_deps/set_up_java_deps.sh index ce6dc81f4e29d5..61f0f6e9e465b3 100755 --- a/third_party/java_deps/set_up_java_deps.sh +++ b/third_party/java_deps/set_up_java_deps.sh @@ -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 diff --git a/third_party/java_deps/stub_src/BUILD.gn b/third_party/java_deps/stub_src/BUILD.gn new file mode 100644 index 00000000000000..b66b79aa9ee28d --- /dev/null +++ b/third_party/java_deps/stub_src/BUILD.gn @@ -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" ] +} diff --git a/third_party/java_deps/stub_src/android/bluetooth/BluetoothGatt.java b/third_party/java_deps/stub_src/android/bluetooth/BluetoothGatt.java new file mode 100644 index 00000000000000..3eddf8dadeb443 --- /dev/null +++ b/third_party/java_deps/stub_src/android/bluetooth/BluetoothGatt.java @@ -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 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; + } +} diff --git a/third_party/java_deps/stub_src/android/bluetooth/BluetoothGattCallback.java b/third_party/java_deps/stub_src/android/bluetooth/BluetoothGattCallback.java new file mode 100644 index 00000000000000..74c7f6ac42d909 --- /dev/null +++ b/third_party/java_deps/stub_src/android/bluetooth/BluetoothGattCallback.java @@ -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) {} +} diff --git a/third_party/java_deps/stub_src/android/bluetooth/BluetoothGattCharacteristic.java b/third_party/java_deps/stub_src/android/bluetooth/BluetoothGattCharacteristic.java new file mode 100644 index 00000000000000..202d23fb683e59 --- /dev/null +++ b/third_party/java_deps/stub_src/android/bluetooth/BluetoothGattCharacteristic.java @@ -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; + } +} diff --git a/third_party/java_deps/stub_src/android/bluetooth/BluetoothGattDescriptor.java b/third_party/java_deps/stub_src/android/bluetooth/BluetoothGattDescriptor.java new file mode 100644 index 00000000000000..d3f7ad2b1cbbde --- /dev/null +++ b/third_party/java_deps/stub_src/android/bluetooth/BluetoothGattDescriptor.java @@ -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; + } +} diff --git a/third_party/java_deps/stub_src/android/bluetooth/BluetoothGattService.java b/third_party/java_deps/stub_src/android/bluetooth/BluetoothGattService.java new file mode 100644 index 00000000000000..30a5f1d6c7ee99 --- /dev/null +++ b/third_party/java_deps/stub_src/android/bluetooth/BluetoothGattService.java @@ -0,0 +1,41 @@ +/* + * + * 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. + */ + +/** BluetoothGattService.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 class BluetoothGattService { + protected UUID mUuid; + + public BluetoothGattCharacteristic getCharacteristic(UUID uuid) { + return null; + } + + public List getCharacteristics() { + return null; + } + + public UUID getUuid() { + return mUuid; + } +} diff --git a/third_party/java_deps/stub_src/android/bluetooth/BluetoothProfile.java b/third_party/java_deps/stub_src/android/bluetooth/BluetoothProfile.java new file mode 100644 index 00000000000000..8319ea32ac7c1f --- /dev/null +++ b/third_party/java_deps/stub_src/android/bluetooth/BluetoothProfile.java @@ -0,0 +1,34 @@ +/* + * + * 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. + */ + +/** BluetoothProfile.java Stub file to allow compiling standalone, without Android SDK. */ +package android.bluetooth; + +// Stub class to allow standalone compilation without Android +public final class BluetoothProfile { + + /** The profile is in disconnected state */ + public static final int STATE_DISCONNECTED = 0; + /** The profile is in connecting state */ + public static final int STATE_CONNECTING = 1; + /** The profile is in connected state */ + public static final int STATE_CONNECTED = 2; + /** The profile is in disconnecting state */ + public static final int STATE_DISCONNECTING = 3; +} diff --git a/third_party/java_deps/stub_src/android/os/Build.java b/third_party/java_deps/stub_src/android/os/Build.java new file mode 100644 index 00000000000000..7f41ba7f2c0f47 --- /dev/null +++ b/third_party/java_deps/stub_src/android/os/Build.java @@ -0,0 +1,35 @@ +/* + * + * 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. + */ + +/** Build.java Stub file to allow compiling standalone, without Android SDK. */ +package android.os; + +public final class Build { + public static class VERSION { + public static final int SDK_INT = 0; + } + + public static class VERSION_CODES { + public static final int JELLY_BEAN_MR2 = 18; + } + + public static final String MANUFACTURER = "Unknown"; + + public static final String MODEL = "Unknown"; +} diff --git a/third_party/java_deps/stub_src/android/util/Log.java b/third_party/java_deps/stub_src/android/util/Log.java new file mode 100644 index 00000000000000..f67df58ed091c1 --- /dev/null +++ b/third_party/java_deps/stub_src/android/util/Log.java @@ -0,0 +1,39 @@ +/* + * + * 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. + */ + +/** Log.java Stub file to allow compiling standalone, without Android SDK. */ +package android.util; + +public final class Log { + public static int d(String tag, String message) { + return 0; + } + + public static int e(String tag, String msg) { + return 0; + } + + public static int e(String tag, String msg, Throwable tr) { + return 0; + } + + public static int w(String tag, String message) { + return 0; + } +}