Skip to content

Commit 5bd3782

Browse files
author
Hung-ying Tyan
committed
Check if VoIP API is supported in SipManager.
This is to make SipManager.isVoipSupported() effective. Also add NPE check now that we may return null SipAudioCall when VOIP is not supported. Bug: 3251016 Change-Id: Icd551123499f55eef190743b90980922893c4a13
1 parent c724f2f commit 5bd3782

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

voip/java/android/net/sip/SipAudioCall.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,10 +519,15 @@ private void onError(int errorCode, String message) {
519519
* @param session the session that receives the incoming call
520520
* @param sessionDescription the session description of the incoming call
521521
* @throws SipException if the SIP service fails to attach this object to
522-
* the session
522+
* the session or VOIP API is not supported by the device
523+
* @see SipManager#isVoipSupported
523524
*/
524525
public void attachCall(SipSession session, String sessionDescription)
525526
throws SipException {
527+
if (!SipManager.isVoipSupported(mContext)) {
528+
throw new SipException("VOIP API is not supported");
529+
}
530+
526531
synchronized (this) {
527532
mSipSession = session;
528533
mPeerSd = sessionDescription;
@@ -548,10 +553,15 @@ public void attachCall(SipSession session, String sessionDescription)
548553
* SIP protocol) is used if {@code timeout} is zero or negative.
549554
* @see Listener#onError
550555
* @throws SipException if the SIP service fails to create a session for the
551-
* call
556+
* call or VOIP API is not supported by the device
557+
* @see SipManager#isVoipSupported
552558
*/
553559
public void makeCall(SipProfile peerProfile, SipSession sipSession,
554560
int timeout) throws SipException {
561+
if (!SipManager.isVoipSupported(mContext)) {
562+
throw new SipException("VOIP API is not supported");
563+
}
564+
555565
synchronized (this) {
556566
mSipSession = sipSession;
557567
try {
@@ -595,6 +605,9 @@ public void endCall() throws SipException {
595605
public void holdCall(int timeout) throws SipException {
596606
synchronized (this) {
597607
if (mHold) return;
608+
if (mSipSession == null) {
609+
throw new SipException("Not in a call to hold call");
610+
}
598611
mSipSession.changeCall(createHoldOffer().encode(), timeout);
599612
mHold = true;
600613
setAudioGroupMode();
@@ -614,6 +627,9 @@ public void holdCall(int timeout) throws SipException {
614627
*/
615628
public void answerCall(int timeout) throws SipException {
616629
synchronized (this) {
630+
if (mSipSession == null) {
631+
throw new SipException("No call to answer");
632+
}
617633
try {
618634
mAudioStream = new AudioStream(InetAddress.getByName(
619635
getLocalIp()));

voip/java/android/net/sip/SipManager.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public static boolean isApiSupported(Context context) {
133133
}
134134

135135
/**
136-
* Returns true if the system supports SIP-based VoIP.
136+
* Returns true if the system supports SIP-based VOIP API.
137137
*/
138138
public static boolean isVoipSupported(Context context) {
139139
return context.getPackageManager().hasSystemFeature(
@@ -305,12 +305,17 @@ public boolean isRegistered(String localProfileUri) throws SipException {
305305
* @param timeout the timeout value in seconds. Default value (defined by
306306
* SIP protocol) is used if {@code timeout} is zero or negative.
307307
* @return a {@link SipAudioCall} object
308-
* @throws SipException if calling the SIP service results in an error
308+
* @throws SipException if calling the SIP service results in an error or
309+
* VOIP API is not supported by the device
309310
* @see SipAudioCall.Listener#onError
311+
* @see #isVoipSupported
310312
*/
311313
public SipAudioCall makeAudioCall(SipProfile localProfile,
312314
SipProfile peerProfile, SipAudioCall.Listener listener, int timeout)
313315
throws SipException {
316+
if (!isVoipSupported(mContext)) {
317+
throw new SipException("VOIP API is not supported");
318+
}
314319
SipAudioCall call = new SipAudioCall(mContext, localProfile);
315320
call.setListener(listener);
316321
SipSession s = createSipSession(localProfile, null);
@@ -332,12 +337,17 @@ public SipAudioCall makeAudioCall(SipProfile localProfile,
332337
* @param timeout the timeout value in seconds. Default value (defined by
333338
* SIP protocol) is used if {@code timeout} is zero or negative.
334339
* @return a {@link SipAudioCall} object
335-
* @throws SipException if calling the SIP service results in an error
340+
* @throws SipException if calling the SIP service results in an error or
341+
* VOIP API is not supported by the device
336342
* @see SipAudioCall.Listener#onError
343+
* @see #isVoipSupported
337344
*/
338345
public SipAudioCall makeAudioCall(String localProfileUri,
339346
String peerProfileUri, SipAudioCall.Listener listener, int timeout)
340347
throws SipException {
348+
if (!isVoipSupported(mContext)) {
349+
throw new SipException("VOIP API is not supported");
350+
}
341351
try {
342352
return makeAudioCall(
343353
new SipProfile.Builder(localProfileUri).build(),

0 commit comments

Comments
 (0)