am 1862af57
: Merge "SipService: supply PendingIntent when open a profile." into gingerbread
Merge commit '1862af57b2c5ca5387b12974e8ef661651edb97d' into gingerbread-plus-aosp * commit '1862af57b2c5ca5387b12974e8ef661651edb97d': SipService: supply PendingIntent when open a profile.
This commit is contained in:
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package android.net.sip;
|
package android.net.sip;
|
||||||
|
|
||||||
|
import android.app.PendingIntent;
|
||||||
import android.net.sip.ISipSession;
|
import android.net.sip.ISipSession;
|
||||||
import android.net.sip.ISipSessionListener;
|
import android.net.sip.ISipSessionListener;
|
||||||
import android.net.sip.SipProfile;
|
import android.net.sip.SipProfile;
|
||||||
@ -26,7 +27,7 @@ import android.net.sip.SipProfile;
|
|||||||
interface ISipService {
|
interface ISipService {
|
||||||
void open(in SipProfile localProfile);
|
void open(in SipProfile localProfile);
|
||||||
void open3(in SipProfile localProfile,
|
void open3(in SipProfile localProfile,
|
||||||
String incomingCallBroadcastAction,
|
in PendingIntent incomingCallPendingIntent,
|
||||||
in ISipSessionListener listener);
|
in ISipSessionListener listener);
|
||||||
void close(in String localProfileUri);
|
void close(in String localProfileUri);
|
||||||
boolean isOpened(String localProfileUri);
|
boolean isOpened(String localProfileUri);
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package android.net.sip;
|
package android.net.sip;
|
||||||
|
|
||||||
|
import android.app.PendingIntent;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
@ -34,7 +35,7 @@ import java.text.ParseException;
|
|||||||
* <li>open a {@link SipProfile} to get ready for making outbound calls or have
|
* <li>open a {@link SipProfile} to get ready for making outbound calls or have
|
||||||
* the background SIP service listen to incoming calls and broadcast them
|
* the background SIP service listen to incoming calls and broadcast them
|
||||||
* with registered command string. See
|
* with registered command string. See
|
||||||
* {@link #open(SipProfile, String, SipRegistrationListener)},
|
* {@link #open(SipProfile, PendingIntent, SipRegistrationListener)},
|
||||||
* {@link #open(SipProfile)}, {@link #close}, {@link #isOpened} and
|
* {@link #open(SipProfile)}, {@link #close}, {@link #isOpened} and
|
||||||
* {@link #isRegistered}. It also facilitates handling of the incoming call
|
* {@link #isRegistered}. It also facilitates handling of the incoming call
|
||||||
* broadcast intent. See
|
* broadcast intent. See
|
||||||
@ -50,6 +51,19 @@ import java.text.ParseException;
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public class SipManager {
|
public class SipManager {
|
||||||
|
/**
|
||||||
|
* The result code to be sent back with the incoming call
|
||||||
|
* {@link PendingIntent}.
|
||||||
|
* @see #open(SipProfile, PendingIntent, SipRegistrationListener)
|
||||||
|
*/
|
||||||
|
public static final int INCOMING_CALL_RESULT_CODE = 101;
|
||||||
|
|
||||||
|
/** Part of the incoming call intent. */
|
||||||
|
public static final String EXTRA_CALL_ID = "android:sipCallID";
|
||||||
|
|
||||||
|
/** Part of the incoming call intent. */
|
||||||
|
public static final String EXTRA_OFFER_SD = "android:sipOfferSD";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action string for the incoming call intent for the Phone app.
|
* Action string for the incoming call intent for the Phone app.
|
||||||
* Internal use only.
|
* Internal use only.
|
||||||
@ -78,12 +92,6 @@ public class SipManager {
|
|||||||
*/
|
*/
|
||||||
public static final String EXTRA_LOCAL_URI = "android:localSipUri";
|
public static final String EXTRA_LOCAL_URI = "android:localSipUri";
|
||||||
|
|
||||||
/** Part of the incoming call intent. */
|
|
||||||
public static final String EXTRA_CALL_ID = "android:sipCallID";
|
|
||||||
|
|
||||||
/** Part of the incoming call intent. */
|
|
||||||
public static final String EXTRA_OFFER_SD = "android:sipOfferSD";
|
|
||||||
|
|
||||||
private static final String TAG = "SipManager";
|
private static final String TAG = "SipManager";
|
||||||
|
|
||||||
private ISipService mSipService;
|
private ISipService mSipService;
|
||||||
@ -142,7 +150,8 @@ public class SipManager {
|
|||||||
/**
|
/**
|
||||||
* Opens the profile for making calls. The caller may make subsequent calls
|
* Opens the profile for making calls. The caller may make subsequent calls
|
||||||
* through {@link #makeAudioCall}. If one also wants to receive calls on the
|
* through {@link #makeAudioCall}. If one also wants to receive calls on the
|
||||||
* profile, use {@link #open(SipProfile, String, SipRegistrationListener)}
|
* profile, use
|
||||||
|
* {@link #open(SipProfile, PendingIntent, SipRegistrationListener)}
|
||||||
* instead.
|
* instead.
|
||||||
*
|
*
|
||||||
* @param localProfile the SIP profile to make calls from
|
* @param localProfile the SIP profile to make calls from
|
||||||
@ -165,17 +174,29 @@ public class SipManager {
|
|||||||
* in order to receive calls from the provider.
|
* in order to receive calls from the provider.
|
||||||
*
|
*
|
||||||
* @param localProfile the SIP profile to receive incoming calls for
|
* @param localProfile the SIP profile to receive incoming calls for
|
||||||
* @param incomingCallBroadcastAction the action to be broadcast when an
|
* @param incomingCallPendingIntent When an incoming call is received, the
|
||||||
* incoming call is received
|
* SIP service will call
|
||||||
|
* {@link PendingIntent#send(Context, int, Intent)} to send back the
|
||||||
|
* intent to the caller with {@link #INCOMING_CALL_RESULT_CODE} as the
|
||||||
|
* result code and the intent to fill in the call ID and session
|
||||||
|
* description information. It cannot be null.
|
||||||
* @param listener to listen to registration events; can be null
|
* @param listener to listen to registration events; can be null
|
||||||
|
* @see #getCallId
|
||||||
|
* @see #getOfferSessionDescription
|
||||||
|
* @see #takeAudioCall
|
||||||
|
* @throws NullPointerException if {@code incomingCallPendingIntent} is null
|
||||||
* @throws SipException if the profile contains incorrect settings or
|
* @throws SipException if the profile contains incorrect settings or
|
||||||
* calling the SIP service results in an error
|
* calling the SIP service results in an error
|
||||||
*/
|
*/
|
||||||
public void open(SipProfile localProfile,
|
public void open(SipProfile localProfile,
|
||||||
String incomingCallBroadcastAction,
|
PendingIntent incomingCallPendingIntent,
|
||||||
SipRegistrationListener listener) throws SipException {
|
SipRegistrationListener listener) throws SipException {
|
||||||
|
if (incomingCallPendingIntent == null) {
|
||||||
|
throw new NullPointerException(
|
||||||
|
"incomingCallPendingIntent cannot be null");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
mSipService.open3(localProfile, incomingCallBroadcastAction,
|
mSipService.open3(localProfile, incomingCallPendingIntent,
|
||||||
createRelay(listener, localProfile.getUriString()));
|
createRelay(listener, localProfile.getUriString()));
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw new SipException("open()", e);
|
throw new SipException("open()", e);
|
||||||
@ -184,7 +205,8 @@ public class SipManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the listener to listen to registration events. No effect if the
|
* Sets the listener to listen to registration events. No effect if the
|
||||||
* profile has not been opened to receive calls (see {@link #open}).
|
* profile has not been opened to receive calls (see
|
||||||
|
* {@link #open(SipProfile, PendingIntent, SipRegistrationListener)}).
|
||||||
*
|
*
|
||||||
* @param localProfileUri the URI of the profile
|
* @param localProfileUri the URI of the profile
|
||||||
* @param listener to listen to registration events; can be null
|
* @param listener to listen to registration events; can be null
|
||||||
@ -282,9 +304,9 @@ public class SipManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link SipAudioCall} to make a call. To use this method, one
|
* Creates a {@link SipAudioCall} to make an audio call. The attempt will be
|
||||||
* must call {@link #open(SipProfile)} first. The attempt will be timed out
|
* timed out if the call is not established within {@code timeout} seconds
|
||||||
* if the call is not established within {@code timeout} seconds and
|
* and
|
||||||
* {@code SipAudioCall.Listener.onError(SipAudioCall, SipErrorCode.TIME_OUT, String)}
|
* {@code SipAudioCall.Listener.onError(SipAudioCall, SipErrorCode.TIME_OUT, String)}
|
||||||
* will be called.
|
* will be called.
|
||||||
*
|
*
|
||||||
@ -416,9 +438,11 @@ public class SipManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Manually registers the profile to the corresponding SIP provider for
|
* Manually registers the profile to the corresponding SIP provider for
|
||||||
* receiving calls. {@link #open(SipProfile, String, SipRegistrationListener)}
|
* receiving calls.
|
||||||
* is still needed to be called at least once in order for the SIP service
|
* {@link #open(SipProfile, PendingIntent, SipRegistrationListener)} is
|
||||||
* to broadcast an intent when an incoming call is received.
|
* still needed to be called at least once in order for the SIP service to
|
||||||
|
* notify the caller with the {@code PendingIntent} when an incoming call is
|
||||||
|
* received.
|
||||||
*
|
*
|
||||||
* @param localProfile the SIP profile to register with
|
* @param localProfile the SIP profile to register with
|
||||||
* @param expiryTime registration expiration time (in seconds)
|
* @param expiryTime registration expiration time (in seconds)
|
||||||
|
@ -134,14 +134,6 @@ public final class SipService extends ISipService.Stub {
|
|||||||
|
|
||||||
public void open(SipProfile localProfile) {
|
public void open(SipProfile localProfile) {
|
||||||
localProfile.setCallingUid(Binder.getCallingUid());
|
localProfile.setCallingUid(Binder.getCallingUid());
|
||||||
if (localProfile.getAutoRegistration() && isCallerRadio()) {
|
|
||||||
openToReceiveCalls(localProfile);
|
|
||||||
} else {
|
|
||||||
openToMakeCalls(localProfile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void openToMakeCalls(SipProfile localProfile) {
|
|
||||||
try {
|
try {
|
||||||
createGroup(localProfile);
|
createGroup(localProfile);
|
||||||
} catch (SipException e) {
|
} catch (SipException e) {
|
||||||
@ -150,28 +142,20 @@ public final class SipService extends ISipService.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openToReceiveCalls(SipProfile localProfile) {
|
|
||||||
open3(localProfile, SipManager.ACTION_SIP_INCOMING_CALL, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void open3(SipProfile localProfile,
|
public synchronized void open3(SipProfile localProfile,
|
||||||
String incomingCallBroadcastAction, ISipSessionListener listener) {
|
PendingIntent incomingCallPendingIntent,
|
||||||
|
ISipSessionListener listener) {
|
||||||
localProfile.setCallingUid(Binder.getCallingUid());
|
localProfile.setCallingUid(Binder.getCallingUid());
|
||||||
if (TextUtils.isEmpty(incomingCallBroadcastAction)) {
|
if (incomingCallPendingIntent == null) {
|
||||||
Log.w(TAG, "empty broadcast action for incoming call");
|
Log.w(TAG, "incomingCallPendingIntent cannot be null; "
|
||||||
return;
|
+ "the profile is not opened");
|
||||||
}
|
|
||||||
if (incomingCallBroadcastAction.equals(
|
|
||||||
SipManager.ACTION_SIP_INCOMING_CALL) && !isCallerRadio()) {
|
|
||||||
Log.w(TAG, "failed to open the profile; "
|
|
||||||
+ "the action string is reserved");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (DEBUG) Log.d(TAG, "open3: " + localProfile.getUriString() + ": "
|
if (DEBUG) Log.d(TAG, "open3: " + localProfile.getUriString() + ": "
|
||||||
+ incomingCallBroadcastAction + ": " + listener);
|
+ incomingCallPendingIntent + ": " + listener);
|
||||||
try {
|
try {
|
||||||
SipSessionGroupExt group = createGroup(localProfile,
|
SipSessionGroupExt group = createGroup(localProfile,
|
||||||
incomingCallBroadcastAction, listener);
|
incomingCallPendingIntent, listener);
|
||||||
if (localProfile.getAutoRegistration()) {
|
if (localProfile.getAutoRegistration()) {
|
||||||
group.openToReceiveCalls();
|
group.openToReceiveCalls();
|
||||||
if (isWifiOn()) grabWifiLock();
|
if (isWifiOn()) grabWifiLock();
|
||||||
@ -287,20 +271,19 @@ public final class SipService extends ISipService.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private SipSessionGroupExt createGroup(SipProfile localProfile,
|
private SipSessionGroupExt createGroup(SipProfile localProfile,
|
||||||
String incomingCallBroadcastAction, ISipSessionListener listener)
|
PendingIntent incomingCallPendingIntent,
|
||||||
throws SipException {
|
ISipSessionListener listener) throws SipException {
|
||||||
String key = localProfile.getUriString();
|
String key = localProfile.getUriString();
|
||||||
SipSessionGroupExt group = mSipGroups.get(key);
|
SipSessionGroupExt group = mSipGroups.get(key);
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
if (!isCallerCreator(group)) {
|
if (!isCallerCreator(group)) {
|
||||||
throw new SipException("only creator can access the profile");
|
throw new SipException("only creator can access the profile");
|
||||||
}
|
}
|
||||||
group.setIncomingCallBroadcastAction(
|
group.setIncomingCallPendingIntent(incomingCallPendingIntent);
|
||||||
incomingCallBroadcastAction);
|
|
||||||
group.setListener(listener);
|
group.setListener(listener);
|
||||||
} else {
|
} else {
|
||||||
group = new SipSessionGroupExt(localProfile,
|
group = new SipSessionGroupExt(localProfile,
|
||||||
incomingCallBroadcastAction, listener);
|
incomingCallPendingIntent, listener);
|
||||||
mSipGroups.put(key, group);
|
mSipGroups.put(key, group);
|
||||||
notifyProfileAdded(localProfile);
|
notifyProfileAdded(localProfile);
|
||||||
}
|
}
|
||||||
@ -405,19 +388,19 @@ public final class SipService extends ISipService.Stub {
|
|||||||
|
|
||||||
private class SipSessionGroupExt extends SipSessionAdapter {
|
private class SipSessionGroupExt extends SipSessionAdapter {
|
||||||
private SipSessionGroup mSipGroup;
|
private SipSessionGroup mSipGroup;
|
||||||
private String mIncomingCallBroadcastAction;
|
private PendingIntent mIncomingCallPendingIntent;
|
||||||
private boolean mOpened;
|
private boolean mOpened;
|
||||||
|
|
||||||
private AutoRegistrationProcess mAutoRegistration =
|
private AutoRegistrationProcess mAutoRegistration =
|
||||||
new AutoRegistrationProcess();
|
new AutoRegistrationProcess();
|
||||||
|
|
||||||
public SipSessionGroupExt(SipProfile localProfile,
|
public SipSessionGroupExt(SipProfile localProfile,
|
||||||
String incomingCallBroadcastAction,
|
PendingIntent incomingCallPendingIntent,
|
||||||
ISipSessionListener listener) throws SipException {
|
ISipSessionListener listener) throws SipException {
|
||||||
String password = localProfile.getPassword();
|
String password = localProfile.getPassword();
|
||||||
SipProfile p = duplicate(localProfile);
|
SipProfile p = duplicate(localProfile);
|
||||||
mSipGroup = createSipSessionGroup(mLocalIp, p, password);
|
mSipGroup = createSipSessionGroup(mLocalIp, p, password);
|
||||||
mIncomingCallBroadcastAction = incomingCallBroadcastAction;
|
mIncomingCallPendingIntent = incomingCallPendingIntent;
|
||||||
mAutoRegistration.setListener(listener);
|
mAutoRegistration.setListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -458,8 +441,8 @@ public final class SipService extends ISipService.Stub {
|
|||||||
mAutoRegistration.setListener(listener);
|
mAutoRegistration.setListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIncomingCallBroadcastAction(String action) {
|
public void setIncomingCallPendingIntent(PendingIntent pIntent) {
|
||||||
mIncomingCallBroadcastAction = action;
|
mIncomingCallPendingIntent = pIntent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void openToReceiveCalls() throws SipException {
|
public void openToReceiveCalls() throws SipException {
|
||||||
@ -469,7 +452,7 @@ public final class SipService extends ISipService.Stub {
|
|||||||
mAutoRegistration.start(mSipGroup);
|
mAutoRegistration.start(mSipGroup);
|
||||||
}
|
}
|
||||||
if (DEBUG) Log.d(TAG, " openToReceiveCalls: " + getUri() + ": "
|
if (DEBUG) Log.d(TAG, " openToReceiveCalls: " + getUri() + ": "
|
||||||
+ mIncomingCallBroadcastAction);
|
+ mIncomingCallPendingIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onConnectivityChanged(boolean connected)
|
public void onConnectivityChanged(boolean connected)
|
||||||
@ -481,7 +464,7 @@ public final class SipService extends ISipService.Stub {
|
|||||||
} else {
|
} else {
|
||||||
// close mSipGroup but remember mOpened
|
// close mSipGroup but remember mOpened
|
||||||
if (DEBUG) Log.d(TAG, " close auto reg temporarily: "
|
if (DEBUG) Log.d(TAG, " close auto reg temporarily: "
|
||||||
+ getUri() + ": " + mIncomingCallBroadcastAction);
|
+ getUri() + ": " + mIncomingCallPendingIntent);
|
||||||
mSipGroup.close();
|
mSipGroup.close();
|
||||||
mAutoRegistration.stop();
|
mAutoRegistration.stop();
|
||||||
}
|
}
|
||||||
@ -508,7 +491,7 @@ public final class SipService extends ISipService.Stub {
|
|||||||
mSipGroup.close();
|
mSipGroup.close();
|
||||||
mAutoRegistration.stop();
|
mAutoRegistration.stop();
|
||||||
if (DEBUG) Log.d(TAG, " close: " + getUri() + ": "
|
if (DEBUG) Log.d(TAG, " close: " + getUri() + ": "
|
||||||
+ mIncomingCallBroadcastAction);
|
+ mIncomingCallPendingIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ISipSession createSession(ISipSessionListener listener) {
|
public ISipSession createSession(ISipSessionListener listener) {
|
||||||
@ -516,8 +499,10 @@ public final class SipService extends ISipService.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRinging(ISipSession session, SipProfile caller,
|
public void onRinging(ISipSession s, SipProfile caller,
|
||||||
String sessionDescription) {
|
String sessionDescription) {
|
||||||
|
SipSessionGroup.SipSessionImpl session =
|
||||||
|
(SipSessionGroup.SipSessionImpl) s;
|
||||||
synchronized (SipService.this) {
|
synchronized (SipService.this) {
|
||||||
try {
|
try {
|
||||||
if (!isRegistered()) {
|
if (!isRegistered()) {
|
||||||
@ -528,15 +513,15 @@ public final class SipService extends ISipService.Stub {
|
|||||||
// send out incoming call broadcast
|
// send out incoming call broadcast
|
||||||
addPendingSession(session);
|
addPendingSession(session);
|
||||||
Intent intent = SipManager.createIncomingCallBroadcast(
|
Intent intent = SipManager.createIncomingCallBroadcast(
|
||||||
session.getCallId(), sessionDescription)
|
session.getCallId(), sessionDescription);
|
||||||
.setAction(mIncomingCallBroadcastAction);
|
|
||||||
if (DEBUG) Log.d(TAG, " ringing~~ " + getUri() + ": "
|
if (DEBUG) Log.d(TAG, " ringing~~ " + getUri() + ": "
|
||||||
+ caller.getUri() + ": " + session.getCallId()
|
+ caller.getUri() + ": " + session.getCallId()
|
||||||
+ " " + mIncomingCallBroadcastAction);
|
+ " " + mIncomingCallPendingIntent);
|
||||||
mContext.sendBroadcast(intent);
|
mIncomingCallPendingIntent.send(mContext,
|
||||||
} catch (RemoteException e) {
|
SipManager.INCOMING_CALL_RESULT_CODE, intent);
|
||||||
// should never happen with a local call
|
} catch (PendingIntent.CanceledException e) {
|
||||||
Log.e(TAG, "processCall()", e);
|
Log.w(TAG, "pendingIntent is canceled, drop incoming call");
|
||||||
|
session.endCall();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user