add preference to disable removable storage scanning

This commit is contained in:
Hans-Christoph Steiner 2018-08-01 15:59:15 +02:00
parent f9bc219073
commit c4b0955c96
5 changed files with 34 additions and 9 deletions

View File

@ -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"
* <p>
* 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 <a href="https://stackoverflow.com/a/40201333">Universal way to write to external SD card on Android</a>
@ -69,10 +75,12 @@ public class SDCardScannerService extends IntentService {
}
public static void scan(Context context) {
if (Preferences.get().isScanRemovableStorageEnabled()) {
Intent intent = new Intent(context, SDCardScannerService.class);
intent.setAction(ACTION_SCAN);
context.startService(intent);
}
}
@Override
protected void onHandleIntent(Intent intent) {

View File

@ -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,11 +73,13 @@ public class TreeUriScannerIntentService extends IntentService {
}
public static void scan(Context context, Uri data) {
if (Preferences.get().isScanRemovableStorageEnabled()) {
Intent intent = new Intent(context, TreeUriScannerIntentService.class);
intent.setAction(ACTION_SCAN_TREE_URI);
intent.setData(data);
context.startService(intent);
}
}
@Override
protected void onHandleIntent(Intent intent) {

View File

@ -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);
}

View File

@ -59,6 +59,10 @@
<string name="local_repo_name">Name of your Local Repo</string>
<string name="local_repo_name_summary">The advertised title of your local repo: %s</string>
<string name="local_repo_https_on">Use encrypted HTTPS:// connection for local repo</string>
<string name="scan_removable_storage_title">Scan removable storage</string>
<string name="scan_removable_storage_summary">Look for package repos on removable storage like SD Cards
and USB thumb drives
</string>
<string name="login_title">Authentication required</string>
<string name="login_name">Username</string>

View File

@ -96,6 +96,11 @@
<EditTextPreference
android:key="localRepoName"
android:title="@string/local_repo_name"/>
<SwitchPreference
android:key="scanRemovableStorage"
android:defaultValue="true"
android:title="@string/scan_removable_storage_title"
android:summary="@string/scan_removable_storage_summary"/>
</android.support.v7.preference.PreferenceCategory>
<android.support.v7.preference.PreferenceCategory android:title="@string/proxy">