Search in sources :

Example 6 with BluetoothAdapter

use of android.bluetooth.BluetoothAdapter in project android_frameworks_base by ResurrectionRemix.

the class ExternalSharedPermsDiffKeyTest method testRunBluetoothAndFineLocation.

/** The use of location manager and bluetooth below are simply to simulate an app that
     *  tries to use them, so we can verify whether permissions are granted and accessible.
     * */
public void testRunBluetoothAndFineLocation() {
    LocationManager locationManager = (LocationManager) getInstrumentation().getContext().getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {

        public void onLocationChanged(Location location) {
        }

        public void onProviderDisabled(String provider) {
        }

        public void onProviderEnabled(String provider) {
        }

        public void onStatusChanged(String provider, int status, Bundle extras) {
        }
    });
    BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if ((mBluetoothAdapter != null) && (!mBluetoothAdapter.isEnabled())) {
        mBluetoothAdapter.getName();
    }
    fail("this app was signed by a different cert and should crash/fail to run by now");
}
Also used : LocationManager(android.location.LocationManager) Bundle(android.os.Bundle) LocationListener(android.location.LocationListener) BluetoothAdapter(android.bluetooth.BluetoothAdapter) Location(android.location.Location)

Example 7 with BluetoothAdapter

use of android.bluetooth.BluetoothAdapter in project android_frameworks_base by ResurrectionRemix.

the class Tethering method setBluetoothTethering.

private void setBluetoothTethering(final boolean enable, final ResultReceiver receiver) {
    final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (adapter == null || !adapter.isEnabled()) {
        Log.w(TAG, "Tried to enable bluetooth tethering with null or disabled adapter. null: " + (adapter == null));
        sendTetherResult(receiver, ConnectivityManager.TETHER_ERROR_SERVICE_UNAVAIL);
        return;
    }
    adapter.getProfileProxy(mContext, new ServiceListener() {

        @Override
        public void onServiceDisconnected(int profile) {
        }

        @Override
        public void onServiceConnected(int profile, BluetoothProfile proxy) {
            ((BluetoothPan) proxy).setBluetoothTethering(enable);
            // TODO: Enabling bluetooth tethering can fail asynchronously here.
            // We should figure out a way to bubble up that failure instead of sending success.
            int result = ((BluetoothPan) proxy).isTetheringOn() == enable ? ConnectivityManager.TETHER_ERROR_NO_ERROR : ConnectivityManager.TETHER_ERROR_MASTER_ERROR;
            sendTetherResult(receiver, result);
            if (enable && isTetherProvisioningRequired()) {
                scheduleProvisioningRechecks(ConnectivityManager.TETHERING_BLUETOOTH);
            }
            adapter.closeProfileProxy(BluetoothProfile.PAN, proxy);
        }
    }, BluetoothProfile.PAN);
}
Also used : ServiceListener(android.bluetooth.BluetoothProfile.ServiceListener) BluetoothProfile(android.bluetooth.BluetoothProfile) BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 8 with BluetoothAdapter

use of android.bluetooth.BluetoothAdapter in project AndroidChromium by JackyAndroid.

the class Utils method getBluetoothEnabledStatus.

public static int getBluetoothEnabledStatus() {
    int statusResult = RESULT_INDETERMINATE;
    if (isBluetoothPermissionGranted()) {
        BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter();
        statusResult = (bt != null && bt.isEnabled()) ? RESULT_SUCCESS : RESULT_FAILURE;
    }
    return statusResult;
}
Also used : BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 9 with BluetoothAdapter

use of android.bluetooth.BluetoothAdapter in project android_frameworks_base by DirtyUnicorns.

the class ScanFilterTest method setUp.

@Override
protected void setUp() throws Exception {
    byte[] scanRecord = new byte[] { // advertising flags
    0x02, // advertising flags
    0x01, // advertising flags
    0x1a, // 16 bit service uuids
    0x05, // 16 bit service uuids
    0x02, // 16 bit service uuids
    0x0b, // 16 bit service uuids
    0x11, // 16 bit service uuids
    0x0a, // 16 bit service uuids
    0x11, // setName
    0x04, // setName
    0x09, // setName
    0x50, // setName
    0x65, // setName
    0x64, // tx power level
    0x02, // tx power level
    0x0A, // tx power level
    (byte) 0xec, // service data
    0x05, // service data
    0x16, // service data
    0x0b, // service data
    0x11, // service data
    0x50, // service data
    0x64, // manufacturer specific data
    0x05, // manufacturer specific data
    (byte) 0xff, // manufacturer specific data
    (byte) 0xe0, // manufacturer specific data
    0x00, // manufacturer specific data
    0x02, // manufacturer specific data
    0x15, // an unknown data type won't cause trouble
    0x03, // an unknown data type won't cause trouble
    0x50, // an unknown data type won't cause trouble
    0x01, // an unknown data type won't cause trouble
    0x02 };
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    BluetoothDevice device = adapter.getRemoteDevice(DEVICE_MAC);
    mScanResult = new ScanResult(device, ScanRecord.parseFromBytes(scanRecord), -10, 1397545200000000L);
    mFilterBuilder = new ScanFilter.Builder();
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) ScanFilter(android.bluetooth.le.ScanFilter) BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 10 with BluetoothAdapter

use of android.bluetooth.BluetoothAdapter in project android_frameworks_base by DirtyUnicorns.

the class ExternalSharedPermsDiffKeyTest method testRunBluetoothAndFineLocation.

/** The use of location manager and bluetooth below are simply to simulate an app that
     *  tries to use them, so we can verify whether permissions are granted and accessible.
     * */
public void testRunBluetoothAndFineLocation() {
    LocationManager locationManager = (LocationManager) getInstrumentation().getContext().getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {

        public void onLocationChanged(Location location) {
        }

        public void onProviderDisabled(String provider) {
        }

        public void onProviderEnabled(String provider) {
        }

        public void onStatusChanged(String provider, int status, Bundle extras) {
        }
    });
    BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if ((mBluetoothAdapter != null) && (!mBluetoothAdapter.isEnabled())) {
        mBluetoothAdapter.getName();
    }
    fail("this app was signed by a different cert and should crash/fail to run by now");
}
Also used : LocationManager(android.location.LocationManager) Bundle(android.os.Bundle) LocationListener(android.location.LocationListener) BluetoothAdapter(android.bluetooth.BluetoothAdapter) Location(android.location.Location)

Aggregations

BluetoothAdapter (android.bluetooth.BluetoothAdapter)184 Intent (android.content.Intent)27 BluetoothDevice (android.bluetooth.BluetoothDevice)22 BluetoothManager (android.bluetooth.BluetoothManager)16 BluetoothPan (android.bluetooth.BluetoothPan)15 IntentFilter (android.content.IntentFilter)15 LocationManager (android.location.LocationManager)15 BluetoothProfile (android.bluetooth.BluetoothProfile)13 Location (android.location.Location)12 LocationListener (android.location.LocationListener)12 Bundle (android.os.Bundle)12 TextView (android.widget.TextView)10 BluetoothLeScanner (android.bluetooth.le.BluetoothLeScanner)9 ScanSettings (android.bluetooth.le.ScanSettings)9 ScanCallback (android.bluetooth.le.ScanCallback)8 ScanResult (android.bluetooth.le.ScanResult)8 Method (java.lang.reflect.Method)8 List (java.util.List)8 Activity (android.app.Activity)7 ScanFilter (android.bluetooth.le.ScanFilter)7