private void initData(Context context) {
    this.mContext = context;
    mActivity = (Activity) context;
    DisplayMetrics dm = new DisplayMetrics();
    mActivity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    mDensity = dm.density;
    mWidth = dm.widthPixels;
    mInflater = LayoutInflater.from(mContext);
    AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
    audioManager.setMode(AudioManager.MODE_NORMAL);
    if (audioManager.isSpeakerphoneOn()) {
      audioManager.setSpeakerphoneOn(true);
    } else {
      audioManager.setSpeakerphoneOn(false);
    }
    mp.setAudioStreamType(AudioManager.STREAM_RING);
    mp.setOnErrorListener(
        new OnErrorListener() {

          @Override
          public boolean onError(MediaPlayer mp, int what, int extra) {
            return false;
          }
        });
  }
  public void playVoice(String filePath) {
    if (!(new File(filePath).exists())) {
      return;
    }
    AudioManager audioManager = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);

    mediaPlayer = new MediaPlayer();
    if (EMChatManager.getInstance().getChatOptions().getUseSpeaker()) {
      audioManager.setMode(AudioManager.MODE_NORMAL);
      audioManager.setSpeakerphoneOn(true);
      mediaPlayer.setAudioStreamType(AudioManager.STREAM_RING);
    } else {
      audioManager.setSpeakerphoneOn(false); // 关闭扬声器
      // 把声音设定成Earpiece(听筒)出来,设定为正在通话中
      audioManager.setMode(AudioManager.MODE_IN_CALL);
      mediaPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);
    }
    try {
      mediaPlayer.setDataSource(filePath);
      mediaPlayer.prepare();
      mediaPlayer.setOnCompletionListener(
          new MediaPlayer.OnCompletionListener() {

            @Override
            public void onCompletion(MediaPlayer mp) {
              // TODO Auto-generated method stub
              mediaPlayer.release();
              mediaPlayer = null;
              stopPlayVoice(); // stop animation
            }
          });
      isPlaying = true;
      currentPlayListener = this;
      currentMessage = message;
      mediaPlayer.start();
      showAnimation();
      try {
        // 如果是接收的消息
        if (!message.isAcked && message.direct == EMMessage.Direct.RECEIVE) {
          message.isAcked = true;
          if (iv_read_status != null && iv_read_status.getVisibility() == View.VISIBLE) {
            // 隐藏自己未播放这条语音消息的标志
            iv_read_status.setVisibility(View.INVISIBLE);
            EMChatDB.getInstance().updateMessageAck(message.getMsgId(), true);
          }
          // 告知对方已读这条消息
          if (chatType != ChatType.GroupChat)
            EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId());
        }
      } catch (Exception e) {
        message.isAcked = false;
      }
    } catch (Exception e) {
    }
  }
Exemplo n.º 3
0
  @Override
  protected void onPause() {
    super.onPause();
    //	removeWindow();
    kl.reenableKeyguard();
    unregisterReceiver(mWifiReceiver);
    unregisterReceiver(mPowerBroadcastReceiver);
    sensorManager.unregisterListener(lsn);
    mWifiHandler.removeMessages(WIFI_MSG_SCAN);
    Log.d(TAG, " __________________---------- oldBrightness = " + oldBrightness);

    switch (mRecorder.state()) {
      case Recorder.IDLE_STATE:
        mRecorder.delete();
        break;
      case Recorder.PLAYING_STATE:
        mRecorder.stop();
        mRecorder.delete();
        break;
      case Recorder.RECORDING_STATE:
        mRecorder.stop();
        mRecorder.clear();
        break;
    }
    mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, mOldVolume, 0);
    if (mSpeakerOn) {
      mAudioManager.setSpeakerphoneOn(false);
    }
    //		unregisterReceiver(mPowerBroadcastReceiver);
  }
Exemplo n.º 4
0
  /**
   * 播放拨号响铃
   *
   * @param sound
   * @param number
   */
  protected int playMakeCallSounds() {
    try {
      // 最大音量
      float audioMaxVolumn = audioManager.getStreamMaxVolume(AudioManager.STREAM_RING);
      // 当前音量
      float audioCurrentVolumn = audioManager.getStreamVolume(AudioManager.STREAM_RING);
      float volumnRatio = audioCurrentVolumn / audioMaxVolumn;

      audioManager.setMode(AudioManager.MODE_RINGTONE);
      audioManager.setSpeakerphoneOn(false);

      // 播放
      int id =
          soundPool.play(
              outgoing, // 声音资源
              0.3f, // 左声道
              0.3f, // 右声道
              1, // 优先级,0最低
              -1, // 循环次数,0是不循环,-1是永远循环
              1); // 回放速度,0.5-2.0之间。1为正常速度
      return id;
    } catch (Exception e) {
      return -1;
    }
  }
 /** Sets the speaker phone mode. */
 private void setSpeakerphoneOn(boolean on) {
   boolean wasOn = audioManager.isSpeakerphoneOn();
   if (wasOn == on) {
     return;
   }
   audioManager.setSpeakerphoneOn(on);
 }
Exemplo n.º 6
0
 // 打开扬声器
 protected void openSpeakerOn() {
   try {
     if (!audioManager.isSpeakerphoneOn()) audioManager.setSpeakerphoneOn(true);
     audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 7
0
 @SuppressWarnings("deprecation")
 public static void getAudioRoute(AudioManager am) {
   if (am.isBluetoothA2dpOn()) {
     am.setBluetoothA2dpOn(true);
   } else if (am.isSpeakerphoneOn()) {
     am.setSpeakerphoneOn(true);
   } else if (am.isWiredHeadsetOn()) {
     am.setWiredHeadsetOn(true);
   }
 }
 public static void setMode(int mode) {
   Editor edit = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).edit();
   edit.putBoolean(org.sipdroid.sipua.ui.Settings.PREF_SETMODE, true);
   edit.commit();
   AudioManager am = (AudioManager) Receiver.mContext.getSystemService(Context.AUDIO_SERVICE);
   if (Integer.parseInt(Build.VERSION.SDK) >= 5) {
     am.setSpeakerphoneOn(mode == AudioManager.MODE_NORMAL);
     if (samsung) RtpStreamSender.changed = true;
   } else am.setMode(mode);
 }
Exemplo n.º 9
0
 public void setSpeakerphoneOn(boolean on) throws SameThreadException {
   if (service != null && restartAudioWhenRoutingChange && !ringer.isRinging()) {
     service.setNoSnd();
     userWantSpeaker = on;
     service.setSnd();
   } else {
     userWantSpeaker = on;
     audioManager.setSpeakerphoneOn(on);
   }
   broadcastMediaChanged();
 }
 public void setAudioPlayByEarPhone(int state) {
   AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
   int currVolume = audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL);
   audioManager.setMode(AudioManager.MODE_IN_CALL);
   if (state == 0) {
     mIsEarPhoneOn = false;
     audioManager.setSpeakerphoneOn(true);
     audioManager.setStreamVolume(
         AudioManager.STREAM_VOICE_CALL,
         audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL),
         AudioManager.STREAM_VOICE_CALL);
     Log.i(TAG, "set SpeakerphoneOn true!");
   } else {
     mIsEarPhoneOn = true;
     audioManager.setSpeakerphoneOn(false);
     audioManager.setStreamVolume(
         AudioManager.STREAM_VOICE_CALL, currVolume, AudioManager.STREAM_VOICE_CALL);
     Log.i(TAG, "set SpeakerphoneOn false!");
   }
 }
Exemplo n.º 11
0
  public synchronized void setSpeakerOn() throws SameThreadException {
    if (mAudioManager != null) {
      mUserAgentBroadcastReceiver.setNoSnd();
      mUserAgentBroadcastReceiver.setSnd();
      mAudioManager.setSpeakerphoneOn(userWantSpeaker = !userWantSpeaker);

      mAudioManager.setStreamVolume(
          AudioManager.STREAM_MUSIC,
          mAudioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL),
          AudioManager.STREAM_VOICE_CALL);
    }
  }
Exemplo n.º 12
0
        public void onClick(View arg0) {
          switch (arg0.getId()) {
            case R.id.camera_switch_btu:
              mCameraDevice.stopPreview();
              mCameraDevice.release();
              mCameraDevice = null;
              mCurrentCameraId = (mCurrentCameraId + 1) % mNumberOfCameras;

              mCameraDevice = Camera.open(mCurrentCameraId);
              /*if(mHardwareRotation==0) // XXX
              	mCameraDevice.setDisplayOrientation(90);
              mCameraDevice.setDisplayOrientation(90);
              */
              mSurfaceHolder = null;
              mSurfaceView.setVisibility(View.GONE);
              mSurfaceView.setVisibility(View.VISIBLE);
              break;
            case R.id.brightnesstestbut:
              if (isTestBrightness) {
                mBrightnessHandler.removeMessages(0);
                setBrightness(oldBrightness);
                brightnessbut.setText(R.string.BrightnessTitle);
              } else {
                mBrightnessHandler.sendEmptyMessage(0);
                brightnessbut.setText(R.string.BrightnessTitleStop);
              }
              isTestBrightness = !isTestBrightness;
              break;
            case R.id.recordtestbutton:
              mAudioManager.setStreamVolume(
                  AudioManager.STREAM_MUSIC,
                  mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC),
                  0);
              mSpeakerOn = mAudioManager.isSpeakerphoneOn();
              if (!mSpeakerOn) {
                mAudioManager.setSpeakerphoneOn(true);
              }
              mRecordHandler.sendEmptyMessage(MSG_TEST_MIC_START);
              recordtestbutton.setEnabled(false);
              break;
            case R.id.singletest:
              Intent tmp = new Intent(FirstRun.this, DeviceTest.class);
              FirstRun.this.startActivity(tmp);
              break;
            case R.id.closefirstrun:
              FirstRun.this.finish();
              break;
            default:
              break;
          }
        }
 public static void restoreMode() {
   if (PreferenceManager.getDefaultSharedPreferences(Receiver.mContext)
       .getBoolean(
           org.sipdroid.sipua.ui.Settings.PREF_SETMODE,
           org.sipdroid.sipua.ui.Settings.DEFAULT_SETMODE)) {
     Editor edit = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).edit();
     edit.putBoolean(org.sipdroid.sipua.ui.Settings.PREF_SETMODE, false);
     edit.commit();
     if (Receiver.pstn_state == null || Receiver.pstn_state.equals("IDLE")) {
       AudioManager am = (AudioManager) Receiver.mContext.getSystemService(Context.AUDIO_SERVICE);
       if (Integer.parseInt(Build.VERSION.SDK) >= 5) am.setSpeakerphoneOn(false);
       else am.setMode(AudioManager.MODE_NORMAL);
     }
   }
 }
Exemplo n.º 14
0
  /**
   * <pre>
   * 关闭扬声器
   * @param mContext
   * </pre>
   */
  public void CloseSpeaker(Context mContext) {

    try {
      AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
      if (audioManager != null) {
        if (audioManager.isSpeakerphoneOn()) {
          audioManager.setSpeakerphoneOn(false);
          audioManager.setStreamVolume(
              AudioManager.STREAM_VOICE_CALL, currVolume, AudioManager.STREAM_VOICE_CALL);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    // Toast.makeText(context,"揚聲器已經關閉",Toast.LENGTH_SHORT).show();
  }
Exemplo n.º 15
0
  // 关闭扬声器
  protected void closeSpeakerOn() {

    try {
      if (audioManager != null) {
        // int curVolume =
        // audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL);
        if (audioManager.isSpeakerphoneOn()) audioManager.setSpeakerphoneOn(false);
        audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
        // audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL,
        // curVolume, AudioManager.STREAM_VOICE_CALL);

      }

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 16
0
  /**
   * <pre>
   * 打开扬声器
   * @param mContext
   * </pre>
   */
  public void OpenSpeaker(Context mContext) {

    try {
      AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
      audioManager.setMode(AudioManager.ROUTE_SPEAKER);
      currVolume = audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL);

      if (!audioManager.isSpeakerphoneOn()) {
        audioManager.setSpeakerphoneOn(true);

        audioManager.setStreamVolume(
            AudioManager.STREAM_VOICE_CALL,
            audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL),
            AudioManager.STREAM_VOICE_CALL);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 17
0
  /** Restore the state of the audio */
  @SuppressWarnings("deprecation")
  private final synchronized void restoreAudioState() {
    if (!prefs.getBoolean("isSavedAudioState", false)) {
      // If we have NEVER set, do not try to reset !
      return;
    }

    ContentResolver ctntResolver = service.getContentResolver();

    Settings.System.putInt(
        ctntResolver,
        Settings.System.WIFI_SLEEP_POLICY,
        prefs.getInt("savedWifiPolicy", Settings.System.WIFI_SLEEP_POLICY_DEFAULT));
    // audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER,
    // prefs.getInt("savedVibrateRing",
    // AudioManager.VIBRATE_SETTING_ONLY_SILENT));
    // audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION,
    // prefs.getInt("savedVibradeNotif", AudioManager.VIBRATE_SETTING_OFF));
    // audioManager.setRingerMode(prefs.getInt("savedRingerMode",
    // AudioManager.RINGER_MODE_NORMAL));

    int inCallStream = Compatibility.getInCallStream(userWantBluetooth);
    setStreamVolume(
        inCallStream,
        prefs.getInt("savedVolume", (int) (audioManager.getStreamMaxVolume(inCallStream) * 0.8)),
        0);

    int targetMode = getAudioTargetMode();
    if (service.getPrefs().useRoutingApi()) {
      audioManager.setRouting(
          targetMode,
          prefs.getInt("savedRoute", AudioManager.ROUTE_SPEAKER),
          AudioManager.ROUTE_ALL);
    } else {
      audioManager.setSpeakerphoneOn(prefs.getBoolean("savedSpeakerPhone", false));
    }
    audioManager.setMode(prefs.getInt("savedMode", AudioManager.MODE_NORMAL));

    Editor ed = prefs.edit();
    ed.putBoolean("isSavedAudioState", false);
    ed.commit();
  }
Exemplo n.º 18
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    receiveButton = (Button) findViewById(R.id.receive_button);
    stopButton = (Button) findViewById(R.id.stop_button);
    findViewById(R.id.receive_label);

    receiveButton.setOnClickListener(receiveListener);
    stopButton.setOnClickListener(stopListener);

    /*ForText
    recTV = (TextView) findViewById(R.id.rec_TV);
    recTV.setText("Ready To receive");
    */

    am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    am.setMode(AudioManager.MODE_IN_CALL);
    am.setSpeakerphoneOn(false);
  }
Exemplo n.º 19
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Thread.setDefaultUncaughtExceptionHandler(new UnhandledExceptionHandler(this));

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    Point displaySize = new Point();
    getWindowManager().getDefaultDisplay().getRealSize(displaySize);

    vsv = new AppRTCGLView(this, displaySize);
    VideoRendererGui.setView(vsv);
    remoteRender = VideoRendererGui.create(0, 0, 100, 100);
    localRender = VideoRendererGui.create(70, 5, 25, 25);

    vsv.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            toggleHUD();
          }
        });
    setContentView(vsv);
    logAndToast("Tap the screen to toggle stats visibility");

    hudView = new TextView(this);
    hudView.setTextColor(Color.BLACK);
    hudView.setBackgroundColor(Color.WHITE);
    hudView.setAlpha(0.4f);
    hudView.setTextSize(TypedValue.COMPLEX_UNIT_PT, 5);
    hudView.setVisibility(View.INVISIBLE);
    addContentView(hudView, hudLayout);

    if (!factoryStaticInitialized) {
      abortUnless(
          PeerConnectionFactory.initializeAndroidGlobals(this, true, true),
          "Failed to initializeAndroidGlobals");
      factoryStaticInitialized = true;
    }

    AudioManager audioManager = ((AudioManager) getSystemService(AUDIO_SERVICE));
    // TODO(fischman): figure out how to do this Right(tm) and remove the
    // suppression.
    @SuppressWarnings("deprecation")
    boolean isWiredHeadsetOn = audioManager.isWiredHeadsetOn();
    audioManager.setMode(
        isWiredHeadsetOn ? AudioManager.MODE_IN_CALL : AudioManager.MODE_IN_COMMUNICATION);
    audioManager.setSpeakerphoneOn(!isWiredHeadsetOn);

    sdpMediaConstraints = new MediaConstraints();
    sdpMediaConstraints.mandatory.add(
        new MediaConstraints.KeyValuePair("OfferToReceiveAudio", "true"));
    sdpMediaConstraints.mandatory.add(
        new MediaConstraints.KeyValuePair("OfferToReceiveVideo", "true"));

    final Intent intent = getIntent();
    if ("android.intent.action.VIEW".equals(intent.getAction())) {
      connectToRoom(intent.getData().toString());
      return;
    }
    showGetRoomUI();
  }
Exemplo n.º 20
0
  @SuppressWarnings("deprecation")
  @TestTargets({
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "setBluetoothA2dpOn",
        args = {boolean.class}),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "setBluetoothScoOn",
        args = {boolean.class}),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "getRouting",
        args = {int.class}),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "isBluetoothA2dpOn",
        args = {}),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "isBluetoothScoOn",
        args = {}),
    @TestTargetNew(
        level = TestLevel.NOT_FEASIBLE,
        method = "setRouting",
        args = {int.class, int.class, int.class}),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "setSpeakerphoneOn",
        args = {boolean.class}),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "isSpeakerphoneOn",
        args = {})
  })
  @ToBeFixed(
      bug = "1713090",
      explanation =
          "setRouting() has not only been deprecated, but is no" + " longer having any effect.")
  public void testRouting() throws Exception {
    // setBluetoothA2dpOn is a no-op, and getRouting should always return -1
    // AudioManager.MODE_CURRENT
    boolean oldA2DP = mAudioManager.isBluetoothA2dpOn();
    mAudioManager.setBluetoothA2dpOn(true);
    assertEquals(oldA2DP, mAudioManager.isBluetoothA2dpOn());
    mAudioManager.setBluetoothA2dpOn(false);
    assertEquals(oldA2DP, mAudioManager.isBluetoothA2dpOn());

    assertEquals(AudioManager.MODE_CURRENT, mAudioManager.getRouting(MODE_RINGTONE));
    assertEquals(AudioManager.MODE_CURRENT, mAudioManager.getRouting(MODE_NORMAL));
    assertEquals(AudioManager.MODE_CURRENT, mAudioManager.getRouting(MODE_IN_CALL));

    mAudioManager.setBluetoothScoOn(true);
    assertTrue(mAudioManager.isBluetoothScoOn());
    assertEquals(AudioManager.MODE_CURRENT, mAudioManager.getRouting(MODE_RINGTONE));
    assertEquals(AudioManager.MODE_CURRENT, mAudioManager.getRouting(MODE_NORMAL));
    assertEquals(AudioManager.MODE_CURRENT, mAudioManager.getRouting(MODE_IN_CALL));

    mAudioManager.setBluetoothScoOn(false);
    assertFalse(mAudioManager.isBluetoothScoOn());
    assertEquals(AudioManager.MODE_CURRENT, mAudioManager.getRouting(MODE_RINGTONE));
    assertEquals(AudioManager.MODE_CURRENT, mAudioManager.getRouting(MODE_NORMAL));
    assertEquals(AudioManager.MODE_CURRENT, mAudioManager.getRouting(MODE_IN_CALL));

    mAudioManager.setSpeakerphoneOn(true);
    assertTrue(mAudioManager.isSpeakerphoneOn());
    assertEquals(AudioManager.MODE_CURRENT, mAudioManager.getRouting(MODE_IN_CALL));
    mAudioManager.setSpeakerphoneOn(false);
    assertFalse(mAudioManager.isSpeakerphoneOn());
    assertEquals(AudioManager.MODE_CURRENT, mAudioManager.getRouting(MODE_IN_CALL));
  }
Exemplo n.º 21
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_watch);
    ButterKnife.bind(this);

    getWindow()
        .addFlags(
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON // 保持屏幕常亮
                | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD // 关闭键盘
            );

    // 退出登录并使用username_uuid登录,记着拼接下划线(LoginUtil.USERNAME_EYE_DEPART)
    LoginUtil.relogin(
        AppConfig.getUsername() + LoginUtil.USERNAME_EYE_DEPART + CommonUtil.getUUID(this),
        new EMCallBack() {
          @Override
          public void onSuccess() {
            LogUtil.e("xmh-login", "eye");
            initAfterLogin();
          }

          @Override
          public void onError(int i, String s) {
            // do nothing
          }

          @Override
          public void onProgress(int i, String s) {
            // do nothing
          }
        });

    callHelper = EMVideoCallHelper.getInstance();
    LogUtil.e("xmh-record", "helper-create");
    cameraHelper = new CameraHelper(this, callHelper, surface.getHolder());

    callHelper.setSurfaceView(null);
    surface.getHolder().addCallback(new LocalCallback());

    // 设置视频状态监听
    setCallStateListener();
    setConnectionListener();
    audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
    audioManager.setMode(AudioManager.MODE_RINGTONE);
    audioManager.setSpeakerphoneOn(true);

    // 监听结束通话广播
    LocalBroadcastManager.getInstance(this)
        .registerReceiver(
            new BroadcastReceiver() {
              @Override
              public void onReceive(Context context, Intent intent) {
                if (isGoing) {
                  // 结束通话
                  EMChatManager.getInstance().endCall();
                  cameraHelper.setStartFlag(false);
                  isGoing = false;
                  LogUtil.e("xmh-record", "end call", true);
                }
              }
            },
            new IntentFilter(CommendUtil.ACTION_END_CALL));
  }
Exemplo n.º 22
0
  /** Set the audio mode as in call */
  @SuppressWarnings("deprecation")
  private synchronized void actualSetAudioInCall() {
    // Ensure not already set
    if (isSetAudioMode) {
      return;
    }
    stopRing();
    saveAudioState();

    // Set the rest of the phone in a better state to not interferate with
    // current call
    // Do that only if we were not already in silent mode
    /*
     * Not needed anymore with on flight gsm call capture
     * if(audioManager.getRingerMode() != AudioManager.RINGER_MODE_SILENT) {
     * audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER,
     * AudioManager.VIBRATE_SETTING_ON);
     * audioManager.setVibrateSetting(AudioManager
     * .VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_OFF);
     * audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); }
     */

    // LOCKS

    // Wifi management if necessary
    ContentResolver ctntResolver = service.getContentResolver();
    Settings.System.putInt(
        ctntResolver, Settings.System.WIFI_SLEEP_POLICY, Settings.System.WIFI_SLEEP_POLICY_NEVER);

    // Acquire wifi lock
    WifiManager wman = (WifiManager) service.getSystemService(Context.WIFI_SERVICE);
    if (wifiLock == null) {
      wifiLock =
          wman.createWifiLock(
              (Compatibility.isCompatible(9))
                  ? WifiManager.WIFI_MODE_FULL_HIGH_PERF
                  : WifiManager.WIFI_MODE_FULL,
              "com.csipsimple.InCallLock");
      wifiLock.setReferenceCounted(false);
    }
    WifiInfo winfo = wman.getConnectionInfo();
    if (winfo != null) {
      DetailedState dstate = WifiInfo.getDetailedStateOf(winfo.getSupplicantState());
      // We assume that if obtaining ip addr, we are almost connected so
      // can keep wifi lock
      if (dstate == DetailedState.OBTAINING_IPADDR || dstate == DetailedState.CONNECTED) {
        if (!wifiLock.isHeld()) {
          wifiLock.acquire();
        }
      }

      // This wake lock purpose is to prevent PSP wifi mode
      if (service.getPrefs().getPreferenceBooleanValue(SipConfigManager.KEEP_AWAKE_IN_CALL)) {
        if (screenLock == null) {
          PowerManager pm = (PowerManager) service.getSystemService(Context.POWER_SERVICE);
          screenLock =
              pm.newWakeLock(
                  PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE,
                  "com.csipsimple.onIncomingCall.SCREEN");
          screenLock.setReferenceCounted(false);
        }
        // Ensure single lock
        if (!screenLock.isHeld()) {
          screenLock.acquire();
        }
      }
    }

    if (!useWebRTCImpl) {
      // Audio routing
      int targetMode = getAudioTargetMode();
      Log.d(THIS_FILE, "Set mode audio in call to " + targetMode);

      if (service.getPrefs().generateForSetCall()) {
        boolean needOutOfSilent = (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT);
        if (needOutOfSilent) {
          audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        }
        ToneGenerator toneGenerator = new ToneGenerator(AudioManager.STREAM_VOICE_CALL, 1);
        toneGenerator.startTone(41 /* ToneGenerator.TONE_CDMA_CONFIRM */);
        toneGenerator.stopTone();
        toneGenerator.release();
        // Restore silent mode
        if (needOutOfSilent) {
          audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
        }
      }

      // Set mode
      if (targetMode != AudioManager.MODE_IN_CALL && useSgsWrkAround) {
        // For galaxy S we need to set in call mode before to reset
        // stack
        audioManager.setMode(AudioManager.MODE_IN_CALL);
      }

      audioManager.setMode(targetMode);

      // Routing
      if (service.getPrefs().useRoutingApi()) {
        audioManager.setRouting(
            targetMode,
            userWantSpeaker ? AudioManager.ROUTE_SPEAKER : AudioManager.ROUTE_EARPIECE,
            AudioManager.ROUTE_ALL);
      } else {
        audioManager.setSpeakerphoneOn(userWantSpeaker ? true : false);
      }

      audioManager.setMicrophoneMute(false);
      if (bluetoothWrapper != null && userWantBluetooth && bluetoothWrapper.canBluetooth()) {
        Log.d(THIS_FILE, "Try to enable bluetooth");
        bluetoothWrapper.setBluetoothOn(true);
      }

    } else {
      // WebRTC implementation for routing
      int apiLevel = Compatibility.getApiLevel();

      // SetAudioMode
      // ***IMPORTANT*** When the API level for honeycomb (H) has been
      // decided,
      // the condition should be changed to include API level 8 to H-1.
      if (android.os.Build.BRAND.equalsIgnoreCase("Samsung") && (8 == apiLevel)) {
        // Set Samsung specific VoIP mode for 2.2 devices
        int mode = 4;
        audioManager.setMode(mode);
        if (audioManager.getMode() != mode) {
          Log.e(THIS_FILE, "Could not set audio mode for Samsung device");
        }
      }

      // SetPlayoutSpeaker
      if ((3 == apiLevel) || (4 == apiLevel)) {
        // 1.5 and 1.6 devices
        if (userWantSpeaker) {
          // route audio to back speaker
          audioManager.setMode(AudioManager.MODE_NORMAL);
        } else {
          // route audio to earpiece
          audioManager.setMode(AudioManager.MODE_IN_CALL);
        }
      } else {
        // 2.x devices
        if ((android.os.Build.BRAND.equalsIgnoreCase("samsung"))
            && ((5 == apiLevel) || (6 == apiLevel) || (7 == apiLevel))) {
          // Samsung 2.0, 2.0.1 and 2.1 devices
          if (userWantSpeaker) {
            // route audio to back speaker
            audioManager.setMode(AudioManager.MODE_IN_CALL);
            audioManager.setSpeakerphoneOn(userWantSpeaker);
          } else {
            // route audio to earpiece
            audioManager.setSpeakerphoneOn(userWantSpeaker);
            audioManager.setMode(AudioManager.MODE_NORMAL);
          }
        } else {
          // Non-Samsung and Samsung 2.2 and up devices
          audioManager.setSpeakerphoneOn(userWantSpeaker);
        }
      }
    }

    // Set stream solo/volume/focus

    int inCallStream = Compatibility.getInCallStream(userWantBluetooth);
    if (doFocusAudio) {
      if (!accessibilityManager.isEnabled()) {
        audioManager.setStreamSolo(inCallStream, true);
      }
      audioFocusWrapper.focus(userWantBluetooth);
    }
    Log.d(THIS_FILE, "Initial volume level : " + service.getPrefs().getInitialVolumeLevel());
    setStreamVolume(
        inCallStream,
        (int)
            (audioManager.getStreamMaxVolume(inCallStream)
                * service.getPrefs().getInitialVolumeLevel()),
        0);

    isSetAudioMode = true;
    // System.gc();
  }
Exemplo n.º 23
0
 public static void enableSpeakerphoneRouting(Context context) {
   AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
   am.setSpeakerphoneOn(true);
   Log.d(TAG, "Set speakerphone audio routing");
 }
Exemplo n.º 24
0
 public static void enableDefaultRouting(Context context) {
   AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
   am.setSpeakerphoneOn(false);
   am.setBluetoothScoOn(false);
   Log.d(TAG, "Set default audio routing");
 }