From 930c906460930cb7c3742f0a4f84d72a85a2dcb2 Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Mon, 17 Aug 2015 00:35:35 +1000 Subject: [PATCH] Allow bluetooth:// URLs to be parsed by java.net.URL. Sets a stream handler in FDroidApp which understands bluetooth:// URLs and returns a non-functioning URL handler for such URLs. The reason it is non-funcitoning is because the openConnection() function is not being used by the BluetoothDownloader at this point. In the absense of this, a MalformedURLException is thrown. The bluetooth stuff is still broken, but it is not broken in this way any more. --- F-Droid/src/org/fdroid/fdroid/FDroidApp.java | 16 ++++++++++++++++ F-Droid/src/org/fdroid/fdroid/RepoUpdater.java | 2 +- .../fdroid/fdroid/localrepo/SwapService.java | 3 ++- .../sun/net/www/protocol/bluetooth/Handler.java | 17 +++++++++++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 F-Droid/src/sun/net/www/protocol/bluetooth/Handler.java diff --git a/F-Droid/src/org/fdroid/fdroid/FDroidApp.java b/F-Droid/src/org/fdroid/fdroid/FDroidApp.java index 85cdbe56d..ea3c75d55 100644 --- a/F-Droid/src/org/fdroid/fdroid/FDroidApp.java +++ b/F-Droid/src/org/fdroid/fdroid/FDroidApp.java @@ -33,6 +33,7 @@ import android.content.res.Configuration; import android.net.Uri; import android.os.Build; import android.preference.PreferenceManager; +import android.text.TextUtils; import android.widget.Toast; import com.nostra13.universalimageloader.cache.disc.impl.LimitedAgeDiskCache; @@ -50,9 +51,14 @@ import org.fdroid.fdroid.net.IconDownloader; import org.fdroid.fdroid.net.WifiStateChangeService; import java.io.File; +import java.net.URL; +import java.net.URLStreamHandler; +import java.net.URLStreamHandlerFactory; import java.security.Security; import java.util.Locale; +import sun.net.www.protocol.bluetooth.Handler; + public class FDroidApp extends Application { // for the local repo on this device, all static since there is only one @@ -173,6 +179,16 @@ public class FDroidApp extends Application { } }); + // This is added so that the bluetooth:// scheme we use for URLs the BluetoothDownloader + // understands is not treated as invalid by the java.net.URL class. The actual Handler does + // nothing, but its presence is enough. + URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() { + @Override + public URLStreamHandler createURLStreamHandler(String protocol) { + return TextUtils.equals(protocol, "bluetooth") ? new Handler() : null; + } + }); + // Clear cached apk files. We used to just remove them after they'd // been installed, but this causes problems for proprietary gapps // users since the introduction of verification (on pre-4.2 Android), diff --git a/F-Droid/src/org/fdroid/fdroid/RepoUpdater.java b/F-Droid/src/org/fdroid/fdroid/RepoUpdater.java index 936d2e963..b04d46bf0 100644 --- a/F-Droid/src/org/fdroid/fdroid/RepoUpdater.java +++ b/F-Droid/src/org/fdroid/fdroid/RepoUpdater.java @@ -70,7 +70,7 @@ public class RepoUpdater { public List getApks() { return apks; } - protected URL getIndexAddress() throws MalformedURLException { + private URL getIndexAddress() throws MalformedURLException { String urlString = repo.address + "/index.jar"; try { String versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; diff --git a/F-Droid/src/org/fdroid/fdroid/localrepo/SwapService.java b/F-Droid/src/org/fdroid/fdroid/localrepo/SwapService.java index 8b79eb0df..48f84af94 100644 --- a/F-Droid/src/org/fdroid/fdroid/localrepo/SwapService.java +++ b/F-Droid/src/org/fdroid/fdroid/localrepo/SwapService.java @@ -63,6 +63,7 @@ import java.util.TimerTask; * * TODO: Show "Waiting for other device to finish setting up swap" when only F-Droid shown in swap * TODO: Handle "not connected to wifi" more gracefully. For example, Bonjour discovery falls over. + * TODO: When unable to reach the swap repo, but viewing apps to swap, show relevant feedback when attempting to download and install. * TODO: Remove peers from list of peers when no longer "visible". * TODO: Feedback for "Setting up (wifi|bluetooth)" in start swap view is not as immediate as I had hoped. * TODO: Turn off bluetooth after cancelling/timing out if we turned it on. @@ -70,7 +71,7 @@ import java.util.TimerTask; * * TODO: Starting wifi after cancelling swap and beginning again doesn't work properly * TODO: Scan QR hangs when updating repoo. Swapper was 2.3.3 and Swappee was 5.0 - * + * TODO: Showing the progress bar during install doesn't work when the view is inflated again, or when the adapter is scrolled off screen and back again. */ public class SwapService extends Service { diff --git a/F-Droid/src/sun/net/www/protocol/bluetooth/Handler.java b/F-Droid/src/sun/net/www/protocol/bluetooth/Handler.java new file mode 100644 index 000000000..18ce3d877 --- /dev/null +++ b/F-Droid/src/sun/net/www/protocol/bluetooth/Handler.java @@ -0,0 +1,17 @@ +package sun.net.www.protocol.bluetooth; + +import java.io.IOException; +import java.net.URL; +import java.net.URLConnection; +import java.net.URLStreamHandler; + +/** + * This class is added so that the bluetooth:// scheme we use for the {@link org.fdroid.fdroid.net.BluetoothDownloader} + * is not treated as invalid by the {@link URL} class. + */ +public class Handler extends URLStreamHandler { + @Override + protected URLConnection openConnection(URL u) throws IOException { + throw new UnsupportedOperationException("openConnection() not supported on bluetooth:// URLs"); + } +}