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 16 package com.android.bluetooth; 17 18 import android.bluetooth.BluetoothSocket; 19 20 import java.io.DataInputStream; 21 import java.io.DataOutputStream; 22 import java.io.IOException; 23 import java.io.InputStream; 24 import java.io.OutputStream; 25 26 import javax.obex.ObexTransport; 27 28 /** 29 * Generic Obex Transport class, to be used in OBEX based Bluetooth 30 * Profiles. 31 */ 32 public class BluetoothObexTransport implements ObexTransport { 33 private BluetoothSocket mSocket = null; 34 35 public BluetoothObexTransport(BluetoothSocket socket) { 36 this.mSocket = socket; 37 } 38 39 public void close() throws IOException { 40 mSocket.close(); 41 } 42 43 public DataInputStream openDataInputStream() throws IOException { 44 return new DataInputStream(openInputStream()); 45 } 46 47 public DataOutputStream openDataOutputStream() throws IOException { 48 return new DataOutputStream(openOutputStream()); 49 } 50 51 public InputStream openInputStream() throws IOException { 52 return mSocket.getInputStream(); 53 } 54 55 public OutputStream openOutputStream() throws IOException { 56 return mSocket.getOutputStream(); 57 } 58 59 public void connect() throws IOException { 60 } 61 62 public void create() throws IOException { 63 } 64 65 public void disconnect() throws IOException { 66 } 67 68 public void listen() throws IOException { 69 } 70 71 public boolean isConnected() throws IOException { 72 return true; 73 } 74 75 public int getMaxTransmitPacketSize() { 76 if (mSocket.getConnectionType() != BluetoothSocket.TYPE_L2CAP) { 77 return -1; 78 } 79 return mSocket.getMaxTransmitPacketSize(); 80 } 81 82 public int getMaxReceivePacketSize() { 83 if (mSocket.getConnectionType() != BluetoothSocket.TYPE_L2CAP) { 84 return -1; 85 } 86 return mSocket.getMaxReceivePacketSize(); 87 } 88 89 public String getRemoteAddress() { 90 if (mSocket == null) 91 return null; 92 return mSocket.getRemoteDevice().getAddress(); 93 } 94 95 @Override 96 public boolean isSrmSupported() { 97 if(mSocket.getConnectionType() == BluetoothSocket.TYPE_L2CAP) { 98 return true; 99 } 100 return false; 101 } 102 } 103