Bug 1337115 - Part 1 - Make "Is first run" pref generally useable. r=sebastian

This pref could be useful for things outside of the TelemetryCorePingDelegate as well, so we have it live in GeckoApp now.

MozReview-Commit-ID: 2JZ3vNqSzcl

--HG--
extra : rebase_source : 0cf6d4f799a705d4e47be89de409925079bf661b
This commit is contained in:
Jan Henning 2017-02-23 22:16:26 +01:00
Родитель f394903529
Коммит 9e83e205d6
3 изменённых файлов: 27 добавлений и 8 удалений

Просмотреть файл

@ -1215,6 +1215,8 @@ public class BrowserApp extends GeckoApp
for (final BrowserAppDelegate delegate : delegates) {
delegate.onStop(this);
}
onAfterStop();
}
@Override

Просмотреть файл

@ -163,6 +163,10 @@ public abstract class GeckoApp
public static final String PREFS_CRASHED_COUNT = "crashedCount";
public static final String PREFS_CLEANUP_TEMP_FILES = "cleanupTempFiles";
// Originally, this was only used for the telemetry core ping logic. To avoid
// having to write custom migration logic, we just keep the original pref key.
public static final String PREFS_IS_FIRST_RUN = "telemetry-isFirstRun";
public static final String SAVED_STATE_IN_BACKGROUND = "inBackground";
public static final String SAVED_STATE_PRIVATE_SESSION = "privateSession";
@ -375,6 +379,10 @@ public abstract class GeckoApp
return GeckoSharedPrefs.forApp(this);
}
public SharedPreferences getSharedPreferencesForProfile() {
return GeckoSharedPrefs.forProfile(this);
}
@Override
public Activity getActivity() {
return this;
@ -563,7 +571,7 @@ public abstract class GeckoApp
// Make sure the Guest Browsing notification goes away when we quit.
GuestSession.hideNotification(this);
final SharedPreferences prefs = GeckoSharedPrefs.forProfile(this);
final SharedPreferences prefs = getSharedPreferencesForProfile();
final Set<String> clearSet =
PrefUtils.getStringSet(prefs, ClearOnShutdownPref.PREF, new HashSet<String>());
@ -1458,7 +1466,7 @@ public abstract class GeckoApp
// We use per-profile prefs here, because we're tracking against
// a Gecko pref. The same applies to the locale switcher!
BrowserLocaleManager.storeAndNotifyOSLocale(GeckoSharedPrefs.forProfile(GeckoApp.this), osLocale);
BrowserLocaleManager.storeAndNotifyOSLocale(getSharedPreferencesForProfile(), osLocale);
}
});
@ -1485,6 +1493,18 @@ public abstract class GeckoApp
}
}
/**
* Derived classes may call this if they require something to be done *after* they've
* done their onStop() handling.
*/
protected void onAfterStop() {
final SharedPreferences sharedPrefs = getSharedPreferencesForProfile();
if (sharedPrefs.getBoolean(PREFS_IS_FIRST_RUN, true)) {
sharedPrefs.edit().putBoolean(PREFS_IS_FIRST_RUN, false).apply();
}
}
/**
* At this point, the resource system and the rest of the browser are
* aware of the locale.

Просмотреть файл

@ -12,6 +12,7 @@ import android.support.annotation.Nullable;
import android.support.annotation.WorkerThread;
import android.util.Log;
import org.mozilla.gecko.BrowserApp;
import org.mozilla.gecko.GeckoApp;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.GeckoSharedPrefs;
import org.mozilla.gecko.adjust.AttributionHelperListener;
@ -36,8 +37,6 @@ public class TelemetryCorePingDelegate extends BrowserAppDelegateWithReference
private static final String LOGTAG = StringUtils.safeSubstring(
"Gecko" + TelemetryCorePingDelegate.class.getSimpleName(), 0, 23);
private static final String PREF_IS_FIRST_RUN = "telemetry-isFirstRun";
private TelemetryDispatcher telemetryDispatcher; // lazy
private final SessionMeasurements sessionMeasurements = new SessionMeasurements();
@ -70,10 +69,8 @@ public class TelemetryCorePingDelegate extends BrowserAppDelegateWithReference
// If we are really interested in the user's last session data, we could consider uploading in onStop
// but it's less robust (see discussion in bug 1277091).
final SharedPreferences sharedPrefs = getSharedPreferences(browserApp);
if (sharedPrefs.getBoolean(PREF_IS_FIRST_RUN, true)) {
sharedPrefs.edit()
.putBoolean(PREF_IS_FIRST_RUN, false)
.apply();
if (sharedPrefs.getBoolean(GeckoApp.PREFS_IS_FIRST_RUN, true)) {
// GeckoApp will set this pref to false afterwards.
uploadPing(browserApp);
}
}