IMS call merge call-back changes.
[android/platform/frameworks/opt/net/ims.git] / src / java / com / android / ims / ImsCall.java
index 1879dc4..778679a 100644 (file)
@@ -644,6 +644,15 @@ public class ImsCall implements ICall {
     }
 
     /**
+     * Determines if the call is a multiparty call.
+     *
+     * @return {@code True} if the call is a multiparty call.
+     */
+    public boolean isMultiparty() {
+        return mSession.isMultiparty();
+    }
+
+    /**
      * Sets the listener to listen to the IMS call events.
      * The method calls {@link #setListener setListener(listener, false)}.
      *
@@ -939,6 +948,20 @@ public class ImsCall implements ICall {
             log("hold :: session=" + mSession);
         }
 
+        // perform operation on owner before doing any local checks: local
+        // call may not have its status updated
+        synchronized (mLockObj) {
+            CallGroup callGroup = mCallGroup;
+            if (callGroup != null && !callGroup.isOwner(ImsCall.this)) {
+                log("hold owner of the call group");
+                ImsCall owner = (ImsCall) callGroup.getOwner();
+                if (owner != null) {
+                    owner.hold();
+                    return;
+                }
+            }
+        }
+
         if (isOnHold()) {
             if (DBG) {
                 log("hold :: call is already on hold");
@@ -977,6 +1000,20 @@ public class ImsCall implements ICall {
             log("resume :: session=" + mSession);
         }
 
+        // perform operation on owner before doing any local checks: local
+        // call may not have its status updated
+        synchronized (mLockObj) {
+            CallGroup callGroup = mCallGroup;
+            if (callGroup != null && !callGroup.isOwner(ImsCall.this)) {
+                log("resume owner of the call group");
+                ImsCall owner = (ImsCall) callGroup.getOwner();
+                if (owner != null) {
+                    owner.resume();
+                    return;
+                }
+            }
+        }
+
         if (!isOnHold()) {
             if (DBG) {
                 log("resume :: call is in conversation");
@@ -1319,7 +1356,7 @@ public class ImsCall implements ICall {
         mCallGroup = null;
     }
 
-    private CallGroup getCallGroup() {
+    public CallGroup getCallGroup() {
         synchronized(mLockObj) {
             return mCallGroup;
         }
@@ -1435,10 +1472,10 @@ public class ImsCall implements ICall {
         ImsCall.Listener listener;
 
         if (mCallGroup.isOwner(ImsCall.this)) {
-            loge("Group Owner! Size of referrers list = " + mCallGroup.getReferrers().size());
+            log("Group Owner! Size of referrers list = " + mCallGroup.getReferrers().size());
             while (mCallGroup.hasReferrer()) {
                 ImsCall call = (ImsCall) mCallGroup.getReferrers().get(0);
-                loge("onCallTerminated to be called for the call:: " + call);
+                log("onCallTerminated to be called for the call:: " + call);
 
                 if (call == null) {
                     continue;
@@ -1471,6 +1508,42 @@ public class ImsCall implements ICall {
         }
     }
 
+    private void notifyConferenceStateUpdatedThroughGroupOwner(int update) {
+        ImsCall.Listener listener;
+
+        if (mCallGroup.isOwner(ImsCall.this)) {
+            log("Group Owner! Size of referrers list = " + mCallGroup.getReferrers().size());
+            for (ICall icall : mCallGroup.getReferrers()) {
+                ImsCall call = (ImsCall) icall;
+                log("notifyConferenceStateUpdatedThroughGroupOwner to be called for the call:: " + call);
+
+                if (call == null) {
+                    continue;
+                }
+
+                listener = call.mListener;
+
+                if (listener != null) {
+                    try {
+                        switch (update) {
+                            case UPDATE_HOLD:
+                                listener.onCallHeld(call);
+                                break;
+                            case UPDATE_RESUME:
+                                listener.onCallResumed(call);
+                                break;
+                            default:
+                                loge("notifyConferenceStateUpdatedThroughGroupOwner :: not handled update "
+                                        + update);
+                        }
+                    } catch (Throwable t) {
+                        loge("notifyConferenceStateUpdatedThroughGroupOwner :: ", t);
+                    }
+                }
+            }
+        }
+    }
+
     private void notifyConferenceStateUpdated(ImsConferenceState state) {
         Set<Entry<String, Bundle>> paticipants = state.mParticipants.entrySet();
 
@@ -1683,6 +1756,10 @@ public class ImsCall implements ICall {
                     loge("callSessionHeld :: ", t);
                 }
             }
+
+            if (mCallGroup != null) {
+                notifyConferenceStateUpdatedThroughGroupOwner(UPDATE_HOLD);
+            }
         }
 
         @Override
@@ -1764,6 +1841,10 @@ public class ImsCall implements ICall {
                     loge("callSessionResumed :: ", t);
                 }
             }
+
+            if (mCallGroup != null) {
+                notifyConferenceStateUpdatedThroughGroupOwner(UPDATE_RESUME);
+            }
         }
 
         @Override
@@ -1815,10 +1896,10 @@ public class ImsCall implements ICall {
         }
 
         @Override
-        public void callSessionMerged(ImsCallSession session,
+        public void callSessionMergeStarted(ImsCallSession session,
                 ImsCallSession newSession, ImsCallProfile profile) {
             if (DBG) {
-                log("callSessionMerged :: session=" + session
+                log("callSessionMergeStarted :: session=" + session
                         + ", newSession=" + newSession + ", profile=" + profile);
             }
 
@@ -1843,12 +1924,21 @@ public class ImsCall implements ICall {
                 try {
                     listener.onCallMerged(ImsCall.this, newCall);
                 } catch (Throwable t) {
-                    loge("callSessionMerged :: ", t);
+                    loge("callSessionMergeStarted :: ", t);
                 }
             }
         }
 
         @Override
+        public void callSessionMergeComplete(ImsCallSession session) {
+            if (DBG) {
+                log("callSessionMergeComplete :: session=" + session);
+            }
+
+            // TODO handle successful completion of call session merge.
+        }
+
+        @Override
         public void callSessionMergeFailed(ImsCallSession session,
                 ImsReasonInfo reasonInfo) {
             if (DBG) {