Skip to content

Commit 753cb9c

Browse files
add android dummy stub for java matter controller application (#23261)
1 parent 236e14e commit 753cb9c

File tree

16 files changed

+433
-11
lines changed

16 files changed

+433
-11
lines changed

examples/build_overrides/build.gni

+1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@
1515
declare_args() {
1616
# Root directory for build files.
1717
build_root = "//third_party/connectedhomeip/build"
18+
build_java_matter_controller = false
1819
}

examples/java-matter-controller/BUILD.gn

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ import("${build_root}/config/android_abi.gni")
1919
import("${chip_root}/build/chip/java/rules.gni")
2020
import("${chip_root}/build/chip/tools.gni")
2121

22+
build_java_matter_controller = true
23+
2224
android_binary("java-matter-controller") {
2325
output_name = "java-matter-controller"
24-
2526
deps = [
2627
"${chip_root}/src/controller/java",
2728
"${chip_root}/src/setup_payload/java",

examples/java-matter-controller/java/src/com/matter/controller/Main.java

+9
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,17 @@
1717
*/
1818
package com.matter.controller;
1919

20+
import chip.devicecontroller.ChipDeviceController;
21+
import chip.devicecontroller.ControllerParams;
22+
2023
public class Main {
2124
public static void main(String[] args) {
25+
ChipDeviceController controller =
26+
new ChipDeviceController(
27+
ControllerParams.newBuilder()
28+
.setUdpListenPort(0)
29+
.setControllerVendorId(0xFFF1)
30+
.build());
2231
System.out.println("Hello Matter Controller!");
2332

2433
for (String s : args) {

src/controller/java/BUILD.gn

+22-6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ import("//build_overrides/chip.gni")
1717
import("${build_root}/config/android_abi.gni")
1818
import("${chip_root}/build/chip/java/rules.gni")
1919

20+
if (defined(build_java_matter_controller)) {
21+
build_java_matter_controller = build_java_matter_controller
22+
} else {
23+
build_java_matter_controller = false
24+
}
25+
2026
shared_library("jni") {
2127
output_name = "libCHIPController"
2228

@@ -67,10 +73,7 @@ shared_library("jni") {
6773
android_library("java") {
6874
output_name = "CHIPController.jar"
6975

70-
deps = [
71-
":android",
72-
"${chip_root}/third_party/java_deps:annotation",
73-
]
76+
deps = [ "${chip_root}/third_party/java_deps:annotation" ]
7477

7578
data_deps = [
7679
":jni",
@@ -122,12 +125,25 @@ android_library("java") {
122125
"zap-generated/chip/devicecontroller/ClusterWriteMapping.java",
123126
]
124127

128+
if (build_java_matter_controller) {
129+
deps += [
130+
"${chip_root}/third_party/java_deps:json",
131+
"${chip_root}/third_party/java_deps/stub_src",
132+
]
133+
} else {
134+
deps += [ ":android" ]
135+
136+
data_deps += [ "${chip_root}/build/chip/java:shared_cpplib" ]
137+
}
138+
125139
javac_flags = [ "-Xlint:deprecation" ]
126140

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

131-
java_prebuilt("android") {
132-
jar_path = "${android_sdk_root}/platforms/android-21/android.jar"
145+
if (!build_java_matter_controller) {
146+
java_prebuilt("android") {
147+
jar_path = "${android_sdk_root}/platforms/android-21/android.jar"
148+
}
133149
}

src/setup_payload/java/BUILD.gn

+11-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ import("//build_overrides/chip.gni")
1818
import("${build_root}/config/android_abi.gni")
1919
import("${chip_root}/build/chip/java/rules.gni")
2020

21+
if (defined(build_java_matter_controller)) {
22+
build_java_matter_controller = build_java_matter_controller
23+
} else {
24+
build_java_matter_controller = false
25+
}
26+
2127
shared_library("jni") {
2228
output_name = "libSetupPayloadParser"
2329

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

37-
data_deps = [
38-
":jni",
39-
"${chip_root}/build/chip/java:shared_cpplib",
40-
]
43+
data_deps = [ ":jni" ]
44+
45+
if (!build_java_matter_controller) {
46+
data_deps += [ "${chip_root}/build/chip/java:shared_cpplib" ]
47+
}
4148

4249
sources = [
4350
"src/chip/setuppayload/DiscoveryCapability.java",

third_party/java_deps/BUILD.gn

+4
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ import("${chip_root}/build/chip/java/rules.gni")
2020
java_prebuilt("annotation") {
2121
jar_path = "artifacts/jsr305-3.0.2.jar"
2222
}
23+
24+
java_prebuilt("json") {
25+
jar_path = "artifacts/json-20220924.jar"
26+
}

third_party/java_deps/set_up_java_deps.sh

+1
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@
1818

1919
mkdir third_party/java_deps/artifacts
2020
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
21+
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright (c) 2020-2021 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
#TODO: Decouple Android Bluetooth stuff from ChipDeviceController.Java, remove dummy implemenation here.
16+
#TODO: Decouple Android Logging from from ChipDeviceController.Java, remove dummy implemenation here.
17+
18+
import("//build_overrides/build.gni")
19+
import("//build_overrides/chip.gni")
20+
import("${build_root}/config/android_abi.gni")
21+
import("${chip_root}/build/chip/java/rules.gni")
22+
23+
android_library("stub_src") {
24+
output_name = "Android.jar"
25+
26+
sources = [
27+
"android/bluetooth/BluetoothGatt.java",
28+
"android/bluetooth/BluetoothGattCallback.java",
29+
"android/bluetooth/BluetoothGattCharacteristic.java",
30+
"android/bluetooth/BluetoothGattDescriptor.java",
31+
"android/bluetooth/BluetoothGattService.java",
32+
"android/bluetooth/BluetoothProfile.java",
33+
"android/os/Build.java",
34+
"android/util/Log.java",
35+
]
36+
37+
javac_flags = [ "-Xlint:deprecation" ]
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
*
3+
* Copyright (c) 2023 Project CHIP Authors
4+
* Copyright (c) 2015-2017 Nest Labs, Inc.
5+
* All rights reserved.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
/** BluetoothGatt.java Stub file to allow compiling standalone, without Android SDK. */
21+
package android.bluetooth;
22+
23+
import java.util.List;
24+
import java.util.UUID;
25+
26+
// Stub class to allow standalone compilation without Android
27+
public final class BluetoothGatt {
28+
29+
public static final int GATT_SUCCESS = 0;
30+
31+
public void close() {}
32+
33+
public BluetoothGattService getService(UUID uuid) {
34+
return null;
35+
}
36+
37+
public List<BluetoothGattService> getServices() {
38+
return null;
39+
}
40+
41+
public boolean setCharacteristicNotification(
42+
BluetoothGattCharacteristic characteristic, boolean enable) {
43+
return false;
44+
}
45+
46+
public boolean writeCharacteristic(BluetoothGattCharacteristic characteristic) {
47+
return false;
48+
}
49+
50+
public boolean writeDescriptor(BluetoothGattDescriptor descriptor) {
51+
return false;
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
*
3+
* Copyright (c) 2023 Project CHIP Authors
4+
* Copyright (c) 2015-2017 Nest Labs, Inc.
5+
* All rights reserved.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
/** BluetoothGattCallback.java Stub file to allow compiling standalone, without Android SDK. */
21+
package android.bluetooth;
22+
23+
// Stub class to allow standalone compilation without Android
24+
public abstract class BluetoothGattCallback {
25+
public void onCharacteristicChanged(
26+
BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {}
27+
28+
public void onCharacteristicRead(
29+
BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {}
30+
31+
public void onCharacteristicWrite(
32+
BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {}
33+
34+
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {}
35+
36+
public void onDescriptorRead(
37+
BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {}
38+
39+
public void onDescriptorWrite(
40+
BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {}
41+
42+
public void onServicesDiscovered(BluetoothGatt gatt, int status) {}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
*
3+
* Copyright (c) 2023 Project CHIP Authors
4+
* Copyright (c) 2015-2017 Nest Labs, Inc.
5+
* All rights reserved.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
/**
21+
* BluetoothGattCharacteristic.java Stub file to allow compiling standalone, without Android SDK.
22+
*/
23+
package android.bluetooth;
24+
25+
import java.util.UUID;
26+
27+
// Stub class to allow standalone compilation without Android
28+
public class BluetoothGattCharacteristic {
29+
protected UUID mUuid;
30+
31+
public BluetoothGattDescriptor getDescriptor(UUID uuid) {
32+
return null;
33+
}
34+
35+
public BluetoothGattService getService() {
36+
return null;
37+
}
38+
39+
public UUID getUuid() {
40+
return mUuid;
41+
}
42+
43+
public byte[] getValue() {
44+
return null;
45+
}
46+
47+
public boolean setValue(byte[] value) {
48+
return false;
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
*
3+
* Copyright (c) 2023 Project CHIP Authors
4+
* Copyright (c) 2015-2017 Nest Labs, Inc.
5+
* All rights reserved.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
/** BluetoothGattDescriptor.java Stub file to allow compiling standalone, without Android SDK. */
21+
package android.bluetooth;
22+
23+
import java.util.UUID;
24+
25+
// Stub class to allow standalone compilation without Android
26+
public class BluetoothGattDescriptor {
27+
public static final byte[] ENABLE_NOTIFICATION_VALUE = {0x01, 0x00};
28+
29+
public static final byte[] ENABLE_INDICATION_VALUE = {0x02, 0x00};
30+
31+
public static final byte[] DISABLE_NOTIFICATION_VALUE = {0x00, 0x00};
32+
33+
protected UUID mUuid;
34+
35+
public BluetoothGattCharacteristic getCharacteristic() {
36+
return null;
37+
}
38+
39+
public UUID getUuid() {
40+
return mUuid;
41+
}
42+
43+
public byte[] getValue() {
44+
return null;
45+
}
46+
47+
public boolean setValue(byte[] value) {
48+
return true;
49+
}
50+
}

0 commit comments

Comments
 (0)