allow repos on removable storage to work without any internet

This commit is contained in:
Hans-Christoph Steiner 2018-12-20 23:13:07 +01:00
parent 69e2ca4283
commit f95af36140

View File

@ -26,6 +26,7 @@ import android.app.job.JobInfo;
import android.app.job.JobScheduler; import android.app.job.JobScheduler;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
@ -406,6 +407,13 @@ public class UpdateService extends JobIntentService {
}); });
} }
private static boolean isLocalRepoAddress(String address) {
return address != null &&
(address.startsWith(BluetoothDownloader.SCHEME)
|| address.startsWith(ContentResolver.SCHEME_CONTENT)
|| address.startsWith(ContentResolver.SCHEME_FILE));
}
@Override @Override
protected void onHandleWork(@NonNull Intent intent) { protected void onHandleWork(@NonNull Intent intent) {
Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST); Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST);
@ -417,16 +425,38 @@ public class UpdateService extends JobIntentService {
try { try {
final Preferences fdroidPrefs = Preferences.get(); final Preferences fdroidPrefs = Preferences.get();
// Grab some preliminary information, then we can release the
// database while we do all the downloading, etc...
List<Repo> repos = RepoProvider.Helper.all(this);
// See if it's time to actually do anything yet... // See if it's time to actually do anything yet...
int netState = ConnectivityMonitorService.getNetworkState(this); int netState = ConnectivityMonitorService.getNetworkState(this);
if (address != null && address.startsWith(BluetoothDownloader.SCHEME)) { if (isLocalRepoAddress(address)) {
Utils.debugLog(TAG, "skipping internet check, this is bluetooth"); Utils.debugLog(TAG, "skipping internet check, this is local: " + address);
} else if (netState == ConnectivityMonitorService.FLAG_NET_UNAVAILABLE) { } else if (netState == ConnectivityMonitorService.FLAG_NET_UNAVAILABLE) {
boolean foundLocalRepo = false;
for (Repo repo : repos) {
if (isLocalRepoAddress(repo.address)) {
foundLocalRepo = true;
} else {
for (String mirrorAddress : repo.getMirrorList()) {
if (isLocalRepoAddress(mirrorAddress)) {
foundLocalRepo = true;
//localRepos.add(repo);
//FDroidApp.setLastWorkingMirror(repo.getId(), mirrorAddress);
break;
}
}
}
}
if (!foundLocalRepo) {
Utils.debugLog(TAG, "No internet, cannot update"); Utils.debugLog(TAG, "No internet, cannot update");
if (manualUpdate) { if (manualUpdate) {
sendNoInternetToast(); sendNoInternetToast();
} }
return; return;
}
} else if ((manualUpdate || forcedUpdate) && fdroidPrefs.isOnDemandDownloadAllowed()) { } else if ((manualUpdate || forcedUpdate) && fdroidPrefs.isOnDemandDownloadAllowed()) {
Utils.debugLog(TAG, "manually requested or forced update"); Utils.debugLog(TAG, "manually requested or forced update");
if (forcedUpdate) { if (forcedUpdate) {
@ -442,10 +472,6 @@ public class UpdateService extends JobIntentService {
LocalBroadcastManager.getInstance(this).registerReceiver(updateStatusReceiver, LocalBroadcastManager.getInstance(this).registerReceiver(updateStatusReceiver,
new IntentFilter(LOCAL_ACTION_STATUS)); new IntentFilter(LOCAL_ACTION_STATUS));
// Grab some preliminary information, then we can release the
// database while we do all the downloading, etc...
List<Repo> repos = RepoProvider.Helper.all(this);
int unchangedRepos = 0; int unchangedRepos = 0;
int updatedRepos = 0; int updatedRepos = 0;
int errorRepos = 0; int errorRepos = 0;
@ -482,7 +508,8 @@ public class UpdateService extends JobIntentService {
} catch (IndexUpdater.UpdateException e) { } catch (IndexUpdater.UpdateException e) {
errorRepos++; errorRepos++;
repoErrors.add(e.getMessage()); repoErrors.add(e.getMessage());
Log.e(TAG, "Error updating repository " + repo.address, e); Log.e(TAG, "Error updating repository " + repo.address);
e.printStackTrace();
} }
// now that downloading the index is done, start downloading updates // now that downloading the index is done, start downloading updates