ResearchSettings.java revision 75e6fb68e91b440707b399b22fbcfcd67760a949
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 17package com.android.inputmethod.research; 18 19import android.content.SharedPreferences; 20 21import java.util.UUID; 22 23public 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 28 private ResearchSettings() { 29 // Intentional empty constructor for singleton. 30 } 31 32 public static String readResearchLoggerUuid(final SharedPreferences prefs) { 33 if (prefs.contains(PREF_RESEARCH_LOGGER_UUID)) { 34 return prefs.getString(PREF_RESEARCH_LOGGER_UUID, null); 35 } 36 // Generate a random string as uuid if not yet set 37 final String newUuid = UUID.randomUUID().toString(); 38 prefs.edit().putString(PREF_RESEARCH_LOGGER_UUID, newUuid).apply(); 39 return newUuid; 40 } 41 42 public static boolean readResearchLoggerEnabledFlag(final SharedPreferences prefs) { 43 return prefs.getBoolean(PREF_RESEARCH_LOGGER_ENABLED_FLAG, false); 44 } 45 46 public static void writeResearchLoggerEnabledFlag(final SharedPreferences prefs, 47 final boolean isEnabled) { 48 prefs.edit().putBoolean(PREF_RESEARCH_LOGGER_ENABLED_FLAG, isEnabled).apply(); 49 } 50} 51