• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.systemui.people;
18 
19 import static com.android.systemui.people.PeopleSpaceUtils.INVALID_USER_ID;
20 import static com.android.systemui.people.PeopleSpaceUtils.PACKAGE_NAME;
21 import static com.android.systemui.people.PeopleSpaceUtils.SHORTCUT_ID;
22 import static com.android.systemui.people.PeopleSpaceUtils.USER_ID;
23 
24 import android.content.SharedPreferences;
25 
26 import com.android.systemui.people.widget.PeopleTileKey;
27 
28 /** Helper class for Conversations widgets SharedPreferences storage. */
29 public class SharedPreferencesHelper {
30     /** Clears all storage from {@code sp}. */
clear(SharedPreferences sp)31     public static void clear(SharedPreferences sp) {
32         SharedPreferences.Editor editor = sp.edit();
33         editor.clear();
34         editor.apply();
35     }
36 
37     /** Sets {@code sp}'s storage to identify a {@link PeopleTileKey}. */
setPeopleTileKey(SharedPreferences sp, PeopleTileKey key)38     public static void setPeopleTileKey(SharedPreferences sp, PeopleTileKey key) {
39         setPeopleTileKey(sp, key.getShortcutId(), key.getUserId(), key.getPackageName());
40     }
41 
42     /** Sets {@code sp}'s storage to identify a {@link PeopleTileKey}. */
setPeopleTileKey(SharedPreferences sp, String shortcutId, int userId, String packageName)43     public static void setPeopleTileKey(SharedPreferences sp, String shortcutId, int userId,
44             String packageName) {
45         SharedPreferences.Editor editor = sp.edit();
46         editor.putString(SHORTCUT_ID, shortcutId);
47         editor.putInt(USER_ID, userId);
48         editor.putString(PACKAGE_NAME, packageName);
49         editor.apply();
50     }
51 
52     /** Returns a {@link PeopleTileKey} based on storage from {@code sp}. */
getPeopleTileKey(SharedPreferences sp)53     public static PeopleTileKey getPeopleTileKey(SharedPreferences sp) {
54         String shortcutId = sp.getString(SHORTCUT_ID, null);
55         String packageName = sp.getString(PACKAGE_NAME, null);
56         int userId = sp.getInt(USER_ID, INVALID_USER_ID);
57         return new PeopleTileKey(shortcutId, userId, packageName);
58     }
59 }
60