My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
/**
* BlueCove - Java library for Bluetooth
*
* Java docs licensed under the Apache License, Version 2.0
* http://www.apache.org/licenses/LICENSE-2.0
* (c) Copyright 2001, 2002 Motorola, Inc. ALL RIGHTS RESERVED.
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
* @version $Id$
*/
package javax.bluetooth;

import java.io.IOException;

import javax.microedition.io.Connection;

import com.intel.bluetooth.DebugLog;
import com.intel.bluetooth.RemoteDeviceHelper;
import com.intel.bluetooth.UtilsJavaSE;

/**
* The <code>RemoteDevice</code> class represents a remote Bluetooth device.
* It provides basic information about a remote device including the device's
* Bluetooth address and its friendly name.
*
*/
public class RemoteDevice {

/**
* A bluetooth hex address
*/
private String addressStr;

/**
* A bluetooth address for internal use
*/
private long addressLong;

/**
* Creates a Bluetooth device based upon its address. The Bluetooth address
* must be 12 hex characters long. Valid characters are 0-9, a-f, and A-F.
* There is no preceding "0x" in the string. For example, valid Bluetooth
* addresses include but are not limited to:<BR>
* <code>008037144297</code><BR>
* <code>00af8300cd0b</code><BR>
* <code>014bd91DA8FC</code>
*
* @param address
* the address of the Bluetooth device as a 12 character hex
* string
*
* @exception NullPointerException
* if <code>address</code> is <code>null</code>
*
* @exception IllegalArgumentException
* if <code>address</code> is the address of the local
* device or is not a valid Bluetooth address
*/
protected RemoteDevice(String address) {
if (address == null) {
throw new NullPointerException("address is null");
}
if (address.length() != 12) {
throw new IllegalArgumentException("Malformed address: " + address + "; should be 12 characters");
}
if (address.startsWith("-")) {
throw new IllegalArgumentException("Malformed address: " + address + "; can't be negative");
}
DebugLog.debug("new RemoteDevice", address);
this.addressStr = RemoteDeviceHelper.formatBluetoothAddress(address);
try {
if (this.addressStr.equals(LocalDevice.getLocalDevice().getBluetoothAddress())) {
throw new IllegalArgumentException("can't use the LocalDevice address.");
}
} catch (BluetoothStateException e) {
throw (RuntimeException) UtilsJavaSE.initCause(new RuntimeException("Can't initialize bluetooth support"), e);
}
this.addressLong = RemoteDeviceHelper.getAddress(address);
}

/**
* Determines if this is a trusted device according to the BCC.
*
* @return <code>true</code> if the device is a trusted device, otherwise
* <code>false</code>
*/
public boolean isTrustedDevice() {
return RemoteDeviceHelper.implIsTrustedDevice(this);
}

/**
* Returns the name of this device. The Bluetooth specification calls this
* name the "Bluetooth device name" or the "user-friendly name". This method
* will only contact the remote device if the name is not known or
* <code>alwaysAsk</code> is <code>true</code>.
*
* @param alwaysAsk
* if <code>true</code> then the device will be contacted for
* its name, otherwise, if there exists a known name for this
* device, the name will be returned without contacting the
* remote device
*
* @return the name of the device, or <code>null</code> if the Bluetooth
* system does not support this feature; if the local device is able
* to contact the remote device, the result will never be
* <code>null</code>; if the remote device does not have a name
* then an empty string will be returned
*
* @exception IOException
* if the remote device can not be contacted or the remote
* device could not provide its name
*/
public String getFriendlyName(boolean alwaysAsk) throws IOException {
return RemoteDeviceHelper.implGetFriendlyName(this, this.addressLong, alwaysAsk);
}

/**
* Retrieves the Bluetooth address of this device. The Bluetooth address
* will be 12 characters long. Valid characters are 0-9 and A-F. This method
* will never return <code>null</code>.
*
* @return the Bluetooth address of the remote device
*/
public final String getBluetoothAddress() {
return this.addressStr;
}

/**
* Determines if two <code>RemoteDevice</code>s are equal. Two devices
* are equal if they have the same Bluetooth device address.
*
* @param obj
* the object to compare to
*
* @return <code>true</code> if both devices have the same Bluetooth
* address; <code>false</code> if both devices do not have the
* same address; <code>false</code> if <code>obj</code> is
* <code>null</code>; <code>false</code> if <code>obj</code>
* is not a <code>RemoteDevice</code>
*/
public boolean equals(Object obj) {
return obj != null && obj instanceof RemoteDevice && ((RemoteDevice) obj).addressLong == addressLong;
}

/**
* Computes the hash code for this object. This method will return the same
* value when it is called multiple times on the same object.
*
* @return the hash code for this object
*/
public int hashCode() {
return new Long(addressLong).hashCode();
}

/**
* Retrieves the Bluetooth device that is at the other end of the Bluetooth
* Serial Port Profile connection, L2CAP connection, or OBEX over RFCOMM
* connection provided. This method will never return <code>null</code>.
*
* @param conn
* the Bluetooth Serial Port connection, L2CAP connection, or
* OBEX over RFCOMM connection whose remote Bluetooth device is
* needed
*
* @return the remote device involved in the connection
*
* @exception IllegalArgumentException
* if <code>conn</code> is not a Bluetooth Serial Port
* Profile connection, L2CAP connection, or OBEX over RFCOMM
* connection; if <code>conn</code> is a
* <code>L2CAPConnectionNotifier</code>,
* <code>StreamConnectionNotifier</code>, or
* <code>SessionNotifier</code>
*
* @exception IOException
* if the connection is closed
*
* @exception NullPointerException
* if <code>conn</code> is <code>null</code>
*/
public static RemoteDevice getRemoteDevice(Connection conn) throws IOException {
return RemoteDeviceHelper.implGetRemoteDevice(conn);
}

/**
* Attempts to authenticate this <code>RemoteDevice</code>.
* Authentication is a means of verifying the identity of a remote device.
* Authentication involves a device-to-device challenge and response scheme
* that requires a 128-bit common secret link key derived from a PIN code
* shared by both devices. If either side's PIN code does not match, the
* authentication process fails and the method returns <code>false</code>.
* The method will also return <code>false</code> if authentication is
* incompatible with the current security settings of the local device
* established by the BCC, if the stack does not support authentication at
* all, or if the stack does not support authentication subsequent to
* connection establishment.
*
* <p>
* If this <code>RemoteDevice</code> has previously been authenticated,
* then this method returns <code>true</code> without attempting to
* re-authenticate this <code>RemoteDevice</code>.
*
* @return <code>true</code> if authentication is successful; otherwise
* <code>false</code>
*
* @exception IOException
* if there are no open connections between the local device
* and this <code>RemoteDevice</code>
*/
public boolean authenticate() throws IOException {
return RemoteDeviceHelper.authenticate(this);
}

/**
* Determines if this <code>RemoteDevice</code> should be allowed to
* continue to access the local service provided by the
* <code>Connection</code>. In Bluetooth, authorization is defined as the
* process of deciding if device X is allowed to access service Y. The
* implementation of the <code>authorize(Connection conn)</code> method
* asks the Bluetooth Control Center (BCC) to decide if it is acceptable for
* <code>RemoteDevice</code> to continue to access a local service over
* the connection <code>conn</code>. In devices with a user interface,
* the BCC is expected to consult with the user to obtain approval.
*
* <p>
* Some Bluetooth systems may allow the user to permanently authorize a
* remote device for all local services. When a device is authorized in this
* way, it is known as a "trusted device" -- see
* {@link #isTrustedDevice() isTrustedDevice()}.
*
* <p>
* The <code>authorize()</code> method will also check that the identity
* of the <code>RemoteDevice</code> can be verified through
* authentication. If this <code>RemoteDevice</code> has been authorized
* for <code>conn</code> previously, then this method returns
* <code>true</code> without attempting to re-authorize this
* <code>RemoteDevice</code>.
*
* @see #isTrustedDevice
*
* @param conn
* the connection that this <code>RemoteDevice</code> is using
* to access a local service
*
* @return <code>true</code> if this <code>RemoteDevice</code> is
* successfully authenticated and authorized, otherwise
* <code>false</code> if authentication or authorization fails
*
* @exception IllegalArgumentException
* if <code>conn</code> is not a connection to this
* <code>RemoteDevice</code>, or if the local device
* initiated the connection, i.e., the local device is the
* client rather than the server. This exception is also
* thrown if <code>conn</code> was created by
* <code>RemoteDevice</code> using a scheme other than
* <code>btspp</code>, <code>btl2cap</code>, or
* <code>btgoep</code>. This exception is thrown if
* <code>conn</code> is a notifier used by a server to wait
* for a client connection, since the notifier is not a
* connection to this <code>RemoteDevice</code>.
*
* @exception IOException
* if <code>conn</code> is closed
*/
public boolean authorize(javax.microedition.io.Connection conn) throws IOException {
return RemoteDeviceHelper.implAuthorize(this, conn);
}

/**
* Attempts to turn encryption on or off for an existing connection. In the
* case where the parameter <code>on</code> is <code>true</code>, this
* method will first authenticate this <code>RemoteDevice</code> if it has
* not already been authenticated. Then it will attempt to turn on
* encryption. If the connection is already encrypted then this method
* returns <code>true</code>. Otherwise, when the parameter
* <code>on</code> is <code>true</code>, either:
* <UL>
* <LI> the method succeeds in turning on encryption for the connection and
* returns <code>true</code>, or
* <LI> the method was unsuccessful in turning on encryption and returns
* <code>false</code>. This could happen because the stack does not
* support encryption or because encryption conflicts with the user's
* security settings for the device.
* </UL>
*
* <p>
* In the case where the parameter <code>on</code> is <code>false</code>,
* there are again two possible outcomes:
* <UL>
* <LI> encryption is turned off on the connection and <code>true</code>
* is returned, or
* <LI> encryption is left on for the connection and <code>false</code> is
* returned.
* </UL>
* Encryption may be left on following <code>encrypt(conn,
* false)</code>
* for a variety of reasons. The user's current security settings for the
* device may require encryption or the stack may not have a mechanism to
* turn off encryption. Also, the BCC may have determined that encryption
* will be kept on for the physical link to this <code>RemoteDevice</code>.
* The details of the BCC are implementation dependent, but encryption might
* be left on because other connections to the same device need encryption.
* (All of the connections over the same physical link must be encrypted if
* any of them are encrypted.)
*
* <p>
* While attempting to turn encryption off may not succeed immediately
* because other connections need encryption on, there may be a delayed
* effect. At some point, all of the connections over this physical link
* needing encryption could be closed or also have had the method
* <code>encrypt(conn, false)</code> invoked for them. In this case, the
* BCC may turn off encryption for all connections over this physical link.
* (The policy used by the BCC is implementation dependent.) It is
* recommended that applications do <code>encrypt(conn,
* false)</code> once
* they no longer need encryption to allow the BCC to determine if it can
* reduce the overhead on connections to this <code>RemoteDevice</code>.
*
* <p>
* The fact that <code>encrypt(conn, false)</code> may not succeed in
* turning off encryption has very few consequences for applications. The
* stack handles encryption and decryption, so the application does not have
* to do anything different depending on whether the connection is still
* encrypted or not.
*
* @param conn
* the connection whose need for encryption has changed
*
* @param on
* <code>true</code> attempts to turn on encryption;
* <code>false</code> attempts to turn off encryption
*
* @return <code>true</code> if the change succeeded, otherwise
* <code>false</code> if it failed
*
* @exception IOException
* if <code>conn</code> is closed
*
* @exception IllegalArgumentException
* if <code>conn</code> is not a connection to this
* <code>RemoteDevice</code>; if <code>conn</code> was
* created by the client side of the connection using a
* scheme other than <code>btspp</code>,
* <code>btl2cap</code>, or <code>btgoep</code> (for
* example, this exception will be thrown if
* <code>conn</code> was created using the
* <code>file</code> or <code>http</code> schemes.); if
* <code>conn</code> is a notifier used by a server to wait
* for a client connection, since the notifier is not a
* connection to this <code>RemoteDevice</code>
*/
public boolean encrypt(javax.microedition.io.Connection conn, boolean on) throws IOException {
return RemoteDeviceHelper.implEncrypt(this, conn, on);
}

/**
* Determines if this <code>RemoteDevice</code> has been authenticated.
* <P>
* A device may have been authenticated by this application or another
* application. Authentication applies to an ACL link between devices and
* not on a specific L2CAP, RFCOMM, or OBEX connection. Therefore, if
* <code>authenticate()</code> is performed when an L2CAP connection is
* made to device A, then <code>isAuthenticated()</code> may return
* <code>true</code> when tested as part of making an RFCOMM connection to
* device A.
*
* @return <code>true</code> if this <code>RemoteDevice</code> has
* previously been authenticated; <code>false</code> if it has not
* been authenticated or there are no open connections between the
* local device and this <code>RemoteDevice</code>
*/
public boolean isAuthenticated() {
return RemoteDeviceHelper.implIsAuthenticated(this);
}

/**
* Determines if this <code>RemoteDevice</code> has been authorized
* previously by the BCC of the local device to exchange data related to the
* service associated with the connection. Both clients and servers can call
* this method. However, for clients this method returns <code>false</code>
* for all legal values of the <code>conn</code> argument.
*
* @param conn
* a connection that this <code>RemoteDevice</code> is using to
* access a service or provide a service
*
* @return <code>true</code> if <code>conn</code> is a server-side
* connection and this <code>RemoteDevice</code> has been
* authorized; <code>false</code> if <code>conn</code> is a
* client-side connection, or a server-side connection that has not
* been authorized
*
* @exception IllegalArgumentException
* if <code>conn</code> is not a connection to this
* <code>RemoteDevice</code>; if <code>conn</code> was
* not created using one of the schemes <code>btspp</code>,
* <code>btl2cap</code>, or <code>btgoep</code>; or if
* <code>conn</code> is a notifier used by a server to wait
* for a client connection, since the notifier is not a
* connection to this <code>RemoteDevice</code>.
*
* @exception IOException
* if <code>conn</code> is closed
*/
public boolean isAuthorized(javax.microedition.io.Connection conn) throws IOException {
return RemoteDeviceHelper.implIsAuthorized(this, conn);
}

/**
* Determines if data exchanges with this <code>RemoteDevice</code> are
* currently being encrypted.
* <P>
* Encryption may have been previously turned on by this or another
* application. Encryption applies to an ACL link between devices and not on
* a specific L2CAP, RFCOMM, or OBEX connection. Therefore, if
* <code>encrypt()</code> is performed with the <code>on</code>
* parameter set to <code>true</code> when an L2CAP connection is made to
* device A, then <code>isEncrypted()</code> may return <code>true</code>
* when tested as part of making an RFCOMM connection to device A.
*
* @return <code>true</code> if data exchanges with this
* <code>RemoteDevice</code> are being encrypted;
* <code>false</code> if they are not being encrypted, or there
* are no open connections between the local device and this
* <code>RemoteDevice</code>
*/
public boolean isEncrypted() {
return RemoteDeviceHelper.implIsEncrypted(this);
}

}

Change log

r2732 by skarzhevskyy on Feb 12, 2009   Diff
corrections to java docs
Go to: 
Project members, sign in to write a code review

Older revisions

r2530 by skarzhevskyy on Dec 9, 2008   Diff
sync package javax.bluetooth javadocs
with JSR-82 1.1.1
r2471 by skarzhevskyy on Nov 30, 2008   Diff
Change license to Apache License,
Version 2.0, Update headers
r2466 by skarzhevskyy on Nov 30, 2008   Diff
corrections to
IllegalArgumentException messages
All revisions of this file

File info

Size: 19301 bytes, 447 lines

File properties

svn:mime-type
text/plain
svn:eol-style
native
svn:keywords
Date Author Id Revision
Powered by Google Project Hosting