109e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly/*
209e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * Copyright (c) 2008-2009, Motorola, Inc.
309e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly *
409e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * All rights reserved.
509e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly *
609e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * Redistribution and use in source and binary forms, with or without
709e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * modification, are permitted provided that the following conditions are met:
809e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly *
909e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * - Redistributions of source code must retain the above copyright notice,
1009e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * this list of conditions and the following disclaimer.
1109e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly *
1209e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * - Redistributions in binary form must reproduce the above copyright notice,
1309e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * this list of conditions and the following disclaimer in the documentation
1409e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * and/or other materials provided with the distribution.
1509e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly *
1609e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * - Neither the name of the Motorola, Inc. nor the names of its contributors
1709e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * may be used to endorse or promote products derived from this software
1809e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * without specific prior written permission.
1909e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly *
2009e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2109e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2209e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2309e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
2409e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2509e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2609e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2709e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2809e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2909e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3009e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly * POSSIBILITY OF SUCH DAMAGE.
3109e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly */
3209e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly
3309e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pellypackage com.android.bluetooth.opp;
3409e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly
3509e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pellyimport java.io.DataInputStream;
3609e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pellyimport java.io.DataOutputStream;
3709e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pellyimport java.io.IOException;
3809e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pellyimport java.io.InputStream;
3909e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pellyimport java.io.OutputStream;
4009e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly
4109e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pellyimport android.bluetooth.BluetoothSocket;
4209e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly
4309e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pellyimport javax.obex.ObexTransport;
4409e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly
4509e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pellypublic class BluetoothOppRfcommTransport implements ObexTransport {
4609e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly
4741ef8d494511c040451f2f887cb31c3100746b61Nick Pelly    private final BluetoothSocket mSocket;
4809e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly
4941ef8d494511c040451f2f887cb31c3100746b61Nick Pelly    public BluetoothOppRfcommTransport(BluetoothSocket socket) {
5009e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly        super();
5141ef8d494511c040451f2f887cb31c3100746b61Nick Pelly        this.mSocket = socket;
5209e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    }
5309e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly
5409e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    public void close() throws IOException {
5541ef8d494511c040451f2f887cb31c3100746b61Nick Pelly        mSocket.close();
5609e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    }
5709e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly
5809e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    public DataInputStream openDataInputStream() throws IOException {
5909e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly        return new DataInputStream(openInputStream());
6009e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    }
6109e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly
6209e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    public DataOutputStream openDataOutputStream() throws IOException {
6309e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly        return new DataOutputStream(openOutputStream());
6409e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    }
6509e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly
6609e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    public InputStream openInputStream() throws IOException {
6741ef8d494511c040451f2f887cb31c3100746b61Nick Pelly        return mSocket.getInputStream();
6809e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    }
6909e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly
7009e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    public OutputStream openOutputStream() throws IOException {
7141ef8d494511c040451f2f887cb31c3100746b61Nick Pelly        return mSocket.getOutputStream();
7209e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    }
7309e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly
7409e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    public void connect() throws IOException {
7509e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    }
7609e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly
7709e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    public void create() throws IOException {
7809e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    }
7909e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly
8009e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    public void disconnect() throws IOException {
8109e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    }
8209e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly
8309e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    public void listen() throws IOException {
8409e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    }
8509e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly
8609e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    public boolean isConnected() throws IOException {
8741ef8d494511c040451f2f887cb31c3100746b61Nick Pelly        //return mSocket.isConnected();
8809e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly        // TODO: add implementation
8909e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly        return true;
9009e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    }
9109e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly
9209e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    public String getRemoteAddress() {
9341ef8d494511c040451f2f887cb31c3100746b61Nick Pelly        if (mSocket == null)
9409e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly            return null;
9541ef8d494511c040451f2f887cb31c3100746b61Nick Pelly        return mSocket.getRemoteDevice().getAddress();
9609e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly    }
9709e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly
9809e9cba205af60b3f42e7a4d891a7d1392e1f2a5Nick Pelly}
99