Search in sources :

Example 1 with PREF_KEY_INTERACTED_PACKAGES

use of com.android.settings.homepage.contextualcards.slices.ContextualNotificationChannelSlice.PREF_KEY_INTERACTED_PACKAGES in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class NotificationChannelWorker method removeUninstalledPackages.

private void removeUninstalledPackages() {
    final SharedPreferences prefs = getContext().getSharedPreferences(PREFS, MODE_PRIVATE);
    final Set<String> interactedPackages = prefs.getStringSet(PREF_KEY_INTERACTED_PACKAGES, new ArraySet());
    if (interactedPackages.isEmpty()) {
        return;
    }
    final List<PackageInfo> installedPackageInfos = getContext().getPackageManager().getInstalledPackages(0);
    final List<String> installedPackages = installedPackageInfos.stream().map(packageInfo -> packageInfo.packageName).collect(Collectors.toList());
    final Set<String> newInteractedPackages = new ArraySet<>();
    for (String packageName : interactedPackages) {
        if (installedPackages.contains(packageName)) {
            newInteractedPackages.add(packageName);
        }
    }
    prefs.edit().putStringSet(PREF_KEY_INTERACTED_PACKAGES, newInteractedPackages).apply();
}
Also used : Context(android.content.Context) PREFS(com.android.settings.homepage.contextualcards.slices.ContextualNotificationChannelSlice.PREFS) SliceBackgroundWorker(com.android.settings.slices.SliceBackgroundWorker) PREF_KEY_INTERACTED_PACKAGES(com.android.settings.homepage.contextualcards.slices.ContextualNotificationChannelSlice.PREF_KEY_INTERACTED_PACKAGES) Uri(android.net.Uri) Set(java.util.Set) IOException(java.io.IOException) PackageInfo(android.content.pm.PackageInfo) Collectors(java.util.stream.Collectors) List(java.util.List) SharedPreferences(android.content.SharedPreferences) MODE_PRIVATE(android.content.Context.MODE_PRIVATE) ArraySet(android.util.ArraySet) ArraySet(android.util.ArraySet) SharedPreferences(android.content.SharedPreferences) PackageInfo(android.content.pm.PackageInfo)

Aggregations

Context (android.content.Context)1 MODE_PRIVATE (android.content.Context.MODE_PRIVATE)1 SharedPreferences (android.content.SharedPreferences)1 PackageInfo (android.content.pm.PackageInfo)1 Uri (android.net.Uri)1 ArraySet (android.util.ArraySet)1 PREFS (com.android.settings.homepage.contextualcards.slices.ContextualNotificationChannelSlice.PREFS)1 PREF_KEY_INTERACTED_PACKAGES (com.android.settings.homepage.contextualcards.slices.ContextualNotificationChannelSlice.PREF_KEY_INTERACTED_PACKAGES)1 SliceBackgroundWorker (com.android.settings.slices.SliceBackgroundWorker)1 IOException (java.io.IOException)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1