rename Apk.getUrl() to getCanonicalUrl() to highlight it is also an ID

This method returns the URL that points to the canonical download
source for this package.  This is also used as the unique ID for
tracking downloading, progress, and notifications throughout the
whole install process.  It is guaranteed to uniquely represent
this file since it points to a file on the file system of the
canonical webserver.
This commit is contained in:
Hans-Christoph Steiner 2019-03-26 12:07:46 +01:00
parent 19a0428944
commit a0b318c383
7 changed files with 22 additions and 13 deletions

View File

@ -314,7 +314,7 @@ public class SwapAppsView extends ListView implements
} }
if (apk != null) { if (apk != null) {
String urlString = apk.getUrl(); String urlString = apk.getCanonicalUrl();
// TODO unregister receivers? or will they just die with this instance // TODO unregister receivers? or will they just die with this instance
IntentFilter downloadFilter = DownloaderService.getIntentFilter(urlString); IntentFilter downloadFilter = DownloaderService.getIntentFilter(urlString);

View File

@ -836,7 +836,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
} }
public void install(@NonNull final App app, @NonNull final Apk apk) { public void install(@NonNull final App app, @NonNull final Apk apk) {
Uri downloadUri = Uri.parse(apk.getUrl()); Uri downloadUri = Uri.parse(apk.getCanonicalUrl());
localBroadcastManager.registerReceiver(installReceiver, localBroadcastManager.registerReceiver(installReceiver,
Installer.getInstallIntentFilter(downloadUri)); Installer.getInstallIntentFilter(downloadUri));
InstallManagerService.queue(this, app, apk); InstallManagerService.queue(this, app, apk);

View File

@ -133,7 +133,7 @@ public final class AppUpdateStatusManager {
* @see org.fdroid.fdroid.installer.InstallManagerService * @see org.fdroid.fdroid.installer.InstallManagerService
*/ */
public String getUniqueKey() { public String getUniqueKey() {
return apk.getUrl(); return apk.getCanonicalUrl();
} }
/** /**
@ -321,7 +321,7 @@ public final class AppUpdateStatusManager {
ContentResolver resolver = context.getContentResolver(); ContentResolver resolver = context.getContentResolver();
App app = AppProvider.Helper.findSpecificApp(resolver, apk.packageName, apk.repoId); App app = AppProvider.Helper.findSpecificApp(resolver, apk.packageName, apk.repoId);
AppUpdateStatus ret = new AppUpdateStatus(app, apk, status, intent); AppUpdateStatus ret = new AppUpdateStatus(app, apk, status, intent);
appMapping.put(apk.getUrl(), ret); appMapping.put(apk.getCanonicalUrl(), ret);
return ret; return ret;
} }
} }
@ -347,7 +347,7 @@ public final class AppUpdateStatusManager {
} }
synchronized (appMapping) { synchronized (appMapping) {
AppUpdateStatus entry = appMapping.get(apk.getUrl()); AppUpdateStatus entry = appMapping.get(apk.getCanonicalUrl());
if (entry != null) { if (entry != null) {
updateApkInternal(entry, status, pendingIntent); updateApkInternal(entry, status, pendingIntent);
} else { } else {
@ -435,7 +435,7 @@ public final class AppUpdateStatusManager {
public void setApkError(Apk apk, String errorText) { public void setApkError(Apk apk, String errorText) {
synchronized (appMapping) { synchronized (appMapping) {
AppUpdateStatus entry = appMapping.get(apk.getUrl()); AppUpdateStatus entry = appMapping.get(apk.getCanonicalUrl());
if (entry == null) { if (entry == null) {
entry = createAppEntry(apk, Status.InstallError, null); entry = createAppEntry(apk, Status.InstallError, null);
} }

View File

@ -263,8 +263,17 @@ public class Apk extends ValueObject implements Comparable<Apk>, Parcelable {
} }
} }
/**
* Get the URL that points to the canonical download source for this
* package. This is also used as the unique ID for tracking downloading,
* progress, and notifications throughout the whole install process. It
* is guaranteed to uniquely represent this file since it points to a file
* on the file system of the canonical webserver.
*
* @see org.fdroid.fdroid.installer.InstallManagerService
*/
@JsonIgnore // prevent tests from failing due to nulls in checkRepoAddress() @JsonIgnore // prevent tests from failing due to nulls in checkRepoAddress()
public String getUrl() { public String getCanonicalUrl() {
checkRepoAddress(); checkRepoAddress();
return repoAddress + "/" + apkName.replace(" ", "%20"); return repoAddress + "/" + apkName.replace(" ", "%20");
} }
@ -527,7 +536,7 @@ public class Apk extends ValueObject implements Comparable<Apk>, Parcelable {
public File getMediaInstallPath(Context context) { public File getMediaInstallPath(Context context) {
File path = Environment.getExternalStoragePublicDirectory( File path = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS); // Default for all other non-apk/media files Environment.DIRECTORY_DOWNLOADS); // Default for all other non-apk/media files
String fileExtension = MimeTypeMap.getFileExtensionFromUrl(this.getUrl()); String fileExtension = MimeTypeMap.getFileExtensionFromUrl(this.getCanonicalUrl());
if (TextUtils.isEmpty(fileExtension)) return path; if (TextUtils.isEmpty(fileExtension)) return path;
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton(); MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
String[] mimeType = mimeTypeMap.getMimeTypeFromExtension(fileExtension).split("/"); String[] mimeType = mimeTypeMap.getMimeTypeFromExtension(fileExtension).split("/");

View File

@ -209,7 +209,7 @@ public class InstallManagerService extends Service {
getObb(urlString, apk.getMainObbUrl(), apk.getMainObbFile(), apk.obbMainFileSha256); getObb(urlString, apk.getMainObbUrl(), apk.getMainObbFile(), apk.obbMainFileSha256);
getObb(urlString, apk.getPatchObbUrl(), apk.getPatchObbFile(), apk.obbPatchFileSha256); getObb(urlString, apk.getPatchObbUrl(), apk.getPatchObbFile(), apk.obbPatchFileSha256);
File apkFilePath = ApkCache.getApkDownloadPath(this, apk.getUrl()); File apkFilePath = ApkCache.getApkDownloadPath(this, apk.getCanonicalUrl());
long apkFileSize = apkFilePath.length(); long apkFileSize = apkFilePath.length();
if (!apkFilePath.exists() || apkFileSize < apk.size) { if (!apkFilePath.exists() || apkFileSize < apk.size) {
Utils.debugLog(TAG, "download " + urlString + " " + apkFilePath); Utils.debugLog(TAG, "download " + urlString + " " + apkFilePath);
@ -464,7 +464,7 @@ public class InstallManagerService extends Service {
* @param context this app's {@link Context} * @param context this app's {@link Context}
*/ */
public static void queue(Context context, App app, @NonNull Apk apk) { public static void queue(Context context, App app, @NonNull Apk apk) {
String urlString = apk.getUrl(); String urlString = apk.getCanonicalUrl();
AppUpdateStatusManager.getInstance(context).addApk(apk, AppUpdateStatusManager.Status.PendingInstall, null); AppUpdateStatusManager.getInstance(context).addApk(apk, AppUpdateStatusManager.Status.PendingInstall, null);
putPendingInstall(context, urlString, apk.packageName); putPendingInstall(context, urlString, apk.packageName);
Utils.debugLog(TAG, "queue " + app.packageName + " " + apk.versionCode + " from " + urlString); Utils.debugLog(TAG, "queue " + app.packageName + " " + apk.versionCode + " from " + urlString);

View File

@ -483,9 +483,9 @@ public abstract class AppListItemController extends RecyclerView.ViewHolder {
} }
if (currentStatus != null && currentStatus.status == AppUpdateStatusManager.Status.ReadyToInstall) { if (currentStatus != null && currentStatus.status == AppUpdateStatusManager.Status.ReadyToInstall) {
String urlString = currentStatus.apk.getUrl(); String urlString = currentStatus.apk.getCanonicalUrl();
File apkFilePath = ApkCache.getApkDownloadPath(activity, urlString); File apkFilePath = ApkCache.getApkDownloadPath(activity, urlString);
Utils.debugLog(TAG, "skip download, we have already downloaded " + currentStatus.apk.getUrl() + Utils.debugLog(TAG, "skip download, we have already downloaded " + currentStatus.apk.getCanonicalUrl() +
" to " + apkFilePath); " to " + apkFilePath);
final LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(activity); final LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(activity);

View File

@ -73,7 +73,7 @@ public class KnownVulnAppListItemController extends AppListItemController {
Apk suggestedApk = ApkProvider.Helper.findSuggestedApk(activity, app); Apk suggestedApk = ApkProvider.Helper.findSuggestedApk(activity, app);
if (shouldUpgradeInsteadOfUninstall(app, suggestedApk)) { if (shouldUpgradeInsteadOfUninstall(app, suggestedApk)) {
LocalBroadcastManager manager = LocalBroadcastManager.getInstance(activity); LocalBroadcastManager manager = LocalBroadcastManager.getInstance(activity);
Uri uri = Uri.parse(suggestedApk.getUrl()); Uri uri = Uri.parse(suggestedApk.getCanonicalUrl());
manager.registerReceiver(installReceiver, Installer.getInstallIntentFilter(uri)); manager.registerReceiver(installReceiver, Installer.getInstallIntentFilter(uri));
InstallManagerService.queue(activity, app, suggestedApk); InstallManagerService.queue(activity, app, suggestedApk);
} else { } else {