normalize canonical URL variable names
This commit is contained in:
parent
e346d2351b
commit
6b0a784a26
@ -359,9 +359,9 @@ public final class AppUpdateStatusManager {
|
|||||||
/**
|
/**
|
||||||
* @param pendingIntent Action when notification is clicked. Can be null for default action(s)
|
* @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) {
|
synchronized (appMapping) {
|
||||||
AppUpdateStatus entry = appMapping.get(key);
|
AppUpdateStatus entry = appMapping.get(canonicalUrl);
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
updateApkInternal(entry, status, pendingIntent);
|
updateApkInternal(entry, status, pendingIntent);
|
||||||
}
|
}
|
||||||
@ -369,9 +369,9 @@ public final class AppUpdateStatusManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Apk getApk(String key) {
|
public Apk getApk(String canonicalUrl) {
|
||||||
synchronized (appMapping) {
|
synchronized (appMapping) {
|
||||||
AppUpdateStatus entry = appMapping.get(key);
|
AppUpdateStatus entry = appMapping.get(canonicalUrl);
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
return entry.apk;
|
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}
|
* 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
|
* @see org.fdroid.fdroid.installer.InstallManagerService
|
||||||
*/
|
*/
|
||||||
public void removeApk(String key) {
|
public void removeApk(String canonicalUrl) {
|
||||||
synchronized (appMapping) {
|
synchronized (appMapping) {
|
||||||
InstallManagerService.removePendingInstall(context, key);
|
InstallManagerService.removePendingInstall(context, canonicalUrl);
|
||||||
AppUpdateStatus entry = appMapping.remove(key);
|
AppUpdateStatus entry = appMapping.remove(canonicalUrl);
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
Utils.debugLog(LOGTAG, "Remove APK " + entry.apk.apkName);
|
Utils.debugLog(LOGTAG, "Remove APK " + entry.apk.apkName);
|
||||||
notifyRemove(entry);
|
notifyRemove(entry);
|
||||||
@ -396,9 +396,9 @@ public final class AppUpdateStatusManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshApk(String key) {
|
public void refreshApk(String canonicalUrl) {
|
||||||
synchronized (appMapping) {
|
synchronized (appMapping) {
|
||||||
AppUpdateStatus entry = appMapping.get(key);
|
AppUpdateStatus entry = appMapping.get(canonicalUrl);
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
Utils.debugLog(LOGTAG, "Refresh APK " + entry.apk.apkName);
|
Utils.debugLog(LOGTAG, "Refresh APK " + entry.apk.apkName);
|
||||||
notifyChange(entry, true);
|
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) {
|
synchronized (appMapping) {
|
||||||
AppUpdateStatus entry = appMapping.get(key);
|
AppUpdateStatus entry = appMapping.get(canonicalUrl);
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
entry.progressMax = max;
|
entry.progressMax = max;
|
||||||
entry.progressCurrent = current;
|
entry.progressCurrent = current;
|
||||||
|
@ -464,23 +464,23 @@ 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.getCanonicalUrl();
|
String canonicalUrl = 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, canonicalUrl, apk.packageName);
|
||||||
Utils.debugLog(TAG, "queue " + app.packageName + " " + apk.versionCode + " from " + urlString);
|
Utils.debugLog(TAG, "queue " + app.packageName + " " + apk.versionCode + " from " + canonicalUrl);
|
||||||
Intent intent = new Intent(context, InstallManagerService.class);
|
Intent intent = new Intent(context, InstallManagerService.class);
|
||||||
intent.setAction(ACTION_INSTALL);
|
intent.setAction(ACTION_INSTALL);
|
||||||
intent.setData(Uri.parse(urlString));
|
intent.setData(Uri.parse(canonicalUrl));
|
||||||
intent.putExtra(EXTRA_APP, app);
|
intent.putExtra(EXTRA_APP, app);
|
||||||
intent.putExtra(EXTRA_APK, apk);
|
intent.putExtra(EXTRA_APK, apk);
|
||||||
context.startService(intent);
|
context.startService(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void cancel(Context context, String urlString) {
|
public static void cancel(Context context, String canonicalUrl) {
|
||||||
removePendingInstall(context, urlString);
|
removePendingInstall(context, canonicalUrl);
|
||||||
Intent intent = new Intent(context, InstallManagerService.class);
|
Intent intent = new Intent(context, InstallManagerService.class);
|
||||||
intent.setAction(ACTION_CANCEL);
|
intent.setAction(ACTION_CANCEL);
|
||||||
intent.setData(Uri.parse(urlString));
|
intent.setData(Uri.parse(canonicalUrl));
|
||||||
context.startService(intent);
|
context.startService(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -491,29 +491,29 @@ public class InstallManagerService extends Service {
|
|||||||
* completed, or the device lost power in the middle of the install
|
* completed, or the device lost power in the middle of the install
|
||||||
* process.
|
* process.
|
||||||
*/
|
*/
|
||||||
public boolean isPendingInstall(String urlString) {
|
public boolean isPendingInstall(String canonicalUrl) {
|
||||||
return pendingInstalls.contains(urlString);
|
return pendingInstalls.contains(canonicalUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark a given APK as in the process of being installed, with
|
* 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.
|
* and the file hash used to verify that things are the same.
|
||||||
*
|
*
|
||||||
* @see #isPendingInstall(String)
|
* @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) {
|
if (pendingInstalls == null) {
|
||||||
pendingInstalls = getPendingInstalls(context);
|
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) {
|
if (pendingInstalls == null) {
|
||||||
pendingInstalls = getPendingInstalls(context);
|
pendingInstalls = getPendingInstalls(context);
|
||||||
}
|
}
|
||||||
pendingInstalls.edit().remove(urlString).apply();
|
pendingInstalls.edit().remove(canonicalUrl).apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SharedPreferences getPendingInstalls(Context context) {
|
private static SharedPreferences getPendingInstalls(Context context) {
|
||||||
|
@ -199,9 +199,9 @@ public class DownloaderService extends Service {
|
|||||||
private void handleIntent(Intent intent) {
|
private void handleIntent(Intent intent) {
|
||||||
final Uri uri = intent.getData();
|
final Uri uri = intent.getData();
|
||||||
long repoId = intent.getLongExtra(Downloader.EXTRA_REPO_ID, 0);
|
long repoId = intent.getLongExtra(Downloader.EXTRA_REPO_ID, 0);
|
||||||
String canonicalUrlString = intent.getStringExtra(Downloader.EXTRA_CANONICAL_URL);
|
String canonicalUrl = intent.getStringExtra(Downloader.EXTRA_CANONICAL_URL);
|
||||||
final SanitizedFile localFile = ApkCache.getApkDownloadPath(this, canonicalUrlString);
|
final SanitizedFile localFile = ApkCache.getApkDownloadPath(this, canonicalUrl);
|
||||||
sendBroadcast(uri, Downloader.ACTION_STARTED, localFile, repoId, canonicalUrlString);
|
sendBroadcast(uri, Downloader.ACTION_STARTED, localFile, repoId, canonicalUrl);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
downloader = DownloaderFactory.create(this, uri, localFile);
|
downloader = DownloaderFactory.create(this, uri, localFile);
|
||||||
@ -219,22 +219,22 @@ public class DownloaderService extends Service {
|
|||||||
downloader.download();
|
downloader.download();
|
||||||
if (downloader.isNotFound()) {
|
if (downloader.isNotFound()) {
|
||||||
sendBroadcast(uri, Downloader.ACTION_INTERRUPTED, localFile, getString(R.string.download_404),
|
sendBroadcast(uri, Downloader.ACTION_INTERRUPTED, localFile, getString(R.string.download_404),
|
||||||
repoId, canonicalUrlString);
|
repoId, canonicalUrl);
|
||||||
} else {
|
} else {
|
||||||
sendBroadcast(uri, Downloader.ACTION_COMPLETE, localFile, repoId, canonicalUrlString);
|
sendBroadcast(uri, Downloader.ACTION_COMPLETE, localFile, repoId, canonicalUrl);
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
sendBroadcast(uri, Downloader.ACTION_INTERRUPTED, localFile, repoId, canonicalUrlString);
|
sendBroadcast(uri, Downloader.ACTION_INTERRUPTED, localFile, repoId, canonicalUrl);
|
||||||
} catch (ConnectException | HttpRetryException | NoRouteToHostException | SocketTimeoutException
|
} catch (ConnectException | HttpRetryException | NoRouteToHostException | SocketTimeoutException
|
||||||
| SSLHandshakeException | SSLKeyException | SSLPeerUnverifiedException | SSLProtocolException
|
| SSLHandshakeException | SSLKeyException | SSLPeerUnverifiedException | SSLProtocolException
|
||||||
| ProtocolException | UnknownHostException e) {
|
| ProtocolException | UnknownHostException e) {
|
||||||
// if the above list of exceptions changes, also change it in IndexV1Updater.update()
|
// if the above list of exceptions changes, also change it in IndexV1Updater.update()
|
||||||
Log.e(TAG, e.getLocalizedMessage());
|
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) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
sendBroadcast(uri, Downloader.ACTION_INTERRUPTED, localFile,
|
sendBroadcast(uri, Downloader.ACTION_INTERRUPTED, localFile,
|
||||||
e.getLocalizedMessage(), repoId, canonicalUrlString);
|
e.getLocalizedMessage(), repoId, canonicalUrl);
|
||||||
} finally {
|
} finally {
|
||||||
if (downloader != null) {
|
if (downloader != null) {
|
||||||
downloader.close();
|
downloader.close();
|
||||||
@ -247,8 +247,8 @@ public class DownloaderService extends Service {
|
|||||||
sendBroadcast(uri, action, null, null);
|
sendBroadcast(uri, action, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendBroadcast(Uri uri, String action, File file, long repoId, String originalUrlString) {
|
private void sendBroadcast(Uri uri, String action, File file, long repoId, String canonicalUrl) {
|
||||||
sendBroadcast(uri, action, file, null, repoId, originalUrlString);
|
sendBroadcast(uri, action, file, null, repoId, canonicalUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendBroadcast(Uri uri, String action, File file, String errorMessage) {
|
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,
|
private void sendBroadcast(Uri uri, String action, File file, String errorMessage, long repoId,
|
||||||
String originalUrlString) {
|
String canonicalUrl) {
|
||||||
Intent intent = new Intent(action);
|
Intent intent = new Intent(action);
|
||||||
if (originalUrlString != null) {
|
if (canonicalUrl != null) {
|
||||||
intent.setData(Uri.parse(originalUrlString));
|
intent.setData(Uri.parse(canonicalUrl));
|
||||||
}
|
}
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
intent.putExtra(Downloader.EXTRA_DOWNLOAD_PATH, file.getAbsolutePath());
|
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 context this app's {@link Context}
|
||||||
* @param mirrorUrlString The URL to add to the download queue
|
* @param mirrorUrlString The URL to add to the download queue
|
||||||
* @param repoId the database ID number representing one repo
|
* @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)
|
* @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)) {
|
if (TextUtils.isEmpty(mirrorUrlString)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -292,7 +292,7 @@ public class DownloaderService extends Service {
|
|||||||
intent.setAction(ACTION_QUEUE);
|
intent.setAction(ACTION_QUEUE);
|
||||||
intent.setData(Uri.parse(mirrorUrlString));
|
intent.setData(Uri.parse(mirrorUrlString));
|
||||||
intent.putExtra(Downloader.EXTRA_REPO_ID, repoId);
|
intent.putExtra(Downloader.EXTRA_REPO_ID, repoId);
|
||||||
intent.putExtra(Downloader.EXTRA_CANONICAL_URL, urlString);
|
intent.putExtra(Downloader.EXTRA_CANONICAL_URL, canonicalUrl);
|
||||||
context.startService(intent);
|
context.startService(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user