Search in sources :

Example 1 with AppUpdateStatusManager

use of org.fdroid.fdroid.AppUpdateStatusManager in project fdroidclient by f-droid.

the class InstalledAppProviderService method onHandleWork.

@Override
protected void onHandleWork(@NonNull Intent intent) {
    Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST);
    AppUpdateStatusManager ausm = AppUpdateStatusManager.getInstance(this);
    String packageName = intent.getData().getSchemeSpecificPart();
    final String action = intent.getAction();
    if (ACTION_INSERT.equals(action)) {
        PackageInfo packageInfo = getPackageInfo(intent, packageName);
        if (packageInfo != null) {
            for (AppUpdateStatusManager.AppUpdateStatus status : ausm.getByPackageName(packageName)) {
                ausm.updateApk(status.getCanonicalUrl(), AppUpdateStatusManager.Status.Installed, null);
            }
            File apk = getPathToInstalledApk(packageInfo);
            if (apk == null) {
                return;
            }
            if (apk.exists() && apk.canRead()) {
                try {
                    String hashType = "sha256";
                    String hash = Utils.getFileHexDigest(apk, hashType);
                    insertAppIntoDb(this, packageInfo, hashType, hash);
                } catch (IllegalArgumentException e) {
                    Utils.debugLog(TAG, e.getMessage());
                    ACRA.getErrorReporter().handleException(e, false);
                    return;
                }
            }
        }
    } else if (ACTION_DELETE.equals(action)) {
        deleteAppFromDb(this, packageName);
        for (AppUpdateStatusManager.AppUpdateStatus status : ausm.getByPackageName(packageName)) {
            ausm.updateApk(status.getCanonicalUrl(), AppUpdateStatusManager.Status.InstallError, null);
        }
    }
    packageChangeNotifier.onNext(packageName);
}
Also used : PackageInfo(android.content.pm.PackageInfo) AppUpdateStatusManager(org.fdroid.fdroid.AppUpdateStatusManager) File(java.io.File)

Example 2 with AppUpdateStatusManager

use of org.fdroid.fdroid.AppUpdateStatusManager in project fdroidclient by f-droid.

the class AppStatusListItemController method onDismissApp.

@NonNull
@Override
protected DismissResult onDismissApp(@NonNull App app) {
    AppUpdateStatus status = getCurrentStatus();
    CharSequence message = null;
    if (status != null) {
        AppUpdateStatusManager manager = AppUpdateStatusManager.getInstance(activity);
        manager.removeApk(status.getUniqueKey());
        switch(status.status) {
            case ReadyToInstall:
                manager.markAsNoLongerPendingInstall(status);
                // of a "Ready to install" app being dismissed.
                break;
            case Downloading:
                cancelDownload();
                message = activity.getString(R.string.app_list__dismiss_downloading_app);
                break;
        }
    }
    return new DismissResult(message, true);
}
Also used : DismissResult(org.fdroid.fdroid.views.updates.DismissResult) AppUpdateStatus(org.fdroid.fdroid.AppUpdateStatusManager.AppUpdateStatus) AppUpdateStatusManager(org.fdroid.fdroid.AppUpdateStatusManager) NonNull(android.support.annotation.NonNull)

Example 3 with AppUpdateStatusManager

use of org.fdroid.fdroid.AppUpdateStatusManager in project fdroidclient by f-droid.

the class AppDetailsActivity method refreshStatus.

/**
 * Figures out the current install/update/download/etc status for the app we are viewing.
 * Then, asks the view to update itself to reflect this status.
 */
private void refreshStatus() {
    AppUpdateStatusManager ausm = AppUpdateStatusManager.getInstance(this);
    Iterator<AppUpdateStatusManager.AppUpdateStatus> statuses = ausm.getByPackageName(app.packageName).iterator();
    if (statuses.hasNext()) {
        AppUpdateStatusManager.AppUpdateStatus status = statuses.next();
        updateAppStatus(status, false);
    }
    currentStatus = null;
}
Also used : AppUpdateStatusManager(org.fdroid.fdroid.AppUpdateStatusManager)

Example 4 with AppUpdateStatusManager

use of org.fdroid.fdroid.AppUpdateStatusManager in project fdroidclient by f-droid.

the class AppDetailsActivity method resetCurrentApp.

/**
 * Reset the display and list contents. Used when entering the activity, and
 * also when something has been installed/uninstalled.  An index update or
 * other external factors might have changed since {@code app} was set
 * before.  This also removes all pending installs with
 * {@link AppUpdateStatusManager.Status#Installed Installed}
 * status for this {@code packageName}, to prevent any lingering open ones from
 * messing up any action that the user might take.  They sometimes might not get
 * removed while F-Droid was in the background.
 * <p>
 * Shows a {@link Toast} if no {@link App} was found matching {@code packageName}.
 *
 * @return whether the {@link App} for a given {@code packageName} is still available
 */
private boolean resetCurrentApp(String packageName) {
    if (TextUtils.isEmpty(packageName)) {
        return false;
    }
    app = AppProvider.Helper.findHighestPriorityMetadata(getContentResolver(), packageName);
    // 
    AppUpdateStatusManager ausm = AppUpdateStatusManager.getInstance(this);
    for (AppUpdateStatusManager.AppUpdateStatus status : ausm.getByPackageName(packageName)) {
        if (status.status == AppUpdateStatusManager.Status.Installed) {
            ausm.removeApk(status.getCanonicalUrl());
        }
    }
    if (app == null) {
        Toast.makeText(this, R.string.no_such_app, Toast.LENGTH_LONG).show();
        return false;
    }
    return true;
}
Also used : AppUpdateStatusManager(org.fdroid.fdroid.AppUpdateStatusManager)

Example 5 with AppUpdateStatusManager

use of org.fdroid.fdroid.AppUpdateStatusManager in project fdroidclient by f-droid.

the class UpdatesAdapter method populateAppStatuses.

/**
 * Adds items from the {@link AppUpdateStatusManager} to {@link UpdatesAdapter#appsToShowStatus}.
 * Note that this will then subsequently rebuild the underlying adapter data structure by
 * invoking {@link UpdatesAdapter#populateItems}. However as per the populateItems method, it
 * does not know how best to notify the recycler view of any changes. That is up to the caller
 * of this method.
 */
private void populateAppStatuses() {
    for (AppUpdateStatusManager.AppUpdateStatus status : AppUpdateStatusManager.getInstance(activity).getAll()) {
        if (shouldShowStatus(status)) {
            appsToShowStatus.add(new AppStatus(activity, status));
        }
    }
    Collections.sort(appsToShowStatus, new Comparator<AppStatus>() {

        @Override
        public int compare(AppStatus o1, AppStatus o2) {
            return o1.status.app.name.compareTo(o2.status.app.name);
        }
    });
    populateItems();
}
Also used : AppStatus(org.fdroid.fdroid.views.updates.items.AppStatus) AppUpdateStatusManager(org.fdroid.fdroid.AppUpdateStatusManager)

Aggregations

AppUpdateStatusManager (org.fdroid.fdroid.AppUpdateStatusManager)6 AppUpdateStatus (org.fdroid.fdroid.AppUpdateStatusManager.AppUpdateStatus)2 PackageInfo (android.content.pm.PackageInfo)1 NonNull (android.support.annotation.NonNull)1 View (android.view.View)1 File (java.io.File)1 DismissResult (org.fdroid.fdroid.views.updates.DismissResult)1 AppStatus (org.fdroid.fdroid.views.updates.items.AppStatus)1