Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1180f2a0 authored by Hung-ying Tyan's avatar Hung-ying Tyan Committed by Android (Google) Code Review
Browse files

Merge "Remove ringtone API from SipAudioCall." into gingerbread

parents 3466e1fc 9b449e56
Loading
Loading
Loading
Loading
+0 −45
Original line number Diff line number Diff line
@@ -96518,32 +96518,6 @@
<parameter name="callbackImmediately" type="boolean">
</parameter>
</method>
<method name="setRingbackToneEnabled"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="enabled" type="boolean">
</parameter>
</method>
<method name="setRingtoneEnabled"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="enabled" type="boolean">
</parameter>
</method>
<method name="setSpeakerMode"
 return="void"
 abstract="false"
@@ -97242,25 +97216,6 @@
<exception name="SipException" type="android.net.sip.SipException">
</exception>
</method>
<method name="takeAudioCall"
 return="android.net.sip.SipAudioCall"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="incomingCallIntent" type="android.content.Intent">
</parameter>
<parameter name="listener" type="android.net.sip.SipAudioCall.Listener">
</parameter>
<parameter name="ringtoneEnabled" type="boolean">
</parameter>
<exception name="SipException" type="android.net.sip.SipException">
</exception>
</method>
<method name="unregister"
 return="void"
 abstract="false"
+0 −1
Original line number Diff line number Diff line
@@ -714,7 +714,6 @@ public class SipPhone extends SipPhoneBase {
            setState(Call.State.DIALING);
            mSipAudioCall = mSipManager.makeAudioCall(mProfile, mPeer, null,
                    TIMEOUT_MAKE_CALL);
            mSipAudioCall.setRingbackToneEnabled(false);
            mSipAudioCall.setListener(mAdapter);
        }

+0 −85
Original line number Diff line number Diff line
@@ -18,10 +18,6 @@ package android.net.sip;

import android.content.Context;
import android.media.AudioManager;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.media.ToneGenerator;
import android.net.Uri;
import android.net.rtp.AudioCodec;
import android.net.rtp.AudioGroup;
import android.net.rtp.AudioStream;
@@ -30,8 +26,6 @@ import android.net.sip.SimpleSessionDescription.Media;
import android.net.wifi.WifiManager;
import android.os.Message;
import android.os.RemoteException;
import android.os.Vibrator;
import android.provider.Settings;
import android.util.Log;

import java.io.IOException;
@@ -175,11 +169,6 @@ public class SipAudioCall {
    private boolean mMuted = false;
    private boolean mHold = false;

    private boolean mRingbackToneEnabled = true;
    private boolean mRingtoneEnabled = true;
    private Ringtone mRingtone;
    private ToneGenerator mRingbackTone;

    private SipProfile mPendingCallRequest;
    private WifiManager mWm;
    private WifiManager.WifiLock mWifiHighPerfLock;
@@ -285,8 +274,6 @@ public class SipAudioCall {

    private synchronized void close(boolean closeRtp) {
        if (closeRtp) stopCall(RELEASE_SOCKET);
        stopRingbackTone();
        stopRinging();

        mInCall = false;
        mHold = false;
@@ -366,7 +353,6 @@ public class SipAudioCall {
            @Override
            public void onRingingBack(SipSession session) {
                Log.d(TAG, "sip call ringing back: " + session);
                if (!mInCall) startRingbackTone();
                Listener listener = mListener;
                if (listener != null) {
                    try {
@@ -403,8 +389,6 @@ public class SipAudioCall {
            @Override
            public void onCallEstablished(SipSession session,
                    String sessionDescription) {
                stopRingbackTone();
                stopRinging();
                mPeerSd = sessionDescription;
                Log.v(TAG, "onCallEstablished()" + mPeerSd);

@@ -533,10 +517,6 @@ public class SipAudioCall {
            Log.v(TAG, "attachCall()" + mPeerSd);
            try {
                session.setListener(createListener());

                if (getState() == SipSession.State.INCOMING_CALL) {
                    startRinging();
                }
            } catch (Throwable e) {
                Log.e(TAG, "attachCall()", e);
                throwSipException(e);
@@ -580,7 +560,6 @@ public class SipAudioCall {
     */
    public void endCall() throws SipException {
        synchronized (this) {
            stopRinging();
            stopCall(RELEASE_SOCKET);
            mInCall = false;

@@ -625,7 +604,6 @@ public class SipAudioCall {
     */
    public void answerCall(int timeout) throws SipException {
        synchronized (this) {
            stopRinging();
            try {
                mAudioStream = new AudioStream(InetAddress.getByName(
                        getLocalIp()));
@@ -1024,69 +1002,6 @@ public class SipAudioCall {
        return mSipSession.getLocalIp();
    }


    /**
     * Enables/disables the ring-back tone.
     *
     * @param enabled true to enable; false to disable
     */
    public void setRingbackToneEnabled(boolean enabled) {
        synchronized (this) {
            mRingbackToneEnabled = enabled;
        }
    }

    /**
     * Enables/disables the ring tone.
     *
     * @param enabled true to enable; false to disable
     */
    public void setRingtoneEnabled(boolean enabled) {
        synchronized (this) {
            mRingtoneEnabled = enabled;
        }
    }

    private void startRingbackTone() {
        if (!mRingbackToneEnabled) return;
        if (mRingbackTone == null) {
            // The volume relative to other sounds in the stream
            int toneVolume = 80;
            mRingbackTone = new ToneGenerator(
                    AudioManager.STREAM_VOICE_CALL, toneVolume);
        }
        mRingbackTone.startTone(ToneGenerator.TONE_CDMA_LOW_PBX_L);
    }

    private void stopRingbackTone() {
        if (mRingbackTone != null) {
            mRingbackTone.stopTone();
            mRingbackTone.release();
            mRingbackTone = null;
        }
    }

    private void startRinging() {
        if (!mRingtoneEnabled) return;
        ((Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE))
                .vibrate(new long[] {0, 1000, 1000}, 1);
        AudioManager am = (AudioManager)
                mContext.getSystemService(Context.AUDIO_SERVICE);
        if (am.getStreamVolume(AudioManager.STREAM_RING) > 0) {
            String ringtoneUri =
                    Settings.System.DEFAULT_RINGTONE_URI.toString();
            mRingtone = RingtoneManager.getRingtone(mContext,
                    Uri.parse(ringtoneUri));
            mRingtone.play();
        }
    }

    private void stopRinging() {
        ((Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE))
                .cancel();
        if (mRingtone != null) mRingtone.stop();
    }

    private void throwSipException(Throwable throwable) throws SipException {
        if (throwable instanceof SipException) {
            throw (SipException) throwable;
+1 −14
Original line number Diff line number Diff line
@@ -350,17 +350,6 @@ public class SipManager {
        }
    }

    /**
     * The method calls {@code takeAudioCall(incomingCallIntent,
     * listener, true}.
     *
     * @see #takeAudioCall(Intent, SipAudioCall.Listener, boolean)
     */
    public SipAudioCall takeAudioCall(Intent incomingCallIntent,
            SipAudioCall.Listener listener) throws SipException {
        return takeAudioCall(incomingCallIntent, listener, true);
    }

    /**
     * Creates a {@link SipAudioCall} to take an incoming call. Before the call
     * is returned, the listener will receive a
@@ -374,8 +363,7 @@ public class SipManager {
     * @throws SipException if calling the SIP service results in an error
     */
    public SipAudioCall takeAudioCall(Intent incomingCallIntent,
            SipAudioCall.Listener listener, boolean ringtoneEnabled)
            throws SipException {
            SipAudioCall.Listener listener) throws SipException {
        if (incomingCallIntent == null) return null;

        String callId = getCallId(incomingCallIntent);
@@ -394,7 +382,6 @@ public class SipManager {
            if (session == null) return null;
            SipAudioCall call = new SipAudioCall(
                    mContext, session.getLocalProfile());
            call.setRingtoneEnabled(ringtoneEnabled);
            call.attachCall(new SipSession(session), offerSd);
            call.setListener(listener);
            return call;