Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Android Build
on:
on:
push:
paths-ignore:
- 'ios/**'
Expand All @@ -17,15 +17,15 @@ jobs:
env:
CCACHE_DIR: ${{ github.workspace }}/.ccache
USE_CCACHE: 1
SDK_VERSION: 10.1.0.v20210820083427
SDK_VERSION: 11.1.1.GA
MODULE_ID: appcelerator.ble
steps:
- uses: actions/checkout@v2

- name: Use Node.js 12.x
uses: actions/setup-node@v1
- name: Use Node.js 16.x
uses: actions/setup-node@v3
with:
node-version: '12.x'
node-version: '16.x'

- name: Use JDK 11
uses: actions/setup-java@v2
Expand Down
4 changes: 2 additions & 2 deletions android/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 2.0.0
version: 2.1.0
apiversion: 4
architectures: arm64-v8a armeabi-v7a x86 x86_64
description: Provides BluetoothLowEnergy module for Titanium applications.
Expand All @@ -15,4 +15,4 @@ name: BluetoothLowEnergy
moduleid: appcelerator.ble
guid: 8d0b486f-27ff-4029-a989-56e4a6755e6f
platform: android
minsdk: 10.0.0
minsdk: 9.0.0
11 changes: 10 additions & 1 deletion android/src/appcelerator/ble/AppceleratorBleModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import android.bluetooth.BluetoothManager;
import android.bluetooth.le.ScanSettings;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
Expand Down Expand Up @@ -139,6 +140,14 @@ public class AppceleratorBleModule extends KrollModule
@Kroll.constant
public static final int ATT_INSUFFICIENT_ENCRYPTION_ERROR = BluetoothGatt.GATT_INSUFFICIENT_ENCRYPTION;

@Kroll.constant
public static final int SCAN_MODE_LOW_POWER = ScanSettings.SCAN_MODE_LOW_POWER;
public static final int SCAN_MODE_LOW_LATENCY = ScanSettings.SCAN_MODE_LOW_LATENCY;
public static final int SCAN_MODE_BALANCED = ScanSettings.SCAN_MODE_BALANCED;
public static final int SCAN_MODE_OPPORTUNISTIC = ScanSettings.SCAN_MODE_OPPORTUNISTIC;



public AppceleratorBleModule()
{
super();
Expand Down Expand Up @@ -315,7 +324,7 @@ public boolean isAdvertisingSupported()
@Kroll.method
public TiBLECentralManagerProxy initCentralManager(@Kroll.argument(optional = true) KrollDict dict)
{
return centralManagerProxy = new TiBLECentralManagerProxy();
return centralManagerProxy = new TiBLECentralManagerProxy(dict);
}

@Kroll.method
Expand Down
4 changes: 2 additions & 2 deletions android/src/appcelerator/ble/TiBLECentralManagerProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class TiBLECentralManagerProxy extends KrollProxy
private TiBLEPeripheralProxy peripheralProxy;
private boolean autoConnect;

public TiBLECentralManagerProxy()
public TiBLECentralManagerProxy(KrollDict data)
{
final Context context = TiApplication.getInstance();
BluetoothManager bluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
Expand All @@ -59,7 +59,7 @@ public TiBLECentralManagerProxy()
}
peripheralProvider = new TiBLEPeripheralProvider();
if (btAdapter != null) {
scanManager = ScanManager.build(btAdapter, scanListener);
scanManager = ScanManager.build(btAdapter, scanListener, data);
}

IntentFilter intentFilter = new IntentFilter();
Expand Down
3 changes: 3 additions & 0 deletions android/src/appcelerator/ble/TiBLEPeripheralProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public boolean isConnected()
@Kroll.getProperty
public TiBLEServiceProxy[] services()
{
if (services == null) {
return null;
}
TiBLEServiceProxy[] serviceProxies = new TiBLEServiceProxy[services.size()];
for (int i = 0; i < services.size(); i++) {
serviceProxies[i] = new TiBLEServiceProxy(services.get(i));
Expand Down
6 changes: 4 additions & 2 deletions android/src/appcelerator/ble/scan/ScanManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import android.os.Build;
import android.util.Log;

import org.appcelerator.kroll.KrollDict;

public abstract class ScanManager
{

Expand Down Expand Up @@ -53,12 +55,12 @@ public void onPeripheralFound(BluetoothDevice bluetoothDevice, int i, byte[] byt
listener.onScanDeviceFound(bluetoothDevice, i, bytes);
}

public static ScanManager build(BluetoothAdapter btAdapter, IScanDeviceFoundListener listener)
public static ScanManager build(BluetoothAdapter btAdapter, IScanDeviceFoundListener listener, KrollDict data)
{
ScanManager scanManager;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
scanManager = new ScanManagerAPI21Onwards(btAdapter, listener);
scanManager = new ScanManagerAPI21Onwards(btAdapter, listener, data);
} else {
scanManager = new ScanManager19Onwards(btAdapter, listener);
}
Expand Down
12 changes: 9 additions & 3 deletions android/src/appcelerator/ble/scan/ScanManagerAPI21Onwards.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import android.os.ParcelUuid;
import android.util.Log;
import androidx.annotation.RequiresApi;

import org.appcelerator.kroll.KrollDict;

import java.util.ArrayList;
import java.util.List;

Expand All @@ -25,13 +28,16 @@ public class ScanManagerAPI21Onwards extends ScanManager

public static final String LCAT = "ScanManagerAPI21Onwards";
private final ScanSettings scanSetting;

protected ScanManagerAPI21Onwards(BluetoothAdapter adapter, IScanDeviceFoundListener listener)
private int scanMode = ScanSettings.SCAN_MODE_LOW_POWER;
protected ScanManagerAPI21Onwards(BluetoothAdapter adapter, IScanDeviceFoundListener listener, KrollDict data)
{
super(adapter, listener);

if (data != null && data.containsKeyAndNotNull("scanMode")){
scanMode = data.getInt("scanMode");
}
ScanSettings.Builder scanBuilder = new ScanSettings.Builder();
scanBuilder.setScanMode(ScanSettings.SCAN_MODE_LOW_POWER);
scanBuilder.setScanMode(scanMode);
this.scanSetting = scanBuilder.build();
}

Expand Down
63 changes: 47 additions & 16 deletions apidoc/Ble.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ summary: Add-on Bluetooth Low Energy module
since: "1.0.0"
description: |
Using Bluetooth Low Energy module is used to interact with Bluetooth Low Energy (BLE) devices.

<p class="note">Note: This feature requires a Pro or Enterprise subscription. More infos <a href="https://www.appcelerator.com/pricing/" target="_blank">here</a>!</p>

- Note (IOS): Starting iOS 13, it's mandatory for developers to specify the Privacy Usage Description
Expand All @@ -30,7 +30,7 @@ description: |
scan must specify the service types. wild card scan is not supported in the background.

Note: A detailed information about how to use module in your application, can be found with artifacts at path modules/iphone (platform)/appcelerator.ble/x.y.z (version of module)/documentation/index.html
platforms: [android, iphone, ipad]
platforms: [android, iphone, ipad]

properties:
- name: AUTHORISATION_STATUS_NOT_DETERMINED
Expand All @@ -48,15 +48,15 @@ properties:
platforms: [iphone, ipad]
since: "1.0.0"
value: 1

- name: AUTHORISATION_STATUS_DENIED
type: Number
summary: A state that indicates the user explicitly denied Bluetooth access for this app.
permission: read-only
platforms: [iphone, ipad]
since: "1.0.0"
value: 2

- name: AUTHORISATION_STATUS_ALLOWED_ALWAYS
type: Number
summary: A state that indicates the user has authorized Bluetooth at any time.
Expand All @@ -72,7 +72,7 @@ properties:
platforms: [iphone, ipad, android]
since: "1.0.0"
value: 1 in android and 0 in iOS.

- name: CHARACTERISTIC_PERMISSION_WRITEABLE
type: Number
summary: A permission that indicates a peripheral can write the attribute’s value.
Expand Down Expand Up @@ -263,15 +263,15 @@ properties:
permission: read-only
platforms: [iphone, ipad]
since: "1.0.0"
value: 3
value: 3

- name: MANAGER_STATE_UNKNOWN
type: Number
summary: The Peripheral and Central manager’s state is unknown
permission: read-only
platforms: [iphone, ipad]
since: "1.0.0"
value: 0
value: 0

- name: MANAGER_STATE_RESETTING
type: Number
Expand Down Expand Up @@ -304,7 +304,7 @@ properties:
platforms: [android, iphone, ipad]
since: "1.0.0"
value: 10 in android and 4 in iOS.

- name: MANAGER_STATE_POWERED_ON
type: Number
summary: A state that indicates Bluetooth is currently powered on and available to use.
Expand All @@ -320,7 +320,7 @@ properties:
platforms: [iphone, ipad]
since: "1.0.0"
value: 0

- name: CONNECTION_EVENT_TYPE_PEER_CONNECTED
type: Number
summary: Peer connected event type. This is 'event' type value for CENTREL_MANAGER_EVENT_PERIPHERAL_CONNECTION_EVENT_DID_OCCUR event.
Expand All @@ -334,9 +334,9 @@ properties:
summary: A Boolean value that specifies whether the system should display an alert when connecting a peripheral in the background.
description: |
options object key used in Modules.BLE.CentralManager.connectPeripheral.
The value for this key is an Boolean. This key is useful for apps that haven’t specified the bluetooth-central background mode and can’t display their own alert.
The value for this key is an Boolean. This key is useful for apps that haven’t specified the bluetooth-central background mode and can’t display their own alert.
If more than one app requests a notification for a given peripheral, the one that was most recently in the foreground receives the alert. If the key isn’t specified,
the default value is false.
the default value is false.
permission: read-only
platforms: [iphone, ipad]
since: "1.0.0"
Expand All @@ -346,7 +346,7 @@ properties:
summary: A Boolean value that specifies whether the system should display an alert when disconnecting a peripheral in the background.
description: |
options object key used in Modules.BLE.CentralManager.connectPeripheral.
The value for this key is an Boolean. This key is useful for apps that haven’t specified the bluetooth-central background mode and can’t display their own alert.
The value for this key is an Boolean. This key is useful for apps that haven’t specified the bluetooth-central background mode and can’t display their own alert.
If more than one app requests a notification for a given peripheral, the one that was most recently in the foreground receives the alert. If the key isn’t specified,
the default value is false.
permission: read-only
Expand Down Expand Up @@ -614,7 +614,7 @@ properties:
permission: read-only
platforms: [iphone, ipad]
since: "1.0.0"

- name: PERIPHERAL_MANAGER_CONNECTION_LATENCY_HIGH
type: Number
summary: A latency setting that prioritizes extending battery life over rapid communication.
Expand Down Expand Up @@ -730,7 +730,7 @@ properties:

- name: LOCATION_MANAGER_AUTHORIZATION_STATUS_AUTHORIZED_ALWAYS
type: Number
summary: User has granted authorization to use their location only while they are using your app.
summary: User has granted authorization to use their location only while they are using your app.
permission: read-only
platforms: [iphone, ipad]
since: "1.1.0"
Expand All @@ -741,7 +741,7 @@ properties:
permission: read-only
platforms: [iphone, ipad]
since: "1.1.0"

- name: LOCATION_MANAGER_AUTHORIZATION_STATUS_DENIED
type: Number
summary: User has explicitly denied authorization for this application, or location services are disabled in Settings.
Expand Down Expand Up @@ -812,6 +812,34 @@ properties:
platforms: [iphone, ipad]
since: "1.1.0"

- name: SCAN_MODE_LOW_POWER
type: Number
summary: Perform Bluetooth LE scan in low power mode. This is the default scan mode as it consumes the least power. This mode is enforced if the scanning application is not in foreground.
permission: read-only
platforms: [android]
since: "2.1.0"

- name: SCAN_MODE_LOW_LATENCY
type: Number
summary: Scan using highest duty cycle. It's recommended to only use this mode when the application is running in the foreground.
permission: read-only
platforms: [android]
since: "2.1.0"

- name: SCAN_MODE_OPPORTUNISTIC
type: Number
summary: A special Bluetooth LE scan mode. Applications using this scan mode will passively listen for other scan results without starting BLE scans themselves.
permission: read-only
platforms: [android]
since: "2.1.0"

- name: SCAN_MODE_BALANCED
type: Number
summary: Perform Bluetooth LE scan in balanced power mode. Scan results are returned at a rate that provides a good trade-off between scan frequency and power consumption.
permission: read-only
platforms: [android]
since: "2.1.0"

methods:
- name: initCentralManager
summary: Initializes the module's central manager. This function must be called in an app that acts as a central before any other function can be used.
Expand All @@ -824,6 +852,9 @@ methods:
- name: restoreIdentifier
type: String
summary: A string containing a unique identifier (UID) for the central manager to instantiate.
- name: scanMode
type: Number
summary: Android only. defines the scan mode. Use one of the `SCAN_MODE_*` constants.
returns:
type: Modules.BLE.CentralManager

Expand Down Expand Up @@ -877,7 +908,7 @@ methods:
summary: The permission for descriptor. This parameter is only for android. In android, the
permissions can be different for characteristic and descriptor. If Characteristic have the
read permission then it is only readable and if descriptor have the write permission, then
it is only writable.
it is only writable.
optional: false
returns:
type: Modules.BLE.Descriptor
Expand Down