{"gattClientScanFilterDeleteNative", "(IIIIIJJJJLjava/lang/String;Ljava/lang/String;B[B[B)V", (void *) gattClientScanFilterDeleteNative},
{"gattClientScanFilterClearNative", "(II)V", (void *) gattClientScanFilterClearNative},
{"gattClientScanFilterEnableNative", "(IZ)V", (void *) gattClientScanFilterEnableNative},
+ {"gattSetScanParametersNative", "(II)V", (void *) gattSetScanParametersNative},
};
// JNI functions defined in GattService class.
{"gattServerSendResponseNative", "(IIIIII[BI)V", (void *) gattServerSendResponseNative},
{"gattSetAdvDataNative", "(IZZZIII[B[B[B)V", (void *) gattSetAdvDataNative},
- {"gattSetScanParametersNative", "(II)V", (void *) gattSetScanParametersNative},
{"gattTestNative", "(IJJLjava/lang/String;IIIII)V", (void *) gattTestNative},
};
HandleMap mHandleMap = new HandleMap();
private List<UUID> mAdvertisingServiceUuids = new ArrayList<UUID>();
- private static int lastConfiguredScanSetting = Integer.MIN_VALUE;
private int mMaxScanFilters;
/**
mScanManager.flushBatchScanResults(new ScanClient(clientIf, isServer));
}
- // TODO: Move this to ScanManager.
- void configureScanParams(int appIf) {
- if (DBG) Log.d(TAG, "configureScanParams() - queue=" + mScanManager.scanQueue().size());
- int curScanSetting = Integer.MIN_VALUE;
-
- for(ScanClient client : mScanManager.scanQueue()) {
- // ScanClient scan settings are assumed to be monotonically increasing in value for more
- // power hungry(higher duty cycle) operation
- if (client.settings.getScanMode() > curScanSetting) {
- curScanSetting = client.settings.getScanMode();
- }
- }
-
- if (DBG) Log.d(TAG, "configureScanParams() - ScanSetting Scan mode=" + curScanSetting +
- " lastConfiguredScanSetting=" + lastConfiguredScanSetting);
-
- if (curScanSetting != Integer.MIN_VALUE) {
- if (curScanSetting != lastConfiguredScanSetting) {
- int scanWindow, scanInterval;
- switch (curScanSetting){
- case ScanSettings.SCAN_MODE_LOW_POWER:
- scanWindow = SCAN_MODE_LOW_POWER_WINDOW_MS;
- scanInterval = SCAN_MODE_LOW_POWER_INTERVAL_MS;
- break;
- case ScanSettings.SCAN_MODE_BALANCED:
- scanWindow = SCAN_MODE_BALANCED_WINDOW_MS;
- scanInterval = SCAN_MODE_BALANCED_INTERVAL_MS;
- break;
- case ScanSettings.SCAN_MODE_LOW_LATENCY:
- scanWindow = SCAN_MODE_LOW_LATENCY_WINDOW_MS;
- scanInterval = SCAN_MODE_LOW_LATENCY_INTERVAL_MS;
- break;
- default:
- Log.e(TAG, "Invalid value for curScanSetting " + curScanSetting);
- scanWindow = SCAN_MODE_LOW_POWER_WINDOW_MS;
- scanInterval = SCAN_MODE_LOW_POWER_INTERVAL_MS;
- break;
- }
- // convert scanWindow and scanInterval from ms to LE scan units(0.625ms)
- scanWindow = (scanWindow * 1000)/625;
- scanInterval = (scanInterval * 1000)/625;
- // Presence of scan clients means scan is active.
- mScanManager.stopScan(new ScanClient(appIf, false));
- gattSetScanParametersNative(scanInterval, scanWindow);
- lastConfiguredScanSetting = curScanSetting;
- }
- } else {
- lastConfiguredScanSetting = curScanSetting;
- mScanManager.stopScan(new ScanClient(appIf, false));
- if (DBG) Log.d(TAG, "configureScanParams() - queue emtpy, scan stopped");
- }
- }
-
void stopScan(int appIf, boolean isServer) {
enforceAdminPermission();
if (DBG) Log.d(TAG, "stopScan() - queue=" + mScanManager.scanQueue().size());
private native void gattClientUnregisterAppNative(int clientIf);
- private native void gattSetScanParametersNative(int scan_interval, int scan_window);
-
private native void gattClientConnectNative(int clientIf, String address,
boolean isDirect, int transport);
// Timeout for each controller operation.
private static final int OPERATION_TIME_OUT_MILLIS = 500;
+ private static int lastConfiguredScanSetting = Integer.MIN_VALUE;
+
private GattService mService;
private ScanNative mScanNative;
private ClientHandler mHandler;
mScanNative.startBatchScan(client);
} else {
mRegularScanClients.add(client);
- mScanNative.startRegularScan(client);
+ mScanNative.configureRegularScanParams();
}
}
Utils.enforceAdminPermission(mService);
if (mRegularScanClients.contains(client)) {
mRegularScanClients.remove(client);
+ mScanNative.configureRegularScanParams();
mScanNative.stopRegularScan(client);
} else {
mBatchClients.remove(client);
private static final int ALLOW_ALL_FILTER_INDEX = 1;
private static final int ALLOW_ALL_FILTER_SELECTION = 0;
+ /**
+ * Scan params corresponding to scan setting
+ */
+ private static final int SCAN_MODE_LOW_POWER_WINDOW_MS = 500;
+ private static final int SCAN_MODE_LOW_POWER_INTERVAL_MS = 5000;
+ private static final int SCAN_MODE_BALANCED_WINDOW_MS = 2000;
+ private static final int SCAN_MODE_BALANCED_INTERVAL_MS = 5000;
+ private static final int SCAN_MODE_LOW_LATENCY_WINDOW_MS = 5000;
+ private static final int SCAN_MODE_LOW_LATENCY_INTERVAL_MS = 5000;
+
+
// The logic is AND for each filter field.
private static final int LIST_LOGIC_TYPE = 0x1111111;
private static final int FILTER_LOGIC_TYPE = 1;
}
}
+ void configureRegularScanParams() {
+ if (DBG) Log.d(TAG, "configureRegularScanParams() - queue=" + mRegularScanClients.size());
+ int curScanSetting = Integer.MIN_VALUE;
+
+ for(ScanClient client : mRegularScanClients) {
+ // ScanClient scan settings are assumed to be monotonically increasing in value for more
+ // power hungry(higher duty cycle) operation
+ if (client.settings.getScanMode() > curScanSetting) {
+ curScanSetting = client.settings.getScanMode();
+ }
+ }
+
+ if (DBG) Log.d(TAG, "configureRegularScanParams() - ScanSetting Scan mode=" + curScanSetting +
+ " lastConfiguredScanSetting=" + lastConfiguredScanSetting);
+
+ if (curScanSetting != Integer.MIN_VALUE) {
+ if (curScanSetting != lastConfiguredScanSetting) {
+ int scanWindow, scanInterval;
+ switch (curScanSetting){
+ case ScanSettings.SCAN_MODE_LOW_POWER:
+ scanWindow = SCAN_MODE_LOW_POWER_WINDOW_MS;
+ scanInterval = SCAN_MODE_LOW_POWER_INTERVAL_MS;
+ break;
+ case ScanSettings.SCAN_MODE_BALANCED:
+ scanWindow = SCAN_MODE_BALANCED_WINDOW_MS;
+ scanInterval = SCAN_MODE_BALANCED_INTERVAL_MS;
+ break;
+ case ScanSettings.SCAN_MODE_LOW_LATENCY:
+ scanWindow = SCAN_MODE_LOW_LATENCY_WINDOW_MS;
+ scanInterval = SCAN_MODE_LOW_LATENCY_INTERVAL_MS;
+ break;
+ default:
+ Log.e(TAG, "Invalid value for curScanSetting " + curScanSetting);
+ scanWindow = SCAN_MODE_LOW_POWER_WINDOW_MS;
+ scanInterval = SCAN_MODE_LOW_POWER_INTERVAL_MS;
+ break;
+ }
+ // convert scanWindow and scanInterval from ms to LE scan units(0.625ms)
+ scanWindow = (scanWindow * 1000)/625;
+ scanInterval = (scanInterval * 1000)/625;
+ gattSetScanParametersNative(scanInterval, scanWindow);
+ lastConfiguredScanSetting = curScanSetting;
+ }
+ } else {
+ lastConfiguredScanSetting = curScanSetting;
+ if (DBG) Log.d(TAG, "configureRegularScanParams() - queue emtpy, scan stopped");
+ }
+ }
+
+
void startRegularScan(ScanClient client) {
if (mFilterIndexStack.isEmpty() && isFilteringSupported()) {
initFilterIndexStack();
/************************** Regular scan related native methods **************************/
private native void gattClientScanNative(boolean start);
+ private native void gattSetScanParametersNative(int scan_interval,
+ int scan_window);
+
/************************** Filter related native methods ********************************/
private native void gattClientScanFilterAddNative(int client_if,
int filter_type, int filter_index, int company_id,