diff --git a/examples/build_overrides/build.gni b/examples/build_overrides/build.gni index 323b150ed3399a..2d4c9ebbd14760 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 = true } diff --git a/examples/java-matter-controller/BUILD.gn b/examples/java-matter-controller/BUILD.gn index 8f0d8a43a3763d..6b7bdfcdc46672 100644 --- a/examples/java-matter-controller/BUILD.gn +++ b/examples/java-matter-controller/BUILD.gn @@ -21,8 +21,8 @@ import("${chip_root}/build/chip/tools.gni") android_binary("java-matter-controller") { output_name = "java-matter-controller" - deps = [ + "${chip_root}/examples/java-matter-controller/stub_src", "${chip_root}/src/controller/java", "${chip_root}/src/setup_payload/java", "${chip_root}/third_party/java_deps:annotation", 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..585342f141f65b 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,11 @@ */ package com.matter.controller; +import chip.devicecontroller.ChipDeviceController; + public class Main { public static void main(String[] args) { + ChipDeviceController controller = new ChipDeviceController(null); System.out.println("Hello Matter Controller!"); for (String s : args) { diff --git a/examples/java-matter-controller/stub_src/BUILD.gn b/examples/java-matter-controller/stub_src/BUILD.gn new file mode 100644 index 00000000000000..07e5f02d0cfc83 --- /dev/null +++ b/examples/java-matter-controller/stub_src/BUILD.gn @@ -0,0 +1,36 @@ +# 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. + +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/annotations/Nullable.java", + "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/examples/java-matter-controller/stub_src/android/annotations/Nullable.java b/examples/java-matter-controller/stub_src/android/annotations/Nullable.java new file mode 100644 index 00000000000000..d2a5371db635bf --- /dev/null +++ b/examples/java-matter-controller/stub_src/android/annotations/Nullable.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php + * + * 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. + */ + +// Modified from AOSP + +package androidx.annotation; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.LOCAL_VARIABLE; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Denotes that a parameter, field or method return value can be null. Note: this is the + * default assumption for most Java APIs and the default assumption made by most static code + * checking tools, so usually you don't need to use this annotation; its primary use is to override + * a default wider annotation like {@link NonNullByDefault}. + * + *

When decorating a method call parameter, this denotes the parameter can legitimately be null + * and the method will gracefully deal with it. Typically used on optional parameters. + * + *

When decorating a method, this denotes the method might legitimately return null. + * + *

This is a marker annotation and it has no specific attributes. + */ +@Documented +@Retention(RetentionPolicy.SOURCE) +@Target({METHOD, PARAMETER, LOCAL_VARIABLE, FIELD}) +public @interface Nullable {} diff --git a/examples/java-matter-controller/stub_src/android/bluetooth/BluetoothGatt.java b/examples/java-matter-controller/stub_src/android/bluetooth/BluetoothGatt.java new file mode 100644 index 00000000000000..3eddf8dadeb443 --- /dev/null +++ b/examples/java-matter-controller/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/examples/java-matter-controller/stub_src/android/bluetooth/BluetoothGattCallback.java b/examples/java-matter-controller/stub_src/android/bluetooth/BluetoothGattCallback.java new file mode 100644 index 00000000000000..74c7f6ac42d909 --- /dev/null +++ b/examples/java-matter-controller/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/examples/java-matter-controller/stub_src/android/bluetooth/BluetoothGattCharacteristic.java b/examples/java-matter-controller/stub_src/android/bluetooth/BluetoothGattCharacteristic.java new file mode 100644 index 00000000000000..202d23fb683e59 --- /dev/null +++ b/examples/java-matter-controller/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/examples/java-matter-controller/stub_src/android/bluetooth/BluetoothGattDescriptor.java b/examples/java-matter-controller/stub_src/android/bluetooth/BluetoothGattDescriptor.java new file mode 100644 index 00000000000000..d3f7ad2b1cbbde --- /dev/null +++ b/examples/java-matter-controller/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/examples/java-matter-controller/stub_src/android/bluetooth/BluetoothGattService.java b/examples/java-matter-controller/stub_src/android/bluetooth/BluetoothGattService.java new file mode 100644 index 00000000000000..30a5f1d6c7ee99 --- /dev/null +++ b/examples/java-matter-controller/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/examples/java-matter-controller/stub_src/android/bluetooth/BluetoothProfile.java b/examples/java-matter-controller/stub_src/android/bluetooth/BluetoothProfile.java new file mode 100644 index 00000000000000..8319ea32ac7c1f --- /dev/null +++ b/examples/java-matter-controller/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/examples/java-matter-controller/stub_src/android/os/Build.java b/examples/java-matter-controller/stub_src/android/os/Build.java new file mode 100644 index 00000000000000..7f41ba7f2c0f47 --- /dev/null +++ b/examples/java-matter-controller/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/examples/java-matter-controller/stub_src/android/util/Log.java b/examples/java-matter-controller/stub_src/android/util/Log.java new file mode 100644 index 00000000000000..f67df58ed091c1 --- /dev/null +++ b/examples/java-matter-controller/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; + } +} diff --git a/src/controller/java/BUILD.gn b/src/controller/java/BUILD.gn index 69137520fad329..d9142db0af7ee6 100644 --- a/src/controller/java/BUILD.gn +++ b/src/controller/java/BUILD.gn @@ -68,7 +68,6 @@ android_library("java") { output_name = "CHIPController.jar" deps = [ - ":android", "${chip_root}/third_party/java_deps:annotation", ] @@ -122,12 +121,27 @@ android_library("java") { "zap-generated/chip/devicecontroller/ClusterWriteMapping.java", ] + if (build_java_matter_controller) { + deps += [ + "${chip_root}/examples/java-matter-controller/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" + } } diff --git a/src/setup_payload/java/BUILD.gn b/src/setup_payload/java/BUILD.gn index f2b922a2a34b2d..d4be20e6d3edff 100644 --- a/src/setup_payload/java/BUILD.gn +++ b/src/setup_payload/java/BUILD.gn @@ -36,9 +36,12 @@ android_library("java") { data_deps = [ ":jni", - "${chip_root}/build/chip/java:shared_cpplib", ] + if (!build_java_matter_controller) { + data_deps += [ "${chip_root}/build/chip/java:shared_cpplib" ] + } + sources = [ "src/chip/setuppayload/DiscoveryCapability.java", "src/chip/setuppayload/OptionalQRCodeInfo.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..fd1d0bded9a737 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 \ No newline at end of file