diff --git a/src/platform/android/DnssdImpl.cpp b/src/platform/android/DnssdImpl.cpp index ccfb3ce178c8a4..f17cb32a188642 100644 --- a/src/platform/android/DnssdImpl.cpp +++ b/src/platform/android/DnssdImpl.cpp @@ -41,7 +41,7 @@ jobject sResolverObject = nullptr; jobject sMdnsCallbackObject = nullptr; jmethodID sResolveMethod = nullptr; jmethodID sPublishMethod = nullptr; -jmethodID sRemoveMethod = nullptr; +jmethodID sRemoveMethod = nullptr; } // namespace // Implemention of functions declared in lib/dnssd/platform/Dnssd.h @@ -75,9 +75,12 @@ CHIP_ERROR ChipDnssdRemoveServices() return CHIP_JNI_ERROR_EXCEPTION_THROWN; } - if(jret) { + if (jret) + { return CHIP_NO_ERROR; - } else { + } + else + { return CHIP_JNI_ERROR_JAVA_ERROR; } } @@ -97,27 +100,29 @@ CHIP_ERROR ChipDnssdPublishService(const DnssdService * service) UtfString jniServiceType(env, serviceType.c_str()); jclass stringClass = env->FindClass("java/lang/String"); - jobjectArray keys = env->NewObjectArray(service->mTextEntrySize, stringClass, nullptr); + jobjectArray keys = env->NewObjectArray(service->mTextEntrySize, stringClass, nullptr); jclass arrayElemType = env->FindClass("[B"); - jobjectArray datas = env->NewObjectArray(service->mTextEntrySize, arrayElemType, nullptr); + jobjectArray datas = env->NewObjectArray(service->mTextEntrySize, arrayElemType, nullptr); - for(size_t i=0;i < service->mTextEntrySize;i++) { + for (size_t i = 0; i < service->mTextEntrySize; i++) + { UtfString jniKey(env, service->mTextEntries[i].mKey); - env->SetObjectArrayElement(keys,i,jniKey.jniValue()); + env->SetObjectArrayElement(keys, i, jniKey.jniValue()); - ByteArray jniData(env, (const jbyte *)service->mTextEntries[i].mData, service->mTextEntries[i].mDataSize); - env->SetObjectArrayElement(datas,i,jniData.jniValue()); + ByteArray jniData(env, (const jbyte *) service->mTextEntries[i].mData, service->mTextEntries[i].mDataSize); + env->SetObjectArrayElement(datas, i, jniData.jniValue()); } jobjectArray subTypes = env->NewObjectArray(service->mSubTypeSize, stringClass, nullptr); - for(size_t i=0; i< service->mSubTypeSize; i++) { + for (size_t i = 0; i < service->mSubTypeSize; i++) + { UtfString jniSubType(env, service->mSubTypes[i]); - env->SetObjectArrayElement(subTypes,i,jniSubType.jniValue()); + env->SetObjectArrayElement(subTypes, i, jniSubType.jniValue()); } - jboolean jret = env->CallBooleanMethod(sResolverObject, sPublishMethod, jniName.jniValue(), jniHostName.jniValue() - , jniServiceType.jniValue(), service->mPort, keys, datas, subTypes); + jboolean jret = env->CallBooleanMethod(sResolverObject, sPublishMethod, jniName.jniValue(), jniHostName.jniValue(), + jniServiceType.jniValue(), service->mPort, keys, datas, subTypes); env->DeleteLocalRef(keys); env->DeleteLocalRef(datas); @@ -131,9 +136,12 @@ CHIP_ERROR ChipDnssdPublishService(const DnssdService * service) return CHIP_JNI_ERROR_EXCEPTION_THROWN; } - if(jret) { + if (jret) + { return CHIP_NO_ERROR; - } else { + } + else + { return CHIP_JNI_ERROR_JAVA_ERROR; } } @@ -197,7 +205,9 @@ void InitializeWithObjects(jobject resolverObject, jobject mdnsCallbackObject) env->ExceptionClear(); } - sPublishMethod = env->GetMethodID(resolverClass, "publish", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I[Ljava/lang/String;[[B[Ljava/lang/String;)Z"); + sPublishMethod = + env->GetMethodID(resolverClass, "publish", + "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I[Ljava/lang/String;[[B[Ljava/lang/String;)Z"); if (sPublishMethod == nullptr) { ChipLogError(Discovery, "Failed to access Resolver 'publish' method"); diff --git a/src/platform/android/java/chip/platform/NsdManagerServiceResolver.java b/src/platform/android/java/chip/platform/NsdManagerServiceResolver.java index 0757b65fcbed26..3a84a3edd653d3 100644 --- a/src/platform/android/java/chip/platform/NsdManagerServiceResolver.java +++ b/src/platform/android/java/chip/platform/NsdManagerServiceResolver.java @@ -25,7 +25,6 @@ import android.os.Handler; import android.os.Looper; import android.util.Log; - import java.util.*; public class NsdManagerServiceResolver implements ServiceResolver { @@ -116,49 +115,60 @@ public void onServiceResolved(NsdServiceInfo serviceInfo) { mainThreadHandler.postDelayed(timeoutRunnable, RESOLVE_SERVICE_TIMEOUT); } - @Override - public boolean publish(String serviceName, String hostName, String type, int port, String[] textEntriesKeys, byte[][] textEntriesDatas, String[] subTypes) { - NsdServiceInfo serviceInfo = new NsdServiceInfo(); - serviceInfo.setServiceName(serviceName); - serviceInfo.setServiceType(type); - serviceInfo.setPort(port); - Log.i(TAG,"publish serviceName="+serviceName+" type="+type+" port="+port); - - NsdManager.RegistrationListener registrationListener = new NsdManager.RegistrationListener() { - @Override - public void onRegistrationFailed(NsdServiceInfo serviceInfo, int errorCode) { - Log.w(TAG, "service " + serviceInfo.getServiceName() + " onRegistrationFailed:" + errorCode); - } + @Override + public boolean publish( + String serviceName, + String hostName, + String type, + int port, + String[] textEntriesKeys, + byte[][] textEntriesDatas, + String[] subTypes) { + NsdServiceInfo serviceInfo = new NsdServiceInfo(); + serviceInfo.setServiceName(serviceName); + serviceInfo.setServiceType(type); + serviceInfo.setPort(port); + Log.i(TAG, "publish serviceName=" + serviceName + " type=" + type + " port=" + port); - @Override - public void onUnregistrationFailed(NsdServiceInfo serviceInfo, int errorCode) { - Log.w(TAG, "service " + serviceInfo.getServiceName() + " onUnregistrationFailed:" + errorCode); - } + NsdManager.RegistrationListener registrationListener = + new NsdManager.RegistrationListener() { + @Override + public void onRegistrationFailed(NsdServiceInfo serviceInfo, int errorCode) { + Log.w( + TAG, + "service " + serviceInfo.getServiceName() + " onRegistrationFailed:" + errorCode); + } - @Override - public void onServiceRegistered(NsdServiceInfo serviceInfo) { - Log.i(TAG, "service " + serviceInfo.getServiceName() + " onServiceRegistered:"); - } + @Override + public void onUnregistrationFailed(NsdServiceInfo serviceInfo, int errorCode) { + Log.w( + TAG, + "service " + serviceInfo.getServiceName() + " onUnregistrationFailed:" + errorCode); + } - @Override - public void onServiceUnregistered(NsdServiceInfo serviceInfo) { - Log.i(TAG, "service " + serviceInfo.getServiceName() + " onServiceRegistered:"); - } - }; - mRegistrationListeners.add(registrationListener); + @Override + public void onServiceRegistered(NsdServiceInfo serviceInfo) { + Log.i(TAG, "service " + serviceInfo.getServiceName() + " onServiceRegistered:"); + } - nsdManager.registerService( - serviceInfo, NsdManager.PROTOCOL_DNS_SD, registrationListener); + @Override + public void onServiceUnregistered(NsdServiceInfo serviceInfo) { + Log.i(TAG, "service " + serviceInfo.getServiceName() + " onServiceRegistered:"); + } + }; + mRegistrationListeners.add(registrationListener); - return true; - } + nsdManager.registerService(serviceInfo, NsdManager.PROTOCOL_DNS_SD, registrationListener); - @Override - public boolean remove() { - for (NsdManager.RegistrationListener l:mRegistrationListeners) { - nsdManager.unregisterService(l); - } + return true; + } - return true; + @Override + public boolean remove() { + for (NsdManager.RegistrationListener l : mRegistrationListeners) { + nsdManager.unregisterService(l); } + + return true; + } } diff --git a/src/platform/android/java/chip/platform/ServiceResolver.java b/src/platform/android/java/chip/platform/ServiceResolver.java index 4c2154176f22e6..5a34cc8ad8f57d 100644 --- a/src/platform/android/java/chip/platform/ServiceResolver.java +++ b/src/platform/android/java/chip/platform/ServiceResolver.java @@ -34,9 +34,9 @@ void resolve( /** * Publishes a service via DNS-SD. * - * Calling the function again with the same service name, type, protocol, - * interface and port but different text will update the text published. - * This function will NOT take the ownership of service->mTextEntries memory. + *
Calling the function again with the same service name, type, protocol, interface and port + * but different text will update the text published. This function will NOT take the ownership of + * service->mTextEntries memory. */ boolean publish( String serviceName, @@ -45,11 +45,8 @@ boolean publish( int port, String[] textEntriesKeys, byte[][] textEntriesDatas, - String[] subTypes - ); + String[] subTypes); - /** - * Removes or marks all services being advertised for removal. - */ + /** Removes or marks all services being advertised for removal. */ boolean remove(); }