diff options
author | Grace Jia <xiaotonj@google.com> | 2020-01-16 11:24:49 -0800 |
---|---|---|
committer | Grace Jia <xiaotonj@google.com> | 2020-01-16 14:43:42 -0800 |
commit | fee59e454c7c4da2230c5a19e101315cbf9e42f0 (patch) | |
tree | 18df5d78cf81b5dcb25f68949788de96163dc48d /src | |
parent | 1f7f1a6160b0c5153d412a1517c3b9c55b22dab5 (diff) | |
download | voip-fee59e454c7c4da2230c5a19e101315cbf9e42f0.tar.gz |
Expose SipAudioCall#getAudioGroup and SipAudioCall#SetAudioGroup
as public API.
Change all methods to synchronize on a private final lock object
instead of the instance itself to avoid exposing internal locks.
Test: manual
Bug: 145923259
Change-Id: I73f4d476e6872c124a08dd588bd26f34eaf2813f
Diffstat (limited to 'src')
-rw-r--r-- | src/java/android/net/sip/SipAudioCall.java | 53 |
1 files changed, 28 insertions, 25 deletions
diff --git a/src/java/android/net/sip/SipAudioCall.java b/src/java/android/net/sip/SipAudioCall.java index f1eb35b..a1a5ae8 100644 --- a/src/java/android/net/sip/SipAudioCall.java +++ b/src/java/android/net/sip/SipAudioCall.java @@ -16,6 +16,8 @@ package android.net.sip; +import android.annotation.NonNull; +import android.annotation.Nullable; import android.content.Context; import android.media.AudioManager; import android.net.rtp.AudioCodec; @@ -27,6 +29,7 @@ import android.net.wifi.WifiManager; import android.os.Message; import android.telephony.Rlog; import android.text.TextUtils; + import java.io.IOException; import java.net.InetAddress; import java.net.UnknownHostException; @@ -191,6 +194,7 @@ public class SipAudioCall { private int mErrorCode = SipErrorCode.NO_ERROR; private String mErrorMessage; + private final Object mLock; /** * Creates a call object with the local SIP profile. @@ -201,6 +205,7 @@ public class SipAudioCall { mContext = context; mLocalProfile = localProfile; mWm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); + mLock = new Object(); } /** @@ -265,7 +270,7 @@ public class SipAudioCall { * @return true if the call is established */ public boolean isInCall() { - synchronized (this) { + synchronized (mLock) { return mInCall; } } @@ -276,7 +281,7 @@ public class SipAudioCall { * @return true if the call is on hold */ public boolean isOnHold() { - synchronized (this) { + synchronized (mLock) { return mHold; } } @@ -309,7 +314,7 @@ public class SipAudioCall { * @return the local SIP profile */ public SipProfile getLocalProfile() { - synchronized (this) { + synchronized (mLock) { return mLocalProfile; } } @@ -320,7 +325,7 @@ public class SipAudioCall { * @return the peer's SIP profile */ public SipProfile getPeerProfile() { - synchronized (this) { + synchronized (mLock) { return (mSipSession == null) ? null : mSipSession.getPeerProfile(); } } @@ -332,7 +337,7 @@ public class SipAudioCall { * @return the session state */ public int getState() { - synchronized (this) { + synchronized (mLock) { if (mSipSession == null) return SipSession.State.READY_TO_CALL; return mSipSession.getState(); } @@ -346,7 +351,7 @@ public class SipAudioCall { * @hide */ public SipSession getSipSession() { - synchronized (this) { + synchronized (mLock) { return mSipSession; } } @@ -404,7 +409,7 @@ public class SipAudioCall { public void onRinging(SipSession session, SipProfile peerProfile, String sessionDescription) { // this callback is triggered only for reinvite. - synchronized (SipAudioCall.this) { + synchronized (mLock) { if ((mSipSession == null) || !mInCall || !session.getCallId().equals( mSipSession.getCallId())) { @@ -568,7 +573,7 @@ public class SipAudioCall { loge("onError():", t); } } - synchronized (this) { + synchronized (mLock) { if ((errorCode == SipErrorCode.DATA_CONNECTION_LOST) || !isInCall()) { close(true); @@ -591,7 +596,7 @@ public class SipAudioCall { throw new SipException("VOIP API is not supported"); } - synchronized (this) { + synchronized (mLock) { mSipSession = session; mPeerSd = sessionDescription; if (DBG) log("attachCall(): " + mPeerSd); @@ -626,7 +631,7 @@ public class SipAudioCall { throw new SipException("VOIP API is not supported"); } - synchronized (this) { + synchronized (mLock) { mSipSession = sipSession; try { mAudioStream = new AudioStream(InetAddress.getByName( @@ -647,7 +652,7 @@ public class SipAudioCall { */ public void endCall() throws SipException { if (DBG) log("endCall: mSipSession" + mSipSession); - synchronized (this) { + synchronized (mLock) { stopCall(RELEASE_SOCKET); mInCall = false; @@ -670,7 +675,7 @@ public class SipAudioCall { */ public void holdCall(int timeout) throws SipException { if (DBG) log("holdCall: mSipSession" + mSipSession + " timeout=" + timeout); - synchronized (this) { + synchronized (mLock) { if (mHold) return; if (mSipSession == null) { loge("holdCall:"); @@ -695,7 +700,7 @@ public class SipAudioCall { */ public void answerCall(int timeout) throws SipException { if (DBG) log("answerCall: mSipSession" + mSipSession + " timeout=" + timeout); - synchronized (this) { + synchronized (mLock) { if (mSipSession == null) { throw new SipException("No call to answer"); } @@ -724,7 +729,7 @@ public class SipAudioCall { */ public void continueCall(int timeout) throws SipException { if (DBG) log("continueCall: mSipSession" + mSipSession + " timeout=" + timeout); - synchronized (this) { + synchronized (mLock) { if (!mHold) return; mSipSession.changeCall(createContinueOffer().encode(), timeout); mHold = false; @@ -854,7 +859,7 @@ public class SipAudioCall { /** Toggles mute. */ public void toggleMute() { - synchronized (this) { + synchronized (mLock) { mMuted = !mMuted; setAudioGroupMode(); } @@ -866,7 +871,7 @@ public class SipAudioCall { * @return true if the call is muted */ public boolean isMuted() { - synchronized (this) { + synchronized (mLock) { return mMuted; } } @@ -879,7 +884,7 @@ public class SipAudioCall { * @param speakerMode set true to enable speaker mode; false to disable */ public void setSpeakerMode(boolean speakerMode) { - synchronized (this) { + synchronized (mLock) { ((AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE)) .setSpeakerphoneOn(speakerMode); setAudioGroupMode(); @@ -915,7 +920,7 @@ public class SipAudioCall { * @param result the result message to send when done */ public void sendDtmf(int code, Message result) { - synchronized (this) { + synchronized (mLock) { AudioGroup audioGroup = getAudioGroup(); if ((audioGroup != null) && (mSipSession != null) && (SipSession.State.IN_CALL == getState())) { @@ -938,7 +943,7 @@ public class SipAudioCall { * @hide */ public AudioStream getAudioStream() { - synchronized (this) { + synchronized (mLock) { return mAudioStream; } } @@ -955,10 +960,9 @@ public class SipAudioCall { * @return the {@link AudioGroup} object or null if the RTP stream has not * yet been set up * @see #getAudioStream - * @hide */ - public AudioGroup getAudioGroup() { - synchronized (this) { + public @Nullable AudioGroup getAudioGroup() { + synchronized (mLock) { if (mAudioGroup != null) return mAudioGroup; return ((mAudioStream == null) ? null : mAudioStream.getGroup()); } @@ -974,10 +978,9 @@ public class SipAudioCall { * settings of the first object (that merges others) override others'. * * @see #getAudioStream - * @hide */ - public void setAudioGroup(AudioGroup group) { - synchronized (this) { + public void setAudioGroup(@NonNull AudioGroup group) { + synchronized (mLock) { if (DBG) log("setAudioGroup: group=" + group); if ((mAudioStream != null) && (mAudioStream.getGroup() != null)) { mAudioStream.join(group); |