Android Open Source - SenqmAndroid Connection Manager Service






From Project

Back to project page SenqmAndroid.

License

The source code is released under:

GNU General Public License

If you think the Android project SenqmAndroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 *      Copyright  2014 Alban GRUIN//from  w  ww  . ja  va2 s. c  o m
 *
 *      This file is part of SenqmAndroid.
 *
 *      SenqmAndroid is free software: you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation, either version 3 of the License, or
 *      (at your option) any later version.
 *
 *      SenqmAndroid is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with SenqmAndroid.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.agrn.senqm.network.service;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import com.agrn.senqm.network.Message;
import com.agrn.senqm.network.connection.Connection;

import java.util.ArrayList;

public class ConnectionManagerService extends Service
{
    private static boolean running = false;

    private final IBinder binder = new ConnectionManagerBinder();

    private ArrayList<Connection> connectionList = new ArrayList<>();

    @Override
    public IBinder onBind(Intent intent)
    {
        return binder;
    }

    @Override
    public void onDestroy()
    {
        for(Connection connection: connectionList)
            connection.close();

        running = false;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId)
    {
        running = true;

        return START_STICKY;
    }

    public Connection addConnection(String hostAddress)
    {
        Connection connection = new Connection(hostAddress);
        connection.connect();

        connectionList.add(connection);

        return connection;
    }

    public void broadcastMessage(Message message)
    {
        for(Connection connection: connectionList)
            connection.sendMessage(message);
    }

    public int connectionCount()
    {
        return connectionList.size();
    }

    public void disconnect(String hostAddress)
    {
        getConnectionFromHostAddress(hostAddress).close();
    }

    public Connection getConnectionFromHostAddress(String hostAddress)
    {
        for(Connection connection: connectionList)
        {
            if(connection.getHostAddress() == hostAddress)
                return connection;
        }

        return null;
    }

    public static boolean isRunning()
    {
        return running;
    }

    public class ConnectionManagerBinder extends Binder
    {
        public ConnectionManagerService getService()
        {
            return ConnectionManagerService.this;
        }
    }
}




Java Source Code List

com.agrn.senqm.MainActivity.java
com.agrn.senqm.database.DatabaseHelper.java
com.agrn.senqm.database.entities.Computer.java
com.agrn.senqm.network.Message.java
com.agrn.senqm.network.WifiLockContainer.java
com.agrn.senqm.network.connection.ConnectionHandler.java
com.agrn.senqm.network.connection.Connection.java
com.agrn.senqm.network.service.ConnectionManagerServiceBoundListener.java
com.agrn.senqm.network.service.ConnectionManagerServiceConnection.java
com.agrn.senqm.network.service.ConnectionManagerService.java
com.agrn.senqm.telephony.PhoneBroadcaster.java
com.agrn.senqm.telephony.sms.SMSBroadcaster.java
com.agrn.senqm.telephony.sms.SendSMS.java