BluetoothObexTransport.java revision c4fbd756e2645147470c486ae96f2253f5e13a52
1/* 2* Copyright (C) 2014 Samsung System LSI 3* Licensed under the Apache License, Version 2.0 (the "License"); 4* you may not use this file except in compliance with the License. 5* You may obtain a copy of the License at 6* 7* http://www.apache.org/licenses/LICENSE-2.0 8* 9* Unless required by applicable law or agreed to in writing, software 10* distributed under the License is distributed on an "AS IS" BASIS, 11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12* See the License for the specific language governing permissions and 13* limitations under the License. 14*/ 15 16package com.android.bluetooth; 17 18import android.bluetooth.BluetoothSocket; 19 20import java.io.DataInputStream; 21import java.io.DataOutputStream; 22import java.io.IOException; 23import java.io.InputStream; 24import java.io.OutputStream; 25 26import javax.obex.ObexTransport; 27 28/** 29 * Generic Obex Transport class, to be used in OBEX based Bluetooth 30 * Profiles. 31 */ 32public class BluetoothObexTransport implements ObexTransport { 33 private BluetoothSocket mSocket = null; 34 35 public BluetoothObexTransport(BluetoothSocket socket) { 36 this.mSocket = socket; 37 } 38 39 @Override 40 public void close() throws IOException { 41 mSocket.close(); 42 } 43 44 @Override 45 public DataInputStream openDataInputStream() throws IOException { 46 return new DataInputStream(openInputStream()); 47 } 48 49 @Override 50 public DataOutputStream openDataOutputStream() throws IOException { 51 return new DataOutputStream(openOutputStream()); 52 } 53 54 @Override 55 public InputStream openInputStream() throws IOException { 56 return mSocket.getInputStream(); 57 } 58 59 @Override 60 public OutputStream openOutputStream() throws IOException { 61 return mSocket.getOutputStream(); 62 } 63 64 @Override 65 public void connect() throws IOException { 66 } 67 68 @Override 69 public void create() throws IOException { 70 } 71 72 @Override 73 public void disconnect() throws IOException { 74 } 75 76 @Override 77 public void listen() throws IOException { 78 } 79 80 public boolean isConnected() throws IOException { 81 return true; 82 } 83 84 @Override 85 public int getMaxTransmitPacketSize() { 86 if (mSocket.getConnectionType() != BluetoothSocket.TYPE_L2CAP) { 87 return -1; 88 } 89 return mSocket.getMaxTransmitPacketSize(); 90 } 91 92 @Override 93 public int getMaxReceivePacketSize() { 94 if (mSocket.getConnectionType() != BluetoothSocket.TYPE_L2CAP) { 95 return -1; 96 } 97 return mSocket.getMaxReceivePacketSize(); 98 } 99 100 public String getRemoteAddress() { 101 if (mSocket == null) { 102 return null; 103 } 104 return mSocket.getRemoteDevice().getAddress(); 105 } 106 107 @Override 108 public boolean isSrmSupported() { 109 if (mSocket.getConnectionType() == BluetoothSocket.TYPE_L2CAP) { 110 return true; 111 } 112 return false; 113 } 114} 115