// Path: asynctcp/src/main/java/com/beetle/AsyncTCP.java
// public class AsyncTCP {
//     private int sock;
//     private int events;
// 
//     private byte[] data;
//     private boolean connecting;
//     
//     private TCPConnectCallback connectCallback;
//     private TCPReadCallback readCallback;
//     private long self;
//    
// 
//     public void setConnectCallback(TCPConnectCallback cb) {
// 	connectCallback = cb;
//     }
//     public void setReadCallback(TCPReadCallback cb) {
// 	readCallback = cb;
//     }
//     public native boolean connect(String host, int port);
//     public native void close();
// 
//     public native void writeData(byte[] bytes);
//     
//     public native void startRead();
//   
// 
//     static {
//         System.loadLibrary("async_tcp");
//     }
// }
// 
// Path: asynctcp/src/main/java/com/beetle/TCPConnectCallback.java
// public interface TCPConnectCallback {
//  
//     public void onConnect(Object tcp, int status);
//  
// }
// 
// Path: asynctcp/src/main/java/com/beetle/TCPReadCallback.java
// public interface TCPReadCallback {
//  
//     public void onRead(Object tcp, byte[] data);
//  
// }


import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.util.Log;
import com.beetle.AsyncTCP;
import com.beetle.TCPConnectCallback;
import com.beetle.TCPReadCallback;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import static android.os.SystemClock.uptimeMillis;
        Log.i(TAG, "start im service");
        this.stopped = false;
        this.resume();

        //应用在后台的情况下基本不太可能调用start
        if (this.isBackground) {
            Log.w(TAG, "start im service when app is background");
        }
    }

    public void stop() {
        if (this.stopped) {
            Log.i(TAG, "already stopped");
            return;
        }
        Log.i(TAG, "stop im service");
        stopped = true;
        suspend();
    }

    private void suspend() {
        if (this.suspended) {
            Log.i(TAG, "suspended");
            return;
        }
        this.close();
        heartbeatTimer.suspend();
        connectTimer.suspend();
        this.suspended = true;

// Path: asynctcp/src/main/java/com/beetle/AsyncTCP.java
// public class AsyncTCP {
//     private int sock;
//     private int events;
// 
//     private byte[] data;
//     private boolean connecting;
//     
//     private TCPConnectCallback connectCallback;
//     private TCPReadCallback readCallback;
//     private long self;
//    
// 
//     public void setConnectCallback(TCPConnectCallback cb) {
// 	connectCallback = cb;
//     }
//     public void setReadCallback(TCPReadCallback cb) {
// 	readCallback = cb;
//     }
//     public native boolean connect(String host, int port);
//     public native void close();
// 
//     public native void writeData(byte[] bytes);
//     
//     public native void startRead();
//   
// 
//     static {
//         System.loadLibrary("async_tcp");
//     }
// }
// 
// Path: asynctcp/src/main/java/com/beetle/TCPConnectCallback.java
// public interface TCPConnectCallback {
//  
//     public void onConnect(Object tcp, int status);
//  
// }
// 
// Path: asynctcp/src/main/java/com/beetle/TCPReadCallback.java
// public interface TCPReadCallback {
//  
//     public void onRead(Object tcp, byte[] data);
//  
// }


// Path: imsdk/src/main/java/com/beetle/im/IMService.java
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.util.Log;
import com.beetle.AsyncTCP;
import com.beetle.TCPConnectCallback;
import com.beetle.TCPReadCallback;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import static android.os.SystemClock.uptimeMillis;

        Log.i(TAG, "start im service");
        this.stopped = false;
        this.resume();

        //应用在后台的情况下基本不太可能调用start
        if (this.isBackground) {
            Log.w(TAG, "start im service when app is background");
        }
    }

    public void stop() {
        if (this.stopped) {
            Log.i(TAG, "already stopped");
            return;
        }
        Log.i(TAG, "stop im service");
        stopped = true;
        suspend();
    }

    private void suspend() {
        if (this.suspended) {
            Log.i(TAG, "suspended");
            return;
        }
        this.close();
        heartbeatTimer.suspend();
        connectTimer.suspend();
        this.suspended = true;

        Log.i(TAG, "suspend im service");