use of org.fdroid.fdroid.data.Repo in project fdroidclient by f-droid.
the class UpdateService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST);
final long startTime = System.currentTimeMillis();
boolean manualUpdate = false;
boolean forcedUpdate = false;
String address = null;
if (intent != null) {
address = intent.getStringExtra(EXTRA_ADDRESS);
manualUpdate = intent.getBooleanExtra(EXTRA_MANUAL_UPDATE, false);
forcedUpdate = intent.getBooleanExtra(EXTRA_FORCED_UPDATE, false);
}
try {
// See if it's time to actually do anything yet...
int netState = getNetworkState(this);
if (netState == FLAG_NET_UNAVAILABLE) {
Utils.debugLog(TAG, "No internet, cannot update");
if (manualUpdate) {
sendNoInternetToast();
}
return;
}
if (manualUpdate || forcedUpdate) {
Utils.debugLog(TAG, "manually requested or forced update");
} else if (!verifyIsTimeForScheduledRun() || (netState == FLAG_NET_METERED && Preferences.get().isUpdateOnlyOnUnmeteredNetworks())) {
Utils.debugLog(TAG, "don't run update");
return;
}
updating = true;
notificationManager.notify(NOTIFY_ID_UPDATING, notificationBuilder.build());
LocalBroadcastManager.getInstance(this).registerReceiver(updateStatusReceiver, 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 updatedRepos = 0;
int errorRepos = 0;
ArrayList<CharSequence> repoErrors = new ArrayList<>();
boolean changes = false;
boolean singleRepoUpdate = !TextUtils.isEmpty(address);
final Preferences fdroidPrefs = Preferences.get();
for (final Repo repo : repos) {
if (!repo.inuse) {
continue;
}
if (singleRepoUpdate && !repo.address.equals(address)) {
unchangedRepos++;
continue;
}
if (!singleRepoUpdate && repo.isSwap) {
continue;
}
sendStatus(this, STATUS_INFO, getString(R.string.status_connecting_to_repo, repo.address));
if (forcedUpdate) {
DBHelper.resetTransient(this);
}
try {
RepoUpdater updater = new IndexV1Updater(this, repo);
if (Preferences.get().isForceOldIndexEnabled() || !updater.update()) {
updater = new RepoUpdater(getBaseContext(), repo);
updater.update();
}
if (updater.hasChanged()) {
updatedRepos++;
changes = true;
} else {
unchangedRepos++;
}
} catch (RepoUpdater.UpdateException e) {
errorRepos++;
repoErrors.add(e.getMessage());
Log.e(TAG, "Error updating repository " + repo.address, e);
}
// now that downloading the index is done, start downloading updates
if (changes && fdroidPrefs.isAutoDownloadEnabled()) {
autoDownloadUpdates(this);
}
}
if (!changes) {
Utils.debugLog(TAG, "Not checking app details or compatibility, because all repos were up to date.");
} else {
notifyContentProviders();
if (fdroidPrefs.isUpdateNotificationEnabled() && !fdroidPrefs.isAutoDownloadEnabled()) {
performUpdateNotification();
}
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
SharedPreferences.Editor e = prefs.edit();
e.putLong(STATE_LAST_UPDATED, System.currentTimeMillis());
e.apply();
if (errorRepos == 0) {
if (changes) {
sendStatus(this, STATUS_COMPLETE_WITH_CHANGES);
} else {
sendStatus(this, STATUS_COMPLETE_AND_SAME);
}
} else {
if (updatedRepos + unchangedRepos == 0) {
sendRepoErrorStatus(STATUS_ERROR_LOCAL, repoErrors);
} else {
sendRepoErrorStatus(STATUS_ERROR_LOCAL_SMALL, repoErrors);
}
}
} catch (Exception e) {
Log.e(TAG, "Exception during update processing", e);
sendStatus(this, STATUS_ERROR_GLOBAL, e.getMessage());
} finally {
updating = false;
}
long time = System.currentTimeMillis() - startTime;
Log.i(TAG, "Updating repo(s) complete, took " + time / 1000 + " seconds to complete.");
}
use of org.fdroid.fdroid.data.Repo in project fdroidclient by f-droid.
the class DownloaderFactory method create.
public static Downloader create(Context context, Uri uri, File destFile) throws IOException {
Downloader downloader;
String scheme = uri.getScheme();
if ("bluetooth".equals(scheme)) {
downloader = new BluetoothDownloader(uri, destFile);
} else {
final String[] projection = { Schema.RepoTable.Cols.USERNAME, Schema.RepoTable.Cols.PASSWORD };
Repo repo = RepoProvider.Helper.findByUrl(context, uri, projection);
if (repo == null) {
downloader = new HttpDownloader(uri, destFile);
} else {
downloader = new HttpDownloader(uri, destFile, repo.username, repo.password);
}
}
return downloader;
}
use of org.fdroid.fdroid.data.Repo in project fdroidclient by f-droid.
the class Provisioner method scanAndProcess.
/**
* search for provision files and process them
*/
static void scanAndProcess(Context context) {
File externalFilesDir = context.getExternalFilesDir(null);
if (externalFilesDir == null) {
return;
}
File provisionDir = new File(externalFilesDir.getAbsolutePath(), NEW_PROVISIONS_DIR);
if (!provisionDir.isDirectory()) {
Utils.debugLog(TAG, "Provisions dir does not exists: '" + provisionDir.getAbsolutePath() + "' moving on ...");
} else if (provisionDir.list().length == 0) {
Utils.debugLog(TAG, "Provisions dir is empty: '" + provisionDir.getAbsolutePath() + "' moving on ...");
} else {
Provisioner p = new Provisioner();
List<File> files = p.findProvisionFiles(context);
List<ProvisionPlaintext> plaintexts = p.extractProvisionsPlaintext(files);
List<Provision> provisions = p.parseProvisions(plaintexts);
if (provisions == null || provisions.size() == 0) {
Utils.debugLog(TAG, "Provision dir does not contain any provisions: '" + provisionDir.getAbsolutePath() + "' moving on ...");
} else {
int cleanupCounter = 0;
for (Provision provision : provisions) {
if (provision.getRepositoryProvision() != null) {
RepositoryProvision repo = provision.getRepositoryProvision();
Repo storedRepo = RepoProvider.Helper.findByAddress(context, repo.getUrl());
if (storedRepo != null) {
Utils.debugLog(TAG, "Provision contains a repo which is already added: '" + provision.getProvisonPath() + "' ignoring ...");
} else {
// Note: only the last started activity will visible to users.
// All other prompting attempts will be lost.
Uri origUrl = Uri.parse(repo.getUrl());
Uri.Builder data = new Uri.Builder();
data.scheme(origUrl.getScheme());
data.encodedAuthority(Uri.encode(repo.getUsername()) + ':' + Uri.encode(repo.getPassword()) + '@' + Uri.encode(origUrl.getAuthority()));
data.path(origUrl.getPath());
data.appendQueryParameter("fingerprint", repo.getSigfp());
Intent i = new Intent(context, ManageReposActivity.class);
i.setData(data.build());
context.startActivity(i);
Utils.debugLog(TAG, "Provision processed: '" + provision.getProvisonPath() + "' prompted user ...");
}
}
// remove provision file
try {
if (new File(provision.getProvisonPath()).delete()) {
cleanupCounter++;
}
} catch (SecurityException e) {
// ignore this exception
Utils.debugLog(TAG, "Removing provision not possible: " + e.getMessage() + " ()");
}
}
Utils.debugLog(TAG, "Provisions done, removed " + cleanupCounter + " provision(s).");
}
}
}
use of org.fdroid.fdroid.data.Repo in project fdroidclient by f-droid.
the class ManageReposActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
((FDroidApp) getApplication()).applyTheme(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.repo_list_activity);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
final ListView repoList = (ListView) findViewById(R.id.list);
repoAdapter = RepoAdapter.create(this, null, CursorAdapterCompat.FLAG_AUTO_REQUERY);
repoAdapter.setEnabledListener(this);
repoList.setAdapter(repoAdapter);
repoList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Repo repo = new Repo((Cursor) repoList.getItemAtPosition(position));
editRepo(repo);
}
});
}
use of org.fdroid.fdroid.data.Repo in project fdroidclient by f-droid.
the class RepoAdapter method setupView.
private void setupView(Cursor cursor, View view, CompoundButton switchView) {
final Repo repo = new Repo(cursor);
switchView.setChecked(repo.inuse);
// Add this listener *after* setting the checked status, so we don't
// invoke the listener while setting up the view...
switchView.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (enabledListener != null) {
enabledListener.onSetEnabled(repo, isChecked);
}
}
});
TextView nameView = (TextView) view.findViewById(R.id.repo_name);
nameView.setText(repo.getName());
View unsignedView = view.findViewById(R.id.repo_unsigned);
View unverifiedView = view.findViewById(R.id.repo_unverified);
if (repo.isSigned()) {
unsignedView.setVisibility(View.GONE);
unverifiedView.setVisibility(View.GONE);
} else if (repo.isSignedButUnverified()) {
unsignedView.setVisibility(View.GONE);
unverifiedView.setVisibility(View.VISIBLE);
} else {
unsignedView.setVisibility(View.VISIBLE);
unverifiedView.setVisibility(View.GONE);
}
}
Aggregations