Android Open Source - Glass-IntentTunnel Server Service






From Project

Back to project page Glass-IntentTunnel.

License

The source code is released under:

MIT License

If you think the Android project Glass-IntentTunnel 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

package com.masterbaron.intenttunnel.router;
//from   w  w  w .  jav a  2  s  . c o  m
import android.bluetooth.BluetoothAdapter;
import android.os.Message;

import com.masterbaron.intenttunnel.common.R;

import java.util.Queue;
import java.util.UUID;

import ktlab.lib.connection.ConnectionCommand;
import ktlab.lib.connection.bluetooth.BluetoothConnection;
import ktlab.lib.connection.bluetooth.ServerBluetoothConnection;

/**
 * Created by Van Etten on 12/2/13.
 */
public class ServerService extends BluetoothService {
    private static int MESSAGE_RECONNECT = 3200;

    public static ServerService service;

    public ServerService(RouterService routerService) {
        super(routerService);
    }

    @Override
    protected BluetoothConnection createNewBTConnection() {
        BluetoothAdapter defaultAdapter = BluetoothAdapter.getDefaultAdapter();

        if (defaultAdapter != null) {
            return new ServerBluetoothConnection(getUUIDFromAddress(defaultAdapter.getAddress()), this, false);
        }
        return null;
    }

    @Override
    public void onConnectionLost() {
        boolean enabled = isEnabled();
        super.onConnectionLost();
        if (enabled) {
            mHandler.sendEmptyMessageDelayed(MESSAGE_RECONNECT, 2000);
        }
    }

    @Override
    public void onConnectionFailed() {
        boolean enabled = isEnabled();
        super.onConnectionFailed();

        BluetoothAdapter defaultAdapter = BluetoothAdapter.getDefaultAdapter();
        if (defaultAdapter != null && defaultAdapter.isEnabled() && enabled) {
            mHandler.sendEmptyMessageDelayed(MESSAGE_RECONNECT, 10000);
        }
    }

    @Override
    public boolean handleMessage(Message msg) {
        if (msg.what == MESSAGE_RECONNECT) {
            startConnection();
            return true;
        }

        return super.handleMessage(msg);
    }

    public static boolean isServiceRunning() {
        ServerService ss = ServerService.service;
        return (ss != null && ss.isRunning());
    }

    public static String getServiceStatus() {
        ServerService ss = ServerService.service;
        if (ss != null) {
            return ss.getStatus();
        }
        return "Never Started";
    }
}




Java Source Code List

com.masterbaron.intenttunnel.IntentTunnelActivity.java
com.masterbaron.intenttunnel.android.AndroidConfigureActivity.java
com.masterbaron.intenttunnel.android.DeviceSelectActivity.java
com.masterbaron.intenttunnel.glass.DeviceSelectActivity.java
com.masterbaron.intenttunnel.glass.GlassConfigureActivity.java
com.masterbaron.intenttunnel.router.BluetoothService.java
com.masterbaron.intenttunnel.router.ClientService.java
com.masterbaron.intenttunnel.router.Packet.java
com.masterbaron.intenttunnel.router.RouterService.java
com.masterbaron.intenttunnel.router.ServerService.java
com.masterbaron.intenttunnel.router.ServiceReceiver.java
com.masterbaron.musicpusher.MusicActivity.java
ktlab.lib.connection.CommandReceiveThread.java
ktlab.lib.connection.CommandSendThread.java
ktlab.lib.connection.ConnectionCallback.java
ktlab.lib.connection.ConnectionCommand.java
ktlab.lib.connection.ConnectionThread.java
ktlab.lib.connection.Connection.java
ktlab.lib.connection.bluetooth.BluetoothConnectionThread.java
ktlab.lib.connection.bluetooth.BluetoothConnection.java
ktlab.lib.connection.bluetooth.ClientBluetoothConnectionThread.java
ktlab.lib.connection.bluetooth.ClientBluetoothConnection.java
ktlab.lib.connection.bluetooth.ServerBluetoothConnectionThread.java
ktlab.lib.connection.bluetooth.ServerBluetoothConnection.java