Fix log reporting for release builds (#1916)

* Fix log reporting for release builds

* Fix logs for release builds

* wip

* Clean up the branch to exclude unrelated changes

* With java docs

* Uncomment quiz checker

* Check for external storage permissions before sending logs

* With more java docs

* Fix crash while zipping log files

* Do not log token and cookies

* Add instruction to restart app
This commit is contained in:
Vivek Maskara 2018-10-14 16:49:43 +05:30 committed by Josephine Lim
parent 02fe0044a6
commit b0b4b08100
28 changed files with 761 additions and 136 deletions

View file

@ -8,7 +8,9 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.os.Build;
import android.os.Process;
import android.support.annotation.NonNull;
import android.util.Log;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.imagepipeline.core.ImagePipelineConfig;
@ -28,9 +30,13 @@ import javax.inject.Named;
import fr.free.nrw.commons.auth.SessionManager;
import fr.free.nrw.commons.category.CategoryDao;
import fr.free.nrw.commons.concurrency.BackgroundPoolExceptionHandler;
import fr.free.nrw.commons.concurrency.ThreadPoolService;
import fr.free.nrw.commons.contributions.ContributionDao;
import fr.free.nrw.commons.data.DBOpenHelper;
import fr.free.nrw.commons.di.ApplicationlessInjection;
import fr.free.nrw.commons.logging.FileLoggingTree;
import fr.free.nrw.commons.logging.LogUtils;
import fr.free.nrw.commons.modifications.ModifierSequenceDao;
import fr.free.nrw.commons.upload.FileUtils;
import fr.free.nrw.commons.utils.ContributionUtils;
@ -38,7 +44,6 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import timber.log.Timber;
// TODO: Use ProGuard to rip out reporting when publishing
@ReportsCrashes(
mailTo = "commons-app-android-private@googlegroups.com",
mode = ReportingInteractionMode.DIALOG,
@ -48,13 +53,15 @@ import timber.log.Timber;
resDialogOkToast = R.string.crash_dialog_ok_toast
)
public class CommonsApplication extends Application {
@Inject SessionManager sessionManager;
@Inject DBOpenHelper dbOpenHelper;
@Inject @Named("default_preferences") SharedPreferences defaultPrefs;
@Inject @Named("application_preferences") SharedPreferences applicationPrefs;
@Inject @Named("prefs") SharedPreferences otherPrefs;
@Inject
@Named("isBeta")
boolean isBeta;
/**
* Constants begin
@ -67,10 +74,6 @@ public class CommonsApplication extends Application {
public static final String FEEDBACK_EMAIL_SUBJECT = "Commons Android App (%s) Feedback";
public static final String LOGS_PRIVATE_EMAIL = "commons-app-android-private@googlegroups.com";
public static final String LOGS_PRIVATE_EMAIL_SUBJECT = "Commons Android App (%s) Logs";
public static final String NOTIFICATION_CHANNEL_ID_ALL = "CommonsNotificationAll";
/**
@ -97,7 +100,7 @@ public class CommonsApplication extends Application {
.getCommonsApplicationComponent()
.inject(this);
Timber.plant(new Timber.DebugTree());
initTimber();
// Set DownsampleEnabled to True to downsample the image in case it's heavy
ImagePipelineConfig config = ImagePipelineConfig.newBuilder(this)
@ -109,24 +112,62 @@ public class CommonsApplication extends Application {
Timber.e(e);
// TODO: Remove when we're able to initialize Fresco in test builds.
}
if (setupLeakCanary() == RefWatcher.DISABLED) {
return;
}
// Empty temp directory in case some temp files are created and never removed.
ContributionUtils.emptyTemporaryDirectory();
if (!BuildConfig.DEBUG) {
ACRA.init(this);
} else {
initAcra();
if (BuildConfig.DEBUG) {
Stetho.initializeWithDefaults(this);
}
createNotificationChannel(this);
if (setupLeakCanary() == RefWatcher.DISABLED) {
return;
}
// Fire progress callbacks for every 3% of uploaded content
System.setProperty("in.yuvi.http.fluent.PROGRESS_TRIGGER_THRESHOLD", "3.0");
}
/**
* Plants debug and file logging tree.
* Timber lets you plant your own logging trees.
*
*/
private void initTimber() {
String logFileName = isBeta ? "CommonsBetaAppLogs" : "CommonsAppLogs";
String logDirectory = LogUtils.getLogDirectory(isBeta);
FileLoggingTree tree = new FileLoggingTree(
Log.DEBUG,
logFileName,
logDirectory,
1000,
getFileLoggingThreadPool());
Timber.plant(tree);
Timber.plant(new Timber.DebugTree());
}
/**
* Remove ACRA's UncaughtExceptionHandler
* We do this because ACRA's handler spawns a new process possibly screwing up with a few things
*/
private void initAcra() {
Thread.UncaughtExceptionHandler exceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
ACRA.init(this);
Thread.setDefaultUncaughtExceptionHandler(exceptionHandler);
}
private ThreadPoolService getFileLoggingThreadPool() {
return new ThreadPoolService.Builder("file-logging-thread")
.setPriority(Process.THREAD_PRIORITY_LOWEST)
.setPoolSize(1)
.setExceptionHandler(new BackgroundPoolExceptionHandler())
.build();
}
public static void createNotificationChannel(@NonNull Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);