use Android constants for common URI schemes

This makes the code easier to trace.
This commit is contained in:
Hans-Christoph Steiner 2018-08-10 11:58:09 +02:00
parent d8e8cc82f1
commit 59befbd355
2 changed files with 7 additions and 5 deletions

View File

@ -23,6 +23,7 @@ package org.fdroid.fdroid.installer;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.ContentResolver;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.net.Uri; import android.net.Uri;
@ -78,11 +79,11 @@ public class DefaultInstallerActivity extends FragmentActivity {
} }
// https://code.google.com/p/android/issues/detail?id=205827 // https://code.google.com/p/android/issues/detail?id=205827
if ((Build.VERSION.SDK_INT < 24) if ((Build.VERSION.SDK_INT < 24)
&& (!uri.getScheme().equals("file"))) { && (!ContentResolver.SCHEME_FILE.equals(uri.getScheme()))) {
throw new RuntimeException("PackageInstaller < Android N only supports file scheme!"); throw new RuntimeException("PackageInstaller < Android N only supports file scheme!");
} }
if ((Build.VERSION.SDK_INT >= 24) if ((Build.VERSION.SDK_INT >= 24)
&& (!uri.getScheme().equals("content"))) { && (!ContentResolver.SCHEME_CONTENT.equals(uri.getScheme()))) {
throw new RuntimeException("PackageInstaller >= Android N only supports content scheme!"); throw new RuntimeException("PackageInstaller >= Android N only supports content scheme!");
} }

View File

@ -1,5 +1,6 @@
package org.fdroid.fdroid.net; package org.fdroid.fdroid.net;
import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.net.Uri; import android.net.Uri;
import org.fdroid.fdroid.data.Repo; import org.fdroid.fdroid.data.Repo;
@ -29,11 +30,11 @@ public class DownloaderFactory {
Downloader downloader; Downloader downloader;
String scheme = uri.getScheme(); String scheme = uri.getScheme();
if ("bluetooth".equals(scheme)) { if (BluetoothDownloader.SCHEME.equals(scheme)) {
downloader = new BluetoothDownloader(uri, destFile); downloader = new BluetoothDownloader(uri, destFile);
} else if ("content".equals(scheme)) { } else if (ContentResolver.SCHEME_CONTENT.equals(scheme)) {
downloader = new TreeUriDownloader(uri, destFile); downloader = new TreeUriDownloader(uri, destFile);
} else if ("file".equals(scheme)) { } else if (ContentResolver.SCHEME_FILE.equals(scheme)) {
downloader = new LocalFileDownloader(uri, destFile); downloader = new LocalFileDownloader(uri, destFile);
} else { } else {
final String[] projection = {Schema.RepoTable.Cols.USERNAME, Schema.RepoTable.Cols.PASSWORD}; final String[] projection = {Schema.RepoTable.Cols.USERNAME, Schema.RepoTable.Cols.PASSWORD};