Exemplo n.º 1
0
  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();
    }
  }
Exemplo n.º 2
0
 private void doToggleWifiLock() {
   if (mWifiLock.isHeld()) {
     mWifiLock.release();
   } else {
     mWifiLock.acquire();
   }
   ActivityCompat.invalidateOptionsMenu(this);
 }
Exemplo n.º 3
0
  private void unregisterReceivers() {
    mContext.unregisterReceiver(mConnectivityReceiver);
    if (DEBUG) Log.d(TAG, " --- unregister receivers");

    // Reset variables maintained by ConnectivityReceiver.
    mWifiLock.release();
    mConnected = false;
  }
  @Override
  protected void onStop() {
    super.onStop();

    if (controllerService != null) unbindService(connection);

    RobotLog.cancelWriteLogcatToDisk(this);

    wifiLock.release();
  }
Exemplo n.º 5
0
  void relaxResource(boolean isReleaseMediaPlayer) {
    stopForeground(true);
    if (isReleaseMediaPlayer && mediaPlayer != null) {
      mediaPlayer.reset();
      mediaPlayer.release();
      mediaPlayer = null;
    }

    if (wifiLock.isHeld()) {
      wifiLock.release();
    }
  }
Exemplo n.º 6
0
 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();
   }
 }
Exemplo n.º 8
0
  // 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);
    }
  }
Exemplo n.º 9
0
 @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();
   }
 }
Exemplo n.º 10
0
 @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();
   }
 }
Exemplo n.º 11
0
  /**
   * 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 synchronized void releaseWifiLockIfNecessary() {
   if (wifiLock != null && wifiLock.isHeld()) {
     wifiLock.release();
   }
 }
 @Override
 protected void onPostExecute(Void aVoid) {
   wl.release();
   wifiLock.release();
   Log.d("DexcomShareDashclock", "Sync broadcast complete");
 }
 public void releaseLocks() {
   wakeLock.release();
   wifiLock.release();
 }
Exemplo n.º 15
0
  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);
    }
  }
 public void releaseWifiLock() {
   if (mWifiLock != null && mWifiLock.isHeld()) {
     Log.d(TAG, "releasing WifiLock");
     mWifiLock.release();
   }
 }