Пример #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();
    }
  }
  @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();
  }
Пример #3
0
 private void doToggleWifiLock() {
   if (mWifiLock.isHeld()) {
     mWifiLock.release();
   } else {
     mWifiLock.acquire();
   }
   ActivityCompat.invalidateOptionsMenu(this);
 }
Пример #4
0
  @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 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();
    }
 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();
   }
 }
Пример #8
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();
   }
 }
Пример #10
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);
    }
  }
  @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();
  }
Пример #12
0
  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();
  }
Пример #13
0
 public void ReleaseWifilock() {
   if (mWifilock.isHeld()) { // ?ж??????
     mWifilock.acquire();
   }
 }
Пример #14
0
 // 解锁WifiLock
 public void ReleaseWifiLock() {
   // 判断时候锁定
   if (mWifilock.isHeld()) {
     mWifilock.acquire();
   }
 }
Пример #15
0
 // 锁定WifiLock
 public void AcquireWifiLock() {
   mWifilock.acquire();
 }
Пример #16
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);
    }
  }