/*
 * Copyright (c) 2016 大前良介 (OHMAE Ryosuke)
 *
 * This software is released under the MIT License.
 * http://opensource.org/licenses/MIT
 */

package net.mm2d.dmsexplorer;

import android.app.Application;

import net.mm2d.dmsexplorer.domain.AppRepository;
import net.mm2d.dmsexplorer.log.EventLogger;
import net.mm2d.dmsexplorer.settings.Settings;
import net.mm2d.dmsexplorer.util.update.UpdateChecker;
import net.mm2d.log.AndroidLogInitializer;
import net.mm2d.log.Log;

import io.reactivex.exceptions.UndeliverableException;
import io.reactivex.plugins.RxJavaPlugins;

/**
 * Log出力変更のための継承。
 *
 * @author <a href="mailto:ryo@mm2d.net">大前良介 (OHMAE Ryosuke)</a>
 */
public class App extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Log.setInitializer(AndroidLogInitializer.get());
        Log.initialize(BuildConfig.DEBUG, true);
        RxJavaPlugins.setErrorHandler(e -> Log.w(e instanceof UndeliverableException ? e.getCause() : e));
        Settings.initialize(this);
        EventLogger.initialize(this);
        Repository.set(new AppRepository(this));
        new UpdateChecker(this).check();
    }
}

@@ -199,16 +199,128 @@
 ication;
+%0Aimport android.os.StrictMode;%0Aimport android.os.StrictMode.ThreadPolicy;%0Aimport android.os.StrictMode.VmPolicy;
 %0A%0Aimport
@@ -987,16 +987,41 @@
  true);%0A
+        setStrictMode();%0A
         
@@ -1237,24 +1237,24 @@
 ory(this));%0A
-
         new 
@@ -1287,11 +1287,654 @@
 );%0A    %7D
+%0A%0A    private void setStrictMode() %7B%0A        if (BuildConfig.DEBUG) %7B%0A            StrictMode.setThreadPolicy(new ThreadPolicy.Builder()%0A                    .detectAll()%0A                    .penaltyLog()%0A                    .penaltyDropBox()%0A                    .penaltyDialog()%0A                    .build());%0A            StrictMode.setVmPolicy(new VmPolicy.Builder()%0A                    .detectAll()%0A                    .penaltyLog()%0A                    .penaltyDropBox()%0A                    .build());%0A        %7D else %7B%0A            StrictMode.setThreadPolicy(ThreadPolicy.LAX);%0A            StrictMode.setVmPolicy(VmPolicy.LAX);%0A        %7D%0A    %7D
 %0A%7D%0A

set StrictMode