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:uk.org.openseizuredetector.client.SdClientService.java
/** * onCreate() - called when services is created. Starts message * handler process to listen for messages from other processes. *///from ww w .j av a 2 s .c om @Override public void onCreate() { Log.v(TAG, "onCreate()"); // FIXME - do we really need this for the client??? // Create a wake lock, but don't use it until the service is started. PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag"); }
From source file:com.jtxdriggers.android.ventriloid.VentriloidService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { int id = intent.getExtras().getInt("id"); ServerAdapter db = new ServerAdapter(this); server = db.getServer(id);/*from www . ja v a2 s .c om*/ items = new ItemData(this); queue.clear(); volumePrefs = getSharedPreferences("VOLUMES" + server.getId(), Context.MODE_PRIVATE); passwordPrefs = getSharedPreferences("PASSWORDS" + server.getId(), Context.MODE_PRIVATE); wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE)) .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "VentriloidWakeLock"); wakeLock.acquire(); wifiLock = ((WifiManager) getSystemService(Context.WIFI_SERVICE)).createWifiLock(WifiManager.WIFI_MODE_FULL, "VentriloidWifiLock"); wifiLock.acquire(); disconnect = true; r = new Runnable() { public void run() { timeout = true; handler.postDelayed(new Runnable() { @Override public void run() { if (timeout) { VentriloInterface.logout(); sendBroadcast(new Intent(Main.SERVICE_RECEIVER).putExtra("type", (short) VentriloEvents.V3_EVENT_LOGIN_FAIL)); Toast.makeText(getApplicationContext(), "Connection timed out.", Toast.LENGTH_SHORT) .show(); reconnectTimer = 10; handler.post(r); } } }, 9500); if (VentriloInterface.login(server.getHostname() + ":" + server.getPort(), server.getUsername(), server.getPassword(), server.getPhonetic())) { new Thread(new Runnable() { public void run() { while (VentriloInterface.recv()) ; } }).start(); } else { handler.post(new Runnable() { @Override public void run() { VentriloEventData data = new VentriloEventData(); VentriloInterface.error(data); sendBroadcast(new Intent(Main.SERVICE_RECEIVER).putExtra("type", (short) VentriloEvents.V3_EVENT_LOGIN_FAIL)); Toast.makeText(getApplicationContext(), bytesToString(data.error.message), Toast.LENGTH_SHORT).show(); } }); } timeout = false; } }; handler.post(r); return Service.START_NOT_STICKY; }
From source file:org.gateshipone.odyssey.artworkdatabase.BulkDownloadService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (intent != null && intent.getAction().equals(ACTION_START_BULKDOWNLOAD)) { Log.v(TAG, "Starting bulk download in service with thread id: " + Thread.currentThread().getId()); // reset counter mRemainingArtists = 0;/*from w w w . j a va 2 s .c o m*/ mRemainingAlbums = 0; mSumImageDownloads = 0; String artistProvider = getString(R.string.pref_artwork_provider_artist_default); String albumProvider = getString(R.string.pref_artwork_provider_album_default); mWifiOnly = true; // read setting from extras Bundle extras = intent.getExtras(); if (extras != null) { artistProvider = extras.getString(BUNDLE_KEY_ARTIST_PROVIDER, getString(R.string.pref_artwork_provider_artist_default)); albumProvider = extras.getString(BUNDLE_KEY_ALBUM_PROVIDER, getString(R.string.pref_artwork_provider_album_default)); mWifiOnly = intent.getBooleanExtra(BUNDLE_KEY_WIFI_ONLY, true); } if (artistProvider.equals(getString(R.string.pref_artwork_provider_none_key)) && albumProvider.equals(getString(R.string.pref_artwork_provider_none_key))) { return START_NOT_STICKY; } if (!isDownloadAllowed(this)) { return START_NOT_STICKY; } PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); mWakelock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Odyssey_BulkDownloader"); // FIXME do some timeout checking. e.g. 5 minutes no new image then cancel the process mWakelock.acquire(); ArtworkManager artworkManager = ArtworkManager.getInstance(getApplicationContext()); artworkManager.initialize(artistProvider, albumProvider, mWifiOnly); artworkManager.bulkLoadImages(this, getApplicationContext()); } return START_STICKY; }
From source file:at.alladin.rmbt.android.test.RMBTService.java
@Override public void onCreate() { Log.d(DEBUG_TAG, "created"); super.onCreate(); handler = new Handler(); // initialise the locks loopMode = ConfigHelper.isLoopMode(this); // initialise the locks wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "RMBTWifiLock"); wakeLock = ((PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE)) .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "RMBTWakeLock"); // mNetworkStateIntentReceiver = new BroadcastReceiver() { // @Override//from w w w . j av a 2s . co m // public void onReceive(Context context, Intent intent) { // if // (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) // { // // final boolean connected = ! // intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, // false); // if (! connected) // stopTest(); // } // } // }; // final IntentFilter networkStateChangedFilter = new IntentFilter(); // networkStateChangedFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); // // registerReceiver(mNetworkStateIntentReceiver, // networkStateChangedFilter); }
From source file:cn.dacas.providers.downloads.DownloadThread.java
/** * Executes the download in a separate thread *///from ww w . j a v a2 s . co m public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); State state = new State(mInfo); AndroidHttpClient client = null; PowerManager.WakeLock wakeLock = null; int finalStatus = Downloads.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 = AndroidHttpClient.newInstance(userAgent(), mContext); boolean finished = false; while (!finished) { Log.i(Constants.TAG, "Initiating request for download " + mInfo.mId); 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.mUri); } finalizeDestinationFile(state); finalStatus = Downloads.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()); finalStatus = error.mFinalStatus; // 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); finalStatus = Downloads.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.mGotData, state.mFilename, state.mNewUri, state.mMimeType); mInfo.mHasActiveThread = false; } }
From source file:com.kong.zxreader.down.downloads.DownloadThread.java
/** * Executes the download in a separate thread *///www .ja v a 2s . c om public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); State state = new State(mInfo); AndroidHttpClient client = null; PowerManager.WakeLock wakeLock = null; int finalStatus = Downloads.STATUS_UNKNOWN_ERROR; try { PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, DownConstants.TAG); wakeLock.acquire(); if (DownConstants.LOGV) { Log.v(DownConstants.TAG, "initiating download for " + mInfo.mUri); } client = AndroidHttpClient.newInstance(userAgent(), mContext); boolean finished = false; while (!finished) { Log.i(DownConstants.TAG, "Initiating request for download " + mInfo.mId); HttpGet request = new HttpGet(state.mRequestUri); try { executeDownload(state, client, request); finished = true; } catch (RetryDownload exc) { // fall through } finally { request.abort(); request = null; } } if (DownConstants.LOGV) { Log.v(DownConstants.TAG, "download completed for " + mInfo.mUri); } finalizeDestinationFile(state); finalStatus = Downloads.STATUS_SUCCESS; } catch (StopRequest error) { // remove the cause before printing, in case it contains PII Log.w(DownConstants.TAG, "Aborting request for download " + mInfo.mId + ": " + error.getMessage()); finalStatus = error.mFinalStatus; // fall through to finally block } catch (Throwable ex) { // sometimes the socket code throws unchecked // exceptions Log.w(DownConstants.TAG, "Exception for id " + mInfo.mId + ": " + ex); finalStatus = Downloads.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.mGotData, state.mFilename, state.mNewUri, state.mMimeType); mInfo.mHasActiveThread = false; } }
From source file:com.sentaroh.android.TaskAutomation.TaskExecutor.java
public TaskExecutor(TaskResponse tr, TaskManagerParms tmp, TaskListItem tai, EnvironmentParms sdv) { taskListItem = tai;//from w ww. j a va 2 s.c o m envParms = sdv; taskResponse = tr; taskMgrParms = tmp; taskResponse.active_group_name = tai.group_name; taskResponse.active_task_name = tai.task_name; taskResponse.active_event_name = tai.event_name; taskResponse.prof_notification = tai.prof_notification; taskResponse.task_action_notification = tai.task_action_notification; mWakelockTask = ((PowerManager) taskMgrParms.context.getSystemService(Context.POWER_SERVICE)) .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK // | PowerManager.ON_AFTER_RELEASE , "TaskAutomation-TaskExecutor"); mWakelockTask.acquire(); }
From source file:com.foolhorse.downloaddemo.man.DownloadThread.java
/** * Executes the download in a separate thread *///from www . j a va2 s. co m @Override public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); State state = new State(mInfo); AndroidHttpClient client = null; PowerManager.WakeLock wakeLock = null; int finalStatus = Downloads.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 = AndroidHttpClient.newInstance(userAgent(), mContext); boolean finished = false; while (!finished) { Log.i(Constants.TAG, "Initiating request for download " + mInfo.mId); 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.mUri); } finalizeDestinationFile(state); finalStatus = Downloads.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()); finalStatus = error.mFinalStatus; // 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); finalStatus = Downloads.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.mGotData, state.mFilename, state.mNewUri, state.mMimeType); mInfo.mHasActiveThread = false; } }
From source file:com.android.providers.downloads.DownloadThread.java
/** * Executes the download in a separate thread *///from ww w . j a v a2 s . co m public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); State state = new State(mInfo); AndroidHttpClient 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 = AndroidHttpClient.newInstance(userAgent(), mContext); boolean finished = false; while (!finished) { Log.i(Constants.TAG, "Initiating request for download " + mInfo.mId); 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.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()); finalStatus = error.mFinalStatus; // 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); finalStatus = Downloads.Impl.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); // We have written new information to the database, the data in the update thread // is no longer valid. This needs to be synchronized to prevent the information // to change while the Update Thread in Download Service is using it. synchronized (mSystemFacade) { notifyDownloadCompleted(finalStatus, state.mCountRetry, state.mRetryAfter, state.mGotData, state.mFilename, state.mNewUri, state.mMimeType); mInfo.mHasActiveThread = false; mSystemFacade.setUpdateThreadDataIsOutdated(true); } } }
From source file:com.mine.psf.PsfPlaybackService.java
@Override public void onCreate() { super.onCreate(); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName()); mWakeLock.setReferenceCounted(false); Log.d(LOGTAG, "onCreate, Acquire Wake Lock"); PsfAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); PsfControlResponder = new ComponentName(getPackageName(), RemoteControlReceiver.class.getName()); PsfAudioManager.registerMediaButtonEventReceiver(PsfControlResponder); mPreferences = PreferenceManager.getDefaultSharedPreferences(this); reloadQueue();//from ww w . j a va 2s .c o m // If the service was idle, but got killed before it stopped itself, the // system will relaunch it. Make sure it gets stopped again in that case. Message msg = mDelayedStopHandler.obtainMessage(); mDelayedStopHandler.sendMessageDelayed(msg, IDLE_DELAY); // Register sd card mount/unmount listener registerExternalStorageListener(); // Register noisy listener, it should // 1) Playing with headset, unplug headset, sound should be paused; // 2) Playing with speaker, plug headset, sound should keep playing. registerNoisyListener(); }