normalize canonical URL variable names

This commit is contained in:
Hans-Christoph Steiner 2019-03-26 13:48:45 +01:00
parent e346d2351b
commit 6b0a784a26
3 changed files with 42 additions and 42 deletions

View File

@ -359,9 +359,9 @@ public final class AppUpdateStatusManager {
/**
* @param pendingIntent Action when notification is clicked. Can be null for default action(s)
*/
public void updateApk(String key, @NonNull Status status, @Nullable PendingIntent pendingIntent) {
public void updateApk(String canonicalUrl, @NonNull Status status, @Nullable PendingIntent pendingIntent) {
synchronized (appMapping) {
AppUpdateStatus entry = appMapping.get(key);
AppUpdateStatus entry = appMapping.get(canonicalUrl);
if (entry != null) {
updateApkInternal(entry, status, pendingIntent);
}
@ -369,9 +369,9 @@ public final class AppUpdateStatusManager {
}
@Nullable
public Apk getApk(String key) {
public Apk getApk(String canonicalUrl) {
synchronized (appMapping) {
AppUpdateStatus entry = appMapping.get(key);
AppUpdateStatus entry = appMapping.get(canonicalUrl);
if (entry != null) {
return entry.apk;
}
@ -382,13 +382,13 @@ public final class AppUpdateStatusManager {
/**
* Remove an APK from being tracked, since it is now considered {@link Status#Installed}
*
* @param key the unique ID for the install process, also called {@code urlString}
* @param canonicalUrl the unique ID for the install process
* @see org.fdroid.fdroid.installer.InstallManagerService
*/
public void removeApk(String key) {
public void removeApk(String canonicalUrl) {
synchronized (appMapping) {
InstallManagerService.removePendingInstall(context, key);
AppUpdateStatus entry = appMapping.remove(key);
InstallManagerService.removePendingInstall(context, canonicalUrl);
AppUpdateStatus entry = appMapping.remove(canonicalUrl);
if (entry != null) {
Utils.debugLog(LOGTAG, "Remove APK " + entry.apk.apkName);
notifyRemove(entry);
@ -396,9 +396,9 @@ public final class AppUpdateStatusManager {
}
}
public void refreshApk(String key) {
public void refreshApk(String canonicalUrl) {
synchronized (appMapping) {
AppUpdateStatus entry = appMapping.get(key);
AppUpdateStatus entry = appMapping.get(canonicalUrl);
if (entry != null) {
Utils.debugLog(LOGTAG, "Refresh APK " + entry.apk.apkName);
notifyChange(entry, true);
@ -406,9 +406,9 @@ public final class AppUpdateStatusManager {
}
}
public void updateApkProgress(String key, long max, long current) {
public void updateApkProgress(String canonicalUrl, long max, long current) {
synchronized (appMapping) {
AppUpdateStatus entry = appMapping.get(key);
AppUpdateStatus entry = appMapping.get(canonicalUrl);
if (entry != null) {
entry.progressMax = max;
entry.progressCurrent = current;

View File

@ -464,23 +464,23 @@ 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.getCanonicalUrl();
String canonicalUrl = 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);
putPendingInstall(context, canonicalUrl, apk.packageName);
Utils.debugLog(TAG, "queue " + app.packageName + " " + apk.versionCode + " from " + canonicalUrl);
Intent intent = new Intent(context, InstallManagerService.class);
intent.setAction(ACTION_INSTALL);
intent.setData(Uri.parse(urlString));
intent.setData(Uri.parse(canonicalUrl));
intent.putExtra(EXTRA_APP, app);
intent.putExtra(EXTRA_APK, apk);
context.startService(intent);
}
public static void cancel(Context context, String urlString) {
removePendingInstall(context, urlString);
public static void cancel(Context context, String canonicalUrl) {
removePendingInstall(context, canonicalUrl);
Intent intent = new Intent(context, InstallManagerService.class);
intent.setAction(ACTION_CANCEL);
intent.setData(Uri.parse(urlString));
intent.setData(Uri.parse(canonicalUrl));
context.startService(intent);
}
@ -491,29 +491,29 @@ public class InstallManagerService extends Service {
* completed, or the device lost power in the middle of the install
* process.
*/
public boolean isPendingInstall(String urlString) {
return pendingInstalls.contains(urlString);
public boolean isPendingInstall(String canonicalUrl) {
return pendingInstalls.contains(canonicalUrl);
}
/**
* Mark a given APK as in the process of being installed, with
* the {@code urlString} of the download used as the unique ID,
* the {@code canonicalUrl} of the download used as the unique ID,
* and the file hash used to verify that things are the same.
*
* @see #isPendingInstall(String)
*/
public static void putPendingInstall(Context context, String urlString, String packageName) {
public static void putPendingInstall(Context context, String canonicalUrl, String packageName) {
if (pendingInstalls == null) {
pendingInstalls = getPendingInstalls(context);
}
pendingInstalls.edit().putString(urlString, packageName).apply();
pendingInstalls.edit().putString(canonicalUrl, packageName).apply();
}
public static void removePendingInstall(Context context, String urlString) {
public static void removePendingInstall(Context context, String canonicalUrl) {
if (pendingInstalls == null) {
pendingInstalls = getPendingInstalls(context);
}
pendingInstalls.edit().remove(urlString).apply();
pendingInstalls.edit().remove(canonicalUrl).apply();
}
private static SharedPreferences getPendingInstalls(Context context) {

View File

@ -199,9 +199,9 @@ public class DownloaderService extends Service {
private void handleIntent(Intent intent) {
final Uri uri = intent.getData();
long repoId = intent.getLongExtra(Downloader.EXTRA_REPO_ID, 0);
String canonicalUrlString = intent.getStringExtra(Downloader.EXTRA_CANONICAL_URL);
final SanitizedFile localFile = ApkCache.getApkDownloadPath(this, canonicalUrlString);
sendBroadcast(uri, Downloader.ACTION_STARTED, localFile, repoId, canonicalUrlString);
String canonicalUrl = intent.getStringExtra(Downloader.EXTRA_CANONICAL_URL);
final SanitizedFile localFile = ApkCache.getApkDownloadPath(this, canonicalUrl);
sendBroadcast(uri, Downloader.ACTION_STARTED, localFile, repoId, canonicalUrl);
try {
downloader = DownloaderFactory.create(this, uri, localFile);
@ -219,22 +219,22 @@ public class DownloaderService extends Service {
downloader.download();
if (downloader.isNotFound()) {
sendBroadcast(uri, Downloader.ACTION_INTERRUPTED, localFile, getString(R.string.download_404),
repoId, canonicalUrlString);
repoId, canonicalUrl);
} else {
sendBroadcast(uri, Downloader.ACTION_COMPLETE, localFile, repoId, canonicalUrlString);
sendBroadcast(uri, Downloader.ACTION_COMPLETE, localFile, repoId, canonicalUrl);
}
} catch (InterruptedException e) {
sendBroadcast(uri, Downloader.ACTION_INTERRUPTED, localFile, repoId, canonicalUrlString);
sendBroadcast(uri, Downloader.ACTION_INTERRUPTED, localFile, repoId, canonicalUrl);
} catch (ConnectException | HttpRetryException | NoRouteToHostException | SocketTimeoutException
| SSLHandshakeException | SSLKeyException | SSLPeerUnverifiedException | SSLProtocolException
| ProtocolException | UnknownHostException e) {
// if the above list of exceptions changes, also change it in IndexV1Updater.update()
Log.e(TAG, e.getLocalizedMessage());
sendBroadcast(uri, Downloader.ACTION_CONNECTION_FAILED, localFile, repoId, canonicalUrlString);
sendBroadcast(uri, Downloader.ACTION_CONNECTION_FAILED, localFile, repoId, canonicalUrl);
} catch (IOException e) {
e.printStackTrace();
sendBroadcast(uri, Downloader.ACTION_INTERRUPTED, localFile,
e.getLocalizedMessage(), repoId, canonicalUrlString);
e.getLocalizedMessage(), repoId, canonicalUrl);
} finally {
if (downloader != null) {
downloader.close();
@ -247,8 +247,8 @@ public class DownloaderService extends Service {
sendBroadcast(uri, action, null, null);
}
private void sendBroadcast(Uri uri, String action, File file, long repoId, String originalUrlString) {
sendBroadcast(uri, action, file, null, repoId, originalUrlString);
private void sendBroadcast(Uri uri, String action, File file, long repoId, String canonicalUrl) {
sendBroadcast(uri, action, file, null, repoId, canonicalUrl);
}
private void sendBroadcast(Uri uri, String action, File file, String errorMessage) {
@ -256,10 +256,10 @@ public class DownloaderService extends Service {
}
private void sendBroadcast(Uri uri, String action, File file, String errorMessage, long repoId,
String originalUrlString) {
String canonicalUrl) {
Intent intent = new Intent(action);
if (originalUrlString != null) {
intent.setData(Uri.parse(originalUrlString));
if (canonicalUrl != null) {
intent.setData(Uri.parse(canonicalUrl));
}
if (file != null) {
intent.putExtra(Downloader.EXTRA_DOWNLOAD_PATH, file.getAbsolutePath());
@ -280,10 +280,10 @@ public class DownloaderService extends Service {
* @param context this app's {@link Context}
* @param mirrorUrlString The URL to add to the download queue
* @param repoId the database ID number representing one repo
* @param urlString the URL used as the unique ID throughout F-Droid
* @param canonicalUrl the URL used as the unique ID throughout F-Droid
* @see #cancel(Context, String)
*/
public static void queue(Context context, String mirrorUrlString, long repoId, String urlString) {
public static void queue(Context context, String mirrorUrlString, long repoId, String canonicalUrl) {
if (TextUtils.isEmpty(mirrorUrlString)) {
return;
}
@ -292,7 +292,7 @@ public class DownloaderService extends Service {
intent.setAction(ACTION_QUEUE);
intent.setData(Uri.parse(mirrorUrlString));
intent.putExtra(Downloader.EXTRA_REPO_ID, repoId);
intent.putExtra(Downloader.EXTRA_CANONICAL_URL, urlString);
intent.putExtra(Downloader.EXTRA_CANONICAL_URL, canonicalUrl);
context.startService(intent);
}