Android JellyBean and P2P support - android

I am analysing Android JellyBean 4.3 source code.I could find the varialbe p2p_supported in HAL layer for Wi-Fi Direct support. In the below code snippet from wifi_ath.c
int wifi_start_supplicant(int p2p_supported)
{
if (p2p_supported)
{
strcpy(supplicant_name, P2P_SUPPLICANT_NAME);
strcpy(supplicant_prop_name, P2P_PROP_NAME); // for P2P support
.......................
}
else {
strcpy(supplicant_name, SUPPLICANT_NAME);
strcpy(supplicant_prop_name, SUPP_PROP_NAME); //for station support
}
The values of the macros are:
P2P_SUPPLICANT_NAME = p2p_supplicant ,P2P_PROP_NAME= init.svc.p2p_supplicant
SUPPLICANT_NAME=wpa_supplicant ,SUPP_PROP_NAME=init.svc.wpa_supplicant
Even while connecting in station mode the if part is getting executed and I could not make the WiFi up. Where in the code exactly p2p_supported variable is enabled and disabled so that both the P2P and Wi-Fi works smoothly?

From Jelly Bean(4.1) you only need to turn WiFi on to use WiFi Direct functionality, though using both together depends upon whether your chip supports it.(For that see this SO question)

Related

is it possible to recognize wifi network inside app with xamarin

I'm just wondering if it's possible for an app to recognize what network you are connected to. I'm making and app where you have to be connected to a specific network before the app lets you use it's functions, but I'm wondering if that is even possible, I am using xamarin but I can program with androidand a little bit ofswift, so I also want to know if it's possible forxamarinto do this, if it's possible with android studio andxcode. I am usingxamarin.forms` by the way.
This used to be disabled for security reasons but after iOS 4.0 Apple enabled it.
Although this question is for Xcode, the answer can be applied in Xamarin.
This is a sample application built with the feature in question, although it is for Xamarin.Mac
Use function CNCopyCurrentNetworkInfo.
This is possible but you will have to do native implementations to access the specific platform apis. For Android you will need to use WifiManager (https://developer.android.com/reference/android/net/wifi/WifiManager) and for iOS you could possibly use NEHotspotConfiguration (https://developer.apple.com/documentation/networkextension/nehotspotconfiguration).
I have used WifiManager for Android to connect to a specific Wifi network programmatically.
You can use "CrossConnectivity" plugin in Xamarin by adding the package "xam.plugin.connectivity". Below is the code to check connectivity. From the connectionType property you can detect to which network the device is connected and perform operations accordingly. `
CrossConnectivity.Current.ConnectivityTypeChanged += (sender, e) =>
{
var wifi = Plugin.Connectivity.Abstractions.ConnectionType.WiFi;
var cellular = Plugin.Connectivity.Abstractions.ConnectionType.Cellular;
var connectionTypes = CrossConnectivity.Current.ConnectionTypes;
if (connectionTypes.Contains(cellular))
{
//Do operations with cellular
}
else if (connectionTypes.Contains(wifi))
{
//Do operations with wifi
}
};`

How can i check my android device support wifi direct?

I am working with android wifi direct demo application. After installation in my device I noticed that it is not working as expected.
I am confused, does my device support wifi direct or special hardware feature required for wifi direct? My device is local walton brand and API level 16. After reading android documentation i know that Wi-Fi Direct added in API level 14 doesn't need a wireless access point.
My other question is if in a place where no wifi zone is created using wifi direct two or more device communicate with each other. in summing my problem, i need to know if my device not support wifi direct what i do to run wifi demo. Thanks in advance.
you should check in this way, because some devices do not support WiFi direct but still keep the WifiP2pManager code in framework.
private boolean isWifiDirectSupported(Context ctx) {
PackageManager pm = ctx.getPackageManager();
FeatureInfo[] features = pm.getSystemAvailableFeatures();
for (FeatureInfo info : features) {
if (info != null && info.name != null && info.name.equalsIgnoreCase("android.hardware.wifi.direct")) {
return true;
}
}
return false;
}
In addition to StoneLam's answer, which is probably the most robust, a quicker-and-dirtier method would be to go ahead and call WifiP2pManager.discoverPeers() as you would if WiFi Direct were supported. The latter takes an ActionListener with an onFailure() callback. The failure reason passed to onFailure(int reason) can be P2P_UNSUPPORTED, which would answer your question: the device doesn't support WiFi Direct.
A call to onSuccess() would mean the device does support WiFi Direct. A call to onFailure() with other failure reasons would probably be inconclusive as to the device's capabilities.
Android 4.0 and later support Wi-Fi Direct. However, some of 4.x devices does not support Wi-Fi Direct because of it's WiFi driver
you can check your device using the code below
mManager.discoverPeers(mChannel, new ActionListener() {
#Override
public void onSuccess() {
//onSuccess
}
#Override
public void onFailure(int reason) {
//onFailure
}
});
If your device support Wi-Fi Direct, onSuccess will be called after a moment. Otherwise, onFailure will be called.
Above API 21 you can directly use isP2pSupported () from WifiManager class.
For lower Api's you can use PackageManager class,
if(getPackageManager().hasSystemFeature("android.hardware.wifi.direct"))
//Wifi direct available
Checking if Wifi P2P is supported:
In code: If you cannot get the system service, it's not supported
mManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
Without code: Check whether the option is in the Settings app (Under Wifi)
As per your second question: yes, devices connected via wifi direct communicate without any existing wifi network.

Android Bluetooth PIN pairing without user interface on Android 4.2+

There are similar questions to this here already, but the answers and suggestions relate to older versions of Android. I understand that the bluetooth stack has been completely revised from 4.2 onwards and older solutions do not work anymore.
I have tried all the older solutions to no avail. the use of the private APIs no longer works because they have changed. I dont mind using private APIs but it must work on the newest versions and later (ie API 17+)
I am trying to do the following:
set up a bluetooth pairing between an Android device and an embedded device using legacy PIN pairing without the embedded device being discoverable nor the user having to manually enter the PIN. In fact I want no PIN entry dialog box at all.
The plan is that the two devices have a predefined shared secret PIN, so that I can perform the pairing programmatically and then open an RFCOMM connection between them. All of this without UI. The hardware address of the embedded device is known to the Android program.
There is no security issue here. the project involves just talking to a nearyby, small embedded device through BT as simple as possible.
Ideas that might work on Android 4.2 (Jelly Bean) most welcome, thanks.
turns out some of the problem was inside the embedded device. on the Android side, the following works:
BluetoothSocket s = null;
try
{
s = device.createInsecureRfcommSocketToServiceRecord(SerialPortServiceClass_UUID);
}
catch (IOException e)
{
Log.e(TAG, "BT connect failed", e);
return false;
}
where
private static final UUID SerialPortServiceClass_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");

how to remove the bluetooth module from android

I have a device which runs android 4.1.
But the device does not have a bluetooth, so I want to remove bluetooth related items from the 4.1 platform (like sharing menu, setting items which contain "bluetooth ").
but it seems a miscellaneous work ( settings, filesharing , ).
Is there any method that can tell the platform that the current devices don't have a bluetooth only by config some files???
in Android 4.1 Settings.java (packages/apps/settings/) the code
// Remove Bluetooth Settings if Bluetooth service is not available.
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
target.remove(header);
}
is used to judge if the devices support Bluetooth service.
the configing files are under systemtem/etc/permissions/xxxx.xml which are copied from /framework/base/data/etc/xxx.xml
PackageManager.FEATURE_BLUETOOTH = "android.hardware.wifi"
PackageManager.FEATURE_BLUETOOTH = "android.hardware.bluetooth"
Since it only provides a method to flag whether the devices support Bluetooth service, the View items that contain Bluetooth should be removed separately.

Android Bluetooth Low Energy Motorola API pairing

I am working on using the BT 4.0 API that Motorola has provided with the RAZR. In one of their documents it states to use the Android API to pair before connecting and using their framework. Per their instructions I have been pairing with OS Bluetooth settings application, but it never prompts me for a key. It will pair but doesn't appear to bond, and this is critical for me.
My question is, when they say "using the Android API" is this referring to simply using the OS Bluetooth utility to pair before hand (like I have been doing), or is there some way to do it with code in my application. They reference the "createBond()" function which, to my knowledge, is not an accessible function (at least not without some squirrely libraries or reflection).
Any advice is greatly appreciated, especially anyone who has used the API successfully, if they could give an account of their process. I'm just looking for some clarity at this point :)
Lloyd,
You are correct, follow the instructions in the link you posted.
Outside of coding, when they say use the standard android api for "non-le" operations, they mean go ahead and pair the ble device the same way you would any bluetooth classic devices inside android settings -> wireless & network -> bluetooth -> scan for devices.
If the device you are using is a motorola le compatible device the ble device will be paired but not connected.
Now, in the code, you can detect this paired device through the same method of
BluetoothAdapter.getDefaultAdapter().getBondedDevices()
To double check if your Android Phone is LE compatible, run this code:
public static boolean checkBLESupport() {
boolean deviceSupportsLE;
try {
#SuppressWarnings({ "unused", "rawtypes" })
Class object = Class.forName("android.server.BluetoothGattService");
deviceSupportsLE = true;
} catch (Exception e) {
deviceSupportsLE = false;
}
return deviceSupportsLE;
}
And to double check if the bluetooth device you paired is LE, when you are looping through the bonded devices.
Check the device with this code.
if (device.getBluetoothClass() == null) {
Log.i(TAG, "This device is BLE compatible");
b = true;
} else {
Log.i(TAG, "This device is not BLE");
b = false;
}
Now for establishing connection from your LE compatible phone to your LE compatible bluetooth device, follow the Gatt service instructions under the link you posted. http://developer.motorola.com/docs/bluetooth-low-energy-api/
Take note that under this example it is connecting to a bluetooth low energy heart rate monitor.
If you are not trying to connect to the heart rate monitor with LE heart rate profile, here is a link to another Motorola document that details creating your own LE Profile to use with the GATT framework. http://developer.motorola.com/docs/bluetooth-low-energy-gatt-framework-api/
If the instructions are not clear enough at any point in either of these documents, motorola offers sample android applications using the frameworks in those documents.
I guess motorola stack has BLE support. But what i feel is that it does not pair with the devices that require bonding though It does work some sensors. I have tried with a proximity sensor that require bonding. It never gets paired though the devices is discovered with Razr which even does not with S3.
There's a helpful video here.
Late to the game, but can confirm -
If your BLE Peripheral requires bonding, Moto X - and some other older Motorola devices - MUST be paired via Bluetooth Settings prior to programmatic connection via the Android GATT interface.
If you bond via the createBond method, or reading of an encrypted characteristic, your connection will be dropped typically in under 60 seconds, despite DDMS logs that show a good bond may be established.

Categories

Resources