Home | History | Annotate | Download | only in research
      1 /*
      2  * Copyright (C) 2013 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.inputmethod.research;
     18 
     19 import android.content.SharedPreferences;
     20 
     21 import java.util.UUID;
     22 
     23 public final class ResearchSettings {
     24     public static final String PREF_RESEARCH_LOGGER_UUID = "pref_research_logger_uuid";
     25     public static final String PREF_RESEARCH_LOGGER_ENABLED_FLAG =
     26             "pref_research_logger_enabled_flag";
     27     public static final String PREF_RESEARCH_LOGGER_HAS_SEEN_SPLASH =
     28             "pref_research_logger_has_seen_splash";
     29     public static final String PREF_RESEARCH_LAST_DIR_CLEANUP_TIME =
     30             "pref_research_last_dir_cleanup_time";
     31 
     32     private ResearchSettings() {
     33         // Intentional empty constructor for singleton.
     34     }
     35 
     36     public static String readResearchLoggerUuid(final SharedPreferences prefs) {
     37         if (prefs.contains(PREF_RESEARCH_LOGGER_UUID)) {
     38             return prefs.getString(PREF_RESEARCH_LOGGER_UUID, null);
     39         }
     40         // Generate a random string as uuid if not yet set
     41         final String newUuid = UUID.randomUUID().toString();
     42         prefs.edit().putString(PREF_RESEARCH_LOGGER_UUID, newUuid).apply();
     43         return newUuid;
     44     }
     45 
     46     public static boolean readResearchLoggerEnabledFlag(final SharedPreferences prefs) {
     47         return prefs.getBoolean(PREF_RESEARCH_LOGGER_ENABLED_FLAG, false);
     48     }
     49 
     50     public static void writeResearchLoggerEnabledFlag(final SharedPreferences prefs,
     51             final boolean isEnabled) {
     52         prefs.edit().putBoolean(PREF_RESEARCH_LOGGER_ENABLED_FLAG, isEnabled).apply();
     53     }
     54 
     55     public static boolean readHasSeenSplash(final SharedPreferences prefs) {
     56         return prefs.getBoolean(PREF_RESEARCH_LOGGER_HAS_SEEN_SPLASH, false);
     57     }
     58 
     59     public static void writeHasSeenSplash(final SharedPreferences prefs,
     60             final boolean hasSeenSplash) {
     61         prefs.edit().putBoolean(PREF_RESEARCH_LOGGER_HAS_SEEN_SPLASH, hasSeenSplash).apply();
     62     }
     63 
     64     public static long readResearchLastDirCleanupTime(final SharedPreferences prefs) {
     65         return prefs.getLong(PREF_RESEARCH_LAST_DIR_CLEANUP_TIME, 0L);
     66     }
     67 
     68     public static void writeResearchLastDirCleanupTime(final SharedPreferences prefs,
     69             final long lastDirCleanupTime) {
     70         prefs.edit().putLong(PREF_RESEARCH_LAST_DIR_CLEANUP_TIME, lastDirCleanupTime).apply();
     71     }
     72 }
     73