From bf0350776c6ff626f7bdf3fbe5e150b44f04ffa6 Mon Sep 17 00:00:00 2001 From: Garfield Tan Date: Thu, 13 Jul 2017 11:14:03 -0700 Subject: [PATCH] Disable debug & verbose logging on release builds. --- app/build.gradle | 20 +++++++++++++------ app/src/main/cpp/logger/logger.h | 10 ++++++++++ .../base/DocumentCursor.java | 3 ++- .../provider/SambaDocumentsProvider.java | 9 +++++---- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index b7885c9..5f2b4e8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,12 +11,6 @@ android { versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - externalNativeBuild { - cmake { - cppFlags "" - } - } - ndk { abiFilters 'armeabi-v7a' abiFilters 'arm64-v8a' @@ -28,9 +22,23 @@ android { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + + externalNativeBuild { + cmake { + cppFlags "" + } + } + } debug { jniDebuggable true + + externalNativeBuild { + cmake { + cppFlags "-DDEBUG" + } + } + } } externalNativeBuild { diff --git a/app/src/main/cpp/logger/logger.h b/app/src/main/cpp/logger/logger.h index b16a4c7..ac2b65c 100644 --- a/app/src/main/cpp/logger/logger.h +++ b/app/src/main/cpp/logger/logger.h @@ -23,10 +23,20 @@ #define LOG(level, tag, args...) \ __android_log_print((level), (tag), args) +#ifdef DEBUG + #define LOGV(tag, args...) LOG(ANDROID_LOG_VERBOSE, tag, args) #define LOGD(tag, args...) LOG(ANDROID_LOG_DEBUG, tag, args) +#else // DEBUG + +#define LOGV(tag, args...) + +#define LOGD(tag, args...) + +#endif // DEBUG + #define LOGI(tag, args...) LOG(ANDROID_LOG_INFO, tag, args) #define LOGW(tag, args...) LOG(ANDROID_LOG_WARN, tag, args) diff --git a/app/src/main/java/com/google/android/sambadocumentsprovider/base/DocumentCursor.java b/app/src/main/java/com/google/android/sambadocumentsprovider/base/DocumentCursor.java index 8e7d3e2..b21ce0f 100644 --- a/app/src/main/java/com/google/android/sambadocumentsprovider/base/DocumentCursor.java +++ b/app/src/main/java/com/google/android/sambadocumentsprovider/base/DocumentCursor.java @@ -24,6 +24,7 @@ import android.os.AsyncTask.Status; import android.os.Bundle; import android.support.annotation.Nullable; import android.util.Log; +import com.google.android.sambadocumentsprovider.BuildConfig; /** * Use this class to avoid using {@link Cursor#setExtras(Bundle)} on API level < 23. @@ -57,7 +58,7 @@ public class DocumentCursor extends MatrixCursor { public void close() { super.close(); if (mLoadingTask != null && mLoadingTask.getStatus() != Status.FINISHED) { - Log.d(TAG, "Cursor is closed. Cancel the loading task " + mLoadingTask); + if(BuildConfig.DEBUG) Log.d(TAG, "Cursor is closed. Cancel the loading task " + mLoadingTask); // Interrupting the task is not a good choice as it's waiting for the Samba client thread // returning the result. Interrupting the task only frees the task from waiting for the // result, rather than freeing the Samba client thread doing the hard work. diff --git a/app/src/main/java/com/google/android/sambadocumentsprovider/provider/SambaDocumentsProvider.java b/app/src/main/java/com/google/android/sambadocumentsprovider/provider/SambaDocumentsProvider.java index bacb216..3713690 100644 --- a/app/src/main/java/com/google/android/sambadocumentsprovider/provider/SambaDocumentsProvider.java +++ b/app/src/main/java/com/google/android/sambadocumentsprovider/provider/SambaDocumentsProvider.java @@ -39,6 +39,7 @@ import android.provider.DocumentsProvider; import android.support.annotation.Nullable; import android.support.annotation.StringRes; import android.util.Log; +import com.google.android.sambadocumentsprovider.BuildConfig; import com.google.android.sambadocumentsprovider.R; import com.google.android.sambadocumentsprovider.SambaProviderApplication; import com.google.android.sambadocumentsprovider.ShareManager; @@ -160,7 +161,7 @@ public class SambaDocumentsProvider extends DocumentsProvider { @Override public Cursor queryRoots(String[] projection) throws FileNotFoundException { - Log.d(TAG, "Querying roots."); + if(BuildConfig.DEBUG) Log.d(TAG, "Querying roots."); projection = (projection == null) ? DEFAULT_ROOT_PROJECTION : projection; MatrixCursor cursor = new MatrixCursor(projection, mShareManager.size()); @@ -200,7 +201,7 @@ public class SambaDocumentsProvider extends DocumentsProvider { @Override public Cursor queryDocument(String documentId, String[] projection) throws FileNotFoundException { - Log.d(TAG, "Querying document: " + documentId); + if (BuildConfig.DEBUG) Log.d(TAG, "Querying document: " + documentId); projection = (projection == null) ? DEFAULT_DOCUMENT_PROJECTION : projection; final Uri uri = toUri(documentId); @@ -235,7 +236,7 @@ public class SambaDocumentsProvider extends DocumentsProvider { @Override public Cursor queryChildDocuments(String documentId, String[] projection, String sortOrder) throws FileNotFoundException { - Log.d(TAG, "Querying children documents under " + documentId); + if (BuildConfig.DEBUG) Log.d(TAG, "Querying children documents under " + documentId); projection = (projection == null) ? DEFAULT_DOCUMENT_PROJECTION : projection; final Uri uri = toUri(documentId); @@ -555,7 +556,7 @@ public class SambaDocumentsProvider extends DocumentsProvider { @Override public ParcelFileDescriptor openDocument(String documentId, String mode, CancellationSignal cancellationSignal) throws FileNotFoundException { - Log.d(TAG, "Opening document " + documentId + " with mode " + mode); + if (BuildConfig.DEBUG) Log.d(TAG, "Opening document " + documentId + " with mode " + mode); try { final String uri = toUriString(documentId);