List of usage examples for android.os PowerManager PARTIAL_WAKE_LOCK
int PARTIAL_WAKE_LOCK
To view the source code for android.os PowerManager PARTIAL_WAKE_LOCK.
Click Source Link
From source file:org.videolan.vlc.MediaService.java
@Override public void onCreate() { super.onCreate(); // Get libVLC instance try {// w w w . java2 s . co m mLibVLC = Util.getLibVlcInstance(); } catch (LibVlcException e) { e.printStackTrace(); } Thread.setDefaultUncaughtExceptionHandler(new VlcCrashHandler()); mCallback = new HashMap<IMediaServiceCallback, Integer>(); mMediaList = new ArrayList<Media>(); mPrevious = new Stack<Media>(); mEventHandler = EventHandler.getInstance(); mRemoteControlClientReceiverComponent = new ComponentName(getPackageName(), RemoteControlClientReceiver.class.getName()); // Make sure the audio player will acquire a wake-lock while playing. If we don't do // that, the CPU might go to sleep while the song is playing, causing playback to stop. PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); IntentFilter filter = new IntentFilter(); filter.setPriority(Integer.MAX_VALUE); filter.addAction(ACTION_REMOTE_BACKWARD); filter.addAction(ACTION_REMOTE_PLAYPAUSE); filter.addAction(ACTION_REMOTE_PLAY); filter.addAction(ACTION_REMOTE_PAUSE); filter.addAction(ACTION_REMOTE_STOP); filter.addAction(ACTION_REMOTE_FORWARD); filter.addAction(ACTION_REMOTE_LAST_PLAYLIST); filter.addAction(Intent.ACTION_HEADSET_PLUG); filter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY); filter.addAction(VLCApplication.SLEEP_INTENT); registerReceiver(serviceReceiver, filter); final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); boolean stealRemoteControl = pref.getBoolean("enable_steal_remote_control", false); if (!Util.isFroyoOrLater() || stealRemoteControl) { /* Backward compatibility for API 7 */ filter = new IntentFilter(); if (stealRemoteControl) filter.setPriority(Integer.MAX_VALUE); filter.addAction(Intent.ACTION_MEDIA_BUTTON); mRemoteControlClientReceiver = new RemoteControlClientReceiver(); registerReceiver(mRemoteControlClientReceiver, filter); } AudioUtil.prepareCacheFolder(this); }
From source file:butter.droid.base.torrent.TorrentService.java
public void streamTorrent(@NonNull final String torrentUrl) { Timber.d("streamTorrent"); mStopped = false;/* w w w . j a v a2s . co m*/ if (mTorrentStream.isStreaming()) return; Timber.d("Starting streaming"); PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); if (mWakeLock != null && mWakeLock.isHeld()) { mWakeLock.release(); mWakeLock = null; } mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKE_LOCK); mWakeLock.acquire(); TorrentOptions options = mTorrentStream.getOptions(); options.setRemoveFilesAfterStop(true); options.setMaxConnections(PrefUtils.get(this, Prefs.LIBTORRENT_CONNECTION_LIMIT, 200)); options.setMaxDownloadSpeed(PrefUtils.get(this, Prefs.LIBTORRENT_DOWNLOAD_LIMIT, 0)); options.setMaxUploadSpeed(PrefUtils.get(this, Prefs.LIBTORRENT_UPLOAD_LIMIT, 0)); options.setSaveLocation(PrefUtils.get(this, Prefs.STORAGE_LOCATION, ButterApplication.getStreamDir())); mTorrentStream.setOptions(options); mIsReady = false; mTorrentStream.addListener(this); mTorrentStream.startStream(torrentUrl); }
From source file:com.ifeng.util.download.DownloadThread.java
/** * Executes the download in a separate thread */// www .jav a 2s . c om @Override public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); State state = new State(mInfo); ProxyHttpClient client = null; PowerManager.WakeLock wakeLock = null; int finalStatus = Downloads.Impl.STATUS_UNKNOWN_ERROR; try { PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Constants.TAG); wakeLock.acquire(); if (Constants.LOGV) { Log.v(Constants.TAG, "initiating download for " + mInfo.mUri); } client = new ProxyHttpClient(mContext, userAgent()); boolean finished = false; while (!finished) { Log.i(Constants.TAG, "Initiating request for download " + mInfo.mId); HttpGet request = new HttpGet(state.mRequestUri.trim()); try { executeDownload(state, client, request); finished = true; } catch (RetryDownload exc) { // fall through exc.printStackTrace(); } finally { request.abort(); request = null; } } if (Constants.LOGV) { Log.v(Constants.TAG, "download completed for " + mInfo.mUri); } finalizeDestinationFile(state); finalStatus = Downloads.Impl.STATUS_SUCCESS; } catch (StopRequest error) { // remove the cause before printing, in case it contains PII Log.w(Constants.TAG, "Aborting request for download " + mInfo.mId + ": " + error.getMessage()); Log.w(Constants.TAG, "download error:", error); finalStatus = error.mFinalStatus; displayMsg(finalStatus, error.getMessage()); // mInfo.mFailedReason = mInfo.mFailedReason + " |||| " + Utils.getStackTraceString(error); // fall through to finally block } catch (Throwable ex) { // sometimes the socket code throws unchecked // exceptions Log.w(Constants.TAG, "Exception for id " + mInfo.mId + ": " + ex); Log.w(Constants.TAG, "download error:", ex); finalStatus = Downloads.Impl.STATUS_UNKNOWN_ERROR; displayMsg(finalStatus, ex.getMessage()); // mInfo.mFailedReason = mInfo.mFailedReason + "||||" + Utils.getStackTraceString(ex); // falls through to the code that reports an error } finally { if (wakeLock != null) { wakeLock.release(); wakeLock = null; } if (client != null) { client.close(); client = null; } cleanupDestination(state, finalStatus); notifyDownloadCompleted(finalStatus, state.mCountRetry, state.mRetryAfter, state.mRedirectCount, state.mGotData, state.mFilename, state.mNewUri, state.mMimeType); --DownloadService.mCurrentThreadNum; if (!Downloads.Impl.isStatusCompleted(finalStatus)) { mInfo.mHasActiveThread = false; } } }
From source file:com.cyanogenmod.eleven.MediaButtonIntentReceiver.java
private static void acquireWakeLockAndSendMessage(Context context, Message msg, long delay) { if (mWakeLock == null) { Context appContext = context.getApplicationContext(); PowerManager pm = (PowerManager) appContext.getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Eleven headset button"); mWakeLock.setReferenceCounted(false); }// w w w.j ava2 s. c om if (DEBUG) Log.v(TAG, "Acquiring wake lock and sending " + msg.what); // Make sure we don't indefinitely hold the wake lock under any circumstances mWakeLock.acquire(10000); mHandler.sendMessageDelayed(msg, delay); }
From source file:com.yamin.kk.service.AudioService.java
@Override public void onCreate() { super.onCreate(); // Get libVLC instance try {//from www. j a v a 2 s . co m mLibVLC = Util.getLibVlcInstance(); } catch (LibVlcException e) { e.printStackTrace(); } mCallback = new HashMap<IAudioServiceCallback, Integer>(); mCurrentIndex = -1; mPrevious = new Stack<Integer>(); mEventHandler = EventHandler.getInstance(); mRemoteControlClientReceiverComponent = new ComponentName(getPackageName(), RemoteControlClientReceiver.class.getName()); // Make sure the audio player will acquire a wake-lock while playing. If we don't do // that, the CPU might go to sleep while the song is playing, causing playback to stop. PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); IntentFilter filter = new IntentFilter(); filter.setPriority(Integer.MAX_VALUE); filter.addAction(ACTION_REMOTE_BACKWARD); filter.addAction(ACTION_REMOTE_PLAYPAUSE); filter.addAction(ACTION_REMOTE_PLAY); filter.addAction(ACTION_REMOTE_PAUSE); filter.addAction(ACTION_REMOTE_STOP); filter.addAction(ACTION_REMOTE_FORWARD); filter.addAction(ACTION_REMOTE_LAST_PLAYLIST); filter.addAction(ACTION_WIDGET_INIT); filter.addAction(Intent.ACTION_HEADSET_PLUG); filter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY); filter.addAction(VLCApplication.SLEEP_INTENT); registerReceiver(serviceReceiver, filter); final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); boolean stealRemoteControl = pref.getBoolean("enable_steal_remote_control", false); if (!Util.isFroyoOrLater() || stealRemoteControl) { /* Backward compatibility for API 7 */ filter = new IntentFilter(); if (stealRemoteControl) filter.setPriority(Integer.MAX_VALUE); filter.addAction(Intent.ACTION_MEDIA_BUTTON); mRemoteControlClientReceiver = new RemoteControlClientReceiver(); registerReceiver(mRemoteControlClientReceiver, filter); } }
From source file:com.andrew.apollo.MediaButtonIntentReceiver.java
private static void acquireWakeLockAndSendMessage(Context context, Message msg, long delay) { if (mWakeLock == null) { Context appContext = context.getApplicationContext(); PowerManager pm = (PowerManager) appContext.getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Apollo headset button"); mWakeLock.setReferenceCounted(false); }//from w ww . ja va2s . c om if (DEBUG) Log.v(TAG, "Acquiring wake lock and sending " + msg.what); // Make sure we don't indefinitely hold the wake lock under any circumstances mWakeLock.acquire(10000); mHandler.sendMessageDelayed(msg, delay); }
From source file:com.github.diogochbittencourt.googleplaydownloader.downloader.impl.DownloadThread.java
/** * Executes the download in a separate thread *//* w w w. j a v a 2 s. c o m*/ public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); State state = new State(mInfo, mService); AndroidHttpClient client = null; PowerManager.WakeLock wakeLock = null; int finalStatus = DownloaderService.STATUS_UNKNOWN_ERROR; try { PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Constants.TAG); wakeLock.acquire(); if (Constants.LOGV) { Log.v(Constants.TAG, "initiating download for " + mInfo.mFileName); Log.v(Constants.TAG, " at " + mInfo.mUri); } client = AndroidHttpClient.newInstance(userAgent(), mContext); boolean finished = false; while (!finished) { if (Constants.LOGV) { Log.v(Constants.TAG, "initiating download for " + mInfo.mFileName); Log.v(Constants.TAG, " at " + mInfo.mUri); } // Set or unset proxy, which may have changed since last GET // request. // setDefaultProxy() supports null as proxy parameter. ConnRouteParams.setDefaultProxy(client.getParams(), getPreferredHttpHost(mContext, state.mRequestUri)); HttpGet request = new HttpGet(state.mRequestUri); try { executeDownload(state, client, request); finished = true; } catch (RetryDownload exc) { // fall through } finally { request.abort(); request = null; } } if (Constants.LOGV) { Log.v(Constants.TAG, "download completed for " + mInfo.mFileName); Log.v(Constants.TAG, " at " + mInfo.mUri); } finalizeDestinationFile(state); finalStatus = DownloaderService.STATUS_SUCCESS; } catch (StopRequest error) { // remove the cause before printing, in case it contains PII Log.w(Constants.TAG, "Aborting request for download " + mInfo.mFileName + ": " + error.getMessage()); error.printStackTrace(); finalStatus = error.mFinalStatus; // fall through to finally block } catch (Throwable ex) { // sometimes the socket code throws unchecked // exceptions Log.w(Constants.TAG, "Exception for " + mInfo.mFileName + ": " + ex); finalStatus = DownloaderService.STATUS_UNKNOWN_ERROR; // falls through to the code that reports an error } finally { if (wakeLock != null) { wakeLock.release(); wakeLock = null; } if (client != null) { client.close(); client = null; } cleanupDestination(state, finalStatus); notifyDownloadCompleted(finalStatus, state.mCountRetry, state.mRetryAfter, state.mRedirectCount, state.mGotData, state.mFilename); } }
From source file:com.google.android.vending.expansion.downloader.impl.DownloadThread.java
/** * Executes the download in a separate thread *//*from ww w.ja v a2 s. co m*/ public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); State state = new State(mInfo, mService); AndroidHttpClient client = null; PowerManager.WakeLock wakeLock = null; int finalStatus = DownloaderService.STATUS_UNKNOWN_ERROR; try { PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Constants.TAG); wakeLock.acquire(); if (Constants.LOGV) { Log.v(Constants.TAG, "initiating download for " + mInfo.mFileName); Log.v(Constants.TAG, " at " + mInfo.mUri); } client = AndroidHttpClient.newInstance(userAgent(), mContext); boolean finished = false; while (!finished) { if (Constants.LOGV) { Log.v(Constants.TAG, "initiating download for " + mInfo.mFileName); Log.v(Constants.TAG, " at " + mInfo.mUri); } // Set or unset proxy, which may have changed since last GET // request. // setDefaultProxy() supports null as proxy parameter. ConnRouteParams.setDefaultProxy(client.getParams(), getPreferredHttpHost(mContext, state.mRequestUri)); HttpGet request = new HttpGet(state.mRequestUri); try { executeDownload(state, client, request); finished = true; } catch (RetryDownload exc) { // fall through } finally { request.abort(); request = null; } } if (Constants.LOGV) { Log.v(Constants.TAG, "download completed for " + mInfo.mFileName); Log.v(Constants.TAG, " at " + mInfo.mUri); } finalizeDestinationFile(state); finalStatus = DownloaderService.STATUS_SUCCESS; } catch (StopRequest error) { // remove the cause before printing, in case it contains PII Log.w(Constants.TAG, "Aborting request for download " + mInfo.mFileName + ": " + error.getMessage()); error.printStackTrace(); finalStatus = error.mFinalStatus; // fall through to finally block } catch (Throwable ex) { // sometimes the socket code throws unchecked // exceptions Log.w(Constants.TAG, "Exception for " + mInfo.mFileName + ": " + ex); finalStatus = DownloaderService.STATUS_UNKNOWN_ERROR; // falls through to the code that reports an error } finally { if (wakeLock != null) { wakeLock.release(); wakeLock = null; } if (client != null) { client.close(); client = null; } cleanupDestination(state, finalStatus); notifyDownloadCompleted(finalStatus, state.mCountRetry, state.mRetryAfter, state.mRedirectCount, state.mGotData, state.mFilename); } }
From source file:com.google.android.gcm.GCMBaseIntentService.java
/** * Called from the broadcast receiver.//from ww w . jav a 2 s . com * <p> * Will process the received intent, call handleMessage(), registered(), * etc. in background threads, with a wake lock, while keeping the service * alive. */ static void runIntentInService(Context context, Intent intent, String className) { synchronized (LOCK) { if (sWakeLock == null) { // This is called from BroadcastReceiver, there is no init. PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); sWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCK_KEY); } } Log.v(TAG, "Acquiring wakelock"); sWakeLock.acquire(); intent.setClassName(context, className); context.startService(intent); }
From source file:org.videolan.myvlc.core.mediaController.AudioService.java
@Override public void onCreate() { super.onCreate(); // Get libVLC instance // try { // mLibVLC = Util.getLibVlcInstance(); // } catch (LibVlcException e) { // e.printStackTrace(); // }/*from w ww .ja v a 2 s .c o m*/ // mCallback = new HashMap<IAudioServiceCallback, Integer>(); mMediaList = new ArrayList<Media>(); mPrevious = new Stack<Media>(); // mEventHandler = EventHandler.getInstance(); mRemoteControlClientReceiverComponent = new ComponentName(getPackageName(), RemoteControlClientReceiver.class.getName()); // Make sure the audio player will acquire a wake-lock while playing. If we don't do // that, the CPU might go to sleep while the song is playing, causing playback to stop. PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); IntentFilter filter = new IntentFilter(); filter.setPriority(Integer.MAX_VALUE); filter.addAction(ACTION_REMOTE_BACKWARD); filter.addAction(ACTION_REMOTE_PLAYPAUSE); filter.addAction(ACTION_REMOTE_PLAY); filter.addAction(ACTION_REMOTE_PAUSE); filter.addAction(ACTION_REMOTE_STOP); filter.addAction(ACTION_REMOTE_FORWARD); filter.addAction(ACTION_REMOTE_LAST_PLAYLIST); filter.addAction(ACTION_WIDGET_INIT); filter.addAction(Intent.ACTION_HEADSET_PLUG); filter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY); filter.addAction(MyVLCApp.SLEEP_INTENT); registerReceiver(serviceReceiver, filter); final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); boolean stealRemoteControl = pref.getBoolean("enable_steal_remote_control", false); if (!Util.isFroyoOrLater() || stealRemoteControl) { /* Backward compatibility for API 7 */ filter = new IntentFilter(); if (stealRemoteControl) filter.setPriority(Integer.MAX_VALUE); filter.addAction(Intent.ACTION_MEDIA_BUTTON); mRemoteControlClientReceiver = new RemoteControlClientReceiver(); registerReceiver(mRemoteControlClientReceiver, filter); } //AudioUtil.prepareCacheFolder(this); }