Search in sources :

Example 36 with BluetoothAdapter

use of android.bluetooth.BluetoothAdapter in project bitcoin-wallet by bitcoin-wallet.

the class AlertDialogsFragment method handleProperty.

private boolean handleProperty(final String key, final String value) {
    if (key.equalsIgnoreCase("min.security_patch.bluetooth")) {
        final String minSecurityPatchLevel = value;
        log.info("according to \"{}\", minimum security patch level for bluetooth is {}", versionUrl, minSecurityPatchLevel);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Build.VERSION.SECURITY_PATCH.compareTo(minSecurityPatchLevel) < 0) {
            final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
            if (bluetoothAdapter != null && BluetoothAdapter.getDefaultAdapter().isEnabled()) {
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        if (isAdded())
                            createInsecureBluetoothAlertDialog(minSecurityPatchLevel).show();
                    }
                });
                return true;
            }
        }
    } else {
        log.info("Ignoring key: {}", key);
    }
    return false;
}
Also used : BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 37 with BluetoothAdapter

use of android.bluetooth.BluetoothAdapter in project android_packages_apps_Settings by LineageOS.

the class TetherSettings method updateBluetoothState.

private void updateBluetoothState() {
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (adapter == null) {
        return;
    }
    int btState = adapter.getState();
    if (btState == BluetoothAdapter.STATE_TURNING_OFF) {
        mBluetoothTether.setEnabled(false);
    } else if (btState == BluetoothAdapter.STATE_TURNING_ON) {
        mBluetoothTether.setEnabled(false);
    } else {
        BluetoothPan bluetoothPan = mBluetoothPan.get();
        if (btState == BluetoothAdapter.STATE_ON && bluetoothPan != null && bluetoothPan.isTetheringOn()) {
            mBluetoothTether.setChecked(true);
            mBluetoothTether.setEnabled(!mDataSaverEnabled);
        } else {
            mBluetoothTether.setEnabled(!mDataSaverEnabled);
            mBluetoothTether.setChecked(false);
        }
    }
}
Also used : BluetoothAdapter(android.bluetooth.BluetoothAdapter) BluetoothPan(android.bluetooth.BluetoothPan)

Example 38 with BluetoothAdapter

use of android.bluetooth.BluetoothAdapter in project android_packages_apps_Settings by LineageOS.

the class TetherSettings method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    addPreferencesFromResource(R.xml.tether_prefs);
    mFooterPreferenceMixin.createFooterPreference().setTitle(R.string.tethering_footer_info);
    mDataSaverBackend = new DataSaverBackend(getContext());
    mDataSaverEnabled = mDataSaverBackend.isDataSaverEnabled();
    mDataSaverFooter = findPreference(DATA_SAVER_FOOTER);
    setIfOnlyAvailableForAdmins(true);
    if (isUiRestricted()) {
        mUnavailable = true;
        getPreferenceScreen().removeAll();
        return;
    }
    final Activity activity = getActivity();
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (adapter != null) {
        adapter.getProfileProxy(activity.getApplicationContext(), mProfileServiceListener, BluetoothProfile.PAN);
    }
    mEnableWifiAp = (SwitchPreference) findPreference(ENABLE_WIFI_AP);
    Preference wifiApSettings = findPreference(WIFI_AP_SSID_AND_SECURITY);
    mUsbTether = (SwitchPreference) findPreference(USB_TETHER_SETTINGS);
    mBluetoothTether = (SwitchPreference) findPreference(ENABLE_BLUETOOTH_TETHERING);
    mDataSaverBackend.addListener(this);
    mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    mUsbRegexs = mCm.getTetherableUsbRegexs();
    mWifiRegexs = mCm.getTetherableWifiRegexs();
    mBluetoothRegexs = mCm.getTetherableBluetoothRegexs();
    final boolean usbAvailable = mUsbRegexs.length != 0;
    final boolean wifiAvailable = mWifiRegexs.length != 0;
    final boolean bluetoothAvailable = mBluetoothRegexs.length != 0;
    if (!usbAvailable || Utils.isMonkeyRunning()) {
        getPreferenceScreen().removePreference(mUsbTether);
    }
    mWifiTetherPreferenceController.displayPreference(getPreferenceScreen());
    if (WifiTetherSettings.isTetherSettingPageEnabled()) {
        removePreference(ENABLE_WIFI_AP);
        removePreference(WIFI_AP_SSID_AND_SECURITY);
    } else {
        if (wifiAvailable && !Utils.isMonkeyRunning()) {
            mWifiApEnabler = new WifiApEnabler(activity, mDataSaverBackend, mEnableWifiAp);
            initWifiTethering();
        } else {
            getPreferenceScreen().removePreference(mEnableWifiAp);
            getPreferenceScreen().removePreference(wifiApSettings);
        }
    }
    if (!bluetoothAvailable) {
        getPreferenceScreen().removePreference(mBluetoothTether);
    } else {
        BluetoothPan pan = mBluetoothPan.get();
        if (pan != null && pan.isTetheringOn()) {
            mBluetoothTether.setChecked(true);
        } else {
            mBluetoothTether.setChecked(false);
        }
    }
    // Set initial state based on Data Saver mode.
    onDataSaverChanged(mDataSaverBackend.isDataSaverEnabled());
}
Also used : DataSaverBackend(com.android.settings.datausage.DataSaverBackend) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference) WifiApEnabler(com.android.settings.wifi.WifiApEnabler) Activity(android.app.Activity) BluetoothAdapter(android.bluetooth.BluetoothAdapter) BluetoothPan(android.bluetooth.BluetoothPan)

Example 39 with BluetoothAdapter

use of android.bluetooth.BluetoothAdapter in project android_packages_apps_Settings by LineageOS.

the class TetherSettings method onDestroy.

@Override
public void onDestroy() {
    mDataSaverBackend.remListener(this);
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    BluetoothProfile profile = mBluetoothPan.getAndSet(null);
    if (profile != null && adapter != null) {
        adapter.closeProfileProxy(BluetoothProfile.PAN, profile);
    }
    super.onDestroy();
}
Also used : BluetoothProfile(android.bluetooth.BluetoothProfile) BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 40 with BluetoothAdapter

use of android.bluetooth.BluetoothAdapter in project android_packages_apps_Settings by LineageOS.

the class TetherSettings method startTethering.

private void startTethering(int choice) {
    if (choice == TETHERING_BLUETOOTH) {
        // Turn on Bluetooth first.
        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
        if (adapter.getState() == BluetoothAdapter.STATE_OFF) {
            mBluetoothEnableForTether = true;
            adapter.enable();
            mBluetoothTether.setSummary(R.string.bluetooth_turning_on);
            mBluetoothTether.setEnabled(false);
            return;
        }
    }
    mCm.startTethering(choice, true, mStartTetheringCallback, mHandler);
}
Also used : BluetoothAdapter(android.bluetooth.BluetoothAdapter)

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