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:com.marianhello.cordova.bgloc.LocationUpdateService.java
@Override public void onCreate() { super.onCreate(); Log.i(TAG, "OnCreate"); locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); toneGenerator = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100); connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); // Stop-detection PI stationaryAlarmPI = PendingIntent.getBroadcast(this, 0, new Intent(STATIONARY_ALARM_ACTION), 0); registerReceiver(stationaryAlarmReceiver, new IntentFilter(STATIONARY_ALARM_ACTION)); // Stationary region PI stationaryRegionPI = PendingIntent.getBroadcast(this, 0, new Intent(STATIONARY_REGION_ACTION), PendingIntent.FLAG_CANCEL_CURRENT); registerReceiver(stationaryRegionReceiver, new IntentFilter(STATIONARY_REGION_ACTION)); // Stationary location monitor PI stationaryLocationPollingPI = PendingIntent.getBroadcast(this, 0, new Intent(STATIONARY_LOCATION_MONITOR_ACTION), 0); registerReceiver(stationaryLocationMonitorReceiver, new IntentFilter(STATIONARY_LOCATION_MONITOR_ACTION)); // One-shot PI (TODO currently unused) singleUpdatePI = PendingIntent.getBroadcast(this, 0, new Intent(SINGLE_LOCATION_UPDATE_ACTION), PendingIntent.FLAG_CANCEL_CURRENT); registerReceiver(singleUpdateReceiver, new IntentFilter(SINGLE_LOCATION_UPDATE_ACTION)); /////*from w w w . j a v a 2s . c om*/ // DISABLED // Listen to Cell-tower switches (NOTE does not operate while suspended) //telephonyManager.listen(phoneStateListener, LISTEN_CELL_LOCATION); // PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); wakeLock.acquire(); // Location criteria criteria = new Criteria(); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setSpeedRequired(true); criteria.setCostAllowed(true); }
From source file:step.StepService.java
private void acquireWakeLock() { PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); int wakeFlags; wakeFlags = PowerManager.PARTIAL_WAKE_LOCK; wakeLock = pm.newWakeLock(wakeFlags, TAG); wakeLock.acquire();/*from www . j av a 2s . c o m*/ }
From source file:tree.love.providers.downloads.DownloadThread.java
private void runInternal() { // Skip when download already marked as finished; this download was // probably started again while racing with UpdateThread. if (DownloadInfo.queryDownloadStatus(mContext.getContentResolver(), mInfo.mId) == Downloads.Impl.STATUS_SUCCESS) { Log.d(TAG, "Download " + mInfo.mId + " already finished; skipping"); return;/*from w w w.j ava 2 s. c o m*/ } State state = new State(mInfo); PowerManager.WakeLock wakeLock = null; int finalStatus = Downloads.Impl.STATUS_UNKNOWN_ERROR; int numFailed = mInfo.mNumFailed; String errorMsg = null; // final NetworkPolicyManager netPolicy = // NetworkPolicyManager.from(mContext); final PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); try { wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Constants.TAG); // wakeLock.setWorkSource(new WorkSource(mInfo.mUid)); wakeLock.acquire(); // while performing download, register for rules updates // netPolicy.registerListener(mPolicyListener); Log.i(Constants.TAG, "Download " + mInfo.mId + " starting"); // Remember which network this download started on; used to // determine if errors were due to network changes. final NetworkInfo info = mSystemFacade.getActiveNetworkInfo(mInfo.mUid); if (info != null) { state.mNetworkType = info.getType(); } // Network traffic on this thread should be counted against the // requesting UID, and is tagged with well-known value. TrafficStatsCompat.setThreadStatsTag(TrafficStatsCompat.getThreadStatsTag()); // TrafficStatsCompat.setThreadStatsUid(mInfo.mUid); try { // TODO: migrate URL sanity checking into client side of API state.mUrl = new URL(state.mRequestUri); } catch (MalformedURLException e) { throw new StopRequestException(STATUS_BAD_REQUEST, e); } executeDownload(state); finalizeDestinationFile(state); finalStatus = Downloads.Impl.STATUS_SUCCESS; } catch (StopRequestException error) { // remove the cause before printing, in case it contains PII errorMsg = error.getMessage(); String msg = "Aborting request for download " + mInfo.mId + ": " + errorMsg; Log.w(Constants.TAG, msg); if (Constants.LOGV) { Log.w(Constants.TAG, msg, error); } finalStatus = error.getFinalStatus(); // Nobody below our level should request retries, since we handle // failure counts at this level. if (finalStatus == STATUS_WAITING_TO_RETRY) { throw new IllegalStateException("Execution should always throw final error codes"); } // Some errors should be retryable, unless we fail too many times. if (isStatusRetryable(finalStatus)) { if (state.mGotData) { numFailed = 1; } else { numFailed += 1; } if (numFailed < Constants.MAX_RETRIES) { final NetworkInfo info = mSystemFacade.getActiveNetworkInfo(mInfo.mUid); if (info != null && info.getType() == state.mNetworkType && info.isConnected()) { // Underlying network is still intact, use normal backoff finalStatus = STATUS_WAITING_TO_RETRY; } else { // Network changed, retry on any next available finalStatus = STATUS_WAITING_FOR_NETWORK; } } } // fall through to finally block } catch (Throwable ex) { errorMsg = ex.getMessage(); String msg = "Exception for id " + mInfo.mId + ": " + errorMsg; Log.w(Constants.TAG, msg, ex); finalStatus = Downloads.Impl.STATUS_UNKNOWN_ERROR; // falls through to the code that reports an error } finally { if (finalStatus == STATUS_SUCCESS) { TrafficStatsCompat.incrementOperationCount(1); } TrafficStatsCompat.clearThreadStatsTag(); // TrafficStatsCompat.clearThreadStatsUid(); cleanupDestination(state, finalStatus); notifyDownloadCompleted(state, finalStatus, errorMsg, numFailed); Log.i(Constants.TAG, "Download " + mInfo.mId + " finished with status " + Downloads.Impl.statusToString(finalStatus)); // netPolicy.unregisterListener(mPolicyListener); if (wakeLock != null) { wakeLock.release(); wakeLock = null; } } mStorageManager.incrementNumDownloadsSoFar(); }
From source file:com.mattprecious.prioritysms.receiver.AlarmReceiver.java
private void doNotify(Context context, BaseProfile profile) { AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); MediaPlayer mediaPlayer = new MediaPlayer(); try {//from w w w. ja va2s . co m if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL || profile.isOverrideSilent()) { mediaPlayer.setWakeMode(context, PowerManager.PARTIAL_WAKE_LOCK); mediaPlayer.setAudioStreamType( profile.isOverrideSilent() ? AudioManager.STREAM_ALARM : AudioManager.STREAM_NOTIFICATION); mediaPlayer.setDataSource(context, profile.getRingtone()); mediaPlayer.prepare(); mediaPlayer.start(); if (profile.isVibrate()) { Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(VIBRATE_PATTERN, -1); } } } catch (IllegalArgumentException e) { Log.e(TAG, "failed to play audio", e); } catch (IOException e) { Log.e(TAG, "failed to play audio", e); } }
From source file:eu.faircode.adblocker.ServiceSinkhole.java
synchronized private static PowerManager.WakeLock getLock(Context context) { if (wlInstance == null) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); wlInstance = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, context.getString(R.string.app_name) + " wakelock"); wlInstance.setReferenceCounted(true); }//from ww w .jav a2 s. com return wlInstance; }
From source file:com.yohpapa.research.simplemusicplayer.PlaybackService.java
private MediaPlayer initializePlayer() { MediaPlayer player = new MediaPlayer(); player.setAudioStreamType(AudioManager.STREAM_MUSIC); player.setOnPreparedListener(this); player.setOnCompletionListener(this); player.setOnErrorListener(this); player.setOnSeekCompleteListener(this); player.setWakeMode(this, PowerManager.PARTIAL_WAKE_LOCK); IntentFilter filter = new IntentFilter(); filter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY); filter.addAction(Intent.ACTION_HEADSET_PLUG); filter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED); filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED); registerReceiver(audioOutputChangedEventReceiver, filter); return player; }
From source file:com.eggwall.SoundSleep.AudioService.java
/** * Create a media player with the standard configuration both for white noise and music. * @return a generic Media player suitable for this application. *///from w w w . j av a2s. c o m private MediaPlayer getGenericMediaPlayer() { final MediaPlayer player = new MediaPlayer(); // Keep the CPU awake while playing music. player.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK); player.setOnPreparedListener(this); return player; }
From source file:it.cnr.isti.doremi.sleeplogger.SensorSamplingService.java
@Override public void onCreate() { super.onCreate(); Log.i(TAG, "onCreate()"); mSensorManager = ((SensorManager) getSystemService(SENSOR_SERVICE)); /*for (Sensor s : mSensorManager.getSensorList(Sensor.TYPE_ALL)) // print all the available sensors {/*from w w w . j a v a 2s. c o m*/ Log.d(TAG, "Sensor: " + s.getName() + ", type = " + s.getType()); }*/ // Use SENSOR_TYPE_HEARTRATE_GEAR_LIVE below to have a better accuracy (only for Samsung Gear Live) mHeartRateSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE); selHB = new SensorEventListener() { @Override public void onSensorChanged(SensorEvent sensorEvent) { lastHB = sensorEvent.values[0]; } @Override public void onAccuracyChanged(Sensor sensor, int i) { } }; mSensorManager.registerListener(selHB, this.mHeartRateSensor, 500000); // Forced to 0.5s mAccelerationSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); selAcc = new SensorEventListener() { @Override public void onSensorChanged(SensorEvent sensorEvent) { lastAcc = sensorEvent.values; } @Override public void onAccuracyChanged(Sensor sensor, int i) { } }; mSensorManager.registerListener(selAcc, this.mAccelerationSensor, SAMPLING_INTERVAL * 750); // sampling interval * 0.75 // ENABLE IF REQUIRED /* mGyroscopeSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); selGyroscope = new SensorEventListener() { @Override public void onSensorChanged(SensorEvent sensorEvent) { lastGyro = sensorEvent.values; } @Override public void onAccuracyChanged(Sensor sensor, int i) {} }; mSensorManager.registerListener(selGyroscope, this.mGyroscopeSensor, SAMPLING_INTERVAL * 1000); mOrientationSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); selOrientation = new SensorEventListener() { @Override public void onSensorChanged(SensorEvent sensorEvent) { lastOrientation = sensorEvent.values; } @Override public void onAccuracyChanged(Sensor sensor, int i) {} }; mSensorManager.registerListener(selOrientation, this.mOrientationSensor, SAMPLING_INTERVAL * 1000); mStepSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER); selStep = new SensorEventListener() { @Override public void onSensorChanged(SensorEvent sensorEvent) { lastStepCount = sensorEvent.values[0]; } @Override public void onAccuracyChanged(Sensor sensor, int i) {} }; mSensorManager.registerListener(selStep, this.mStepSensor, 1000000); // Forced to 1s */ File logFile = new File(Environment.getExternalStorageDirectory() + File.separator + "logs" + File.separator + "hb_log-" + sdf.format(new Date()) + ".txt"); try { logFile.getParentFile().mkdirs(); logFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } try { Log.d(TAG, "Log saved to : " + logFile.getAbsolutePath()); bw = new BufferedWriter(new FileWriter(logFile)); bw.write(String.format(Locale.ENGLISH, LOG_HEADER)); } catch (Exception e) { e.printStackTrace(); } powerManager = (PowerManager) getSystemService(POWER_SERVICE); wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "SensorSamplingServiceWakeLock"); }
From source file:com.terminal.ide.TermService.java
@Override public void onCreate() { compat = new ServiceForegroundCompat(this); mTermSessions = new ArrayList<TermSession>(); /**//from w w w . j ava 2 s .c o m * ?? * @author wanghao * @date 2015-3-27 * ???Activity */ //?intent //warning??start.class //?mainActivity Intent openMainActivityIntent = new Intent(this, mainAvtivity.class); Intent openTerminalActivityIntent = new Intent(this, Term.class); openTerminalActivityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); openMainActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Intent exitTerminalIntent = new Intent(this, ExitService.class); Notification sessionBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher) .setContentTitle(getText(R.string.application_terminal)) .setContentText(getText(R.string.service_notify_text)) .setContentIntent(PendingIntent.getActivity(this, 0, openMainActivityIntent, 0)) .setStyle(new NotificationCompat.BigTextStyle().bigText(getText(R.string.service_notify_text))) .addAction(R.drawable.ic_action_iconfont_terminal, getText(R.string.notification_open_termianl), PendingIntent.getActivity(this, 0, openTerminalActivityIntent, Intent.FLAG_ACTIVITY_CLEAR_TOP)) .addAction(R.drawable.ic_action_iconfont_exit, getText(R.string.notification_exit_app), PendingIntent.getService(this, 0, exitTerminalIntent, 0)) .setOngoing(true).build(); compat.startForeground(RUNNING_NOTIFICATION, sessionBuilder); mPrefs = PreferenceManager.getDefaultSharedPreferences(this); mPrefs.registerOnSharedPreferenceChangeListener(this); mHardKeys.setKeyMappings(mPrefs); //Setup the Hard Key Mappings.. mSettings = new TermSettings(mPrefs); //Need to set the HOME Folder and Bash startup.. //Sometime getfilesdir return NULL ? mSessionInit = false; File home = getFilesDir(); if (home != null) { initSessions(home); } //Start a webserver for comms.. // mServer = new webserver(this); // mServer.start(); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); //Get a wake lock mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TermDebug.LOG_TAG); mScreenLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, TermDebug.LOG_TAG); mWifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL, TermDebug.LOG_TAG); //Get the Initial Values // boolean cpulock = getStringPref("cpulock","1") == 1 ? true : false; // boolean wifilock = getStringPref("wifilock","0") == 1 ? true : false; // boolean screenlock = getStringPref("screenlock","0") == 1 ? true : false; setupWakeLocks(); Log.d(TermDebug.LOG_TAG, "TermService started"); return; }
From source file:org.videolan.vlc.audio.AudioService.java
@Override public void onCreate() { super.onCreate(); // Get libVLC instance try {/*from w w w. j av a2 s .c om*/ mLibVLC = VLCInstance.getLibVlcInstance(); } catch (LibVlcException e) { e.printStackTrace(); } mCallback = new HashMap<IAudioServiceCallback, Integer>(); mCurrentIndex = -1; mPrevIndex = -1; mNextIndex = -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 (!LibVlcUtil.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); } }