summaryrefslogtreecommitdiffstats
path: root/rcs/rcsservice/src/com/android/service/ims/StackListener.java
blob: 7edf080e2e5beeca5af4f440896b2bda1d226c33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
/*
 * Copyright (c) 2015, Motorola Mobility LLC
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     - Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     - Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     - Neither the name of Motorola Mobility nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MOTOROLA MOBILITY LLC BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 */

package com.android.service.ims;

import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.Parcel;
import android.os.RemoteException;
import android.telephony.ims.RcsContactUceCapability;
import android.text.TextUtils;
import android.util.Log;

import com.android.ims.RcsManager;
import com.android.ims.RcsPresenceInfo;
import com.android.ims.internal.Logger;
import com.android.ims.internal.uce.common.StatusCode;
import com.android.ims.internal.uce.presence.IPresenceListener;
import com.android.ims.internal.uce.presence.PresCmdId;
import com.android.ims.internal.uce.presence.PresCmdStatus;
import com.android.ims.internal.uce.presence.PresPublishTriggerType;
import com.android.ims.internal.uce.presence.PresResInfo;
import com.android.ims.internal.uce.presence.PresRlmiInfo;
import com.android.ims.internal.uce.presence.PresSipResponse;
import com.android.ims.internal.uce.presence.PresSubscriptionState;
import com.android.ims.internal.uce.presence.PresTupleInfo;
import com.android.service.ims.presence.PresencePublication;
import com.android.service.ims.presence.PresenceSubscriber;

import java.util.ArrayList;

public class StackListener extends Handler{
    /*
     * The logger
     */
    private Logger logger = Logger.getLogger(this.getClass().getName());

    Context mContext;
    private PresencePublication mPresencePublication = null;
    private PresenceSubscriber mPresenceSubscriber = null;

    // RCS stack notify the AP to publish the presence.
    private static final short PRESENCE_IMS_UNSOL_PUBLISH_TRIGGER = 1;
    // PUBLISH CMD status changed
    private static final short PRESENCE_IMS_UNSOL_PUBLISH_CMDSTATUS = 2;
    // Received the SIP response for publish
    private static final short PRESENCE_IMS_UNSOL_PUBLISH_SIPRESPONSE = 3;
    // Received the presence for single contact
    private static final short PRESENCE_IMS_UNSOL_NOTIFY_UPDATE = 4;
    // Received the presence for contacts.
    private static final short PRESENCE_IMS_UNSOL_NOTIFY_LIST_UPDATE = 5;
    // Received the CMD status for capability/availability request
    private static final short PRESENCE_IMS_UNSOL_NOTIFY_UPDATE_CMDSTATUS = 6;
    // Received the SIP response for capability/availability request
    private static final short PRESENCE_IMS_UNSOL_NOTIFY_UPDATE_SIPRESPONSE = 7;

    private final Object mSyncObj = new Object();

    public StackListener(Context context, Looper looper) {
        super(looper);
        mContext = context;
    }

    public void setPresencePublication(PresencePublication presencePublication) {
        mPresencePublication = presencePublication;
    }

    public void setPresenceSubscriber(PresenceSubscriber presenceSubscriber){
        mPresenceSubscriber = presenceSubscriber;
    }

    @Override
    public void handleMessage(Message msg) {
        super.handleMessage(msg);

        logger.debug( "Thread=" + Thread.currentThread().getName() + " received "
                + msg);
        if(msg == null){
            logger.error("msg=null");
            return;
        }

        switch (msg.what) {
            // RCS stack notify the AP to publish the presence.
            case PRESENCE_IMS_UNSOL_PUBLISH_TRIGGER:
            {
                PresPublishTriggerType val = (PresPublishTriggerType) msg.obj;
                if(mPresencePublication == null || val == null){
                    logger.error("mPresencePublication=" + mPresencePublication + " val=" + val);
                    return;
                }

                mPresencePublication.onStackPublishRequested(
                        convertToStackPublishTriggerType(val.getPublishTrigeerType()));
                break;
            }

            // RCS stack tell AP that the CMD status changed.
            case PRESENCE_IMS_UNSOL_PUBLISH_CMDSTATUS:
            {
                PresCmdStatus pCmdStatus = (PresCmdStatus) msg.obj;
                if(mPresencePublication == null || pCmdStatus == null) {
                    logger.error("mPresencePublication=" + mPresencePublication +
                            " pCmdStatus=" + pCmdStatus);
                    return;
                }

                int commandResult = RcsUtils.statusCodeToResultCode(
                        pCmdStatus.getStatus().getStatusCode());
                mPresencePublication.onCommandStatusUpdated(pCmdStatus.getUserData(),
                        pCmdStatus.getRequestId(), commandResult);
            }
                break;

            // RCS stack tells AP that the CMD status changed.
            case PRESENCE_IMS_UNSOL_NOTIFY_UPDATE_CMDSTATUS:
            {
                PresCmdStatus pCmdStatus = (PresCmdStatus) msg.obj;
                if(mPresenceSubscriber == null || pCmdStatus == null){
                    logger.error("mPresenceSubcriber=" + mPresenceSubscriber +
                            " pCmdStatus=" + pCmdStatus);
                    return;
                }
                int commandResult = RcsUtils.statusCodeToResultCode(
                        pCmdStatus.getStatus().getStatusCode());
                mPresenceSubscriber.onCommandStatusUpdated(pCmdStatus.getUserData(),
                        pCmdStatus.getRequestId(), commandResult);
                break;
            }

            // RCS stack tells AP that the SIP response has been received.
            case PRESENCE_IMS_UNSOL_PUBLISH_SIPRESPONSE:
            {
                PresSipResponse pSipResponse =  (PresSipResponse) msg.obj;
                if(mPresencePublication == null || pSipResponse == null) {
                    logger.error("mPresencePublication=" + mPresencePublication +
                            "pSipResponse=" +pSipResponse);
                    return;
                }

                mPresencePublication.onSipResponse(pSipResponse.getRequestId(),
                        pSipResponse.getSipResponseCode(), pSipResponse.getReasonPhrase());
                break;
            }

            // RCS stack tells AP that the SIP response has been received.
            case PRESENCE_IMS_UNSOL_NOTIFY_UPDATE_SIPRESPONSE:
            {
                PresSipResponse pSipResponse =  (PresSipResponse) msg.obj;
                if(mPresenceSubscriber == null || pSipResponse == null){
                    logger.error("mPresenceSubscriber=" + mPresenceSubscriber +
                            " pSipResponse=" + pSipResponse);
                    return;
                }

                mPresenceSubscriber.onSipResponse(pSipResponse.getRequestId(),
                        pSipResponse.getSipResponseCode(), pSipResponse.getReasonPhrase());
                break;
            }

            // RCS stack tells AP that the presence data has been received.
            case PRESENCE_IMS_UNSOL_NOTIFY_UPDATE:
            {
                NotifyData notifyData = (NotifyData) msg.obj;
                if(mPresenceSubscriber == null || notifyData == null){
                    logger.error("mPresenceSubscriber=" + mPresenceSubscriber +
                            " notifyData=" + notifyData);
                    return;
                }
                RcsPresenceInfo rcsPresenceInfo = PresenceInfoParser.getPresenceInfoFromTuple(
                        notifyData.getUri(), notifyData.getTupleInfo());
                if(rcsPresenceInfo == null || TextUtils.isEmpty(
                        rcsPresenceInfo.getContactNumber())){
                    logger.error("rcsPresenceInfo is null or " +
                            "TextUtils.isEmpty(rcsPresenceInfo.getContactNumber()");
                    return;
                }
                mPresenceSubscriber.updatePresence(
                        PresenceInfoParser.getUceCapability(rcsPresenceInfo));
                break;
            }

            case PRESENCE_IMS_UNSOL_NOTIFY_LIST_UPDATE:
            {
                NotifyListData notifyListData = (NotifyListData) msg.obj;
                logger.debug("Received PRESENCE_IMS_UNSOL_NOTIFY_LIST_UPDATE");
                if(mPresenceSubscriber==null || notifyListData == null){
                    logger.error("mPresenceSubscriber=" + mPresenceSubscriber +
                            " notifyListData=" + notifyListData);
                    return;
                }

                RcsPresenceInfo[] rcsPresenceInfos = PresenceInfoParser.
                        getPresenceInfosFromPresenceRes(notifyListData.getRlmiInfo(),
                                notifyListData.getResInfo());
                if(rcsPresenceInfos == null){
                    logger.error("updatePresences: rcsPresenceInfos == null");
                    return;
                }

                PresRlmiInfo info = notifyListData.getRlmiInfo();
                boolean isTerminated = false;
                if (info.getPresSubscriptionState() != null) {
                    if (info.getPresSubscriptionState().getPresSubscriptionStateValue() ==
                            PresSubscriptionState.UCE_PRES_SUBSCRIPTION_STATE_TERMINATED) {
                        isTerminated = true;
                    }
                }

                ArrayList<RcsContactUceCapability> capabilities = new ArrayList<>();

                for (int i=0; i < rcsPresenceInfos.length; i++) {
                    if(rcsPresenceInfos[i] != null && TextUtils.isEmpty(
                            rcsPresenceInfos[i].getContactNumber())){
                        continue;
                    }
                    RcsContactUceCapability capability = PresenceInfoParser.getUceCapability(
                            rcsPresenceInfos[i]);
                    if(capability != null && (capability.getContactUri() != null)){
                        logger.debug("capability=" + capability);
                        capabilities.add(capability);
                    }
                }

                mPresenceSubscriber.updatePresences(info.getRequestId(), capabilities, isTerminated,
                        info.getSubscriptionTerminatedReason());
                break;
            }

            default:
                logger.debug("Unknown mesg " + msg.what + " recieved.");
        }
    }

    public class NotifyData{
        private String mUri;
        private PresTupleInfo[] mTupleInfo;

        NotifyData(){
            mUri = null;
            mTupleInfo = null;
        }

        NotifyData(String uri, PresTupleInfo[] pTupleInfo){
            mUri = uri;
            mTupleInfo = pTupleInfo;
        }

        public String getUri(){
            return mUri;
        }

        public PresTupleInfo[] getTupleInfo(){
            return mTupleInfo;
        }
    }

    public class NotifyListData{
        private PresRlmiInfo mRlmiInfo;
        private PresResInfo[] mResInfo;

        NotifyListData(){
            mRlmiInfo = null;
            mResInfo = null;
        }

        NotifyListData(PresRlmiInfo pRlmiInfo, PresResInfo[] pResInfo){
            mRlmiInfo = pRlmiInfo;
            mResInfo = pResInfo;
        }

        public PresRlmiInfo getRlmiInfo(){
            return mRlmiInfo;
        }

        public PresResInfo[] getResInfo(){
            return mResInfo;
        }
    }

    public IPresenceListener mPresenceListener = new IPresenceListener.Stub() {
        public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
               throws RemoteException{
            try{
                return super.onTransact(code, data, reply, flags);
            } catch (RemoteException e) {
                Log.w("ListenerHandler", "Unexpected remote exception", e);
                e.printStackTrace();
                throw e;
           }
        }

        public void getVersionCb(String pVersion) {
            logger.debug("pVersion=" + pVersion);
        }

        public void sipResponseReceived(PresSipResponse pSipResponse) throws RemoteException {
            synchronized(mSyncObj){
                if(pSipResponse == null){
                    logger.error("ISipResponseReceived pSipResponse=null");
                    return;
                }

                logger.debug("pSipResponse.getCmdId() "+
                        pSipResponse.getCmdId().getCmdId());
                logger.debug("getReasonPhrase() "+pSipResponse.getReasonPhrase());
                logger.debug("getsRequestID() "+pSipResponse.getRequestId());
                logger.debug("getsSipResponseCode() "+pSipResponse.getSipResponseCode());

                switch (pSipResponse.getCmdId().getCmdId()) {
                    case PresCmdId.UCE_PRES_CMD_PUBLISHMYCAP:
                    {
                        Message updateMesgSipPub = StackListener.this.obtainMessage(
                                PRESENCE_IMS_UNSOL_PUBLISH_SIPRESPONSE,
                                pSipResponse);
                        StackListener.this.sendMessage(updateMesgSipPub);
                        break;
                    }

                    case PresCmdId.UCE_PRES_CMD_GETCONTACTCAP:
                    case PresCmdId.UCE_PRES_CMD_GETCONTACTLISTCAP:
                    {
                        Message updateMesgSipPub = StackListener.this.obtainMessage(
                                PRESENCE_IMS_UNSOL_NOTIFY_UPDATE_SIPRESPONSE,
                                pSipResponse);
                        StackListener.this.sendMessage(updateMesgSipPub);

                        break;
                    }

                    case PresCmdId.UCE_PRES_CMD_SETNEWFEATURETAG:
                    {
                        logger.debug("UCE_PRES_CMD_SETNEWFEATURETAG, doesn't care it");
                        break;
                    }

                    default:
                        logger.debug("CMD ID for unknown value=" +
                                pSipResponse.getCmdId().getCmdId());
                }
            }
        }

        public void serviceUnAvailable(StatusCode statusCode) throws RemoteException {
            synchronized(mSyncObj){
                if(statusCode == null){
                    logger.error("statusCode=null");
                }else{
                    logger.debug("IServiceUnAvailable statusCode " +
                        statusCode.getStatusCode());
                }
                logger.debug("QPresListener_ServiceUnAvailable");

                RcsStackAdaptor rcsStackAdaptor = RcsStackAdaptor.getInstance(null);
                if (rcsStackAdaptor != null) {
                    rcsStackAdaptor.setImsEnableState(false);
                }

                Intent intent = new Intent(RcsManager.ACTION_RCS_SERVICE_UNAVAILABLE);
                mContext.sendBroadcast(intent,
                        "com.android.ims.rcs.permission.STATUS_CHANGED");
            }
        }

        public void serviceAvailable(StatusCode statusCode) throws RemoteException {
            synchronized(mSyncObj){
                if(statusCode == null){
                    logger.error("statusCode=null");
                }else{
                    logger.debug("IServiceAvailable statusCode " +
                        statusCode.getStatusCode());
                }

                logger.debug("QPresListener_ServiceAvailable");

                RcsStackAdaptor rcsStackAdaptor = RcsStackAdaptor.getInstance(null);
                if (rcsStackAdaptor != null) {
                    rcsStackAdaptor.setImsEnableState(true);
                }

                // Handle the cached trigger which got from stack
                if(mPresencePublication != null) {
                    logger.debug("publish for cached trigger");
                    mPresencePublication.onStackAvailable();
                }

                Intent intent = new Intent(RcsManager.ACTION_RCS_SERVICE_AVAILABLE);
                mContext.sendBroadcast(intent,
                        "com.android.ims.rcs.permission.STATUS_CHANGED");
            }
        }

        public void publishTriggering(PresPublishTriggerType publishTrigger)
                throws RemoteException {
            if(publishTrigger == null){
                logger.error("publishTrigger=null");
            }else{
                logger.debug("getPublishTrigeerType() "+
                         publishTrigger.getPublishTrigeerType());
            }
            logger.debug("ListenerHandler : PublishTriggering");

            Message publishTrigerMsg = StackListener.this.obtainMessage(
                    PRESENCE_IMS_UNSOL_PUBLISH_TRIGGER, publishTrigger);
            StackListener.this.sendMessage(publishTrigerMsg);
        }

        public void listCapInfoReceived(PresRlmiInfo pRlmiInfo, PresResInfo[] pResInfo)
                throws RemoteException {
            if(pRlmiInfo == null || pResInfo == null){
                logger.error("pRlmiInfo=" + pRlmiInfo + " pResInfo=" + pResInfo);
            }else{
                logger.debug("pRlmiInfo.getListName "+pRlmiInfo.getListName());
                logger.debug("pRlmiInfo.isFullState "+pRlmiInfo.isFullState());
                logger.debug("pRlmiInfo.getUri "+pRlmiInfo.getUri());
                logger.debug("pRlmiInfo.getVersion "+pRlmiInfo.getVersion());
                logger.debug("pRlmiInfo.getSubscriptionTerminatedReason " +
                        pRlmiInfo.getSubscriptionTerminatedReason());
                logger.debug("pRlmiInfo.getPresSubscriptionState " +
                        pRlmiInfo.getPresSubscriptionState());
                logger.debug("pRlmiInfo.getRequestID=" + pRlmiInfo.getRequestId());
                for(int i=0; i < pResInfo.length; i++ ){
                    if(pResInfo[i] == null){
                        logger.debug("ignoring, pResInfo[" + i + "]=null");
                        continue;
                    }

                    logger.debug(".getDisplayName() "+pResInfo[i].getDisplayName());
                    logger.debug("getResUri() "+pResInfo[i].getResUri());
                    if(pResInfo[i].getInstanceInfo() != null){
                        logger.debug("getInstanceInfo().getPresentityUri() "+
                                 pResInfo[i].getInstanceInfo().getPresentityUri());
                        logger.debug("getInstanceInfo().getResId() "+
                                 pResInfo[i].getInstanceInfo().getResId());
                        logger.debug("getInstanceInfo().getsReason() "+
                                 pResInfo[i].getInstanceInfo().getReason());
                        logger.debug("getInstanceInfo().getResInstanceState() "+
                                 pResInfo[i].getInstanceInfo().getResInstanceState());
                        if(pResInfo[i].getInstanceInfo().getTupleInfo() == null){
                           logger.debug("pResInfo[" + i +"].getInstanceInfo().getTupleInfo()=null");
                            continue;
                        }

                        logger.debug("getTupleInfo().length "+
                                 pResInfo[i].getInstanceInfo().getTupleInfo().length);
                        if(pResInfo[i].getInstanceInfo().getTupleInfo() != null){
                            for(int j = 0; j < pResInfo[i].getInstanceInfo().getTupleInfo().length;
                                j++)
                            {
                                if(pResInfo[i].getInstanceInfo().getTupleInfo() == null){
                                    logger.debug("ignoring, pResInfo[" + i +
                                            "].getInstanceInfo().getTupleInfo()[" +j + "]");
                                    continue;
                                }

                                logger.debug("getFeatureTag "+
                                        pResInfo[i].getInstanceInfo().getTupleInfo()[j].
                                        getFeatureTag());
                                logger.debug("getsContactUri "+
                                        pResInfo[i].getInstanceInfo().getTupleInfo()[j].
                                        getContactUri());
                                logger.debug("getsTimestamp "+
                                        pResInfo[i].getInstanceInfo().getTupleInfo()[j].
                                        getTimestamp());
                            }
                        }
                    }
                }
            }

            Message notifyListReceivedMsg = StackListener.this.obtainMessage(
                    PRESENCE_IMS_UNSOL_NOTIFY_LIST_UPDATE,
                    new NotifyListData(pRlmiInfo, pResInfo));
            logger.debug("Send PRESENCE_IMS_UNSOL_NOTIFY_LIST_UPDATE");

            StackListener.this.sendMessage(notifyListReceivedMsg);
        }

        public void capInfoReceived(String presentityURI, PresTupleInfo[] pTupleInfo)
                throws RemoteException {
            logger.debug("ListenerHandler : CapInfoReceived");
            if(presentityURI == null || presentityURI == null){
                logger.error("presentityURI=null or presentityURI=null");
                return;
            }

            logger.debug("ListenerHandler : CapInfoReceived : presentityURI "+ presentityURI);

            Message notifyReceivedMsg = StackListener.this.obtainMessage(
                    PRESENCE_IMS_UNSOL_NOTIFY_UPDATE,
                    new NotifyData(presentityURI, pTupleInfo));
            StackListener.this.sendMessage(notifyReceivedMsg);
        }

        public void cmdStatus(PresCmdStatus pCmdStatus) throws RemoteException {
            synchronized(mSyncObj){
                if(pCmdStatus == null || pCmdStatus.getCmdId() == null){
                     logger.debug( "ICMDStatus error, pCmdStatus="+ pCmdStatus);
                    return;
                 }

                logger.debug("ListenerHandler : CMDStatus");
                logger.debug("ListenerHandler : CMDStatus : pCmdStatus.getRequestID() "+
                        pCmdStatus.getRequestId());
                logger.debug("ListenerHandler : CMDStatus : pCmdStatus.getUserData() "+
                        pCmdStatus.getUserData());
                logger.debug("ListenerHandler : CMDStatus : pCmdStatus.getCmdId() "+
                        pCmdStatus.getCmdId().getCmdId());
                if(pCmdStatus.getStatus() != null){
                    logger.debug("ListenerHandler : CMDStatus : pCmdStatus.getStatus() "+
                           pCmdStatus.getStatus().getStatusCode());
                }

                switch (pCmdStatus.getCmdId().getCmdId()) {
                case PresCmdId.UCE_PRES_CMD_PUBLISHMYCAP:
                    Message publishCmdMsg = StackListener.this.obtainMessage(
                            PRESENCE_IMS_UNSOL_PUBLISH_CMDSTATUS,
                            pCmdStatus);
                    StackListener.this.sendMessage(publishCmdMsg);
                    break;

                case PresCmdId.UCE_PRES_CMD_GETCONTACTCAP:
                case PresCmdId.UCE_PRES_CMD_GETCONTACTLISTCAP:
                    Message notifyUpdateCmdMsg = StackListener.this.obtainMessage(
                            PRESENCE_IMS_UNSOL_NOTIFY_UPDATE_CMDSTATUS,
                            pCmdStatus);
                    StackListener.this.sendMessage(notifyUpdateCmdMsg);
                    break;

                case PresCmdId.UCE_PRES_CMD_SETNEWFEATURETAG:
                    logger.debug("UCE_PRES_CMD_SETNEWFEATURETAG: app does not care it");
                    break;

                default:
                    logger.debug("CMD ID for unknown value=" +
                            pCmdStatus.getCmdId().getCmdId());
                }
            }
        }

        public void unpublishMessageSent() {
            logger.debug("unpublishMessageSent()");
        }
    };

    @PresencePublication.StackPublishTriggerType
    private static int convertToStackPublishTriggerType(int presPublishTriggerType) {
        switch (presPublishTriggerType) {
            case PresPublishTriggerType.UCE_PRES_PUBLISH_TRIGGER_ETAG_EXPIRED:
                return PresencePublication.UCE_PRES_PUBLISH_TRIGGER_ETAG_EXPIRED;
            case PresPublishTriggerType.UCE_PRES_PUBLISH_TRIGGER_MOVE_TO_LTE_VOPS_DISABLED:
                return PresencePublication.UCE_PRES_PUBLISH_TRIGGER_MOVE_TO_LTE_VOPS_DISABLED;
            case PresPublishTriggerType.UCE_PRES_PUBLISH_TRIGGER_MOVE_TO_LTE_VOPS_ENABLED:
                return PresencePublication.UCE_PRES_PUBLISH_TRIGGER_MOVE_TO_LTE_VOPS_ENABLED;
            case PresPublishTriggerType.UCE_PRES_PUBLISH_TRIGGER_MOVE_TO_EHRPD:
                return PresencePublication.UCE_PRES_PUBLISH_TRIGGER_MOVE_TO_EHRPD;
            case PresPublishTriggerType.UCE_PRES_PUBLISH_TRIGGER_MOVE_TO_HSPAPLUS:
                return PresencePublication.UCE_PRES_PUBLISH_TRIGGER_MOVE_TO_HSPAPLUS;
            case PresPublishTriggerType.UCE_PRES_PUBLISH_TRIGGER_MOVE_TO_3G:
                return PresencePublication.UCE_PRES_PUBLISH_TRIGGER_MOVE_TO_3G;
            case PresPublishTriggerType.UCE_PRES_PUBLISH_TRIGGER_MOVE_TO_2G:
                return PresencePublication.UCE_PRES_PUBLISH_TRIGGER_MOVE_TO_2G;
            case PresPublishTriggerType.UCE_PRES_PUBLISH_TRIGGER_MOVE_TO_WLAN:
                return PresencePublication.UCE_PRES_PUBLISH_TRIGGER_MOVE_TO_WLAN;
            case PresPublishTriggerType.UCE_PRES_PUBLISH_TRIGGER_MOVE_TO_IWLAN:
                return PresencePublication.UCE_PRES_PUBLISH_TRIGGER_MOVE_TO_IWLAN;
        }
        return PresencePublication.UCE_PRES_PUBLISH_TRIGGER_UNKNOWN;
    }
}