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);
}
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);
}
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;
}
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;
}
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();
}
Aggregations