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

Commit 75e6fb68 authored by Kurt Partridge's avatar Kurt Partridge
Browse files

Clean up PREF_USABILITY_STUDY_MODE

- Refer to a common default value in DebugSettings
- Make PREF_USABILITY_STUDY_MODE independent of the ResearchLogger
- ResearchLogger uses its own preference through ResearchSettings

multi-project commit with Ie0df836c9d779eba484b522666ec357f4e234823

Change-Id: I88547a2f619db6e7364abbbec12f9f76855dd11a
parent 788dc556
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ public final class DebugSettings extends PreferenceFragment
        if (usabilityStudyPref instanceof CheckBoxPreference) {
            final CheckBoxPreference checkbox = (CheckBoxPreference)usabilityStudyPref;
            checkbox.setChecked(prefs.getBoolean(PREF_USABILITY_STUDY_MODE,
                    ResearchLogger.DEFAULT_USABILITY_STUDY_MODE));
                    LatinImeLogger.getUsabilityStudyMode(prefs)));
            checkbox.setSummary(R.string.settings_warning_researcher_mode);
        }
        final Preference statisticsLoggingPref = findPreference(PREF_STATISTICS_LOGGING);
+4 −0
Original line number Diff line number Diff line
@@ -37,6 +37,10 @@ public final class LatinImeLogger implements SharedPreferences.OnSharedPreferenc
    public static void commit() {
    }

    public static boolean getUsabilityStudyMode(final SharedPreferences prefs) {
        return false;
    }

    public static void onDestroy() {
    }

+4 −14
Original line number Diff line number Diff line
@@ -122,7 +122,6 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
    // field holds a channel name, the developer does not have to re-enter it when using the
    // feedback mechanism to generate multiple tests.
    private static final boolean FEEDBACK_DIALOG_SHOULD_PRESERVE_TEXT_FIELD = false;
    public static final boolean DEFAULT_USABILITY_STUDY_MODE = false;
    /* package */ static boolean sIsLogging = false;
    private static final int OUTPUT_FORMAT_VERSION = 5;
    private static final String PREF_USABILITY_STUDY_MODE = "usability_study_mode";
@@ -249,12 +248,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
        mSuggest = suggest;
        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(latinIME);
        if (prefs != null) {
            if (!prefs.contains(PREF_USABILITY_STUDY_MODE)) {
                Editor e = prefs.edit();
                e.putBoolean(PREF_USABILITY_STUDY_MODE, DEFAULT_USABILITY_STUDY_MODE);
                e.apply();
            }
            sIsLogging = prefs.getBoolean(PREF_USABILITY_STUDY_MODE, false);
            sIsLogging = ResearchSettings.readResearchLoggerEnabledFlag(prefs);
            prefs.registerOnSharedPreferenceChangeListener(this);

            final long lastCleanupTime = prefs.getLong(PREF_LAST_CLEANUP_TIME, 0L);
@@ -397,13 +391,9 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
        restart();
    }

    private void setLoggingAllowed(boolean enableLogging) {
        if (mPrefs == null) {
            return;
        }
        Editor e = mPrefs.edit();
        e.putBoolean(PREF_USABILITY_STUDY_MODE, enableLogging);
        e.apply();
    private void setLoggingAllowed(final boolean enableLogging) {
        if (mPrefs == null) return;
        ResearchSettings.writeResearchLoggerEnabledFlag(mPrefs, enableLogging);
        sIsLogging = enableLogging;
    }

+11 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import java.util.UUID;

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";

    private ResearchSettings() {
        // Intentional empty constructor for singleton.
@@ -36,4 +38,13 @@ public final class ResearchSettings {
        prefs.edit().putString(PREF_RESEARCH_LOGGER_UUID, newUuid).apply();
        return newUuid;
    }

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

    public static void writeResearchLoggerEnabledFlag(final SharedPreferences prefs,
            final boolean isEnabled) {
        prefs.edit().putBoolean(PREF_RESEARCH_LOGGER_ENABLED_FLAG, isEnabled).apply();
    }
}