How do I find all connected input devices in a native activity? - android

In my android native activity, I would like to find all of the game controllers connected to the android device.
In input.h, there is a comment above AInputEvent_getDeviceId() that says
/*
* An input device id of 0 indicates that the event didn't come from a physical device;
* other numbers are arbitrary and you shouldn't depend on the values.
* Use the provided input device query API to obtain information about input devices.
*/
Does anyone know which "provided input device query API" the comment is referring to?
If I can't find all the connected devices, then maybe I can wait until AKEYCODE_BUTTON_START is pressed, and then assign that device as Player1...
Thanks!

Related

What is the maximum number of bonded i.e. 'Paired Devices' for Bluetooth LE devices in Android?

The information being sought with this question is I think similar (but not the same) as the information sought here...
"How many devices we can pair via Bluetooth of BLE to Android?"
...and so let's re-ask it a different way:
Let's say we have a use case where someone with a mobile phone may want to connect securely (using industry standard security mechanisms) to a Bluetooth LE device using Pairing. When Pairing occurs, bonding information is stored in the mobile phones - - > Settings - - > Wireless - -> Bluetooth - - > Paired Devices window (dialog).
These 'Paired Devices' will remain present in this list regardless of whether or not active connections are maintained, correct?
And if this answer is correct, how many hundreds or thousands of previously Paired/bonded devices can be accrued in this list before the Android OS (or iPhone's iOS) begins to start to incur performance issues?
My understanding is... neither Android OS or iPhone OS offer programmatic ability to 'clean out' the list of old paired / bonded devices. And mobile phone users who neglect to remove those devices manually could have a challenging task at hand if they've allowed the list of Paired/Bonded devices to get out-of-hand.
Thoughts? Thanks much in advance, --DJ Regan
2018-November-12 Update... New news today: In profiling many BLE paired devices with Android - - > a team mate of mine discovered their Bluetooth radio had become unavailable (as in un-useable) after attempting to pair to the 102nd device+ today. Additional profiling is on-going. So... perhaps this is a use case that neither iOS or Android should be trusted to support? --DJ Regan
From sources I guess 100 is the right number pointing to the max devices you can bond with. Also proved in practise.
/* The number of security records for peer devices. */
#ifndef BTM_SEC_MAX_DEVICE_RECORDS
#define BTM_SEC_MAX_DEVICE_RECORDS 100
#endif
...
/************************************************************************************
** Local type definitions
************************************************************************************/
typedef struct
{
uint32_t num_devices;
bt_bdaddr_t devices[BTM_SEC_MAX_DEVICE_RECORDS];
} btif_bonded_devices_t;
According to the bluetooth implementation, if there are more than 100 device records the allocation will fail.
The responsible BTM_SEC_MAX_DEVICE_RECORDS is defined in bt_target.h:
/* The number of security records for peer devices. */
#ifndef BTM_SEC_MAX_DEVICE_RECORDS
#define BTM_SEC_MAX_DEVICE_RECORDS 100
#endif
This is then used inside btm_dev.c, specifically in BTM_SecAddDevice which returns false after 100 pairings:
/* There is no device record, allocate one.
* If we can not find an empty spot for this one, let it fail. */
for (i = 0; i < BTM_SEC_MAX_DEVICE_RECORDS; i++)
You can connect maximum 8 devices via bluetooth.

BLE: Bonding initiated with already bonded device

I have two BLE devices configured to work as peripheral(s) with simple static pass pairing program and Android phone as client.
1) peripheral_1 address = 0xCECECECECE with static passkey 123456, Device name = Garden, appearance = generic tag.
2) peripheral_2 address = 0xC1C1C1C1C1 with static passkey 123456, Device name = Garden, appearance = generic tag.
Both peripherals IO configured as display only.
I try to connect to peripheral_1 through nrfConnect app, I get pop-up to feed passkey, after giving correct passkey the devices are bonded and all good.
repeated the same procedure with peripheral_2 and all good as well.
Now the real problem comes in. After disconnecting with peripheral_2, I tried to connect to peripheral_1, I get pop again to feed in passkey for already bonded device, why?
Also, after feeding in the passkey I can't read any of the characteristics values unless I disconnect and re-connect to peripheral_1. Why?
Now I repeat with peripheral_2 and I see the same behaviour(client asks to feed in passkey again).
I believe the STK/LTK should be uniquely generated based on the BT address and store in client's database.
Suppose if I change the appearance of one of the peripheral to "unknown" then I see the client does not ask for passkey to re-enter again after bonding. Only with this combination
appearance it works("unknown" vs "").
Any inputs, suggestions are greatly appreciated.

Check SIMCards's PIN

So I've research this subject and I didn't get much information, even though I did read a few threads here like Check SIM PIN with SDK Android and Ask user for SIM Card PIN but neither of them really answer the question - the app I'm trying to write is based on USSD and will run on devices with SIMCards.
I also read the thread Use system PIN dialog in Android application, but I'm not trying to overwrite the OS, I'm just trying to write a simple app that can check an entered String against the SIMCard PIN. On this last thread, a user (a.ch.) said that trying to access or even check the SIMCard PIN number is not allowed by the OS (at least without modifications, I suppose). Can you guys confirm or give me a link that mentions this prohibition?
Also, is it possible to, using only USSD, check the PIN? For example, I only know the MMI code to change PIN:
**04*Current PIN * New PIN * New PIN#.
And this actually returns fail or sucess messages, and if I make Current PIN = New PIN, I can actually identify if the PIN I introduced is correct or not, but I see this on a text message. Does the smartphone return this info in a attribute that I can check? How can I access the return code?
I need all the help I can get :)

Discovering vendor-specific bluetooth devices only

Need to discover or search for Bluetooth devices of certain "vendor-specific" devices.
"vendor-specific" means all devices will have similar starting bits in their "MAC" address
For example, I want to search only for devices whose MAC address starts with 12:34:56:
It should search only for specific series of MAC addresses and list them.
Perform a full discovery, then filter using BluetoothDevice.getAddress()
// Define Vendor ID Prefix
public static final String VENDOR_ID = "12:34:56:"
// First, do a full discovery...
BluetoothAdapter.getDefaultAdapter().startDiscovery()
//...
// Then, for each device returned from discovery...
if ( device.getAddress().startsWith(VENDOR_ID) ) {
// Do Something
}
My Explanation will be based on the BluetoothChat example from the Android SDK, hopefully this is ok, otherwise I would need to write a lot more. If you haven't seen the BluetoothChat example, go take a look, it's really nice!
If you want to use a device where you don't know the complete adress, you'll have to do a complete discovery with BluetoothAdapter.startDiscovery() and search the received addresses for the ones you want to.
If you know the complete address of the device you want to connect to you can directly connect to this device with BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address)

How to implement a Android bluetooth paring without pop up a dialog to get a user permition?

These days , i implement a blue tooth paring function on android platform,say in details:
The master device is Google TV(3.2), the slave device is blue tooth keyboard,both are HID device.
The Keyboard can be easily put in to discoverable status, When the TV bootup first time ,In TV setup guide, i need to let the tv paring with keyboard,
As you know, in generall, enable bluetooth on TV side we need get the user permition, then can connect.Then my question happend is that i don't want to pop up a dialog to get permition, is there some body can tell me how to do ?
Thanks!
I found a simple way - in the Android code tree, in external\bluetooth\bluez\src\device.c:
/* If our IO capability is NoInputNoOutput use medium security
* level (i.e. don't require MITM protection) else use high
* security level */
if (capability == 0x03)
sec_level = BT_IO_SEC_MEDIUM;
else
sec_level = BT_IO_SEC_HIGH;
//david10000 add
if (device_is_david10000_BTDEV(device)) {
sec_level = BT_IO_SEC_MEDIUM;
}
This means we can low level the security to let your special device connect automatically.
Another way is you can program it to auto fill the passkey/pin etc. when you get the Android pair request.
If you have this problem, try this, it works for me.

Categories

Resources