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 BluetoothObexTransport(BluetoothSocket socket)35 public BluetoothObexTransport(BluetoothSocket socket) { 36 this.mSocket = socket; 37 } 38 39 @Override close()40 public void close() throws IOException { 41 mSocket.close(); 42 } 43 44 @Override openDataInputStream()45 public DataInputStream openDataInputStream() throws IOException { 46 return new DataInputStream(openInputStream()); 47 } 48 49 @Override openDataOutputStream()50 public DataOutputStream openDataOutputStream() throws IOException { 51 return new DataOutputStream(openOutputStream()); 52 } 53 54 @Override openInputStream()55 public InputStream openInputStream() throws IOException { 56 return mSocket.getInputStream(); 57 } 58 59 @Override openOutputStream()60 public OutputStream openOutputStream() throws IOException { 61 return mSocket.getOutputStream(); 62 } 63 64 @Override connect()65 public void connect() throws IOException { 66 } 67 68 @Override create()69 public void create() throws IOException { 70 } 71 72 @Override disconnect()73 public void disconnect() throws IOException { 74 } 75 76 @Override listen()77 public void listen() throws IOException { 78 } 79 isConnected()80 public boolean isConnected() throws IOException { 81 return true; 82 } 83 84 @Override getMaxTransmitPacketSize()85 public int getMaxTransmitPacketSize() { 86 if (mSocket.getConnectionType() != BluetoothSocket.TYPE_L2CAP) { 87 return -1; 88 } 89 return mSocket.getMaxTransmitPacketSize(); 90 } 91 92 @Override getMaxReceivePacketSize()93 public int getMaxReceivePacketSize() { 94 if (mSocket.getConnectionType() != BluetoothSocket.TYPE_L2CAP) { 95 return -1; 96 } 97 return mSocket.getMaxReceivePacketSize(); 98 } 99 getRemoteAddress()100 public String getRemoteAddress() { 101 if (mSocket == null) { 102 return null; 103 } 104 return mSocket.getRemoteDevice().getAddress(); 105 } 106 107 @Override isSrmSupported()108 public boolean isSrmSupported() { 109 if (mSocket.getConnectionType() == BluetoothSocket.TYPE_L2CAP) { 110 return true; 111 } 112 return false; 113 } 114 } 115