javax.bluetooth.ServiceRecord Java Examples

The following examples show how to use javax.bluetooth.ServiceRecord. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocalDeviceImpl.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
public void updateRecord(ServiceRecord srvRecord)
        throws ServiceRegistrationException {
    if (DEBUG) {
        System.out.println("LocalDeviceImpl.updateRecord");
    }
    if (srvRecord == null) {
        throw new NullPointerException("Null record specified.");
    }
    if (!(srvRecord instanceof ServiceRecordImpl)) {
        throw new IllegalArgumentException("Invalid service record class.");
    }
    ServiceRecordImpl record = (ServiceRecordImpl)srvRecord;
    BluetoothNotifier notifier = record.getNotifier();
    if (notifier == null) {
        throw new IllegalArgumentException(
                "Service record is not from local SDDB.");
    }
    notifier.updateServiceRecord(record);
}
 
Example #2
Source File: ArdulinkDiscoveryListener.java    From Ardulink-1 with Apache License 2.0 6 votes vote down vote up
@Override
public void serviceSearchCompleted(int arg0, int arg1) {
	
	Map<String, ServiceRecord> ports = new HashMap<String, ServiceRecord>();
	
	for (Entry<RemoteDevice, ServiceRecord[]> entry : services.entrySet()) {
		RemoteDevice remoteDevice = entry.getKey();
		ServiceRecord service = findService(entry.getValue());
		if (service != null) {
			String name = "noname";
			try {
				name = remoteDevice.getFriendlyName(false);
			} catch (Exception e) {
			}

			name += " " + remoteDevice.getBluetoothAddress();
			ports.put(name, service);
		}
	}
	
	bluetoothConnection.setPorts(ports);
	
       synchronized (lock) {
           lock.notify();
       }
}
 
Example #3
Source File: LocalDeviceImpl.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
public ServiceRecord getRecord(Connection notifier) {
    if (notifier == null) {
        throw new NullPointerException("Null notifier specified.");
    }
    if (!(notifier instanceof BluetoothNotifier)) {
        if (!(notifier instanceof SessionNotifierImpl)) {
            throw new IllegalArgumentException("Invalid notifier class.");
        }
        Connection transport =
            ((SessionNotifierImpl)notifier).getTransport();
        if (!(transport instanceof BluetoothNotifier)) {
            throw new IllegalArgumentException("Invalid notifier class.");
        }
        return ((BluetoothNotifier)transport).getServiceRecord();
    }
    return ((BluetoothNotifier)notifier).getServiceRecord();
}
 
Example #4
Source File: ServiceRecordSerializer.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
public static synchronized byte[] serialize(ServiceRecord record) {
    DataElement seq = new DataElement(DataElement.DATSEQ);
    int[] attrIDs = record.getAttributeIDs();
    for (int i = 0; i < attrIDs.length; i++) {
        DataElement attrID = new DataElement(DataElement.U_INT_2,
                attrIDs[i]);
        DataElement attrValue = record.getAttributeValue(attrIDs[i]);
        if (attrValue != null) {
            seq.addElement(attrID);
            seq.addElement(attrValue);
        }
    }
    try {
        return des.serialize(seq);
    } catch (IOException e) {
        return null;
    }
}
 
Example #5
Source File: BTL2CapChannelFactory.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
public ServiceRecord getFromServiceCache( String btAddr, String uuidStr ) {
	ServiceRecord r = null;
	Map< String, ServiceRecord > m = serviceCache.get( btAddr );
	if( m != null ) {
		r = serviceCache.get( btAddr ).get( uuidStr );
	}
	return r;
}
 
Example #6
Source File: BlucatServer.java    From blucat with GNU General Public License v2.0 5 votes vote down vote up
public static void startServerUuid(String uuidValue) throws IOException{
	
	uuidValue = uuidValue.replace("-", "");
	
	UUID uuid = new UUID(uuidValue, false);
	
	String url = "btspp://localhost:" + uuid.toString() + 
			";name=BlueCatPipe"; //;authenticate=false;authorize=false;encrypt=false;master=false";
	
	PrintUtil.verbose("Creating server with UUID " + uuid);

       StreamConnectionNotifier service = (StreamConnectionNotifier) Connector.open(url);

       ServiceRecord rec = LocalDevice.getLocalDevice().getRecord(service);
       
       //PrintUtil.out.println(rec.toString());
       String remoteUrl = rec.getConnectionURL(ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
       remoteUrl = remoteUrl.substring(0, remoteUrl.indexOf(";"));

       PrintUtil.verbose("#" + new Date() + " - Listening at " + remoteUrl);
       
       BlucatConnection.handle(service);

}
 
Example #7
Source File: ListServices.java    From blucat with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void servicesDiscovered(int arg0, ServiceRecord[] arg1) {
	
	//PrintUtil.out.println(arg1);
	for (ServiceRecord servRec : arg1) {
		printServiceRecord(servRec);
		toReturn.add(servRec);
          }
}
 
Example #8
Source File: BluetoothNotifier.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
ServiceRecord getServiceRecord() {
    if (isClosed) {
        throw new IllegalArgumentException("Notifier is closed.");
    }
    // IMPL_NOTE: copy should probably be returned instead of a reference,
    // but the current implementation returns reference to make TCK pass
    // return serviceRec.copy();
    return serviceRec;
}
 
Example #9
Source File: SelectServiceHandler.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
private String selectService(RemoteDevice btDev, UUID uuid, int security,
        boolean master) {
    UUID[] uuidSet = new UUID[] {uuid};
    ServiceSelector selector = new ServiceSelector(null, uuidSet, btDev);
    ServiceRecord serRec = selector.getServiceRecord();

    if (serRec == null) {
        return null;
    } else {
        return serRec.getConnectionURL(security, master);
    }
}
 
Example #10
Source File: ArdulinkDiscoveryListener.java    From Ardulink-1 with Apache License 2.0 5 votes vote down vote up
@Override
public void servicesDiscovered(int transID, ServiceRecord[] serviceRecords) {
	for(ServiceRecord serviceRecord : serviceRecords) {
		RemoteDevice currentDevice = serviceRecord.getHostDevice();
		services.put(currentDevice, serviceRecords);
	}
}
 
Example #11
Source File: ArdulinkDiscoveryListener.java    From Ardulink-1 with Apache License 2.0 5 votes vote down vote up
/**
 * Find service for a device that is named: OBEX Object Push
 * @param serviceRecords
 * @return the service record
 */
private ServiceRecord findService(ServiceRecord[] serviceRecords) {
	ServiceRecord retvalue = null;
	if(serviceRecords.length == 1) {
		retvalue = serviceRecords[0];
	} else {
		for (int i = 0; i < serviceRecords.length; i++) {
            DataElement serviceName = serviceRecords[i].getAttributeValue(0x0100);
            if (serviceName != null && serviceName.getValue().equals("DevB")) {
            	retvalue = serviceRecords[i];
            }
		}
	}
	return retvalue;
}
 
Example #12
Source File: BluetoothService.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void servicesDiscovered( int transID, ServiceRecord[] serviceRecords ) {
	ValueVector vec = value.getChildren( "service" );
	Value v;
	for( ServiceRecord record : serviceRecords ) {
		v = Value.create();
		v.getFirstChild( "location" ).setValue(
			record.getConnectionURL( ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false ) );
		vec.add( v );
	}
}
 
Example #13
Source File: BTServiceDiscoveryListener.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void servicesDiscovered( int transID, ServiceRecord[] serviceRecords ) {
	DataElement e;
	ServiceRecord r;
	Enumeration< DataElement > en;
	boolean keepRun = true;
	for( int i = 0; i < serviceRecords.length && keepRun; i++ ) {
		r = serviceRecords[ i ];
		// Search for the desired UUID
		if( (e = r.getAttributeValue( 0x0001 )) != null ) {
			if( e.getDataType() == DataElement.DATSEQ ) {
				en = (Enumeration< DataElement >) e.getValue();
				Object o;
				while( en.hasMoreElements() ) {
					o = en.nextElement().getValue();
					if( o instanceof UUID ) {
						if( o.equals( uuid ) ) {
							serviceRecord = r;
							keepRun = false;
						}
					}
				}
			} else if( e.getDataType() == DataElement.UUID ) {
				if( e.getValue().equals( uuid ) ) {
					serviceRecord = r;
					keepRun = false;
				}
			}
		}
	}
}
 
Example #14
Source File: BTServiceDiscoveryListener.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
public ServiceRecord getResult() {
	synchronized( this ) {
		while( !completed ) {
			try {
				this.wait();
			} catch( InterruptedException e ) {
			}
		}
	}
	return serviceRecord;
}
 
Example #15
Source File: BTL2CapChannelFactory.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void putInServiceCache( String btAddr, String uuidStr, ServiceRecord record ) {
	if( serviceCache.size() > CACHE_LIMIT ) {
		serviceCache.remove( serviceCache.keySet().iterator().next() );
	}
	Map< String, ServiceRecord > map = serviceCache.computeIfAbsent( btAddr, k -> new HashMap<>() );
	if( map.size() > CACHE_LIMIT ) {
		map.remove( map.keySet().iterator().next() );
	}
	map.put( uuidStr, record );
}
 
Example #16
Source File: ArdulinkDiscoveryListener.java    From Ardulink-1 with Apache License 2.0 4 votes vote down vote up
public Map<RemoteDevice, ServiceRecord[]> getServices() {
	return services;
}
 
Example #17
Source File: BluetoothConnection.java    From Ardulink-1 with Apache License 2.0 4 votes vote down vote up
public void setPorts(Map<String, ServiceRecord> ports) {
	this.ports = ports;
}
 
Example #18
Source File: SelectServiceHandler.java    From pluotsorbet with GNU General Public License v2.0 4 votes vote down vote up
public void servicesDiscovered(int transID, ServiceRecord[] servRecord) {
    throw new RuntimeException("unexpected call");
}
 
Example #19
Source File: ListServices.java    From blucat with GNU General Public License v2.0 4 votes vote down vote up
public static void listServices() throws Exception{
	
	PrintUtil.out.println("#" + "Listing all services");
	@SuppressWarnings("unused")
	Set<ServiceRecord> records = findViaSDP();
}
 
Example #20
Source File: ListServices.java    From blucat with GNU General Public License v2.0 4 votes vote down vote up
private static void printServiceRecord(ServiceRecord rec){
	
	try{
		String name = "";
		if (rec.getAttributeValue(0x0100) != null)
			name = "" + rec.getAttributeValue(0x0100).getValue();
		
		String desc = "";
		if (rec.getAttributeValue(0x0003) != null)
			desc = "" + rec.getAttributeValue(0x0003).getValue();
		
		
		String url = rec.getConnectionURL(ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
		if (url != null)
			url = url.substring(0, url.indexOf(";"));
		
		
		String remoteMac = rec.getHostDevice().getBluetoothAddress();
		String remoteName = rec.getHostDevice().getFriendlyName(false);
		
		PrintUtil.out.print("-,");
		
		if (BlucatState.csv)
			PrintUtil.out.print((new Date()).getTime() + ", " + BluCatUtil.clean(remoteMac) + ", \"" + BluCatUtil.clean(remoteName) + "\", ");
		
		PrintUtil.out.println("\"" + BluCatUtil.clean(name) + "\", \"" + BluCatUtil.clean(desc) + "\", " + BluCatUtil.clean(url));
		
		if (BlucatState.verbose){
			PrintUtil.out.println("  #Attributes Returned " + rec.getAttributeIDs().length );
			for (int i : rec.getAttributeIDs()){
				DataElement val = rec.getAttributeValue(i);
				
				@SuppressWarnings("deprecation")
				String sval = val.toString();
				sval = sval.replace("\n", "\n          ");
				
				PrintUtil.out.println("  #" + String.format("0x%04x",i) + "=" + sval);
			}
		}
		
		
		}catch(Exception e){
			
			PrintUtil.out.println("#Error: " + e.getMessage());
			e.printStackTrace();
		}
}
 
Example #21
Source File: BlucatServer.java    From blucat with GNU General Public License v2.0 4 votes vote down vote up
public static void startServerRFCOMM() throws IOException{
	
	String url = "btspp://localhost:" + BluetoothConsts.RFCOMM_PROTOCOL_UUID + 
			";name=BlueCatPipe;authenticate=false;encrypt=false;master=true";
	
	PrintUtil.verbose("#" + "Creating RFCOMM server");
	
       StreamConnectionNotifier service = (StreamConnectionNotifier) Connector.open(url);

       ServiceRecord rec = LocalDevice.getLocalDevice().getRecord(service);
       
       //PrintUtil.out.println(rec.toString());
       String remoteUrl = rec.getConnectionURL(ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
       remoteUrl = remoteUrl.substring(0, remoteUrl.indexOf(";"));

       PrintUtil.verbose("#" + new Date() + " - Listening at " + remoteUrl);
       
       BlucatConnection.handle(service);
}
 
Example #22
Source File: BluetoothLinkFactory.java    From Ardulink-2 with Apache License 2.0 4 votes vote down vote up
public ServiceRecord getServiceRecord(BluetoothLinkConfig config) {
	ServiceRecord serviceRecord = BluetoothDiscoveryUtil.getDevices().get(config.getDeviceName());
	checkState(serviceRecord != null,
			"The connection could not be made. Device not discovered");
	return serviceRecord;
}
 
Example #23
Source File: BlucatServer.java    From blucat with GNU General Public License v2.0 4 votes vote down vote up
public static void startServerChannel(String port) throws IOException{
	
	String url = null;
	
	
	if (BlucatState.l2cap){
		url = "btl2cap://localhost:" + port + ";name=BlueCatL2CAP";
	}else{
		url = "btspp://localhost:" + port + ";name=BlueCatRFCOM";
	}
	
	PrintUtil.verbose("#" + "Creating server on channel " + port);
	
       Connection service = Connector.open(url);

       ServiceRecord rec = LocalDevice.getLocalDevice().getRecord(service);
       
       //PrintUtil.out.println(rec.toString());
       String remoteUrl = rec.getConnectionURL(ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
       remoteUrl = remoteUrl.substring(0, remoteUrl.indexOf(";"));

       PrintUtil.verbose("#" + new Date() + " - Listening at " + remoteUrl);
       
       BlucatConnection.handle(service);
}
 
Example #24
Source File: ListServices.java    From blucat with GNU General Public License v2.0 2 votes vote down vote up
static Set<ServiceRecord> findViaSDP() throws Exception{
		
		Set<ServiceRecord> toReturn = new HashSet<ServiceRecord>();
		
		UUID[] uuidSet ={
				//new UUID(0x1002),
			//BluetoothConsts.RFCOMM_PROTOCOL_UUID,
			BluetoothConsts.L2CAP_PROTOCOL_UUID
//			BluetoothConsts.OBEX_PROTOCOL_UUID,
//			new UUID(0x0003)

			
			
		};
		
        int[] attrIDs =  new int[] {
                0x0100 // Service name
                ,0x0003
        };
		
        
        RemoteDeviceDiscovery.findDevices();
		Set<RemoteDevice> devices  = RemoteDeviceDiscovery.getDevices();
		
		
		for (RemoteDevice remote : devices){
        
	        synchronized(serviceSearchCompletedEvent) {
	        	
	        	PrintUtil.verbose("#" + "Searching for services on ");
	            PrintUtil.out.println("+," + RemoteDeviceDiscovery.deviceName(remote));
	        
	            LocalDevice.getLocalDevice().getDiscoveryAgent()
	            .searchServices(attrIDs, uuidSet, remote, new ServiceDiscoveryListener(toReturn));
	            
	            serviceSearchCompletedEvent.wait();
	        }
		
		}
		return toReturn;
	}
 
Example #25
Source File: ListServices.java    From blucat with GNU General Public License v2.0 2 votes vote down vote up
public ServiceDiscoveryListener(Set<ServiceRecord> toReturn) {
	
	this.toReturn = toReturn;
}