Skip to content

Commit

Permalink
Fix android icd checkin message
Browse files Browse the repository at this point in the history
  • Loading branch information
joonhaengHeo committed May 22, 2024
1 parent 6bd80b0 commit 834f8e2
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,16 @@ class CHIPToolActivity :
}
}

override fun onResume() {
super.onResume()
ChipClient.startDnssd()
}

override fun onPause() {
ChipClient.stopDnssd()
super.onPause()
}

companion object {
private const val TAG = "CHIPToolActivity"
private const val ADDRESS_COMMISSIONING_FRAGMENT_TAG = "address_commissioning_fragment"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@ object ChipClient {
icdCheckInCallback = callback
}

fun startDnssd() {
if (this::chipDeviceController.isInitialized) {
chipDeviceController.startDnssd()
}
}

fun stopDnssd() {
if (this::chipDeviceController.isInitialized) {
chipDeviceController.stopDnssd()
}
}

/**
* Wrapper around [ChipDeviceController.getConnectedDevicePointer] to return the value directly.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ class AddressUpdateFragment : ICDCheckInCallback, Fragment() {
val runnable =
object : Runnable {
override fun run() {
if (!isAdded) {
Log.d(TAG, "Fragment is not attached")
return
}
if (icdTotalRemainStayActiveTimeMs >= ICD_PROGRESS_STEP) {
icdDeviceRemainStayActiveTimeMs -= ICD_PROGRESS_STEP
icdTotalRemainStayActiveTimeMs -= ICD_PROGRESS_STEP
Expand Down
4 changes: 3 additions & 1 deletion src/app/server/Dnssd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,9 @@ void DnssdServer::StartServer()
void DnssdServer::StopServer()
{
// Make sure we don't hold on to a dangling fabric table pointer.
mFabricTable = nullptr;

// Joonhaeng Heo, How to solve..................
//mFabricTable = nullptr;

DeviceLayer::PlatformMgr().RemoveEventHandler(OnPlatformEventWrapper, 0);

Expand Down
15 changes: 15 additions & 0 deletions src/controller/java/CHIPDeviceController-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <app/InteractionModelEngine.h>
#include <app/ReadClient.h>
#include <app/WriteClient.h>
#include <app/server/Dnssd.h>
#include <atomic>
#include <ble/Ble.h>
#include <controller/CHIPDeviceController.h>
Expand Down Expand Up @@ -2154,6 +2155,20 @@ JNI_METHOD(jbyteArray, validateAndExtractCSR)(JNIEnv * env, jclass clazz, jbyteA
return javaCsr;
}

JNI_METHOD(void, startDnssd)(JNIEnv * env, jobject self, jlong devicePtr)
{
ChipLogProgress(Controller, "startDnssd() called");
chip::DeviceLayer::StackLock lock;
chip::app::DnssdServer::Instance().StartServer();
}

JNI_METHOD(void, stopDnssd)(JNIEnv * env, jobject self, jlong devicePtr)
{
ChipLogProgress(Controller, "stopDnssd() called");
chip::DeviceLayer::StackLock lock;
chip::app::DnssdServer::Instance().StopServer();
}

void * IOThreadMain(void * arg)
{
JNIEnv * env;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,14 @@ public byte[] getAttestationChallenge(long devicePtr) {
return getAttestationChallenge(deviceControllerPtr, devicePtr);
}

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

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

/**
* @brief Auto-Resubscribe to the given attribute path with keepSubscriptions and isFabricFiltered
* @param SubscriptionEstablishedCallback Callback when a subscribe response has been received and
Expand Down Expand Up @@ -1587,6 +1595,10 @@ private native void updateCommissioningICDRegistrationInfo(

private native void shutdownCommissioning(long deviceControllerPtr);

private native void startDnssd(long deviceControllerPtr);

private native void stopDnssd(long deviceControllerPtr);

static {
System.loadLibrary("CHIPController");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class NsdManagerServiceResolver implements ServiceResolver {
private static final long RESOLVE_SERVICE_TIMEOUT = 30000;
private final NsdManager nsdManager;
private MulticastLock multicastLock;
private MulticastLock publishMulticastLock;
private List<NsdManager.RegistrationListener> registrationListeners = new ArrayList<>();
private final CopyOnWriteArrayList<String> mMFServiceName = new CopyOnWriteArrayList<>();
@Nullable private final NsdManagerResolverAvailState nsdManagerResolverAvailState;
Expand All @@ -60,6 +61,12 @@ public NsdManagerServiceResolver(
((WifiManager) context.getSystemService(Context.WIFI_SERVICE))
.createMulticastLock("chipMulticastLock");
this.multicastLock.setReferenceCounted(true);

this.publishMulticastLock =
((WifiManager) context.getSystemService(Context.WIFI_SERVICE))
.createMulticastLock("chipPublishMulticastLock");
this.publishMulticastLock.setReferenceCounted(true);

this.nsdManagerResolverAvailState = nsdManagerResolverAvailState;
this.timeout = timeout;
}
Expand Down Expand Up @@ -204,7 +211,7 @@ public void onServiceUnregistered(NsdServiceInfo serviceInfo) {
}
};
if (registrationListeners.size() == 0) {
multicastLock.acquire();
publishMulticastLock.acquire();
}
registrationListeners.add(registrationListener);
mMFServiceName.add(serviceName);
Expand All @@ -216,8 +223,8 @@ public void onServiceUnregistered(NsdServiceInfo serviceInfo) {
@Override
public void removeServices() {
Log.d(TAG, "removeServices: ");
if (registrationListeners.size() > 0) {
multicastLock.release();
if (registrationListeners.size() > 0 && publishMulticastLock.isHeld()) {
publishMulticastLock.release();
}
for (NsdManager.RegistrationListener l : registrationListeners) {
Log.i(TAG, "Remove " + l);
Expand Down

0 comments on commit 834f8e2

Please sign in to comment.