号簿助手 v4.6.31版本的 MD5 值为:9d7ff98a6bb5cc178eac2df4d1b2f0e0

以下内容为反编译后的 DecodeTask.java 源代码,内容仅作参考


package com.sttri.speech.android;

import android.os.Process;
import android.util.Log;
import com.sttri.speech.net.AudHttpPost;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.SocketTimeoutException;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.params.HttpClientParams;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpProtocolParams;

public class DecodeTask extends Thread {
    public static String CurrSessionID = null;
    private static final String TAG = "<<HttpTask>>";
    public static String strDeviceId;
    public static String strURL;
    private String SessionID;
    private String api_id;
    private String api_key;
    HttpClient httpClient;
    public MFEManager mHandler;
    private String secret_key;
    public static BlockingQueue<CallbackData> backDataList = new LinkedBlockingQueue();
    public static volatile boolean isAlived = false;
    public static volatile boolean isRecordOver = false;
    public static int idx = 1;
    private final String NLPVersion = "1.0.0.2 mfe";
    public int iCount = 0;

    public DecodeTask(MFEManager mfeManager, String strDeviceId2, String strSession, String strurl, String api_id, String api_key, String secret_key) {
        this.mHandler = null;
        this.httpClient = null;
        this.mHandler = mfeManager;
        strDeviceId = strDeviceId2;
        this.SessionID = strSession;
        CurrSessionID = strSession;
        strURL = strurl;
        this.api_id = api_id;
        this.api_key = api_key;
        this.secret_key = secret_key;
        BasicHttpParams httpParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpParams, 20000);
        HttpConnectionParams.setSoTimeout(httpParams, 30000);
        HttpConnectionParams.setSocketBufferSize(httpParams, 8192);
        HttpClientParams.setRedirecting(httpParams, true);
        HttpConnectionParams.setStaleCheckingEnabled(httpParams, false);
        HttpProtocolParams.setUserAgent(httpParams, "CTTR");
        HttpConnectionParams.setTcpNoDelay(httpParams, true);
        this.httpClient = new DefaultHttpClient(httpParams);
    }

    public void CallHandler(int iCode, Object obj) {
        if (this.mHandler != null && isAlived && CurrSessionID.equals(this.SessionID)) {
            Msg msg = new Msg(iCode, obj);
            this.mHandler.appendMsg(msg);
            Log.e(TAG, "sendMessage " + msg);
        }
    }

    @Override
    public void run() {
        CallbackData temp;
        Process.setThreadPriority(10);
        Log.e(TAG, "NLP SDK Version = 1.0.0.2 mfe");
        isAlived = true;
        isRecordOver = false;
        try {
            Thread.sleep(20L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        int idx2 = 0;
        try {
            Thread.sleep(200L);
        } catch (InterruptedException e2) {
            e2.printStackTrace();
        }
        AudHttpPost audHttpPost = new AudHttpPost(strURL, this.httpClient);
        byte[] postBuffer = new byte[2560];
        boolean first = true;
        while (true) {
            if (!isAlived) {
                break;
            }
            while (!audHttpPost.isReady()) {
                try {
                    Thread.sleep(20L);
                } catch (InterruptedException e3) {
                    e3.printStackTrace();
                }
            }
            int postBufferLen = 0;
            int istate = 0;
            try {
                temp = backDataList.peek();
            } catch (InterruptedException e1) {
                Log.e(TAG, e1.toString());
            }
            if (temp == null) {
                if (isRecordOver) {
                    isAlived = false;
                    break;
                }
                if ((postBuffer == null && postBufferLen > 0 && isAlived) || istate == 2) {
                    idx2++;
                    try {
                        String jsonStr = "{\"app\":\"" + this.api_id + "\",\"idx\":" + (istate == 2 ? idx2 * (-1) : idx2) + ",\"glb\":\"" + this.SessionID + "\",\"rtn\":\"json\",\"prop_list\":\"{\\\"prop_list\\\":[10006]}\",\"fun\":\"262401\",\"ptc\":101,\"enc\":\"utf-8\"}";
                        audHttpPost.setData(jsonStr, postBuffer, postBufferLen);
                        if (first) {
                            first = false;
                            ProfStat.markDecStart();
                        }
                        if (istate == 2) {
                            ProfStat.markDecSend();
                        }
                        String response = audHttpPost.call();
                        if (response == null) {
                            isAlived = false;
                            CallHandler(Msg.MSG_NLP_ERROR, Integer.valueOf(Msg.POST_GET_CONNECT_ERR));
                            break;
                        }
                        if (CurrSessionID.equals(this.SessionID)) {
                            if (audHttpPost.getStatusCode() == 200) {
                                Log.e(TAG, String.format("----Request Success,  %s", response));
                                if (istate == 2) {
                                    ProfStat.markDecEnd();
                                    CallHandler(Msg.MSG_NLP_RESULT, response);
                                    isAlived = false;
                                    break;
                                }
                            } else {
                                Log.e(TAG, "!!! ResponseCode = " + audHttpPost.getStatusCode());
                                CallHandler(Msg.MSG_NLP_ERROR, Integer.valueOf(Msg.POST_GET_CONNECT_ERR));
                                isAlived = false;
                                break;
                            }
                        } else {
                            return;
                        }
                    } catch (SocketTimeoutException e4) {
                        CallHandler(Msg.MSG_NLP_ERROR, -109);
                        Log.e(TAG, String.format("POST %s\n", strURL), e4);
                        e4.printStackTrace();
                    } catch (ClientProtocolException e5) {
                        CallHandler(Msg.MSG_NLP_ERROR, Integer.valueOf(Msg.POST_CLIENT_PROTOCOL_ERR));
                        Log.e(TAG, String.format("POST %s\n", strURL), e5);
                        e5.printStackTrace();
                    } catch (ConnectTimeoutException e6) {
                        CallHandler(Msg.MSG_NLP_ERROR, Integer.valueOf(Msg.POST_CONNET_TIMR_OUT_ERR));
                        Log.e(TAG, String.format("POST %s\n", strURL), e6);
                        e6.printStackTrace();
                    } catch (IOException e7) {
                        CallHandler(Msg.MSG_NLP_ERROR, Integer.valueOf(Msg.POST_IO_ERR));
                        Log.e(TAG, String.format("POST %s\n", strURL), e7);
                        e7.printStackTrace();
                    } catch (Exception e8) {
                        CallHandler(Msg.MSG_NLP_ERROR, Integer.valueOf(Msg.POST_OTHER_ERR));
                        Log.e(TAG, String.format("POST %s\n", strURL), e8);
                        e8.printStackTrace();
                    }
                }
            }
            do {
                if (temp.buffer.length + postBufferLen > 2560) {
                    break;
                }
                CallbackData temp2 = backDataList.poll(20L, TimeUnit.MILLISECONDS);
                istate = temp2.flag;
                System.arraycopy(temp2.buffer, 0, postBuffer, postBufferLen, temp2.buffer.length);
                postBufferLen += temp2.buffer.length;
                temp = backDataList.peek();
            } while (temp != null);
            if (postBuffer == null) {
            }
        }
        Log.e(TAG, "RecordTask Exit.");
    }

    private byte[] InputStreamToByte(InputStream is) throws IOException {
        ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
        while (true) {
            int ch = is.read();
            if (ch != -1) {
                bytestream.write(ch);
            } else {
                byte[] imgdata = bytestream.toByteArray();
                bytestream.close();
                return imgdata;
            }
        }
    }
}