Bug 1346413 - Part 3 - Remove GeckoActivityStatus-based background detection. r?jchen
MozReview-Commit-ID: 6EhSACAvgt8
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoActivity.java
@@ -1,83 +1,42 @@
/* 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;
import android.support.v7.app.AppCompatActivity;
-import org.mozilla.gecko.util.IntentUtils;
-
-public abstract class GeckoActivity extends AppCompatActivity implements GeckoActivityStatus {
- // Has this activity recently started another Gecko activity?
- private boolean mGeckoActivityOpened;
-
+public abstract class GeckoActivity extends AppCompatActivity {
/**
* Display any resources that show strings or encompass locale-specific
* representations.
*
* onLocaleReady must always be called on the UI thread.
*/
public void onLocaleReady(final String locale) {
}
@Override
- public void onPause() {
- super.onPause();
-
- if (getApplication() instanceof GeckoApplication) {
- ((GeckoApplication) getApplication()).onActivityPause(this);
- }
- }
-
- @Override
- public void onResume() {
- super.onResume();
-
- if (getApplication() instanceof GeckoApplication) {
- ((GeckoApplication) getApplication()).onActivityResume(this);
- mGeckoActivityOpened = false;
- }
- }
-
- @Override
public void onCreate(android.os.Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (AppConstants.MOZ_ANDROID_ANR_REPORTER) {
ANRReporter.register(getApplicationContext());
}
}
@Override
public void onDestroy() {
if (AppConstants.MOZ_ANDROID_ANR_REPORTER) {
ANRReporter.unregister();
}
super.onDestroy();
}
- @Override
- public void startActivity(Intent intent) {
- mGeckoActivityOpened = IntentUtils.checkIfGeckoActivity(intent);
- super.startActivity(intent);
- }
-
- @Override
- public void startActivityForResult(Intent intent, int request) {
- mGeckoActivityOpened = IntentUtils.checkIfGeckoActivity(intent);
- super.startActivityForResult(intent, request);
- }
-
- @Override
- public boolean isGeckoActivityOpened() {
- return mGeckoActivityOpened;
- }
-
public boolean isApplicationInBackground() {
return ((GeckoApplication) getApplication()).isApplicationInBackground();
}
@Override
public void onLowMemory() {
MemoryMonitor.getInstance().onLowMemory();
super.onLowMemory();
deleted file mode 100644
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoActivityStatus.java
+++ /dev/null
@@ -1,10 +0,0 @@
-/* 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;
-
-public interface GeckoActivityStatus {
- public boolean isGeckoActivityOpened();
- public boolean isFinishing(); // typically from android.app.Activity
-};
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
@@ -168,18 +168,16 @@ public class GeckoApplication extends Ap
} catch (IllegalStateException ex) {
// GeckoApp hasn't started, so we have no ContextGetter in BrowserLocaleManager.
Log.w(LOG_TAG, "Couldn't correct locale.", ex);
}
super.onConfigurationChanged(config);
}
- public void onActivityPause(GeckoActivityStatus activity) { }
-
public void onApplicationBackground() {
mInBackground = true;
// 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.
@@ -192,18 +190,16 @@ public class GeckoApplication extends Ap
public void run() {
db.expireHistory(getContentResolver(), BrowserContract.ExpirePriority.NORMAL);
}
});
GeckoNetworkManager.getInstance().stop();
}
- public void onActivityResume(GeckoActivityStatus activity) { }
-
public void onApplicationForeground() {
if (mIsInitialResume) {
GeckoBatteryManager.getInstance().start(this);
GeckoFontScaleListener.getInstance().initialize(this);
GeckoNetworkManager.getInstance().start(this);
mIsInitialResume = false;
} else if (mPausedGecko) {
GeckoThread.onResume();
--- a/mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferences.java
+++ b/mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferences.java
@@ -10,17 +10,16 @@ import org.mozilla.gecko.AboutPages;
import org.mozilla.gecko.AdjustConstants;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.BrowserApp;
import org.mozilla.gecko.BrowserLocaleManager;
import org.mozilla.gecko.DataReportingNotification;
import org.mozilla.gecko.DynamicToolbar;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.Experiments;
-import org.mozilla.gecko.GeckoActivityStatus;
import org.mozilla.gecko.GeckoApplication;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.GeckoSharedPrefs;
import org.mozilla.gecko.LocaleManager;
import org.mozilla.gecko.Locales;
import org.mozilla.gecko.PrefsHelper;
import org.mozilla.gecko.R;
import org.mozilla.gecko.SnackbarBuilder;
@@ -39,17 +38,16 @@ import org.mozilla.gecko.tabqueue.TabQue
import org.mozilla.gecko.updater.UpdateService;
import org.mozilla.gecko.updater.UpdateServiceHelper;
import org.mozilla.gecko.util.BundleEventListener;
import org.mozilla.gecko.util.ContextUtils;
import org.mozilla.gecko.util.EventCallback;
import org.mozilla.gecko.util.GeckoBundle;
import org.mozilla.gecko.util.HardwareUtils;
import org.mozilla.gecko.util.InputOptionsUtils;
-import org.mozilla.gecko.util.IntentUtils;
import org.mozilla.gecko.util.ThreadUtils;
import org.mozilla.gecko.util.ViewUtil;
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.Fragment;
import android.app.FragmentManager;
@@ -99,17 +97,16 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
public class GeckoPreferences
extends AppCompatPreferenceActivity
implements BundleEventListener,
- GeckoActivityStatus,
OnPreferenceChangeListener,
OnSharedPreferenceChangeListener
{
private static final String LOGTAG = "GeckoPreferences";
// We have a white background, which makes transitions on
// some devices look bad. Don't use transitions on those
// devices.
@@ -117,19 +114,16 @@ public class GeckoPreferences
private static final int NO_SUCH_ID = 0;
public static final String NON_PREF_PREFIX = "android.not_a_preference.";
public static final String INTENT_EXTRA_RESOURCES = "resource";
public static final String PREFS_TRACKING_PROTECTION_PROMPT_SHOWN = NON_PREF_PREFIX + "trackingProtectionPromptShown";
public static final String PREFS_HEALTHREPORT_UPLOAD_ENABLED = NON_PREF_PREFIX + "healthreport.uploadEnabled";
public static final String PREFS_SYNC = NON_PREF_PREFIX + "sync";
- // Has this activity recently started another Gecko activity?
- private boolean mGeckoActivityOpened;
-
private static boolean sIsCharEncodingEnabled;
private boolean mInitialized;
private PrefsHelper.PrefHandler mPrefsRequest;
private List<Header> mHeaders;
// These match keys in resources/xml*/preferences*.xml
private static final String PREFS_SEARCH_RESTORE_DEFAULTS = NON_PREF_PREFIX + "search.restore_defaults";
private static final String PREFS_DATA_REPORTING_PREFERENCES = NON_PREF_PREFIX + "datareporting.preferences";
@@ -546,33 +540,24 @@ public class GeckoPreferences
// Symmetric with onResume.
if (isMultiPane()) {
SharedPreferences prefs = GeckoSharedPrefs.forApp(this);
prefs.unregisterOnSharedPreferenceChangeListener(this);
}
super.onPause();
-
- if (getApplication() instanceof GeckoApplication) {
- ((GeckoApplication) getApplication()).onActivityPause(this);
- }
}
@Override
public void onResume() {
super.onResume();
EventDispatcher.getInstance().registerUiThreadListener(this, "Snackbar:Show");
- if (getApplication() instanceof GeckoApplication) {
- ((GeckoApplication) getApplication()).onActivityResume(this);
- mGeckoActivityOpened = false;
- }
-
// Watch prefs, otherwise we don't reliably get told when they change.
// See documentation for onSharedPreferenceChange for more.
// Inexplicably only needed on tablet.
if (isMultiPane()) {
SharedPreferences prefs = GeckoSharedPrefs.forApp(this);
prefs.registerOnSharedPreferenceChangeListener(this);
}
}
@@ -584,32 +569,25 @@ public class GeckoPreferences
// Specifically, when we open a link, we want to back out of all
// the settings screens.
// We need to start nested PreferenceScreens withStartActivityForResult().
// Android doesn't let us do that (see Preference.onClick), so we're overriding here.
startActivityForResultChoosingTransition(intent, REQUEST_CODE_PREF_SCREEN);
}
@Override
- public void startActivityForResult(Intent intent, int request) {
- mGeckoActivityOpened = IntentUtils.checkIfGeckoActivity(intent);
- super.startActivityForResult(intent, request);
- }
-
- @Override
public void startWithFragment(String fragmentName, Bundle args,
Fragment resultTo, int resultRequestCode, int titleRes, int shortTitleRes) {
Log.v(LOGTAG, "Starting with fragment: " + fragmentName + ", title " + titleRes);
// Overriding because we want to use startActivityForResult for Fragment intents.
Intent intent = onBuildStartFragmentIntent(fragmentName, args, titleRes, shortTitleRes);
if (resultTo == null) {
startActivityForResultChoosingTransition(intent, REQUEST_CODE_PREF_SCREEN);
} else {
- mGeckoActivityOpened = IntentUtils.checkIfGeckoActivity(intent);
resultTo.startActivityForResult(intent, resultRequestCode);
if (NO_TRANSITIONS) {
overridePendingTransition(0, 0);
}
}
}
@Override
@@ -1506,21 +1484,16 @@ public class GeckoPreferences
private PrefsHelper.PrefHandler getGeckoPreferences(final PreferenceGroup screen,
ArrayList<String> prefs) {
final PrefsHelper.PrefHandler prefHandler = new PrefCallbacks(screen);
final String[] prefNames = prefs.toArray(new String[prefs.size()]);
PrefsHelper.addObserver(prefNames, prefHandler);
return prefHandler;
}
- @Override
- public boolean isGeckoActivityOpened() {
- return mGeckoActivityOpened;
- }
-
/**
* Given an Intent instance, add extras to specify which settings section to
* open.
*
* resource should be a valid Android XML resource identifier.
*
* The mechanism to open a section differs based on Android version.
*/
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -632,17 +632,16 @@ gbjar.sources += ['java/org/mozilla/geck
'firstrun/FirstrunPagerConfig.java',
'firstrun/FirstrunPanel.java',
'firstrun/RestrictedWelcomePanel.java',
'firstrun/SyncPanel.java',
'firstrun/TabQueuePanel.java',
'FormAssistPopup.java',
'GeckoActivity.java',
'GeckoActivityMonitor.java',
- 'GeckoActivityStatus.java',
'GeckoApp.java',
'GeckoApplication.java',
'GeckoFontScaleListener.java',
'GeckoJavaSampler.java',
'GeckoMessageReceiver.java',
'GeckoProfilesProvider.java',
'GeckoService.java',
'GeckoUpdateReceiver.java',
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/IntentUtils.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/IntentUtils.java
@@ -103,25 +103,9 @@ public class IntentUtils {
* The return value of this method should be used early since other
* initialization may depend on its results.
*/
@CheckResult
public static boolean getIsInAutomationFromEnvironment(final SafeIntent intent) {
final HashMap<String, String> envVars = IntentUtils.getEnvVarMap(intent);
return !TextUtils.isEmpty(envVars.get(IntentUtils.ENV_VAR_IN_AUTOMATION));
}
-
- /**
- * Checks whether the target of the passed intent will result in us opening one
- * of our own activities or not.
- *
- * @param intent The intent to be checked.
- * @return True if the intent target is within our app.
- */
- public static boolean checkIfGeckoActivity(Intent intent) {
- // Whenever we call our own activity, the component and its package name is set.
- // If we call an activity from another package, or an open intent (leaving android to resolve)
- // component has a different package name or it is null.
- ComponentName component = intent.getComponent();
- return (component != null &&
- AppConstants.ANDROID_PACKAGE_NAME.equals(component.getPackageName()));
- }
}