Browse Source

Don't write to Android logcat if app is build in release mode.

pull/11/head
Eric Kok 11 years ago
parent
commit
dc2d484be2
  1. 7
      core/src/org/transdroid/core/gui/log/Log.java
  2. 19
      core/src/org/transdroid/core/gui/navigation/NavigationHelper.java

7
core/src/org/transdroid/core/gui/log/Log.java

@ -3,9 +3,11 @@ package org.transdroid.core.gui.log;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Date; import java.util.Date;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EBean; import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.EBean.Scope; import org.androidannotations.annotations.EBean.Scope;
import org.androidannotations.annotations.OrmLiteDao; import org.androidannotations.annotations.OrmLiteDao;
import org.transdroid.core.gui.navigation.NavigationHelper;
import org.transdroid.daemon.util.ITLogger; import org.transdroid.daemon.util.ITLogger;
import android.content.Context; import android.content.Context;
@ -27,13 +29,16 @@ public class Log implements ITLogger {
private Context context; private Context context;
@OrmLiteDao(helper = DatabaseHelper.class, model = ErrorLogEntry.class) @OrmLiteDao(helper = DatabaseHelper.class, model = ErrorLogEntry.class)
Dao<ErrorLogEntry, Integer> errorLogDao; Dao<ErrorLogEntry, Integer> errorLogDao;
@Bean
protected NavigationHelper navigationHelper;
protected Log(Context context) { protected Log(Context context) {
this.context = context; this.context = context;
} }
protected void log(String logName, int priority, String message) { protected void log(String logName, int priority, String message) {
android.util.Log.println(priority, LOG_NAME, message); if (!navigationHelper.inDebugMode())
android.util.Log.println(priority, LOG_NAME, message);
try { try {
// Store this log message to the database // Store this log message to the database
errorLogDao.create(new ErrorLogEntry(priority, logName, message)); errorLogDao.create(new ErrorLogEntry(priority, logName, message));

19
core/src/org/transdroid/core/gui/navigation/NavigationHelper.java

@ -6,6 +6,7 @@ import org.transdroid.core.R;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.text.Spannable; import android.text.Spannable;
@ -34,6 +35,7 @@ public class NavigationHelper {
@RootContext @RootContext
protected Context context; protected Context context;
private Boolean inDebugMode;
private static ImageLoader imageCache; private static ImageLoader imageCache;
/** /**
@ -89,6 +91,23 @@ public class NavigationHelper {
} }
} }
/**
* Returns whether the application is running in debug mode, as opposed to release mode. Use to show/hide features
* in the ui based on the build mode.
* @return True if the app is compiled in/running as debug mode, false otherwise
*/
public boolean inDebugMode() {
try {
if (inDebugMode == null) {
PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
inDebugMode = (pi.applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
}
return inDebugMode;
} catch (NameNotFoundException e) {
return false;
}
}
/** /**
* Returns whether the device is considered small (i.e. a phone) rather than large (i.e. a tablet). Can, for * Returns whether the device is considered small (i.e. a phone) rather than large (i.e. a tablet). Can, for
* example, be used to determine if a dialog should be shown full screen. Currently is true if the device's smallest * example, be used to determine if a dialog should be shown full screen. Currently is true if the device's smallest

Loading…
Cancel
Save