public void playNextSong(MusicItem musicItem) { String url = musicItem.audio; Logger.debug(TAG, ">>>" + "playNextSong:" + url); if (musicPlayBackCallback != null) { musicPlayBackCallback.onPreparing(currentItem); } mState = State.Stopped; relaxResource(false); try { setupMediaPlayerIfNeeded(); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mediaPlayer.setDataSource(url); isStreaming = url.startsWith("http:") || url.startsWith("https:"); songTitle = url; mState = State.Preparing; setupAsForeGround(musicItem); /** @see onPreparedListener */ mediaPlayer.prepareAsync(); if (isStreaming) { wifiLock.acquire(); } else if (wifiLock.isHeld()) { wifiLock.release(); } } catch (Exception e) { e.printStackTrace(); } }
private void doToggleWifiLock() { if (mWifiLock.isHeld()) { mWifiLock.release(); } else { mWifiLock.acquire(); } ActivityCompat.invalidateOptionsMenu(this); }
public void aquireWifiLock() { if (mWifiLock == null) { Log.d(TAG, "creating new WifiLock"); mWifiLock = mManager.createWifiLock(WifiManager.WIFI_MODE_FULL, WIFI_LOCK_TAG); } if (!mWifiLock.isHeld()) { Log.d(TAG, "aquiring WifiLock"); mWifiLock.acquire(); } }
private synchronized void acquireWifiLockIfNecessary() { if (stream) { if (wifiLock == null) { wifiLock = ((WifiManager) context.getSystemService(Context.WIFI_SERVICE)) .createWifiLock(WifiManager.WIFI_MODE_FULL, TAG); wifiLock.setReferenceCounted(false); } wifiLock.acquire(); } }
void relaxResource(boolean isReleaseMediaPlayer) { stopForeground(true); if (isReleaseMediaPlayer && mediaPlayer != null) { mediaPlayer.reset(); mediaPlayer.release(); mediaPlayer = null; } if (wifiLock.isHeld()) { wifiLock.release(); } }
private void updateWifiLock(boolean isStarted) { WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); if (null == wifiLock) { wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "fqrouter wifi hotspot"); } if (isStarted) { wifiLock.acquire(); } else { if (wifiLock.isHeld()) { wifiLock.release(); } } }
void lock(boolean lock) { try { if (lock) { boolean lockNew = (keepon && Receiver.on_wlan) || (InCallScreen.mSlidingCardManager != null && InCallScreen.mSlidingCardManager.isSlideInProgress()) || Receiver.call_state == UserAgent.UA_STATE_INCOMING_CALL || Receiver.call_state == UserAgent.UA_STATE_HOLD || RtpStreamSender.delay != 0 || !InCallScreen.started; if (lockFirst || lockLast != lockNew) { lockLast = lockNew; lock(false); lockFirst = false; if (pwl == null) { PowerManager pm = (PowerManager) Receiver.mContext.getSystemService(Context.POWER_SERVICE); pwl = pm.newWakeLock( lockNew ? (PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP) : PROXIMITY_SCREEN_OFF_WAKE_LOCK, "Sipdroid.Receiver"); pwl.acquire(); } } } else { lockFirst = true; if (pwl != null) { pwl.release(); pwl = null; } } } catch (Exception e) { } if (lock) { if (pwl2 == null) { PowerManager pm = (PowerManager) Receiver.mContext.getSystemService(Context.POWER_SERVICE); WifiManager wm = (WifiManager) Receiver.mContext.getSystemService(Context.WIFI_SERVICE); pwl2 = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Sipdroid.Receiver"); pwl2.acquire(); wwl = wm.createWifiLock(3, "Sipdroid.Receiver"); wwl.acquire(); } } else if (pwl2 != null) { pwl2.release(); pwl2 = null; wwl.release(); } }
// call to acquire or release resources held by the WifiLock. // acquisition: every time the Monitor loop calls setClientStatus: computingStatus == // COMPUTING_STATUS_COMPUTING || COMPUTING_STATUS_IDLE // release: every time acquisition criteria is not met , and in Monitor.onDestroy() public void setWifiLock(Boolean acquire) { try { if (wifiLock.isHeld() == acquire) return; // wifiLock already in desired state if (acquire) { // acquire wakeLock wifiLock.acquire(); if (Logging.DEBUG) Log.d(Logging.TAG, "wifiLock acquired"); } else { // release wakeLock wifiLock.release(); if (Logging.DEBUG) Log.d(Logging.TAG, "wifiLock released"); } } catch (Exception e) { if (Logging.WARNING) Log.w(Logging.TAG, "Exception durign setWifiLock " + acquire, e); } }
@Override protected void onStart() { super.onStart(); // save 4MB of logcat to the SD card RobotLog.writeLogcatToDisk(this, 4 * 1024); Intent intent = new Intent(this, FtcRobotControllerService.class); bindService(intent, connection, Context.BIND_AUTO_CREATE); utility.updateHeader( Utility.NO_FILE, R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); callback.wifiDirectUpdate(WifiDirectAssistant.Event.DISCONNECTED); entireScreenLayout.setOnTouchListener( new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { dimmer.handleDimTimer(); return false; } }); wifiLock.acquire(); }
@Override public void stop(boolean notifyListeners) { mState = PlaybackStateCompat.STATE_STOPPED; if (notifyListeners && mCallback != null) { mCallback.onPlaybackStatusChanged(mState); } mCurrentPosition = getCurrentStreamPosition(); // Give up Audio focus giveUpAudioFocus(); unregisterAudioNoisyReceiver(); // Relax all resources relaxResources(true); if (mWifiLock.isHeld()) { mWifiLock.release(); } }
/** * Releases resources used by the service for playback. This includes the "foreground service" * status, the wake locks and possibly the MediaPlayer. * * @param releaseMediaPlayer Indicates whether the Media Player should also be released or not */ private void relaxResources(boolean releaseMediaPlayer) { LogHelper.d(TAG, "relaxResources. releaseMediaPlayer=", releaseMediaPlayer); mService.stopForeground(true); // stop and release the Media Player, if it's available if (releaseMediaPlayer && mMediaPlayer != null) { mMediaPlayer.reset(); mMediaPlayer.release(); mMediaPlayer = null; } // we can also release the Wifi lock, if we're holding it if (mWifiLock.isHeld()) { mWifiLock.release(); } }
private void unregisterReceivers() { mContext.unregisterReceiver(mConnectivityReceiver); if (DEBUG) Log.d(TAG, " --- unregister receivers"); // Reset variables maintained by ConnectivityReceiver. mWifiLock.release(); mConnected = false; }
@Override public void onDestroy() { super.onDestroy(); mViewFlipper.removeAllViews(); unbindService(mTSConnection); if (mStopServiceOnFinish) { stopService(TSIntent); } mTermService = null; mTSConnection = null; if (mWakeLock.isHeld()) { mWakeLock.release(); } if (mWifiLock.isHeld()) { mWifiLock.release(); } }
protected static synchronized WifiManager.WifiLock getWifiLock(Context context) { // keep wifi alive if (wifilock == null) { WifiManager manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifilock = manager.createWifiLock(CLASS_TAG); wifilock.setReferenceCounted(true); } return wifilock; }
@Override public void play(QueueItem item) { mPlayOnFocusGain = true; tryToGetAudioFocus(); registerAudioNoisyReceiver(); String mediaId = item.getDescription().getMediaId(); boolean mediaHasChanged = !TextUtils.equals(mediaId, mCurrentMediaId); if (mediaHasChanged) { mCurrentPosition = 0; mCurrentMediaId = mediaId; } if (mState == PlaybackStateCompat.STATE_PAUSED && !mediaHasChanged && mMediaPlayer != null) { configMediaPlayerState(); } else { mState = PlaybackStateCompat.STATE_STOPPED; relaxResources(false); // release everything except MediaPlayer MediaMetadataCompat track = mMusicProvider.getMusic( MediaIDHelper.extractMusicIDFromMediaID(item.getDescription().getMediaId())); String source = MusicProvider.getTrackSource(track.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID)); try { createMediaPlayerIfNeeded(); mState = PlaybackStateCompat.STATE_BUFFERING; mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mMediaPlayer.setDataSource(source); // Starts preparing the media player in the background. When // it's done, it will call our OnPreparedListener (that is, // the onPrepared() method on this class, since we set the // listener to 'this'). Until the media player is prepared, // we *cannot* call start() on it! mMediaPlayer.prepareAsync(); // If we are streaming from the internet, we want to hold a // Wifi lock, which prevents the Wifi radio from going to // sleep while the song is playing. mWifiLock.acquire(); if (mCallback != null) { mCallback.onPlaybackStatusChanged(mState); } } catch (IOException ex) { LogHelper.e(TAG, ex, "Exception playing song"); if (mCallback != null) { mCallback.onError(ex.getMessage()); } } } }
@Override protected void onStop() { super.onStop(); if (controllerService != null) unbindService(connection); RobotLog.cancelWriteLogcatToDisk(this); wifiLock.release(); }
@Override protected void onPreExecute() { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DexcomShareDashclock"); wl.acquire(); WifiManager wfm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifiLock = wfm.createWifiLock("DexcomShareDashclock"); wifiLock.acquire(); }
private SipService(Context context) { if (DEBUG) Log.d(TAG, " service started!"); mContext = context; mConnectivityReceiver = new ConnectivityReceiver(); mWifiLock = ((WifiManager) context.getSystemService(Context.WIFI_SERVICE)) .createWifiLock(WifiManager.WIFI_MODE_FULL, TAG); mWifiLock.setReferenceCounted(false); mSipOnWifiOnly = SipManager.isSipWifiOnly(context); mMyWakeLock = new SipWakeLock((PowerManager) context.getSystemService(Context.POWER_SERVICE)); mTimer = new SipWakeupTimer(context, mExecutor); }
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem wakeLockItem = menu.findItem(R.id.menu_toggle_wakelock); MenuItem wifiLockItem = menu.findItem(R.id.menu_toggle_wifilock); if (mWakeLock.isHeld()) { wakeLockItem.setTitle(R.string.disable_wakelock); } else { wakeLockItem.setTitle(R.string.enable_wakelock); } if (mWifiLock.isHeld()) { wifiLockItem.setTitle(R.string.disable_wifilock); } else { wifiLockItem.setTitle(R.string.enable_wifilock); } return super.onPrepareOptionsMenu(menu); }
public ClientStatus(Context ctx) { this.ctx = ctx; // set up CPU Wake Lock // see documentation at http://developer.android.com/reference/android/os/PowerManager.html PowerManager pm = (PowerManager) ctx.getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Logging.TAG); wakeLock.setReferenceCounted( false); // "one call to release() is sufficient to undo the effect of all previous calls to // acquire()" // set up Wifi wake lock WifiManager wm = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE); wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL, "MyWifiLock"); wifiLock.setReferenceCounted(false); }
@Override public void onCreate() { super.onCreate(); // TODO Auto-generated method stub // Instantiate the current List of geofences mCurrentGeofences = new ArrayList<Geofence>(); // Instantiate a new geofence storage area mPrefs = new SimpleGeofenceStore(this); mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); // geofenceList = ""; PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "SetLocService"); wakeLock.acquire(); WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL, "SetLocService"); wifiLock.acquire(); }
private void init() { artistName = (TextView) findViewById(R.id.artistNameTextView); albumName = (TextView) findViewById(R.id.albumNameTextView); albumImage = (ImageView) findViewById(R.id.albumImageView); songName = (TextView) findViewById(R.id.songNameTextView); songProgress = (SeekBar) findViewById(R.id.songProgressBar); startTime = (TextView) findViewById(R.id.startTimeTextView); endTime = (TextView) findViewById(R.id.endTimeTextView); previousSong = (ImageButton) findViewById(R.id.previousButtom); playPause = (ImageButton) findViewById(R.id.playPauseButtom); nextSong = (ImageButton) findViewById(R.id.nextButtom); // mediaPlayer = new MediaPlayer(); // mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); // mediaPlayer.setWakeMode(this, PowerManager.PARTIAL_WAKE_LOCK); // mediaPlayer.setOnPreparedListener(this); wifiLock = ((WifiManager) getSystemService(WIFI_SERVICE)) .createWifiLock(WifiManager.WIFI_MODE_FULL, "MusicLock"); wifiLock.acquire(); }
public void ReleaseWifilock() { if (mWifilock.isHeld()) { // ?ж?????? mWifilock.acquire(); } }
private synchronized void releaseWifiLockIfNecessary() { if (wifiLock != null && wifiLock.isHeld()) { wifiLock.release(); } }
public void releaseWifiLock() { if (mWifiLock != null && mWifiLock.isHeld()) { Log.d(TAG, "releasing WifiLock"); mWifiLock.release(); } }
@Override protected void onPostExecute(Void aVoid) { wl.release(); wifiLock.release(); Log.d("DexcomShareDashclock", "Sync broadcast complete"); }
private synchronized void onConnectivityChanged(NetworkInfo info) { // We only care about the default network, and getActiveNetworkInfo() // is the only way to distinguish them. However, as broadcasts are // delivered asynchronously, we might miss DISCONNECTED events from // getActiveNetworkInfo(), which is critical to our SIP stack. To // solve this, if it is a DISCONNECTED event to our current network, // respect it. Otherwise get a new one from getActiveNetworkInfo(). if (info == null || info.isConnected() || !info.getTypeName().equals(mNetworkType)) { ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); info = cm.getActiveNetworkInfo(); } // Some devices limit SIP on Wi-Fi. In this case, if we are not on // Wi-Fi, treat it as a DISCONNECTED event. boolean connected = (info != null && info.isConnected() && (!mSipOnWifiOnly || info.getType() == ConnectivityManager.TYPE_WIFI)); String networkType = connected ? info.getTypeName() : "null"; // Ignore the event if the current active network is not changed. if (connected == mConnected && networkType.equals(mNetworkType)) { return; } if (DEBUG) { Log.d(TAG, "onConnectivityChanged(): " + mNetworkType + " -> " + networkType); } try { if (mConnected) { mLocalIp = null; stopPortMappingMeasurement(); for (SipSessionGroupExt group : mSipGroups.values()) { group.onConnectivityChanged(false); } } mConnected = connected; mNetworkType = networkType; if (connected) { mLocalIp = determineLocalIp(); mKeepAliveInterval = -1; mLastGoodKeepAliveInterval = DEFAULT_KEEPALIVE_INTERVAL; for (SipSessionGroupExt group : mSipGroups.values()) { group.onConnectivityChanged(true); } // If we are on Wi-Fi, grab the WifiLock. Otherwise release it. if (info.getType() == ConnectivityManager.TYPE_WIFI) { mWifiLock.acquire(); } else { mWifiLock.release(); } } else { // Always grab the WifiLock when we are disconnected, so the // system will keep trying to reconnect. We will release it // if we eventually connect via something else. mWifiLock.acquire(); mMyWakeLock.reset(); // in case there's a leak } } catch (SipException e) { Log.e(TAG, "onConnectivityChanged()", e); } }
// 解锁WifiLock public void ReleaseWifiLock() { // 判断时候锁定 if (mWifilock.isHeld()) { mWifilock.acquire(); } }
public void releaseLocks() { wakeLock.release(); wifiLock.release(); }
// 锁定WifiLock public void AcquireWifiLock() { mWifilock.acquire(); }