Browse Source

Fixes #391 by requesting location permission if user want to use Local network (based on wifi SSID) feature for alternative local configuration.

bugfix/391
Eric Kok 6 years ago
parent
commit
78dd4bdc57
  1. 4
      app/build.gradle
  2. 5
      app/src/main/AndroidManifest.xml
  3. 47
      app/src/main/java/org/transdroid/core/gui/settings/InterceptableEditTextPreference.java
  4. 30
      app/src/main/java/org/transdroid/core/gui/settings/ServerSettingsActivity.java
  5. 48
      app/src/main/java/org/transdroid/core/service/ConnectivityHelper.java
  6. 1
      app/src/main/res/values/changelog.xml
  7. 2
      app/src/main/res/values/strings.xml
  8. 5
      app/src/main/res/xml/pref_server.xml

4
app/build.gradle

@ -8,8 +8,8 @@ android {
defaultConfig { defaultConfig {
minSdkVersion 15 minSdkVersion 15
targetSdkVersion 28 targetSdkVersion 28
versionCode 234 versionCode 235
versionName '2.5.14' versionName '2.5.15'
javaCompileOptions { javaCompileOptions {
annotationProcessorOptions { annotationProcessorOptions {

5
app/src/main/AndroidManifest.xml

@ -29,10 +29,15 @@
android:xlargeScreens="true" /> android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<!-- To check for an active connection -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- To check currently connected wifi network name -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission-sdk-23 android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- To start rss and torrents background check services -->
<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" />
<!-- To export settings file to external storage -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature <uses-feature

47
app/src/main/java/org/transdroid/core/gui/settings/InterceptableEditTextPreference.java

@ -0,0 +1,47 @@
package org.transdroid.core.gui.settings;
import android.content.Context;
import android.os.Build;
import android.preference.EditTextPreference;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
public class InterceptableEditTextPreference extends EditTextPreference {
private OnPreferenceClickListener overrideClickListener = null;
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public InterceptableEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public InterceptableEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public InterceptableEditTextPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
public InterceptableEditTextPreference(Context context) {
super(context);
}
@Override
public OnPreferenceClickListener getOnPreferenceClickListener() {
return overrideClickListener;
}
@Override
public void setOnPreferenceClickListener(OnPreferenceClickListener onPreferenceClickListener) {
this.overrideClickListener = onPreferenceClickListener;
}
@Override
protected void onClick() {
if (overrideClickListener == null || !overrideClickListener.onPreferenceClick(this)) {
super.onClick();
}
}
}

30
app/src/main/java/org/transdroid/core/gui/settings/ServerSettingsActivity.java

@ -26,14 +26,16 @@ import android.content.SharedPreferences;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.preference.EditTextPreference; import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.text.TextUtils; import android.support.annotation.NonNull;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EActivity; import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.OptionsItem; import org.androidannotations.annotations.OptionsItem;
import org.androidannotations.annotations.OptionsMenu; import org.androidannotations.annotations.OptionsMenu;
import org.transdroid.R; import org.transdroid.R;
import org.transdroid.core.app.settings.ApplicationSettings_; import org.transdroid.core.app.settings.ApplicationSettings_;
import org.transdroid.core.service.ConnectivityHelper;
import org.transdroid.daemon.Daemon; import org.transdroid.daemon.Daemon;
/** /**
@ -44,9 +46,12 @@ import org.transdroid.daemon.Daemon;
@OptionsMenu(R.menu.activity_deleteableprefs) @OptionsMenu(R.menu.activity_deleteableprefs)
public class ServerSettingsActivity extends KeyBoundPreferencesActivity { public class ServerSettingsActivity extends KeyBoundPreferencesActivity {
@Bean
protected ConnectivityHelper connectivityHelper;
private static final int DIALOG_CONFIRMREMOVE = 0; private static final int DIALOG_CONFIRMREMOVE = 0;
private EditTextPreference extraPass, folder, downloadDir, excludeFilter, includeFilter; private EditTextPreference extraPass, folder, downloadDir, excludeFilter, includeFilter, localNetworkPreference;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -63,7 +68,7 @@ public class ServerSettingsActivity extends KeyBoundPreferencesActivity {
initTextPreference("server_user"); initTextPreference("server_user");
initTextPreference("server_pass"); initTextPreference("server_pass");
extraPass = initTextPreference("server_extrapass"); extraPass = initTextPreference("server_extrapass");
initTextPreference("server_localnetwork"); localNetworkPreference = initTextPreference("server_localnetwork");
initTextPreference("server_localaddress"); initTextPreference("server_localaddress");
initTextPreference("server_localport"); initTextPreference("server_localport");
folder = initTextPreference("server_folder"); folder = initTextPreference("server_folder");
@ -83,6 +88,16 @@ public class ServerSettingsActivity extends KeyBoundPreferencesActivity {
initTextPreference("server_ssltrustkey", null, "server_sslenabled"); initTextPreference("server_ssltrustkey", null, "server_sslenabled");
onPreferencesChanged(); onPreferencesChanged();
localNetworkPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(final Preference preference) {
if (!connectivityHelper.hasNetworkNamePermission(ServerSettingsActivity.this)) {
connectivityHelper.askNetworkNamePermission(ServerSettingsActivity.this);
return true;
}
return false;
}
});
} }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @TargetApi(Build.VERSION_CODES.HONEYCOMB)
@ -113,6 +128,13 @@ public class ServerSettingsActivity extends KeyBoundPreferencesActivity {
return null; return null;
} }
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (connectivityHelper.requestedPermissionWasGranted(requestCode, permissions, grantResults)) {
localNetworkPreference.getOnPreferenceClickListener().onPreferenceClick(localNetworkPreference);
}
}
@Override @Override
protected void onPreferencesChanged() { protected void onPreferencesChanged() {

48
app/src/main/java/org/transdroid/core/service/ConnectivityHelper.java

@ -16,17 +16,26 @@
*/ */
package org.transdroid.core.service; package org.transdroid.core.service;
import org.androidannotations.annotations.EBean; import android.Manifest;
import org.androidannotations.annotations.SystemService; import android.app.Activity;
import org.androidannotations.annotations.EBean.Scope;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.wifi.WifiManager; import android.net.wifi.WifiManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.EBean.Scope;
import org.androidannotations.annotations.SystemService;
import org.transdroid.R;
@EBean(scope = Scope.Singleton) @EBean(scope = Scope.Singleton)
public class ConnectivityHelper { public class ConnectivityHelper {
private static final int REQUEST_LOCATION_PERMISSION = 0;
@SystemService @SystemService
protected ConnectivityManager connectivityManager; protected ConnectivityManager connectivityManager;
@SystemService @SystemService
@ -39,10 +48,39 @@ public class ConnectivityHelper {
} }
public String getConnectedNetworkName() { public String getConnectedNetworkName() {
if (wifiManager.getConnectionInfo() != null && wifiManager.getConnectionInfo().getSSID() != null) { if (wifiManager != null && wifiManager.getConnectionInfo() != null && wifiManager.getConnectionInfo().getSSID() != null) {
return wifiManager.getConnectionInfo().getSSID().replace("\"", ""); return wifiManager.getConnectionInfo().getSSID().replace("\"", "");
} }
return null; return null;
} }
public boolean hasNetworkNamePermission(final Context activityContext) {
return ContextCompat.checkSelfPermission(activityContext, Manifest.permission.ACCESS_FINE_LOCATION) ==
PackageManager.PERMISSION_GRANTED;
}
public void askNetworkNamePermission(final Activity activity) {
new AlertDialog.Builder(activity)
.setTitle(R.string.pref_local_permission_title)
.setMessage(activity.getString(R.string.pref_local_permission_rationale,
activity.getString(R.string.app_name)))
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ActivityCompat.requestPermissions(activity,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_LOCATION_PERMISSION);
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
}
public boolean requestedPermissionWasGranted(int requestCode, String[] permissions, int[] grantResults) {
return (requestCode == REQUEST_LOCATION_PERMISSION
&& permissions != null
&& grantResults != null
&& permissions[0].equals(Manifest.permission.ACCESS_FINE_LOCATION)
&& grantResults[0] == PackageManager.PERMISSION_GRANTED);
}
} }

1
app/src/main/res/values/changelog.xml

@ -18,6 +18,7 @@
<resources> <resources>
<string name="system_changelog"> <string name="system_changelog">
Transdroid 2.5.15\n Transdroid 2.5.15\n
- Support local network config on Android 8.1+ by asking for location permission\n
- Hacky fix to prevent crashes on > 1000 torrents\n - Hacky fix to prevent crashes on > 1000 torrents\n
- Fix crashes during background or config changes\n - Fix crashes during background or config changes\n
- Removed donate link in Transdrone\n - Removed donate link in Transdrone\n

2
app/src/main/res/values/strings.xml

@ -270,6 +270,8 @@
<string name="pref_localport">Local port number</string> <string name="pref_localport">Local port number</string>
<string name="pref_localnetwork">Local network</string> <string name="pref_localnetwork">Local network</string>
<string name="pref_localnetwork_info">The server\'s local network SSID</string> <string name="pref_localnetwork_info">The server\'s local network SSID</string>
<string name="pref_local_permission_title">Location permission</string>
<string name="pref_local_permission_rationale">To known the connected Wifi network SSID name, %1$s requires the location permission</string>
<string name="pref_folder">Folder</string> <string name="pref_folder">Folder</string>
<string name="pref_folder_info">Usually empty</string> <string name="pref_folder_info">Usually empty</string>
<string name="pref_scgifolder">SCGI mount point</string> <string name="pref_scgifolder">SCGI mount point</string>

5
app/src/main/res/xml/pref_server.xml

@ -15,7 +15,8 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with Transdroid. If not, see <http://www.gnu.org/licenses/>. along with Transdroid. If not, see <http://www.gnu.org/licenses/>.
--> -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" > <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<EditTextPreference <EditTextPreference
android:key="server_name" android:key="server_name"
@ -49,7 +50,7 @@
android:key="server_port" android:key="server_port"
android:title="@string/pref_port" android:title="@string/pref_port"
android:inputType="numberSigned" /> android:inputType="numberSigned" />
<EditTextPreference <org.transdroid.core.gui.settings.InterceptableEditTextPreference
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"

Loading…
Cancel
Save