コード例 #1
0
  /** Reset the audio mode */
  private synchronized void actualUnsetAudioInCall() {

    if (!prefs.getBoolean("isSavedAudioState", false) || !isSetAudioMode) {
      return;
    }

    Log.d(THIS_FILE, "Unset Audio In call");

    int inCallStream = Compatibility.getInCallStream(userWantBluetooth);
    if (bluetoothWrapper != null) {
      // This fixes the BT activation but... but... seems to introduce a
      // lot of other issues
      // bluetoothWrapper.setBluetoothOn(true);
      Log.d(THIS_FILE, "Unset bt");
      bluetoothWrapper.setBluetoothOn(false);
    }
    audioManager.setMicrophoneMute(false);
    if (doFocusAudio) {
      audioManager.setStreamSolo(inCallStream, false);
      audioFocusWrapper.unFocus();
    }
    restoreAudioState();

    if (wifiLock != null && wifiLock.isHeld()) {
      wifiLock.release();
    }
    if (screenLock != null && screenLock.isHeld()) {
      Log.d(THIS_FILE, "Release screen lock");
      screenLock.release();
    }

    isSetAudioMode = false;
  }
コード例 #2
0
  @Override
  public void onPause() {
    super.onPause();

    videoView.pause();

    if (wifiLock != null && wifiLock.isHeld()) {
      wifiLock.release();
    }
  }
コード例 #3
0
  @Override
  public synchronized void onDestroy() {
    instance = null;
    LinphoneManager.getLc().setPresenceInfo(0, null, OnlineStatus.Offline);
    LinphoneManager.destroy();

    // Make sure our notification is gone.
    //	    stopForegroundCompat(NOTIF_ID);
    //	    mNM.cancel(INCALL_NOTIF_ID);
    mWifiLock.release();
    super.onDestroy();
  }
コード例 #4
0
 @Override
 public void onCompletion(final MediaPlayer mp) {
   if (DEBUG) {
     Log.d(TAG, "Video playback completed");
   }
   completed = true;
   if (wifiLock != null && wifiLock.isHeld()) {
     wifiLock.release();
   }
   if (finishOnComplete) {
     getActivity().finish();
   }
 }
コード例 #5
0
ファイル: ScanResultTest.java プロジェクト: rcoscali/cts
 @Override
 protected void tearDown() throws Exception {
   if (!WifiFeature.isWifiSupported(getContext())) {
     // skip the test if WiFi is not supported
     super.tearDown();
     return;
   }
   mWifiLock.release();
   mContext.unregisterReceiver(mReceiver);
   if (!mWifiManager.isWifiEnabled()) setWifiEnabled(true);
   Thread.sleep(ENABLE_WAIT_MSEC);
   super.tearDown();
 }
コード例 #6
0
  /**
   * Releases resources used by the service for playback. This includes the "foreground service"
   * status and notification, the wake locks and possibly the MediaPlayer.
   *
   * @param releaseMediaPlayer Indicates whether the Media Player should also be released or not
   */
  void relaxResources(boolean releaseMediaPlayer) {
    // stop being a foreground service
    stopForeground(true);

    // stop and release the Media Player, if it's available
    if (releaseMediaPlayer && mPlayer != null) {
      mPlayer.reset();
      mPlayer.release();
      mPlayer = null;
    }

    // we can also release the Wifi lock, if we're holding it
    if (mWifiLock.isHeld()) mWifiLock.release();
  }
コード例 #7
0
  /**
   * Starts playing the next song. If manualUrl is null, the next song will be randomly selected
   * from our Media Retriever (that is, it will be a random song in the user's device). If manualUrl
   * is non-null, then it specifies the URL or path to the song that will be played next.
   */
  void playNextSong(String manualUrl) {
    mState = State.Stopped;
    relaxResources(false); // release everything except MediaPlayer

    try {
      if (manualUrl != null) {
        // set the source of the media player to a manual URL or path
        createMediaPlayerIfNeeded();
        mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mPlayer.setDataSource(manualUrl);
        mSongTitle = manualUrl;
        mIsStreaming = manualUrl.startsWith("http:") || manualUrl.startsWith("https:");
      } else {
        mIsStreaming = false; // playing a locally available song

        MusicRetriever.Item item = mRetriever.getRandomItem();
        if (item == null) {
          say("No song to play :-(");
          return;
        }

        // set the source of the media player a a content URI
        createMediaPlayerIfNeeded();
        mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mPlayer.setDataSource(getApplicationContext(), item.getURI());
        mSongTitle = item.getTitle();
      }

      mState = State.Preparing;
      setUpAsForeground(mSongTitle + " (loading)");

      // 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!
      mPlayer.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. If, on the other hand,
      // we are *not* streaming, we want to release the lock if we were holding it before.
      if (mIsStreaming) mWifiLock.acquire();
      else if (mWifiLock.isHeld()) mWifiLock.release();
    } catch (IOException ex) {
      Log.e("MusicService", "IOException playing next song: " + ex.getMessage());
      ex.printStackTrace();
    }
  }
コード例 #8
0
  public void onCallStateChanged(final LinphoneCall call, final State state, final String message) {
    if (instance == null) {
      Log.i("Service not ready, discarding call state change to ", state.toString());
      return;
    }
    if (state == LinphoneCall.State.IncomingReceived) {
      onIncomingReceived();
    }

    if (state == State.CallUpdatedByRemote) {
      // If the correspondent proposes video while audio call
      boolean remoteVideo = call.getRemoteParams().getVideoEnabled();
      boolean localVideo = call.getCurrentParamsCopy().getVideoEnabled();
      boolean autoAcceptCameraPolicy = LinphoneManager.getInstance().isAutoAcceptCamera();
      if (remoteVideo && !localVideo && !autoAcceptCameraPolicy) {
        try {
          LinphoneManager.getLc().deferCallUpdate(call);

          if (incallListener() != null) incallListener().onCallStateChanged(call, state, message);
        } catch (LinphoneCoreException e) {
          e.printStackTrace();
        }
      }
    }

    if (state == State.StreamsRunning) {
      // Workaround bug current call seems to be updated after state changed to streams running
      //	refreshIncallIcon(call);
      mWifiLock.acquire();
    } else {
      //	refreshIncallIcon(LinphoneManager.getLc().getCurrentCall());
    }
    if ((state == State.CallEnd || state == State.Error)
        && LinphoneManager.getLc().getCallsNb() < 1) {
      mWifiLock.release();
    }
    //		mHandler.post(new Runnable() {
    //			public void run() {
    //				if (guiListener() != null)
    //					guiListener().onCallStateChanged(call, state, message);
    //			}
    //		});
  }
コード例 #9
0
ファイル: System.java プロジェクト: Haxin-hipopcorn/android
  public static void clean(boolean releaseLocks) {
    setForwarding(false);

    try {
      if (releaseLocks) {
        Logger.debug("Releasing locks.");

        if (mWifiLock != null && mWifiLock.isHeld()) mWifiLock.release();

        if (mWakeLock != null && mWakeLock.isHeld()) mWakeLock.release();
      }

      synchronized (mTargets) {
        for (Target t : mTargets) for (Session s : t.getSessions()) s.stopSession();

        mTargets.clear();
      }

      Client.Disconnect();
      mCoreInitialized = false;
    } catch (Exception e) {
      errorLogging(e);
    }
  }
コード例 #10
0
    @Override
    public void run() {
      _wifiLock.acquire();
      final String asxUrl = _episode.getAsxUrl();
      AsxModel asx;
      try {
        asx = AsxModel.createModelFromUrl(asxUrl);
      } catch (IOException e) {
        e.printStackTrace();
        _handler.sendDownloadFailedMessage();
        return;
      }
      final List<AsxEntryModel> entries = asx.getEntries();
      final String[] playlist = new String[entries.size()];
      for (int i = 0; i < playlist.length; i++) {
        final AsxEntryModel entry = entries.get(i);
        final String ref = entry.getRef();
        playlist[i] = ref;
      }

      long totalSize = 10L;
      for (final String url : playlist) {
        try {
          final MMSInputStream mmsStream = new MMSInputStream(url);
          totalSize += mmsStream.getSize();
          mmsStream.close();
        } catch (final Exception e) {
          Log.e(TAG, e.getMessage());
          _handler.sendDownloadFailedMessage();
          _wifiLock.release();
          return;
        }
      }
      _handler.sendTotalSizeUpdateMessage(totalSize);

      for (final String url : playlist) {
        _threadFinishedCount = 0;
        try {
          final MMSInputStream mmsStream = new MMSInputStream(url);
          final long size = mmsStream.getSize();
          final double length = mmsStream.getLength();

          final List<FileOutputStream> files;
          final String filePath;
          try {
            final String externalStorageState = Environment.getExternalStorageState();
            if (externalStorageState.equals(Environment.MEDIA_REMOVED)) {
              _handler.sendDownloadFailedMessage();
              _wifiLock.release();
              mmsStream.close();
              return;
            }
            final File sdCardRoot = Environment.getExternalStorageDirectory();
            final String sdCardPath = sdCardRoot.getPath();
            final File rthkFolder = new File(sdCardPath + "/RthkArchivePlayer");

            if (!rthkFolder.exists()) {
              rthkFolder.mkdirs();
            }

            final String rthkPath = rthkFolder.getPath();
            final String filename = URLEncoder.encode(url, "utf-8");
            filePath = rthkPath + "/" + filename;

            files = new ArrayList<FileOutputStream>(_threadNum);
            String ext = "";
            for (int i = 0; i < _threadNum; i++, ext = ".part" + i) {
              final FileOutputStream stream = new FileOutputStream(filePath + ext);
              files.add(stream);
            }

          } catch (final Exception e) {
            Log.e(TAG, e.getMessage());
            _handler.sendDownloadFailedMessage();
            _wifiLock.release();
            return;
          }

          int streamNum = 0;
          final long stepSize = size / _threadNum;

          long startPos = -1L;
          long readCap = -1L;
          DownloadThread downloadThread = null;

          for (final FileOutputStream file : files) {
            final MMSInputStream stream;
            if (streamNum == 0) {
              stream = mmsStream;
              startPos = 0L;
            } else {
              stream = new MMSInputStream(url);
              final long pos = stream.seekByte(stepSize * streamNum);
              readCap = pos - startPos;
              downloadThread.setReadCapacity(readCap);
              downloadThread.start();
              startPos = pos;
            }

            downloadThread = new DownloadThread(stream, file, streamNum);

            streamNum++;

            if (streamNum == _threadNum) {
              downloadThread.setReadCapacity(size * 2);
              downloadThread.start();
            }
          }

          synchronized (this) {
            while (_threadFinishedCount < _threadNum) {
              try {
                wait();
              } catch (final InterruptedException e) {
                e.printStackTrace();
              }
            }
          }

          final FileOutputStream baseFile = new FileOutputStream(filePath, true);
          ;
          for (int i = 1; i < _threadNum; i++) {
            final String path = filePath + ".part" + i;
            try {
              final File file = new File(path);
              final FileInputStream inputStream = new FileInputStream(file);
              final byte[] buffer = new byte[1024];
              int read = 0;
              while ((read = inputStream.read(buffer)) > 0) {
                baseFile.write(buffer, 0, read);
              }
              inputStream.close();
              file.delete();
            } catch (final IOException e) {
              Log.e(TAG, e.getMessage());
            }
          }
          baseFile.close();

          final AsfFileDbAdapter dbAdapter = new AsfFileDbAdapter(_context);
          dbAdapter.open();
          dbAdapter.createFile(url, filePath, length, size);
          dbAdapter.close();
        } catch (final IOException e) {
          Log.e(TAG, e.getMessage());
          _handler.sendDownloadFailedMessage();
          _wifiLock.release();
          return;
        }
      }
      _wifiLock.release();
      _handler.sendDownloadSuccessMessage();
    }
コード例 #11
0
 private void releaseWifiLock() {
   if (mWifiLock != null) {
     mWifiLock.release();
     mWifiLock = null;
   }
 }
コード例 #12
0
ファイル: PollHandler.java プロジェクト: Elbandi/Nagroid
 private void postPoll() {
   if (mWifiLock != null) {
     mWifiLock.release();
   }
 }
コード例 #13
0
ファイル: RMBTService.java プロジェクト: aaron6187/open-rmbt
  public static void unlock() {
    if (wakeLock != null && wakeLock.isHeld()) wakeLock.release();
    if (wifiLock != null && wifiLock.isHeld()) wifiLock.release();

    Log.d(DEBUG_TAG, "Unlock");
  }