Skip to content

Commit

Permalink
javax: bluetooth: Finish the file additions.
Browse files Browse the repository at this point in the history
The code in them should now be mostly identical to the javadocs.

Commit redone to add all changes to UUID and general cleanups
to bluetooth as seen on the original hex007 repository's PR
num. 145
  • Loading branch information
AShiningRay committed Sep 20, 2024
1 parent 355a967 commit f010c28
Show file tree
Hide file tree
Showing 15 changed files with 153 additions and 80 deletions.
9 changes: 5 additions & 4 deletions src/javax/bluetooth/DeviceClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
*/
package javax.bluetooth;

public abstract class DeviceClass
public class DeviceClass
{

public DeviceClass(int record) { System.out.println("DeviceClass record:" + record); }

public abstract int getMajorDeviceClass();
public int getMajorDeviceClass() { return 0x200; }

public abstract int getMinorDeviceClass();
public int getMinorDeviceClass() { return 0x04; }

public int getServiceClasses() { return 0x22000 | 0x100000; }

public abstract int getServiceClasses();
}
25 changes: 13 additions & 12 deletions src/javax/bluetooth/DiscoveryAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,29 @@
*/
package javax.bluetooth;

public abstract class DiscoveryAgent
public class DiscoveryAgent
{

public static final int CACHED = 0;
public static final int CACHED = 0x00;

public static final int GIAC = 10390323;
public static final int GIAC = 0x9E8B33;

public static final int LIAC = 10390272;
public static final int LIAC = 0x9E8B00;

public static final int NOT_DISCOVERABLE = 0;
public static final int NOT_DISCOVERABLE = 0x00;

public static final int PREKNOWN = 1;
public static final int PREKNOWN = 0x01;

public abstract boolean cancelInquiry(DiscoveryListener listener);
public boolean cancelInquiry(DiscoveryListener listener) { return false; }

public abstract boolean cancelServiceSearch(int transID);
public boolean cancelServiceSearch(int transID) { return false; }

public abstract RemoteDevice[] retrieveDevices(int option);
public RemoteDevice[] retrieveDevices(int option) { return null; }

public abstract int searchServices(int[] attrSet, UUID[] uuidSet, RemoteDevice btDev, DiscoveryListener discListener);
public int searchServices(int[] attrSet, UUID[] uuidSet, RemoteDevice btDev, DiscoveryListener discListener) { return 0; }

public abstract String selectService(UUID uuid, int security, boolean master);
public String selectService(UUID uuid, int security, boolean master) { return null; }

public abstract boolean startInquiry(int accessCode, DiscoveryListener listener);
public boolean startInquiry(int accessCode, DiscoveryListener listener) { return false; }

}
27 changes: 14 additions & 13 deletions src/javax/bluetooth/DiscoveryListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,31 @@
*/
package javax.bluetooth;

public abstract interface DiscoveryListener
public interface DiscoveryListener
{

public static int INQUIRY_COMPLETED = 0;
static final int INQUIRY_COMPLETED = 0x00;

public static int INQUIRY_ERROR = 7;
static final int INQUIRY_ERROR = 0x07;

public static int INQUIRY_TERMINATED = 5;
static final int INQUIRY_TERMINATED = 0x05;

public static int SERVICE_SEARCH_COMPLETED = 1;
static final int SERVICE_SEARCH_COMPLETED = 0x01;

public static int SERVICE_SEARCH_DEVICE_NOT_REACHABLE = 6;
static final int SERVICE_SEARCH_DEVICE_NOT_REACHABLE = 0x06;

public static int SERVICE_SEARCH_ERROR = 3;
static final int SERVICE_SEARCH_ERROR = 0x03;

public static int SERVICE_SEARCH_NO_RECORDS = 4;
static final int SERVICE_SEARCH_NO_RECORDS = 0x04;

public static int SERVICE_SEARCH_TERMINATED = 2;
static final int SERVICE_SEARCH_TERMINATED = 0x02;

public abstract void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod);
void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod);

public abstract void inquiryCompleted(int discType);
void inquiryCompleted(int discType);

public abstract void servicesDiscovered(int transID, ServiceRecord[] servRecord);
void servicesDiscovered(int transID, ServiceRecord[] servRecord);

public abstract void serviceSearchCompleted(int transID, int respCode);
void serviceSearchCompleted(int transID, int respCode);

}
16 changes: 9 additions & 7 deletions src/javax/bluetooth/L2CAPConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,25 @@
package javax.bluetooth;

import java.io.IOException;
import java.io.InterruptedIOException;

import javax.microedition.io.Connection;

public interface L2CAPConnection extends Connection
{

public static final int DEFAULT_MTU = 672;
static final int DEFAULT_MTU = 0x02A0;

public static final int MINIMUM_MTU = 48;
static final int MINIMUM_MTU = 0x30;

public int getTransmitMTU() throws IOException;
int getTransmitMTU() throws IOException;

public int getReceiveMTU() throws IOException;
int getReceiveMTU() throws IOException;

public void send(byte[] data) throws IOException;
void send(byte[] data) throws IOException, NullPointerException;

public int receive(byte[] inBuf) throws IOException;
int receive(byte[] inBuf) throws IOException, NullPointerException, InterruptedIOException;

boolean ready() throws IOException;

public boolean ready() throws IOException;
}
2 changes: 1 addition & 1 deletion src/javax/bluetooth/L2CAPConnectionNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
public interface L2CAPConnectionNotifier extends Connection
{

public L2CAPConnection acceptAndOpen() throws IOException;
L2CAPConnection acceptAndOpen() throws IOException, ServiceRegistrationException, BluetoothStateException;

}
53 changes: 41 additions & 12 deletions src/javax/bluetooth/LocalDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,57 @@

import javax.microedition.io.Connection;

import java.util.Hashtable;

public abstract class LocalDevice
import javax.obex.SessionNotifier;

public class LocalDevice
{
public abstract String getBluetoothAddress();

public abstract DeviceClass getDeviceClass();
private static LocalDevice locDevc;

private static DiscoveryAgent disAgnt;

private static DeviceClass devcCls;

private static ServiceRecord srvcRcd;

private static Hashtable<String, String> properties = new Hashtable<String, String>();

static
{ /* We won't have functional Bluetooth yet */
properties.put("bluetooth.api.version", "0.0");
properties.put("bluetooth.master.switch", "false");
properties.put("bluetooth.sd.attr.retrievable.max", "0");
properties.put("bluetooth.connected.devices.max", "0");
properties.put("bluetooth.l2cap.receiveMTU.max", "0");
properties.put("bluetooth.sd.trans.max", "0");
properties.put("bluetooth.connected.inquiry.scan", "false");
properties.put("bluetooth.connected.page.scan", "false");
properties.put("bluetooth.connected.inquiry", "false");
properties.put("bluetooth.connected.page", "false");
}

public static String getBluetoothAddress() throws BluetoothStateException { return "000000000000"; }

public static DeviceClass getDeviceClass() { return devcCls; }

public static int getDiscoverable() { return DiscoveryAgent.NOT_DISCOVERABLE; }

public abstract int getDiscoverable();
public static DiscoveryAgent getDiscoveryAgent() { return disAgnt; }

public abstract DiscoveryAgent getDiscoveryAgent();
public static String getFriendlyName() { return "noDevice"; }

public abstract String getFriendlyName();
public static LocalDevice getLocalDevice() throws BluetoothStateException { return locDevc; }

public abstract LocalDevice getLocalDevice();
public static String getProperty(String property) { return properties.get(property); }

public abstract String getProperty(String property);
public static ServiceRecord getRecord(Connection notifier) throws IllegalArgumentException, NullPointerException { return srvcRcd; }

public abstract ServiceRecord getRecord(Connection notifier);
public static boolean isPowerOn() { return false; }

public static boolean isPowerOn() { return false; /* We won't have functional Bluetooth yet */ }
public static boolean setDiscoverable(int mode) throws IllegalArgumentException, BluetoothStateException { return false; }

public abstract boolean setDiscoverable(int mode);
public static void updateRecord(ServiceRecord srvRecord) throws NullPointerException, IllegalArgumentException, ServiceRegistrationException { }

public abstract void updateRecord(ServiceRecord srvRecord);
}
67 changes: 59 additions & 8 deletions src/javax/bluetooth/UUID.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
This file is part of FreeJ2ME.
Expand All @@ -17,16 +16,68 @@
*/
package javax.bluetooth;

public abstract class UUID
public class UUID
{
public UUID(long uuidValue) { System.out.println("UUID Value:" + uuidValue); }

private static final long[] baseUUID = { 0x0000_0000L, 0x0000_1000L, 0x8000_0080L, 0x5F9B_34FBL };

public UUID(String uuidValue, boolean shortUUID) { System.out.println("UUID Value:" + uuidValue); }
private long[] UUIDval = { 0x0000_0000L, 0x0000_0000L, 0x0000_0000L, 0x0000_0000L };

public abstract boolean equals(Object value);

public abstract int hashCode();
public UUID(long uuidValue) throws IllegalArgumentException
{
if (uuidValue < 0L || uuidValue > 0xffffffffL) { throw new IllegalArgumentException("Invalid UUID Value, must be between 0 an (2^32)-1"); }
else
{
UUIDval[0] = uuidValue;
UUIDval[1] = baseUUID[1];
UUIDval[2] = baseUUID[2];
UUIDval[3] = baseUUID[3];
}
}

public abstract String toString();
public UUID(String uuidValue, boolean shortUUID) throws IllegalArgumentException, NullPointerException, NumberFormatException
{
int length = uuidValue.length();

if(length == 0 || length > 32 || (shortUUID && length > 8) )
{
throw new IllegalArgumentException("Received an UUID with invalid length.");
}

if (shortUUID)
{
String formattedUuidValue = String.format("%1$" + 8 + "s", uuidValue).replace(' ', '0');
UUIDval[0] = Long.parseUnsignedLong(formattedUuidValue, 16);
UUIDval[1] = baseUUID[1];
UUIDval[2] = baseUUID[2];
UUIDval[3] = baseUUID[3];
}
else
{
String formattedUuidValue = String.format("%1$" + 32 + "s", uuidValue).replace(' ', '0');
UUIDval[0] = Long.parseUnsignedLong(formattedUuidValue.substring(0, 8), 16);
UUIDval[1] = Long.parseUnsignedLong(formattedUuidValue.substring(8, 16), 16);
UUIDval[2] = Long.parseUnsignedLong(formattedUuidValue.substring(16, 24), 16);
UUIDval[3] = Long.parseUnsignedLong(formattedUuidValue.substring(24, 32), 16);
}
}

@Override
public boolean equals(Object value)
{
if (value == null || (value instanceof UUID) == false) { return false; }

return ((UUID)value).toString().equals(this.toString());
}

@Override
public int hashCode() { return (int)(UUIDval[0] & 0xFFFFFFFF); }

@Override
public String toString()
{
String uuidString = String.format("%08X", UUIDval[0]) + String.format("%08X", UUIDval[1]) + String.format("%08X", UUIDval[2]) + String.format("%08X", UUIDval[3]);
return uuidString.replaceFirst("^0+", "");
}
}

3 changes: 1 addition & 2 deletions src/javax/obex/Authenticator.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
public interface Authenticator
{

PasswordAuthentication onAuthenticationChallenge(String description,
boolean isUserIdRequired, boolean isFullAccess);
PasswordAuthentication onAuthenticationChallenge(String description, boolean isUserIdRequired, boolean isFullAccess);

byte[] onAuthenticationResponse(byte[] userName);

Expand Down
3 changes: 1 addition & 2 deletions src/javax/obex/ClientSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public interface ClientSession extends Connection

HeaderSet disconnect(HeaderSet headers) throws IOException, IllegalArgumentException;

HeaderSet setPath(HeaderSet headers, boolean backup, boolean create) throws IOException,
IllegalArgumentException;
HeaderSet setPath(HeaderSet headers, boolean backup, boolean create) throws IOException, IllegalArgumentException;

HeaderSet delete(HeaderSet headers) throws IOException, IllegalArgumentException;

Expand Down
3 changes: 1 addition & 2 deletions src/javax/obex/HeaderSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ public interface HeaderSet

int[] getHeaderList() throws IOException;

void createAuthenticationChallenge(java.lang.String realm, boolean userID,
boolean access);
void createAuthenticationChallenge(java.lang.String realm, boolean userID, boolean access);

int getResponseCode() throws IOException;

Expand Down
3 changes: 1 addition & 2 deletions src/javax/obex/Operation.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public interface Operation extends Connection

HeaderSet getReceivedHeaders() throws IOException;

void sendHeaders(HeaderSet headers) throws IOException, NullPointerException,
IllegalArgumentException;
void sendHeaders(HeaderSet headers) throws IOException, NullPointerException, IllegalArgumentException;

int getResponseCode() throws IOException;

Expand Down
3 changes: 1 addition & 2 deletions src/javax/obex/PasswordAuthentication.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public class PasswordAuthentication extends Object

byte[] name, pass;

public PasswordAuthentication(byte[] userName, byte[] password) throws
NullPointerException
public PasswordAuthentication(byte[] userName, byte[] password) throws NullPointerException
{
name = userName;
pass = password;
Expand Down
1 change: 0 additions & 1 deletion src/javax/obex/ResponseCodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,4 @@ public class ResponseCodes extends Object

public static final int OBEX_DATABASE_LOCKED = 0xE1;


}
12 changes: 4 additions & 8 deletions src/javax/obex/ServerRequestHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,15 @@ public void setConnectionID(long id) throws IllegalArgumentException { }

public long getConnectionID() { return this.connectionID; }

public int onConnect(HeaderSet request, HeaderSet reply)
{ return ResponseCodes.OBEX_HTTP_OK; }
public int onConnect(HeaderSet request, HeaderSet reply) { return ResponseCodes.OBEX_HTTP_OK; }

public void onDisconnect(HeaderSet request, HeaderSet reply) { }

public int onSetPath(HeaderSet request, HeaderSet reply, boolean backup,
boolean create) { return ResponseCodes.OBEX_HTTP_NOT_IMPLEMENTED; }
public int onSetPath(HeaderSet request, HeaderSet reply, boolean backup, boolean create) { return ResponseCodes.OBEX_HTTP_NOT_IMPLEMENTED; }

public int onDelete(HeaderSet request, HeaderSet reply)
{ return ResponseCodes.OBEX_HTTP_NOT_IMPLEMENTED; }
public int onDelete(HeaderSet request, HeaderSet reply) { return ResponseCodes.OBEX_HTTP_NOT_IMPLEMENTED; }

public int onPut(Operation op)
{ return ResponseCodes.OBEX_HTTP_NOT_IMPLEMENTED; }
public int onPut(Operation op) { return ResponseCodes.OBEX_HTTP_NOT_IMPLEMENTED; }

public void onAuthenticationFailure(byte[] userName) { }

Expand Down
6 changes: 2 additions & 4 deletions src/javax/obex/SessionNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
public interface SessionNotifier extends Connection
{

Connection acceptAndOpen(ServerRequestHandler handler) throws IOException,
NullPointerException;
Connection acceptAndOpen(ServerRequestHandler handler) throws IOException, NullPointerException;

Connection acceptAndOpen(ServerRequestHandler handler, Authenticator auth)
throws IOException, NullPointerException;
Connection acceptAndOpen(ServerRequestHandler handler, Authenticator auth) throws IOException, NullPointerException;

}

0 comments on commit f010c28

Please sign in to comment.