Skip to content

Commit

Permalink
[Android] Move InitChipStack() to AndroidChipPlatform (#11647)
Browse files Browse the repository at this point in the history
* Move InitChipStack() to AndroidChipPlatform

* Restyled by clang-format

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
2 people authored and pull[bot] committed Mar 8, 2022
1 parent d98d224 commit 1507036
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
3 changes: 0 additions & 3 deletions src/app/server/java/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ CHIP_ERROR ChipAndroidAppInit(void)
err = chip::Platform::MemoryInit();
SuccessOrExit(err);

err = chip::DeviceLayer::PlatformMgr().InitChipStack();
SuccessOrExit(err);

ConfigurationMgr().LogDeviceConfig();

// Init ZCL Data Model and CHIP App Server
Expand Down
4 changes: 0 additions & 4 deletions src/controller/java/CHIPDeviceController-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,6 @@ JNI_METHOD(jlong, newDeviceController)(JNIEnv * env, jobject self)

ChipLogProgress(Controller, "newDeviceController() called");

// sSystemLayer and sInetLayer are in platform/android to share with app server
err = DeviceLayer::PlatformMgr().InitChipStack();
SuccessOrExit(err);

wrapper = AndroidDeviceControllerWrapper::AllocateNew(sJVM, self, kLocalDeviceId, &DeviceLayer::SystemLayer(),
&DeviceLayer::InetLayer(), &err);
SuccessOrExit(err);
Expand Down
6 changes: 6 additions & 0 deletions src/platform/android/AndroidChipPlatform-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ void AndroidChipPlatformJNI_OnUnload(JavaVM * jvm, void * reserved)
chip::Platform::MemoryShutdown();
}

JNI_METHOD(void, initChipStack)(JNIEnv * env, jobject self)
{
CHIP_ERROR err = chip::DeviceLayer::PlatformMgr().InitChipStack();
VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(DeviceLayer, "Error initializing CHIP stack: %s", ErrorStr(err)));
}

// for BLEManager
JNI_METHOD(void, nativeSetBLEManager)(JNIEnv *, jobject, jobject manager)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ public AndroidChipPlatform(
ConfigurationManager cfg,
ServiceResolver resolver,
ChipMdnsCallback chipMdnsCallback) {
// Order is important here: initChipStack() initializes the BLEManagerImpl, which depends on the
// BLEManager being set. setConfigurationManager() depends on the CHIP stack being initialized.
setBLEManager(ble);
initChipStack();
setKeyValueStoreManager(kvm);
setConfigurationManager(cfg);
setServiceResolver(resolver, chipMdnsCallback);
Expand Down Expand Up @@ -72,6 +75,9 @@ public native void handleUnsubscribeComplete(
// for ConfigurationManager
private native void setConfigurationManager(ConfigurationManager manager);

/** Initialize the CHIP stack. */
private native void initChipStack();

// for ServiceResolver
private void setServiceResolver(ServiceResolver resolver, ChipMdnsCallback chipMdnsCallback) {
if (resolver != null) {
Expand Down

0 comments on commit 1507036

Please sign in to comment.