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:
parent
19a0428944
commit
a0b318c383
@ -314,7 +314,7 @@ public class SwapAppsView extends ListView implements
|
||||
}
|
||||
|
||||
if (apk != null) {
|
||||
String urlString = apk.getUrl();
|
||||
String urlString = apk.getCanonicalUrl();
|
||||
|
||||
// TODO unregister receivers? or will they just die with this instance
|
||||
IntentFilter downloadFilter = DownloaderService.getIntentFilter(urlString);
|
||||
|
@ -836,7 +836,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
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,
|
||||
Installer.getInstallIntentFilter(downloadUri));
|
||||
InstallManagerService.queue(this, app, apk);
|
||||
|
@ -133,7 +133,7 @@ public final class AppUpdateStatusManager {
|
||||
* @see org.fdroid.fdroid.installer.InstallManagerService
|
||||
*/
|
||||
public String getUniqueKey() {
|
||||
return apk.getUrl();
|
||||
return apk.getCanonicalUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -321,7 +321,7 @@ public final class AppUpdateStatusManager {
|
||||
ContentResolver resolver = context.getContentResolver();
|
||||
App app = AppProvider.Helper.findSpecificApp(resolver, apk.packageName, apk.repoId);
|
||||
AppUpdateStatus ret = new AppUpdateStatus(app, apk, status, intent);
|
||||
appMapping.put(apk.getUrl(), ret);
|
||||
appMapping.put(apk.getCanonicalUrl(), ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@ -347,7 +347,7 @@ public final class AppUpdateStatusManager {
|
||||
}
|
||||
|
||||
synchronized (appMapping) {
|
||||
AppUpdateStatus entry = appMapping.get(apk.getUrl());
|
||||
AppUpdateStatus entry = appMapping.get(apk.getCanonicalUrl());
|
||||
if (entry != null) {
|
||||
updateApkInternal(entry, status, pendingIntent);
|
||||
} else {
|
||||
@ -435,7 +435,7 @@ public final class AppUpdateStatusManager {
|
||||
|
||||
public void setApkError(Apk apk, String errorText) {
|
||||
synchronized (appMapping) {
|
||||
AppUpdateStatus entry = appMapping.get(apk.getUrl());
|
||||
AppUpdateStatus entry = appMapping.get(apk.getCanonicalUrl());
|
||||
if (entry == null) {
|
||||
entry = createAppEntry(apk, Status.InstallError, null);
|
||||
}
|
||||
|
@ -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()
|
||||
public String getUrl() {
|
||||
public String getCanonicalUrl() {
|
||||
checkRepoAddress();
|
||||
return repoAddress + "/" + apkName.replace(" ", "%20");
|
||||
}
|
||||
@ -527,7 +536,7 @@ public class Apk extends ValueObject implements Comparable<Apk>, Parcelable {
|
||||
public File getMediaInstallPath(Context context) {
|
||||
File path = Environment.getExternalStoragePublicDirectory(
|
||||
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;
|
||||
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
|
||||
String[] mimeType = mimeTypeMap.getMimeTypeFromExtension(fileExtension).split("/");
|
||||
|
@ -209,7 +209,7 @@ public class InstallManagerService extends Service {
|
||||
getObb(urlString, apk.getMainObbUrl(), apk.getMainObbFile(), apk.obbMainFileSha256);
|
||||
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();
|
||||
if (!apkFilePath.exists() || apkFileSize < apk.size) {
|
||||
Utils.debugLog(TAG, "download " + urlString + " " + apkFilePath);
|
||||
@ -464,7 +464,7 @@ public class InstallManagerService extends Service {
|
||||
* @param context this app's {@link Context}
|
||||
*/
|
||||
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);
|
||||
putPendingInstall(context, urlString, apk.packageName);
|
||||
Utils.debugLog(TAG, "queue " + app.packageName + " " + apk.versionCode + " from " + urlString);
|
||||
|
@ -483,9 +483,9 @@ public abstract class AppListItemController extends RecyclerView.ViewHolder {
|
||||
}
|
||||
|
||||
if (currentStatus != null && currentStatus.status == AppUpdateStatusManager.Status.ReadyToInstall) {
|
||||
String urlString = currentStatus.apk.getUrl();
|
||||
String urlString = currentStatus.apk.getCanonicalUrl();
|
||||
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);
|
||||
|
||||
final LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(activity);
|
||||
|
@ -73,7 +73,7 @@ public class KnownVulnAppListItemController extends AppListItemController {
|
||||
Apk suggestedApk = ApkProvider.Helper.findSuggestedApk(activity, app);
|
||||
if (shouldUpgradeInsteadOfUninstall(app, suggestedApk)) {
|
||||
LocalBroadcastManager manager = LocalBroadcastManager.getInstance(activity);
|
||||
Uri uri = Uri.parse(suggestedApk.getUrl());
|
||||
Uri uri = Uri.parse(suggestedApk.getCanonicalUrl());
|
||||
manager.registerReceiver(installReceiver, Installer.getInstallIntentFilter(uri));
|
||||
InstallManagerService.queue(activity, app, suggestedApk);
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user