2012-04-03 18:58:01 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
package org.mozilla.gecko;
|
|
|
|
|
2013-04-05 15:37:28 +00:00
|
|
|
import org.mozilla.gecko.db.BrowserContract;
|
|
|
|
import org.mozilla.gecko.db.BrowserDB;
|
2013-03-08 08:27:46 +00:00
|
|
|
import org.mozilla.gecko.mozglue.GeckoLoader;
|
2013-06-07 20:39:37 +00:00
|
|
|
import org.mozilla.gecko.util.Clipboard;
|
2013-04-02 14:03:39 +00:00
|
|
|
import org.mozilla.gecko.util.HardwareUtils;
|
2013-04-05 15:37:28 +00:00
|
|
|
import org.mozilla.gecko.util.ThreadUtils;
|
2012-04-03 18:58:01 +00:00
|
|
|
|
2013-04-08 07:51:56 +00:00
|
|
|
import android.app.Application;
|
2013-07-02 18:36:33 +00:00
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.IntentFilter;
|
2013-04-08 07:51:56 +00:00
|
|
|
|
2012-07-18 00:54:54 +00:00
|
|
|
public class GeckoApplication extends Application {
|
|
|
|
|
2012-09-27 14:52:59 +00:00
|
|
|
private boolean mInited;
|
2012-09-14 15:19:40 +00:00
|
|
|
private boolean mInBackground;
|
2013-01-29 21:59:42 +00:00
|
|
|
private boolean mPausedGecko;
|
2013-07-02 18:36:33 +00:00
|
|
|
private boolean mNeedsRestart;
|
2012-04-03 18:58:01 +00:00
|
|
|
|
2012-11-01 05:10:59 +00:00
|
|
|
private LightweightTheme mLightweightTheme;
|
|
|
|
|
2012-09-27 14:52:59 +00:00
|
|
|
protected void initialize() {
|
|
|
|
if (mInited)
|
|
|
|
return;
|
|
|
|
|
2012-07-07 05:38:05 +00:00
|
|
|
// workaround for http://code.google.com/p/android/issues/detail?id=20915
|
|
|
|
try {
|
|
|
|
Class.forName("android.os.AsyncTask");
|
|
|
|
} catch (ClassNotFoundException e) {}
|
|
|
|
|
2012-11-01 05:10:59 +00:00
|
|
|
mLightweightTheme = new LightweightTheme(this);
|
|
|
|
|
2012-09-14 15:19:40 +00:00
|
|
|
GeckoConnectivityReceiver.getInstance().init(getApplicationContext());
|
|
|
|
GeckoBatteryManager.getInstance().init(getApplicationContext());
|
|
|
|
GeckoBatteryManager.getInstance().start();
|
|
|
|
GeckoNetworkManager.getInstance().init(getApplicationContext());
|
2012-09-19 19:21:19 +00:00
|
|
|
MemoryMonitor.getInstance().init(getApplicationContext());
|
2013-03-11 18:59:23 +00:00
|
|
|
|
2013-07-02 18:36:33 +00:00
|
|
|
BroadcastReceiver receiver = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
mNeedsRestart = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
registerReceiver(receiver, new IntentFilter(Intent.ACTION_LOCALE_CHANGED));
|
|
|
|
|
2012-09-27 14:52:59 +00:00
|
|
|
mInited = true;
|
2012-04-03 18:58:01 +00:00
|
|
|
}
|
|
|
|
|
2013-11-11 18:41:16 +00:00
|
|
|
public void onActivityPause(GeckoActivityStatus activity) {
|
2012-05-08 23:40:12 +00:00
|
|
|
mInBackground = true;
|
|
|
|
|
2013-01-29 21:59:42 +00:00
|
|
|
if ((activity.isFinishing() == false) &&
|
|
|
|
(activity.isGeckoActivityOpened() == false)) {
|
|
|
|
// Notify Gecko that we are pausing; the cache service will be
|
|
|
|
// shutdown, closing the disk cache cleanly. If the android
|
|
|
|
// low memory killer subsequently kills us, the disk cache will
|
|
|
|
// be left in a consistent state, avoiding costly cleanup and
|
|
|
|
// re-creation.
|
2013-03-26 18:05:10 +00:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createAppBackgroundingEvent());
|
2013-01-29 21:59:42 +00:00
|
|
|
mPausedGecko = true;
|
2013-04-05 15:37:28 +00:00
|
|
|
|
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
BrowserDB.expireHistory(getContentResolver(),
|
|
|
|
BrowserContract.ExpirePriority.NORMAL);
|
|
|
|
}
|
|
|
|
});
|
2013-01-29 21:59:42 +00:00
|
|
|
}
|
2012-09-14 15:19:40 +00:00
|
|
|
GeckoConnectivityReceiver.getInstance().stop();
|
|
|
|
GeckoNetworkManager.getInstance().stop();
|
2012-04-03 18:58:01 +00:00
|
|
|
}
|
|
|
|
|
2013-11-11 18:41:16 +00:00
|
|
|
public void onActivityResume(GeckoActivityStatus activity) {
|
2013-01-29 21:59:42 +00:00
|
|
|
if (mPausedGecko) {
|
2013-03-26 18:05:10 +00:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createAppForegroundingEvent());
|
2013-01-29 21:59:42 +00:00
|
|
|
mPausedGecko = false;
|
|
|
|
}
|
2012-09-14 15:19:40 +00:00
|
|
|
GeckoConnectivityReceiver.getInstance().start();
|
|
|
|
GeckoNetworkManager.getInstance().start();
|
2012-05-08 23:40:12 +00:00
|
|
|
|
|
|
|
mInBackground = false;
|
|
|
|
}
|
|
|
|
|
2013-07-02 18:36:33 +00:00
|
|
|
protected boolean needsRestart() {
|
|
|
|
return mNeedsRestart;
|
|
|
|
}
|
|
|
|
|
2013-03-08 08:27:46 +00:00
|
|
|
@Override
|
|
|
|
public void onCreate() {
|
2013-04-02 14:03:39 +00:00
|
|
|
HardwareUtils.init(getApplicationContext());
|
2013-06-07 20:39:37 +00:00
|
|
|
Clipboard.init(getApplicationContext());
|
2013-07-04 01:31:10 +00:00
|
|
|
GeckoLoader.loadMozGlue();
|
2013-03-08 08:27:46 +00:00
|
|
|
super.onCreate();
|
|
|
|
}
|
|
|
|
|
2012-05-08 23:40:12 +00:00
|
|
|
public boolean isApplicationInBackground() {
|
|
|
|
return mInBackground;
|
2012-04-03 18:58:01 +00:00
|
|
|
}
|
2012-11-01 05:10:59 +00:00
|
|
|
|
|
|
|
public LightweightTheme getLightweightTheme() {
|
|
|
|
return mLightweightTheme;
|
|
|
|
}
|
2012-04-03 18:58:01 +00:00
|
|
|
}
|