Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 157c0014 authored by Kurt Partridge's avatar Kurt Partridge
Browse files

Clean up logic in onUserLoggingConsent

- Make ResearchSetting for whether the user has seen the splash screen
- Inline #setLoggingAllowed, which is short and is now only called by
  onUserLoggingConsent

Change-Id: Icdf4592777b80643807b6ccf1d3896459c503e02
parent 75e6fb68
Loading
Loading
Loading
Loading
+6 −17
Original line number Diff line number Diff line
@@ -125,7 +125,6 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
    /* package */ static boolean sIsLogging = false;
    private static final int OUTPUT_FORMAT_VERSION = 5;
    private static final String PREF_USABILITY_STUDY_MODE = "usability_study_mode";
    private static final String PREF_RESEARCH_HAS_SEEN_SPLASH = "pref_research_has_seen_splash";
    /* package */ static final String LOG_FILENAME_PREFIX = "researchLog";
    private static final String LOG_FILENAME_SUFFIX = ".txt";
    /* package */ static final String USER_RECORDING_FILENAME_PREFIX = "recording";
@@ -321,14 +320,10 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
        }
    }

    private boolean hasSeenSplash() {
        return mPrefs.getBoolean(PREF_RESEARCH_HAS_SEEN_SPLASH, false);
    }

    private Dialog mSplashDialog = null;

    private void maybeShowSplashScreen() {
        if (hasSeenSplash()) {
        if (ResearchSettings.readHasSeenSplash(mPrefs)) {
            return;
        }
        if (mSplashDialog != null && mSplashDialog.isShowing()) {
@@ -381,22 +376,16 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
    }

    public void onUserLoggingConsent() {
        setLoggingAllowed(true);
        if (mPrefs == null) {
            return;
            mPrefs = PreferenceManager.getDefaultSharedPreferences(mLatinIME);
            if (mPrefs == null) return;
        }
        final Editor e = mPrefs.edit();
        e.putBoolean(PREF_RESEARCH_HAS_SEEN_SPLASH, true);
        e.apply();
        sIsLogging = true;
        ResearchSettings.writeResearchLoggerEnabledFlag(mPrefs, true);
        ResearchSettings.writeHasSeenSplash(mPrefs, true);
        restart();
    }

    private void setLoggingAllowed(final boolean enableLogging) {
        if (mPrefs == null) return;
        ResearchSettings.writeResearchLoggerEnabledFlag(mPrefs, enableLogging);
        sIsLogging = enableLogging;
    }

    private static int sLogFileCounter = 0;

    private File createLogFile(final File filesDir) {
+11 −0
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ public final class ResearchSettings {
    public static final String PREF_RESEARCH_LOGGER_UUID = "pref_research_logger_uuid";
    public static final String PREF_RESEARCH_LOGGER_ENABLED_FLAG =
            "pref_research_logger_enabled_flag";
    public static final String PREF_RESEARCH_LOGGER_HAS_SEEN_SPLASH =
            "pref_research_logger_has_seen_splash";

    private ResearchSettings() {
        // Intentional empty constructor for singleton.
@@ -47,4 +49,13 @@ public final class ResearchSettings {
            final boolean isEnabled) {
        prefs.edit().putBoolean(PREF_RESEARCH_LOGGER_ENABLED_FLAG, isEnabled).apply();
    }

    public static boolean readHasSeenSplash(final SharedPreferences prefs) {
        return prefs.getBoolean(PREF_RESEARCH_LOGGER_HAS_SEEN_SPLASH, false);
    }

    public static void writeHasSeenSplash(final SharedPreferences prefs,
            final boolean hasSeenSplash) {
        prefs.edit().putBoolean(PREF_RESEARCH_LOGGER_HAS_SEEN_SPLASH, hasSeenSplash).apply();
    }
}