diff --git a/app/src/full/java/org/fdroid/fdroid/localrepo/SDCardScannerService.java b/app/src/full/java/org/fdroid/fdroid/localrepo/SDCardScannerService.java index a242b081e..6a021cbb0 100644 --- a/app/src/full/java/org/fdroid/fdroid/localrepo/SDCardScannerService.java +++ b/app/src/full/java/org/fdroid/fdroid/localrepo/SDCardScannerService.java @@ -30,8 +30,9 @@ import android.os.Environment; import android.os.Process; import android.support.v4.content.ContextCompat; import android.util.Log; -import org.fdroid.fdroid.IndexV1Updater; import org.fdroid.fdroid.IndexUpdater; +import org.fdroid.fdroid.IndexV1Updater; +import org.fdroid.fdroid.Preferences; import org.fdroid.fdroid.Utils; import java.io.File; @@ -52,6 +53,11 @@ import java.util.List; * only ever allow for reading repos, never writing. It also will not work * for removeable storage devices plugged in via USB, since do not show up as * "External Storage" + *
+ * Scanning the removable storage requires that the user allowed it. This
+ * requires both the {@link Preferences#isScanRemovableStorageEnabled()}
+ * and the {@link android.Manifest.permission#READ_EXTERNAL_STORAGE}
+ * permission to be enabled.
*
* @see TreeUriScannerIntentService TreeUri method for writing repos to be shared
* @see Universal way to write to external SD card on Android
@@ -69,9 +75,11 @@ public class SDCardScannerService extends IntentService {
}
public static void scan(Context context) {
- Intent intent = new Intent(context, SDCardScannerService.class);
- intent.setAction(ACTION_SCAN);
- context.startService(intent);
+ if (Preferences.get().isScanRemovableStorageEnabled()) {
+ Intent intent = new Intent(context, SDCardScannerService.class);
+ intent.setAction(ACTION_SCAN);
+ context.startService(intent);
+ }
}
@Override
diff --git a/app/src/full/java/org/fdroid/fdroid/localrepo/TreeUriScannerIntentService.java b/app/src/full/java/org/fdroid/fdroid/localrepo/TreeUriScannerIntentService.java
index 399e6477e..0c90fcd2f 100644
--- a/app/src/full/java/org/fdroid/fdroid/localrepo/TreeUriScannerIntentService.java
+++ b/app/src/full/java/org/fdroid/fdroid/localrepo/TreeUriScannerIntentService.java
@@ -29,8 +29,9 @@ import android.support.v4.provider.DocumentFile;
import android.util.Log;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
-import org.fdroid.fdroid.IndexV1Updater;
import org.fdroid.fdroid.IndexUpdater;
+import org.fdroid.fdroid.IndexV1Updater;
+import org.fdroid.fdroid.Preferences;
import org.fdroid.fdroid.Utils;
import org.fdroid.fdroid.data.Repo;
import org.fdroid.fdroid.data.RepoProvider;
@@ -72,10 +73,12 @@ public class TreeUriScannerIntentService extends IntentService {
}
public static void scan(Context context, Uri data) {
- Intent intent = new Intent(context, TreeUriScannerIntentService.class);
- intent.setAction(ACTION_SCAN_TREE_URI);
- intent.setData(data);
- context.startService(intent);
+ if (Preferences.get().isScanRemovableStorageEnabled()) {
+ Intent intent = new Intent(context, TreeUriScannerIntentService.class);
+ intent.setAction(ACTION_SCAN_TREE_URI);
+ intent.setData(data);
+ context.startService(intent);
+ }
}
@Override
diff --git a/app/src/main/java/org/fdroid/fdroid/Preferences.java b/app/src/main/java/org/fdroid/fdroid/Preferences.java
index 9a3fc4b09..9dc93a1ab 100644
--- a/app/src/main/java/org/fdroid/fdroid/Preferences.java
+++ b/app/src/main/java/org/fdroid/fdroid/Preferences.java
@@ -92,6 +92,7 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
public static final String PREF_PRIVILEGED_INSTALLER = "privilegedInstaller";
public static final String PREF_LOCAL_REPO_NAME = "localRepoName";
public static final String PREF_LOCAL_REPO_HTTPS = "localRepoHttps";
+ public static final String PREF_SCAN_REMOVABLE_STORAGE = "scanRemovableStorage";
public static final String PREF_LANGUAGE = "language";
public static final String PREF_USE_TOR = "useTor";
public static final String PREF_ENABLE_PROXY = "enableProxy";
@@ -400,6 +401,10 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
return preferences.getString(PREF_LOCAL_REPO_NAME, getDefaultLocalRepoName());
}
+ public boolean isScanRemovableStorageEnabled() {
+ return preferences.getBoolean(PREF_SCAN_REMOVABLE_STORAGE, true);
+ }
+
public boolean isUpdateNotificationEnabled() {
return preferences.getBoolean(PREF_UPDATE_NOTIFICATION_ENABLED, true);
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 9b4f9d958..076eba5ee 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -59,6 +59,10 @@