Java Code Examples for android.os.Process#THREAD_PRIORITY_FOREGROUND
The following examples show how to use
android.os.Process#THREAD_PRIORITY_FOREGROUND .
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: MediaPlayer.java From droidel with Apache License 2.0 | 6 votes |
public TimeProvider(MediaPlayer mp) { mPlayer = mp; try { getCurrentTimeUs(true, false); } catch (IllegalStateException e) { // we assume starting position mRefresh = true; } Looper looper; if ((looper = Looper.myLooper()) == null && (looper = Looper.getMainLooper()) == null) { // Create our own looper here in case MP was created without one mHandlerThread = new HandlerThread("MediaPlayerMTPEventThread", Process.THREAD_PRIORITY_FOREGROUND); mHandlerThread.start(); looper = mHandlerThread.getLooper(); } mEventHandler = new EventHandler(looper); mListeners = new MediaTimeProvider.OnMediaTimeListener[0]; mTimes = new long[0]; mLastTimeUs = 0; mTimeAdjustment = 0; }
Example 2
Source File: QueuedWork.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Lazily create a handler on a separate thread. * * @return the handler */ private static Handler getHandler() { synchronized (sLock) { if (sHandler == null) { HandlerThread handlerThread = new HandlerThread("queued-work-looper", Process.THREAD_PRIORITY_FOREGROUND); handlerThread.start(); sHandler = new QueuedWorkHandler(handlerThread.getLooper()); } return sHandler; } }
Example 3
Source File: MaterialLiveWallpaperService.java From GeometricWeather with GNU Lesser General Public License v3.0 | 5 votes |
WeatherEngine() { super(); deviceOrientation = DeviceOrientation.TOP; handlerThread = new HandlerThread( String.valueOf(System.currentTimeMillis()), Process.THREAD_PRIORITY_FOREGROUND ); handlerThread.start(); handler = new Handler(handlerThread.getLooper()); }
Example 4
Source File: BackgroundService.java From pjsip-android with Apache License 2.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getSimpleName()); mWakeLock.acquire(); mWorkerThread = new HandlerThread(getClass().getSimpleName(), Process.THREAD_PRIORITY_FOREGROUND); mWorkerThread.setPriority(Thread.MAX_PRIORITY); mWorkerThread.start(); mHandler = new Handler(mWorkerThread.getLooper()); }
Example 5
Source File: PjSipService.java From react-native-sip with GNU General Public License v3.0 | 4 votes |
@Override public int onStartCommand(final Intent intent, int flags, int startId) { if (!mInitialized) { if (intent != null && intent.hasExtra("service")) { mServiceConfiguration = ServiceConfigurationDTO.fromMap((Map) intent.getSerializableExtra("service")); } mWorkerThread = new HandlerThread(getClass().getSimpleName(), Process.THREAD_PRIORITY_FOREGROUND); mWorkerThread.setPriority(Thread.MAX_PRIORITY); mWorkerThread.start(); mHandler = new Handler(mWorkerThread.getLooper()); mEmitter = new PjSipBroadcastEmiter(this); mAudioManager = (AudioManager) getApplicationContext().getSystemService(AUDIO_SERVICE); mPowerManager = (PowerManager) getApplicationContext().getSystemService(POWER_SERVICE); mWifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); mWifiLock = mWifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, this.getPackageName()+"-wifi-call-lock"); mWifiLock.setReferenceCounted(false); mTelephonyManager = (TelephonyManager) getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE); mGSMIdle = mTelephonyManager.getCallState() == TelephonyManager.CALL_STATE_IDLE; IntentFilter phoneStateFilter = new IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED); registerReceiver(mPhoneStateChangedReceiver, phoneStateFilter); mInitialized = true; job(new Runnable() { @Override public void run() { load(); } }); } if (intent != null) { job(new Runnable() { @Override public void run() { handle(intent); } }); } return START_NOT_STICKY; }
Example 6
Source File: UiThread.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
private UiThread() { super("android.ui", Process.THREAD_PRIORITY_FOREGROUND, false /*allowIo*/); }
Example 7
Source File: ServiceSinkhole.java From tracker-control-android with GNU General Public License v3.0 | 4 votes |
@Override public void onCreate() { Log.i(TAG, "Create version=" + Util.getSelfVersionName(this) + "/" + Util.getSelfVersionCode(this)); startForeground(NOTIFY_WAITING, getWaitingNotification()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); if (jni_context != 0) { Log.w(TAG, "Create with context=" + jni_context); jni_stop(jni_context); synchronized (jni_lock) { jni_done(jni_context); jni_context = 0; } } // Native init jni_context = jni_init(Build.VERSION.SDK_INT); Log.i(TAG, "Created context=" + jni_context); boolean pcap = prefs.getBoolean("pcap", false); setPcap(pcap, this); prefs.registerOnSharedPreferenceChangeListener(this); Util.setTheme(this); super.onCreate(); HandlerThread commandThread = new HandlerThread(getString(R.string.app_name) + " command", Process.THREAD_PRIORITY_FOREGROUND); HandlerThread logThread = new HandlerThread(getString(R.string.app_name) + " log", Process.THREAD_PRIORITY_BACKGROUND); HandlerThread statsThread = new HandlerThread(getString(R.string.app_name) + " stats", Process.THREAD_PRIORITY_BACKGROUND); commandThread.start(); logThread.start(); statsThread.start(); commandLooper = commandThread.getLooper(); logLooper = logThread.getLooper(); statsLooper = statsThread.getLooper(); commandHandler = new CommandHandler(commandLooper); logHandler = new LogHandler(logLooper); statsHandler = new StatsHandler(statsLooper); // Listen for user switches if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { IntentFilter ifUser = new IntentFilter(); ifUser.addAction(Intent.ACTION_USER_BACKGROUND); ifUser.addAction(Intent.ACTION_USER_FOREGROUND); registerReceiver(userReceiver, ifUser); registeredUser = true; } // Listen for idle mode state changes if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { IntentFilter ifIdle = new IntentFilter(); ifIdle.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED); registerReceiver(idleStateReceiver, ifIdle); registeredIdleState = true; } // Listen for added/removed applications IntentFilter ifPackage = new IntentFilter(); ifPackage.addAction(Intent.ACTION_PACKAGE_ADDED); ifPackage.addAction(Intent.ACTION_PACKAGE_REMOVED); ifPackage.addDataScheme("package"); registerReceiver(packageChangedReceiver, ifPackage); registeredPackageChanged = true; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) try { listenNetworkChanges(); } catch (Throwable ex) { Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); listenConnectivityChanges(); } else listenConnectivityChanges(); // Monitor networks ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); cm.registerNetworkCallback( new NetworkRequest.Builder() .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET).build(), networkMonitorCallback); // Setup house holding Intent alarmIntent = new Intent(this, ServiceSinkhole.class); alarmIntent.setAction(ACTION_HOUSE_HOLDING); PendingIntent pi; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) pi = PendingIntent.getForegroundService(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); else pi = PendingIntent.getService(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); am.setInexactRepeating(AlarmManager.RTC, SystemClock.elapsedRealtime() + 60 * 1000, AlarmManager.INTERVAL_HALF_DAY, pi); }
Example 8
Source File: ServiceVPN.java From InviZible with GNU General Public License v3.0 | 4 votes |
@Override public void onCreate() { notificationManager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE); Log.i(LOG_TAG, "VPN Create version=" + Util.getSelfVersionName(this) + "/" + Util.getSelfVersionCode(this)); Util.canFilterAsynchronous(this); if (jni_context != 0) { Log.w(LOG_TAG, "VPN Create with context=" + jni_context); jni_stop(jni_context); synchronized (jni_lock) { jni_done(jni_context); jni_context = 0; } } // Native init jni_context = jni_init(Build.VERSION.SDK_INT); Log.i(LOG_TAG, "VPN Created context=" + jni_context); super.onCreate(); HandlerThread commandThread = new HandlerThread(getString(R.string.app_name) + " command", Process.THREAD_PRIORITY_FOREGROUND); commandThread.start(); commandLooper = commandThread.getLooper(); commandHandler = ServiceVPNHandler.getInstance(commandLooper, this); // Listen for idle mode state changes if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { IntentFilter ifIdle = new IntentFilter(); ifIdle.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED); registerReceiver(idleStateReceiver, ifIdle); registeredIdleState = true; } // Listen for added/removed applications IntentFilter ifPackage = new IntentFilter(); ifPackage.addAction(Intent.ACTION_PACKAGE_ADDED); ifPackage.addAction(Intent.ACTION_PACKAGE_REMOVED); ifPackage.addDataScheme("package"); registerReceiver(packageChangedReceiver, ifPackage); registeredPackageChanged = true; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { try { listenNetworkChanges(); } catch (Throwable ex) { Log.w(LOG_TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); listenConnectivityChanges(); } } else { listenConnectivityChanges(); } }
Example 9
Source File: Priority.java From Rocket with Apache License 2.0 | 4 votes |
@IntRange(from = Process.THREAD_PRIORITY_FOREGROUND, to = Process.THREAD_PRIORITY_LOWEST) int priority();
Example 10
Source File: PjSipService.java From react-native-pjsip with GNU General Public License v3.0 | 4 votes |
@Override public int onStartCommand(final Intent intent, int flags, int startId) { if (!mInitialized) { if (intent != null && intent.hasExtra("service")) { mServiceConfiguration = ServiceConfigurationDTO.fromMap((Map) intent.getSerializableExtra("service")); } mWorkerThread = new HandlerThread(getClass().getSimpleName(), Process.THREAD_PRIORITY_FOREGROUND); mWorkerThread.setPriority(Thread.MAX_PRIORITY); mWorkerThread.start(); mHandler = new Handler(mWorkerThread.getLooper()); mEmitter = new PjSipBroadcastEmiter(this); mAudioManager = (AudioManager) getApplicationContext().getSystemService(AUDIO_SERVICE); mPowerManager = (PowerManager) getApplicationContext().getSystemService(POWER_SERVICE); mWifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); mWifiLock = mWifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, this.getPackageName()+"-wifi-call-lock"); mWifiLock.setReferenceCounted(false); mTelephonyManager = (TelephonyManager) getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE); mGSMIdle = mTelephonyManager.getCallState() == TelephonyManager.CALL_STATE_IDLE; IntentFilter phoneStateFilter = new IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED); registerReceiver(mPhoneStateChangedReceiver, phoneStateFilter); mInitialized = true; job(new Runnable() { @Override public void run() { load(); } }); } if (intent != null) { job(new Runnable() { @Override public void run() { handle(intent); } }); } return START_NOT_STICKY; }
Example 11
Source File: ServiceSinkhole.java From NetGuard with GNU General Public License v3.0 | 4 votes |
@Override public void onCreate() { Log.i(TAG, "Create version=" + Util.getSelfVersionName(this) + "/" + Util.getSelfVersionCode(this)); startForeground(NOTIFY_WAITING, getWaitingNotification()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); if (jni_context != 0) { Log.w(TAG, "Create with context=" + jni_context); jni_stop(jni_context); synchronized (jni_lock) { jni_done(jni_context); jni_context = 0; } } // Native init jni_context = jni_init(Build.VERSION.SDK_INT); Log.i(TAG, "Created context=" + jni_context); boolean pcap = prefs.getBoolean("pcap", false); setPcap(pcap, this); prefs.registerOnSharedPreferenceChangeListener(this); Util.setTheme(this); super.onCreate(); HandlerThread commandThread = new HandlerThread(getString(R.string.app_name) + " command", Process.THREAD_PRIORITY_FOREGROUND); HandlerThread logThread = new HandlerThread(getString(R.string.app_name) + " log", Process.THREAD_PRIORITY_BACKGROUND); HandlerThread statsThread = new HandlerThread(getString(R.string.app_name) + " stats", Process.THREAD_PRIORITY_BACKGROUND); commandThread.start(); logThread.start(); statsThread.start(); commandLooper = commandThread.getLooper(); logLooper = logThread.getLooper(); statsLooper = statsThread.getLooper(); commandHandler = new CommandHandler(commandLooper); logHandler = new LogHandler(logLooper); statsHandler = new StatsHandler(statsLooper); // Listen for user switches if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { IntentFilter ifUser = new IntentFilter(); ifUser.addAction(Intent.ACTION_USER_BACKGROUND); ifUser.addAction(Intent.ACTION_USER_FOREGROUND); registerReceiver(userReceiver, ifUser); registeredUser = true; } // Listen for idle mode state changes if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { IntentFilter ifIdle = new IntentFilter(); ifIdle.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED); registerReceiver(idleStateReceiver, ifIdle); registeredIdleState = true; } // Listen for added/removed applications IntentFilter ifPackage = new IntentFilter(); ifPackage.addAction(Intent.ACTION_PACKAGE_ADDED); ifPackage.addAction(Intent.ACTION_PACKAGE_REMOVED); ifPackage.addDataScheme("package"); registerReceiver(packageChangedReceiver, ifPackage); registeredPackageChanged = true; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) try { listenNetworkChanges(); } catch (Throwable ex) { Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); listenConnectivityChanges(); } else listenConnectivityChanges(); // Monitor networks ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); cm.registerNetworkCallback( new NetworkRequest.Builder() .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET).build(), networkMonitorCallback); // Setup house holding Intent alarmIntent = new Intent(this, ServiceSinkhole.class); alarmIntent.setAction(ACTION_HOUSE_HOLDING); PendingIntent pi; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) pi = PendingIntent.getForegroundService(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); else pi = PendingIntent.getService(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); am.setInexactRepeating(AlarmManager.RTC, SystemClock.elapsedRealtime() + 60 * 1000, AlarmManager.INTERVAL_HALF_DAY, pi); }
Example 12
Source File: ITask.java From android-performance with MIT License | 2 votes |
/** * 优先级的范围,可根据Task重要程度及工作量指定;之后根据实际情况决定是否有必要放更大 * * @return */ @IntRange(from = Process.THREAD_PRIORITY_FOREGROUND, to = Process.THREAD_PRIORITY_LOWEST) int priority();