Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the AndroidChipLogging #34899

Merged
merged 3 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/platform/android/AndroidChipPlatform-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@
#include <lib/support/CodeUtils.h>
#include <lib/support/JniReferences.h>
#include <lib/support/JniTypeWrappers.h>
#include <lib/support/logging/CHIPLogging.h>
#include <platform/CHIPDeviceConfig.h>
#include <platform/ConfigurationManager.h>
#include <platform/ConnectivityManager.h>
#include <platform/KeyValueStoreManager.h>
#include <platform/internal/BLEManager.h>

#include <android/log.h>

#include "AndroidChipPlatform-JNI.h"
#include "BLEManagerImpl.h"
#include "BleConnectCallback-JNI.h"
Expand All @@ -45,6 +48,8 @@
using namespace chip;

#define JNI_METHOD(RETURN, METHOD_NAME) extern "C" JNIEXPORT RETURN JNICALL Java_chip_platform_AndroidChipPlatform_##METHOD_NAME
#define JNI_LOGGING_METHOD(RETURN, METHOD_NAME) \
extern "C" JNIEXPORT RETURN JNICALL Java_chip_platform_AndroidChipLogging_##METHOD_NAME
#define JNI_MDNSCALLBACK_METHOD(RETURN, METHOD_NAME) \
extern "C" JNIEXPORT RETURN JNICALL Java_chip_platform_ChipMdnsCallbackImpl_##METHOD_NAME

Expand Down Expand Up @@ -245,6 +250,30 @@ JNI_METHOD(void, nativeSetDnssdDelegates)(JNIEnv * env, jclass self, jobject res
chip::Dnssd::InitializeWithObjects(resolver, browser, chipMdnsCallback);
}

JNI_LOGGING_METHOD(void, setLogFilter)(JNIEnv * env, jclass clazz, jint level)
{
using namespace chip::Logging;

uint8_t category = kLogCategory_Detail;
switch (level)
{
case ANDROID_LOG_VERBOSE:
case ANDROID_LOG_DEBUG:
category = kLogCategory_Detail;
break;
case ANDROID_LOG_INFO:
category = kLogCategory_Progress;
break;
case ANDROID_LOG_WARN:
case ANDROID_LOG_ERROR:
category = kLogCategory_Error;
break;
default:
break;
}
SetLogFilter(category);
}

JNI_MDNSCALLBACK_METHOD(void, handleServiceResolve)
(JNIEnv * env, jclass self, jstring instanceName, jstring serviceType, jstring hostName, jstring address, jint port,
jobject attributes, jlong callbackHandle, jlong contextHandle)
Expand Down
1 change: 1 addition & 0 deletions src/platform/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ android_library("java") {

sources = [
"java/chip/platform/AndroidBleManager.java",
"java/chip/platform/AndroidChipLogging.java",
"java/chip/platform/AndroidChipPlatform.java",
"java/chip/platform/AndroidChipPlatformException.java",
"java/chip/platform/BleCallback.java",
Expand Down
2 changes: 1 addition & 1 deletion src/platform/android/CHIPPlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ using CHIP_CONFIG_PERSISTED_STORAGE_KEY_TYPE = const char *;
#endif // CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS

#ifndef CHIP_LOG_FILTERING
#define CHIP_LOG_FILTERING 0
#define CHIP_LOG_FILTERING 1
#endif // CHIP_LOG_FILTERING

#ifndef CHIP_CONFIG_BDX_MAX_NUM_TRANSFERS
Expand Down
16 changes: 15 additions & 1 deletion src/platform/android/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,21 @@ namespace Platform {

void LogV(const char * module, uint8_t category, const char * msg, va_list v)
{
int priority = (category == kLogCategory_Error) ? ANDROID_LOG_ERROR : ANDROID_LOG_DEBUG;
int priority = ANDROID_LOG_DEBUG;
switch (category)
{
case kLogCategory_Error:
priority = ANDROID_LOG_ERROR;
break;
case kLogCategory_Progress:
priority = ANDROID_LOG_INFO;
break;
case kLogCategory_Detail:
priority = ANDROID_LOG_DEBUG;
break;
default:
break;
}
__android_log_vprint(priority, module, msg, v);
}

Expand Down
23 changes: 23 additions & 0 deletions src/platform/android/java/chip/platform/AndroidChipLogging.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2024 Project CHIP Authors
* 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.
*
*/
package chip.platform;

public class AndroidChipLogging {
// logging level is in android.util.Log class
public static native void setLogFilter(int level);
}
Loading