Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sharadb-amazon committed Apr 11, 2024
1 parent d172c24 commit f841c6b
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 123 deletions.
2 changes: 2 additions & 0 deletions examples/tv-casting-app/android/App/app/libs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This directory will contain any .jar files required by the TV Casting demo app
for Android.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import android.content.Context;
import android.util.Log;
import chip.appserver.ChipAppServer;
import chip.devicecontroller.ChipInteractionClient;
import chip.platform.AndroidBleManager;
import chip.platform.AndroidChipPlatform;
import chip.platform.ChipMdnsCallbackImpl;
Expand Down Expand Up @@ -48,8 +47,7 @@ public final class CastingApp {
private NsdManagerServiceResolver.NsdManagerResolverAvailState nsdManagerResolverAvailState;
private ChipAppServer chipAppServer;

private CastingApp() { // ChipInteractionClient.loadJni();
}
private CastingApp() {}

public static CastingApp getInstance() {
if (sInstance == null) {
Expand Down Expand Up @@ -103,7 +101,6 @@ public MatterError initialize(AppParameters appParameters) {

if (err.hasNoError()) {
chipAppServer = new ChipAppServer(); // get a reference to the Matter server now
ChipInteractionClient.loadJni();
mState = CastingAppState.NOT_RUNNING; // initialization done, set state to NOT_RUNNING
}
return err;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,14 @@ TvCastingAppJNI TvCastingAppJNI::sInstance;
jint JNI_OnLoad(JavaVM * jvm, void * reserved)
{
jint ret = AndroidAppServerJNI_OnLoad(jvm, reserved);
if (ret != JNI_VERSION_1_6)
{
return ret;
}

VerifyOrReturnValue(ret != JNI_ERR, ret);
return AndroidChipInteractionJNI_OnLoad(jvm, reserved);
}

void JNI_OnUnload(JavaVM * jvm, void * reserved)
{
return AndroidAppServerJNI_OnUnload(jvm, reserved);
AndroidChipInteractionJNI_OnUnload(jvm, reserved);
AndroidAppServerJNI_OnUnload(jvm, reserved);
}

JNI_METHOD(jboolean, preInitJni)(JNIEnv *, jobject, jobject jAppParameters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ class MatterCallbackJNI
ChipLogProgress(AppServer, "MatterCallbackJNI::SetUp called");
VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NO_ENV, ChipLogError(AppServer, "JNIEnv was null!"));

mCallbackObject.Reset();
if (mCallbackObject.HasValidObjectRef())
{
mCallbackObject.Reset();
}
ReturnErrorOnFailure(mCallbackObject.Init(inCallback));

jclass mClazz = env->GetObjectClass(mCallbackObject.ObjectRef());
Expand Down
7 changes: 2 additions & 5 deletions examples/tv-casting-app/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ shared_library("jni") {
"${chip_root}/examples/tv-casting-app/tv-casting-common",
"${chip_root}/src/app/data-model:heap",
"${chip_root}/src/app/server/java:jni",
"${chip_root}/src/controller/java:android_chip_im_jni_src",
"${chip_root}/src/controller/java:android_chip_im_jni",
"${chip_root}/src/lib",
"${chip_root}/third_party/inipp",
]
Expand Down Expand Up @@ -122,10 +122,7 @@ android_library("java") {
"App/app/src/main/jni/com/matter/casting/support/MatterError.java",
]

javac_flags = [
"-Xlint:deprecation",
"-parameters", # Store infomation about method parameters
]
javac_flags = [ "-Xlint:deprecation" ]

# TODO: add classpath support (we likely need to add something like
# ..../platforms/android-26/android.jar to access BLE items)
Expand Down
10 changes: 4 additions & 6 deletions scripts/build/builders/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ def copyToSrcAndroid(self):

jars = {
"CHIPController.jar": "src/controller/java/CHIPController.jar",
"CHIPInteractionModel.jar": "src/controller/java/CHIPInteractionModel.jar",
"OnboardingPayload.jar": "src/controller/java/OnboardingPayload.jar",
"AndroidPlatform.jar": "src/platform/android/AndroidPlatform.jar",
"libMatterJson.jar": "src/controller/java/libMatterJson.jar",
Expand Down Expand Up @@ -587,12 +588,6 @@ def build_outputs(self):
self.output_dir, "content-app", "outputs", "apk", "debug", "content-app-debug.apk"
)
}
elif self.app == AndroidApp.TV_CASTING_APP:
outputs = {
self.app.AppName() + "app-debug.apk": os.path.join(
self.output_dir, "tv-casting-app", "app", "outputs", "apk", "debug", "app-debug.apk"
),
}
elif self.app == AndroidApp.VIRTUAL_DEVICE_APP:
outputs = {
self.app.AppName() + "app-debug.apk": os.path.join(
Expand All @@ -613,6 +608,9 @@ def build_outputs(self):
"CHIPController.jar": os.path.join(
self.output_dir, "lib", "src/controller/java/CHIPController.jar"
),
"CHIPInteractionModel.jar": os.path.join(
self.output_dir, "lib", "src/controller/java/CHIPInteractionModel.jar"
),
"libMatterTlv.jar": os.path.join(
self.output_dir, "lib", "src/controller/java/libMatterTlv.jar"
),
Expand Down
72 changes: 6 additions & 66 deletions src/controller/java/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ if (!matter_enable_java_compilation) {
import("${build_root}/config/android_abi.gni")
}

source_set("android_chip_im_jni_src") {
output_name = "libCHIPInteractionModel"

source_set("android_chip_im_jni") {
sources = [
"AndroidCallbacks-JNI.cpp",
"AndroidCallbacks.cpp",
Expand All @@ -71,68 +69,10 @@ source_set("android_chip_im_jni_src") {
]
}

public_deps = [
"${chip_root}/src/app/data-model:heap",
"${chip_root}/src/app/server/java:jni",
"${chip_root}/src/lib",
"${chip_root}/src/lib/support/jsontlv",
"${chip_root}/third_party/inipp",
]
}

static_library("android_chip_im_jni") {
output_name = "libCHIPInteractionModel"

public_deps = [
"${chip_root}/src/app/data-model:heap",
"${chip_root}/src/app/server/java:jni",
deps = [
"${chip_root}/src/lib",
"${chip_root}/src/lib/support/jsontlv",
"${chip_root}/third_party/inipp",
]

deps = [ ":android_chip_im_jni_src" ]

if (chip_build_controller_dynamic_server) {
defines += [ "CHIP_CONFIG_SKIP_APP_SPECIFIC_GENERATED_HEADER_INCLUDES=1" ]

deps += [ "${chip_root}/src/controller:nodatamodel" ]
} else {
#deps += [ "${chip_root}/src/controller/data_model" ]
}

if (matter_enable_java_compilation) {
defines += [ "JAVA_MATTER_CONTROLLER_TEST" ]

include_dirs = java_matter_controller_dependent_paths
include_dirs += [ "${chip_root}/zzz_generated/controller-clusters" ]

deps += [ "${chip_root}/third_party/inipp" ]

if (current_os == "mac") {
deps += [ "${chip_root}/src/platform/Darwin" ]
} else {
deps += [ "${chip_root}/src/platform/Linux" ]
}

cflags = [
"-Wno-unknown-pragmas",
"-Wconversion",
]

#output_dir = "${root_out_dir}/lib/jni"
} else {
deps += [ "${chip_root}/src/platform/android" ]
#output_dir = "${root_out_dir}/lib/jni/${android_abi}"
}

if (current_os == "mac") {
ldflags = [ "-Wl,-dead_strip" ]
} else {
ldflags = [ "-Wl,--gc-sections" ]
}

public_configs = [ "${chip_root}/src:includes" ]
}

shared_library("jni") {
Expand Down Expand Up @@ -173,7 +113,7 @@ shared_library("jni") {
]

deps = [
":android_chip_im",
":android_chip_im_jni",
":controller_config",
"${chip_root}/src/app/icd/client:handler",
"${chip_root}/src/app/icd/client:manager",
Expand Down Expand Up @@ -534,12 +474,13 @@ android_library("chipclusterID") {
]
}

# Android CHIP IM .java files
android_library("android_chip_im") {
output_name = "CHIPInteractionModel.jar"

# Android CHIP IM .java files
sources = [
"${chip_root}/src/controller/java/src/chip/devicecontroller/ChipClusterException.java",
"${chip_root}/src/controller/java/src/chip/devicecontroller/ChipDeviceControllerException.java",
"${chip_root}/src/controller/java/src/chip/devicecontroller/ChipInteractionClient.java",
"${chip_root}/src/controller/java/src/chip/devicecontroller/ExtendableInvokeCallback.java",
"${chip_root}/src/controller/java/src/chip/devicecontroller/ExtendableInvokeCallbackJni.java",
Expand Down Expand Up @@ -608,8 +549,6 @@ android_library("android_chip_im") {
data_deps = [ "${chip_root}/build/chip/java:shared_cpplib" ]
}

data_deps += [ ":android_chip_im_jni" ]

javac_flags = [
"-Xlint:deprecation",
"-parameters", # Store infomation about method parameters
Expand All @@ -620,6 +559,7 @@ android_library("java") {
output_name = "CHIPController.jar"

deps = [
":android_chip_im",
":chipcluster",
":chipclusterID",
"${chip_root}/third_party/java_deps:annotation",
Expand Down
39 changes: 20 additions & 19 deletions src/controller/java/CHIPInteractionClient-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,20 @@
*/
#include "CHIPInteractionClient-JNI.h"
#include "AndroidInteractionClient.h"

#include <lib/support/CHIPJNIError.h>
#include <lib/support/CHIPMem.h>
#include <platform/CHIPDeviceLayer.h>

#define JNI_METHOD(RETURN, METHOD_NAME) \
extern "C" JNIEXPORT RETURN JNICALL Java_chip_devicecontroller_ChipInteractionClient_##METHOD_NAME

/*jint JNI_OnLoad(JavaVM * jvm, void * reserved)
{
return JNI_VERSION_1_6;
//return AndroidChipInteractionJNI_OnLoad(jvm, reserved);
}*/

jint AndroidChipInteractionJNI_OnLoad(JavaVM * jvm, void * reserved)
{
CHIP_ERROR err = CHIP_NO_ERROR;
JNIEnv * env;

ChipLogProgress(Controller, "ChipInteractionClient JNI_OnLoad() called");
ChipLogProgress(Controller, "AndroidChipInteractionJNI_OnLoad called");

chip::Platform::MemoryInit();

Expand All @@ -42,33 +39,37 @@ jint AndroidChipInteractionJNI_OnLoad(JavaVM * jvm, void * reserved)

// Get a JNI environment object.
env = chip::JniReferences::GetInstance().GetEnvForCurrentThread();
// temporarily commented out
// VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV);
// VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV);
VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV);
VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV);

ChipLogProgress(Controller, "ChipInteractionClient Loading Java class references.");
ChipLogProgress(Controller, "Loading Java class references.");

// Get various class references need by the API.
jclass controllerExceptionCls;
err = chip::JniReferences::GetInstance().GetLocalClassRef(env, "chip/devicecontroller/ChipClusterException",
err = chip::JniReferences::GetInstance().GetLocalClassRef(env, "chip/devicecontroller/ChipDeviceControllerException",
controllerExceptionCls);
// temporarily commented out
// SuccessOrExit(err = sChipDeviceControllerExceptionCls.Init(controllerExceptionCls));
VerifyOrReturnValue(err == CHIP_NO_ERROR, JNI_ERR);

ChipLogProgress(Controller, "ChipInteractionClient Java class references loaded.");
ChipLogProgress(Controller, "Java class references loaded.");

exit:
if (err != CHIP_NO_ERROR)
{
// temporarily commented out
// JniReferences::GetInstance().ThrowError(env, sChipDeviceControllerExceptionCls, err);
// chip::DeviceLayer::StackUnlock unlock;
// JNI_OnUnload(jvm, reserved);
chip::JniReferences::GetInstance().ThrowError(env, controllerExceptionCls, err);
chip::DeviceLayer::StackUnlock unlock;
JNI_OnUnload(jvm, reserved);
}

return (err == CHIP_NO_ERROR) ? JNI_VERSION_1_6 : JNI_ERR;
}

void AndroidChipInteractionJNI_OnUnload(JavaVM * jvm, void * reserved)
{
chip::DeviceLayer::StackLock lock;
ChipLogProgress(AppServer, "AndroidChipInteractionJNI_OnUnload() called");
chip::Platform::MemoryShutdown();
}

JNI_METHOD(void, subscribe)
(JNIEnv * env, jobject self, jlong handle, jlong callbackHandle, jlong devicePtr, jobject attributePathList, jobject eventPathList,
jint minInterval, jint maxInterval, jboolean keepSubscriptions, jboolean isFabricFiltered, jint imTimeoutMs)
Expand Down
4 changes: 3 additions & 1 deletion src/controller/java/CHIPInteractionClient-JNI.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2021 Project CHIP Authors
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -20,3 +20,5 @@
#include <jni.h>

jint AndroidChipInteractionJNI_OnLoad(JavaVM * jvm, void * reserved);

void AndroidChipInteractionJNI_OnUnload(JavaVM * jvm, void * reserved);
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,15 @@ public PaseVerifierParams computePaseVerifier(
return computePaseVerifier(deviceControllerPtr, devicePtr, setupPincode, iterations, salt);
}

public void shutdownCommissioning() {
shutdownCommissioning(deviceControllerPtr);
}

public static native byte[] validateAndExtractCSR(byte[] csrElements, byte[] csrNonce);

private native PaseVerifierParams computePaseVerifier(
long deviceControllerPtr, long devicePtr, long setupPincode, long iterations, byte[] salt);

static native void subscribe(
long deviceControllerPtr,
long callbackHandle,
Expand Down Expand Up @@ -1418,15 +1427,6 @@ static native void extendableInvoke(
int timedRequestTimeoutMs,
int imTimeoutMs);

public void shutdownCommissioning() {
shutdownCommissioning(deviceControllerPtr);
}

public static native byte[] validateAndExtractCSR(byte[] csrElements, byte[] csrNonce);

private native PaseVerifierParams computePaseVerifier(
long deviceControllerPtr, long devicePtr, long setupPincode, long iterations, byte[] salt);

private native long newDeviceController(ControllerParams params);

private native void setDeviceAttestationDelegate(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
*
* Copyright (c) 2024 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.
*/
package chip.devicecontroller;

import chip.devicecontroller.model.AttributeWriteRequest;
Expand Down Expand Up @@ -61,10 +77,4 @@ static native void extendableInvoke(
public static void loadJni() {
System.out.println("ChipInteractionClient loadJni called");
}

/*static {
System.out.println("Loading CHIPInteractionModel");
System.loadLibrary("CHIPInteractionModel");
System.out.println("Loading CHIPInteractionModel done");
}*/
}

0 comments on commit f841c6b

Please sign in to comment.