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

3
core/res/xml/pref_server.xml

@ -57,7 +57,8 @@ @@ -57,7 +57,8 @@
<EditTextPreference
android:key="server_localnetwork"
android:title="@string/pref_localnetwork"
android:summary="@string/pref_localnetwork_info" />
android:summary="@string/pref_localnetwork_info"
android:inputType="textNoSuggestions" />
<EditTextPreference
android:key="server_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 { @@ -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
* @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
*/
public IDaemonAdapter createServerAdapter() {
return type.createAdapter(convertToDaemonSettings());
public IDaemonAdapter createServerAdapter(String connectedToNetwork) {
return type.createAdapter(convertToDaemonSettings(connectedToNetwork));
}
private DaemonSettings convertToDaemonSettings() {
// Convert local server settings into an old-style DaemonSetting object
// The local integer key is converted to the idString string
// TODO: Add localaddress and localnetwork to DaemonSettings, or solve properly rework the Connect library
// handling of settings
return new DaemonSettings(name, type, address, port, ssl, sslTrustAll, sslTrustKey,
folder, useAuthentication, username, password, extraPass, os, downloadDir, ftpUrl, ftpPassword,
timeout, alarmOnFinishedDownload, alarmOnNewTorrent, Integer.toString(key), isAutoGenerated);
/**
* Converts local server settings into an old-style {@link DaemonSettings} object.
* @param connectedToNetwork The name of the (wifi) network we are currently connected to, or null if this could not
* be determined
* @return A {@link DaemonSettings} object to execute server commands against
*/
private DaemonSettings convertToDaemonSettings(String connectedToNetwork) {
// 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; @@ -35,6 +35,7 @@ import org.transdroid.core.gui.lists.LocalTorrent;
import org.transdroid.core.gui.log.Log;
import org.transdroid.core.gui.navigation.Label;
import org.transdroid.core.gui.navigation.NavigationHelper;
import org.transdroid.core.service.ConnectivityHelper;
import org.transdroid.daemon.Daemon;
import org.transdroid.daemon.IDaemonAdapter;
import org.transdroid.daemon.Priority;
@ -91,6 +92,8 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent @@ -91,6 +92,8 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent
@Bean
protected NavigationHelper navigationHelper;
@Bean
protected ConnectivityHelper connectivityHelper;
@Bean
protected ApplicationSettings applicationSettings;
private IDaemonAdapter currentConnection = null;
@ -123,7 +126,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent @@ -123,7 +126,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent
// Connect to the last used server
ServerSetting lastUsed = applicationSettings.getLastUsedServer();
currentConnection = lastUsed.createServerAdapter();
currentConnection = lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName());
// Show details and load fine stats and torrent files
fragmentDetails.updateTorrent(torrent);

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

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

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

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

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

@ -22,18 +22,21 @@ import org.androidannotations.annotations.EBean.Scope; @@ -22,18 +22,21 @@ import org.androidannotations.annotations.EBean.Scope;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.wifi.WifiManager;
@EBean(scope = Scope.Singleton)
public class ConnectivityHelper {
@SystemService
protected ConnectivityManager connectivityManager;
@SystemService
protected WifiManager wifiManager;
public ConnectivityHelper(Context context) {
}
@SuppressWarnings("deprecation")
public boolean shouldPerformActions() {
public boolean shouldPerformBackgroundActions() {
// First check the old background data setting (this will always be true for ICS+)
if (!connectivityManager.getBackgroundDataSetting())
return false;
@ -42,4 +45,10 @@ public class ConnectivityHelper { @@ -42,4 +45,10 @@ public class ConnectivityHelper {
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 { @@ -62,7 +62,7 @@ public class RssCheckerService extends IntentService {
@Override
protected void onHandleIntent(Intent intent) {
if (!connectivityHelper.shouldPerformActions() || !notificationSettings.isEnabled()) {
if (!connectivityHelper.shouldPerformBackgroundActions() || !notificationSettings.isEnabled()) {
Log.d(this,
"Skip the RSS checker service, as background data is disabled, the service is disabled or we are not connected.");
return;

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

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

1
full/AndroidManifest.xml

@ -33,6 +33,7 @@ @@ -33,6 +33,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<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.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

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

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

1
lite/AndroidManifest.xml

@ -33,6 +33,7 @@ @@ -33,6 +33,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<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.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Loading…
Cancel
Save