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.eclipse.paho.android.service.MqttConnection.java
/** * Acquires a partial wake lock for this client *///from ww w . j a v a 2 s . c o m private void acquireWakeLock() { if (wakelock == null) { PowerManager pm = (PowerManager) service.getSystemService(Service.POWER_SERVICE); wakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, wakeLockTag); } wakelock.acquire(); }
From source file:com.android.exchange.ExchangeService.java
private void acquireWakeLock(long id) { synchronized (mWakeLocks) { Boolean lock = mWakeLocks.get(id); if (lock == null) { if (mWakeLock == null) { PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MAIL_SERVICE"); mWakeLock.acquire();/* ww w . j av a2 s . c om*/ //log("+WAKE LOCK ACQUIRED"); } mWakeLocks.put(id, true); } } }
From source file:com.csipsimple.service.SipService.java
/** * Ask to take the control of the wifi and the partial wake lock if * configured//from ww w . ja v a 2 s. c o m */ private synchronized void acquireResources() { if (holdResources) { return; } // Add a wake lock for CPU if necessary if (prefsWrapper.getPreferenceBooleanValue(SipConfigManager.USE_PARTIAL_WAKE_LOCK)) { PowerManager pman = (PowerManager) getSystemService(Context.POWER_SERVICE); if (wakeLock == null) { wakeLock = pman.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "com.csipsimple.SipService"); wakeLock.setReferenceCounted(false); } // Extra check if set reference counted is false ??? if (!wakeLock.isHeld()) { wakeLock.acquire(); } } // Add a lock for WIFI if necessary WifiManager wman = (WifiManager) getSystemService(Context.WIFI_SERVICE); if (wifiLock == null) { int mode = WifiManager.WIFI_MODE_FULL; if (Compatibility.isCompatible(9) && prefsWrapper.getPreferenceBooleanValue(SipConfigManager.LOCK_WIFI_PERFS)) { mode = 0x3; // WIFI_MODE_FULL_HIGH_PERF } wifiLock = wman.createWifiLock(mode, "com.csipsimple.SipService"); wifiLock.setReferenceCounted(false); } if (prefsWrapper.getPreferenceBooleanValue(SipConfigManager.LOCK_WIFI) && !wifiLock.isHeld()) { WifiInfo winfo = wman.getConnectionInfo(); if (winfo != null) { DetailedState dstate = WifiInfo.getDetailedStateOf(winfo.getSupplicantState()); // We assume that if obtaining ip addr, we are almost connected // so can keep wifi lock if (dstate == DetailedState.OBTAINING_IPADDR || dstate == DetailedState.CONNECTED) { if (!wifiLock.isHeld()) { wifiLock.acquire(); } } } } holdResources = true; }
From source file:com.halseyburgund.rwframework.core.RWService.java
/** * Creates a media player for sound playback, with initial volume of 0. *//*from w w w . j a v a2s .c o m*/ private void createPlayer() { if (mPlayer == null) { mPlayer = new MediaPlayer(); mPlayer.setWakeMode(this, PowerManager.PARTIAL_WAKE_LOCK); float volume = (float) 0.0; mPlayer.setVolume(volume, volume); mVolumeLevel = 0; mPlayer.pause(); mPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { if (D) { Log.d(TAG, "MediaPlayer prepared event"); } broadcast(RW.READY_TO_PLAY); if (mStartPlayingWhenReady) { playbackFadeIn(mVolumeLevel); } mAssetTracker.start(); } }); mPlayer.setOnInfoListener(new MediaPlayer.OnInfoListener() { @Override public boolean onInfo(MediaPlayer mp, int what, int extra) { if (D) { Log.i(TAG, "MediaPlayer info event"); if (MediaPlayer.MEDIA_INFO_METADATA_UPDATE == what) { Log.i(TAG, "MediaPlayer metadata updated, extra = " + extra); } } return true; } }); mPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() { @Override public boolean onError(MediaPlayer mp, int what, int extra) { if (D) { Log.d(TAG, "MediaPlayer error event"); } mAssetTracker.reset(); return true; } }); mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { if (D) { Log.d(TAG, "MediaPlayer completion event"); } mAssetTracker.stop(); mp.stop(); broadcast(RW.PLAYBACK_FINISHED); } }); mPlayer.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() { @Override public void onBufferingUpdate(MediaPlayer mp, int percent) { if (D) { Log.d(TAG, "MediaPlayer buffering event, %=" + percent); } } }); } }
From source file:github.daneren2005.dsub.service.DownloadService.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private synchronized void setupNext(final DownloadFile downloadFile) { try {/*w w w . j ava2 s . c om*/ final File file = downloadFile.isCompleteFileAvailable() ? downloadFile.getCompleteFile() : downloadFile.getPartialFile(); resetNext(); // Exit when using remote controllers if (remoteState != LOCAL) { return; } nextMediaPlayer = new MediaPlayer(); nextMediaPlayer.setWakeMode(DownloadService.this, PowerManager.PARTIAL_WAKE_LOCK); try { nextMediaPlayer.setAudioSessionId(audioSessionId); } catch (Throwable e) { nextMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); } nextMediaPlayer.setDataSource(file.getPath()); setNextPlayerState(PREPARING); nextMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { public void onPrepared(MediaPlayer mp) { // Changed to different while preparing so ignore if (nextMediaPlayer != mp) { return; } try { setNextPlayerState(PREPARED); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && (playerState == PlayerState.STARTED || playerState == PlayerState.PAUSED)) { mediaPlayer.setNextMediaPlayer(nextMediaPlayer); nextSetup = true; } applyReplayGain(nextMediaPlayer, downloadFile); } catch (Exception x) { handleErrorNext(x); } } }); nextMediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() { public boolean onError(MediaPlayer mediaPlayer, int what, int extra) { Log.w(TAG, "Error on playing next " + "(" + what + ", " + extra + "): " + downloadFile); return true; } }); nextMediaPlayer.prepareAsync(); } catch (Exception x) { handleErrorNext(x); } }
From source file:com.xorcode.andtweet.AndTweetService.java
private PowerManager.WakeLock getWakeLock() { PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); wakeLock.acquire();/*from w w w . jav a 2 s .com*/ return wakeLock; }
From source file:me.spadival.podmode.PodModeService.java
/** * Makes sure the media player exists and has been reset. This will create * the media player if needed, or reset the existing media player if one * already exists.// w ww. j a va 2s .c om */ void createMediaPlayerIfNeeded() { if (mPlayer == null) { mPlayer = new MediaPlayer(); // Make sure the media 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. // // Remember that to use this, we have to declare the // android.permission.WAKE_LOCK // permission in AndroidManifest.xml. mPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK); // we want the media player to notify us when it's ready preparing, // and when it's done // playing: mPlayer.setOnPreparedListener(this); mPlayer.setOnCompletionListener(this); mPlayer.setOnErrorListener(this); } else mPlayer.reset(); }
From source file:com.grazerss.EntryManager.java
private void switchStorageProvider() { Log.d(TAG, "Switch Storage Provider"); if (isModelCurrentlyUpdated()) { return;/*from w w w . j a v a 2s . c o m*/ } final String newPrefValue = getSharedPreferences().getString(SETTINGS_STORAGE_PROVIDER_KEY, null); final String oldStorageProviderClass = fileContextAdapter.getClass().getName(); final String newStorageProviderClass = STORAGE_PROVIDER_SD_CARD.equals(newPrefValue) ? SdCardStorageAdapter.class.getName() : PhoneMemoryStorageAdapter.class.getName(); if (!oldStorageProviderClass.equals(newStorageProviderClass)) { runningThread = new Thread(new Runnable() { public void run() { final PowerManager pm = (PowerManager) ctx.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); Log.i(TAG, "Wake lock acquired at " + new Date().toString() + "."); wl.acquire(); Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); final Timing t = new Timing("Storage Provider Switch", ctx); ModelUpdateResult result = null; if (isModelCurrentlyUpdated()) { return; } try { lockModel("EM.switchStorageProvider.run"); } catch (final IllegalStateException ise) { return; } try { Log.i(TAG, "Switching storage providers started at " + new Date().toString() + "."); fireModelUpdateStarted("Switching storage providers", false, true); Log.d(TAG, "Change of storage provider detected."); final List<Job> jobList = new LinkedList<Job>(); final Job clearOldStorageProvider = new Job("Clearing Old Storage Provider", EntryManager.this) { @Override public void run() { Log.d(TAG, "Clearing the old storage provider."); doClearCache(); if (fileContextAdapter.canWrite()) { WebPageDownloadDirector.removeAllAssets(fileContextAdapter, ctx); } } }; jobList.add(clearOldStorageProvider); final Job switchStorageProviders = new Job("Switching Storage Providers", EntryManager.this) { @Override public void run() throws Exception { Log.d(TAG, "Establishing new storage provider: " + newStorageProviderClass); fileContextAdapter = newStorageProviderClass.equals( SdCardStorageAdapter.class.getName()) ? new SdCardStorageAdapter(ctx) : new PhoneMemoryStorageAdapter(ctx); Log.d(TAG, "New storage provider established."); } }; jobList.add(switchStorageProviders); final Job clearNewStorageProvider = new Job("Clearing New Storage Provider", EntryManager.this) { @Override public void run() { Log.d(TAG, "Clearing the new storage provider."); doClearCache(); if (fileContextAdapter.canWrite()) { WebPageDownloadDirector.removeAllAssets(fileContextAdapter, ctx); } } }; jobList.add(clearNewStorageProvider); runJobs(jobList); result = new SwitchStorageProviderResult(); } catch (final Throwable throwable) { result = new SwitchStorageProviderFailed(throwable); Log.d(TAG, "Problem during switching storage providers.", throwable); t.stop(); } finally { unlockModel("EM.switchStorageProvider.run"); clearCancelState(); fireModelUpdateFinished(result); fireStatusUpdated(); Log.i(TAG, "Switching storage providers finished at " + new Date().toString() + "."); wl.release(); t.stop(); } } }, "Storage Provider Switch Worker"); runningThread.start(); } }
From source file:com.plusot.senselib.SenseMain.java
@SuppressLint("Wakelock") @SuppressWarnings("deprecation") public void updateSetting(SharedPreferences prefs, PreferenceKey key, boolean firstTime) { switch (key) { case AUTOSWITCH: if (key.getInt() > 1800000) { PreferenceKey.CLICKSWITCH.set(true); }//from w w w . j a v a 2 s. c o m break; case CLICKSWITCH: clickSwitch = key.isTrue(); break; case DIM: if (wakeLock != null && wakeLock.isHeld()) { wakeLock.release(); wakeLock = null; } final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); allowHandWake = false; switch (PreferenceKey.getDimmable()) { case SCREENOFF_WAKE: allowHandWake = true; case SCREENOFF_FULL: getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Globals.TAG + "_WakeLock"); wakeLock.acquire(); break; case NODIM: getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); break; case DIM: default: allowHandWake = true; getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, Globals.TAG + "_WakeLock"); wakeLock.acquire(); break; } break; case DISPLAYNAME: UserInfo.UserData user = UserInfo.getUserData(); if (user == null) return; key.getString(user.name); break; case HASMAP: new SleepAndWake(new SleepAndWake.Listener() { @Override public void onWake() { if (PreferenceKey.HASMAP.isTrue()) { addMap(); adjustViews(); } else { releaseMap(); if (!visible) toggleValuesVisible(); } } }, 500); break; case HTTPPOST: HttpSender.isHttpPost = key.isTrue(); break; case STOPSTATE: PreferenceKey.getStopState(); break; case STORAGE: Value.fileTypes = PreferenceKey.getStorageFiles(); break; case TESTING: PreferenceKey.isTesting(); break; case WHEELSIZE: case WHEELCIRC: PreferenceKey.getWheelCirc(); break; case XTRAVALUES: key.isTrue(); break; case IMEI: UserInfo.resetDeviceId(); break; case TILESOURCE: key.get(); if (!firstTime) { if (map != null) { RelativeLayout view = (RelativeLayout) findViewById(R.id.main_rootlayout); view.removeView(map); map.removeAllViews(); map.setOnTouchListener((ClickableOverlay.Listener) null); map = null; } addMap(); //ToastHelper.showToastLong(R.string.change_tilesource); } break; case BLE_DEVICE: key.get(); break; default: key.get(); } }