Пример #1
0
  @Override
  public void retrieveStaleApplications() {
    SubscriptionHelper.unsubscribe(retrievalSubscription);
    retrievalSubscription =
        interactor
            .getAppEntryList()
            .zipWith(
                interactor.getActiveApplicationPackageNames().toList(),
                (allEntries, packageNames) -> {
                  final Set<PadLockEntry.AllEntries> liveLocations = new HashSet<>();
                  final Set<String> stalePackageNames = new HashSet<>();
                  // Remove all active applications from the list of entries
                  for (final String packageName : packageNames) {
                    Timber.i("Look for package: %s", packageName);
                    final List<PadLockEntry.AllEntries> foundLocations = new ArrayList<>();
                    //noinspection Convert2streamapi
                    for (final PadLockEntry.AllEntries entry : allEntries) {
                      if (entry.packageName().equals(packageName)) {
                        foundLocations.add(entry);
                      }
                    }

                    liveLocations.addAll(foundLocations);
                  }

                  // Remove any found locations
                  for (final PadLockEntry.AllEntries liveLocation : liveLocations) {
                    Timber.d(
                        "Remove live location: %s %s",
                        liveLocation.packageName(), liveLocation.activityName());
                    allEntries.remove(liveLocation);
                  }

                  // The remaining entries in the database are stale
                  for (final PadLockEntry.AllEntries entry : allEntries) {
                    Timber.i(
                        "Stale database entry: %s %s", entry.packageName(), entry.activityName());
                    stalePackageNames.add(entry.packageName());
                  }

                  return stalePackageNames;
                })
            .flatMap(Observable::from)
            .sorted(String::compareToIgnoreCase)
            .subscribeOn(getSubscribeScheduler())
            .observeOn(getObserveScheduler())
            .subscribe(
                s -> getView(view -> view.onStaleApplicationRetrieved(s)),
                throwable -> {
                  Timber.e(throwable, "onError retrieveStaleApplications");
                  getView(View::onRetrievalComplete);
                },
                () -> {
                  SubscriptionHelper.unsubscribe(retrievalSubscription);
                  getView(View::onRetrievalComplete);
                });
  }
Пример #2
0
 @Override
 protected void onUnbind() {
   super.onUnbind();
   SubscriptionHelper.unsubscribe(retrievalSubscription);
   unsubStaleDeletes();
 }