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.Environment;
import android.os.Process;
import androidx.core.content.ContextCompat;
import android.util.Log;
import androidx.core.content.ContextCompat;
import org.fdroid.fdroid.IndexUpdater;
import org.fdroid.fdroid.IndexV1Updater;
import org.fdroid.fdroid.Preferences;
import org.fdroid.fdroid.Utils;
import java.io.File;
@ -55,7 +54,7 @@ import java.util.List;
* "External Storage"
* <p>
* 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}
* permission to be enabled.
*
@ -75,12 +74,10 @@ 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

@ -20,7 +20,6 @@
package org.fdroid.fdroid.nearby;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.IntentService;
import android.content.ContentResolver;
import android.content.Context;
@ -28,15 +27,14 @@ import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Process;
import androidx.documentfile.provider.DocumentFile;
import android.util.Log;
import android.widget.Toast;
import androidx.documentfile.provider.DocumentFile;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.fdroid.fdroid.AddRepoIntentService;
import org.fdroid.fdroid.IndexUpdater;
import org.fdroid.fdroid.IndexV1Updater;
import org.fdroid.fdroid.Preferences;
import org.fdroid.fdroid.R;
import org.fdroid.fdroid.Utils;
import org.fdroid.fdroid.data.Repo;
@ -82,13 +80,11 @@ 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);
}
}
/**
* Now determine if it is External Storage that must be handled by the

View File

@ -539,8 +539,10 @@ public class FDroidApp extends Application {
atStartTime.edit().remove(queryStringKey).apply();
}
if (Preferences.get().isScanRemovableStorageEnabled()) {
SDCardScannerService.scan(this);
}
}
/**
* Asks if the current process is "org.fdroid.fdroid:acra".