Example usage for android.os Process THREAD_PRIORITY_LOWEST

List of usage examples for android.os Process THREAD_PRIORITY_LOWEST

Introduction

In this page you can find the example usage for android.os Process THREAD_PRIORITY_LOWEST.

Prototype

int THREAD_PRIORITY_LOWEST

To view the source code for android.os Process THREAD_PRIORITY_LOWEST.

Click Source Link

Document

Lowest available thread priority.

Usage

From source file:org.fdroid.fdroid.UpdateService.java

@Override
protected void onHandleIntent(Intent intent) {
    Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST);

    final long startTime = System.currentTimeMillis();
    String address = intent.getStringExtra(EXTRA_ADDRESS);
    boolean manualUpdate = intent.getBooleanExtra(EXTRA_MANUAL_UPDATE, false);

    try {//from  w w w  .ja v a  2s .co  m
        // See if it's time to actually do anything yet...
        if (manualUpdate) {
            Utils.debugLog(TAG, "Unscheduled (manually requested) update");
        } else if (!verifyIsTimeForScheduledRun()) {
            return;
        }

        // Grab some preliminary information, then we can release the
        // database while we do all the downloading, etc...
        List<Repo> repos = RepoProvider.Helper.all(this);

        //List<Repo> swapRepos = new ArrayList<>();
        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) {
                //swapRepos.add(repo);
                continue;
            }

            sendStatus(this, STATUS_INFO, getString(R.string.status_connecting_to_repo, repo.address));
            RepoUpdater updater = new RepoUpdater(getBaseContext(), repo);
            localBroadcastManager.registerReceiver(downloadProgressReceiver,
                    DownloaderService.getIntentFilter(updater.indexUrl, Downloader.ACTION_PROGRESS));
            updater.setProgressListener(this);
            try {
                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);
            }
            localBroadcastManager.unregisterReceiver(downloadProgressReceiver);

            // now that downloading the index is done, start downloading updates
            if (changes && fdroidPrefs.isAutoDownloadEnabled()) {
                autoDownloadUpdates(repo.address);
            }
        }

        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());
        PreferencesCompat.apply(e);

        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());
    }

    long time = System.currentTimeMillis() - startTime;
    Log.i(TAG, "Updating repo(s) complete, took " + time / 1000 + " seconds to complete.");
}

From source file:mobisocial.musubi.service.AddressBookUpdateHandler.java

public static AddressBookUpdateHandler newInstance(Context context, SQLiteOpenHelper dbh,
        ContentResolver resolver) {/*from   ww  w.  j  ava2  s  .c o  m*/
    HandlerThread thread = new HandlerThread("AddressBookUpdateThread");
    Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST);
    thread.start();
    AddressBookUpdateHandler abuh = new AddressBookUpdateHandler(context, dbh, thread, resolver);
    return abuh;
}

From source file:com.grazerss.EntryManager.java

public void doUnsubscribeFeed(String feedAtomId) {
    try {// www  .j av  a2  s .c  o  m
        Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST);

        synchronized (this) {
            if (isModelCurrentlyUpdated()) {
                return;
            }
            lockModel("EM.requestUnsubscribeFeed");
        }
        if (canFeedBeUnsubscribed(feedAtomId)) {
            databaseHelper.addFeed2Unsubscribe(feedAtomId);
            DBQuery dbq = prepareMarkFeedReadQuery(feedAtomId);
            if (dbq != null) {
                doMarkAllRead(dbq);
            }
        }
    } finally {
        synchronized (this) {
            unlockModel("EM.requestUnsubscribeFeed");
        }
    }

}

From source file:com.newsrob.EntryManager.java

public void requestClearCacheAndSync() {
    try {//from  w w  w.j  ava 2 s.  c  o  m
        runJob(new Job("Clearing Cache", EntryManager.this) {

            @Override
            public void run() throws Exception {

                try {
                    Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST);

                    synchronized (this) {
                        if (isModelCurrentlyUpdated())
                            return;
                        lockModel("EM.requestClearCacheAndSync");
                    }
                    doClearCache();
                } finally {
                    synchronized (this) {
                        unlockModel("EM.requestClearCacheAndSync");
                    }
                }
                fireModelUpdated();
                requestSynchronization(false);
            }

        });
    } catch (final Throwable e) {
        showExceptionToast("Clear Cache And Sync", e);
    }

}

From source file:com.newsrob.EntryManager.java

private void runSimpleJob(final String name, final Runnable runnable, final Handler handler) {
    new Thread(new Runnable() {
        public void run() {
            try {
                runJob(new Job(name, EntryManager.this) {

                    @Override/*from  w w w  .jav a 2  s  .  co  m*/
                    public void run() throws Exception {

                        try {
                            Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST);

                            synchronized (this) {
                                if (isModelCurrentlyUpdated())
                                    return;
                                lockModel(name);
                            }
                            runnable.run();
                        } finally {
                            synchronized (this) {
                                unlockModel(name);
                            }
                        }
                    }
                });
            } catch (final Throwable e) {
                if (handler != null) {
                    handler.post(new Runnable() {

                        public void run() {
                            showExceptionToast(name, e);
                        }
                    });
                }
            }

        }
    }).start();
}

From source file:com.android.launcher2.AsyncTaskCallback.java

protected void snapToPage(int whichPage, int delta, int duration) {
    super.snapToPage(whichPage, delta, duration);
    updateCurrentTab(whichPage);//from w  ww. ja v a  2s.  co m

    // Update the thread priorities given the direction lookahead
    Iterator<AppsCustomizeAsyncTask> iter = mRunningTasks.iterator();
    while (iter.hasNext()) {
        AppsCustomizeAsyncTask task = (AppsCustomizeAsyncTask) iter.next();
        int pageIndex = task.page;
        if ((mNextPage > mCurrentPage && pageIndex >= mCurrentPage)
                || (mNextPage < mCurrentPage && pageIndex <= mCurrentPage)) {
            task.setThreadPriority(getThreadPriorityForPage(pageIndex));
        } else {
            task.setThreadPriority(Process.THREAD_PRIORITY_LOWEST);
        }
    }
}

From source file:com.phonemetra.turbo.launcher.AsyncTaskCallback.java

protected void snapToPage(int whichPage, int delta, int duration) {
    super.snapToPage(whichPage, delta, duration);

    // Update the thread priorities given the direction lookahead
    Iterator<AppsCustomizeAsyncTask> iter = mRunningTasks.iterator();
    while (iter.hasNext()) {
        AppsCustomizeAsyncTask task = (AppsCustomizeAsyncTask) iter.next();
        int pageIndex = task.page;
        if ((mNextPage > mCurrentPage && pageIndex >= mCurrentPage)
                || (mNextPage < mCurrentPage && pageIndex <= mCurrentPage)) {
            task.setThreadPriority(getThreadPriorityForPage(pageIndex));
        } else {/*from  w  w  w .  j a  v a 2  s. c o m*/
            task.setThreadPriority(Process.THREAD_PRIORITY_LOWEST);
        }
    }
}

From source file:com.android.launcher2.AsyncTaskCallback.java

/**
 * Return the appropriate thread priority for loading for a given page (we give the current
 * page much higher priority)//from www.  j av  a 2s.  com
 */
private int getThreadPriorityForPage(int page) {
    // TODO-APPS_CUSTOMIZE: detect number of cores and set thread priorities accordingly below
    int pageDiff = getWidgetPageLoadPriority(page);
    if (pageDiff <= 0) {
        return Process.THREAD_PRIORITY_LESS_FAVORABLE;
    } else if (pageDiff <= 1) {
        return Process.THREAD_PRIORITY_LOWEST;
    } else {
        return Process.THREAD_PRIORITY_LOWEST;
    }
}

From source file:com.phonemetra.turbo.launcher.AsyncTaskCallback.java

/**
 * Return the appropriate thread priority for loading for a given page (we give the current
 * page much higher priority)//from   w  w w  . ja v  a 2  s  .  co  m
 */
private int getThreadPriorityForPage(int page) {

    int pageDiff = getWidgetPageLoadPriority(page);
    if (pageDiff <= 0) {
        return Process.THREAD_PRIORITY_LESS_FAVORABLE;
    } else if (pageDiff <= 1) {
        return Process.THREAD_PRIORITY_LOWEST;
    } else {
        return Process.THREAD_PRIORITY_LOWEST;
    }
}

From source file:com.grazerss.EntryManager.java

public void requestClearCacheAndSync() {
    try {//from w  w  w  . j a v  a 2 s  .  c o m
        runJob(new Job("Clearing Cache", EntryManager.this) {

            @Override
            public void run() throws Exception {

                try {
                    Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST);

                    synchronized (this) {
                        if (isModelCurrentlyUpdated()) {
                            return;
                        }
                        lockModel("EM.requestClearCacheAndSync");
                    }
                    doClearCache();
                } finally {
                    synchronized (this) {
                        unlockModel("EM.requestClearCacheAndSync");
                    }
                }
                fireModelUpdated();
                requestSynchronization(false);
            }

        });
    } catch (final Throwable e) {
        showExceptionToast("Clear Cache And Sync", e);
    }

}