1 /* 2 * Copyright (C) 2017 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 package com.android.documentsui.prefs; 17 18 import android.content.Context; 19 import android.content.SharedPreferences; 20 import android.content.SharedPreferences.Editor; 21 import android.preference.PreferenceManager; 22 23 /** 24 * Methods for accessing the local preferences with regards to scoped directory access. 25 * TODO(b/111892460): Delete this class after Q is released. 26 */ 27 @Deprecated 28 public class ScopedAccessLocalPreferences { 29 30 private static final String TAG = "ScopedAccessLocalPreferences"; 31 getPrefs(Context context)32 private static SharedPreferences getPrefs(Context context) { 33 return PreferenceManager.getDefaultSharedPreferences(context); 34 } 35 36 /** Clears all scoped directory access preferences. */ clearScopedAccessPreferences(Context context)37 public static void clearScopedAccessPreferences(Context context) { 38 final String keySubstring = "|"; 39 final SharedPreferences prefs = getPrefs(context); 40 Editor editor = null; 41 for (final String key : prefs.getAll().keySet()) { 42 if (key.contains(keySubstring)) { 43 if (editor == null) { 44 editor = prefs.edit(); 45 } 46 editor.remove(key); 47 } 48 } 49 if (editor != null) { 50 editor.apply(); 51 } 52 } 53 } 54