562935844@qq.com
2023-09-05 98340bb2bbd3b0c8b877c7d3314023c40f942c02
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
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
package com.hdl.hdllinphonesdk;
 
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Build;
import android.os.IBinder;
import android.util.Log;
import android.view.TextureView;
import android.widget.Toast;
 
import com.hdl.hdllinphonesdk.activity.HDLLinphoneIntercomActivity;
import com.hdl.hdllinphonesdk.activity.HDLLinphoneReverseCallActivity;
import com.hdl.hdllinphonesdk.callback.OnHDLLinphoneCallListener;
import com.hdl.hdllinphonesdk.callback.OnLPOpenDoorCallBack;
import com.hdl.hdllinphonesdk.core.callback.PhoneCallback;
import com.hdl.hdllinphonesdk.core.callback.RegistrationCallback;
import com.hdl.hdllinphonesdk.core.service.HDLLinphoneService;
import com.hdl.hdllinphonesdk.utils.HDLLog;
 
import org.linphone.core.AccountCreator;
import org.linphone.core.Address;
import org.linphone.core.AudioDevice;
import org.linphone.core.AuthInfo;
import org.linphone.core.Call;
import org.linphone.core.CallParams;
import org.linphone.core.Core;
import org.linphone.core.CoreException;
import org.linphone.core.Factory;
import org.linphone.core.ProxyConfig;
import org.linphone.core.TransportType;
 
import java.io.FileOutputStream;
import java.io.InputStream;
 
import static java.lang.Thread.sleep;
 
/**
 * Created by jlchen on 2021/8/4.
 */
public class HDLLinphoneKit {
    /**
     * 丰林可视对讲
     */
    public static final String INTER_PHONE_TYPE_FLVI = "FLVI";
    /**
     * 大华可视对讲
     */
    public static final String INTER_PHONE_TYPE_IMOUVISIAL = "IMOUVISIAL";
    /**
     * 萤石猫眼
     */
    public static final String INTER_PHONE_TYPE_EZVIZ = "EZVIZ";
    /**
     * HDL可视对讲
     */
    public static final String INTER_PHONE_TYPE_HDL = "HDL";
    /**
     * 全视通可视对讲
     */
    public static final String INTER_PHONE_TYPE_FREEVIEW = "FREEVIEW";
 
    public static final String KEY_TITLE_NAME = "lpTitleName";
    public static final String KEY_SIP_ACCOUNT = "lpSipAccount";
    public static final String HDLLinphoneKitNAME = "HDLLinphoneKit";
    private volatile static HDLLinphoneKit instance;
    private Context viewContext;
    private ServiceWaitThread mServiceWaitThread;
    private String mUsername, mPassword, mServerIP;
    //    private TextureView mRenderingView, mPreviewView;
    private boolean isAutoJumpCallView;//是否自动跳转呼叫页面
    private String intercomeType;
 
    private HDLLinphoneKit() {
 
    }
 
    /**
     * getInstance
     *
     * @return HDLLinphoneKit
     */
    public static synchronized HDLLinphoneKit getInstance() {
        if (instance == null) {
            synchronized (HDLLinphoneKit.class) {
                if (instance == null) {
                    instance = new HDLLinphoneKit();
                }
            }
        }
        return instance;
    }
 
    /**
     * 获取 LinphoneCore
     *
     * @return Core
     */
    public Core getCore() {
        if (!HDLLinphoneService.isReady()) {
            CheckIfNeedstartService();
            return null;
        } else {
            return HDLLinphoneService.getCore();
        }
    }
 
    /**
     * 初始化Linphone
     *
     * @param context
     */
    public void initLinphone(Context context) {
        viewContext = context.getApplicationContext();
        if (!HDLLinphoneService.isReady()) {
            CheckIfNeedstartService();
        } else {
        }
    }
 
    /**
     * startService
     */
    private synchronized void CheckIfNeedstartService() {
        startService(viewContext);
        addCallback(new RegistrationCallback() {
            @Override
            public void registrationOk() {
                super.registrationOk();
                HDLLog.e(HDLLinphoneKitNAME, "registrationOk: ");
                callBackRegistrationOk(viewContext);
            }
 
            @Override
            public void registrationFailed() {
                super.registrationFailed();
                HDLLog.e(HDLLinphoneKitNAME, "registrationFailed: ");
//                    Toast.makeText(LoginActivity.this, "登录失败!", Toast.LENGTH_SHORT).show();
            }
        }, null);
    }
 
    /**
     * 注册成功后,注册呼叫监听
     */
    void callBackRegistrationOk(Context context) {
        addCallback(null, new PhoneCallback() {
            @Override
            public void incomingCall(Call linphoneCall) {
                super.incomingCall(linphoneCall);
                Log.d("HDLLinphoneKit", "------incomingCall------");
                if (linphoneCall != null) {
                    String callUsername = linphoneCall.getRemoteAddress().getUsername();
                    HDLLog.I("来电号码:" + callUsername);
//                    HDLLog.Log("来电号码DisplayName:" + linphoneCall.getRemoteAddress().getDisplayName());
                    if (mOnHDLLinphoneCallListener != null) {
                        mOnHDLLinphoneCallListener.onIncomingCall(callUsername);
                    }
                }
 
                if (isAutoJumpCallView) {
                    //是否需要自动打开呼叫页面
                    gotoHDLLinphoneIntercomActivity();
                }
            }
 
            @Override
            public void outgoingInit() {
                super.outgoingInit();
                Log.d("HDLLinphoneKit", "------outgoingInit------");
            }
 
            @Override
            public void callConnected() {
                super.callConnected();
                // 视频通话默认免提,语音通话默认非免提
                Log.d("HDLLinphoneKit", "------callConnected------");
                toggleSpeaker(true);
            }
 
            @Override
            public void callEnd() {
                super.callEnd();
                Log.d("HDLLinphoneKit", "------callEnd------");
//                context.sendBroadcast(new Intent(HDLLinphoneIntercomActivity.RECEIVE_FINISH_VIDEO_ACTIVITY));
            }
        });
    }
 
    /**
     * 跳转打开呼叫页面
     */
    public void gotoHDLLinphoneIntercomActivity() {
        try {
            Intent intent = new Intent(viewContext, HDLLinphoneIntercomActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            viewContext.startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    private HDLLinphoneService mService;
    private final ServiceConnection connection = new ServiceConnection() {
 
        @Override
        public void onServiceConnected(ComponentName name, IBinder ibinder) {
            HDLLinphoneService.LinphoneBinder binder = (HDLLinphoneService.LinphoneBinder) ibinder;
            mService = binder.getService();
            //初始化
            mService.initCore();
        }
 
        @Override
        public void onServiceDisconnected(ComponentName name) {
            mService = null;
        }
 
    };
 
    /**
     * 开启服务
     *
     * @param context 上下文
     */
    public void startService(Context context) {
        try {
            if (!HDLLinphoneService.isReady()) {
                Intent intent = new Intent(Intent.ACTION_MAIN);
                intent.setClass(context, HDLLinphoneService.class);
                context.bindService(intent, connection, Context.BIND_AUTO_CREATE);
 
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    /**
     * onResume
     */
    public void onResume() {
 
    }
 
    /**
     * onPause
     */
    public void onPause() {
 
    }
 
    /**
     * onDestroy
     */
    public void onDestroy() {
        removePreviewWindow();
        removeVideoWindow();
    }
 
    /**
     * 设置 sip 账户信息
     *
     * @param username sip 账户
     * @param password 密码
     * @param serverIP sip 服务器
     */
    public void setAccountAndLogin(String username, String password, String serverIP, String inter_type) {
        mUsername = username;
        mPassword = password;
        mServerIP = serverIP;
        intercomeType = inter_type;
        login(inter_type);
    }
 
    public String getIntercomeType() {
        return intercomeType;
    }
 
    /**
     * 添加注册状态、通话状态回调
     *
     * @param phoneCallback        通话回调
     * @param registrationCallback 注册状态回调
     */
    public void addCallback(RegistrationCallback registrationCallback, PhoneCallback phoneCallback) {
        if (HDLLinphoneService.isReady()) {
            HDLLinphoneService.addRegistrationCallback(registrationCallback);
            HDLLinphoneService.addPhoneCallback(phoneCallback);
        } else {
            mServiceWaitThread = new ServiceWaitThread(registrationCallback, phoneCallback);
            mServiceWaitThread.start();
        }
    }
 
    /**
     * 登录到 SIP 服务器
     */
    public void login(String inter_type) {
        new Thread(() -> {
            while (!HDLLinphoneService.isReady()) {
                try {
                    sleep(80);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            loginToServer(inter_type);
        }).start();
    }
 
    /**
     * 退出清空账号
     * enableRegister false
     */
    public void logout() {
        try {
            Core core = HDLLinphoneService.getCore();
            if (core != null) {
                ProxyConfig[] configs = core.getProxyConfigList();
                for (ProxyConfig config : configs) {
                    if (config != null) {
                        config.edit();
                        config.enableRegister(false);
                        config.done();
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    /**
     * 清除配置表, 切换账号时会用到
     */
    public void clearProxyConfig() {
        Core core = HDLLinphoneService.getCore();
        if (core != null) {
            core.setDefaultProxyConfig(null);
            core.clearAllAuthInfo();//清除所有认证信息。
            core.clearProxyConfig();//从配置中删除所有代理。
        }
    }
 
    /**
     * ServiceWaitThread
     */
    private class ServiceWaitThread extends Thread {
        private PhoneCallback mPhoneCallback;
        private RegistrationCallback mRegistrationCallback;
 
        ServiceWaitThread(RegistrationCallback registrationCallback, PhoneCallback phoneCallback) {
            mRegistrationCallback = registrationCallback;
            mPhoneCallback = phoneCallback;
        }
 
        @Override
        public void run() {
            super.run();
            while (!HDLLinphoneService.isReady()) {
                try {
                    sleep(80);
                } catch (InterruptedException e) {
                    throw new RuntimeException("waiting thread sleep() has been interrupted");
                }
            }
            HDLLinphoneService.addPhoneCallback(mPhoneCallback);
            HDLLinphoneService.addRegistrationCallback(mRegistrationCallback);
            mServiceWaitThread = null;
        }
    }
 
    /**
     * 登录 SIP 服务器
     */
    private void loginToServer(String inter_type) {
        Log.e("==========", "loginToServer: ");
 
        try {
            if (mUsername == null || mPassword == null || mServerIP == null) {
                throw new RuntimeException("The sip account is not configured.");
            }
            if (inter_type.equals(INTER_PHONE_TYPE_FREEVIEW)) {
                // 全视通可视对讲注册
                freeViewRegisterUserAuth(mUsername, mPassword, mServerIP);
            } else {
                // 其他可视对讲注册
                registerUserAuth(mUsername, mPassword, mServerIP);
            }
        } catch (CoreException e) {
            e.printStackTrace();
        }
    }
 
    /**
     * 提交账号和密码注册到服务器
     *
     * @param name
     * @param password
     * @param host
     * @throws CoreException
     */
    public void registerUserAuth(String name, String password, String host) throws CoreException {
        Core mLinphoneCore = HDLLinphoneService.getCore();
        if (mLinphoneCore == null) return;
 
        AuthInfo authInfo = Factory.instance().createAuthInfo(name, name, password, null, null, host);
        AccountCreator mAccountCreator = mLinphoneCore.createAccountCreator(null);
        mAccountCreator.setUsername(name);
        mAccountCreator.setDomain(host);
        mAccountCreator.setPassword(password);
        mAccountCreator.setTransport(TransportType.Udp);
        ProxyConfig prxCfg = mAccountCreator.createProxyConfig();
 
        prxCfg.enableQualityReporting(false);
        prxCfg.setQualityReportingCollector(null);
        prxCfg.setQualityReportingInterval(0);
        prxCfg.enableRegister(true);
        mLinphoneCore.addProxyConfig(prxCfg);//添加代理配置。如果启用了注册,这将开始在代理上注册。
        mLinphoneCore.addAuthInfo(authInfo);//添加认证信息到,该信息片段将在所有需要的SIP事务中使用身份验证
        mLinphoneCore.setDefaultProxyConfig(prxCfg);//设置默认代理。
    }
 
    /**
     * 提交账号和密码注册到全视通服务器
     *
     * @throws CoreException
     */
    public void freeViewRegisterUserAuth(String userName, String password, String domain) throws CoreException {
        Core mLinphoneCore = HDLLinphoneService.getCore();
        if (mLinphoneCore == null) return;
 
        AuthInfo authInfo = Factory.instance().createAuthInfo(userName, "", password, null, null, domain);
 
        AccountCreator mAccountCreator = mLinphoneCore.createAccountCreator(null);
        mAccountCreator.setUsername(userName);
        mAccountCreator.setDomain("yun");
        mAccountCreator.setPassword(password);
        mAccountCreator.setTransport(TransportType.Udp);
 
        ProxyConfig prxCfg = mAccountCreator.createProxyConfig();
        prxCfg.enableQualityReporting(false);
        prxCfg.setQualityReportingCollector(null);
        prxCfg.setQualityReportingInterval(0);
        prxCfg.enableRegister(true);
        //全视通需要设置固定代理服务器ip
        prxCfg.setServerAddr("sip:139.159.157.75:46000;transport=udp");
 
        mLinphoneCore.addProxyConfig(prxCfg);//添加代理配置。如果启用了注册,这将开始在代理上注册。
        mLinphoneCore.addAuthInfo(authInfo);//添加认证信息到,该信息片段将在所有需要的SIP事务中使用身份验证
        mLinphoneCore.setDefaultProxyConfig(prxCfg);//设置默认代理。
    }
 
    /**
     * 呼叫,全视通可视对讲需要将 外出代理服务器打开,才能使用 空间号呼叫;
     * 暂时没找到怎么打开,所以需要手动加上proxy
     */
    public Call startSingleCallingTo(String userName, boolean isVideoCall) {
        Core mLinphoneCore = HDLLinphoneService.getCore();
        if (mLinphoneCore == null) return null;
 
        Call call = null;
        Core core = HDLLinphoneService.getCore();
        if (core != null) {
            Address addressToCall = core.interpretUrl(userName);
            CallParams params = core.createCallParams(null);
 
            if (isVideoCall) {
                params.enableVideo(true);
                params.enableLowBandwidth(false);
                params.setAudioBandwidthLimit(0); // disable limitation
            } else {
                params.enableVideo(false);
                params.setAudioBandwidthLimit(40); // disable limitation
            }
 
            if (addressToCall != null) {
                call = core.inviteAddressWithParams(addressToCall, params);
                // 设置外放
                for (AudioDevice audioDevice : HDLLinphoneService.getCore().getAudioDevices()) {
                    if (audioDevice.getType() == AudioDevice.Type.Speaker) {
                        call.setOutputAudioDevice(audioDevice);
                    }
                }
            }
        }
        return call;
    }
 
    /**
     * 呼叫指定号码
     *
     * @param num 呼叫号码
     */
    public void callTo(String num, boolean isVideoCall) {
        if (!HDLLinphoneService.isReady() || !HDLLinphoneService.getCoreIsNotNull()) {
            return;
        }
        if (!num.equals("")) {
            startSingleCallingTo(num, isVideoCall);
        }
    }
 
    /**
     * 接听来电
     */
    public void acceptCall() {
        try {
            if (HDLLinphoneService.getCore() == null) return;
            Call currentCall = HDLLinphoneService.getCore().getCurrentCall();
            CallParams params = HDLLinphoneService.getCore().createCallParams(currentCall);
            params.enableVideo(true);
            params.enableLowBandwidth(false);
            params.setAudioBandwidthLimit(0); // disable limitation
            currentCall.acceptWithParams(params);
            Log.d("HDLLinphoneKit", "---acceptCall= ");
 
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    /**
     * 接听来电
     */
    public void acceptCallWithVideo(boolean enableVideo) {
        try {
            if (HDLLinphoneService.getCore() == null) return;
            Call currentCall = HDLLinphoneService.getCore().getCurrentCall();
            CallParams params = HDLLinphoneService.getCore().createCallParams(currentCall);
            params.enableVideo(enableVideo);
            params.setAudioBandwidthLimit(enableVideo ? 0 : 40);
            currentCall.acceptWithParams(params);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    /**
     * 挂断电话
     */
    public void hangUp() {
        Core mLinphoneCore = HDLLinphoneService.getCore();
        if (mLinphoneCore == null) return;
        Call currentCall = mLinphoneCore.getCurrentCall();
        if (currentCall != null) {
//            mLinphoneCore.terminateCall(currentCall);
            mLinphoneCore.terminateAllCalls();
        } else if (mLinphoneCore.isInConference()) {
            mLinphoneCore.terminateConference();
        } else {
            mLinphoneCore.terminateAllCalls();
        }
    }
 
    /**
     * 是否静音
     *
     * @param isMicMuted
     */
    public void toggleMicro(boolean isMicMuted) {
        Core mLinphoneCore = HDLLinphoneService.getCore();
        if (mLinphoneCore == null) return;
        mLinphoneCore.enableMic(!isMicMuted);
    }
 
    /**
     * 是否外放
     *
     * @param isSpeakerEnabled
     */
    public void toggleSpeaker(boolean isSpeakerEnabled) {
        routeAudioToSpeakerHelper(isSpeakerEnabled);
    }
 
    /**
     * 设置外放设备
     */
    private void routeAudioToSpeakerHelper(boolean speakerOn) {
        Log.d("HDLLinphoneKit", "设置外放设备[Audio Manager] Routing audio to " + (speakerOn ? "speaker" : "earpiece"));
        try {
            if (HDLLinphoneService.getCore() == null) return;
            if (HDLLinphoneService.getCore().getCallsNb() == 0) return;
            Call currentCall = HDLLinphoneService.getCore().getCurrentCall();
            if (currentCall == null) currentCall = HDLLinphoneService.getCore().getCalls()[0];
            if (currentCall == null) return;
 
            for (AudioDevice audioDevice : HDLLinphoneService.getCore().getAudioDevices()) {
                Log.d("HDLLinphoneKit", "audioDevice.getType()= " + audioDevice.getType());
            }
 
            for (AudioDevice audioDevice : HDLLinphoneService.getCore().getAudioDevices()) {
                Log.d("HDLLinphoneKit", "设置外放设备speakerOn=" + speakerOn + " audioDevice.getType()=" + audioDevice.getType());
                if (speakerOn && audioDevice.getType() == AudioDevice.Type.Speaker) {
                    currentCall.setOutputAudioDevice(audioDevice);
                    Log.d("HDLLinphoneKit", "AudioDevice.Type.Speaker");
                    return;
                } else if (!speakerOn && audioDevice.getType() == AudioDevice.Type.Earpiece) {
                    currentCall.setOutputAudioDevice(audioDevice);
                    return;
                }
            }
            currentCall.setSpeakerVolumeGain(1.0f);
            currentCall.setSpeakerMuted(speakerOn);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    /**
     * 设置 TextureView
     *
     * @param renderingView 远程 TextureView
     * @param previewView   本地 TextureView
     */
    public void setAndroidVideoWindow(final TextureView renderingView, final TextureView previewView) {
//        mRenderingView = renderingView;
//        mPreviewView = previewView;
        setVideoWindow(renderingView);
        setPreviewWindow(previewView);
 
    }
 
    /**
     * 设置播放View
     *
     * @param o
     */
    private void setVideoWindow(Object o) {
        Core linphoneCore = HDLLinphoneService.getCore();
        if (linphoneCore != null) {
            linphoneCore.setNativeVideoWindowId(o);
        }
    }
 
    /**
     * 移除播放View
     */
    private void removeVideoWindow() {
        Core linphoneCore = HDLLinphoneService.getCore();
        if (linphoneCore != null) {
            linphoneCore.setNativeVideoWindowId(null);
        }
    }
 
    /**
     * 设置本机摄像头采集的View
     *
     * @param o
     */
    private void setPreviewWindow(Object o) {
        Core linphoneCore = HDLLinphoneService.getCore();
        if (linphoneCore != null) {
            linphoneCore.setNativePreviewWindowId(o);
        }
    }
 
    /**
     * 移除视频采集View
     */
    private void removePreviewWindow() {
        Core linphoneCore = HDLLinphoneService.getCore();
        if (linphoneCore != null) {
            linphoneCore.setNativePreviewWindowId(null);
        }
    }
 
    /**
     * 获取当前通话状态
     */
    public Call.State getCallState() {
        if (HDLLinphoneService.getInstance() == null) {
            return null;
        } else {
            return HDLLinphoneService.getInstance().getCurrentCallState();
        }
    }
 
    /**
     * 获取当前通话状态是否为来电中
     */
    public boolean isIncomingReceivedCallState() {
        if (HDLLinphoneService.getInstance() == null || HDLLinphoneService.getInstance().getCurrentCallState() == null) {
            return false;
        } else {
            return (HDLLinphoneService.getInstance().getCurrentCallState() == Call.State.IncomingReceived);
        }
    }
 
    /**
     * 是否自动跳转呼叫页面方案
     */
    public boolean isAutoJumpCallView() {
        return isAutoJumpCallView;
    }
 
    /**
     * 设置是否自动跳转呼叫页面标志
     *
     * @param autoJumpCallView
     */
    public void setAutoJumpCallView(boolean autoJumpCallView) {
        isAutoJumpCallView = autoJumpCallView;
    }
 
    /**
     * 开门回调接口
     */
    private OnLPOpenDoorCallBack openOpenDoorCallBack;
 
    /**
     * setOpenOpenDoorCallBack
     */
    public void setOpenOpenDoorCallBack(OnLPOpenDoorCallBack openOpenDoorCallBack) {
        this.openOpenDoorCallBack = openOpenDoorCallBack;
    }
 
    /**
     * 通知开门成功
     */
    public void onOpenSuccess() {
        if (openOpenDoorCallBack != null) {
            openOpenDoorCallBack.onOpenSuccess();
        }
    }
 
    /**
     * 通知开门失败
     */
    public void onOpenError(String mes) {
        if (openOpenDoorCallBack != null) {
            openOpenDoorCallBack.onOpenError(mes);
        }
    }
 
    /**
     * 呼叫页面相关操作回调接口
     */
    private OnHDLLinphoneCallListener mOnHDLLinphoneCallListener;
 
    /**
     * 获取onHDLLinphoneCallListener
     * 接听、挂断、开锁等 Listener实现
     *
     * @return OnHDLLinphoneCallListener
     */
    public OnHDLLinphoneCallListener getOnHDLLinphoneCallListener() {
        return mOnHDLLinphoneCallListener;
    }
 
    /**
     * 设置onHDLLinphoneCallListener
     *
     * @param onHDLLinphoneCallListener
     */
    public void setOnHDLLinphoneCallListener(OnHDLLinphoneCallListener onHDLLinphoneCallListener) {
        mOnHDLLinphoneCallListener = onHDLLinphoneCallListener;
    }
 
    /**
     * showToast
     */
    private void showToast(String text) {
        Toast.makeText(viewContext, text, Toast.LENGTH_SHORT).show();
    }
}