Browse Source

Choose connection address (hostname or ip) based on locally connected wifi network.

pull/11/head
Eric Kok 11 years ago
parent
commit
b7860c3d5e
  1. 4
      core/res/values/strings.xml
  2. 3
      core/res/xml/pref_server.xml
  3. 30
      core/src/org/transdroid/core/app/settings/ServerSetting.java
  4. 5
      core/src/org/transdroid/core/gui/DetailsActivity.java
  5. 7
      core/src/org/transdroid/core/gui/TorrentsActivity.java
  6. 2
      core/src/org/transdroid/core/service/AppUpdateService.java
  7. 11
      core/src/org/transdroid/core/service/ConnectivityHelper.java
  8. 2
      core/src/org/transdroid/core/service/RssCheckerService.java
  9. 4
      core/src/org/transdroid/core/service/ServerCheckerService.java
  10. 1
      full/AndroidManifest.xml
  11. 8
      lib/src/org/transdroid/daemon/Daemon.java
  12. 1
      lite/AndroidManifest.xml

4
core/res/values/strings.xml

@ -278,10 +278,10 @@
<item>Buffalo NAS -1.31</item> <item>Buffalo NAS -1.31</item>
<item>Deluge 1.2+</item> <item>Deluge 1.2+</item>
<item>DLink Router BT</item> <item>DLink Router BT</item>
<item>Dummy</item>
<item>Ktorrent</item> <item>Ktorrent</item>
<item>qBittorrent</item> <item>qBittorrent</item>
<item>rTorrent</item> <item>rTorrent</item>
<item>Synology</item>
<item>Torrentflux-b4rt</item> <item>Torrentflux-b4rt</item>
<item>Transmission</item> <item>Transmission</item>
<item>µTorrent</item> <item>µTorrent</item>
@ -294,10 +294,10 @@
<item>daemon_buffalonas</item> <item>daemon_buffalonas</item>
<item>daemon_deluge</item> <item>daemon_deluge</item>
<item>daemon_dlinkrouterbt</item> <item>daemon_dlinkrouterbt</item>
<item>daemon_dummy</item>
<item>daemon_ktorrent</item> <item>daemon_ktorrent</item>
<item>daemon_qbittorrent</item> <item>daemon_qbittorrent</item>
<item>daemon_rtorrent</item> <item>daemon_rtorrent</item>
<item>daemon_synology</item>
<item>daemon_tfb4rt</item> <item>daemon_tfb4rt</item>
<item>daemon_transmission</item> <item>daemon_transmission</item>
<item>daemon_utorrent</item> <item>daemon_utorrent</item>

3
core/res/xml/pref_server.xml

@ -57,7 +57,8 @@
<EditTextPreference <EditTextPreference
android:key="server_localnetwork" android:key="server_localnetwork"
android:title="@string/pref_localnetwork" android:title="@string/pref_localnetwork"
android:summary="@string/pref_localnetwork_info" /> android:summary="@string/pref_localnetwork_info"
android:inputType="textNoSuggestions" />
<EditTextPreference <EditTextPreference
android:key="server_folder" android:key="server_folder"
android:title="@string/pref_folder" android:title="@string/pref_folder"

30
core/src/org/transdroid/core/app/settings/ServerSetting.java

@ -250,20 +250,28 @@ public class ServerSetting implements SimpleListItem {
/** /**
* Returns the appropriate daemon adapter to which tasks can be executed, in accordance with this server's settings * Returns the appropriate daemon adapter to which tasks can be executed, in accordance with this server's settings
* @param connectedToNetwork The name of the (wifi) network we are currently connected to, or null if this could not
* be determined
* @return An IDaemonAdapter instance of the specific torrent client daemon type * @return An IDaemonAdapter instance of the specific torrent client daemon type
*/ */
public IDaemonAdapter createServerAdapter() { public IDaemonAdapter createServerAdapter(String connectedToNetwork) {
return type.createAdapter(convertToDaemonSettings()); return type.createAdapter(convertToDaemonSettings(connectedToNetwork));
} }
private DaemonSettings convertToDaemonSettings() { /**
// Convert local server settings into an old-style DaemonSetting object * Converts local server settings into an old-style {@link DaemonSettings} object.
// The local integer key is converted to the idString string * @param connectedToNetwork The name of the (wifi) network we are currently connected to, or null if this could not
// TODO: Add localaddress and localnetwork to DaemonSettings, or solve properly rework the Connect library * be determined
// handling of settings * @return A {@link DaemonSettings} object to execute server commands against
return new DaemonSettings(name, type, address, port, ssl, sslTrustAll, sslTrustKey, */
folder, useAuthentication, username, password, extraPass, os, downloadDir, ftpUrl, ftpPassword, private DaemonSettings convertToDaemonSettings(String connectedToNetwork) {
timeout, alarmOnFinishedDownload, alarmOnNewTorrent, Integer.toString(key), isAutoGenerated); // The local integer key is converted to the idString string.
// The host name address used is dependent on the network that we are currently connected to (to allow a
// distinct connection IP or host name when connected to a local network).
return new DaemonSettings(name, type,
connectedToNetwork != null && connectedToNetwork.equals(localNetwork) ? localAddress : address, port,
ssl, sslTrustAll, sslTrustKey, folder, useAuthentication, username, password, extraPass, os,
downloadDir, ftpUrl, ftpPassword, timeout, alarmOnFinishedDownload, alarmOnNewTorrent,
Integer.toString(key), isAutoGenerated);
} }
} }

5
core/src/org/transdroid/core/gui/DetailsActivity.java

@ -35,6 +35,7 @@ import org.transdroid.core.gui.lists.LocalTorrent;
import org.transdroid.core.gui.log.Log; import org.transdroid.core.gui.log.Log;
import org.transdroid.core.gui.navigation.Label; import org.transdroid.core.gui.navigation.Label;
import org.transdroid.core.gui.navigation.NavigationHelper; import org.transdroid.core.gui.navigation.NavigationHelper;
import org.transdroid.core.service.ConnectivityHelper;
import org.transdroid.daemon.Daemon; import org.transdroid.daemon.Daemon;
import org.transdroid.daemon.IDaemonAdapter; import org.transdroid.daemon.IDaemonAdapter;
import org.transdroid.daemon.Priority; import org.transdroid.daemon.Priority;
@ -91,6 +92,8 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent
@Bean @Bean
protected NavigationHelper navigationHelper; protected NavigationHelper navigationHelper;
@Bean @Bean
protected ConnectivityHelper connectivityHelper;
@Bean
protected ApplicationSettings applicationSettings; protected ApplicationSettings applicationSettings;
private IDaemonAdapter currentConnection = null; private IDaemonAdapter currentConnection = null;
@ -123,7 +126,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent
// Connect to the last used server // Connect to the last used server
ServerSetting lastUsed = applicationSettings.getLastUsedServer(); ServerSetting lastUsed = applicationSettings.getLastUsedServer();
currentConnection = lastUsed.createServerAdapter(); currentConnection = lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName());
// Show details and load fine stats and torrent files // Show details and load fine stats and torrent files
fragmentDetails.updateTorrent(torrent); fragmentDetails.updateTorrent(torrent);

7
core/src/org/transdroid/core/gui/TorrentsActivity.java

@ -55,6 +55,7 @@ import org.transdroid.core.gui.search.FilePickerHelper;
import org.transdroid.core.gui.search.UrlEntryDialog; import org.transdroid.core.gui.search.UrlEntryDialog;
import org.transdroid.core.gui.settings.*; import org.transdroid.core.gui.settings.*;
import org.transdroid.core.service.BootReceiver; import org.transdroid.core.service.BootReceiver;
import org.transdroid.core.service.ConnectivityHelper;
import org.transdroid.daemon.Daemon; import org.transdroid.daemon.Daemon;
import org.transdroid.daemon.IDaemonAdapter; import org.transdroid.daemon.IDaemonAdapter;
import org.transdroid.daemon.Priority; import org.transdroid.daemon.Priority;
@ -125,6 +126,8 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
// Navigation components // Navigation components
@Bean @Bean
protected NavigationHelper navigationHelper; protected NavigationHelper navigationHelper;
@Bean
protected ConnectivityHelper connectivityHelper;
@ViewById @ViewById
protected SherlockListView filtersList; protected SherlockListView filtersList;
protected FilterListAdapter navigationListAdapter = null; protected FilterListAdapter navigationListAdapter = null;
@ -219,7 +222,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
// Handle any start up intents // Handle any start up intents
if (firstStart && getIntent() != null) { if (firstStart && getIntent() != null) {
currentConnection = lastUsed.createServerAdapter(); currentConnection = lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName());
handleStartIntent(); handleStartIntent();
} }
@ -356,7 +359,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
} }
// Update connection to the newly selected server and refresh // Update connection to the newly selected server and refresh
currentConnection = server.createServerAdapter(); currentConnection = server.createServerAdapter(connectivityHelper.getConnectedNetworkName());
applicationSettings.setLastUsedServer(server); applicationSettings.setLastUsedServer(server);
navigationSpinnerAdapter.updateCurrentServer(currentConnection); navigationSpinnerAdapter.updateCurrentServer(currentConnection);
if (forceNewConnection) if (forceNewConnection)

2
core/src/org/transdroid/core/service/AppUpdateService.java

@ -68,7 +68,7 @@ public class AppUpdateService extends IntentService {
@Override @Override
protected void onHandleIntent(Intent intent) { protected void onHandleIntent(Intent intent) {
if (!connectivityHelper.shouldPerformActions() || !systemSettings.checkForUpdates()) { if (!connectivityHelper.shouldPerformBackgroundActions() || !systemSettings.checkForUpdates()) {
Log.d(this, Log.d(this,
"Skip the app update service, as background data is disabled, the service is disabled or we are not connected."); "Skip the app update service, as background data is disabled, the service is disabled or we are not connected.");
return; return;

11
core/src/org/transdroid/core/service/ConnectivityHelper.java

@ -22,18 +22,21 @@ import org.androidannotations.annotations.EBean.Scope;
import android.content.Context; import android.content.Context;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.wifi.WifiManager;
@EBean(scope = Scope.Singleton) @EBean(scope = Scope.Singleton)
public class ConnectivityHelper { public class ConnectivityHelper {
@SystemService @SystemService
protected ConnectivityManager connectivityManager; protected ConnectivityManager connectivityManager;
@SystemService
protected WifiManager wifiManager;
public ConnectivityHelper(Context context) { public ConnectivityHelper(Context context) {
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public boolean shouldPerformActions() { public boolean shouldPerformBackgroundActions() {
// First check the old background data setting (this will always be true for ICS+) // First check the old background data setting (this will always be true for ICS+)
if (!connectivityManager.getBackgroundDataSetting()) if (!connectivityManager.getBackgroundDataSetting())
return false; return false;
@ -42,4 +45,10 @@ public class ConnectivityHelper {
return connectivityManager.getActiveNetworkInfo().isConnected(); return connectivityManager.getActiveNetworkInfo().isConnected();
} }
public String getConnectedNetworkName() {
if (wifiManager.getConnectionInfo() != null) {
return wifiManager.getConnectionInfo().getSSID().replace("\"", "");
}
return null;
}
} }

2
core/src/org/transdroid/core/service/RssCheckerService.java

@ -62,7 +62,7 @@ public class RssCheckerService extends IntentService {
@Override @Override
protected void onHandleIntent(Intent intent) { protected void onHandleIntent(Intent intent) {
if (!connectivityHelper.shouldPerformActions() || !notificationSettings.isEnabled()) { if (!connectivityHelper.shouldPerformBackgroundActions() || !notificationSettings.isEnabled()) {
Log.d(this, Log.d(this,
"Skip the RSS checker service, as background data is disabled, the service is disabled or we are not connected."); "Skip the RSS checker service, as background data is disabled, the service is disabled or we are not connected.");
return; return;

4
core/src/org/transdroid/core/service/ServerCheckerService.java

@ -69,7 +69,7 @@ public class ServerCheckerService extends IntentService {
@Override @Override
protected void onHandleIntent(Intent intent) { protected void onHandleIntent(Intent intent) {
if (!connectivityHelper.shouldPerformActions() || !notificationSettings.isEnabled()) { if (!connectivityHelper.shouldPerformBackgroundActions() || !notificationSettings.isEnabled()) {
Log.d(this, Log.d(this,
"Skip the server checker service, as background data is disabled, the service is disabled or we are not connected."); "Skip the server checker service, as background data is disabled, the service is disabled or we are not connected.");
return; return;
@ -88,7 +88,7 @@ public class ServerCheckerService extends IntentService {
JSONArray lastStats = applicationSettings.getServerLastStats(server); JSONArray lastStats = applicationSettings.getServerLastStats(server);
// Synchronously retrieve torrents listing // Synchronously retrieve torrents listing
IDaemonAdapter adapter = server.createServerAdapter(); IDaemonAdapter adapter = server.createServerAdapter(connectivityHelper.getConnectedNetworkName());
DaemonTaskResult result = RetrieveTask.create(adapter).execute(); DaemonTaskResult result = RetrieveTask.create(adapter).execute();
if (!(result instanceof RetrieveTaskSuccessResult)) { if (!(result instanceof RetrieveTaskSuccessResult)) {
// Cannot retrieve torrents at this time // Cannot retrieve torrents at this time

1
full/AndroidManifest.xml

@ -33,6 +33,7 @@
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

8
lib/src/org/transdroid/daemon/Daemon.java

@ -145,6 +145,8 @@ public enum Daemon {
return "daemon_qbittorrent"; return "daemon_qbittorrent";
case rTorrent: case rTorrent:
return "daemon_rtorrent"; return "daemon_rtorrent";
case Synology:
return "daemon_synology";
case Tfb4rt: case Tfb4rt:
return "daemon_tfb4rt"; return "daemon_tfb4rt";
case Transmission: case Transmission:
@ -197,14 +199,14 @@ public enum Daemon {
if (daemonCode.equals("daemon_rtorrent")) { if (daemonCode.equals("daemon_rtorrent")) {
return rTorrent; return rTorrent;
} }
if (daemonCode.equals("daemon_synology")) {
return Synology;
}
if (daemonCode.equals("daemon_tfb4rt")) { if (daemonCode.equals("daemon_tfb4rt")) {
return Tfb4rt; return Tfb4rt;
} }
if (daemonCode.equals("daemon_transmission")) { if (daemonCode.equals("daemon_transmission")) {
return Transmission; return Transmission;
}
if (daemonCode.equals("daemon_synology")) {
return Synology;
} }
if (daemonCode.equals("daemon_utorrent")) { if (daemonCode.equals("daemon_utorrent")) {
return uTorrent; return uTorrent;

1
lite/AndroidManifest.xml

@ -33,6 +33,7 @@
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Loading…
Cancel
Save