allow SDCard/TreeUri scans to be manually triggered by user button press

Before, the preference blocked all scans.  That lead to confusing UX
since the "Try it" and USB-OTG buttons would do nothing.
This commit is contained in:
Hans-Christoph Steiner 2020-11-11 15:15:24 +01:00
parent 6af66abf54
commit 8209bf9a0b
3 changed files with 13 additions and 18 deletions

View File

@ -28,11 +28,10 @@ import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Environment; import android.os.Environment;
import android.os.Process; import android.os.Process;
import androidx.core.content.ContextCompat;
import android.util.Log; import android.util.Log;
import androidx.core.content.ContextCompat;
import org.fdroid.fdroid.IndexUpdater; import org.fdroid.fdroid.IndexUpdater;
import org.fdroid.fdroid.IndexV1Updater; import org.fdroid.fdroid.IndexV1Updater;
import org.fdroid.fdroid.Preferences;
import org.fdroid.fdroid.Utils; import org.fdroid.fdroid.Utils;
import java.io.File; import java.io.File;
@ -55,7 +54,7 @@ import java.util.List;
* "External Storage" * "External Storage"
* <p> * <p>
* Scanning the removable storage requires that the user allowed it. This * Scanning the removable storage requires that the user allowed it. This
* requires both the {@link Preferences#isScanRemovableStorageEnabled()} * requires both the {@link org.fdroid.fdroid.Preferences#isScanRemovableStorageEnabled()}
* and the {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} * and the {@link android.Manifest.permission#READ_EXTERNAL_STORAGE}
* permission to be enabled. * permission to be enabled.
* *
@ -75,11 +74,9 @@ public class SDCardScannerService extends IntentService {
} }
public static void scan(Context context) { public static void scan(Context context) {
if (Preferences.get().isScanRemovableStorageEnabled()) { Intent intent = new Intent(context, SDCardScannerService.class);
Intent intent = new Intent(context, SDCardScannerService.class); intent.setAction(ACTION_SCAN);
intent.setAction(ACTION_SCAN); context.startService(intent);
context.startService(intent);
}
} }
@Override @Override

View File

@ -20,7 +20,6 @@
package org.fdroid.fdroid.nearby; package org.fdroid.fdroid.nearby;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.Activity;
import android.app.IntentService; import android.app.IntentService;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
@ -28,15 +27,14 @@ import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Process; import android.os.Process;
import androidx.documentfile.provider.DocumentFile;
import android.util.Log; import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
import androidx.documentfile.provider.DocumentFile;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.fdroid.fdroid.AddRepoIntentService; import org.fdroid.fdroid.AddRepoIntentService;
import org.fdroid.fdroid.IndexUpdater; import org.fdroid.fdroid.IndexUpdater;
import org.fdroid.fdroid.IndexV1Updater; import org.fdroid.fdroid.IndexV1Updater;
import org.fdroid.fdroid.Preferences;
import org.fdroid.fdroid.R; import org.fdroid.fdroid.R;
import org.fdroid.fdroid.Utils; import org.fdroid.fdroid.Utils;
import org.fdroid.fdroid.data.Repo; import org.fdroid.fdroid.data.Repo;
@ -82,12 +80,10 @@ public class TreeUriScannerIntentService extends IntentService {
} }
public static void scan(Context context, Uri data) { public static void scan(Context context, Uri data) {
if (Preferences.get().isScanRemovableStorageEnabled()) { Intent intent = new Intent(context, TreeUriScannerIntentService.class);
Intent intent = new Intent(context, TreeUriScannerIntentService.class); intent.setAction(ACTION_SCAN_TREE_URI);
intent.setAction(ACTION_SCAN_TREE_URI); intent.setData(data);
intent.setData(data); context.startService(intent);
context.startService(intent);
}
} }
/** /**

View File

@ -539,7 +539,9 @@ public class FDroidApp extends Application {
atStartTime.edit().remove(queryStringKey).apply(); atStartTime.edit().remove(queryStringKey).apply();
} }
SDCardScannerService.scan(this); if (Preferences.get().isScanRemovableStorageEnabled()) {
SDCardScannerService.scan(this);
}
} }
/** /**