Search in sources :

Example 11 with Repo

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.");
}
Also used : IntentFilter(android.content.IntentFilter) SharedPreferences(android.content.SharedPreferences) ArrayList(java.util.ArrayList) Repo(org.fdroid.fdroid.data.Repo) SharedPreferences(android.content.SharedPreferences)

Example 12 with Repo

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;
}
Also used : Repo(org.fdroid.fdroid.data.Repo)

Example 13 with Repo

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).");
        }
    }
}
Also used : ManageReposActivity(org.fdroid.fdroid.views.ManageReposActivity) Repo(org.fdroid.fdroid.data.Repo) ArrayList(java.util.ArrayList) List(java.util.List) Intent(android.content.Intent) File(java.io.File) Uri(android.net.Uri)

Example 14 with Repo

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);
        }
    });
}
Also used : ListView(android.widget.ListView) Repo(org.fdroid.fdroid.data.Repo) FDroidApp(org.fdroid.fdroid.FDroidApp) AdapterView(android.widget.AdapterView) Cursor(android.database.Cursor) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) SuppressLint(android.annotation.SuppressLint)

Example 15 with 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);
    }
}
Also used : Repo(org.fdroid.fdroid.data.Repo) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) CompoundButton(android.widget.CompoundButton)

Aggregations

Repo (org.fdroid.fdroid.data.Repo)30 Test (org.junit.Test)14 RepoDetails (org.fdroid.fdroid.mock.RepoDetails)8 ArrayList (java.util.ArrayList)5 FDroidProviderTest (org.fdroid.fdroid.data.FDroidProviderTest)5 NonNull (android.support.annotation.NonNull)4 InputStream (java.io.InputStream)4 List (java.util.List)4 JarEntry (java.util.jar.JarEntry)4 JarFile (java.util.jar.JarFile)4 IndexV1Updater (org.fdroid.fdroid.IndexV1Updater)4 Apk (org.fdroid.fdroid.data.Apk)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 ContentValues (android.content.ContentValues)3 App (org.fdroid.fdroid.data.App)3 RepoPushRequest (org.fdroid.fdroid.data.RepoPushRequest)3 Uri (android.net.Uri)2 View (android.view.View)2 TextView (android.widget.TextView)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)2