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.simlar.SimlarService.java
@Override public void onCreate() { Log.i(LOGTAG, "started on device: " + Build.DEVICE); FileHelper.init(this); mVibratorThread = new VibratorThread(this.getApplicationContext()); mRingtoneThread = new RingtoneThread(this.getApplicationContext()); mWakeLock = ((PowerManager) this.getSystemService(Context.POWER_SERVICE)) .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "SimlarWakeLock"); mWifiLock = ((WifiManager) this.getSystemService(Context.WIFI_SERVICE)) .createWifiLock(WifiManager.WIFI_MODE_FULL, "SimlarWifiLock"); startForeground(NOTIFICATION_ID, createNotification(SimlarStatus.OFFLINE)); mLinphoneThread = new LinphoneThread(this, this); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); registerReceiver(mNetworkChangeReceiver, intentFilter); startKeepAwake();/*from ww w. ja v a 2 s .c om*/ mHandler.post(new Runnable() { @Override public void run() { initializeCredentials(); } }); }
From source file:com.goftagram.telegram.messenger.NotificationsController.java
public NotificationsController() { notificationManager = NotificationManagerCompat.from(ApplicationLoader.applicationContext); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Context.MODE_PRIVATE); inChatSoundEnabled = preferences.getBoolean("EnableInChatSound", true); try {/* w ww. j a va 2 s. c om*/ audioManager = (AudioManager) ApplicationLoader.applicationContext .getSystemService(Context.AUDIO_SERVICE); } catch (Exception e) { FileLog.e("tmessages", e); } try { alarmManager = (AlarmManager) ApplicationLoader.applicationContext .getSystemService(Context.ALARM_SERVICE); } catch (Exception e) { FileLog.e("tmessages", e); } try { PowerManager pm = (PowerManager) ApplicationLoader.applicationContext .getSystemService(Context.POWER_SERVICE); notificationDelayWakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "lock"); notificationDelayWakelock.setReferenceCounted(false); } catch (Exception e) { FileLog.e("tmessages", e); } notificationDelayRunnable = new Runnable() { @Override public void run() { FileLog.e("tmessages", "delay reached"); if (!delayedPushMessages.isEmpty()) { showOrUpdateNotification(true); delayedPushMessages.clear(); } try { if (notificationDelayWakelock.isHeld()) { notificationDelayWakelock.release(); } } catch (Exception e) { FileLog.e("tmessages", e); } } }; }
From source file:com.intel.RtcPingDownloadTester.java
@Override protected void onCreate(Bundle savedInstanceState) { /** First, call the superclass onCreate method */ super.onCreate(savedInstanceState); Log.v(TAG, "onCreate: " + savedInstanceState); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "RtcPingDownloadTester"); nWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "RtcPingDownloadTester2"); setContentView(R.layout.main);/* w w w. ja v a 2 s . c o m*/ b_Start = (Button) this.findViewById(R.id.ok); b_Start.setOnClickListener(new OnClickListener() { /* Start button pressed handler.*/ public void onClick(View v) { Log.v(TAG, "onClick : START"); /* a bit of sanity checking..*/ if (nRepeatTimerEntry < 0) nRepeatTimerEntry = 0; else if (nRepeatTimerEntry > 600) nRepeatTimerEntry = 600; /* Entry point for alarm task */ if ((nRepeatTimerEntry != 0) && (is_running == false)) { is_running = true; string_curr_state = "RUNNING"; label_curr_state.setText(string_curr_state); registerReceiver(alarmReceiver, myFilter); new setAlarmTask().execute(nRepeatTimerEntry * 1000); } } }); b_Stop = (Button) this.findViewById(R.id.stop); b_Stop.setOnClickListener(new OnClickListener() { /* Stop button pressed handler*/ public void onClick(View v) { Log.v(TAG, "onClick : STOP"); if (is_running) { unregisterReceiver(alarmReceiver); is_running = false; string_curr_state = "STOPED"; label_curr_state.setText(string_curr_state); clearAlarm(); } } }); label_curr_state = (TextView) this.findViewById(R.id.label_curr_state); label_curr_state.setText(string_curr_state); label_console_box = (TextView) this.findViewById(R.id.label_console_box); label_console_box.setText(string_console_text); textBox_TimerEntry = (EditText) this.findViewById(R.id.textBox_1); textBox_TimerEntry.setText(String.valueOf(nRepeatTimerEntry), TextView.BufferType.EDITABLE); textBox_TimerEntry.addTextChangedListener(textBox_TimerEntry_EditorWatcher); textBox_HostIp = (EditText) this.findViewById(R.id.textBox_2); textBox_HostIp.setText(host_ip_addr, TextView.BufferType.EDITABLE); textBox_HostIp.addTextChangedListener(textBox_HostIp_EditorWatcher); textBox_fileUrl = (EditText) this.findViewById(R.id.textBox_3); textBox_fileUrl.setText(fileUrl, TextView.BufferType.EDITABLE); textBox_fileUrl.addTextChangedListener(textBox_fileUrl_EditorWatcher); textBox_wklk = (EditText) this.findViewById(R.id.textBox_4); textBox_wklk.setText(String.valueOf(wklk), TextView.BufferType.EDITABLE); textBox_wklk.addTextChangedListener(textBox_wklk_EditorWatcher); checkBox_1 = (CheckBox) this.findViewById(R.id.checkBox_1); checkBox_1.setChecked(ping_enabled); checkBox_1.setOnClickListener(new OnClickListener() { /* Ping checkbox handler */ public void onClick(View v) { if (((CheckBox) v).isChecked()) ping_enabled = true; else ping_enabled = false; } }); checkBox_2 = (CheckBox) this.findViewById(R.id.checkBox_2); checkBox_2.setChecked(download_enabled); checkBox_2.setOnClickListener(new OnClickListener() { /* Download checkbox handler */ public void onClick(View v) { if (((CheckBox) v).isChecked()) download_enabled = true; else download_enabled = false; } }); checkBox_3 = (CheckBox) this.findViewById(R.id.checkBox_3); checkBox_3.setChecked(wklk_enabled); checkBox_3.setOnClickListener(new OnClickListener() { /* Download checkbox handler */ public void onClick(View v) { if (((CheckBox) v).isChecked()) wklk_enabled = true; else wklk_enabled = false; } }); }
From source file:com.etime.TimeAlarmService.java
/** * Acquires the wake lock to keep the phone awake while the auto clocks out the user. * @return the wake lock.//from w ww. ja va 2 s. c om */ synchronized static PowerManager.WakeLock getLock() { if (lockStatic == null && lockContext != null) { PowerManager mgr = (PowerManager) lockContext.getSystemService(Context.POWER_SERVICE); lockStatic = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, NAME); lockStatic.setReferenceCounted(true); } return (lockStatic); }
From source file:com.b44t.messenger.NotificationsController.java
public NotificationsController() { mContext = ApplicationLoader.applicationContext; notificationManager = NotificationManagerCompat.from(ApplicationLoader.applicationContext); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Context.MODE_PRIVATE); inChatSoundEnabled = preferences.getBoolean("EnableInChatSound", true); try {//from w ww . ja v a2s. co m audioManager = (AudioManager) ApplicationLoader.applicationContext .getSystemService(Context.AUDIO_SERVICE); } catch (Exception e) { FileLog.e("messenger", e); } try { alarmManager = (AlarmManager) ApplicationLoader.applicationContext .getSystemService(Context.ALARM_SERVICE); } catch (Exception e) { FileLog.e("messenger", e); } try { PowerManager pm = (PowerManager) ApplicationLoader.applicationContext .getSystemService(Context.POWER_SERVICE); notificationDelayWakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "lock"); notificationDelayWakelock.setReferenceCounted(false); } catch (Exception e) { FileLog.e("messenger", e); } notificationDelayRunnable = new Runnable() { @Override public void run() { FileLog.e("messenger", "delay reached"); if (!delayedPushMessages.isEmpty()) { showOrUpdateNotification(true); delayedPushMessages.clear(); } try { if (notificationDelayWakelock.isHeld()) { notificationDelayWakelock.release(); } } catch (Exception e) { FileLog.e("messenger", e); } } }; }
From source file:com.teocci.utubinbg.BackgroundAudioService.java
/** * Initializes media sessions and receives media events *///from w w w . j a v a 2s . co m private void initMediaSessions() { // 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. mMediaPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK); ComponentName eventReceiver = new ComponentName(getApplicationContext().getPackageName(), MediaButtonIntentReceiver.class.getName()); PendingIntent buttonReceiverIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(Intent.ACTION_MEDIA_BUTTON), PendingIntent.FLAG_UPDATE_CURRENT); mSession = new MediaSessionCompat(getApplicationContext(), "simple player session", eventReceiver, buttonReceiverIntent); try { mController = new MediaControllerCompat(getApplicationContext(), mSession.getSessionToken()); mSession.setCallback(new MediaSessionCompat.Callback() { @Override public void onPlay() { super.onPlay(); buildNotification(generateAction(android.R.drawable.ic_media_pause, "Pause", ACTION_PAUSE)); } @Override public void onPause() { super.onPause(); pauseVideo(); buildNotification(generateAction(android.R.drawable.ic_media_play, "Play", ACTION_PLAY)); } @Override public void onSkipToNext() { super.onSkipToNext(); if (!isStarting) { playNext(); } buildNotification(generateAction(android.R.drawable.ic_media_pause, "Pause", ACTION_PAUSE)); } @Override public void onSkipToPrevious() { super.onSkipToPrevious(); if (!isStarting) { playPrevious(); } buildNotification(generateAction(android.R.drawable.ic_media_pause, "Pause", ACTION_PAUSE)); } @Override public void onStop() { super.onStop(); stopPlayer(); //remove notification and stop service NotificationManager notificationManager = (NotificationManager) getApplicationContext() .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(1); Intent intent = new Intent(getApplicationContext(), BackgroundAudioService.class); stopService(intent); } @Override public void onSetRating(RatingCompat rating) { super.onSetRating(rating); } }); } catch (RemoteException re) { re.printStackTrace(); } }
From source file:org.gateshipone.malp.application.artworkdatabase.BulkDownloadService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (intent != null && intent.getAction() != 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;// w w w . j a v a 2s .c om 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); } ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (null == netInfo) { return START_NOT_STICKY; } boolean isWifi = netInfo.getType() == ConnectivityManager.TYPE_WIFI || netInfo.getType() == ConnectivityManager.TYPE_ETHERNET; if (mWifiOnly && !isWifi) { return START_NOT_STICKY; } PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); mWakelock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MALP_BulkDownloader"); ArtworkManager artworkManager = ArtworkManager.getInstance(getApplicationContext()); artworkManager.initialize(artistProvider, albumProvider, mWifiOnly); // FIXME do some timeout checking. e.g. 5 minutes no new image then cancel the process mWakelock.acquire(); ConnectionManager.reconnectLastServer(this); } return START_NOT_STICKY; }
From source file:uk.co.gidley.clockRadio.RadioPlayerService.java
public void play(final String playerUri) { new Thread(new Runnable() { public void run() { setState(State.LOADING); if (StringUtils.isEmpty(playerUri)) { setState(State.STOPPED); return; }//from w w w . ja va2 s.c o m if (mp != null && mp.isPlaying()) { stop(); } // The uri could be a playlist file OR an actual stream check based on // file extension (TODO review if better way of doing this) String audioUri; if (playerUri.endsWith(".pls")) { audioUri = parsePls(playerUri); } else { audioUri = playerUri; } if (StringUtils.isEmpty(audioUri)) { setState(State.STOPPED); return; } Log.d(TAG, "Audio URL:" + audioUri); mp = new MediaPlayer(); try { mp.setDataSource(audioUri); mp.prepare(); mp.start(); setState(State.PLAYING); showNotification(); } catch (IllegalArgumentException e) { setState(State.STOPPED); Log.e(TAG, "Unable to open stream", e); } catch (IllegalStateException e) { setState(State.STOPPED); Log.e(TAG, "Unable to open stream", e); } catch (IOException e) { setState(State.STOPPED); Log.e(TAG, "Unable to open stream", e); } wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); wl.acquire(); } }).start(); }
From source file:nuclei.media.playback.ExoPlayerPlayback.java
public ExoPlayerPlayback(MediaService service) { mService = service;// w w w. j av a2 s . c o m mHandler = new Handler(); final Context ctx = service.getApplicationContext(); mAudioManager = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE); PowerManager powerManager = (PowerManager) ctx.getSystemService(Context.POWER_SERVICE); WifiManager wifiManager = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE); // Create the Wifi lock (this does not acquire the lock, this just creates it) mWifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "nuclei_media_wifi_lock"); mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "nuclei_media_cpu_lock"); }
From source file:uk.org.openseizuredetector.SdServer.java
/** * onCreate() - called when services is created. Starts message * handler process to listen for messages from other processes. */// w ww . j ava 2s. co m @Override public void onCreate() { Log.v(TAG, "onCreate()"); // 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"); }