Skip to content

Commit 0511037

Browse files
add android dummy stub for java matter controller application
1 parent 9f08fc1 commit 0511037

File tree

16 files changed

+623
-18
lines changed

16 files changed

+623
-18
lines changed

examples/java-matter-controller/BUILD.gn

-7
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,16 @@ import("${chip_root}/build/chip/tools.gni")
2121

2222
android_binary("java-matter-controller") {
2323
output_name = "java-matter-controller"
24-
2524
deps = [
26-
":android",
2725
"${chip_root}/src/controller/java",
2826
"${chip_root}/src/setup_payload/java",
29-
"${chip_root}/third_party/android_deps:annotation",
3027
]
3128

3229
sources = [ "java/src/com/matter/controller/Main.java" ]
3330

3431
javac_flags = [ "-Xlint:deprecation" ]
3532
}
3633

37-
java_prebuilt("android") {
38-
jar_path = "${android_sdk_root}/platforms/android-21/android.jar"
39-
}
40-
4134
group("default") {
4235
deps = [ ":java-matter-controller" ]
4336
}

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

+7
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,16 @@
1616
*
1717
*/
1818
package com.matter.controller;
19+
import chip.devicecontroller.ChipDeviceController;
20+
import chip.devicecontroller.ControllerParams;
21+
import chip.devicecontroller.GetConnectedDeviceCallbackJni.GetConnectedDeviceCallback;
1922

2023
public class Main {
2124
public static void main(String[] args) {
25+
ChipDeviceController controller = new ChipDeviceController(null);
26+
String address = "127.0.0.1";
27+
controller.pairDeviceWithAddress(1, address, 5540, 3840, 20202021, null);
28+
2229
System.out.println("Hello Matter Controller!");
2330

2431
for (String s : args) {

src/controller/java/BUILD.gn

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

20+
build_java_matter_controller = true
21+
2022
shared_library("jni") {
2123
output_name = "libCHIPController"
2224

@@ -62,19 +64,17 @@ shared_library("jni") {
6264
output_dir = "${root_out_dir}/lib/jni/${android_abi}"
6365

6466
ldflags = [ "-Wl,--gc-sections" ]
67+
68+
data_deps = [
69+
"${chip_root}/build/chip/java:shared_cpplib",
70+
]
6571
}
6672

6773
android_library("java") {
6874
output_name = "CHIPController.jar"
6975

70-
deps = [
71-
":android",
72-
"${chip_root}/third_party/android_deps:annotation",
73-
]
74-
7576
data_deps = [
7677
":jni",
77-
"${chip_root}/build/chip/java:shared_cpplib",
7878
]
7979

8080
sources = [
@@ -122,12 +122,47 @@ android_library("java") {
122122
"zap-generated/chip/devicecontroller/ClusterWriteMapping.java",
123123
]
124124

125+
if (build_java_matter_controller) {
126+
sources += [
127+
"stub_src/android/annotations/Nullable.java",
128+
"stub_src/android/bluetooth/BluetoothGatt.java",
129+
"stub_src/android/bluetooth/BluetoothGattCallback.java",
130+
"stub_src/android/bluetooth/BluetoothGattCharacteristic.java",
131+
"stub_src/android/bluetooth/BluetoothGattDescriptor.java",
132+
"stub_src/android/bluetooth/BluetoothGattService.java",
133+
"stub_src/android/bluetooth/BluetoothProfile.java",
134+
"stub_src/android/os/Build.java",
135+
"stub_src/android/os/Parcelable.java",
136+
"stub_src/android/os/Parcel.java",
137+
"stub_src/android/util/Log.java",
138+
]
139+
deps = [
140+
":json",
141+
]
142+
}
143+
else
144+
{
145+
deps = [
146+
":android",
147+
"${chip_root}/third_party/android_deps:annotation",
148+
]
149+
}
150+
125151
javac_flags = [ "-Xlint:deprecation" ]
126152

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

131-
java_prebuilt("android") {
132-
jar_path = "${android_sdk_root}/platforms/android-21/android.jar"
157+
if (build_java_matter_controller) {
158+
java_prebuilt("json") {
159+
jar_path = "json-20220924.jar"
160+
}
161+
}
162+
else
163+
{
164+
java_prebuilt("android") {
165+
jar_path = "${android_sdk_root}/platforms/android-21/android.jar"
166+
}
167+
133168
}

src/controller/java/json-20220924.jar

68.7 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (C) 2010 The Android Open Source Project
3+
*
4+
* Licensed under the Eclipse Public License, Version 1.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.eclipse.org/org/documents/epl-v10.php
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
//Modified from AOSP
18+
19+
package androidx.annotation;
20+
import static java.lang.annotation.ElementType.FIELD;
21+
import static java.lang.annotation.ElementType.LOCAL_VARIABLE;
22+
import static java.lang.annotation.ElementType.METHOD;
23+
import static java.lang.annotation.ElementType.PARAMETER;
24+
import java.lang.annotation.Documented;
25+
import java.lang.annotation.Retention;
26+
import java.lang.annotation.RetentionPolicy;
27+
import java.lang.annotation.Target;
28+
/**
29+
* Denotes that a parameter, field or method return value can be null.
30+
* <b>Note</b>: this is the default assumption for most Java APIs and the
31+
* default assumption made by most static code checking tools, so usually you
32+
* don't need to use this annotation; its primary use is to override a default
33+
* wider annotation like {@link NonNullByDefault}.
34+
* <p/>
35+
* When decorating a method call parameter, this denotes the parameter can
36+
* legitimately be null and the method will gracefully deal with it. Typically
37+
* used on optional parameters.
38+
* <p/>
39+
* When decorating a method, this denotes the method might legitimately return
40+
* null.
41+
* <p/>
42+
* This is a marker annotation and it has no specific attributes.
43+
*/
44+
@Documented
45+
@Retention(RetentionPolicy.SOURCE)
46+
@Target({METHOD, PARAMETER, LOCAL_VARIABLE, FIELD})
47+
public @interface Nullable {
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
* BluetoothGatt.java
22+
* Stub file to allow compiling standalone, without Android SDK.
23+
*
24+
*/
25+
26+
package android.bluetooth;
27+
28+
import java.util.List;
29+
import java.util.UUID;
30+
31+
32+
// Stub class to allow standalone compilation without Android
33+
public final class BluetoothGatt
34+
{
35+
36+
public static final int GATT_SUCCESS = 0;
37+
38+
public void close()
39+
{
40+
}
41+
42+
public BluetoothGattService getService(UUID uuid)
43+
{
44+
return null;
45+
}
46+
47+
public List<BluetoothGattService> getServices()
48+
{
49+
return null;
50+
}
51+
52+
public boolean setCharacteristicNotification(BluetoothGattCharacteristic characteristic,
53+
boolean enable)
54+
{
55+
return false;
56+
}
57+
58+
public boolean writeCharacteristic(BluetoothGattCharacteristic characteristic)
59+
{
60+
return false;
61+
}
62+
63+
public boolean writeDescriptor(BluetoothGattDescriptor descriptor)
64+
{
65+
return false;
66+
}
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
* BluetoothGattCallback.java
22+
* Stub file to allow compiling standalone, without Android SDK.
23+
*
24+
*/
25+
26+
package android.bluetooth;
27+
28+
29+
// Stub class to allow standalone compilation without Android
30+
public abstract class BluetoothGattCallback
31+
{
32+
public void onCharacteristicChanged(BluetoothGatt gatt,
33+
BluetoothGattCharacteristic characteristic)
34+
{
35+
}
36+
37+
public void onCharacteristicRead(BluetoothGatt gatt,
38+
BluetoothGattCharacteristic characteristic,
39+
int status)
40+
{
41+
}
42+
43+
public void onCharacteristicWrite(BluetoothGatt gatt,
44+
BluetoothGattCharacteristic characteristic,
45+
int status)
46+
{
47+
}
48+
49+
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState)
50+
{
51+
}
52+
53+
public void onDescriptorRead(BluetoothGatt gatt,
54+
BluetoothGattDescriptor descriptor,
55+
int status)
56+
{
57+
}
58+
59+
public void onDescriptorWrite(BluetoothGatt gatt,
60+
BluetoothGattDescriptor descriptor,
61+
int status)
62+
{
63+
}
64+
65+
public void onServicesDiscovered(BluetoothGatt gatt, int status)
66+
{
67+
}
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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
22+
* Stub file to allow compiling standalone, without Android SDK.
23+
*
24+
*/
25+
26+
package android.bluetooth;
27+
28+
import java.util.UUID;
29+
30+
31+
// Stub class to allow standalone compilation without Android
32+
public class BluetoothGattCharacteristic
33+
{
34+
protected UUID mUuid;
35+
36+
public BluetoothGattDescriptor getDescriptor(UUID uuid)
37+
{
38+
return null;
39+
}
40+
41+
public BluetoothGattService getService()
42+
{
43+
return null;
44+
}
45+
46+
public UUID getUuid()
47+
{
48+
return mUuid;
49+
}
50+
51+
public byte[] getValue()
52+
{
53+
return null;
54+
}
55+
56+
public boolean setValue(byte[] value)
57+
{
58+
return false;
59+
}
60+
}

0 commit comments

Comments
 (0)