• 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.settings.homepage.contextualcards.slices;
18 
19 import static android.content.Context.MODE_PRIVATE;
20 
21 import android.content.Context;
22 import android.net.Uri;
23 import android.util.ArraySet;
24 
25 import com.android.settings.R;
26 import com.android.settings.slices.CustomSliceRegistry;
27 import com.android.settings.slices.SliceBackgroundWorker;
28 
29 import java.util.Set;
30 
31 public class ContextualNotificationChannelSlice extends NotificationChannelSlice {
32 
33     public static final String PREFS = "notification_channel_slice_prefs";
34     public static final String PREF_KEY_INTERACTED_PACKAGES = "interacted_packages";
35 
ContextualNotificationChannelSlice(Context context)36     public ContextualNotificationChannelSlice(Context context) {
37         super(context);
38     }
39 
40     @Override
getUri()41     public Uri getUri() {
42         return CustomSliceRegistry.CONTEXTUAL_NOTIFICATION_CHANNEL_SLICE_URI;
43     }
44 
45     @Override
getSubTitle(String packageName, int uid)46     protected CharSequence getSubTitle(String packageName, int uid) {
47         return mContext.getText(R.string.recently_installed_app);
48     }
49 
50     @Override
isUserInteracted(String packageName)51     protected boolean isUserInteracted(String packageName) {
52         // Check the package has been interacted on current slice or not.
53         final Set<String> interactedPackages =
54                 mContext.getSharedPreferences(PREFS, MODE_PRIVATE)
55                         .getStringSet(PREF_KEY_INTERACTED_PACKAGES, new ArraySet<>());
56         return interactedPackages.contains(packageName);
57     }
58 
59     @Override
getBackgroundWorkerClass()60     public Class<? extends SliceBackgroundWorker> getBackgroundWorkerClass() {
61         return NotificationChannelWorker.class;
62     }
63 }
64