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 19, 2022
1 parent 9f08fc1 commit 0511037
Show file tree
Hide file tree
Showing 16 changed files with 623 additions and 18 deletions.
7 changes: 0 additions & 7 deletions examples/java-matter-controller/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,16 @@ import("${chip_root}/build/chip/tools.gni")

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

deps = [
":android",
"${chip_root}/src/controller/java",
"${chip_root}/src/setup_payload/java",
"${chip_root}/third_party/android_deps:annotation",
]

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

javac_flags = [ "-Xlint:deprecation" ]
}

java_prebuilt("android") {
jar_path = "${android_sdk_root}/platforms/android-21/android.jar"
}

group("default") {
deps = [ ":java-matter-controller" ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@
*
*/
package com.matter.controller;
import chip.devicecontroller.ChipDeviceController;
import chip.devicecontroller.ControllerParams;
import chip.devicecontroller.GetConnectedDeviceCallbackJni.GetConnectedDeviceCallback;

public class Main {
public static void main(String[] args) {
ChipDeviceController controller = new ChipDeviceController(null);
String address = "127.0.0.1";
controller.pairDeviceWithAddress(1, address, 5540, 3840, 20202021, null);

System.out.println("Hello Matter Controller!");

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

build_java_matter_controller = true

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

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

ldflags = [ "-Wl,--gc-sections" ]

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

android_library("java") {
output_name = "CHIPController.jar"

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

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

sources = [
Expand Down Expand Up @@ -122,12 +122,47 @@ android_library("java") {
"zap-generated/chip/devicecontroller/ClusterWriteMapping.java",
]

if (build_java_matter_controller) {
sources += [
"stub_src/android/annotations/Nullable.java",
"stub_src/android/bluetooth/BluetoothGatt.java",
"stub_src/android/bluetooth/BluetoothGattCallback.java",
"stub_src/android/bluetooth/BluetoothGattCharacteristic.java",
"stub_src/android/bluetooth/BluetoothGattDescriptor.java",
"stub_src/android/bluetooth/BluetoothGattService.java",
"stub_src/android/bluetooth/BluetoothProfile.java",
"stub_src/android/os/Build.java",
"stub_src/android/os/Parcelable.java",
"stub_src/android/os/Parcel.java",
"stub_src/android/util/Log.java",
]
deps = [
":json",
]
}
else
{
deps = [
":android",
"${chip_root}/third_party/android_deps:annotation",
]
}

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("json") {
jar_path = "json-20220924.jar"
}
}
else
{
java_prebuilt("android") {
jar_path = "${android_sdk_root}/platforms/android-21/android.jar"
}

}
Binary file added src/controller/java/json-20220924.jar
Binary file not shown.
48 changes: 48 additions & 0 deletions src/controller/java/stub_src/android/annotations/Nullable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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.
* <b>Note</b>: 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}.
* <p/>
* 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.
* <p/>
* When decorating a method, this denotes the method might legitimately return
* null.
* <p/>
* This is a marker annotation and it has no specific attributes.
*/
@Documented
@Retention(RetentionPolicy.SOURCE)
@Target({METHOD, PARAMETER, LOCAL_VARIABLE, FIELD})
public @interface Nullable {
}
67 changes: 67 additions & 0 deletions src/controller/java/stub_src/android/bluetooth/BluetoothGatt.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
*
* 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,68 @@
/*
*
* 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,60 @@
/*
*
* 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;
}
}
Loading

0 comments on commit 0511037

Please sign in to comment.