1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 * except in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the 10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11 * KIND, either express or implied. See the License for the specific language governing 12 * permissions and limitations under the License. 13 */ 14 15 package com.android.systemui.shared.plugins; 16 17 import android.content.Context; 18 import android.content.SharedPreferences; 19 import android.util.ArraySet; 20 21 import java.util.Set; 22 23 /** 24 * Storage for all plugin actions in SharedPreferences. 25 * 26 * This allows the list of actions that the Tuner needs to search for to be generated 27 * instead of hard coded. 28 */ 29 public class PluginPrefs { 30 31 private static final String PREFS = "plugin_prefs"; 32 33 private static final String PLUGIN_ACTIONS = "actions"; 34 private static final String HAS_PLUGINS = "plugins"; 35 36 private final Set<String> mPluginActions; 37 private final SharedPreferences mSharedPrefs; 38 PluginPrefs(Context context)39 public PluginPrefs(Context context) { 40 mSharedPrefs = context.getSharedPreferences(PREFS, 0); 41 mPluginActions = new ArraySet<>(mSharedPrefs.getStringSet(PLUGIN_ACTIONS, null)); 42 } 43 getPluginList()44 public Set<String> getPluginList() { 45 return new ArraySet<>(mPluginActions); 46 } 47 addAction(String action)48 public synchronized void addAction(String action) { 49 if (mPluginActions.add(action)){ 50 mSharedPrefs.edit().putStringSet(PLUGIN_ACTIONS, mPluginActions).apply(); 51 } 52 } 53 hasPlugins(Context context)54 public static boolean hasPlugins(Context context) { 55 return context.getSharedPreferences(PREFS, 0).getBoolean(HAS_PLUGINS, false); 56 } 57 setHasPlugins(Context context)58 public static void setHasPlugins(Context context) { 59 context.getSharedPreferences(PREFS, 0).edit().putBoolean(HAS_PLUGINS, true).apply(); 60 } 61 } 62