frameworks/base
Révision | c0b2dd0f42771c10fc2a97f36054ff0b3fa37118 (tree) |
---|---|
l'heure | 2015-12-22 16:22:07 |
Auteur | Grzegorz Kolodziejczyk <grzegorz.kolodziejczyk@tiet...> |
Commiter | Chih-Wei Huang |
Add support for setting passkey as pairing variant
This is needed if pairing variant is passkey entry.
Change-Id: I8f3efbc90757ac77414a9e86d7c29326c25c12ad
@@ -6202,6 +6202,7 @@ package android.bluetooth { | ||
6202 | 6202 | method public int getType(); |
6203 | 6203 | method public android.os.ParcelUuid[] getUuids(); |
6204 | 6204 | method public boolean setPairingConfirmation(boolean); |
6205 | + method public boolean setPasskey(int); | |
6205 | 6206 | method public boolean setPin(byte[]); |
6206 | 6207 | method public void writeToParcel(android.os.Parcel, int); |
6207 | 6208 | field public static final java.lang.String ACTION_ACL_CONNECTED = "android.bluetooth.device.action.ACL_CONNECTED"; |
@@ -6231,6 +6232,7 @@ package android.bluetooth { | ||
6231 | 6232 | field public static final java.lang.String EXTRA_PREVIOUS_BOND_STATE = "android.bluetooth.device.extra.PREVIOUS_BOND_STATE"; |
6232 | 6233 | field public static final java.lang.String EXTRA_RSSI = "android.bluetooth.device.extra.RSSI"; |
6233 | 6234 | field public static final java.lang.String EXTRA_UUID = "android.bluetooth.device.extra.UUID"; |
6235 | + field public static final int PAIRING_VARIANT_PASSKEY = 1; // 0x1 | |
6234 | 6236 | field public static final int PAIRING_VARIANT_PASSKEY_CONFIRMATION = 2; // 0x2 |
6235 | 6237 | field public static final int PAIRING_VARIANT_PIN = 0; // 0x0 |
6236 | 6238 | } |
@@ -6416,6 +6416,7 @@ package android.bluetooth { | ||
6416 | 6416 | method public boolean isConnected(); |
6417 | 6417 | method public boolean isEncrypted(); |
6418 | 6418 | method public boolean setPairingConfirmation(boolean); |
6419 | + method public boolean setPasskey(int); | |
6419 | 6420 | method public boolean setPin(byte[]); |
6420 | 6421 | method public void writeToParcel(android.os.Parcel, int); |
6421 | 6422 | field public static final java.lang.String ACTION_ACL_CONNECTED = "android.bluetooth.device.action.ACL_CONNECTED"; |
@@ -6445,6 +6446,7 @@ package android.bluetooth { | ||
6445 | 6446 | field public static final java.lang.String EXTRA_PREVIOUS_BOND_STATE = "android.bluetooth.device.extra.PREVIOUS_BOND_STATE"; |
6446 | 6447 | field public static final java.lang.String EXTRA_RSSI = "android.bluetooth.device.extra.RSSI"; |
6447 | 6448 | field public static final java.lang.String EXTRA_UUID = "android.bluetooth.device.extra.UUID"; |
6449 | + field public static final int PAIRING_VARIANT_PASSKEY = 1; // 0x1 | |
6448 | 6450 | field public static final int PAIRING_VARIANT_PASSKEY_CONFIRMATION = 2; // 0x2 |
6449 | 6451 | field public static final int PAIRING_VARIANT_PIN = 0; // 0x0 |
6450 | 6452 | } |
@@ -29,6 +29,8 @@ import android.util.Log; | ||
29 | 29 | import java.io.IOException; |
30 | 30 | import java.io.UnsupportedEncodingException; |
31 | 31 | import java.util.UUID; |
32 | +import java.nio.ByteBuffer; | |
33 | +import java.nio.ByteOrder; | |
32 | 34 | |
33 | 35 | /** |
34 | 36 | * Represents a remote Bluetooth device. A {@link BluetoothDevice} lets you |
@@ -272,6 +274,7 @@ public final class BluetoothDevice implements Parcelable { | ||
272 | 274 | * intents to indicate pairing method used. Possible values are: |
273 | 275 | * {@link #PAIRING_VARIANT_PIN}, |
274 | 276 | * {@link #PAIRING_VARIANT_PASSKEY_CONFIRMATION}, |
277 | + * {@link #PAIRING_VARIANT_PASSKEY}, | |
275 | 278 | */ |
276 | 279 | public static final String EXTRA_PAIRING_VARIANT = |
277 | 280 | "android.bluetooth.device.extra.PAIRING_VARIANT"; |
@@ -483,7 +486,6 @@ public final class BluetoothDevice implements Parcelable { | ||
483 | 486 | |
484 | 487 | /** |
485 | 488 | * The user will be prompted to enter a passkey |
486 | - * @hide | |
487 | 489 | */ |
488 | 490 | public static final int PAIRING_VARIANT_PASSKEY = 1; |
489 | 491 |
@@ -1094,13 +1096,27 @@ public final class BluetoothDevice implements Parcelable { | ||
1094 | 1096 | return false; |
1095 | 1097 | } |
1096 | 1098 | |
1097 | - /** @hide */ | |
1099 | + /** | |
1100 | + * Set the passkey during pairing when the pairing method is | |
1101 | + * {@link #PAIRING_VARIANT_PASSKEY} | |
1102 | + * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. | |
1103 | + * | |
1104 | + * @return true if passkey has been set | |
1105 | + * flase for error | |
1106 | + */ | |
1098 | 1107 | public boolean setPasskey(int passkey) { |
1099 | - //TODO(BT) | |
1100 | - /* | |
1108 | + if (sService == null) { | |
1109 | + Log.e(TAG, "BT not enabled. Cannot set Remote Device passkey"); | |
1110 | + return false; | |
1111 | + } | |
1112 | + ByteBuffer buff = ByteBuffer.allocate(5); | |
1113 | + buff.order(ByteOrder.nativeOrder()); | |
1114 | + buff.putInt(passkey); | |
1115 | + byte[] passkeyByte = buff.array(); | |
1116 | + | |
1101 | 1117 | try { |
1102 | - return sService.setPasskey(this, true, 4, passkey); | |
1103 | - } catch (RemoteException e) {Log.e(TAG, "", e);}*/ | |
1118 | + return sService.setPasskey(this, true, passkeyByte.length, passkeyByte); | |
1119 | + } catch (RemoteException e) {Log.e(TAG, "", e);} | |
1104 | 1120 | return false; |
1105 | 1121 | } |
1106 | 1122 |