lss
2022-05-26 ff886457f58791eea4532f6167af51184d9dfe43
HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/core/service/HDLLinphoneService.java
@@ -18,6 +18,8 @@
import com.hdl.hdllinphonesdk.R;
import com.hdl.hdllinphonesdk.activity.HDLLinphoneIntercomActivity;
import com.hdl.hdllinphonesdk.activity.HDLLinphoneReverseCallActivity;
import com.hdl.hdllinphonesdk.core.callback.PhoneCallback;
import com.hdl.hdllinphonesdk.core.callback.RegistrationCallback;
import com.hdl.hdllinphonesdk.core.linphone.KeepAliveHandler;
@@ -76,12 +78,11 @@
    }
    public static Core getCore() {
        if(sInstance == null){
        if (sInstance == null) {
            return null;
        }
        return sInstance.mCore;
    }
    @Override
    public IBinder onBind(Intent intent) {
@@ -90,11 +91,13 @@
    /**
     * 添加通话状态回调
     *
     * @param phoneCallback
     */
    public static void addPhoneCallback(PhoneCallback phoneCallback) {
        sPhoneCallback = phoneCallback;
    }
    public static void removePhoneCallback() {
        if (sPhoneCallback != null) {
            sPhoneCallback = null;
@@ -103,11 +106,13 @@
    /**
     * 添加注册状态回调
     *
     * @param registrationCallback
     */
    public static void addRegistrationCallback(RegistrationCallback registrationCallback) {
        sRegistrationCallback = registrationCallback;
    }
    public static void removeRegistrationCallback() {
        if (sRegistrationCallback != null) {
            sRegistrationCallback = null;
@@ -154,15 +159,11 @@
                new TimerTask() {
                    @Override
                    public void run() {
                        mHandler.post(
                                new Runnable() {
                                    @Override
                                    public void run() {
                                        if (mCore != null) {
                                            mCore.iterate();
                                        }
                                    }
                                });
                        mHandler.post(() -> {
                            if (mCore != null) {
                                mCore.iterate();
                            }
                        });
                    }
                };
        mTimer = new Timer("Linphone scheduler");
@@ -176,11 +177,11 @@
        removeAllCallback();
        logout();
        if(mTimer != null) {
        if (mTimer != null) {
            mTimer.cancel();
        }
        if(mCore != null){
        if (mCore != null) {
            mCore.removeListener(mCoreListener);
            mCore.stop();
            // A stopped Core can be started again
@@ -222,8 +223,8 @@
        initCoreListener();
        copyAssetsFromPackage(basePath);
        // Create the Core and add our listener
        mCore = Factory.instance()
                .createCore(basePath + "/.linphonerc", basePath + "/linphonerc", this);
        mCore = Factory.instance().createCore(basePath + "/.linphonerc",
                basePath + "/linphonerc", this);
        mCore.addListener(mCoreListener);
        // Core is ready to be configured
        configureCore();
@@ -237,6 +238,7 @@
            @Override
            public void onCallStateChanged(Core core, Call linphoneCall, Call.State state, String message) {
                HDLLog.e(START_LINPHONE_LOGS, "callState: " + state.toString());
                HDLLog.e(START_LINPHONE_LOGS, "state.toInt()=" + state.toInt() + "==============message=========: " + message);
                currentCallState = state;
                if (sPhoneCallback != null) {
                    if (state == Call.State.IncomingReceived) {
@@ -246,7 +248,7 @@
                    } else if (state == Call.State.Connected) {
                        sPhoneCallback.callConnected();
                    } else if (state == Call.State.Error) {
                        sPhoneCallback.error();
                        sPhoneCallback.error(message);
                    } else if (state == Call.State.End) {
                        sPhoneCallback.callEnd();
                    } else if (state == Call.State.Released) {
@@ -261,11 +263,11 @@
                HDLLog.i(START_LINPHONE_LOGS, "registrationState: " + state);
                if (state.equals(RegistrationState.None.toString())) {
                    if (sRegistrationCallback != null){
                    if (sRegistrationCallback != null) {
                        sRegistrationCallback.registrationNone();
                    }
                } else if (state.equals(RegistrationState.Progress.toString())) {
                    if (sRegistrationCallback != null){
                    if (sRegistrationCallback != null) {
                        sRegistrationCallback.registrationProgress();
                    }
                } else if (state.equals(RegistrationState.Ok.toString())) {
@@ -288,6 +290,7 @@
    /**
     * 收到注销成功后移除当前代理
     *
     * @param core
     * @param proxyConfig
     */
@@ -318,7 +321,8 @@
        }
        //1.设置存储用户x509证书的目录的路径
        mCore.setUserCertificatesPath(userCerts);
        //mCore.setUserCertificatesPath(userCerts);
        mCore.setUserCertificatesPath(basePath);
        //2.设置UserAgent
        setUserAgent();
        //3.设置播放铃声
@@ -353,6 +357,9 @@
        mCore.setVideoActivationPolicy(vap);
        //11.设置编码格式
        setCodecMime();
        // 全视通sip设置ca证书
        //mCore.setRootCa(basePath + "/rootca.pem");
    }
    /**
@@ -381,6 +388,7 @@
    /**
     * 设置是否启用铃声,目前发现设置无效待分析原因
     *
     * @param use
     */
    public void enableDeviceRingtone(boolean use) {
@@ -460,6 +468,9 @@
//            mPauseSoundFile = basePath + "/toy_mono.wav";
//            copyIfNotExist(R.raw.toy_mono, basePath + "/toy_mono.wav");
//            String mRootca = basePath + "/rootca.pem"; // 2022-05-23 对接全视通可视对讲添加的证书
//            copyIfNotExist(R.raw.freeview_rootca, mRootca);
            String mLPConfigXsd = basePath + "/lpconfig.xsd";
            copyIfNotExist(R.raw.lpconfig, mLPConfigXsd);
@@ -471,6 +482,7 @@
    /**
     * copyIfNotExist
     *
     * @param ressourceId
     * @param target
     * @throws IOException
@@ -484,6 +496,7 @@
    /**
     * copyFromPackage
     *
     * @param ressourceId
     * @param target
     * @throws IOException
@@ -533,12 +546,14 @@
    //通知ID
    public static final int NOTIFICATION_ID = 2;
    /**
     * 解决android8.0以上无法启动服务的问题
     */
    void hdlStartForeground() {
    }
    /**
     * stopForeground
     */