• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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.server.backup;
18 
19 import android.content.Context;
20 import android.content.SharedPreferences;
21 
22 import java.io.File;
23 import java.util.Collections;
24 import java.util.HashMap;
25 import java.util.HashSet;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.Set;
29 
30 /** Manages the persisted backup preferences per user. */
31 public class UserBackupPreferences {
32     private static final String PREFERENCES_FILE = "backup_preferences";
33 
34     private final SharedPreferences mPreferences;
35     private final SharedPreferences.Editor mEditor;
36 
UserBackupPreferences(Context conext, File storageDir)37     UserBackupPreferences(Context conext, File storageDir) {
38         File excludedKeysFile = new File(storageDir, PREFERENCES_FILE);
39         mPreferences = conext.getSharedPreferences(excludedKeysFile, Context.MODE_PRIVATE);
40         mEditor = mPreferences.edit();
41     }
42 
addExcludedKeys(String packageName, List<String> keys)43     void addExcludedKeys(String packageName, List<String> keys) {
44         Set<String> existingKeys =
45                 new HashSet<>(mPreferences.getStringSet(packageName, Collections.emptySet()));
46         existingKeys.addAll(keys);
47         mEditor.putStringSet(packageName, existingKeys);
48         mEditor.commit();
49     }
50 
getExcludedRestoreKeysForPackage(String packageName)51     Set<String> getExcludedRestoreKeysForPackage(String packageName) {
52         return mPreferences.getStringSet(packageName, Collections.emptySet());
53     }
54 }
55