Merge branch 'more-clean-up-towards-usb-swap' into 'master'

More clean up towards usb swap

See merge request fdroid/fdroidclient!664
This commit is contained in:
Hans-Christoph Steiner 2018-03-30 12:59:06 +00:00
commit 2d0168215e
7 changed files with 39 additions and 32 deletions

View File

@ -82,8 +82,7 @@ public class IndexV1Updater extends RepoUpdater {
Downloader downloader = null; Downloader downloader = null;
try { try {
// read file name from file // read file name from file
final Uri dataUri = Uri.parse(indexUrl); downloader = DownloaderFactory.create(context, indexUrl);
downloader = DownloaderFactory.create(context, dataUri.toString());
downloader.setCacheTag(repo.lastetag); downloader.setCacheTag(repo.lastetag);
downloader.setListener(downloadListener); downloader.setListener(downloadListener);
downloader.download(); downloader.download();
@ -108,8 +107,7 @@ public class IndexV1Updater extends RepoUpdater {
try { try {
mirrorUrl = FDroidApp.getMirror(prevMirrorUrl, repo); mirrorUrl = FDroidApp.getMirror(prevMirrorUrl, repo);
prevMirrorUrl = mirrorUrl; prevMirrorUrl = mirrorUrl;
Uri dataUri2 = Uri.parse(mirrorUrl); downloader = DownloaderFactory.create(context, mirrorUrl);
downloader = DownloaderFactory.create(context, dataUri2.toString());
downloader.setCacheTag(repo.lastetag); downloader.setCacheTag(repo.lastetag);
downloader.setListener(downloadListener); downloader.setListener(downloadListener);
downloader.setTimeout(FDroidApp.getTimeout()); downloader.setTimeout(FDroidApp.getTimeout());

View File

@ -225,10 +225,8 @@ public class InstalledAppProvider extends FDroidProvider {
QuerySelection query = new QuerySelection(where, whereArgs); QuerySelection query = new QuerySelection(where, whereArgs);
query = query.add(queryAppSubQuery(packageName)); query = query.add(queryAppSubQuery(packageName));
Utils.debugLog(TAG, "Deleting " + packageName);
int count = db().delete(getTableName(), query.getSelection(), query.getArgs()); int count = db().delete(getTableName(), query.getSelection(), query.getArgs());
Utils.debugLog(TAG, "Requesting the suggested apk get recalculated for " + packageName);
AppProvider.Helper.calcSuggestedApk(getContext(), packageName); AppProvider.Helper.calcSuggestedApk(getContext(), packageName);
return count; return count;
@ -252,10 +250,8 @@ public class InstalledAppProvider extends FDroidProvider {
verifyVersionNameNotNull(values); verifyVersionNameNotNull(values);
Utils.debugLog(TAG, "Inserting/updating " + packageName);
db().replaceOrThrow(getTableName(), null, values); db().replaceOrThrow(getTableName(), null, values);
Utils.debugLog(TAG, "Requesting the suggested apk get recalculated for " + packageName);
AppProvider.Helper.calcSuggestedApk(getContext(), packageName); AppProvider.Helper.calcSuggestedApk(getContext(), packageName);
return getAppUri(values.getAsString(Cols.Package.NAME)); return getAppUri(values.getAsString(Cols.Package.NAME));

View File

@ -10,7 +10,6 @@ import android.content.pm.Signature;
import android.net.Uri; import android.net.Uri;
import android.os.Process; import android.os.Process;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.util.Log;
import org.acra.ACRA; import org.acra.ACRA;
import org.fdroid.fdroid.AppUpdateStatusManager; import org.fdroid.fdroid.AppUpdateStatusManager;
import org.fdroid.fdroid.Hasher; import org.fdroid.fdroid.Hasher;
@ -221,7 +220,6 @@ public class InstalledAppProviderService extends IntentService {
if (ACTION_INSERT.equals(action)) { if (ACTION_INSERT.equals(action)) {
PackageInfo packageInfo = getPackageInfo(intent, packageName); PackageInfo packageInfo = getPackageInfo(intent, packageName);
if (packageInfo != null) { if (packageInfo != null) {
Log.i(TAG, "Marking " + packageName + " as installed");
File apk = getPathToInstalledApk(packageInfo); File apk = getPathToInstalledApk(packageInfo);
if (apk == null) { if (apk == null) {
return; return;
@ -255,7 +253,6 @@ public class InstalledAppProviderService extends IntentService {
} }
} }
} else if (ACTION_DELETE.equals(action)) { } else if (ACTION_DELETE.equals(action)) {
Log.i(TAG, "Marking " + packageName + " as no longer installed");
deleteAppFromDb(this, packageName); deleteAppFromDb(this, packageName);
} }
packageChangeNotifier.onNext(packageName); packageChangeNotifier.onNext(packageName);

View File

@ -20,19 +20,14 @@ public class DownloaderFactory {
throws IOException { throws IOException {
File destFile = File.createTempFile("dl-", "", context.getCacheDir()); File destFile = File.createTempFile("dl-", "", context.getCacheDir());
destFile.deleteOnExit(); // this probably does nothing, but maybe... destFile.deleteOnExit(); // this probably does nothing, but maybe...
return create(context, urlString, destFile); Uri uri = Uri.parse(urlString);
return create(context, uri, destFile);
} }
public static Downloader create(Context context, Uri uri, File destFile) public static Downloader create(Context context, Uri uri, File destFile)
throws IOException { throws IOException {
return create(context, uri.toString(), destFile);
}
public static Downloader create(Context context, String urlString, File destFile)
throws IOException {
Downloader downloader; Downloader downloader;
Uri uri = Uri.parse(urlString);
String scheme = uri.getScheme(); String scheme = uri.getScheme();
if ("bluetooth".equals(scheme)) { if ("bluetooth".equals(scheme)) {
downloader = new BluetoothDownloader(uri, destFile); downloader = new BluetoothDownloader(uri, destFile);

View File

@ -241,7 +241,8 @@ public class ManageReposActivity extends AppCompatActivity
for (String url : repo.getMirrorList()) { for (String url : repo.getMirrorList()) {
urlRepoMap.put(url, repo); urlRepoMap.put(url, repo);
} }
if (TextUtils.equals(getRepoType(newAddress), getRepoType(repo.address))) { if (!TextUtils.isEmpty(repo.fingerprint)
&& TextUtils.equals(getRepoType(newAddress), getRepoType(repo.address))) {
fingerprintRepoMap.put(repo.fingerprint, repo); fingerprintRepoMap.put(repo.fingerprint, repo);
} }
} }
@ -296,7 +297,7 @@ public class ManageReposActivity extends AppCompatActivity
try { try {
url = normalizeUrl(url); url = normalizeUrl(url);
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
invalidUrl(null); invalidUrl();
return; return;
} }
@ -411,7 +412,7 @@ public class ManageReposActivity extends AppCompatActivity
} }
if (repo == null) { if (repo == null) {
repoDoesntExist(repo); repoDoesntExist();
} else { } else {
if (repo.isSwap) { if (repo.isSwap) {
repoIsSwap(repo); repoIsSwap(repo);
@ -432,8 +433,8 @@ public class ManageReposActivity extends AppCompatActivity
} }
} }
private void repoDoesntExist(Repo repo) { private void repoDoesntExist() {
updateUi(repo, AddRepoState.DOESNT_EXIST, 0, false, R.string.repo_add_add, true); updateUi(null, AddRepoState.DOESNT_EXIST, 0, false, R.string.repo_add_add, true);
} }
private void repoIsSwap(Repo repo) { private void repoIsSwap(Repo repo) {
@ -450,8 +451,8 @@ public class ManageReposActivity extends AppCompatActivity
true, R.string.overwrite, false); true, R.string.overwrite, false);
} }
private void invalidUrl(Repo repo) { private void invalidUrl() {
updateUi(repo, AddRepoState.INVALID_URL, R.string.invalid_url, true, updateUi(null, AddRepoState.INVALID_URL, R.string.invalid_url, true,
R.string.repo_add_add, false); R.string.repo_add_add, false);
} }
@ -480,8 +481,15 @@ public class ManageReposActivity extends AppCompatActivity
if (addRepoState != state) { if (addRepoState != state) {
addRepoState = state; addRepoState = state;
String name;
if (repo == null) {
name = '"' + getString(R.string.unknown) + '"';
} else {
name = repo.name;
}
if (messageRes > 0) { if (messageRes > 0) {
overwriteMessage.setText(String.format(getString(messageRes), repo.name)); overwriteMessage.setText(String.format(getString(messageRes), name));
overwriteMessage.setVisibility(View.VISIBLE); overwriteMessage.setVisibility(View.VISIBLE);
if (redMessage) { if (redMessage) {
overwriteMessage.setTextColor(getResources().getColor(R.color.red)); overwriteMessage.setTextColor(getResources().getColor(R.color.red));
@ -667,17 +675,24 @@ public class ManageReposActivity extends AppCompatActivity
* Currently it normalizes the path so that "/./" are removed and "test/../" is collapsed. * Currently it normalizes the path so that "/./" are removed and "test/../" is collapsed.
* This is done using {@link URI#normalize()}. It also removes multiple consecutive forward * This is done using {@link URI#normalize()}. It also removes multiple consecutive forward
* slashes in the path and replaces them with one. Finally, it removes trailing slashes. * slashes in the path and replaces them with one. Finally, it removes trailing slashes.
* <p>
* {@code content://} URLs used for repos stored on removable storage get messed up by
* {@link URI}.
*/ */
private String normalizeUrl(String urlString) throws URISyntaxException { private String normalizeUrl(String urlString) throws URISyntaxException {
if (urlString == null) { if (urlString == null) {
return null; return null;
} }
URI uri = new URI(urlString); Uri uri = Uri.parse(urlString);
if (!uri.isAbsolute()) { if (!uri.isAbsolute()) {
throw new URISyntaxException(urlString, "Must provide an absolute URI for repositories"); throw new URISyntaxException(urlString, "Must provide an absolute URI for repositories");
} }
if (!uri.isHierarchical()) {
uri = uri.normalize(); throw new URISyntaxException(urlString, "Must provide an hierarchical URI for repositories");
}
if ("content".equals(uri.getScheme())) {
return uri.toString();
}
String path = uri.getPath(); String path = uri.getPath();
if (path != null) { if (path != null) {
path = path.replaceAll("//*/", "/"); // Collapse multiple forward slashes into 1. path = path.replaceAll("//*/", "/"); // Collapse multiple forward slashes into 1.
@ -685,9 +700,13 @@ public class ManageReposActivity extends AppCompatActivity
path = path.substring(0, path.length() - 1); path = path.substring(0, path.length() - 1);
} }
} }
return new URI(uri.getScheme().toLowerCase(Locale.ENGLISH),
return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getUserInfo(),
path, uri.getQuery(), uri.getFragment()).toString(); uri.getHost().toLowerCase(Locale.ENGLISH),
uri.getPort(),
path,
uri.getQuery(),
uri.getFragment()).normalize().toString();
} }
/** /**

View File

@ -117,6 +117,7 @@ public class ScreenShotsActivity extends AppCompatActivity {
@Nullable Bundle savedInstanceState) { @Nullable Bundle savedInstanceState) {
DisplayImageOptions displayImageOptions = Utils.getDefaultDisplayImageOptionsBuilder() DisplayImageOptions displayImageOptions = Utils.getDefaultDisplayImageOptionsBuilder()
.showImageOnFail(R.drawable.screenshot_placeholder)
.showImageOnLoading(R.drawable.screenshot_placeholder) .showImageOnLoading(R.drawable.screenshot_placeholder)
.showImageForEmptyUri(R.drawable.screenshot_placeholder) .showImageForEmptyUri(R.drawable.screenshot_placeholder)
.build(); .build();

View File

@ -26,6 +26,7 @@ class ScreenShotsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.V
screenshots = app.getAllScreenshots(context); screenshots = app.getAllScreenshots(context);
displayImageOptions = Utils.getDefaultDisplayImageOptionsBuilder() displayImageOptions = Utils.getDefaultDisplayImageOptionsBuilder()
.showImageOnFail(R.drawable.screenshot_placeholder)
.showImageOnLoading(R.drawable.screenshot_placeholder) .showImageOnLoading(R.drawable.screenshot_placeholder)
.showImageForEmptyUri(R.drawable.screenshot_placeholder) .showImageForEmptyUri(R.drawable.screenshot_placeholder)
.build(); .build();