Disable debug & verbose logging on release builds.

This commit is contained in:
Garfield Tan 2017-07-13 11:14:03 -07:00
parent 54096c3249
commit bf0350776c
4 changed files with 31 additions and 11 deletions

View file

@ -11,12 +11,6 @@ android {
versionName "1.0" versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
}
}
ndk { ndk {
abiFilters 'armeabi-v7a' abiFilters 'armeabi-v7a'
abiFilters 'arm64-v8a' abiFilters 'arm64-v8a'
@ -28,9 +22,23 @@ android {
release { release {
minifyEnabled false minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
externalNativeBuild {
cmake {
cppFlags ""
}
}
} }
debug { debug {
jniDebuggable true jniDebuggable true
externalNativeBuild {
cmake {
cppFlags "-DDEBUG"
}
}
} }
} }
externalNativeBuild { externalNativeBuild {

View file

@ -23,10 +23,20 @@
#define LOG(level, tag, args...) \ #define LOG(level, tag, args...) \
__android_log_print((level), (tag), args) __android_log_print((level), (tag), args)
#ifdef DEBUG
#define LOGV(tag, args...) LOG(ANDROID_LOG_VERBOSE, tag, args) #define LOGV(tag, args...) LOG(ANDROID_LOG_VERBOSE, tag, args)
#define LOGD(tag, args...) LOG(ANDROID_LOG_DEBUG, 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 LOGI(tag, args...) LOG(ANDROID_LOG_INFO, tag, args)
#define LOGW(tag, args...) LOG(ANDROID_LOG_WARN, tag, args) #define LOGW(tag, args...) LOG(ANDROID_LOG_WARN, tag, args)

View file

@ -24,6 +24,7 @@ import android.os.AsyncTask.Status;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.util.Log; import android.util.Log;
import com.google.android.sambadocumentsprovider.BuildConfig;
/** /**
* Use this class to avoid using {@link Cursor#setExtras(Bundle)} on API level < 23. * 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() { public void close() {
super.close(); super.close();
if (mLoadingTask != null && mLoadingTask.getStatus() != Status.FINISHED) { 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 // 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 // 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. // result, rather than freeing the Samba client thread doing the hard work.

View file

@ -39,6 +39,7 @@ import android.provider.DocumentsProvider;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.annotation.StringRes; import android.support.annotation.StringRes;
import android.util.Log; import android.util.Log;
import com.google.android.sambadocumentsprovider.BuildConfig;
import com.google.android.sambadocumentsprovider.R; import com.google.android.sambadocumentsprovider.R;
import com.google.android.sambadocumentsprovider.SambaProviderApplication; import com.google.android.sambadocumentsprovider.SambaProviderApplication;
import com.google.android.sambadocumentsprovider.ShareManager; import com.google.android.sambadocumentsprovider.ShareManager;
@ -160,7 +161,7 @@ public class SambaDocumentsProvider extends DocumentsProvider {
@Override @Override
public Cursor queryRoots(String[] projection) throws FileNotFoundException { 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; projection = (projection == null) ? DEFAULT_ROOT_PROJECTION : projection;
MatrixCursor cursor = new MatrixCursor(projection, mShareManager.size()); MatrixCursor cursor = new MatrixCursor(projection, mShareManager.size());
@ -200,7 +201,7 @@ public class SambaDocumentsProvider extends DocumentsProvider {
@Override @Override
public Cursor queryDocument(String documentId, String[] projection) throws FileNotFoundException { 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; projection = (projection == null) ? DEFAULT_DOCUMENT_PROJECTION : projection;
final Uri uri = toUri(documentId); final Uri uri = toUri(documentId);
@ -235,7 +236,7 @@ public class SambaDocumentsProvider extends DocumentsProvider {
@Override @Override
public Cursor queryChildDocuments(String documentId, String[] projection, String sortOrder) public Cursor queryChildDocuments(String documentId, String[] projection, String sortOrder)
throws FileNotFoundException { 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; projection = (projection == null) ? DEFAULT_DOCUMENT_PROJECTION : projection;
final Uri uri = toUri(documentId); final Uri uri = toUri(documentId);
@ -555,7 +556,7 @@ public class SambaDocumentsProvider extends DocumentsProvider {
@Override @Override
public ParcelFileDescriptor openDocument(String documentId, String mode, public ParcelFileDescriptor openDocument(String documentId, String mode,
CancellationSignal cancellationSignal) throws FileNotFoundException { 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 { try {
final String uri = toUriString(documentId); final String uri = toUriString(documentId);