You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
2.9 KiB
100 lines
2.9 KiB
package acr.browser.lightning.app; |
|
|
|
import android.app.Activity; |
|
import android.app.Application; |
|
import android.content.Context; |
|
import android.os.Build; |
|
import android.os.StrictMode; |
|
import android.support.annotation.NonNull; |
|
import android.util.Log; |
|
import android.webkit.WebView; |
|
|
|
import com.squareup.leakcanary.LeakCanary; |
|
import com.squareup.otto.Bus; |
|
|
|
import java.util.concurrent.Executor; |
|
import java.util.concurrent.Executors; |
|
|
|
import javax.inject.Inject; |
|
|
|
import acr.browser.lightning.BuildConfig; |
|
import acr.browser.lightning.preference.PreferenceManager; |
|
import acr.browser.lightning.utils.MemoryLeakUtils; |
|
|
|
public class BrowserApp extends Application { |
|
|
|
private static final String TAG = BrowserApp.class.getSimpleName(); |
|
|
|
private static AppComponent mAppComponent; |
|
private static final Executor mIOThread = Executors.newSingleThreadExecutor(); |
|
private static final Executor mTaskThread = Executors.newCachedThreadPool(); |
|
|
|
@Inject Bus mBus; |
|
@Inject PreferenceManager mPreferenceManager; |
|
|
|
@Override |
|
public void onCreate() { |
|
super.onCreate(); |
|
if (BuildConfig.DEBUG) { |
|
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() |
|
.detectAll() |
|
.penaltyLog() |
|
.build()); |
|
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() |
|
.detectAll() |
|
.penaltyLog() |
|
.build()); |
|
} |
|
|
|
mAppComponent = DaggerAppComponent.builder().appModule(new AppModule(this)).build(); |
|
mAppComponent.inject(this); |
|
|
|
if (mPreferenceManager.getUseLeakCanary() && !isRelease()) { |
|
LeakCanary.install(this); |
|
} |
|
if (!isRelease() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { |
|
WebView.setWebContentsDebuggingEnabled(true); |
|
} |
|
|
|
registerActivityLifecycleCallbacks(new MemoryLeakUtils.LifecycleAdapter() { |
|
@Override |
|
public void onActivityDestroyed(Activity activity) { |
|
Log.d(TAG, "Cleaning up after the Android framework"); |
|
MemoryLeakUtils.clearNextServedView(activity, BrowserApp.this); |
|
} |
|
}); |
|
} |
|
|
|
@NonNull |
|
public static BrowserApp get(@NonNull Context context) { |
|
return (BrowserApp) context.getApplicationContext(); |
|
} |
|
|
|
public static AppComponent getAppComponent() { |
|
return mAppComponent; |
|
} |
|
|
|
@NonNull |
|
public static Executor getIOThread() { |
|
return mIOThread; |
|
} |
|
|
|
@NonNull |
|
public static Executor getTaskThread() { |
|
return mTaskThread; |
|
} |
|
|
|
public static Bus getBus(@NonNull Context context) { |
|
return get(context).mBus; |
|
} |
|
|
|
/** |
|
* Determines whether this is a release build. |
|
* |
|
* @return true if this is a release build, false otherwise. |
|
*/ |
|
public static boolean isRelease() { |
|
return !BuildConfig.DEBUG || BuildConfig.BUILD_TYPE.toLowerCase().equals("release"); |
|
} |
|
|
|
}
|
|
|