-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
1,661 additions
and
923 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
easyble/src/main/java/com/ficat/easyble/BleDeviceAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.ficat.easyble; | ||
|
||
import android.bluetooth.BluetoothDevice; | ||
|
||
import com.ficat.easyble.gatt.BleGattImpl; | ||
import com.ficat.easyble.scan.BleScanner; | ||
|
||
|
||
public class BleDeviceAccessor { | ||
/** | ||
* Create a BleDevice instance | ||
* | ||
* @param device BluetoothDevice | ||
* @param key access key | ||
* @return BleDevice instance | ||
*/ | ||
public static BleDevice newBleDevice(BluetoothDevice device, Object key) { | ||
// Thread.currentThread().getStackTrace();//not a good solution (performance / code-obfuscation) | ||
if (device == null) { | ||
throw new IllegalArgumentException("BluetoothDevice is null"); | ||
} | ||
if (!(key instanceof BleScanner.AccessKey)) { | ||
throw new SecurityException("Invalid key"); | ||
} | ||
return new BleDevice(device); | ||
} | ||
|
||
/** | ||
* Access the method {@link BleDevice#setConnectionState(int)} to set connection state | ||
* | ||
* @param device target BleDevice | ||
* @param newConnState new connection state | ||
* @param key access key | ||
*/ | ||
public static void setBleDeviceConnection(BleDevice device, int newConnState, Object key) { | ||
if (device == null) { | ||
throw new IllegalArgumentException("BleDevice is null"); | ||
} | ||
if (!(key instanceof BleGattImpl.AccessKey)) { | ||
throw new SecurityException("Invalid key"); | ||
} | ||
device.setConnectionState(newConnState); | ||
} | ||
|
||
} |
Oops, something went wrong.