Java Code Examples for android.os.Process#THREAD_PRIORITY_LESS_FAVORABLE

The following examples show how to use android.os.Process#THREAD_PRIORITY_LESS_FAVORABLE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThreadUtils.java    From litho with Apache License 2.0 6 votes vote down vote up
/**
 * Try to raise the priority of {@param threadId} to {@param targetThreadPriority}.
 *
 * @return the original thread priority of the target thread.
 */
public static int tryRaiseThreadPriority(int threadId, int targetThreadPriority) {
  // Main thread is about to be blocked, raise the running thread priority.
  final int originalThreadPriority = Process.getThreadPriority(threadId);
  boolean success = false;
  while (!success && targetThreadPriority < originalThreadPriority) {
    // Keep trying to increase thread priority of running thread as long as it is an increase.
    try {
      Process.setThreadPriority(threadId, targetThreadPriority);
      success = true;
    } catch (SecurityException e) {
      /*
       From {@link Process#THREAD_PRIORITY_DISPLAY}, some applications can not change
       the thread priority to that of the main thread. This catches that potential error
       and tries to set a lower priority.
      */
      targetThreadPriority += Process.THREAD_PRIORITY_LESS_FAVORABLE;
    }
  }
  return originalThreadPriority;
}
 
Example 2
Source File: ThreadUtils.java    From litho with Apache License 2.0 6 votes vote down vote up
/**
 * Try to raise the priority of {@param threadId} to {@param targetThreadPriority}.
 *
 * @return the original thread priority of the target thread.
 */
public static int tryRaiseThreadPriority(int threadId, int targetThreadPriority) {
  // Main thread is about to be blocked, raise the running thread priority.
  final int originalThreadPriority = Process.getThreadPriority(threadId);
  boolean success = false;
  while (!success && targetThreadPriority < originalThreadPriority) {
    // Keep trying to increase thread priority of running thread as long as it is an increase.
    try {
      Process.setThreadPriority(threadId, targetThreadPriority);
      success = true;
    } catch (SecurityException e) {
      /*
       From {@link Process#THREAD_PRIORITY_DISPLAY}, some applications can not change
       the thread priority to that of the main thread. This catches that potential error
       and tries to set a lower priority.
      */
      targetThreadPriority += Process.THREAD_PRIORITY_LESS_FAVORABLE;
    }
  }
  return originalThreadPriority;
}
 
Example 3
Source File: AppsCustomizePagedView.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
/**
 * Return the appropriate thread priority for loading for a given page (we give the current
 * page much higher priority)
 */
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;
    }
}
 
Example 4
Source File: AppsCustomizePagedView.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
/**
 * Return the appropriate thread priority for loading for a given page (we give the current
 * page much higher priority)
 */
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;
    }
}