• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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;
18 
19 import static android.content.Context.MODE_PRIVATE;
20 
21 import android.content.Context;
22 import android.content.SharedPreferences;
23 import android.util.ArraySet;
24 
25 import androidx.slice.Slice;
26 import androidx.slice.SliceMetadata;
27 import androidx.slice.core.SliceAction;
28 
29 import com.android.settings.SettingsActivity;
30 import com.android.settings.applications.AppInfoBase;
31 import com.android.settings.homepage.contextualcards.slices.ContextualNotificationChannelSlice;
32 import com.android.settings.slices.CustomSliceRegistry;
33 
34 import java.util.Set;
35 
36 public class ContextualCardFeatureProviderImpl implements ContextualCardFeatureProvider {
37     private final Context mContext;
38 
ContextualCardFeatureProviderImpl(Context context)39     public ContextualCardFeatureProviderImpl(Context context) {
40         mContext = context;
41     }
42 
43     @Override
logNotificationPackage(Slice slice)44     public void logNotificationPackage(Slice slice) {
45         if (slice == null || !slice.getUri().equals(
46                 CustomSliceRegistry.CONTEXTUAL_NOTIFICATION_CHANNEL_SLICE_URI)) {
47             return;
48         }
49 
50         final SliceAction primaryAction = SliceMetadata.from(mContext, slice).getPrimaryAction();
51         final String currentPackage = primaryAction.getAction().getIntent()
52                 .getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS)
53                 .getString(AppInfoBase.ARG_PACKAGE_NAME);
54 
55         final SharedPreferences prefs = mContext.getSharedPreferences(
56                 ContextualNotificationChannelSlice.PREFS, MODE_PRIVATE);
57         final Set<String> interactedPackages = prefs.getStringSet(
58                 ContextualNotificationChannelSlice.PREF_KEY_INTERACTED_PACKAGES, new ArraySet<>());
59 
60         final Set<String> newInteractedPackages = new ArraySet<>(interactedPackages);
61         newInteractedPackages.add(currentPackage);
62         prefs.edit().putStringSet(ContextualNotificationChannelSlice.PREF_KEY_INTERACTED_PACKAGES,
63                 newInteractedPackages).apply();
64     }
65 }
66